[llvm-branch-commits] [Mips] Port ExpandPseudo to NewPM (PR #237090)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Oct 29 21:47:44 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-mips
Author: Aiden Grossman (boomanaiden154)
<details>
<summary>Changes</summary>
Standard NewPM pass porting.
---
Full diff: https://github.com/llvm/llvm-project/pull/237090.diff
6 Files Affected:
- (modified) llvm/lib/Target/Mips/Mips.h (+9-1)
- (modified) llvm/lib/Target/Mips/MipsCodeGenPassBuilder.cpp (+1-1)
- (modified) llvm/lib/Target/Mips/MipsExpandPseudo.cpp (+66-66)
- (modified) llvm/lib/Target/Mips/MipsPassRegistry.def (+1)
- (modified) llvm/lib/Target/Mips/MipsTargetMachine.cpp (+1-1)
- (modified) llvm/test/CodeGen/Mips/newpm-pipeline.ll (+3)
``````````diff
diff --git a/llvm/lib/Target/Mips/Mips.h b/llvm/lib/Target/Mips/Mips.h
index cd1d735036489..899efcab5bc8a 100644
--- a/llvm/lib/Target/Mips/Mips.h
+++ b/llvm/lib/Target/Mips/Mips.h
@@ -103,7 +103,15 @@ FunctionPass *createMipsDelaySlotFillerPass();
FunctionPass *createMipsBranchExpansion();
FunctionPass *createMipsConstantIslandPass();
FunctionPass *createMicroMipsSizeReducePass();
-FunctionPass *createMipsExpandPseudoPass();
+
+class MipsExpandPseudoPass
+ : public RequiredPassInfoMixin<MipsExpandPseudoPass> {
+public:
+ PreservedAnalyses run(MachineFunction &MF,
+ MachineFunctionAnalysisManager &MFAM);
+};
+
+FunctionPass *createMipsExpandPseudoLegacyPass();
FunctionPass *createMipsPreLegalizeCombiner();
FunctionPass *createMipsPostLegalizeCombiner(bool IsOptNone);
FunctionPass *createMipsMulMulBugPass();
diff --git a/llvm/lib/Target/Mips/MipsCodeGenPassBuilder.cpp b/llvm/lib/Target/Mips/MipsCodeGenPassBuilder.cpp
index ee1987ca35c96..aac567f10e4c4 100644
--- a/llvm/lib/Target/Mips/MipsCodeGenPassBuilder.cpp
+++ b/llvm/lib/Target/Mips/MipsCodeGenPassBuilder.cpp
@@ -62,7 +62,7 @@ void MipsCodeGenPassBuilder::addPreRegAlloc(PassManagerWrapper &PMW) {
void MipsCodeGenPassBuilder::addPreEmitPass(PassManagerWrapper &PMW) {
// Expand pseudo instructions that are sensitive to register allocation.
- // TODO(boomanaiden154): Add MipsExpandPseudosPass
+ addMachineFunctionPass(MipsExpandPseudoPass(), PMW);
// The microMIPS size reduction pass performs instruction reselection for
// instructions which can be remapped to a 16 bit instruction.
diff --git a/llvm/lib/Target/Mips/MipsExpandPseudo.cpp b/llvm/lib/Target/Mips/MipsExpandPseudo.cpp
index 08b11fef8fa1e..f232d9af5324c 100644
--- a/llvm/lib/Target/Mips/MipsExpandPseudo.cpp
+++ b/llvm/lib/Target/Mips/MipsExpandPseudo.cpp
@@ -22,57 +22,40 @@
#include "MipsInstrInfo.h"
#include "MipsSubtarget.h"
#include "llvm/CodeGen/LivePhysRegs.h"
+#include "llvm/CodeGen/MachineFunctionAnalysisManager.h"
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
+#include "llvm/CodeGen/MachinePassManager.h"
+#include "llvm/IR/Analysis.h"
using namespace llvm;
-#define DEBUG_TYPE "mips-pseudo"
+#define DEBUG_TYPE "mips-expand-pseudo"
namespace {
- class MipsExpandPseudo : public MachineFunctionPass {
- public:
- static char ID;
- MipsExpandPseudo() : MachineFunctionPass(ID) {}
+class MipsExpandPseudoLegacy : public MachineFunctionPass {
+public:
+ static char ID;
+ MipsExpandPseudoLegacy() : MachineFunctionPass(ID) {}
- const MipsInstrInfo *TII;
- const MipsSubtarget *STI;
+ bool runOnMachineFunction(MachineFunction &Fn) override;
- bool runOnMachineFunction(MachineFunction &Fn) override;
-
- MachineFunctionProperties getRequiredProperties() const override {
- return MachineFunctionProperties().setNoVRegs();
- }
-
- StringRef getPassName() const override {
- return "Mips pseudo instruction expansion pass";
- }
+ MachineFunctionProperties getRequiredProperties() const override {
+ return MachineFunctionProperties().setNoVRegs();
+ }
- private:
- bool expandAtomicCmpSwap(MachineBasicBlock &MBB,
- MachineBasicBlock::iterator MBBI,
- MachineBasicBlock::iterator &NextMBBI);
- bool expandAtomicCmpSwapSubword(MachineBasicBlock &MBB,
- MachineBasicBlock::iterator MBBI,
- MachineBasicBlock::iterator &NextMBBI);
-
- bool expandAtomicBinOp(MachineBasicBlock &BB,
- MachineBasicBlock::iterator I,
- MachineBasicBlock::iterator &NMBBI, unsigned Size);
- bool expandAtomicBinOpSubword(MachineBasicBlock &BB,
- MachineBasicBlock::iterator I,
- MachineBasicBlock::iterator &NMBBI);
-
- bool expandMI(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
- MachineBasicBlock::iterator &NMBB);
- bool expandMBB(MachineBasicBlock &MBB);
- };
- char MipsExpandPseudo::ID = 0;
-}
+ StringRef getPassName() const override {
+ return "Mips pseudo instruction expansion pass";
+ }
+};
+char MipsExpandPseudoLegacy::ID = 0;
+} // namespace
-bool MipsExpandPseudo::expandAtomicCmpSwapSubword(
- MachineBasicBlock &BB, MachineBasicBlock::iterator I,
- MachineBasicBlock::iterator &NMBBI) {
+static bool expandAtomicCmpSwapSubword(MachineBasicBlock &BB,
+ MachineBasicBlock::iterator I,
+ MachineBasicBlock::iterator &NMBBI,
+ const MipsSubtarget *STI,
+ const MipsInstrInfo *TII) {
MachineFunction *MF = BB.getParent();
@@ -198,9 +181,11 @@ bool MipsExpandPseudo::expandAtomicCmpSwapSubword(
return true;
}
-bool MipsExpandPseudo::expandAtomicCmpSwap(MachineBasicBlock &BB,
- MachineBasicBlock::iterator I,
- MachineBasicBlock::iterator &NMBBI) {
+static bool expandAtomicCmpSwap(MachineBasicBlock &BB,
+ MachineBasicBlock::iterator I,
+ MachineBasicBlock::iterator &NMBBI,
+ const MipsSubtarget *STI,
+ const MipsInstrInfo *TII) {
const unsigned Size =
I->getOpcode() == Mips::ATOMIC_CMP_SWAP_I32_POSTRA ? 4 : 8;
@@ -298,9 +283,11 @@ bool MipsExpandPseudo::expandAtomicCmpSwap(MachineBasicBlock &BB,
return true;
}
-bool MipsExpandPseudo::expandAtomicBinOpSubword(
- MachineBasicBlock &BB, MachineBasicBlock::iterator I,
- MachineBasicBlock::iterator &NMBBI) {
+static bool expandAtomicBinOpSubword(MachineBasicBlock &BB,
+ MachineBasicBlock::iterator I,
+ MachineBasicBlock::iterator &NMBBI,
+ const MipsSubtarget *STI,
+ const MipsInstrInfo *TII) {
MachineFunction *MF = BB.getParent();
@@ -705,10 +692,11 @@ bool MipsExpandPseudo::expandAtomicBinOpSubword(
return true;
}
-bool MipsExpandPseudo::expandAtomicBinOp(MachineBasicBlock &BB,
- MachineBasicBlock::iterator I,
- MachineBasicBlock::iterator &NMBBI,
- unsigned Size) {
+static bool expandAtomicBinOp(MachineBasicBlock &BB,
+ MachineBasicBlock::iterator I,
+ MachineBasicBlock::iterator &NMBBI, unsigned Size,
+ const MipsSubtarget *STI,
+ const MipsInstrInfo *TII) {
MachineFunction *MF = BB.getParent();
const bool ArePtrs64bit = STI->getABI().ArePtrs64bit();
@@ -1040,19 +1028,19 @@ bool MipsExpandPseudo::expandAtomicBinOp(MachineBasicBlock &BB,
return true;
}
-bool MipsExpandPseudo::expandMI(MachineBasicBlock &MBB,
- MachineBasicBlock::iterator MBBI,
- MachineBasicBlock::iterator &NMBB) {
+static bool expandMI(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
+ MachineBasicBlock::iterator &NMBB,
+ const MipsSubtarget *STI, const MipsInstrInfo *TII) {
bool Modified = false;
switch (MBBI->getOpcode()) {
case Mips::ATOMIC_CMP_SWAP_I32_POSTRA:
case Mips::ATOMIC_CMP_SWAP_I64_POSTRA:
- return expandAtomicCmpSwap(MBB, MBBI, NMBB);
+ return expandAtomicCmpSwap(MBB, MBBI, NMBB, STI, TII);
case Mips::ATOMIC_CMP_SWAP_I8_POSTRA:
case Mips::ATOMIC_CMP_SWAP_I16_POSTRA:
- return expandAtomicCmpSwapSubword(MBB, MBBI, NMBB);
+ return expandAtomicCmpSwapSubword(MBB, MBBI, NMBB, STI, TII);
case Mips::ATOMIC_SWAP_I8_POSTRA:
case Mips::ATOMIC_SWAP_I16_POSTRA:
case Mips::ATOMIC_LOAD_NAND_I8_POSTRA:
@@ -1075,7 +1063,7 @@ bool MipsExpandPseudo::expandMI(MachineBasicBlock &MBB,
case Mips::ATOMIC_LOAD_UMIN_I16_POSTRA:
case Mips::ATOMIC_LOAD_UMAX_I8_POSTRA:
case Mips::ATOMIC_LOAD_UMAX_I16_POSTRA:
- return expandAtomicBinOpSubword(MBB, MBBI, NMBB);
+ return expandAtomicBinOpSubword(MBB, MBBI, NMBB, STI, TII);
case Mips::ATOMIC_LOAD_ADD_I32_POSTRA:
case Mips::ATOMIC_LOAD_SUB_I32_POSTRA:
case Mips::ATOMIC_LOAD_AND_I32_POSTRA:
@@ -1087,7 +1075,7 @@ bool MipsExpandPseudo::expandMI(MachineBasicBlock &MBB,
case Mips::ATOMIC_LOAD_MAX_I32_POSTRA:
case Mips::ATOMIC_LOAD_UMIN_I32_POSTRA:
case Mips::ATOMIC_LOAD_UMAX_I32_POSTRA:
- return expandAtomicBinOp(MBB, MBBI, NMBB, 4);
+ return expandAtomicBinOp(MBB, MBBI, NMBB, 4, STI, TII);
case Mips::ATOMIC_LOAD_ADD_I64_POSTRA:
case Mips::ATOMIC_LOAD_SUB_I64_POSTRA:
case Mips::ATOMIC_LOAD_AND_I64_POSTRA:
@@ -1099,32 +1087,33 @@ bool MipsExpandPseudo::expandMI(MachineBasicBlock &MBB,
case Mips::ATOMIC_LOAD_MAX_I64_POSTRA:
case Mips::ATOMIC_LOAD_UMIN_I64_POSTRA:
case Mips::ATOMIC_LOAD_UMAX_I64_POSTRA:
- return expandAtomicBinOp(MBB, MBBI, NMBB, 8);
+ return expandAtomicBinOp(MBB, MBBI, NMBB, 8, STI, TII);
default:
return Modified;
}
}
-bool MipsExpandPseudo::expandMBB(MachineBasicBlock &MBB) {
+static bool expandMBB(MachineBasicBlock &MBB, const MipsSubtarget *STI,
+ const MipsInstrInfo *TII) {
bool Modified = false;
MachineBasicBlock::iterator MBBI = MBB.begin(), E = MBB.end();
while (MBBI != E) {
MachineBasicBlock::iterator NMBBI = std::next(MBBI);
- Modified |= expandMI(MBB, MBBI, NMBBI);
+ Modified |= expandMI(MBB, MBBI, NMBBI, STI, TII);
MBBI = NMBBI;
}
return Modified;
}
-bool MipsExpandPseudo::runOnMachineFunction(MachineFunction &MF) {
- STI = &MF.getSubtarget<MipsSubtarget>();
- TII = STI->getInstrInfo();
+static bool expandPseudosInMF(MachineFunction &MF) {
+ const MipsSubtarget *STI = &MF.getSubtarget<MipsSubtarget>();
+ const MipsInstrInfo *TII = STI->getInstrInfo();
bool Modified = false;
for (MachineBasicBlock &MBB : MF)
- Modified |= expandMBB(MBB);
+ Modified |= expandMBB(MBB, STI, TII);
if (Modified)
MF.RenumberBlocks();
@@ -1134,6 +1123,17 @@ bool MipsExpandPseudo::runOnMachineFunction(MachineFunction &MF) {
/// createMipsExpandPseudoPass - returns an instance of the pseudo instruction
/// expansion pass.
-FunctionPass *llvm::createMipsExpandPseudoPass() {
- return new MipsExpandPseudo();
+FunctionPass *llvm::createMipsExpandPseudoLegacyPass() {
+ return new MipsExpandPseudoLegacy();
+}
+
+bool MipsExpandPseudoLegacy::runOnMachineFunction(MachineFunction &MF) {
+ return expandPseudosInMF(MF);
+}
+
+PreservedAnalyses
+MipsExpandPseudoPass::run(MachineFunction &MF,
+ MachineFunctionAnalysisManager &MFAM) {
+ return expandPseudosInMF(MF) ? getMachineFunctionPassPreservedAnalyses()
+ : PreservedAnalyses::all();
}
diff --git a/llvm/lib/Target/Mips/MipsPassRegistry.def b/llvm/lib/Target/Mips/MipsPassRegistry.def
index 05a0e68a2ff88..02f399dd8ad99 100644
--- a/llvm/lib/Target/Mips/MipsPassRegistry.def
+++ b/llvm/lib/Target/Mips/MipsPassRegistry.def
@@ -24,6 +24,7 @@ MODULE_PASS("mips-os16", MipsOs16Pass())
#define MACHINE_FUNCTION_PASS(NAME, CREATE_PASS)
#endif
MACHINE_FUNCTION_PASS("mips-16-isel", Mips16ISelDAGPass(*this, getOptLevel()))
+MACHINE_FUNCTION_PASS("mips-expand-pseudo", MipsExpandPseudoPass())
MACHINE_FUNCTION_PASS("mips-optimize-pic-call", MipsOptimizePICCallPass())
MACHINE_FUNCTION_PASS("mips-se-isel", MipsSEISelDAGPass(*this, getOptLevel()))
#undef MACHINE_FUNCTION_PASS
diff --git a/llvm/lib/Target/Mips/MipsTargetMachine.cpp b/llvm/lib/Target/Mips/MipsTargetMachine.cpp
index 32cfc0185ae94..57f7b1506a5fe 100644
--- a/llvm/lib/Target/Mips/MipsTargetMachine.cpp
+++ b/llvm/lib/Target/Mips/MipsTargetMachine.cpp
@@ -248,7 +248,7 @@ MachineFunctionInfo *MipsTargetMachine::createMachineFunctionInfo(
// machine code is emitted.
void MipsPassConfig::addPreEmitPass() {
// Expand pseudo instructions that are sensitive to register allocation.
- addPass(createMipsExpandPseudoPass());
+ addPass(createMipsExpandPseudoLegacyPass());
// The microMIPS size reduction pass performs instruction reselection for
// instructions which can be remapped to a 16 bit instruction.
diff --git a/llvm/test/CodeGen/Mips/newpm-pipeline.ll b/llvm/test/CodeGen/Mips/newpm-pipeline.ll
index 41030dcff8702..f3c1548936309 100644
--- a/llvm/test/CodeGen/Mips/newpm-pipeline.ll
+++ b/llvm/test/CodeGen/Mips/newpm-pipeline.ll
@@ -86,6 +86,7 @@
; MIPS-NEXT: fentry-insert
; MIPS-NEXT: xray-instrumentation
; MIPS-NEXT: patchable-function
+; MIPS-NEXT: mips-expand-pseudo
; MIPS-NEXT: funclet-layout
; MIPS-NEXT: remove-loads-into-fake-uses
; MIPS-NEXT: StackMapLivenessPass
@@ -177,6 +178,7 @@
; MIPS-OS16-NEXT: fentry-insert
; MIPS-OS16-NEXT: xray-instrumentation
; MIPS-OS16-NEXT: patchable-function
+; MIPS-OS16-NEXT: mips-expand-pseudo
; MIPS-OS16-NEXT: funclet-layout
; MIPS-OS16-NEXT: remove-loads-into-fake-uses
; MIPS-OS16-NEXT: StackMapLivenessPass
@@ -267,6 +269,7 @@
; MIPS-MFIX4300-NEXT: fentry-insert
; MIPS-MFIX4300-NEXT: xray-instrumentation
; MIPS-MFIX4300-NEXT: patchable-function
+; MIPS-MFIX4300-NEXT: mips-expand-pseudo
; MIPS-MFIX4300-NEXT: funclet-layout
; MIPS-MFIX4300-NEXT: remove-loads-into-fake-uses
; MIPS-MFIX4300-NEXT: StackMapLivenessPass
``````````
</details>
https://github.com/llvm/llvm-project/pull/237090
More information about the llvm-branch-commits
mailing list