source: webkit/trunk/Source/JavaScriptCore/build-symbol-table-index.py@ 171660

Last change on this file since 171660 was 171391, checked in by [email protected], 11 years ago

Merge r169628 from ftlopt.

2014-06-04 Matthew Mirman <[email protected]>


Added system for inlining native functions via the FTL.
https://bugs.webkit.org/show_bug.cgi?id=131515


Reviewed by Filip Pizlo.


Also fixed the build to not compress the bitcode and to
include all of the relevant runtime. With GCC_GENERATE_DEBUGGING_SYMBOLS = NO,
the produced bitcode files are a 100th the size they were before.
Now we can include all of the relevant runtime files with only a 3mb overhead.
This is the same overhead as for two compressed files before,
but done more efficiently (on both ends) and with less code.


Deciding whether to inline native functions is left up to LLVM.
The entire module containing the function is linked into the current
compiled JS so that inlining the native functions shouldn't make them smaller.


Rather than loading Runtime.symtbl at runtime FTLState.cpp now generates a file
InlineRuntimeSymbolTable.h which statically builds the symbol table hash table.


  • JavaScriptCore.xcodeproj/project.pbxproj: Added back runtime files to compile.
  • build-symbol-table-index.py: Changed bitcode suffix. Added inclusion of only tested symbols. Added output to InlineRuntimeSymbolTable.h.
  • build-symbol-table-index.sh: Changed bitcode suffix.
  • copy-llvm-ir-to-derived-sources.sh: Removed gzip compression.
  • tested-symbols.symlst: Added.
  • dfg/DFGByteCodeParser.cpp: (JSC::DFG::ByteCodeParser::handleCall): Now sets the knownFunction of the call node if such a function exists and emits a check that during runtime the callee is in fact known.
  • dfg/DFGNode.h: Added functions to set the known function of a call node. (JSC::DFG::Node::canBeKnownFunction): Added. (JSC::DFG::Node::hasKnownFunction): Added. (JSC::DFG::Node::knownFunction): Added. (JSC::DFG::Node::giveKnownFunction): Added.
  • ftl/FTLAbbreviatedTypes.h: Added a typedef for LLVMMemoryBufferRef
  • ftl/FTLAbbreviations.h: Added some abbreviations.
  • ftl/FTLLowerDFGToLLVM.cpp: (JSC::FTL::LowerDFGToLLVM::isInlinableSize): Added. Hardcoded threshold to 275. (JSC::FTL::LowerDFGToLLVM::getModuleByPathForSymbol): Added. (JSC::FTL::LowerDFGToLLVM::getFunctionBySymbol): Added. (JSC::FTL::LowerDFGToLLVM::possiblyCompileInlineableNativeCall): Added. (JSC::FTL::LowerDFGToLLVM::compileCallOrConstruct): Added call to possiblyCompileInlineableNativeCall
  • ftl/FTLOutput.h: (JSC::FTL::Output::allocaName): Added. Useful for debugging.
  • ftl/FTLState.cpp: (JSC::FTL::State::State): Added an include for InlineRuntimeSymbolTable.h
  • ftl/FTLState.h: Added symbol table hash table.
  • ftl/FTLCompile.cpp: (JSC::FTL::compile): Added inlining and dead function elimination passes.
  • heap/HandleStack.h: Added JS_EXPORT_PRIVATE to a few functions to get inlining to compile.
  • llvm/InitializeLLVMMac.mm: Deleted.
  • llvm/InitializeLLVMMac.cpp: Added.
  • llvm/LLVMAPIFunctions.h: Added macros to include Bitcode parsing and linking functions.
  • llvm/LLVMHeaders.h: Added includes for Bitcode parsing and linking.
  • runtime/BundlePath.h: Added.
  • runtime/BundlePath.mm: Added.
  • runtime/DateInstance.h: Added JS_EXPORT_PRIVATE to a few functions to get inlining to compile.
  • runtime/DateInstance.h: ditto.
  • runtime/DateConversion.h: ditto.
  • runtime/ExceptionHelpers.h: ditto.
  • runtime/JSCJSValue.h: ditto.
  • runtime/JSArray.h: ditto.
  • runtime/JSDateMath.h: ditto.
  • runtime/JSObject.h: ditto.
  • runtime/JSObject.h: ditto.
  • runtime/RegExp.h: ditto.
  • runtime/Structure.h: ditto.
  • runtime/Options.h: Added maximumLLVMInstructionCountForNativeInlining.
  • Property svn:executable set to *
File size: 2.9 KB
Line 
1#!/usr/bin/python
2
3import glob
4import os
5import subprocess
6import sys
7from sets import Set
8from operator import itemgetter
9
10
11current_arch = sys.argv[1]
12
13print("Building Index Table")
14
15if current_arch not in ("x86_64", "arm64"):
16 sys.exit()
17
18binary_file_directory = os.path.join(os.getenv("OBJECT_FILE_DIR_" + os.getenv("CURRENT_VARIANT")), current_arch)
19
20if not os.path.isdir(binary_file_directory):
21 print("Failed to build index table at " + binary_file_directory)
22 sys.exit()
23
24framework_directory = os.path.join(os.getenv("BUILT_PRODUCTS_DIR"), os.getenv("JAVASCRIPTCORE_RESOURCES_DIR"), "Runtime", current_arch)
25
26
27symbol_table_location = os.path.join(framework_directory, "Runtime.symtbl")
28
29symbol_table = {}
30
31symbol_table_is_out_of_date = False
32
33symbol_table_modification_time = 0
34
35if os.path.isfile(symbol_table_location):
36 symbol_table_modification_time = os.path.getmtime(symbol_table_location)
37
38file_suffix = "bc"
39file_suffix_length = len(file_suffix)
40
41tested_symbols_location = "./tested-symbols.symlst"
42include_symbol_table_location = os.path.join(os.getenv("SHARED_DERIVED_FILE_DIR"), "JavaScriptCore/InlineRuntimeSymbolTable.h")
43
44tested_symbols = Set([])
45
46if os.path.isfile(tested_symbols_location):
47 with open(tested_symbols_location, 'r') as file:
48 print("Loading tested symbols")
49 for line in file:
50 tested_symbols.add(line[:-1])
51
52for bitcode_file in glob.iglob(os.path.join(framework_directory, "*." + file_suffix)):
53 bitcode_basename = os.path.basename(bitcode_file)
54 binary_file = os.path.join(binary_file_directory, bitcode_basename[:-file_suffix_length] + "o")
55 if os.path.getmtime(binary_file) < symbol_table_modification_time:
56 continue
57
58 symbol_table_is_out_of_date = True
59
60 print("Appending symbols from " + bitcode_basename)
61 lines = subprocess.check_output(["nm", "-U", "-j", binary_file]).splitlines()
62
63 for symbol in lines:
64 if symbol[:2] == "__" and symbol[-3:] != ".eh" and symbol in tested_symbols:
65 symbol_table[symbol[1:]] = bitcode_basename
66
67if not symbol_table_is_out_of_date:
68 sys.exit()
69
70if os.path.isfile(symbol_table_location):
71 with open(symbol_table_location, 'r') as file:
72 print("Loading symbol table")
73 for line in file:
74 symbol, _, location = line[:-1].partition(" ")
75 # don't overwrite new symbols with old locations
76 if not symbol in symbol_table:
77 symbol_table[symbol] = location
78
79symbol_list = symbol_table.items()
80
81print("Writing symbol table")
82
83with open(symbol_table_location, "w") as symbol_file:
84 with open(include_symbol_table_location, "w") as include_file:
85 include_file.write("#define FOR_EACH_LIBRARY_SYMBOL(macro)")
86 for symbol, location in symbol_list:
87 symbol_file.write("{} {}\n".format(symbol, location))
88 include_file.write(" \\\nmacro(\"{}\", \"{}\")".format(symbol, location))
89 include_file.write("\n")
90print("Done")
Note: See TracBrowser for help on using the repository browser.