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
@@ -317,7 +318,7 @@ class StructurizeCFG {
317318
318319 void collectInfos ();
319320
320- void insertConditions (bool Loops);
321+ void insertConditions (bool Loops, SSAUpdaterBulk &PhiInserter );
321322
322323 void simplifyConditions ();
323324
@@ -600,10 +601,9 @@ void StructurizeCFG::collectInfos() {
600601}
601602
602603// / Insert the missing branch conditions
603- void StructurizeCFG::insertConditions (bool Loops) {
604+ void StructurizeCFG::insertConditions (bool Loops, SSAUpdaterBulk &PhiInserter ) {
604605 BranchVector &Conds = Loops ? LoopConds : Conditions;
605606 Value *Default = Loops ? BoolTrue : BoolFalse;
606- SSAUpdater PhiInserter;
607607
608608 for (BranchInst *Term : Conds) {
609609 assert (Term->isConditional ());
@@ -612,8 +612,9 @@ void StructurizeCFG::insertConditions(bool Loops) {
612612 BasicBlock *SuccTrue = Term->getSuccessor (0 );
613613 BasicBlock *SuccFalse = Term->getSuccessor (1 );
614614
615- PhiInserter.Initialize (Boolean, " " );
616- PhiInserter.AddAvailableValue (Loops ? SuccFalse : Parent, Default);
615+ unsigned Variable = PhiInserter.AddVariable (" " , Boolean);
616+ PhiInserter.AddAvailableValue (Variable, Loops ? SuccFalse : Parent,
617+ Default);
617618
618619 BBPredicates &Preds = Loops ? LoopPreds[SuccFalse] : Predicates[SuccTrue];
619620
@@ -626,7 +627,7 @@ void StructurizeCFG::insertConditions(bool Loops) {
626627 ParentInfo = PI;
627628 break ;
628629 }
629- PhiInserter.AddAvailableValue (BB, PI.Pred );
630+ PhiInserter.AddAvailableValue (Variable, BB, PI.Pred );
630631 Dominator.addAndRememberBlock (BB);
631632 }
632633
@@ -635,9 +636,9 @@ void StructurizeCFG::insertConditions(bool Loops) {
635636 CondBranchWeights::setMetadata (*Term, ParentInfo.Weights );
636637 } else {
637638 if (!Dominator.resultIsRememberedBlock ())
638- PhiInserter.AddAvailableValue (Dominator.result (), Default);
639+ PhiInserter.AddAvailableValue (Variable, Dominator.result (), Default);
639640
640- Term->setCondition (PhiInserter. GetValueInMiddleOfBlock (Parent ));
641+ PhiInserter. AddUse (Variable, & Term->getOperandUse ( 0 ));
641642 }
642643 }
643644}
@@ -1321,8 +1322,12 @@ bool StructurizeCFG::run(Region *R, DominatorTree *DT) {
13211322 orderNodes ();
13221323 collectInfos ();
13231324 createFlow ();
1324- insertConditions (false );
1325- insertConditions (true );
1325+
1326+ SSAUpdaterBulk PhiInserter;
1327+ insertConditions (false , PhiInserter);
1328+ insertConditions (true , PhiInserter);
1329+ PhiInserter.RewriteAndOptimizeAllUses (*DT);
1330+
13261331 setPhiValues ();
13271332 simplifyConditions ();
13281333 simplifyAffectedPhis ();
0 commit comments