[llvm] [CodeGen] Add a helper class to reuse `expandMBB`. NFC. (PR #70325)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 26 06:14:54 PDT 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-aarch64
Author: Yingwei Zheng (dtcxzyw)
<details>
<summary>Changes</summary>
This PR adds a helper class `ExpandPseudoInstsPass` to avoid copying and pasting `expandMBB` implementations.
IMHO, I am not sure this change is profitable. I just posted this patch for your opinion.
---
Patch is 34.07 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/70325.diff
14 Files Affected:
- (added) llvm/include/llvm/CodeGen/ExpandPseudoInstsPass.h (+40)
- (modified) llvm/lib/CodeGen/CMakeLists.txt (+1)
- (added) llvm/lib/CodeGen/ExpandPseudoInstsPass.cpp (+34)
- (modified) llvm/lib/Target/AArch64/AArch64ExpandPseudoInsts.cpp (+4-20)
- (modified) llvm/lib/Target/ARM/ARMExpandPseudoInsts.cpp (+7-22)
- (modified) llvm/lib/Target/AVR/AVRExpandPseudoInsts.cpp (+5-19)
- (modified) llvm/lib/Target/LoongArch/LoongArchExpandAtomicPseudoInsts.cpp (+4-18)
- (modified) llvm/lib/Target/LoongArch/LoongArchExpandPseudoInsts.cpp (+7-35)
- (modified) llvm/lib/Target/M68k/M68kExpandPseudo.cpp (+9-24)
- (modified) llvm/lib/Target/Mips/MipsExpandPseudo.cpp (+4-18)
- (modified) llvm/lib/Target/RISCV/RISCVExpandAtomicPseudoInsts.cpp (+4-18)
- (modified) llvm/lib/Target/RISCV/RISCVExpandPseudoInsts.cpp (+7-35)
- (modified) llvm/lib/Target/RISCV/RISCVPostRAExpandPseudoInsts.cpp (+4-18)
- (modified) llvm/lib/Target/X86/X86ExpandPseudo.cpp (+10-25)
``````````diff
diff --git a/llvm/include/llvm/CodeGen/ExpandPseudoInstsPass.h b/llvm/include/llvm/CodeGen/ExpandPseudoInstsPass.h
new file mode 100644
index 000000000000000..b7c47dc1a410df4
--- /dev/null
+++ b/llvm/include/llvm/CodeGen/ExpandPseudoInstsPass.h
@@ -0,0 +1,40 @@
+//===-- ExpandPseudoInstsPass.h - Pass for expanding pseudo insts-*-C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines the ExpandPseudoInstsPass class. It provides a default
+// implementation for expandMBB to simplify target-specific pseudo instruction
+// expansion passes.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CODEGEN_EXPANDPSEUDOINSTSPASS_H
+#define LLVM_CODEGEN_EXPANDPSEUDOINSTSPASS_H
+
+#include "llvm/CodeGen/MachineFunctionPass.h"
+
+namespace llvm {
+
+/// ExpandPseudoInstsPass - Helper class for expanding pseudo instructions.
+class ExpandPseudoInstsPass : public MachineFunctionPass {
+protected:
+ explicit ExpandPseudoInstsPass(char &ID) : MachineFunctionPass(ID) {}
+
+ /// If MBBI references a pseudo instruction that should be expanded here,
+ /// do the expansion and return true. Otherwise return false.
+ virtual bool expandMI(MachineBasicBlock &MBB,
+ MachineBasicBlock::iterator MBBI,
+ MachineBasicBlock::iterator &NextMBBI) = 0;
+
+ /// Iterate over the instructions in basic block MBB and expand any
+ /// pseudo instructions. Return true if anything was modified.
+ bool expandMBB(MachineBasicBlock &MBB);
+};
+
+} // namespace llvm
+
+#endif
diff --git a/llvm/lib/CodeGen/CMakeLists.txt b/llvm/lib/CodeGen/CMakeLists.txt
index 389c70d04f17ba3..aa8e0c4455d3a40 100644
--- a/llvm/lib/CodeGen/CMakeLists.txt
+++ b/llvm/lib/CodeGen/CMakeLists.txt
@@ -72,6 +72,7 @@ add_llvm_component_library(LLVMCodeGen
ExpandLargeFpConvert.cpp
ExpandMemCmp.cpp
ExpandPostRAPseudos.cpp
+ ExpandPseudoInstsPass.cpp
ExpandReductions.cpp
ExpandVectorPredication.cpp
FaultMaps.cpp
diff --git a/llvm/lib/CodeGen/ExpandPseudoInstsPass.cpp b/llvm/lib/CodeGen/ExpandPseudoInstsPass.cpp
new file mode 100644
index 000000000000000..f64c82bd8bca344
--- /dev/null
+++ b/llvm/lib/CodeGen/ExpandPseudoInstsPass.cpp
@@ -0,0 +1,34 @@
+//===- ExpandPseudoInstsPass.cpp - Pass for expanding pseudo insts*-C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements the ExpandPseudoInstsPass class. It provides a default
+// implementation for expandMBB to simplify target-specific pseudo instruction
+// expansion passes.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/CodeGen/ExpandPseudoInstsPass.h"
+
+namespace llvm {
+
+/// Iterate over the instructions in basic block MBB and expand any
+/// pseudo instructions. Return true if anything was modified.
+bool ExpandPseudoInstsPass::expandMBB(MachineBasicBlock &MBB) {
+ 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);
+ MBBI = NMBBI;
+ }
+
+ return Modified;
+}
+
+} // namespace llvm
diff --git a/llvm/lib/Target/AArch64/AArch64ExpandPseudoInsts.cpp b/llvm/lib/Target/AArch64/AArch64ExpandPseudoInsts.cpp
index 42bc390a67b2b18..e20a3c9d5c9b9dd 100644
--- a/llvm/lib/Target/AArch64/AArch64ExpandPseudoInsts.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ExpandPseudoInsts.cpp
@@ -20,11 +20,11 @@
#include "MCTargetDesc/AArch64AddressingModes.h"
#include "Utils/AArch64BaseInfo.h"
#include "llvm/ADT/DenseMap.h"
+#include "llvm/CodeGen/ExpandPseudoInstsPass.h"
#include "llvm/CodeGen/LivePhysRegs.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/CodeGen/MachineConstantPool.h"
#include "llvm/CodeGen/MachineFunction.h"
-#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineOperand.h"
@@ -48,13 +48,13 @@ using namespace llvm;
namespace {
-class AArch64ExpandPseudo : public MachineFunctionPass {
+class AArch64ExpandPseudo : public ExpandPseudoInstsPass {
public:
const AArch64InstrInfo *TII;
static char ID;
- AArch64ExpandPseudo() : MachineFunctionPass(ID) {
+ AArch64ExpandPseudo() : ExpandPseudoInstsPass(ID) {
initializeAArch64ExpandPseudoPass(*PassRegistry::getPassRegistry());
}
@@ -63,9 +63,8 @@ class AArch64ExpandPseudo : public MachineFunctionPass {
StringRef getPassName() const override { return AARCH64_EXPAND_PSEUDO_NAME; }
private:
- bool expandMBB(MachineBasicBlock &MBB);
bool expandMI(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
- MachineBasicBlock::iterator &NextMBBI);
+ MachineBasicBlock::iterator &NextMBBI) override;
bool expandMultiVecPseudo(MachineBasicBlock &MBB,
MachineBasicBlock::iterator MBBI,
TargetRegisterClass ContiguousClass,
@@ -1648,21 +1647,6 @@ bool AArch64ExpandPseudo::expandMI(MachineBasicBlock &MBB,
return false;
}
-/// Iterate over the instructions in basic block MBB and expand any
-/// pseudo instructions. Return true if anything was modified.
-bool AArch64ExpandPseudo::expandMBB(MachineBasicBlock &MBB) {
- 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);
- MBBI = NMBBI;
- }
-
- return Modified;
-}
-
bool AArch64ExpandPseudo::runOnMachineFunction(MachineFunction &MF) {
TII = static_cast<const AArch64InstrInfo *>(MF.getSubtarget().getInstrInfo());
diff --git a/llvm/lib/Target/ARM/ARMExpandPseudoInsts.cpp b/llvm/lib/Target/ARM/ARMExpandPseudoInsts.cpp
index 2f9236bb977fc92..2830ae03cc786dd 100644
--- a/llvm/lib/Target/ARM/ARMExpandPseudoInsts.cpp
+++ b/llvm/lib/Target/ARM/ARMExpandPseudoInsts.cpp
@@ -20,9 +20,9 @@
#include "ARMMachineFunctionInfo.h"
#include "ARMSubtarget.h"
#include "MCTargetDesc/ARMAddressingModes.h"
+#include "llvm/CodeGen/ExpandPseudoInstsPass.h"
#include "llvm/CodeGen/LivePhysRegs.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
-#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineJumpTableInfo.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/Support/Debug.h"
@@ -38,10 +38,10 @@ VerifyARMPseudo("verify-arm-pseudo-expand", cl::Hidden,
#define ARM_EXPAND_PSEUDO_NAME "ARM pseudo instruction expansion pass"
namespace {
- class ARMExpandPseudo : public MachineFunctionPass {
+ class ARMExpandPseudo : public ExpandPseudoInstsPass {
public:
static char ID;
- ARMExpandPseudo() : MachineFunctionPass(ID) {}
+ ARMExpandPseudo() : ExpandPseudoInstsPass(ID) {}
const ARMBaseInstrInfo *TII;
const TargetRegisterInfo *TRI;
@@ -60,10 +60,8 @@ namespace {
}
private:
- bool ExpandMI(MachineBasicBlock &MBB,
- MachineBasicBlock::iterator MBBI,
- MachineBasicBlock::iterator &NextMBBI);
- bool ExpandMBB(MachineBasicBlock &MBB);
+ bool expandMI(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
+ MachineBasicBlock::iterator &NextMBBI) override;
void ExpandVLD(MachineBasicBlock::iterator &MBBI);
void ExpandVST(MachineBasicBlock::iterator &MBBI);
void ExpandLaneOp(MachineBasicBlock::iterator &MBBI);
@@ -2113,7 +2111,7 @@ static void CMSEPopCalleeSaves(const TargetInstrInfo &TII,
}
}
-bool ARMExpandPseudo::ExpandMI(MachineBasicBlock &MBB,
+bool ARMExpandPseudo::expandMI(MachineBasicBlock &MBB,
MachineBasicBlock::iterator MBBI,
MachineBasicBlock::iterator &NextMBBI) {
MachineInstr &MI = *MBBI;
@@ -3224,19 +3222,6 @@ bool ARMExpandPseudo::ExpandMI(MachineBasicBlock &MBB,
}
}
-bool ARMExpandPseudo::ExpandMBB(MachineBasicBlock &MBB) {
- 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);
- MBBI = NMBBI;
- }
-
- return Modified;
-}
-
bool ARMExpandPseudo::runOnMachineFunction(MachineFunction &MF) {
STI = &MF.getSubtarget<ARMSubtarget>();
TII = STI->getInstrInfo();
@@ -3248,7 +3233,7 @@ bool ARMExpandPseudo::runOnMachineFunction(MachineFunction &MF) {
bool Modified = false;
for (MachineBasicBlock &MBB : MF)
- Modified |= ExpandMBB(MBB);
+ Modified |= expandMBB(MBB);
if (VerifyARMPseudo)
MF.verify(this, "After expanding ARM pseudo instructions.");
diff --git a/llvm/lib/Target/AVR/AVRExpandPseudoInsts.cpp b/llvm/lib/Target/AVR/AVRExpandPseudoInsts.cpp
index f257ccea6c50a91..2e683cb6f1c6e7d 100644
--- a/llvm/lib/Target/AVR/AVRExpandPseudoInsts.cpp
+++ b/llvm/lib/Target/AVR/AVRExpandPseudoInsts.cpp
@@ -17,7 +17,7 @@
#include "AVRTargetMachine.h"
#include "MCTargetDesc/AVRMCTargetDesc.h"
-#include "llvm/CodeGen/MachineFunctionPass.h"
+#include "llvm/CodeGen/ExpandPseudoInstsPass.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/TargetRegisterInfo.h"
@@ -30,11 +30,11 @@ namespace {
/// Expands "placeholder" instructions marked as pseudo into
/// actual AVR instructions.
-class AVRExpandPseudo : public MachineFunctionPass {
+class AVRExpandPseudo : public ExpandPseudoInstsPass {
public:
static char ID;
- AVRExpandPseudo() : MachineFunctionPass(ID) {
+ AVRExpandPseudo() : ExpandPseudoInstsPass(ID) {
initializeAVRExpandPseudoPass(*PassRegistry::getPassRegistry());
}
@@ -49,8 +49,7 @@ class AVRExpandPseudo : public MachineFunctionPass {
const AVRRegisterInfo *TRI;
const TargetInstrInfo *TII;
- bool expandMBB(Block &MBB);
- bool expandMI(Block &MBB, BlockIt MBBI);
+ bool expandMI(Block &MBB, BlockIt MBBI, BlockIt &NextMBBI) override;
template <unsigned OP> bool expand(Block &MBB, BlockIt MBBI);
MachineInstrBuilder buildMI(Block &MBB, BlockIt MBBI, unsigned Opcode) {
@@ -107,19 +106,6 @@ class AVRExpandPseudo : public MachineFunctionPass {
char AVRExpandPseudo::ID = 0;
-bool AVRExpandPseudo::expandMBB(MachineBasicBlock &MBB) {
- bool Modified = false;
-
- BlockIt MBBI = MBB.begin(), E = MBB.end();
- while (MBBI != E) {
- BlockIt NMBBI = std::next(MBBI);
- Modified |= expandMI(MBB, MBBI);
- MBBI = NMBBI;
- }
-
- return Modified;
-}
-
bool AVRExpandPseudo::runOnMachineFunction(MachineFunction &MF) {
bool Modified = false;
@@ -2559,7 +2545,7 @@ bool AVRExpandPseudo::expand<AVR::SPWRITE>(Block &MBB, BlockIt MBBI) {
return true;
}
-bool AVRExpandPseudo::expandMI(Block &MBB, BlockIt MBBI) {
+bool AVRExpandPseudo::expandMI(Block &MBB, BlockIt MBBI, BlockIt &NextMBBI) {
MachineInstr &MI = *MBBI;
int Opcode = MBBI->getOpcode();
diff --git a/llvm/lib/Target/LoongArch/LoongArchExpandAtomicPseudoInsts.cpp b/llvm/lib/Target/LoongArch/LoongArchExpandAtomicPseudoInsts.cpp
index 18a532b55ee5a92..4fc3e8c048f8bce 100644
--- a/llvm/lib/Target/LoongArch/LoongArchExpandAtomicPseudoInsts.cpp
+++ b/llvm/lib/Target/LoongArch/LoongArchExpandAtomicPseudoInsts.cpp
@@ -17,8 +17,8 @@
#include "LoongArchInstrInfo.h"
#include "LoongArchTargetMachine.h"
+#include "llvm/CodeGen/ExpandPseudoInstsPass.h"
#include "llvm/CodeGen/LivePhysRegs.h"
-#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
using namespace llvm;
@@ -28,12 +28,12 @@ using namespace llvm;
namespace {
-class LoongArchExpandAtomicPseudo : public MachineFunctionPass {
+class LoongArchExpandAtomicPseudo : public ExpandPseudoInstsPass {
public:
const LoongArchInstrInfo *TII;
static char ID;
- LoongArchExpandAtomicPseudo() : MachineFunctionPass(ID) {
+ LoongArchExpandAtomicPseudo() : ExpandPseudoInstsPass(ID) {
initializeLoongArchExpandAtomicPseudoPass(*PassRegistry::getPassRegistry());
}
@@ -44,9 +44,8 @@ class LoongArchExpandAtomicPseudo : public MachineFunctionPass {
}
private:
- bool expandMBB(MachineBasicBlock &MBB);
bool expandMI(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
- MachineBasicBlock::iterator &NextMBBI);
+ MachineBasicBlock::iterator &NextMBBI) override;
bool expandAtomicBinOp(MachineBasicBlock &MBB,
MachineBasicBlock::iterator MBBI, AtomicRMWInst::BinOp,
bool IsMasked, int Width,
@@ -71,19 +70,6 @@ bool LoongArchExpandAtomicPseudo::runOnMachineFunction(MachineFunction &MF) {
return Modified;
}
-bool LoongArchExpandAtomicPseudo::expandMBB(MachineBasicBlock &MBB) {
- 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);
- MBBI = NMBBI;
- }
-
- return Modified;
-}
-
bool LoongArchExpandAtomicPseudo::expandMI(
MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
MachineBasicBlock::iterator &NextMBBI) {
diff --git a/llvm/lib/Target/LoongArch/LoongArchExpandPseudoInsts.cpp b/llvm/lib/Target/LoongArch/LoongArchExpandPseudoInsts.cpp
index 72c1f1cec198347..f0a793ea2ebbe31 100644
--- a/llvm/lib/Target/LoongArch/LoongArchExpandPseudoInsts.cpp
+++ b/llvm/lib/Target/LoongArch/LoongArchExpandPseudoInsts.cpp
@@ -16,8 +16,8 @@
#include "LoongArchTargetMachine.h"
#include "MCTargetDesc/LoongArchBaseInfo.h"
#include "MCTargetDesc/LoongArchMCTargetDesc.h"
+#include "llvm/CodeGen/ExpandPseudoInstsPass.h"
#include "llvm/CodeGen/LivePhysRegs.h"
-#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineOperand.h"
#include "llvm/CodeGen/Register.h"
@@ -34,12 +34,12 @@ using namespace llvm;
namespace {
-class LoongArchPreRAExpandPseudo : public MachineFunctionPass {
+class LoongArchPreRAExpandPseudo : public ExpandPseudoInstsPass {
public:
const LoongArchInstrInfo *TII;
static char ID;
- LoongArchPreRAExpandPseudo() : MachineFunctionPass(ID) {
+ LoongArchPreRAExpandPseudo() : ExpandPseudoInstsPass(ID) {
initializeLoongArchPreRAExpandPseudoPass(*PassRegistry::getPassRegistry());
}
@@ -54,9 +54,8 @@ class LoongArchPreRAExpandPseudo : public MachineFunctionPass {
}
private:
- bool expandMBB(MachineBasicBlock &MBB);
bool expandMI(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
- MachineBasicBlock::iterator &NextMBBI);
+ MachineBasicBlock::iterator &NextMBBI) override;
bool expandPcalau12iInstPair(MachineBasicBlock &MBB,
MachineBasicBlock::iterator MBBI,
MachineBasicBlock::iterator &NextMBBI,
@@ -112,19 +111,6 @@ bool LoongArchPreRAExpandPseudo::runOnMachineFunction(MachineFunction &MF) {
return Modified;
}
-bool LoongArchPreRAExpandPseudo::expandMBB(MachineBasicBlock &MBB) {
- 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);
- MBBI = NMBBI;
- }
-
- return Modified;
-}
-
bool LoongArchPreRAExpandPseudo::expandMI(
MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
MachineBasicBlock::iterator &NextMBBI) {
@@ -515,12 +501,12 @@ bool LoongArchPreRAExpandPseudo::expandFunctionCALL(
return true;
}
-class LoongArchExpandPseudo : public MachineFunctionPass {
+class LoongArchExpandPseudo : public ExpandPseudoInstsPass {
public:
const LoongArchInstrInfo *TII;
static char ID;
- LoongArchExpandPseudo() : MachineFunctionPass(ID) {
+ LoongArchExpandPseudo() : ExpandPseudoInstsPass(ID) {
initializeLoongArchExpandPseudoPass(*PassRegistry::getPassRegistry());
}
@@ -531,9 +517,8 @@ class LoongArchExpandPseudo : public MachineFunctionPass {
}
private:
- bool expandMBB(MachineBasicBlock &MBB);
bool expandMI(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
- MachineBasicBlock::iterator &NextMBBI);
+ MachineBasicBlock::iterator &NextMBBI) override;
bool expandCopyCFR(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
MachineBasicBlock::iterator &NextMBBI);
};
@@ -551,19 +536,6 @@ bool LoongArchExpandPseudo::runOnMachineFunction(MachineFunction &MF) {
return Modified;
}
-bool LoongArchExpandPseudo::expandMBB(MachineBasicBlock &MBB) {
- 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);
- MBBI = NMBBI;
- }
-
- return Modified;
-}
-
bool LoongArchExpandPseudo::expandMI(MachineBasicBlock &MBB,
MachineBasicBlock::iterator MBBI,
MachineBasicBlock::iterator &NextMBBI) {
diff --git a/llvm/lib/Target/M68k/M68kExpandPseudo.cpp b/llvm/lib/Target/M68k/M68kExpandPseudo.cpp
index 13268d754a9dde6..7214fd5ef4b0e18 100644
--- a/llvm/lib/Target/M68k/M68kExpandPseudo.cpp
+++ b/llvm/lib/Target/M68k/M68kExpandPseudo.cpp
@@ -19,7 +19,7 @@
#include "M68kMachineFunction.h"
#include "M68kSubtarget.h"
-#include "llvm/CodeGen/MachineFunctionPass.h"
+#include "llvm/CodeGen/ExpandPseudoInstsPass.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/Passes.h" // For IDs of passes that are preserved.
@@ -32,10 +32,10 @@ using namespace llvm;
#define PASS_NAME "M68k pseudo instruction expansion pass"
namespace {
-class M68kExpandPseudo : public MachineFunctionPass {
+class M68kExpandPseudo : public ExpandPseudoInstsPass {
public:
static char ID;
- M68kExpandPseudo() : MachineFunctionPass(ID) {}
+ M68kExpandPseudo() : ExpandPseudoInstsPass(ID) {}
void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.setPreservesCFG();
@@ -58,8 +58,8 @@ class M68kExpandPseudo : public MachineFunctionPass {
}
private:
- bool ExpandMI(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI);
- bool ExpandMBB(MachineBasicBlock &MBB);
+ bool expandMI(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
+ MachineBasicBlock::iterator &NextMBBI) override;
};
char M68kExpandPseudo::ID = 0;
} // End anonymous namespace.
@@ -69,8 +69,9 @@ INITIALIZE_PASS(M68kExpandPseudo, DEBUG_TYPE, PASS_NAME, false, false)
/// If \p MBBI is a pseudo instruction, this method expands
/// it to the corresponding (sequence of) actual instruction(s).
/// \returns true if \p MBBI has been expanded.
-bool M68kExpandPseudo::ExpandMI(MachineBasicBlock &MBB,
- MachineBasicBlock::iterator MBBI) {
+bool M68kExpandPseudo::expandMI(MachineBasicBlock &MBB,
+ MachineBasicBlock::iterator MBBI,
+ MachineBasicBlock::iterator &NextMBBI) {
MachineInstr &MI = *MBBI;
MachineInstrBuilder MIB(*MI.getParent()->getParent(), MI);
unsigned Opcode = MI.getOpcode();
@@ -284,22 +285,6 @@ bool M68kExpandPseudo::ExpandMI(MachineBasicBlock &MBB,
llvm_unreachable("Previous switch has a fallthrough?");
}
-/// Expand all pseudo instructions contained in \p MBB.
-/// \returns true if any expansion occurred for \p MBB.
-bool M68kExpandPseudo::ExpandMBB(MachineBasicBlock &MBB) {
- bool Modified = false;
-
- // MBBI may be invalidated by the expansion.
- MachineBasicBlock::iterator MBBI = MBB.begin(), E = MBB.end();
- while (MBBI != E) {
- MachineBasicBlock::iterator NMBBI = std::next(MBBI);
- Modified |= ExpandMI(MBB, MBBI);
- MBBI = NMBBI;
- }...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/70325
More information about the llvm-commits
mailing list