diff options
author | Sam Clegg <sbc@chromium.org> | 2021-02-09 15:31:25 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-09 15:31:25 -0800 |
commit | e130b58895b64a0fe3a088e25f4043a12f3634ca (patch) | |
tree | 6e47bd5f8810b20a2f3f1e612a70a5a81cc85605 | |
parent | 2b63a468d84bd5b9d57f450ac5a8f4bf356ddee9 (diff) | |
download | binaryen-e130b58895b64a0fe3a088e25f4043a12f3634ca.tar.gz binaryen-e130b58895b64a0fe3a088e25f4043a12f3634ca.tar.bz2 binaryen-e130b58895b64a0fe3a088e25f4043a12f3634ca.zip |
Simplify asmConst handling. NFC. (#3558)
Support for multiple signatures per JS code string was removed in #2422.
emscripten now only needs to know that address and the body of the JS
function.
See https://github.com/emscripten-core/emscripten/pull/13452.
-rw-r--r-- | src/wasm/wasm-emscripten.cpp | 85 | ||||
-rw-r--r-- | test/lit/wasm-emscripten-finalize/passive-pic.wat | 2 | ||||
-rw-r--r-- | test/lld/em_asm.wat.mem.out | 6 | ||||
-rw-r--r-- | test/lld/em_asm.wat.out | 6 | ||||
-rw-r--r-- | test/lld/em_asm64.wat.out | 6 | ||||
-rw-r--r-- | test/lld/em_asm_O0.wat.out | 6 | ||||
-rw-r--r-- | test/lld/em_asm_main_thread.wat.out | 6 | ||||
-rw-r--r-- | test/lld/em_asm_shared.wat.out | 6 |
8 files changed, 28 insertions, 95 deletions
diff --git a/src/wasm/wasm-emscripten.cpp b/src/wasm/wasm-emscripten.cpp index 0aabcc0b4..24fb7bcdc 100644 --- a/src/wasm/wasm-emscripten.cpp +++ b/src/wasm/wasm-emscripten.cpp @@ -188,38 +188,17 @@ private: std::vector<Address> segmentOffsets; // segment index => address offset }; -enum class Proxying { - None, - Sync, - Async, -}; - -std::string proxyingSuffix(Proxying proxy) { - switch (proxy) { - case Proxying::None: - return ""; - case Proxying::Sync: - return "sync_on_main_thread_"; - case Proxying::Async: - return "async_on_main_thread_"; - } - WASM_UNREACHABLE("invalid prozy type"); -} - struct AsmConstWalker : public LinearExecutionWalker<AsmConstWalker> { Module& wasm; bool minimizeWasmChanges; StringConstantTracker stringTracker; struct AsmConst { - std::set<Signature> sigs; Address id; std::string code; - Proxying proxy; }; std::vector<AsmConst> asmConsts; - std::set<std::pair<Signature, Proxying>> allSigs; // last sets in the current basic block, per index std::map<Index, LocalSet*> sets; @@ -235,11 +214,8 @@ struct AsmConstWalker : public LinearExecutionWalker<AsmConstWalker> { void process(); private: - void createAsmConst(uint64_t id, std::string code, Signature sig, Name name); - Signature asmConstSig(Signature baseSig); - Name nameForImportWithSig(Signature sig, Proxying proxy); + void createAsmConst(uint64_t id, std::string code); void addImports(); - Proxying proxyType(Name name); std::vector<std::unique_ptr<Function>> queuedImports; }; @@ -263,8 +239,6 @@ void AsmConstWalker::visitCall(Call* curr) { return; } - auto baseSig = wasm.getFunction(curr->target)->sig; - auto sig = asmConstSig(baseSig); auto* arg = curr->operands[0]; while (!arg->dynCast<Const>()) { if (auto* get = arg->dynCast<LocalGet>()) { @@ -320,16 +294,7 @@ void AsmConstWalker::visitCall(Call* curr) { auto* value = arg->cast<Const>(); int64_t address = value->value.getInteger(); auto code = stringTracker.codeForConstAddr(address); - createAsmConst(address, code, sig, importName); -} - -Proxying AsmConstWalker::proxyType(Name name) { - if (name.hasSubstring("_sync_on_main_thread")) { - return Proxying::Sync; - } else if (name.hasSubstring("_async_on_main_thread")) { - return Proxying::Async; - } - return Proxying::None; + createAsmConst(address, code); } void AsmConstWalker::process() { @@ -340,35 +305,21 @@ void AsmConstWalker::process() { addImports(); } -void AsmConstWalker::createAsmConst(uint64_t id, - std::string code, - Signature sig, - Name name) { +void AsmConstWalker::createAsmConst(uint64_t id, std::string code) { AsmConst asmConst; asmConst.id = id; asmConst.code = code; - asmConst.sigs.insert(sig); - asmConst.proxy = proxyType(name); asmConsts.push_back(asmConst); } -Signature AsmConstWalker::asmConstSig(Signature baseSig) { - assert(baseSig.params.size() >= 1); - // Omit the signature of the "code" parameter, taken as a string, as the - // first argument - return Signature( - Type(std::vector<Type>(baseSig.params.begin() + 1, baseSig.params.end())), - baseSig.results); -} - void AsmConstWalker::addImports() { for (auto& import : queuedImports) { wasm.addFunction(import.release()); } } -static AsmConstWalker fixEmAsmConstsAndReturnWalker(Module& wasm, - bool minimizeWasmChanges) { +static AsmConstWalker findEmAsmConstsAndReturnWalker(Module& wasm, + bool minimizeWasmChanges) { AsmConstWalker walker(wasm, minimizeWasmChanges); walker.process(); return walker; @@ -407,7 +358,7 @@ struct EmJsWalker : public PostWalker<EmJsWalker> { } }; -EmJsWalker fixEmJsFuncsAndReturnWalker(Module& wasm) { +EmJsWalker findEmJsFuncsAndReturnWalker(Module& wasm) { EmJsWalker walker(wasm); walker.walkModule(&wasm); @@ -418,20 +369,6 @@ EmJsWalker fixEmJsFuncsAndReturnWalker(Module& wasm) { return walker; } -void printSignatures(std::ostream& o, const std::set<Signature>& c) { - o << "["; - bool first = true; - for (auto& sig : c) { - if (first) { - first = false; - } else { - o << ","; - } - o << '"' << getSig(sig.results, sig.params) << '"'; - } - o << "]"; -} - std::string EmscriptenGlueGenerator::generateEmscriptenMetadata() { bool commaFirst; auto nextElement = [&commaFirst]() { @@ -447,7 +384,7 @@ std::string EmscriptenGlueGenerator::generateEmscriptenMetadata() { meta << "{\n"; AsmConstWalker emAsmWalker = - fixEmAsmConstsAndReturnWalker(wasm, minimizeWasmChanges); + findEmAsmConstsAndReturnWalker(wasm, minimizeWasmChanges); // print commaFirst = true; @@ -455,16 +392,12 @@ std::string EmscriptenGlueGenerator::generateEmscriptenMetadata() { meta << " \"asmConsts\": {"; for (auto& asmConst : emAsmWalker.asmConsts) { meta << nextElement(); - meta << '"' << asmConst.id << "\": [\"" << asmConst.code << "\", "; - printSignatures(meta, asmConst.sigs); - meta << ", [\"" << proxyingSuffix(asmConst.proxy) << "\"]"; - - meta << "]"; + meta << '"' << asmConst.id << "\": \"" << asmConst.code << "\""; } meta << "\n },\n"; } - EmJsWalker emJsWalker = fixEmJsFuncsAndReturnWalker(wasm); + EmJsWalker emJsWalker = findEmJsFuncsAndReturnWalker(wasm); if (!emJsWalker.codeByName.empty()) { meta << " \"emJsFuncs\": {"; commaFirst = true; diff --git a/test/lit/wasm-emscripten-finalize/passive-pic.wat b/test/lit/wasm-emscripten-finalize/passive-pic.wat index e9af5b1d9..14e6842a3 100644 --- a/test/lit/wasm-emscripten-finalize/passive-pic.wat +++ b/test/lit/wasm-emscripten-finalize/passive-pic.wat @@ -4,7 +4,7 @@ ;; RUN: wasm-emscripten-finalize --enable-bulk-memory %s -o out.wasm | filecheck %s ;; CHECK: "asmConsts": { -;; CHECK: "3": ["hello", ["iii"], [""]] +;; CHECK: "3": "hello" ;; CHECK: }, (module diff --git a/test/lld/em_asm.wat.mem.out b/test/lld/em_asm.wat.mem.out index 8a24bb270..ca85963ad 100644 --- a/test/lld/em_asm.wat.mem.out +++ b/test/lld/em_asm.wat.mem.out @@ -68,9 +68,9 @@ --BEGIN METADATA -- { "asmConsts": { - "568": ["{ Module.print(\"Hello world\"); }", ["iii"], [""]], - "602": ["{ return $0 + $1; }", ["iii"], [""]], - "625": ["{ Module.print(\"Got \" + $0); }", ["iii"], [""]] + "568": "{ Module.print(\"Hello world\"); }", + "602": "{ return $0 + $1; }", + "625": "{ Module.print(\"Got \" + $0); }" }, "tableSize": 1, "declares": [ diff --git a/test/lld/em_asm.wat.out b/test/lld/em_asm.wat.out index f7655985c..487f51c14 100644 --- a/test/lld/em_asm.wat.out +++ b/test/lld/em_asm.wat.out @@ -69,9 +69,9 @@ --BEGIN METADATA -- { "asmConsts": { - "568": ["{ Module.print(\"Hello world\"); }", ["iii"], [""]], - "602": ["{ return $0 + $1; }", ["iii"], [""]], - "625": ["{ Module.print(\"Got \" + $0); }", ["iii"], [""]] + "568": "{ Module.print(\"Hello world\"); }", + "602": "{ return $0 + $1; }", + "625": "{ Module.print(\"Got \" + $0); }" }, "tableSize": 1, "declares": [ diff --git a/test/lld/em_asm64.wat.out b/test/lld/em_asm64.wat.out index 35425a600..13a279cd4 100644 --- a/test/lld/em_asm64.wat.out +++ b/test/lld/em_asm64.wat.out @@ -69,9 +69,9 @@ --BEGIN METADATA -- { "asmConsts": { - "568": ["{ Module.print(\"Hello world\"); }", ["ijj"], [""]], - "602": ["{ return $0 + $1; }", ["ijj"], [""]], - "625": ["{ Module.print(\"Got \" + $0); }", ["ijj"], [""]] + "568": "{ Module.print(\"Hello world\"); }", + "602": "{ return $0 + $1; }", + "625": "{ Module.print(\"Got \" + $0); }" }, "tableSize": 1, "declares": [ diff --git a/test/lld/em_asm_O0.wat.out b/test/lld/em_asm_O0.wat.out index 48c9158bc..be664978c 100644 --- a/test/lld/em_asm_O0.wat.out +++ b/test/lld/em_asm_O0.wat.out @@ -94,9 +94,9 @@ --BEGIN METADATA -- { "asmConsts": { - "568": ["{ Module.print(\"Hello world\"); }", ["iii"], [""]], - "601": ["{ return $0 + $1; }", ["iii"], [""]], - "621": ["{ Module.print(\"Got \" + $0); }", ["iii"], [""]] + "568": "{ Module.print(\"Hello world\"); }", + "601": "{ return $0 + $1; }", + "621": "{ Module.print(\"Got \" + $0); }" }, "tableSize": 1, "declares": [ diff --git a/test/lld/em_asm_main_thread.wat.out b/test/lld/em_asm_main_thread.wat.out index 55e992a22..9609cef56 100644 --- a/test/lld/em_asm_main_thread.wat.out +++ b/test/lld/em_asm_main_thread.wat.out @@ -194,9 +194,9 @@ --BEGIN METADATA -- { "asmConsts": { - "568": ["{ Module.print(\"Hello world\"); }", ["iii"], ["sync_on_main_thread_"]], - "601": ["{ return $0 + $1; }", ["iii"], ["sync_on_main_thread_"]], - "621": ["{ Module.print(\"Got \" + $0); }", ["iii"], ["sync_on_main_thread_"]] + "568": "{ Module.print(\"Hello world\"); }", + "601": "{ return $0 + $1; }", + "621": "{ Module.print(\"Got \" + $0); }" }, "tableSize": 1, "declares": [ diff --git a/test/lld/em_asm_shared.wat.out b/test/lld/em_asm_shared.wat.out index c9872a503..fd143a016 100644 --- a/test/lld/em_asm_shared.wat.out +++ b/test/lld/em_asm_shared.wat.out @@ -95,9 +95,9 @@ --BEGIN METADATA -- { "asmConsts": { - "0": ["{ Module.print(\"Hello world\"); }", ["iii"], [""]], - "34": ["{ return $0 + $1; }", ["iii"], [""]], - "57": ["{ Module.print(\"Got \" + $0); }", ["iii"], [""]] + "0": "{ Module.print(\"Hello world\"); }", + "34": "{ return $0 + $1; }", + "57": "{ Module.print(\"Got \" + $0); }" }, "tableSize": 0, "declares": [ |