diff options
author | Heejin Ahn <aheejin@gmail.com> | 2024-03-05 19:54:41 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-05 19:54:41 -0800 |
commit | 403b9cf1bb29d550c419ac5ecd2f764bf5cfa3c0 (patch) | |
tree | 277175430f42f8f9c9cd148dcc7221b54ab42798 | |
parent | ae709c192953be2af61f47e91a3ec9f8d5ffb027 (diff) | |
download | llvm-403b9cf1bb29d550c419ac5ecd2f764bf5cfa3c0.zip llvm-403b9cf1bb29d550c419ac5ecd2f764bf5cfa3c0.tar.gz llvm-403b9cf1bb29d550c419ac5ecd2f764bf5cfa3c0.tar.bz2 |
[WebAssembly] Use RefTypeMem2Local instead of Mem2Reg (#83196)
When reference-types feature is enabled, forcing mem2reg unconditionally
even in `-O0` has some problems described in #81575. This uses
RefTypeMem2Local pass added in #81965 instead. This also removes
`IsForced` parameter added in
https://github.com/llvm/llvm-project/commit/890146b19206827bc48ee1ae1dc1534ff2ff18d7
given that we don't need it anymore.
This may still hurt debug info related to reference type variables a
little during the backend transformation given that they are not stored
in memory anymore, but reference type variables are presumably rare and
it would be still a lot less damage than forcing mem2reg on the whole
program. Also this fixes the EH problem described in #81575.
Fixes #81575.
-rw-r--r-- | llvm/include/llvm/Transforms/Utils.h | 2 | ||||
-rw-r--r-- | llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp | 5 | ||||
-rw-r--r-- | llvm/lib/Transforms/Utils/Mem2Reg.cpp | 12 | ||||
-rw-r--r-- | llvm/test/CodeGen/WebAssembly/ref-type-mem2local.ll | 2 |
4 files changed, 9 insertions, 12 deletions
diff --git a/llvm/include/llvm/Transforms/Utils.h b/llvm/include/llvm/Transforms/Utils.h index 0fa6de3..c6a6a05 100644 --- a/llvm/include/llvm/Transforms/Utils.h +++ b/llvm/include/llvm/Transforms/Utils.h @@ -70,7 +70,7 @@ extern char &LCSSAID; // %Y = load i32* %X // ret i32 %Y // -FunctionPass *createPromoteMemoryToRegisterPass(bool IsForced = false); +FunctionPass *createPromoteMemoryToRegisterPass(); //===----------------------------------------------------------------------===// // diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp index 4d4cae1..70685b2 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp @@ -478,8 +478,9 @@ void WebAssemblyPassConfig::addISelPrepare() { WasmTM->getSubtargetImpl(std::string(WasmTM->getTargetCPU()), std::string(WasmTM->getTargetFeatureString())); if (Subtarget->hasReferenceTypes()) { - // We need to remove allocas for reference types - addPass(createPromoteMemoryToRegisterPass(true)); + // We need to move reference type allocas to WASM_ADDRESS_SPACE_VAR so that + // loads and stores are promoted to local.gets/local.sets. + addPass(createWebAssemblyRefTypeMem2Local()); } // Lower atomics and TLS if necessary addPass(new CoalesceFeaturesAndStripAtomics(&getWebAssemblyTargetMachine())); diff --git a/llvm/lib/Transforms/Utils/Mem2Reg.cpp b/llvm/lib/Transforms/Utils/Mem2Reg.cpp index fbc6dd7..5ad7aeb 100644 --- a/llvm/lib/Transforms/Utils/Mem2Reg.cpp +++ b/llvm/lib/Transforms/Utils/Mem2Reg.cpp @@ -74,19 +74,15 @@ namespace { struct PromoteLegacyPass : public FunctionPass { // Pass identification, replacement for typeid static char ID; - bool ForcePass; /// If true, forces pass to execute, instead of skipping. - PromoteLegacyPass() : FunctionPass(ID), ForcePass(false) { - initializePromoteLegacyPassPass(*PassRegistry::getPassRegistry()); - } - PromoteLegacyPass(bool IsForced) : FunctionPass(ID), ForcePass(IsForced) { + PromoteLegacyPass() : FunctionPass(ID) { initializePromoteLegacyPassPass(*PassRegistry::getPassRegistry()); } // runOnFunction - To run this pass, first we calculate the alloca // instructions that are safe for promotion, then we promote each one. bool runOnFunction(Function &F) override { - if (!ForcePass && skipFunction(F)) + if (skipFunction(F)) return false; DominatorTree &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree(); @@ -115,6 +111,6 @@ INITIALIZE_PASS_END(PromoteLegacyPass, "mem2reg", "Promote Memory to Register", false, false) // createPromoteMemoryToRegister - Provide an entry point to create this pass. -FunctionPass *llvm::createPromoteMemoryToRegisterPass(bool IsForced) { - return new PromoteLegacyPass(IsForced); +FunctionPass *llvm::createPromoteMemoryToRegisterPass() { + return new PromoteLegacyPass(); } diff --git a/llvm/test/CodeGen/WebAssembly/ref-type-mem2local.ll b/llvm/test/CodeGen/WebAssembly/ref-type-mem2local.ll index a38243c..4b32a09 100644 --- a/llvm/test/CodeGen/WebAssembly/ref-type-mem2local.ll +++ b/llvm/test/CodeGen/WebAssembly/ref-type-mem2local.ll @@ -1,4 +1,4 @@ -; RUN: opt < %s -wasm-ref-type-mem2local -S | FileCheck %s +; RUN: llc < %s -mattr=+reference-types -stop-after=wasm-ref-type-mem2local | FileCheck %s target triple = "wasm32-unknown-unknown" |