Skip to content

Conversation

@boomanaiden154
Copy link
Contributor

No tests modified as there are none that explicitly stop at
DynAllocaExpander, and we do not have enough of a pipeline to run those
yet anyways.

Created using spr 1.3.7
@llvmbot
Copy link
Member

llvmbot commented Nov 12, 2025

@llvm/pr-subscribers-backend-x86

Author: Aiden Grossman (boomanaiden154)

Changes

No tests modified as there are none that explicitly stop at
DynAllocaExpander, and we do not have enough of a pipeline to run those
yet anyways.


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

4 Files Affected:

  • (modified) llvm/lib/Target/X86/X86.h (+8-2)
  • (modified) llvm/lib/Target/X86/X86DynAllocaExpander.cpp (+33-9)
  • (modified) llvm/lib/Target/X86/X86PassRegistry.def (+1-1)
  • (modified) llvm/lib/Target/X86/X86TargetMachine.cpp (+2-2)
diff --git a/llvm/lib/Target/X86/X86.h b/llvm/lib/Target/X86/X86.h
index 2b83d575ace91..17acf0415540a 100644
--- a/llvm/lib/Target/X86/X86.h
+++ b/llvm/lib/Target/X86/X86.h
@@ -84,7 +84,13 @@ FunctionPass *createX86AvoidStoreForwardingBlocks();
 FunctionPass *createX86FlagsCopyLoweringPass();
 
 /// Return a pass that expands DynAlloca pseudo-instructions.
-FunctionPass *createX86DynAllocaExpander();
+class X86DynAllocaExpanderPass : public PassInfoMixin<X86DynAllocaExpanderPass> {
+public:
+  PreservedAnalyses run(MachineFunction &MF,
+                        MachineFunctionAnalysisManager &MFAM);
+};
+
+FunctionPass *createX86DynAllocaExpanderLegacyPass();
 
 /// Return a pass that config the tile registers.
 FunctionPass *createX86TileConfigPass();
@@ -237,7 +243,7 @@ void initializeX86CallFrameOptimizationPass(PassRegistry &);
 void initializeX86CmovConverterPassPass(PassRegistry &);
 void initializeX86DAGToDAGISelLegacyPass(PassRegistry &);
 void initializeX86DomainReassignmentPass(PassRegistry &);
-void initializeX86DynAllocaExpanderPass(PassRegistry &);
+void initializeX86DynAllocaExpanderLegacyPass(PassRegistry &);
 void initializeX86ExecutionDomainFixPass(PassRegistry &);
 void initializeX86ExpandPseudoPass(PassRegistry &);
 void initializeX86FastPreTileConfigPass(PassRegistry &);
diff --git a/llvm/lib/Target/X86/X86DynAllocaExpander.cpp b/llvm/lib/Target/X86/X86DynAllocaExpander.cpp
index c2a06efd4d46e..10f46f71bbbbd 100644
--- a/llvm/lib/Target/X86/X86DynAllocaExpander.cpp
+++ b/llvm/lib/Target/X86/X86DynAllocaExpander.cpp
@@ -20,22 +20,22 @@
 #include "X86Subtarget.h"
 #include "llvm/ADT/MapVector.h"
 #include "llvm/ADT/PostOrderIterator.h"
+#include "llvm/CodeGen/MachineFunctionAnalysisManager.h"
 #include "llvm/CodeGen/MachineFunctionPass.h"
 #include "llvm/CodeGen/MachineInstrBuilder.h"
 #include "llvm/CodeGen/MachineRegisterInfo.h"
 #include "llvm/CodeGen/Passes.h"
 #include "llvm/CodeGen/TargetInstrInfo.h"
+#include "llvm/IR/Analysis.h"
 #include "llvm/IR/Function.h"
 
 using namespace llvm;
 
 namespace {
 
-class X86DynAllocaExpander : public MachineFunctionPass {
+class X86DynAllocaExpander {
 public:
-  X86DynAllocaExpander() : MachineFunctionPass(ID) {}
-
-  bool runOnMachineFunction(MachineFunction &MF) override;
+  bool run(MachineFunction &MF);
 
 private:
   /// Strategies for lowering a DynAlloca.
@@ -61,22 +61,30 @@ class X86DynAllocaExpander : public MachineFunctionPass {
   unsigned SlotSize = 0;
   int64_t StackProbeSize = 0;
   bool NoStackArgProbe = false;
+};
+
+class X86DynAllocaExpanderLegacy : public MachineFunctionPass {
+public:
+  X86DynAllocaExpanderLegacy() : MachineFunctionPass(ID) {}
+
+  bool runOnMachineFunction(MachineFunction &MF) override;
 
+private:
   StringRef getPassName() const override { return "X86 DynAlloca Expander"; }
 
 public:
   static char ID;
 };
 
-char X86DynAllocaExpander::ID = 0;
+char X86DynAllocaExpanderLegacy::ID = 0;
 
 } // end anonymous namespace
 
-INITIALIZE_PASS(X86DynAllocaExpander, "x86-dyn-alloca-expander",
+INITIALIZE_PASS(X86DynAllocaExpanderLegacy, "x86-dyn-alloca-expander",
                 "X86 DynAlloca Expander", false, false)
 
-FunctionPass *llvm::createX86DynAllocaExpander() {
-  return new X86DynAllocaExpander();
+FunctionPass *llvm::createX86DynAllocaExpanderLegacyPass() {
+  return new X86DynAllocaExpanderLegacy();
 }
 
 /// Return the allocation amount for a DynAlloca instruction, or -1 if unknown.
@@ -277,7 +285,7 @@ void X86DynAllocaExpander::lower(MachineInstr *MI, Lowering L) {
       AmountDef->eraseFromParent();
 }
 
-bool X86DynAllocaExpander::runOnMachineFunction(MachineFunction &MF) {
+bool X86DynAllocaExpander::run(MachineFunction &MF) {
   if (!MF.getInfo<X86MachineFunctionInfo>()->hasDynAlloca())
     return false;
 
@@ -299,3 +307,19 @@ bool X86DynAllocaExpander::runOnMachineFunction(MachineFunction &MF) {
 
   return true;
 }
+
+bool X86DynAllocaExpanderLegacy::runOnMachineFunction(MachineFunction &MF) {
+  return X86DynAllocaExpander().run(MF);
+}
+
+PreservedAnalyses
+X86DynAllocaExpanderPass::run(MachineFunction &MF,
+                              MachineFunctionAnalysisManager &MFAM) {
+  bool Changed = X86DynAllocaExpander().run(MF);
+  if (!Changed)
+    return PreservedAnalyses::all();
+
+  PreservedAnalyses PA = PreservedAnalyses::none();
+  PA.preserveSet<CFGAnalyses>();
+  return PA;
+}
diff --git a/llvm/lib/Target/X86/X86PassRegistry.def b/llvm/lib/Target/X86/X86PassRegistry.def
index 52463622026d7..0d7095b18daa8 100644
--- a/llvm/lib/Target/X86/X86PassRegistry.def
+++ b/llvm/lib/Target/X86/X86PassRegistry.def
@@ -30,6 +30,7 @@ DUMMY_FUNCTION_PASS("x86-winehstate", WinEHStatePass())
 #define MACHINE_FUNCTION_PASS(NAME, CREATE_PASS)
 #endif
 MACHINE_FUNCTION_PASS("x86-avoid-trailing-call", X86AvoidTrailingCallPass())
+MACHINE_FUNCTION_PASS("x86-dyn-alloca-expander", X86DynAllocaExpanderPass())
 MACHINE_FUNCTION_PASS("x86-isel", X86ISelDAGToDAGPass(*this))
 #undef MACHINE_FUNCTION_PASS
 
@@ -42,7 +43,6 @@ DUMMY_MACHINE_FUNCTION_PASS("x86-cmov-conversion", X86CmovConverterPass())
 DUMMY_MACHINE_FUNCTION_PASS("x86-codege", FPS())
 DUMMY_MACHINE_FUNCTION_PASS("x86-compress-evex", CompressEVEXPass())
 DUMMY_MACHINE_FUNCTION_PASS("x86-domain-reassignment", X86DomainReassignment())
-DUMMY_MACHINE_FUNCTION_PASS("x86-dyn-alloca-expander", X86DynAllocaExpander())
 DUMMY_MACHINE_FUNCTION_PASS("x86-execution-domain-fix", X86ExecutionDomainFix())
 DUMMY_MACHINE_FUNCTION_PASS("fastpretileconfig", X86FastPreTileConfig())
 DUMMY_MACHINE_FUNCTION_PASS("fasttileconfig", X86FastTileConfig())
diff --git a/llvm/lib/Target/X86/X86TargetMachine.cpp b/llvm/lib/Target/X86/X86TargetMachine.cpp
index d4ad98af9b30c..c1214149dfa1d 100644
--- a/llvm/lib/Target/X86/X86TargetMachine.cpp
+++ b/llvm/lib/Target/X86/X86TargetMachine.cpp
@@ -104,7 +104,7 @@ extern "C" LLVM_C_ABI void LLVMInitializeX86Target() {
   initializeX86AsmPrinterPass(PR);
   initializeX86FixupInstTuningPassPass(PR);
   initializeX86FixupVectorConstantsPassPass(PR);
-  initializeX86DynAllocaExpanderPass(PR);
+  initializeX86DynAllocaExpanderLegacyPass(PR);
   initializeX86SuppressAPXForRelocationPassPass(PR);
   initializeX86WinEHUnwindV2Pass(PR);
 }
@@ -516,7 +516,7 @@ void X86PassConfig::addPreRegAlloc() {
 
   addPass(createX86SpeculativeLoadHardeningPass());
   addPass(createX86FlagsCopyLoweringPass());
-  addPass(createX86DynAllocaExpander());
+  addPass(createX86DynAllocaExpanderLegacyPass());
 
   if (getOptLevel() != CodeGenOptLevel::None)
     addPass(createX86PreTileConfigPass());

boomanaiden154 added a commit to boomanaiden154/llvm-project that referenced this pull request Nov 12, 2025
No tests modified as there are none that explicitly stop at
DynAllocaExpander, and we do not have enough of a pipeline to run those
yet anyways.

Pull Request: llvm#167740
@github-actions
Copy link

github-actions bot commented Nov 12, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

Created using spr 1.3.7
@boomanaiden154 boomanaiden154 merged commit 0c0c1a7 into main Nov 12, 2025
9 of 10 checks passed
@boomanaiden154 boomanaiden154 deleted the users/boomanaiden154/x86newpm-port-dynallocaexpander-to-new-pm branch November 12, 2025 20:00
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Nov 12, 2025
No tests modified as there are none that explicitly stop at
DynAllocaExpander, and we do not have enough of a pipeline to run those
yet anyways.

Reviewers: phoebewang, RKSimon, paperchalice, arsenm

Reviewed By: arsenm

Pull Request: llvm/llvm-project#167740
git-crd pushed a commit to git-crd/crd-llvm-project that referenced this pull request Nov 13, 2025
No tests modified as there are none that explicitly stop at
DynAllocaExpander, and we do not have enough of a pipeline to run those
yet anyways.

Reviewers: phoebewang, RKSimon, paperchalice, arsenm

Reviewed By: arsenm

Pull Request: llvm#167740
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.

4 participants