[Mesa-dev] [PATCH 03/12] R600/structurizer: improve finding condition values

Christian König deathsimple at vodafone.de
Thu Feb 14 02:43:01 PST 2013


From: Christian König <christian.koenig at amd.com>

Using the new NearestCommonDominator class.

Signed-off-by: Christian König <christian.koenig at amd.com>
---
 lib/Target/R600/AMDGPUStructurizeCFG.cpp |   31 +++++++++++++++++++++---------
 1 file changed, 22 insertions(+), 9 deletions(-)

diff --git a/lib/Target/R600/AMDGPUStructurizeCFG.cpp b/lib/Target/R600/AMDGPUStructurizeCFG.cpp
index 3801347..e97e049 100644
--- a/lib/Target/R600/AMDGPUStructurizeCFG.cpp
+++ b/lib/Target/R600/AMDGPUStructurizeCFG.cpp
@@ -458,28 +458,41 @@ void AMDGPUStructurizeCFG::insertConditions() {
 
     assert(Term->isConditional());
 
+    Value *Default = (Parent == LoopEnd) ? BoolTrue : BoolFalse;
+
     PhiInserter.Initialize(Boolean, "");
-    if (Parent == LoopEnd) {
+    PhiInserter.AddAvailableValue(&Func->getEntryBlock(), Default);
+    if (Parent == LoopEnd)
       PhiInserter.AddAvailableValue(LoopStart, BoolTrue);
-    } else {
-      PhiInserter.AddAvailableValue(&Func->getEntryBlock(), BoolFalse);
+    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));
+    }
   }
 }
 
-- 
1.7.10.4



More information about the mesa-dev mailing list