Skip to content

Commit 1df8ccd

Browse files
authored
Revert "[NFC][EarlyIfConverter] Turn SSAIfConv into a local variable (#107390)" (#111385)
This reverts commit 09a4c23.
1 parent f658c1b commit 1df8ccd

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

llvm/lib/CodeGen/EarlyIfConversion.cpp

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ class SSAIfConv {
163163
void rewritePHIOperands();
164164

165165
public:
166-
SSAIfConv(MachineFunction &MF) {
166+
/// runOnMachineFunction - Initialize per-function data structures.
167+
void runOnMachineFunction(MachineFunction &MF) {
167168
TII = MF.getSubtarget().getInstrInfo();
168169
TRI = MF.getSubtarget().getRegisterInfo();
169170
MRI = &MF.getRegInfo();
@@ -768,6 +769,7 @@ class EarlyIfConverter : public MachineFunctionPass {
768769
MachineLoopInfo *Loops = nullptr;
769770
MachineTraceMetrics *Traces = nullptr;
770771
MachineTraceMetrics::Ensemble *MinInstr = nullptr;
772+
SSAIfConv IfConv;
771773

772774
public:
773775
static char ID;
@@ -777,9 +779,9 @@ class EarlyIfConverter : public MachineFunctionPass {
777779
StringRef getPassName() const override { return "Early If-Conversion"; }
778780

779781
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();
783785
};
784786
} // end anonymous namespace
785787

@@ -835,7 +837,7 @@ void updateLoops(MachineLoopInfo *Loops,
835837
} // namespace
836838

837839
/// Invalidate MachineTraceMetrics before if-conversion.
838-
void EarlyIfConverter::invalidateTraces(SSAIfConv &IfConv) {
840+
void EarlyIfConverter::invalidateTraces() {
839841
Traces->verifyAnalysis();
840842
Traces->invalidate(IfConv.Head);
841843
Traces->invalidate(IfConv.Tail);
@@ -865,7 +867,7 @@ template <typename Remark> Remark &operator<<(Remark &R, Cycles C) {
865867
/// Apply cost model and heuristics to the if-conversion in IfConv.
866868
/// Return true if the conversion is a good idea.
867869
///
868-
bool EarlyIfConverter::shouldConvertIf(SSAIfConv &IfConv) {
870+
bool EarlyIfConverter::shouldConvertIf() {
869871
// Stress testing mode disables all cost considerations.
870872
if (Stress)
871873
return true;
@@ -1058,11 +1060,11 @@ bool EarlyIfConverter::shouldConvertIf(SSAIfConv &IfConv) {
10581060

10591061
/// Attempt repeated if-conversion on MBB, return true if successful.
10601062
///
1061-
bool EarlyIfConverter::tryConvertIf(SSAIfConv &IfConv, MachineBasicBlock *MBB) {
1063+
bool EarlyIfConverter::tryConvertIf(MachineBasicBlock *MBB) {
10621064
bool Changed = false;
1063-
while (IfConv.canConvertIf(MBB) && shouldConvertIf(IfConv)) {
1065+
while (IfConv.canConvertIf(MBB) && shouldConvertIf()) {
10641066
// If-convert MBB and update analyses.
1065-
invalidateTraces(IfConv);
1067+
invalidateTraces();
10661068
SmallVector<MachineBasicBlock *, 4> RemoveBlocks;
10671069
IfConv.convertIf(RemoveBlocks);
10681070
Changed = true;
@@ -1095,14 +1097,14 @@ bool EarlyIfConverter::runOnMachineFunction(MachineFunction &MF) {
10951097
MinInstr = nullptr;
10961098

10971099
bool Changed = false;
1098-
SSAIfConv IfConv(MF);
1100+
IfConv.runOnMachineFunction(MF);
10991101

11001102
// Visit blocks in dominator tree post-order. The post-order enables nested
11011103
// if-conversion in a single pass. The tryConvertIf() function may erase
11021104
// blocks, but only blocks dominated by the head block. This makes it safe to
11031105
// update the dominator tree while the post-order iterator is still active.
11041106
for (auto *DomNode : post_order(DomTree))
1105-
if (tryConvertIf(IfConv, DomNode->getBlock()))
1107+
if (tryConvertIf(DomNode->getBlock()))
11061108
Changed = true;
11071109

11081110
return Changed;
@@ -1121,6 +1123,7 @@ class EarlyIfPredicator : public MachineFunctionPass {
11211123
MachineDominatorTree *DomTree = nullptr;
11221124
MachineBranchProbabilityInfo *MBPI = nullptr;
11231125
MachineLoopInfo *Loops = nullptr;
1126+
SSAIfConv IfConv;
11241127

11251128
public:
11261129
static char ID;
@@ -1130,8 +1133,8 @@ class EarlyIfPredicator : public MachineFunctionPass {
11301133
StringRef getPassName() const override { return "Early If-predicator"; }
11311134

11321135
protected:
1133-
bool tryConvertIf(SSAIfConv &IfConv, MachineBasicBlock *);
1134-
bool shouldConvertIf(SSAIfConv &IfConv);
1136+
bool tryConvertIf(MachineBasicBlock *);
1137+
bool shouldConvertIf();
11351138
};
11361139
} // end anonymous namespace
11371140

@@ -1158,7 +1161,7 @@ void EarlyIfPredicator::getAnalysisUsage(AnalysisUsage &AU) const {
11581161
}
11591162

11601163
/// Apply the target heuristic to decide if the transformation is profitable.
1161-
bool EarlyIfPredicator::shouldConvertIf(SSAIfConv &IfConv) {
1164+
bool EarlyIfPredicator::shouldConvertIf() {
11621165
auto TrueProbability = MBPI->getEdgeProbability(IfConv.Head, IfConv.TBB);
11631166
if (IfConv.isTriangle()) {
11641167
MachineBasicBlock &IfBlock =
@@ -1198,14 +1201,12 @@ bool EarlyIfPredicator::shouldConvertIf(SSAIfConv &IfConv) {
11981201

11991202
/// Attempt repeated if-conversion on MBB, return true if successful.
12001203
///
1201-
bool EarlyIfPredicator::tryConvertIf(SSAIfConv &IfConv,
1202-
MachineBasicBlock *MBB) {
1204+
bool EarlyIfPredicator::tryConvertIf(MachineBasicBlock *MBB) {
12031205
bool Changed = false;
1204-
while (IfConv.canConvertIf(MBB, /*Predicate=*/true) &&
1205-
shouldConvertIf(IfConv)) {
1206+
while (IfConv.canConvertIf(MBB, /*Predicate*/ true) && shouldConvertIf()) {
12061207
// If-convert MBB and update analyses.
12071208
SmallVector<MachineBasicBlock *, 4> RemoveBlocks;
1208-
IfConv.convertIf(RemoveBlocks, /*Predicate=*/true);
1209+
IfConv.convertIf(RemoveBlocks, /*Predicate*/ true);
12091210
Changed = true;
12101211
updateDomTree(DomTree, IfConv, RemoveBlocks);
12111212
for (MachineBasicBlock *MBB : RemoveBlocks)
@@ -1231,14 +1232,14 @@ bool EarlyIfPredicator::runOnMachineFunction(MachineFunction &MF) {
12311232
MBPI = &getAnalysis<MachineBranchProbabilityInfoWrapperPass>().getMBPI();
12321233

12331234
bool Changed = false;
1234-
SSAIfConv IfConv(MF);
1235+
IfConv.runOnMachineFunction(MF);
12351236

12361237
// Visit blocks in dominator tree post-order. The post-order enables nested
12371238
// if-conversion in a single pass. The tryConvertIf() function may erase
12381239
// blocks, but only blocks dominated by the head block. This makes it safe to
12391240
// update the dominator tree while the post-order iterator is still active.
12401241
for (auto *DomNode : post_order(DomTree))
1241-
if (tryConvertIf(IfConv, DomNode->getBlock()))
1242+
if (tryConvertIf(DomNode->getBlock()))
12421243
Changed = true;
12431244

12441245
return Changed;

0 commit comments

Comments
 (0)