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

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


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-webassembly

Author: Heejin Ahn (aheejin)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/107360.diff


1 Files Affected:

- (modified) llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp (+9-11) 


``````````diff
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;
       }
     }

``````````

</details>


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


More information about the llvm-commits mailing list