[llvm] Revert "[NFC][EarlyIfConverter] Turn SSAIfConv into a local variable (#107390)" (PR #111385)
Juan Manuel Martinez CaamaƱo via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 7 07:20:04 PDT 2024
https://github.com/jmmartinez created https://github.com/llvm/llvm-project/pull/111385
This reverts commit 09a4c23eb410d4be52202bed21c967a3653c3544.
>From 8de9a3a8511f775ee7b1f4e6810543cbd8ed972f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Juan=20Manuel=20Martinez=20Caama=C3=B1o?= <juamarti at amd.com>
Date: Mon, 7 Oct 2024 16:04:24 +0200
Subject: [PATCH] Revert "[NFC][EarlyIfConverter] Turn SSAIfConv into a local
variable (#107390)"
This reverts commit 09a4c23eb410d4be52202bed21c967a3653c3544.
---
llvm/lib/CodeGen/EarlyIfConversion.cpp | 43 +++++++++++++-------------
1 file changed, 22 insertions(+), 21 deletions(-)
diff --git a/llvm/lib/CodeGen/EarlyIfConversion.cpp b/llvm/lib/CodeGen/EarlyIfConversion.cpp
index c827d5bdcf55ba..6ed75861d85109 100644
--- a/llvm/lib/CodeGen/EarlyIfConversion.cpp
+++ b/llvm/lib/CodeGen/EarlyIfConversion.cpp
@@ -163,7 +163,8 @@ class SSAIfConv {
void rewritePHIOperands();
public:
- SSAIfConv(MachineFunction &MF) {
+ /// runOnMachineFunction - Initialize per-function data structures.
+ void runOnMachineFunction(MachineFunction &MF) {
TII = MF.getSubtarget().getInstrInfo();
TRI = MF.getSubtarget().getRegisterInfo();
MRI = &MF.getRegInfo();
@@ -768,6 +769,7 @@ class EarlyIfConverter : public MachineFunctionPass {
MachineLoopInfo *Loops = nullptr;
MachineTraceMetrics *Traces = nullptr;
MachineTraceMetrics::Ensemble *MinInstr = nullptr;
+ SSAIfConv IfConv;
public:
static char ID;
@@ -777,9 +779,9 @@ class EarlyIfConverter : public MachineFunctionPass {
StringRef getPassName() const override { return "Early If-Conversion"; }
private:
- bool tryConvertIf(SSAIfConv &IfConv, MachineBasicBlock *);
- void invalidateTraces(SSAIfConv &IfConv);
- bool shouldConvertIf(SSAIfConv &IfConv);
+ bool tryConvertIf(MachineBasicBlock *);
+ void invalidateTraces();
+ bool shouldConvertIf();
};
} // end anonymous namespace
@@ -835,7 +837,7 @@ void updateLoops(MachineLoopInfo *Loops,
} // namespace
/// Invalidate MachineTraceMetrics before if-conversion.
-void EarlyIfConverter::invalidateTraces(SSAIfConv &IfConv) {
+void EarlyIfConverter::invalidateTraces() {
Traces->verifyAnalysis();
Traces->invalidate(IfConv.Head);
Traces->invalidate(IfConv.Tail);
@@ -865,7 +867,7 @@ template <typename Remark> Remark &operator<<(Remark &R, Cycles C) {
/// Apply cost model and heuristics to the if-conversion in IfConv.
/// Return true if the conversion is a good idea.
///
-bool EarlyIfConverter::shouldConvertIf(SSAIfConv &IfConv) {
+bool EarlyIfConverter::shouldConvertIf() {
// Stress testing mode disables all cost considerations.
if (Stress)
return true;
@@ -1058,11 +1060,11 @@ bool EarlyIfConverter::shouldConvertIf(SSAIfConv &IfConv) {
/// Attempt repeated if-conversion on MBB, return true if successful.
///
-bool EarlyIfConverter::tryConvertIf(SSAIfConv &IfConv, MachineBasicBlock *MBB) {
+bool EarlyIfConverter::tryConvertIf(MachineBasicBlock *MBB) {
bool Changed = false;
- while (IfConv.canConvertIf(MBB) && shouldConvertIf(IfConv)) {
+ while (IfConv.canConvertIf(MBB) && shouldConvertIf()) {
// If-convert MBB and update analyses.
- invalidateTraces(IfConv);
+ invalidateTraces();
SmallVector<MachineBasicBlock *, 4> RemoveBlocks;
IfConv.convertIf(RemoveBlocks);
Changed = true;
@@ -1095,14 +1097,14 @@ bool EarlyIfConverter::runOnMachineFunction(MachineFunction &MF) {
MinInstr = nullptr;
bool Changed = false;
- SSAIfConv IfConv(MF);
+ IfConv.runOnMachineFunction(MF);
// Visit blocks in dominator tree post-order. The post-order enables nested
// if-conversion in a single pass. The tryConvertIf() function may erase
// blocks, but only blocks dominated by the head block. This makes it safe to
// update the dominator tree while the post-order iterator is still active.
for (auto *DomNode : post_order(DomTree))
- if (tryConvertIf(IfConv, DomNode->getBlock()))
+ if (tryConvertIf(DomNode->getBlock()))
Changed = true;
return Changed;
@@ -1121,6 +1123,7 @@ class EarlyIfPredicator : public MachineFunctionPass {
MachineDominatorTree *DomTree = nullptr;
MachineBranchProbabilityInfo *MBPI = nullptr;
MachineLoopInfo *Loops = nullptr;
+ SSAIfConv IfConv;
public:
static char ID;
@@ -1130,8 +1133,8 @@ class EarlyIfPredicator : public MachineFunctionPass {
StringRef getPassName() const override { return "Early If-predicator"; }
protected:
- bool tryConvertIf(SSAIfConv &IfConv, MachineBasicBlock *);
- bool shouldConvertIf(SSAIfConv &IfConv);
+ bool tryConvertIf(MachineBasicBlock *);
+ bool shouldConvertIf();
};
} // end anonymous namespace
@@ -1158,7 +1161,7 @@ void EarlyIfPredicator::getAnalysisUsage(AnalysisUsage &AU) const {
}
/// Apply the target heuristic to decide if the transformation is profitable.
-bool EarlyIfPredicator::shouldConvertIf(SSAIfConv &IfConv) {
+bool EarlyIfPredicator::shouldConvertIf() {
auto TrueProbability = MBPI->getEdgeProbability(IfConv.Head, IfConv.TBB);
if (IfConv.isTriangle()) {
MachineBasicBlock &IfBlock =
@@ -1198,14 +1201,12 @@ bool EarlyIfPredicator::shouldConvertIf(SSAIfConv &IfConv) {
/// Attempt repeated if-conversion on MBB, return true if successful.
///
-bool EarlyIfPredicator::tryConvertIf(SSAIfConv &IfConv,
- MachineBasicBlock *MBB) {
+bool EarlyIfPredicator::tryConvertIf(MachineBasicBlock *MBB) {
bool Changed = false;
- while (IfConv.canConvertIf(MBB, /*Predicate=*/true) &&
- shouldConvertIf(IfConv)) {
+ while (IfConv.canConvertIf(MBB, /*Predicate*/ true) && shouldConvertIf()) {
// If-convert MBB and update analyses.
SmallVector<MachineBasicBlock *, 4> RemoveBlocks;
- IfConv.convertIf(RemoveBlocks, /*Predicate=*/true);
+ IfConv.convertIf(RemoveBlocks, /*Predicate*/ true);
Changed = true;
updateDomTree(DomTree, IfConv, RemoveBlocks);
for (MachineBasicBlock *MBB : RemoveBlocks)
@@ -1231,14 +1232,14 @@ bool EarlyIfPredicator::runOnMachineFunction(MachineFunction &MF) {
MBPI = &getAnalysis<MachineBranchProbabilityInfoWrapperPass>().getMBPI();
bool Changed = false;
- SSAIfConv IfConv(MF);
+ IfConv.runOnMachineFunction(MF);
// Visit blocks in dominator tree post-order. The post-order enables nested
// if-conversion in a single pass. The tryConvertIf() function may erase
// blocks, but only blocks dominated by the head block. This makes it safe to
// update the dominator tree while the post-order iterator is still active.
for (auto *DomNode : post_order(DomTree))
- if (tryConvertIf(IfConv, DomNode->getBlock()))
+ if (tryConvertIf(DomNode->getBlock()))
Changed = true;
return Changed;
More information about the llvm-commits
mailing list