Skip to content

Commit a5924ee

Browse files
vpykhtinakadutta
authored andcommitted
[AMDGPU] Improve StructurizeCFG pass performance by using SSAUpdaterBulk. (llvm#150937)
SSAUpdaterBulk replaces legacy SSAUpdater.
1 parent 6f3ad68 commit a5924ee

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

llvm/lib/Transforms/Scalar/StructurizeCFG.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
4848
#include "llvm/Transforms/Utils/Local.h"
4949
#include "llvm/Transforms/Utils/SSAUpdater.h"
50+
#include "llvm/Transforms/Utils/SSAUpdaterBulk.h"
5051
#include <cassert>
5152
#include <utility>
5253

@@ -321,7 +322,7 @@ class StructurizeCFG {
321322

322323
void collectInfos();
323324

324-
void insertConditions(bool Loops);
325+
void insertConditions(bool Loops, SSAUpdaterBulk &PhiInserter);
325326

326327
void simplifyConditions();
327328

@@ -671,10 +672,9 @@ void StructurizeCFG::collectInfos() {
671672
}
672673

673674
/// Insert the missing branch conditions
674-
void StructurizeCFG::insertConditions(bool Loops) {
675+
void StructurizeCFG::insertConditions(bool Loops, SSAUpdaterBulk &PhiInserter) {
675676
BranchVector &Conds = Loops ? LoopConds : Conditions;
676677
Value *Default = Loops ? BoolTrue : BoolFalse;
677-
SSAUpdater PhiInserter;
678678

679679
for (BranchInst *Term : Conds) {
680680
assert(Term->isConditional());
@@ -683,8 +683,9 @@ void StructurizeCFG::insertConditions(bool Loops) {
683683
BasicBlock *SuccTrue = Term->getSuccessor(0);
684684
BasicBlock *SuccFalse = Term->getSuccessor(1);
685685

686-
PhiInserter.Initialize(Boolean, "");
687-
PhiInserter.AddAvailableValue(Loops ? SuccFalse : Parent, Default);
686+
unsigned Variable = PhiInserter.AddVariable("", Boolean);
687+
PhiInserter.AddAvailableValue(Variable, Loops ? SuccFalse : Parent,
688+
Default);
688689

689690
BBPredicates &Preds = Loops ? LoopPreds[SuccFalse] : Predicates[SuccTrue];
690691

@@ -697,7 +698,7 @@ void StructurizeCFG::insertConditions(bool Loops) {
697698
ParentInfo = PI;
698699
break;
699700
}
700-
PhiInserter.AddAvailableValue(BB, PI.Pred);
701+
PhiInserter.AddAvailableValue(Variable, BB, PI.Pred);
701702
Dominator.addAndRememberBlock(BB);
702703
}
703704

@@ -706,9 +707,9 @@ void StructurizeCFG::insertConditions(bool Loops) {
706707
CondBranchWeights::setMetadata(*Term, ParentInfo.Weights);
707708
} else {
708709
if (!Dominator.resultIsRememberedBlock())
709-
PhiInserter.AddAvailableValue(Dominator.result(), Default);
710+
PhiInserter.AddAvailableValue(Variable, Dominator.result(), Default);
710711

711-
Term->setCondition(PhiInserter.GetValueInMiddleOfBlock(Parent));
712+
PhiInserter.AddUse(Variable, &Term->getOperandUse(0));
712713
}
713714
}
714715
}
@@ -1414,8 +1415,12 @@ bool StructurizeCFG::run(Region *R, DominatorTree *DT,
14141415
orderNodes();
14151416
collectInfos();
14161417
createFlow();
1417-
insertConditions(false);
1418-
insertConditions(true);
1418+
1419+
SSAUpdaterBulk PhiInserter;
1420+
insertConditions(false, PhiInserter);
1421+
insertConditions(true, PhiInserter);
1422+
PhiInserter.RewriteAndOptimizeAllUses(*DT);
1423+
14191424
setPhiValues();
14201425
simplifyHoistedPhis();
14211426
simplifyConditions();

0 commit comments

Comments
 (0)