Changeset 288758 in webkit
- Timestamp:
- Jan 28, 2022 12:48:11 PM (6 months ago)
- Location:
- trunk
- Files:
-
- 6 added
- 10 edited
-
JSTests/ChangeLog (modified) (1 diff)
-
JSTests/wasm.yaml (modified) (1 diff)
-
JSTests/wasm/branch-hints (added)
-
JSTests/wasm/branch-hints/branchHintsModule.wasm (added)
-
JSTests/wasm/branch-hints/branchHintsSection.js (added)
-
Source/JavaScriptCore/ChangeLog (modified) (1 diff)
-
Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj (modified) (5 diffs)
-
Source/JavaScriptCore/Sources.txt (modified) (1 diff)
-
Source/JavaScriptCore/runtime/OptionsList.h (modified) (1 diff)
-
Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp (modified) (3 diffs)
-
Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp (modified) (3 diffs)
-
Source/JavaScriptCore/wasm/WasmBranchHints.h (added)
-
Source/JavaScriptCore/wasm/WasmBranchHintsSectionParser.cpp (added)
-
Source/JavaScriptCore/wasm/WasmBranchHintsSectionParser.h (added)
-
Source/JavaScriptCore/wasm/WasmModuleInformation.h (modified) (3 diffs)
-
Source/JavaScriptCore/wasm/WasmSectionParser.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/JSTests/ChangeLog
r288538 r288758 1 2022-01-28 Tom Tartarin <tom@leaningtech.com> 2 3 [JSC] Add support for WASM branch hinting proposal 4 https://bugs.webkit.org/show_bug.cgi?id=235581 5 6 Reviewed by Yusuke Suzuki. 7 8 Add test for branch hinting custom section 9 10 * wasm.yaml: 11 * wasm/branch-hints/branchHintsModule.wasm: Added. 12 * wasm/branch-hints/branchHintsSection.js: Added. 13 (const.module): 14 1 15 2022-01-24 Yusuke Suzuki <ysuzuki@apple.com> 2 16 -
trunk/JSTests/wasm.yaml
r285065 r288758 48 48 - path: wasm/v8/ 49 49 cmd: runWebAssemblySuite(:no_module, "mjsunit.js") unless parseRunCommands 50 - path: wasm/branch-hints 51 cmd: runWebAssemblySuite("--useWebAssemblyBranchHints=true") 50 52 51 53 - path: wasm/references-spec-tests/elem.wast.js -
trunk/Source/JavaScriptCore/ChangeLog
r288748 r288758 1 2022-01-28 Tom Tartarin <tom@leaningtech.com> 2 3 [JSC] Add support for WASM branch hinting proposal 4 https://bugs.webkit.org/show_bug.cgi?id=235581 5 6 Reviewed by Yusuke Suzuki. 7 8 See the proposal for a more detailed description: https://github.com/WebAssembly/branch-hinting. 9 10 This allows parsing a "code_annotation.branch_hint" custom section, 11 as per the code annotation proposal: https://github.com/WebAssembly/annotations. 12 This section provides per function information about how likely a branch at a 13 given offset is to be taken. It is similar to branch weight metadata in LLVM. 14 15 16 * JavaScriptCore.xcodeproj/project.pbxproj: 17 * Sources.txt: 18 * runtime/OptionsList.h: 19 * wasm/WasmAirIRGenerator.cpp: 20 (JSC::Wasm::AirIRGenerator::addIf): 21 (JSC::Wasm::AirIRGenerator::addBranch): 22 * wasm/WasmB3IRGenerator.cpp: 23 (JSC::Wasm::B3IRGenerator::addIf): 24 (JSC::Wasm::B3IRGenerator::addBranch): 25 * wasm/WasmBranchHints.h: Added. 26 (JSC::Wasm::BranchHintMap::add): 27 (JSC::Wasm::BranchHintMap::getBranchHint const): 28 (JSC::Wasm::BranchHintMap::isValidKey const): 29 (JSC::Wasm::isValidBranchHint): 30 * wasm/WasmBranchHintsSectionParser.cpp: Added. 31 (JSC::Wasm::BranchHintsSectionParser::parse): 32 * wasm/WasmBranchHintsSectionParser.h: Added. 33 (JSC::Wasm::BranchHintsSectionParser::BranchHintsSectionParser): 34 * wasm/WasmModuleInformation.h: 35 (JSC::Wasm::ModuleInformation::getBranchHint const): 36 * wasm/WasmSectionParser.cpp: 37 (JSC::Wasm::SectionParser::parseCustom): 38 1 39 2022-01-28 Yusuke Suzuki <ysuzuki@apple.com> 2 40 -
trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
r288710 r288758 857 857 33B2A54722653481005A0F79 /* B3ValueInlines.h in Headers */ = {isa = PBXBuildFile; fileRef = 0FEC84FB1BDACDAC0080FF74 /* B3ValueInlines.h */; }; 858 858 33B2A548226543BF005A0F79 /* FTLLowerDFGToB3.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 0FEA0A04170513DB00BB722C /* FTLLowerDFGToB3.cpp */; }; 859 37AAC093279F1BFC00D64842 /* WasmBranchHintsSectionParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 37AAC092279F124200D64842 /* WasmBranchHintsSectionParser.h */; }; 860 37AAC094279F1C0500D64842 /* WasmBranchHints.h in Headers */ = {isa = PBXBuildFile; fileRef = 37AAC091279F124200D64842 /* WasmBranchHints.h */; }; 859 861 37C738D21EDB56E4003F2B0B /* ParseInt.h in Headers */ = {isa = PBXBuildFile; fileRef = 37C738D11EDB5672003F2B0B /* ParseInt.h */; settings = {ATTRIBUTES = (Private, ); }; }; 860 862 412952771D2CF6BC00E78B89 /* builtins_generate_internals_wrapper_header.py in Headers */ = {isa = PBXBuildFile; fileRef = 412952731D2CF6AC00E78B89 /* builtins_generate_internals_wrapper_header.py */; settings = {ATTRIBUTES = (Private, ); }; }; … … 3727 3729 37119A7720CCB5DC002C6DC9 /* WebKitTargetConditionals.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = WebKitTargetConditionals.xcconfig; sourceTree = "<group>"; }; 3728 3730 371D842C17C98B6E00ECF994 /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = usr/lib/libz.dylib; sourceTree = SDKROOT; }; 3731 37AAC090279F124100D64842 /* WasmBranchHintsSectionParser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WasmBranchHintsSectionParser.cpp; sourceTree = "<group>"; }; 3732 37AAC091279F124200D64842 /* WasmBranchHints.h */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.h; fileEncoding = 4; path = WasmBranchHints.h; sourceTree = "<group>"; }; 3733 37AAC092279F124200D64842 /* WasmBranchHintsSectionParser.h */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.h; fileEncoding = 4; path = WasmBranchHintsSectionParser.h; sourceTree = "<group>"; }; 3729 3734 37C738D11EDB5672003F2B0B /* ParseInt.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ParseInt.h; sourceTree = "<group>"; }; 3730 3735 412952731D2CF6AC00E78B89 /* builtins_generate_internals_wrapper_header.py */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.python; path = builtins_generate_internals_wrapper_header.py; sourceTree = "<group>"; }; … … 7310 7315 isa = PBXGroup; 7311 7316 children = ( 7317 37AAC091279F124200D64842 /* WasmBranchHints.h */, 7318 37AAC090279F124100D64842 /* WasmBranchHintsSectionParser.cpp */, 7319 37AAC092279F124200D64842 /* WasmBranchHintsSectionParser.h */, 7312 7320 AD2FCB8A1DB5840000B3E736 /* js */, 7313 7321 52847AD921FFB8630061A9DB /* WasmAirIRGenerator.cpp */, … … 10957 10965 0FE0502B1AA9095600D33B33 /* ScopeOffset.h in Headers */, 10958 10966 0F24E55217EE274900ABB217 /* ScratchRegisterAllocator.h in Headers */, 10967 37AAC094279F1C0500D64842 /* WasmBranchHints.h in Headers */, 10959 10968 33111B8B2397256500AA34CE /* Scribble.h in Headers */, 10960 10969 A5FD0068189AFE9C00633231 /* ScriptArguments.h in Headers */, … … 11083 11092 0F572D4F16879FDD00E57FBD /* ThunkGenerator.h in Headers */, 11084 11093 A7386556118697B400540279 /* ThunkGenerators.h in Headers */, 11094 37AAC093279F1BFC00D64842 /* WasmBranchHintsSectionParser.h in Headers */, 11085 11095 141448CD13A1783700F5BA1A /* TinyBloomFilter.h in Headers */, 11086 11096 0F55989817C86C5800A1E543 /* ToNativeFromValue.h in Headers */, -
trunk/Source/JavaScriptCore/Sources.txt
r288261 r288758 1066 1066 wasm/WasmBBQPlan.cpp 1067 1067 wasm/WasmBinding.cpp 1068 wasm/WasmBranchHintsSectionParser.cpp 1068 1069 wasm/WasmCallee.cpp 1069 1070 wasm/WasmCalleeGroup.cpp -
trunk/Source/JavaScriptCore/runtime/OptionsList.h
r288538 r288758 551 551 v(Bool, useWebAssemblyTypedFunctionReferences, false, Normal, "Allow function types from the wasm typed function references spec.") \ 552 552 v(Bool, useWebAssemblyExceptions, true, Normal, "Allow the new section and instructions from the wasm exception handling spec.") \ 553 v(Bool, useWebAssemblyBranchHints, false, Normal, "Allow the new section from the wasm branch hinting spec.") \ 553 554 554 555 -
trunk/Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp
r288261 r288758 45 45 #include "JSWebAssemblyInstance.h" 46 46 #include "ScratchRegisterAllocator.h" 47 #include "WasmBranchHints.h" 47 48 #include "WasmCallingConvention.h" 48 49 #include "WasmContextInlines.h" … … 3175 3176 BasicBlock* notTaken = m_code.addBlock(); 3176 3177 BasicBlock* continuation = m_code.addBlock(); 3177 3178 B3::FrequencyClass takenFrequency = B3::FrequencyClass::Normal; 3179 B3::FrequencyClass notTakenFrequency= B3::FrequencyClass::Normal; 3180 3181 if (Options::useWebAssemblyBranchHints()) { 3182 BranchHint hint = m_info.getBranchHint(m_functionIndex, m_parser->currentOpcodeStartingOffset()); 3183 3184 switch (hint) { 3185 case BranchHint::Unlikely: 3186 takenFrequency = B3::FrequencyClass::Rare; 3187 break; 3188 case BranchHint::Likely: 3189 notTakenFrequency = B3::FrequencyClass::Rare; 3190 break; 3191 case BranchHint::Invalid: 3192 break; 3193 } 3194 } 3195 3178 3196 // Wasm bools are i32. 3179 3197 append(BranchTest32, Arg::resCond(MacroAssembler::NonZero), condition, condition); 3180 m_currentBlock->setSuccessors( taken, notTaken);3198 m_currentBlock->setSuccessors(FrequentedBlock(taken, takenFrequency), FrequentedBlock(notTaken, notTakenFrequency)); 3181 3199 3182 3200 m_currentBlock = taken; … … 3418 3436 3419 3437 BasicBlock* target = data.targetBlockForBranch(); 3438 B3::FrequencyClass targetFrequency = B3::FrequencyClass::Normal; 3439 B3::FrequencyClass continuationFrequency = B3::FrequencyClass::Normal; 3440 3441 if (Options::useWebAssemblyBranchHints()) { 3442 BranchHint hint = m_info.getBranchHint(m_functionIndex, m_parser->currentOpcodeStartingOffset()); 3443 3444 switch (hint) { 3445 case BranchHint::Unlikely: 3446 targetFrequency = B3::FrequencyClass::Rare; 3447 break; 3448 case BranchHint::Likely: 3449 continuationFrequency = B3::FrequencyClass::Rare; 3450 break; 3451 case BranchHint::Invalid: 3452 break; 3453 } 3454 } 3455 3420 3456 if (condition) { 3421 3457 BasicBlock* continuation = m_code.addBlock(); 3422 3458 append(BranchTest32, Arg::resCond(MacroAssembler::NonZero), condition, condition); 3423 m_currentBlock->setSuccessors( target, continuation);3459 m_currentBlock->setSuccessors(FrequentedBlock(target, targetFrequency), FrequentedBlock(continuation, continuationFrequency)); 3424 3460 m_currentBlock = continuation; 3425 3461 } else { 3426 3462 append(Jump); 3427 m_currentBlock->setSuccessors( target);3463 m_currentBlock->setSuccessors(FrequentedBlock(target, targetFrequency)); 3428 3464 } 3429 3465 -
trunk/Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp
r288261 r288758 53 53 #include "ProbeContext.h" 54 54 #include "ScratchRegisterAllocator.h" 55 #include " ScratchRegisterAllocator.h"55 #include "WasmBranchHints.h" 56 56 #include "WasmCallingConvention.h" 57 57 #include "WasmContextInlines.h" … … 2476 2476 BasicBlock* notTaken = m_proc.addBlock(); 2477 2477 BasicBlock* continuation = m_proc.addBlock(); 2478 FrequencyClass takenFrequency = FrequencyClass::Normal; 2479 FrequencyClass notTakenFrequency = FrequencyClass::Normal; 2480 2481 if (Options::useWebAssemblyBranchHints()) { 2482 BranchHint hint = m_info.getBranchHint(m_functionIndex, m_parser->currentOpcodeStartingOffset()); 2483 2484 switch (hint) { 2485 case BranchHint::Unlikely: 2486 takenFrequency = FrequencyClass::Rare; 2487 break; 2488 case BranchHint::Likely: 2489 notTakenFrequency = FrequencyClass::Rare; 2490 break; 2491 case BranchHint::Invalid: 2492 break; 2493 } 2494 } 2478 2495 2479 2496 m_currentBlock->appendNew<Value>(m_proc, B3::Branch, origin(), get(condition)); 2480 m_currentBlock->setSuccessors(FrequentedBlock(taken ), FrequentedBlock(notTaken));2497 m_currentBlock->setSuccessors(FrequentedBlock(taken, takenFrequency), FrequentedBlock(notTaken, notTakenFrequency)); 2481 2498 taken->addPredecessor(m_currentBlock); 2482 2499 notTaken->addPredecessor(m_currentBlock); … … 2722 2739 2723 2740 BasicBlock* target = data.targetBlockForBranch(); 2741 FrequencyClass targetFrequency = FrequencyClass::Normal; 2742 FrequencyClass continuationFrequency = FrequencyClass::Normal; 2743 2744 if (Options::useWebAssemblyBranchHints()) { 2745 BranchHint hint = m_info.getBranchHint(m_functionIndex, m_parser->currentOpcodeStartingOffset()); 2746 2747 switch (hint) { 2748 case BranchHint::Unlikely: 2749 targetFrequency = FrequencyClass::Rare; 2750 break; 2751 case BranchHint::Likely: 2752 continuationFrequency = FrequencyClass::Rare; 2753 break; 2754 case BranchHint::Invalid: 2755 break; 2756 } 2757 } 2758 2724 2759 if (condition) { 2725 2760 BasicBlock* continuation = m_proc.addBlock(); 2726 2761 m_currentBlock->appendNew<Value>(m_proc, B3::Branch, origin(), get(condition)); 2727 m_currentBlock->setSuccessors(FrequentedBlock(target ), FrequentedBlock(continuation));2762 m_currentBlock->setSuccessors(FrequentedBlock(target, targetFrequency), FrequentedBlock(continuation, continuationFrequency)); 2728 2763 target->addPredecessor(m_currentBlock); 2729 2764 continuation->addPredecessor(m_currentBlock); 2730 2765 m_currentBlock = continuation; 2731 2766 } else { 2732 m_currentBlock->appendNewControlValue(m_proc, Jump, origin(), FrequentedBlock(target ));2767 m_currentBlock->appendNewControlValue(m_proc, Jump, origin(), FrequentedBlock(target, targetFrequency)); 2733 2768 target->addPredecessor(m_currentBlock); 2734 2769 } -
trunk/Source/JavaScriptCore/wasm/WasmModuleInformation.h
r288573 r288758 28 28 #if ENABLE(WEBASSEMBLY) 29 29 30 #include "WasmBranchHints.h" 30 31 #include "WasmFormat.h" 31 32 32 33 #include <wtf/BitVector.h> 34 #include <wtf/HashMap.h> 33 35 34 36 namespace JSC { namespace Wasm { 35 37 36 38 struct ModuleInformation : public ThreadSafeRefCounted<ModuleInformation> { 39 40 using BranchHints = HashMap<uint32_t, BranchHintMap, IntHash<uint32_t>, WTF::UnsignedWithZeroKeyHashTraits<uint32_t>>; 41 37 42 ModuleInformation(); 38 43 ModuleInformation(const ModuleInformation&) = delete; … … 97 102 bool hasMemoryImport() const { return memory.isImport(); } 98 103 104 BranchHint getBranchHint(uint32_t functionOffset, uint32_t branchOffset) const 105 { 106 auto it = branchHints.find(functionOffset); 107 return it == branchHints.end() 108 ? BranchHint::Invalid 109 : it->value.getBranchHint(branchOffset); 110 } 111 99 112 Vector<Import> imports; 100 113 Vector<SignatureIndex> importFunctionSignatureIndices; … … 118 131 Vector<CustomSection> customSections; 119 132 Ref<NameSection> nameSection; 133 BranchHints branchHints; 120 134 uint32_t numberOfDataSegments { 0 }; 121 135 -
trunk/Source/JavaScriptCore/wasm/WasmSectionParser.cpp
r285065 r288758 31 31 32 32 #include "JSCJSValueInlines.h" 33 #include "WasmBranchHintsSectionParser.h" 33 34 #include "WasmMemoryInformation.h" 34 35 #include "WasmNameSectionParser.h" … … 897 898 if (auto nameSection = nameSectionParser.parse()) 898 899 m_info->nameSection = WTFMove(*nameSection); 900 } else if (Options::useWebAssemblyBranchHints()) { 901 Name branchHintsName = { 'c', 'o', 'd', 'e', '_', 'a', 'n', 'n', 'o', 't', 'a', 't', 'i', 'o', 'n', '.', 'b', 'r', 'a', 'n', 'c', 'h', '_', 'h', 'i', 'n', 't' }; 902 if (section.name == branchHintsName) { 903 BranchHintsSectionParser branchHintsSectionParser(section.payload.begin(), section.payload.size(), m_info); 904 branchHintsSectionParser.parse(); 905 } 899 906 } 900 907
Note: See TracChangeset
for help on using the changeset viewer.