1818#include " X86MachineFunctionInfo.h"
1919#include " X86Subtarget.h"
2020#include " llvm/CodeGen/LivePhysRegs.h"
21+ #include " llvm/CodeGen/MachineDominators.h"
22+ #include " llvm/CodeGen/MachineFunctionAnalysisManager.h"
2123#include " llvm/CodeGen/MachineFunctionPass.h"
2224#include " llvm/CodeGen/MachineInstrBuilder.h"
25+ #include " llvm/CodeGen/MachineLoopInfo.h"
26+ #include " llvm/CodeGen/MachinePassManager.h"
2327#include " llvm/CodeGen/Passes.h" // For IDs of passes that are preserved.
28+ #include " llvm/IR/Analysis.h"
2429#include " llvm/IR/EHPersonalities.h"
2530#include " llvm/IR/GlobalValue.h"
2631#include " llvm/Target/TargetMachine.h"
2732using namespace llvm ;
2833
29- #define DEBUG_TYPE " x86-pseudo"
34+ #define DEBUG_TYPE " x86-expand- pseudo"
3035#define X86_EXPAND_PSEUDO_NAME " X86 pseudo instruction expansion pass"
3136
3237namespace {
33- class X86ExpandPseudo : public MachineFunctionPass {
38+ class X86ExpandPseudoImpl {
3439public:
35- static char ID;
36- X86ExpandPseudo () : MachineFunctionPass(ID) {}
37-
38- void getAnalysisUsage (AnalysisUsage &AU) const override {
39- AU.setPreservesCFG ();
40- AU.addPreservedID (MachineLoopInfoID);
41- AU.addPreservedID (MachineDominatorsID);
42- MachineFunctionPass::getAnalysisUsage (AU);
43- }
44-
4540 const X86Subtarget *STI = nullptr ;
4641 const X86InstrInfo *TII = nullptr ;
4742 const X86RegisterInfo *TRI = nullptr ;
4843 const X86MachineFunctionInfo *X86FI = nullptr ;
4944 const X86FrameLowering *X86FL = nullptr ;
5045
51- bool runOnMachineFunction (MachineFunction &MF) override ;
52-
53- MachineFunctionProperties getRequiredProperties () const override {
54- return MachineFunctionProperties ().setNoVRegs ();
55- }
56-
57- StringRef getPassName () const override {
58- return " X86 pseudo instruction expansion pass" ;
59- }
46+ bool runOnMachineFunction (MachineFunction &MF);
6047
6148private:
6249 void expandICallBranchFunnel (MachineBasicBlock *MBB,
@@ -78,14 +65,42 @@ class X86ExpandPseudo : public MachineFunctionPass {
7865 MachineBasicBlock *EntryBlk,
7966 MachineBasicBlock::iterator VAStartPseudoInstr) const ;
8067};
81- char X86ExpandPseudo::ID = 0 ;
8268
69+ class X86ExpandPseudoLegacy : public MachineFunctionPass {
70+ public:
71+ static char ID;
72+ X86ExpandPseudoLegacy () : MachineFunctionPass(ID) {}
73+
74+ void getAnalysisUsage (AnalysisUsage &AU) const override {
75+ AU.setPreservesCFG ();
76+ AU.addPreservedID (MachineLoopInfoID);
77+ AU.addPreservedID (MachineDominatorsID);
78+ MachineFunctionPass::getAnalysisUsage (AU);
79+ }
80+
81+ const X86Subtarget *STI = nullptr ;
82+ const X86InstrInfo *TII = nullptr ;
83+ const X86RegisterInfo *TRI = nullptr ;
84+ const X86MachineFunctionInfo *X86FI = nullptr ;
85+ const X86FrameLowering *X86FL = nullptr ;
86+
87+ bool runOnMachineFunction (MachineFunction &MF) override ;
88+
89+ MachineFunctionProperties getRequiredProperties () const override {
90+ return MachineFunctionProperties ().setNoVRegs ();
91+ }
92+
93+ StringRef getPassName () const override {
94+ return " X86 pseudo instruction expansion pass" ;
95+ }
96+ };
97+ char X86ExpandPseudoLegacy::ID = 0 ;
8398} // End anonymous namespace.
8499
85- INITIALIZE_PASS (X86ExpandPseudo , DEBUG_TYPE, X86_EXPAND_PSEUDO_NAME, false ,
86- false )
100+ INITIALIZE_PASS (X86ExpandPseudoLegacy , DEBUG_TYPE, X86_EXPAND_PSEUDO_NAME,
101+ false , false )
87102
88- void X86ExpandPseudo ::expandICallBranchFunnel(
103+ void X86ExpandPseudoImpl ::expandICallBranchFunnel(
89104 MachineBasicBlock *MBB, MachineBasicBlock::iterator MBBI) {
90105 MachineBasicBlock *JTMBB = MBB;
91106 MachineInstr *JTInst = &*MBBI;
@@ -186,8 +201,8 @@ void X86ExpandPseudo::expandICallBranchFunnel(
186201 JTMBB->erase (JTInst);
187202}
188203
189- void X86ExpandPseudo ::expandCALL_RVMARKER (MachineBasicBlock &MBB,
190- MachineBasicBlock::iterator MBBI) {
204+ void X86ExpandPseudoImpl ::expandCALL_RVMARKER (
205+ MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI) {
191206 // Expand CALL_RVMARKER pseudo to call instruction, followed by the special
192207 // "movq %rax, %rdi" marker.
193208 MachineInstr &MI = *MBBI;
@@ -257,8 +272,8 @@ void X86ExpandPseudo::expandCALL_RVMARKER(MachineBasicBlock &MBB,
257272// / If \p MBBI is a pseudo instruction, this method expands
258273// / it to the corresponding (sequence of) actual instruction(s).
259274// / \returns true if \p MBBI has been expanded.
260- bool X86ExpandPseudo ::expandMI (MachineBasicBlock &MBB,
261- MachineBasicBlock::iterator MBBI) {
275+ bool X86ExpandPseudoImpl ::expandMI (MachineBasicBlock &MBB,
276+ MachineBasicBlock::iterator MBBI) {
262277 MachineInstr &MI = *MBBI;
263278 unsigned Opcode = MI.getOpcode ();
264279 const DebugLoc &DL = MBBI->getDebugLoc ();
@@ -813,7 +828,7 @@ bool X86ExpandPseudo::expandMI(MachineBasicBlock &MBB,
813828// | |
814829// | |
815830//
816- void X86ExpandPseudo ::expandVastartSaveXmmRegs (
831+ void X86ExpandPseudoImpl ::expandVastartSaveXmmRegs (
817832 MachineBasicBlock *EntryBlk,
818833 MachineBasicBlock::iterator VAStartPseudoInstr) const {
819834 assert (VAStartPseudoInstr->getOpcode () == X86::VASTART_SAVE_XMM_REGS);
@@ -898,7 +913,7 @@ void X86ExpandPseudo::expandVastartSaveXmmRegs(
898913
899914// / Expand all pseudo instructions contained in \p MBB.
900915// / \returns true if any expansion occurred for \p MBB.
901- bool X86ExpandPseudo ::expandMBB (MachineBasicBlock &MBB) {
916+ bool X86ExpandPseudoImpl ::expandMBB (MachineBasicBlock &MBB) {
902917 bool Modified = false ;
903918
904919 // MBBI may be invalidated by the expansion.
@@ -912,7 +927,8 @@ bool X86ExpandPseudo::expandMBB(MachineBasicBlock &MBB) {
912927 return Modified;
913928}
914929
915- bool X86ExpandPseudo::expandPseudosWhichAffectControlFlow (MachineFunction &MF) {
930+ bool X86ExpandPseudoImpl::expandPseudosWhichAffectControlFlow (
931+ MachineFunction &MF) {
916932 // Currently pseudo which affects control flow is only
917933 // X86::VASTART_SAVE_XMM_REGS which is located in Entry block.
918934 // So we do not need to evaluate other blocks.
@@ -926,7 +942,7 @@ bool X86ExpandPseudo::expandPseudosWhichAffectControlFlow(MachineFunction &MF) {
926942 return false ;
927943}
928944
929- bool X86ExpandPseudo ::runOnMachineFunction (MachineFunction &MF) {
945+ bool X86ExpandPseudoImpl ::runOnMachineFunction (MachineFunction &MF) {
930946 STI = &MF.getSubtarget <X86Subtarget>();
931947 TII = STI->getInstrInfo ();
932948 TRI = STI->getRegisterInfo ();
@@ -941,6 +957,24 @@ bool X86ExpandPseudo::runOnMachineFunction(MachineFunction &MF) {
941957}
942958
943959// / Returns an instance of the pseudo instruction expansion pass.
944- FunctionPass *llvm::createX86ExpandPseudoPass () {
945- return new X86ExpandPseudo ();
960+ FunctionPass *llvm::createX86ExpandPseudoLegacyPass () {
961+ return new X86ExpandPseudoLegacy ();
962+ }
963+
964+ bool X86ExpandPseudoLegacy::runOnMachineFunction (MachineFunction &MF) {
965+ X86ExpandPseudoImpl Impl;
966+ return Impl.runOnMachineFunction (MF);
967+ }
968+
969+ PreservedAnalyses
970+ X86ExpandPseudoPass::run (MachineFunction &MF,
971+ MachineFunctionAnalysisManager &MFAM) {
972+ X86ExpandPseudoImpl Impl;
973+ bool Changed = Impl.runOnMachineFunction (MF);
974+ if (!Changed)
975+ return PreservedAnalyses::all ();
976+
977+ PreservedAnalyses PA = getMachineFunctionPassPreservedAnalyses ();
978+ PA.preserveSet <CFGAnalyses>();
979+ return PA;
946980}
0 commit comments