diff --git a/llvm/include/llvm/Transforms/Utils.h b/llvm/include/llvm/Transforms/Utils.h index 0fa6de3f67130a..c6a6a05f3fddb4 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 d088c7d925ddf0..cb6e9eef365dd4 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp @@ -487,8 +487,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 fbc6dd7613deb8..5ad7aeb463ecb2 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().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 a38243ca218cc1..4b32a0945e2e13 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"