Skip to content

[WebAssembly] Simplify a switch-case in CFGStackify (NFC) #107360

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

Merged
merged 2 commits into from
Sep 5, 2024

Conversation

aheejin
Copy link
Member

@aheejin aheejin commented Sep 5, 2024

This merges some cases 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.

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 llvm#107182 we can do it.
@llvmbot
Copy link
Member

llvmbot commented Sep 5, 2024

@llvm/pr-subscribers-backend-webassembly

Author: Heejin Ahn (aheejin)

Changes

This merges some cases 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 --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;
       }
     }

@aheejin aheejin changed the title [WebAssembly] Tidy up a switch-case in CFGStackify (NFC) [WebAssembly] Simplify a switch-case in CFGStackify (NFC) Sep 5, 2024
defm RETHROW : NRI<(outs), (ins i32imm:$depth), [], "rethrow \t$depth", 0x09>;
} // isTerminator = 1, hasCtrlDep = 1, isBarrier = 1
// isTerminator = 1, hasCtrlDep = 1, isBarrier = 1
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drive-by fix

@aheejin aheejin merged commit 0818c28 into llvm:main Sep 5, 2024
8 checks passed
@aheejin aheejin deleted the stackify_case branch September 5, 2024 16:47
aheejin added a commit to aheejin/llvm-project that referenced this pull request Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants