[llvm] 5337314 - [WebAssembly] Port WebAssemblySetP2AlignOperandsPass

via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 16 16:45:45 PDT 2026


Author: Aiden Grossman
Date: 2026-07-16T16:45:40-07:00
New Revision: 5337314b4bea4be5e86396eb21e59f4d123af175

URL: https://github.com/llvm/llvm-project/commit/5337314b4bea4be5e86396eb21e59f4d123af175
DIFF: https://github.com/llvm/llvm-project/commit/5337314b4bea4be5e86396eb21e59f4d123af175.diff

LOG: [WebAssembly] Port WebAssemblySetP2AlignOperandsPass

Standard NewPM pass porting.

Reviewers: dschuff, sbc100, aheejin

Pull Request: https://github.com/llvm/llvm-project/pull/209871

Added: 
    

Modified: 
    llvm/lib/Target/WebAssembly/WebAssembly.h
    llvm/lib/Target/WebAssembly/WebAssemblyCodeGenPassBuilder.cpp
    llvm/lib/Target/WebAssembly/WebAssemblyPassRegistry.def
    llvm/lib/Target/WebAssembly/WebAssemblySetP2AlignOperands.cpp
    llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/WebAssembly/WebAssembly.h b/llvm/lib/Target/WebAssembly/WebAssembly.h
index 79811ba19fbdb..f838481340c38 100644
--- a/llvm/lib/Target/WebAssembly/WebAssembly.h
+++ b/llvm/lib/Target/WebAssembly/WebAssembly.h
@@ -132,7 +132,15 @@ class WebAssemblyArgumentMovePass
 };
 
 FunctionPass *createWebAssemblyArgumentMoveLegacyPass();
-FunctionPass *createWebAssemblySetP2AlignOperands();
+
+class WebAssemblySetP2AlignOperandsPass
+    : public RequiredPassInfoMixin<WebAssemblySetP2AlignOperandsPass> {
+public:
+  PreservedAnalyses run(MachineFunction &MF,
+                        MachineFunctionAnalysisManager &MFAM);
+};
+
+FunctionPass *createWebAssemblySetP2AlignOperandsLegacyPass();
 FunctionPass *createWebAssemblyCleanCodeAfterTrap();
 
 // Late passes.
@@ -199,7 +207,7 @@ void initializeWebAssemblyRegColoringPass(PassRegistry &);
 void initializeWebAssemblyRegNumberingPass(PassRegistry &);
 void initializeWebAssemblyRegStackifyPass(PassRegistry &);
 void initializeWebAssemblyReplacePhysRegsPass(PassRegistry &);
-void initializeWebAssemblySetP2AlignOperandsPass(PassRegistry &);
+void initializeWebAssemblySetP2AlignOperandsLegacyPass(PassRegistry &);
 void initializeWebAssemblyCoalesceFeaturesAndStripAtomicsLegacyPass(
     PassRegistry &);
 

diff  --git a/llvm/lib/Target/WebAssembly/WebAssemblyCodeGenPassBuilder.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyCodeGenPassBuilder.cpp
index 6eb7bf5d414fe..8cc6e25999a0f 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyCodeGenPassBuilder.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyCodeGenPassBuilder.cpp
@@ -155,7 +155,7 @@ Error WebAssemblyCodeGenPassBuilder::addInstSelector(
   // Set the p2align operands. This information is present during ISel, however
   // it's inconvenient to collect. Collect it now, and update the immediate
   // operands.
-  // TODO(boomanaiden154): WebAssemblySetP2AlignOperands
+  addMachineFunctionPass(WebAssemblySetP2AlignOperandsPass(), PMW);
 
   // Eliminate range checks and add default targets to br_table instructions.
   // TODO(boomanaiden154): WebAssemblyFixBrTableDefaults

diff  --git a/llvm/lib/Target/WebAssembly/WebAssemblyPassRegistry.def b/llvm/lib/Target/WebAssembly/WebAssemblyPassRegistry.def
index 7a369c89e55bb..aeb4f4be02bbc 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyPassRegistry.def
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyPassRegistry.def
@@ -38,4 +38,6 @@ MACHINE_FUNCTION_PASS("wasm-fix-irreducible-control-flow",
                       WebAssemblyFixIrreducibleControlFlowPass())
 MACHINE_FUNCTION_PASS("wasm-nullify-dbg-value-lists",
                       WebAssemblyNullifyDebugValueListsPass())
+MACHINE_FUNCTION_PASS("wasm-set-p2align-operands",
+                      WebAssemblySetP2AlignOperandsPass())
 #undef MACHINE_FUNCTION_PASS

diff  --git a/llvm/lib/Target/WebAssembly/WebAssemblySetP2AlignOperands.cpp b/llvm/lib/Target/WebAssembly/WebAssemblySetP2AlignOperands.cpp
index d52e1dcfa8493..2cc40dd6b0e3f 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblySetP2AlignOperands.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblySetP2AlignOperands.cpp
@@ -15,8 +15,11 @@
 #include "WebAssembly.h"
 #include "WebAssemblyInstrInfo.h"
 #include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
+#include "llvm/CodeGen/MachineFunctionAnalysisManager.h"
 #include "llvm/CodeGen/MachineMemOperand.h"
+#include "llvm/CodeGen/MachinePassManager.h"
 #include "llvm/CodeGen/Passes.h"
+#include "llvm/IR/Analysis.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/raw_ostream.h"
 using namespace llvm;
@@ -24,10 +27,10 @@ using namespace llvm;
 #define DEBUG_TYPE "wasm-set-p2align-operands"
 
 namespace {
-class WebAssemblySetP2AlignOperands final : public MachineFunctionPass {
+class WebAssemblySetP2AlignOperandsLegacy final : public MachineFunctionPass {
 public:
   static char ID; // Pass identification, replacement for typeid
-  WebAssemblySetP2AlignOperands() : MachineFunctionPass(ID) {}
+  WebAssemblySetP2AlignOperandsLegacy() : MachineFunctionPass(ID) {}
 
   StringRef getPassName() const override {
     return "WebAssembly Set p2align Operands";
@@ -44,13 +47,13 @@ class WebAssemblySetP2AlignOperands final : public MachineFunctionPass {
 };
 } // end anonymous namespace
 
-char WebAssemblySetP2AlignOperands::ID = 0;
-INITIALIZE_PASS(WebAssemblySetP2AlignOperands, DEBUG_TYPE,
+char WebAssemblySetP2AlignOperandsLegacy::ID = 0;
+INITIALIZE_PASS(WebAssemblySetP2AlignOperandsLegacy, DEBUG_TYPE,
                 "Set the p2align operands for WebAssembly loads and stores",
                 false, false)
 
-FunctionPass *llvm::createWebAssemblySetP2AlignOperands() {
-  return new WebAssemblySetP2AlignOperands();
+FunctionPass *llvm::createWebAssemblySetP2AlignOperandsLegacyPass() {
+  return new WebAssemblySetP2AlignOperandsLegacy();
 }
 
 static void rewriteP2Align(MachineInstr &MI, unsigned OperandNo) {
@@ -73,7 +76,7 @@ static void rewriteP2Align(MachineInstr &MI, unsigned OperandNo) {
   MI.getOperand(OperandNo).setImm(P2Align);
 }
 
-bool WebAssemblySetP2AlignOperands::runOnMachineFunction(MachineFunction &MF) {
+static bool setP2AlignOperands(MachineFunction &MF) {
   LLVM_DEBUG({
     dbgs() << "********** Set p2align Operands **********\n"
            << "********** Function: " << MF.getName() << '\n';
@@ -94,3 +97,16 @@ bool WebAssemblySetP2AlignOperands::runOnMachineFunction(MachineFunction &MF) {
 
   return Changed;
 }
+
+bool WebAssemblySetP2AlignOperandsLegacy::runOnMachineFunction(
+    MachineFunction &MF) {
+  return setP2AlignOperands(MF);
+}
+
+PreservedAnalyses
+WebAssemblySetP2AlignOperandsPass::run(MachineFunction &MF,
+                                       MachineFunctionAnalysisManager &MFAM) {
+  return setP2AlignOperands(MF) ? getMachineFunctionPassPreservedAnalyses()
+                                      .preserveSet<CFGAnalyses>()
+                                : PreservedAnalyses::all();
+}

diff  --git a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
index e4d1564993ded..b296e71f38ecb 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
@@ -101,7 +101,7 @@ LLVMInitializeWebAssemblyTarget() {
   initializeWebAssemblyRefTypeMem2LocalLegacyPass(PR);
   initializeWebAssemblyArgumentMoveLegacyPass(PR);
   initializeWebAssemblyAsmPrinterPass(PR);
-  initializeWebAssemblySetP2AlignOperandsPass(PR);
+  initializeWebAssemblySetP2AlignOperandsLegacyPass(PR);
   initializeWebAssemblyReplacePhysRegsPass(PR);
   initializeWebAssemblyOptimizeLiveIntervalsPass(PR);
   initializeWebAssemblyMemIntrinsicResultsPass(PR);
@@ -387,7 +387,7 @@ bool WebAssemblyPassConfig::addInstSelector() {
   // Set the p2align operands. This information is present during ISel, however
   // it's inconvenient to collect. Collect it now, and update the immediate
   // operands.
-  addPass(createWebAssemblySetP2AlignOperands());
+  addPass(createWebAssemblySetP2AlignOperandsLegacyPass());
 
   // Eliminate range checks and add default targets to br_table instructions.
   addPass(createWebAssemblyFixBrTableDefaults());
@@ -547,7 +547,7 @@ bool WebAssemblyPassConfig::addGlobalInstructionSelect() {
   // We insert only if ISelDAG won't insert these at a later point.
   if (isGlobalISelAbortEnabled()) {
     addPass(createWebAssemblyArgumentMoveLegacyPass());
-    addPass(createWebAssemblySetP2AlignOperands());
+    addPass(createWebAssemblySetP2AlignOperandsLegacyPass());
     addPass(createWebAssemblyFixBrTableDefaults());
     addPass(createWebAssemblyCleanCodeAfterTrap());
   }


        


More information about the llvm-commits mailing list