[llvm] [WebAssembly] Tidy up a switch-case in CFGStackify (NFC) (PR #107360)

Heejin Ahn via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 5 00:31:09 PDT 2024


https://github.com/aheejin created https://github.com/llvm/llvm-project/pull/107360

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.

>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] [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;
       }
     }



More information about the llvm-commits mailing list