Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WebAssembly] Use RefTypeMem2Local instead of Mem2Reg #83196

Merged
merged 2 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llvm/include/llvm/Transforms/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ extern char &LCSSAID;
// %Y = load i32* %X
// ret i32 %Y
//
FunctionPass *createPromoteMemoryToRegisterPass(bool IsForced = false);
FunctionPass *createPromoteMemoryToRegisterPass();

//===----------------------------------------------------------------------===//
//
Expand Down
5 changes: 3 additions & 2 deletions llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down
12 changes: 4 additions & 8 deletions llvm/lib/Transforms/Utils/Mem2Reg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/WebAssembly/ref-type-mem2local.ll
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
Loading