@@ -163,8 +163,7 @@ class SSAIfConv {
163163 void rewritePHIOperands ();
164164
165165public:
166- // / runOnMachineFunction - Initialize per-function data structures.
167- void runOnMachineFunction (MachineFunction &MF) {
166+ SSAIfConv (MachineFunction &MF) {
168167 TII = MF.getSubtarget ().getInstrInfo ();
169168 TRI = MF.getSubtarget ().getRegisterInfo ();
170169 MRI = &MF.getRegInfo ();
@@ -770,7 +769,6 @@ class EarlyIfConverter : public MachineFunctionPass {
770769 MachineLoopInfo *Loops = nullptr ;
771770 MachineTraceMetrics *Traces = nullptr ;
772771 MachineTraceMetrics::Ensemble *MinInstr = nullptr ;
773- SSAIfConv IfConv;
774772
775773public:
776774 static char ID;
@@ -780,9 +778,9 @@ class EarlyIfConverter : public MachineFunctionPass {
780778 StringRef getPassName () const override { return " Early If-Conversion" ; }
781779
782780private:
783- bool tryConvertIf (MachineBasicBlock*);
784- void invalidateTraces ();
785- bool shouldConvertIf ();
781+ bool tryConvertIf (SSAIfConv &IfConv, MachineBasicBlock *);
782+ void invalidateTraces (SSAIfConv &IfConv );
783+ bool shouldConvertIf (SSAIfConv &IfConv );
786784};
787785} // end anonymous namespace
788786
@@ -838,7 +836,7 @@ void updateLoops(MachineLoopInfo *Loops,
838836} // namespace
839837
840838// / Invalidate MachineTraceMetrics before if-conversion.
841- void EarlyIfConverter::invalidateTraces () {
839+ void EarlyIfConverter::invalidateTraces (SSAIfConv &IfConv ) {
842840 Traces->verifyAnalysis ();
843841 Traces->invalidate (IfConv.Head );
844842 Traces->invalidate (IfConv.Tail );
@@ -868,7 +866,7 @@ template <typename Remark> Remark &operator<<(Remark &R, Cycles C) {
868866// / Apply cost model and heuristics to the if-conversion in IfConv.
869867// / Return true if the conversion is a good idea.
870868// /
871- bool EarlyIfConverter::shouldConvertIf () {
869+ bool EarlyIfConverter::shouldConvertIf (SSAIfConv &IfConv ) {
872870 // Stress testing mode disables all cost considerations.
873871 if (Stress)
874872 return true ;
@@ -1061,11 +1059,11 @@ bool EarlyIfConverter::shouldConvertIf() {
10611059
10621060// / Attempt repeated if-conversion on MBB, return true if successful.
10631061// /
1064- bool EarlyIfConverter::tryConvertIf (MachineBasicBlock *MBB) {
1062+ bool EarlyIfConverter::tryConvertIf (SSAIfConv &IfConv, MachineBasicBlock *MBB) {
10651063 bool Changed = false ;
1066- while (IfConv.canConvertIf (MBB) && shouldConvertIf ()) {
1064+ while (IfConv.canConvertIf (MBB) && shouldConvertIf (IfConv )) {
10671065 // If-convert MBB and update analyses.
1068- invalidateTraces ();
1066+ invalidateTraces (IfConv );
10691067 SmallVector<MachineBasicBlock *, 4 > RemoveBlocks;
10701068 IfConv.convertIf (RemoveBlocks);
10711069 Changed = true ;
@@ -1098,14 +1096,14 @@ bool EarlyIfConverter::runOnMachineFunction(MachineFunction &MF) {
10981096 MinInstr = nullptr ;
10991097
11001098 bool Changed = false ;
1101- IfConv. runOnMachineFunction (MF);
1099+ SSAIfConv IfConv (MF);
11021100
11031101 // Visit blocks in dominator tree post-order. The post-order enables nested
11041102 // if-conversion in a single pass. The tryConvertIf() function may erase
11051103 // blocks, but only blocks dominated by the head block. This makes it safe to
11061104 // update the dominator tree while the post-order iterator is still active.
11071105 for (auto *DomNode : post_order (DomTree))
1108- if (tryConvertIf (DomNode->getBlock ()))
1106+ if (tryConvertIf (IfConv, DomNode->getBlock ()))
11091107 Changed = true ;
11101108
11111109 return Changed;
@@ -1124,7 +1122,6 @@ class EarlyIfPredicator : public MachineFunctionPass {
11241122 MachineDominatorTree *DomTree = nullptr ;
11251123 MachineBranchProbabilityInfo *MBPI = nullptr ;
11261124 MachineLoopInfo *Loops = nullptr ;
1127- SSAIfConv IfConv;
11281125
11291126public:
11301127 static char ID;
@@ -1134,8 +1131,8 @@ class EarlyIfPredicator : public MachineFunctionPass {
11341131 StringRef getPassName () const override { return " Early If-predicator" ; }
11351132
11361133protected:
1137- bool tryConvertIf (MachineBasicBlock *);
1138- bool shouldConvertIf ();
1134+ bool tryConvertIf (SSAIfConv &IfConv, MachineBasicBlock *);
1135+ bool shouldConvertIf (SSAIfConv &IfConv );
11391136};
11401137} // end anonymous namespace
11411138
@@ -1162,7 +1159,7 @@ void EarlyIfPredicator::getAnalysisUsage(AnalysisUsage &AU) const {
11621159}
11631160
11641161// / Apply the target heuristic to decide if the transformation is profitable.
1165- bool EarlyIfPredicator::shouldConvertIf () {
1162+ bool EarlyIfPredicator::shouldConvertIf (SSAIfConv &IfConv ) {
11661163 auto TrueProbability = MBPI->getEdgeProbability (IfConv.Head , IfConv.TBB );
11671164 if (IfConv.isTriangle ()) {
11681165 MachineBasicBlock &IfBlock =
@@ -1202,12 +1199,14 @@ bool EarlyIfPredicator::shouldConvertIf() {
12021199
12031200// / Attempt repeated if-conversion on MBB, return true if successful.
12041201// /
1205- bool EarlyIfPredicator::tryConvertIf (MachineBasicBlock *MBB) {
1202+ bool EarlyIfPredicator::tryConvertIf (SSAIfConv &IfConv,
1203+ MachineBasicBlock *MBB) {
12061204 bool Changed = false ;
1207- while (IfConv.canConvertIf (MBB, /* Predicate*/ true ) && shouldConvertIf ()) {
1205+ while (IfConv.canConvertIf (MBB, /* Predicate=*/ true ) &&
1206+ shouldConvertIf (IfConv)) {
12081207 // If-convert MBB and update analyses.
12091208 SmallVector<MachineBasicBlock *, 4 > RemoveBlocks;
1210- IfConv.convertIf (RemoveBlocks, /* Predicate*/ true );
1209+ IfConv.convertIf (RemoveBlocks, /* Predicate= */ true );
12111210 Changed = true ;
12121211 updateDomTree (DomTree, IfConv, RemoveBlocks);
12131212 for (MachineBasicBlock *MBB : RemoveBlocks)
@@ -1233,14 +1232,14 @@ bool EarlyIfPredicator::runOnMachineFunction(MachineFunction &MF) {
12331232 MBPI = &getAnalysis<MachineBranchProbabilityInfoWrapperPass>().getMBPI ();
12341233
12351234 bool Changed = false ;
1236- IfConv. runOnMachineFunction (MF);
1235+ SSAIfConv IfConv (MF);
12371236
12381237 // Visit blocks in dominator tree post-order. The post-order enables nested
12391238 // if-conversion in a single pass. The tryConvertIf() function may erase
12401239 // blocks, but only blocks dominated by the head block. This makes it safe to
12411240 // update the dominator tree while the post-order iterator is still active.
12421241 for (auto *DomNode : post_order (DomTree))
1243- if (tryConvertIf (DomNode->getBlock ()))
1242+ if (tryConvertIf (IfConv, DomNode->getBlock ()))
12441243 Changed = true ;
12451244
12461245 return Changed;
0 commit comments