88// ===----------------------------------------------------------------------===//
99//
1010
11+ #include " SIShrinkInstructions.h"
1112#include " AMDGPU.h"
1213#include " GCNSubtarget.h"
1314#include " MCTargetDesc/AMDGPUMCTargetDesc.h"
@@ -26,20 +27,13 @@ using namespace llvm;
2627
2728namespace {
2829
29- class SIShrinkInstructions : public MachineFunctionPass {
30+ class SIShrinkInstructions {
3031 MachineFunction *MF;
3132 MachineRegisterInfo *MRI;
3233 const GCNSubtarget *ST;
3334 const SIInstrInfo *TII;
3435 const SIRegisterInfo *TRI;
3536
36- public:
37- static char ID;
38-
39- public:
40- SIShrinkInstructions () : MachineFunctionPass(ID) {
41- }
42-
4337 bool foldImmediates (MachineInstr &MI, bool TryToCommute = true ) const ;
4438 bool shouldShrinkTrue16 (MachineInstr &MI) const ;
4539 bool isKImmOperand (const MachineOperand &Src) const ;
@@ -62,6 +56,18 @@ class SIShrinkInstructions : public MachineFunctionPass {
6256 void dropInstructionKeepingImpDefs (MachineInstr &MI) const ;
6357 MachineInstr *matchSwap (MachineInstr &MovT) const ;
6458
59+ public:
60+ SIShrinkInstructions () = default ;
61+ bool run (MachineFunction &MF);
62+ };
63+
64+ class SIShrinkInstructionsLegacy : public MachineFunctionPass {
65+
66+ public:
67+ static char ID;
68+
69+ SIShrinkInstructionsLegacy () : MachineFunctionPass(ID) {}
70+
6571 bool runOnMachineFunction (MachineFunction &MF) override ;
6672
6773 StringRef getPassName () const override { return " SI Shrink Instructions" ; }
@@ -74,13 +80,13 @@ class SIShrinkInstructions : public MachineFunctionPass {
7480
7581} // End anonymous namespace.
7682
77- INITIALIZE_PASS (SIShrinkInstructions , DEBUG_TYPE,
83+ INITIALIZE_PASS (SIShrinkInstructionsLegacy , DEBUG_TYPE,
7884 " SI Shrink Instructions" , false , false )
7985
80- char SIShrinkInstructions ::ID = 0;
86+ char SIShrinkInstructionsLegacy ::ID = 0;
8187
82- FunctionPass *llvm::createSIShrinkInstructionsPass () {
83- return new SIShrinkInstructions ();
88+ FunctionPass *llvm::createSIShrinkInstructionsLegacyPass () {
89+ return new SIShrinkInstructionsLegacy ();
8490}
8591
8692// / This function checks \p MI for operands defined by a move immediate
@@ -815,9 +821,7 @@ bool SIShrinkInstructions::tryReplaceDeadSDST(MachineInstr &MI) const {
815821 return true ;
816822}
817823
818- bool SIShrinkInstructions::runOnMachineFunction (MachineFunction &MF) {
819- if (skipFunction (MF.getFunction ()))
820- return false ;
824+ bool SIShrinkInstructions::run (MachineFunction &MF) {
821825
822826 this ->MF = &MF;
823827 MRI = &MF.getRegInfo ();
@@ -1077,3 +1081,21 @@ bool SIShrinkInstructions::runOnMachineFunction(MachineFunction &MF) {
10771081 }
10781082 return false ;
10791083}
1084+
1085+ bool SIShrinkInstructionsLegacy::runOnMachineFunction (MachineFunction &MF) {
1086+ if (skipFunction (MF.getFunction ()))
1087+ return false ;
1088+
1089+ return SIShrinkInstructions ().run (MF);
1090+ }
1091+
1092+ PreservedAnalyses
1093+ SIShrinkInstructionsPass::run (MachineFunction &MF,
1094+ MachineFunctionAnalysisManager &) {
1095+ if (MF.getFunction ().hasOptNone () || !SIShrinkInstructions ().run (MF))
1096+ return PreservedAnalyses::all ();
1097+
1098+ auto PA = getMachineFunctionPassPreservedAnalyses ();
1099+ PA.preserveSet <CFGAnalyses>();
1100+ return PA;
1101+ }
0 commit comments