@@ -163,7 +163,8 @@ class SSAIfConv {
163
163
void rewritePHIOperands ();
164
164
165
165
public:
166
- SSAIfConv (MachineFunction &MF) {
166
+ // / runOnMachineFunction - Initialize per-function data structures.
167
+ void runOnMachineFunction (MachineFunction &MF) {
167
168
TII = MF.getSubtarget ().getInstrInfo ();
168
169
TRI = MF.getSubtarget ().getRegisterInfo ();
169
170
MRI = &MF.getRegInfo ();
@@ -768,6 +769,7 @@ class EarlyIfConverter : public MachineFunctionPass {
768
769
MachineLoopInfo *Loops = nullptr ;
769
770
MachineTraceMetrics *Traces = nullptr ;
770
771
MachineTraceMetrics::Ensemble *MinInstr = nullptr ;
772
+ SSAIfConv IfConv;
771
773
772
774
public:
773
775
static char ID;
@@ -777,9 +779,9 @@ class EarlyIfConverter : public MachineFunctionPass {
777
779
StringRef getPassName () const override { return " Early If-Conversion" ; }
778
780
779
781
private:
780
- bool tryConvertIf (SSAIfConv &IfConv, MachineBasicBlock *);
781
- void invalidateTraces (SSAIfConv &IfConv );
782
- bool shouldConvertIf (SSAIfConv &IfConv );
782
+ bool tryConvertIf (MachineBasicBlock *);
783
+ void invalidateTraces ();
784
+ bool shouldConvertIf ();
783
785
};
784
786
} // end anonymous namespace
785
787
@@ -835,7 +837,7 @@ void updateLoops(MachineLoopInfo *Loops,
835
837
} // namespace
836
838
837
839
// / Invalidate MachineTraceMetrics before if-conversion.
838
- void EarlyIfConverter::invalidateTraces (SSAIfConv &IfConv ) {
840
+ void EarlyIfConverter::invalidateTraces () {
839
841
Traces->verifyAnalysis ();
840
842
Traces->invalidate (IfConv.Head );
841
843
Traces->invalidate (IfConv.Tail );
@@ -865,7 +867,7 @@ template <typename Remark> Remark &operator<<(Remark &R, Cycles C) {
865
867
// / Apply cost model and heuristics to the if-conversion in IfConv.
866
868
// / Return true if the conversion is a good idea.
867
869
// /
868
- bool EarlyIfConverter::shouldConvertIf (SSAIfConv &IfConv ) {
870
+ bool EarlyIfConverter::shouldConvertIf () {
869
871
// Stress testing mode disables all cost considerations.
870
872
if (Stress)
871
873
return true ;
@@ -1058,11 +1060,11 @@ bool EarlyIfConverter::shouldConvertIf(SSAIfConv &IfConv) {
1058
1060
1059
1061
// / Attempt repeated if-conversion on MBB, return true if successful.
1060
1062
// /
1061
- bool EarlyIfConverter::tryConvertIf (SSAIfConv &IfConv, MachineBasicBlock *MBB) {
1063
+ bool EarlyIfConverter::tryConvertIf (MachineBasicBlock *MBB) {
1062
1064
bool Changed = false ;
1063
- while (IfConv.canConvertIf (MBB) && shouldConvertIf (IfConv )) {
1065
+ while (IfConv.canConvertIf (MBB) && shouldConvertIf ()) {
1064
1066
// If-convert MBB and update analyses.
1065
- invalidateTraces (IfConv );
1067
+ invalidateTraces ();
1066
1068
SmallVector<MachineBasicBlock *, 4 > RemoveBlocks;
1067
1069
IfConv.convertIf (RemoveBlocks);
1068
1070
Changed = true ;
@@ -1095,14 +1097,14 @@ bool EarlyIfConverter::runOnMachineFunction(MachineFunction &MF) {
1095
1097
MinInstr = nullptr ;
1096
1098
1097
1099
bool Changed = false ;
1098
- SSAIfConv IfConv (MF);
1100
+ IfConv. runOnMachineFunction (MF);
1099
1101
1100
1102
// Visit blocks in dominator tree post-order. The post-order enables nested
1101
1103
// if-conversion in a single pass. The tryConvertIf() function may erase
1102
1104
// blocks, but only blocks dominated by the head block. This makes it safe to
1103
1105
// update the dominator tree while the post-order iterator is still active.
1104
1106
for (auto *DomNode : post_order (DomTree))
1105
- if (tryConvertIf (IfConv, DomNode->getBlock ()))
1107
+ if (tryConvertIf (DomNode->getBlock ()))
1106
1108
Changed = true ;
1107
1109
1108
1110
return Changed;
@@ -1121,6 +1123,7 @@ class EarlyIfPredicator : public MachineFunctionPass {
1121
1123
MachineDominatorTree *DomTree = nullptr ;
1122
1124
MachineBranchProbabilityInfo *MBPI = nullptr ;
1123
1125
MachineLoopInfo *Loops = nullptr ;
1126
+ SSAIfConv IfConv;
1124
1127
1125
1128
public:
1126
1129
static char ID;
@@ -1130,8 +1133,8 @@ class EarlyIfPredicator : public MachineFunctionPass {
1130
1133
StringRef getPassName () const override { return " Early If-predicator" ; }
1131
1134
1132
1135
protected:
1133
- bool tryConvertIf (SSAIfConv &IfConv, MachineBasicBlock *);
1134
- bool shouldConvertIf (SSAIfConv &IfConv );
1136
+ bool tryConvertIf (MachineBasicBlock *);
1137
+ bool shouldConvertIf ();
1135
1138
};
1136
1139
} // end anonymous namespace
1137
1140
@@ -1158,7 +1161,7 @@ void EarlyIfPredicator::getAnalysisUsage(AnalysisUsage &AU) const {
1158
1161
}
1159
1162
1160
1163
// / Apply the target heuristic to decide if the transformation is profitable.
1161
- bool EarlyIfPredicator::shouldConvertIf (SSAIfConv &IfConv ) {
1164
+ bool EarlyIfPredicator::shouldConvertIf () {
1162
1165
auto TrueProbability = MBPI->getEdgeProbability (IfConv.Head , IfConv.TBB );
1163
1166
if (IfConv.isTriangle ()) {
1164
1167
MachineBasicBlock &IfBlock =
@@ -1198,14 +1201,12 @@ bool EarlyIfPredicator::shouldConvertIf(SSAIfConv &IfConv) {
1198
1201
1199
1202
// / Attempt repeated if-conversion on MBB, return true if successful.
1200
1203
// /
1201
- bool EarlyIfPredicator::tryConvertIf (SSAIfConv &IfConv,
1202
- MachineBasicBlock *MBB) {
1204
+ bool EarlyIfPredicator::tryConvertIf (MachineBasicBlock *MBB) {
1203
1205
bool Changed = false ;
1204
- while (IfConv.canConvertIf (MBB, /* Predicate=*/ true ) &&
1205
- shouldConvertIf (IfConv)) {
1206
+ while (IfConv.canConvertIf (MBB, /* Predicate*/ true ) && shouldConvertIf ()) {
1206
1207
// If-convert MBB and update analyses.
1207
1208
SmallVector<MachineBasicBlock *, 4 > RemoveBlocks;
1208
- IfConv.convertIf (RemoveBlocks, /* Predicate= */ true );
1209
+ IfConv.convertIf (RemoveBlocks, /* Predicate*/ true );
1209
1210
Changed = true ;
1210
1211
updateDomTree (DomTree, IfConv, RemoveBlocks);
1211
1212
for (MachineBasicBlock *MBB : RemoveBlocks)
@@ -1231,14 +1232,14 @@ bool EarlyIfPredicator::runOnMachineFunction(MachineFunction &MF) {
1231
1232
MBPI = &getAnalysis<MachineBranchProbabilityInfoWrapperPass>().getMBPI ();
1232
1233
1233
1234
bool Changed = false ;
1234
- SSAIfConv IfConv (MF);
1235
+ IfConv. runOnMachineFunction (MF);
1235
1236
1236
1237
// Visit blocks in dominator tree post-order. The post-order enables nested
1237
1238
// if-conversion in a single pass. The tryConvertIf() function may erase
1238
1239
// blocks, but only blocks dominated by the head block. This makes it safe to
1239
1240
// update the dominator tree while the post-order iterator is still active.
1240
1241
for (auto *DomNode : post_order (DomTree))
1241
- if (tryConvertIf (IfConv, DomNode->getBlock ()))
1242
+ if (tryConvertIf (DomNode->getBlock ()))
1242
1243
Changed = true ;
1243
1244
1244
1245
return Changed;
0 commit comments