3737// The mov_dpp instruction should reside in the same BB as all its uses
3838// ===----------------------------------------------------------------------===//
3939
40+ #include " GCNDPPCombine.h"
4041#include " AMDGPU.h"
4142#include " GCNSubtarget.h"
4243#include " MCTargetDesc/AMDGPUMCTargetDesc.h"
@@ -51,7 +52,7 @@ STATISTIC(NumDPPMovsCombined, "Number of DPP moves combined.");
5152
5253namespace {
5354
54- class GCNDPPCombine : public MachineFunctionPass {
55+ class GCNDPPCombine {
5556 MachineRegisterInfo *MRI;
5657 const SIInstrInfo *TII;
5758 const GCNSubtarget *ST;
@@ -76,12 +77,18 @@ class GCNDPPCombine : public MachineFunctionPass {
7677
7778 bool combineDPPMov (MachineInstr &MI) const ;
7879
80+ int getDPPOp (unsigned Op, bool IsShrinkable) const ;
81+ bool isShrinkable (MachineInstr &MI) const ;
82+
83+ public:
84+ bool run (MachineFunction &MF);
85+ };
86+
87+ class GCNDPPCombineLegacy : public MachineFunctionPass {
7988public:
8089 static char ID;
8190
82- GCNDPPCombine () : MachineFunctionPass(ID) {
83- initializeGCNDPPCombinePass (*PassRegistry::getPassRegistry ());
84- }
91+ GCNDPPCombineLegacy () : MachineFunctionPass(ID) {}
8592
8693 bool runOnMachineFunction (MachineFunction &MF) override ;
8794
@@ -96,22 +103,19 @@ class GCNDPPCombine : public MachineFunctionPass {
96103 return MachineFunctionProperties ()
97104 .set (MachineFunctionProperties::Property::IsSSA);
98105 }
99-
100- private:
101- int getDPPOp (unsigned Op, bool IsShrinkable) const ;
102- bool isShrinkable (MachineInstr &MI) const ;
103106};
104107
105108} // end anonymous namespace
106109
107- INITIALIZE_PASS (GCNDPPCombine, DEBUG_TYPE, " GCN DPP Combine" , false , false )
110+ INITIALIZE_PASS (GCNDPPCombineLegacy, DEBUG_TYPE, " GCN DPP Combine" , false ,
111+ false )
108112
109- char GCNDPPCombine ::ID = 0;
113+ char GCNDPPCombineLegacy ::ID = 0;
110114
111- char &llvm::GCNDPPCombineID = GCNDPPCombine ::ID;
115+ char &llvm::GCNDPPCombineLegacyID = GCNDPPCombineLegacy ::ID;
112116
113117FunctionPass *llvm::createGCNDPPCombinePass () {
114- return new GCNDPPCombine ();
118+ return new GCNDPPCombineLegacy ();
115119}
116120
117121bool GCNDPPCombine::isShrinkable (MachineInstr &MI) const {
@@ -749,9 +753,16 @@ bool GCNDPPCombine::combineDPPMov(MachineInstr &MovMI) const {
749753 return !Rollback;
750754}
751755
752- bool GCNDPPCombine::runOnMachineFunction (MachineFunction &MF) {
756+ bool GCNDPPCombineLegacy::runOnMachineFunction (MachineFunction &MF) {
757+ if (skipFunction (MF.getFunction ()))
758+ return false ;
759+
760+ return GCNDPPCombine ().run (MF);
761+ }
762+
763+ bool GCNDPPCombine::run (MachineFunction &MF) {
753764 ST = &MF.getSubtarget <GCNSubtarget>();
754- if (!ST->hasDPP () || skipFunction (MF. getFunction ()) )
765+ if (!ST->hasDPP ())
755766 return false ;
756767
757768 MRI = &MF.getRegInfo ();
@@ -781,3 +792,19 @@ bool GCNDPPCombine::runOnMachineFunction(MachineFunction &MF) {
781792 }
782793 return Changed;
783794}
795+
796+ PreservedAnalyses GCNDPPCombinePass::run (MachineFunction &MF,
797+ MachineFunctionAnalysisManager &) {
798+ if (MF.getFunction ().hasOptNone ())
799+ return PreservedAnalyses::all ();
800+
801+ MFPropsModifier _ (*this , MF);
802+
803+ bool Changed = GCNDPPCombine ().run (MF);
804+ if (!Changed)
805+ return PreservedAnalyses::all ();
806+
807+ auto PA = getMachineFunctionPassPreservedAnalyses ();
808+ PA.preserveSet <CFGAnalyses>();
809+ return PA;
810+ }
0 commit comments