[llvm-commits] [llvm] r81437 - in /llvm/trunk: include/llvm/Transforms/Utils/SSI.h lib/Transforms/Utils/SSI.cpp

Nick Lewycky nicholas at mxc.ca
Thu Sep 10 00:02:10 PDT 2009


Author: nicholas
Date: Thu Sep 10 02:02:09 2009
New Revision: 81437

URL: http://llvm.org/viewvc/llvm-project?rev=81437&view=rev
Log:
Correctly handle the case where a comparison is created in one BasicBlock and
used by a terminator in another.

Modified:
    llvm/trunk/include/llvm/Transforms/Utils/SSI.h
    llvm/trunk/lib/Transforms/Utils/SSI.cpp

Modified: llvm/trunk/include/llvm/Transforms/Utils/SSI.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Utils/SSI.h?rev=81437&r1=81436&r2=81437&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Transforms/Utils/SSI.h (original)
+++ llvm/trunk/include/llvm/Transforms/Utils/SSI.h Thu Sep 10 02:02:09 2009
@@ -81,6 +81,7 @@
       SmallVector<SmallVector<Instruction *, 1>, 0> value_stack;
 
       void insertSigmaFunctions(SmallVectorImpl<Instruction *> &value);
+      void insertSigma(TerminatorInst *TI, Instruction *I, unsigned pos);
       void insertPhiFunctions(SmallVectorImpl<Instruction *> &value);
       void renameInit(SmallVectorImpl<Instruction *> &value);
       void rename(BasicBlock *BB);
@@ -92,8 +93,6 @@
       unsigned getPositionPhi(PHINode *PN);
       unsigned getPositionSigma(PHINode *PN);
 
-      unsigned isUsedInTerminator(CmpInst *CI);
-
       void init(SmallVectorImpl<Instruction *> &value);
       void clean();
   };

Modified: llvm/trunk/lib/Transforms/Utils/SSI.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SSI.cpp?rev=81437&r1=81436&r2=81437&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SSI.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SSI.cpp Thu Sep 10 02:02:09 2009
@@ -80,36 +80,43 @@
     if (!needConstruction[i])
       continue;
 
-    bool need = false;
     for (Value::use_iterator begin = value[i]->use_begin(), end =
          value[i]->use_end(); begin != end; ++begin) {
       // Test if the Use of the Value is in a comparator
-      CmpInst *CI = dyn_cast<CmpInst>(begin);
-      if (CI && isUsedInTerminator(CI)) {
-        // Basic Block of the Instruction
-        BasicBlock *BB = CI->getParent();
-        // Last Instruction of the Basic Block
-        const TerminatorInst *TI = BB->getTerminator();
-
-        for (unsigned j = 0, e = TI->getNumSuccessors(); j < e; ++j) {
-          // Next Basic Block
-          BasicBlock *BB_next = TI->getSuccessor(j);
-          if (BB_next != BB &&
-              BB_next->getSinglePredecessor() != NULL &&
-              dominateAny(BB_next, value[i])) {
-            PHINode *PN = PHINode::Create(
-                value[i]->getType(), SSI_SIG, BB_next->begin());
-            PN->addIncoming(value[i], BB);
-            sigmas.insert(std::make_pair(PN, i));
-            created.insert(PN);
-            need = true;
-            defsites[i].push_back(BB_next);
-            ++NumSigmaInserted;
+      if (CmpInst *CI = dyn_cast<CmpInst>(begin)) {
+        // Iterates through all uses of CmpInst
+        for (Value::use_iterator begin_ci = CI->use_begin(), end_ci =
+             CI->use_end(); begin_ci != end_ci; ++begin_ci) {
+          // Test if any use of CmpInst is in a Terminator
+          if (TerminatorInst *TI = dyn_cast<TerminatorInst>(begin_ci)) {
+            insertSigma(TI, value[i], i);
           }
         }
       }
     }
-    needConstruction[i] = need;
+  }
+}
+
+/// Inserts Sigma Functions in every BasicBlock successor to Terminator
+/// Instruction TI. All inserted Sigma Function are related to Instruction I.
+///
+void SSI::insertSigma(TerminatorInst *TI, Instruction *I, unsigned pos) {
+  // Basic Block of the Terminator Instruction
+  BasicBlock *BB = TI->getParent();
+  for (unsigned i = 0, e = TI->getNumSuccessors(); i < e; ++i) {
+    // Next Basic Block
+    BasicBlock *BB_next = TI->getSuccessor(i);
+    if (BB_next != BB &&
+        BB_next->getSinglePredecessor() != NULL &&
+        dominateAny(BB_next, I)) {
+      PHINode *PN = PHINode::Create(I->getType(), SSI_SIG, BB_next->begin());
+      PN->addIncoming(I, BB);
+      sigmas.insert(std::make_pair(PN, pos));
+      created.insert(PN);
+      needConstruction[pos] = true;
+      defsites[pos].push_back(BB_next);
+      ++NumSigmaInserted;
+    }
   }
 }
 
@@ -371,20 +378,6 @@
     return val->second;
 }
 
-/// Return true if the the Comparison Instruction is an operator
-/// of the Terminator instruction of its Basic Block.
-///
-unsigned SSI::isUsedInTerminator(CmpInst *CI) {
-  TerminatorInst *TI = CI->getParent()->getTerminator();
-  if (TI->getNumOperands() == 0) {
-    return false;
-  } else if (CI == TI->getOperand(0)) {
-    return true;
-  } else {
-    return false;
-  }
-}
-
 /// Initializes
 ///
 void SSI::init(SmallVectorImpl<Instruction *> &value) {





More information about the llvm-commits mailing list