R600/structurizer: improve finding condition values

Using the new NearestCommonDominator class.

This is a candidate for the stable branch.

Signed-off-by: Christian König <christian.koenig@amd.com>
Reviewed-by: Tom Stellard <thomas.stellard@amd.com>

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@175347 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Christian Konig 2013-02-16 11:27:40 +00:00
parent 4c79c71d99
commit 25bd884c3d

View File

@ -458,29 +458,42 @@ void AMDGPUStructurizeCFG::insertConditions() {
assert(Term->isConditional());
PhiInserter.Initialize(Boolean, "");
if (Parent == LoopEnd) {
PhiInserter.AddAvailableValue(LoopStart, BoolTrue);
} else {
PhiInserter.AddAvailableValue(&Func->getEntryBlock(), BoolFalse);
PhiInserter.AddAvailableValue(Parent, BoolFalse);
}
Value *Default = (Parent == LoopEnd) ? BoolTrue : BoolFalse;
PhiInserter.Initialize(Boolean, "");
PhiInserter.AddAvailableValue(&Func->getEntryBlock(), Default);
if (Parent == LoopEnd)
PhiInserter.AddAvailableValue(LoopStart, BoolTrue);
else
PhiInserter.AddAvailableValue(Parent, BoolFalse);
bool ParentHasValue = false;
BasicBlock *Succ = Term->getSuccessor(0);
BBPredicates &Preds = (Parent == LoopEnd) ? LoopPred : Predicates[Succ];
NearestCommonDominator Dominator(DT);
Dominator.addBlock(Parent, false);
Value *ParentValue = 0;
for (BBPredicates::iterator PI = Preds.begin(), PE = Preds.end();
PI != PE; ++PI) {
if (PI->first == Parent) {
ParentValue = PI->second;
break;
}
PhiInserter.AddAvailableValue(PI->first, PI->second);
ParentHasValue |= PI->first == Parent;
Dominator.addBlock(PI->first);
}
if (ParentHasValue)
Term->setCondition(PhiInserter.GetValueAtEndOfBlock(Parent));
else
if (ParentValue) {
Term->setCondition(ParentValue);
} else {
if (!Dominator.wasResultExplicitMentioned())
PhiInserter.AddAvailableValue(Dominator.getResult(), Default);
Term->setCondition(PhiInserter.GetValueInMiddleOfBlock(Parent));
}
}
}
/// \brief Remove all PHI values coming from "From" into "To" and remember