[Mesa-dev] [PATCH 2/2] R600: optimize structurizer a bit

Christian König deathsimple at vodafone.de
Mon Jan 21 13:28:57 PST 2013


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

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

diff --git a/lib/Target/R600/AMDGPUStructurizeCFG.cpp b/lib/Target/R600/AMDGPUStructurizeCFG.cpp
index 5be40de..70622e7 100644
--- a/lib/Target/R600/AMDGPUStructurizeCFG.cpp
+++ b/lib/Target/R600/AMDGPUStructurizeCFG.cpp
@@ -204,51 +204,33 @@ void AMDGPUStructurizeCFG::buildPredicate(BranchInst *Term, unsigned Idx,
   Value *True = Invert ? BoolFalse : BoolTrue;
   Value *False = Invert ? BoolTrue : BoolFalse;
 
-  RegionInfo *RI = ParentRegion->getRegionInfo();
-  BasicBlock *BB = Term->getParent();
-
-  // Handle the case where multiple regions start at the same block
-  Region *R = BB != ParentRegion->getEntry() ?
-              RI->getRegionFor(BB) : ParentRegion;
+  BasicBlock *Parent = Term->getParent();
 
-  if (R == ParentRegion) {
-    // It's a top level block in our region
-    Value *Cond = True;
-    if (Term->isConditional()) {
-      BasicBlock *Other = Term->getSuccessor(!Idx);
+  Value *Cond = True;
+  if (Term->isConditional()) {
+    BasicBlock *Other = Term->getSuccessor(!Idx);
 
-      if (Visited.count(Other)) {
-        if (!Pred.count(Other))
-          Pred[Other] = False;
-
-        if (!Pred.count(BB))
-          Pred[BB] = True;
-        return;
-      }
-      Cond = Term->getCondition();
+    if (Visited.count(Other)) {
+      if (!Pred.count(Other))
+        Pred[Other] = False;
 
-      if (Idx != Invert)
-        Cond = BinaryOperator::CreateNot(Cond, "", Term);
+      if (!Pred.count(Parent))
+        Pred[Parent] = True;
+      return;
     }
+    Cond = Term->getCondition();
 
-    Pred[BB] = Cond;
-
-  } else if (ParentRegion->contains(R)) {
-    // It's a block in a sub region
-    while(R->getParent() != ParentRegion)
-      R = R->getParent();
-
-    Pred[R->getEntry()] = True;
-
-  } else {
-    // It's a branch from outside into our parent region
-    Pred[BB] = True;
+    if (Idx != Invert)
+      Cond = BinaryOperator::CreateNot(Cond, "", Term);
   }
+
+  Pred[Parent] = Cond;
 }
 
 /// \brief Analyze the successors of each block and build up predicates
 void AMDGPUStructurizeCFG::analyzeBlock(BasicBlock *BB) {
   pred_iterator PI = pred_begin(BB), PE = pred_end(BB);
+  RegionInfo *RI = ParentRegion->getRegionInfo();
   BBPredicates &Pred = Predicates[BB];
 
   for (; PI != PE; ++PI) {
@@ -263,7 +245,26 @@ void AMDGPUStructurizeCFG::analyzeBlock(BasicBlock *BB) {
       BasicBlock *Succ = Term->getSuccessor(i);
       if (Succ != BB)
         continue;
-      buildPredicate(Term, i, Pred, false);
+
+      // Handle the case where multiple regions start at the same block
+      Region *R = *PI != ParentRegion->getEntry() ?
+                  RI->getRegionFor(*PI) : ParentRegion;
+
+      if (R == ParentRegion) {
+        // It's a top level block in our region
+        buildPredicate(Term, i, Pred, false);
+
+      } else if (ParentRegion->contains(R)) {
+        // It's a block in a sub region
+        while(R->getParent() != ParentRegion)
+          R = R->getParent();
+
+        Pred[R->getEntry()] = BoolTrue;
+
+      } else {
+        // It's a branch from outside into our parent region
+        Pred[*PI] = BoolTrue;
+      }
     }
   }
 }
-- 
1.7.10.4



More information about the mesa-dev mailing list