1919// /
2020// ===----------------------------------------------------------------------===//
2121
22+ #include " SIPeepholeSDWA.h"
2223#include " AMDGPU.h"
2324#include " GCNSubtarget.h"
2425#include " MCTargetDesc/AMDGPUMCTargetDesc.h"
@@ -45,7 +46,7 @@ class SDWADstOperand;
4546using SDWAOperandsVector = SmallVector<SDWAOperand *, 4 >;
4647using SDWAOperandsMap = MapVector<MachineInstr *, SDWAOperandsVector>;
4748
48- class SIPeepholeSDWA : public MachineFunctionPass {
49+ class SIPeepholeSDWA {
4950private:
5051 MachineRegisterInfo *MRI;
5152 const SIRegisterInfo *TRI;
@@ -57,23 +58,27 @@ class SIPeepholeSDWA : public MachineFunctionPass {
5758
5859 std::optional<int64_t > foldToImm (const MachineOperand &Op) const ;
5960
60- public:
61- static char ID;
62-
63- SIPeepholeSDWA () : MachineFunctionPass(ID) {
64- initializeSIPeepholeSDWAPass (*PassRegistry::getPassRegistry ());
65- }
66-
67- bool runOnMachineFunction (MachineFunction &MF) override ;
6861 void matchSDWAOperands (MachineBasicBlock &MBB);
6962 std::unique_ptr<SDWAOperand> matchSDWAOperand (MachineInstr &MI);
7063 void pseudoOpConvertToVOP2 (MachineInstr &MI,
7164 const GCNSubtarget &ST) const ;
7265 bool convertToSDWA (MachineInstr &MI, const SDWAOperandsVector &SDWAOperands);
7366 void legalizeScalarOperands (MachineInstr &MI, const GCNSubtarget &ST) const ;
7467
68+ public:
69+ bool run (MachineFunction &MF);
70+ };
71+
72+ class SIPeepholeSDWALegacy : public MachineFunctionPass {
73+ public:
74+ static char ID;
75+
76+ SIPeepholeSDWALegacy () : MachineFunctionPass(ID) {}
77+
7578 StringRef getPassName () const override { return " SI Peephole SDWA" ; }
7679
80+ bool runOnMachineFunction (MachineFunction &MF) override ;
81+
7782 void getAnalysisUsage (AnalysisUsage &AU) const override {
7883 AU.setPreservesCFG ();
7984 MachineFunctionPass::getAnalysisUsage (AU);
@@ -192,17 +197,17 @@ class SDWADstPreserveOperand : public SDWADstOperand {
192197
193198} // end anonymous namespace
194199
195- INITIALIZE_PASS (SIPeepholeSDWA, DEBUG_TYPE, " SI Peephole SDWA" , false , false )
200+ INITIALIZE_PASS (SIPeepholeSDWALegacy, DEBUG_TYPE, " SI Peephole SDWA" , false ,
201+ false )
196202
197- char SIPeepholeSDWA ::ID = 0;
203+ char SIPeepholeSDWALegacy ::ID = 0;
198204
199- char &llvm::SIPeepholeSDWAID = SIPeepholeSDWA ::ID;
205+ char &llvm::SIPeepholeSDWALegacyID = SIPeepholeSDWALegacy ::ID;
200206
201- FunctionPass *llvm::createSIPeepholeSDWAPass () {
202- return new SIPeepholeSDWA ();
207+ FunctionPass *llvm::createSIPeepholeSDWALegacyPass () {
208+ return new SIPeepholeSDWALegacy ();
203209}
204210
205-
206211#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
207212static raw_ostream& operator <<(raw_ostream &OS, SdwaSel Sel) {
208213 switch (Sel) {
@@ -1235,10 +1240,17 @@ void SIPeepholeSDWA::legalizeScalarOperands(MachineInstr &MI,
12351240 }
12361241}
12371242
1238- bool SIPeepholeSDWA::runOnMachineFunction (MachineFunction &MF) {
1243+ bool SIPeepholeSDWALegacy::runOnMachineFunction (MachineFunction &MF) {
1244+ if (skipFunction (MF.getFunction ()))
1245+ return false ;
1246+
1247+ return SIPeepholeSDWA ().run (MF);
1248+ }
1249+
1250+ bool SIPeepholeSDWA::run (MachineFunction &MF) {
12391251 const GCNSubtarget &ST = MF.getSubtarget <GCNSubtarget>();
12401252
1241- if (!ST.hasSDWA () || skipFunction (MF. getFunction ()) )
1253+ if (!ST.hasSDWA ())
12421254 return false ;
12431255
12441256 MRI = &MF.getRegInfo ();
@@ -1295,3 +1307,13 @@ bool SIPeepholeSDWA::runOnMachineFunction(MachineFunction &MF) {
12951307
12961308 return Ret;
12971309}
1310+
1311+ PreservedAnalyses SIPeepholeSDWAPass::run (MachineFunction &MF,
1312+ MachineFunctionAnalysisManager &) {
1313+ if (MF.getFunction ().hasOptNone () || !SIPeepholeSDWA ().run (MF))
1314+ return PreservedAnalyses::all ();
1315+
1316+ PreservedAnalyses PA = getMachineFunctionPassPreservedAnalyses ();
1317+ PA.preserveSet <CFGAnalyses>();
1318+ return PA;
1319+ }
0 commit comments