[llvm] [WebAssembly] Simplify a switch-case in CFGStackify (NFC) (PR #107360)
Heejin Ahn via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 5 01:07:55 PDT 2024
https://github.com/aheejin updated https://github.com/llvm/llvm-project/pull/107360
>From 74805efc48d214863636696e49220cac0a6e5d59 Mon Sep 17 00:00:00 2001
From: Heejin Ahn <aheejin at gmail.com>
Date: Thu, 5 Sep 2024 07:27:32 +0000
Subject: [PATCH 1/2] [WebAssembly] Tidy up a switch-case in CFGStackify (NFC)
This merges some `case`s using `[[fallthrough]]`, and make `DELEGATE` as
a separate `case`. (Previously the reason we didn't do that was not to
duplicate the code in `RewriteOperands`. But now that we've extracted it
into a lambda function in #107182 we can do it.
---
.../WebAssembly/WebAssemblyCFGStackify.cpp | 20 +++++++++----------
1 file changed, 9 insertions(+), 11 deletions(-)
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp
index 3362ea5316e452..3cccc57e629fd7 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp
@@ -1681,18 +1681,14 @@ void WebAssemblyCFGStackify::rewriteDepthImmediates(MachineFunction &MF) {
Stack.pop_back();
break;
- case WebAssembly::END_BLOCK:
- Stack.push_back(std::make_pair(&MBB, &MI));
- break;
-
case WebAssembly::END_TRY: {
- // We handle DELEGATE in the default level, because DELEGATE has
- // immediate operands to rewrite.
- Stack.push_back(std::make_pair(&MBB, &MI));
auto *EHPad = TryToEHPad[EndToBegin[&MI]];
EHPadStack.push_back(EHPad);
- break;
+ [[fallthrough]];
}
+ case WebAssembly::END_BLOCK:
+ Stack.push_back(std::make_pair(&MBB, &MI));
+ break;
case WebAssembly::END_LOOP:
Stack.push_back(std::make_pair(EndToBegin[&MI]->getParent(), &MI));
@@ -1707,12 +1703,14 @@ void WebAssemblyCFGStackify::rewriteDepthImmediates(MachineFunction &MF) {
MI.getOperand(0).setImm(getRethrowDepth(Stack, EHPadStack));
break;
+ case WebAssembly::DELEGATE:
+ RewriteOperands(MI);
+ Stack.push_back(std::make_pair(&MBB, &MI));
+ break;
+
default:
if (MI.isTerminator())
RewriteOperands(MI);
-
- if (MI.getOpcode() == WebAssembly::DELEGATE)
- Stack.push_back(std::make_pair(&MBB, &MI));
break;
}
}
>From c0a98f066e9b97537543ac4c43621796fa4823b0 Mon Sep 17 00:00:00 2001
From: Heejin Ahn <aheejin at gmail.com>
Date: Thu, 5 Sep 2024 08:07:40 +0000
Subject: [PATCH 2/2] drive-by fix
---
llvm/lib/Target/WebAssembly/WebAssemblyInstrControl.td | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyInstrControl.td b/llvm/lib/Target/WebAssembly/WebAssemblyInstrControl.td
index dd40015577fd75..05880b89d1fbc6 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyInstrControl.td
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyInstrControl.td
@@ -147,9 +147,9 @@ let isTerminator = 1, hasSideEffects = 1, isBarrier = 1, hasCtrlDep = 1,
// usage gets low enough.
// Rethrowing an exception: rethrow
-let isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in {
+let isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in
defm RETHROW : NRI<(outs), (ins i32imm:$depth), [], "rethrow \t$depth", 0x09>;
-} // isTerminator = 1, hasCtrlDep = 1, isBarrier = 1
+// isTerminator = 1, hasCtrlDep = 1, isBarrier = 1
// The depth argument will be computed in CFGStackify. We set it to 0 here for
// now.
def : Pat<(int_wasm_rethrow), (RETHROW 0)>;
More information about the llvm-commits
mailing list