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