add a little helper function that does PHI translation.
authorChris Lattner <sabre@nondot.org>
Tue, 2 Dec 2008 07:16:45 +0000 (07:16 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 2 Dec 2008 07:16:45 +0000 (07:16 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60405 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Value.h
lib/VMCore/Value.cpp

index ee7e25ac76a7aae45bbc949e3a94fb39fa6fcbdf..bc741f27b0aaf900474f8f3b3ae42f82d2ac4ba6 100644 (file)
@@ -242,6 +242,17 @@ public:
   const Value *getUnderlyingObject() const {
     return const_cast<Value*>(this)->getUnderlyingObject();
   }
+  
+  /// DoPHITranslation - If this value is a PHI node with CurBB as a its parent,
+  /// return the value in the PHI node corresponding to PredBB.  If not, return
+  /// ourself.  This is useful if you want to know the value something has in a
+  /// predecessor block.
+  Value *DoPHITranslation(const BasicBlock *CurBB, const BasicBlock *PredBB);
+
+  const Value *DoPHITranslation(const BasicBlock *CurBB,
+                                const BasicBlock *PredBB) const{
+    return const_cast<Value*>(this)->DoPHITranslation(CurBB, PredBB);
+  }
 };
 
 inline std::ostream &operator<<(std::ostream &OS, const Value &V) {
index 0976a7459915ad8c4822fcb995e65594b0e4e50e..1b023e2feeacebc49b848740ca6d336881b03227 100644 (file)
@@ -358,6 +358,19 @@ Value *Value::getUnderlyingObject() {
   return this;
 }
 
+/// DoPHITranslation - If this value is a PHI node with CurBB as a its parent,
+/// return the value in the PHI node corresponding to PredBB.  If not, return
+/// ourself.  This is useful if you want to know the value something has in a
+/// predecessor block.
+Value *Value::DoPHITranslation(const BasicBlock *CurBB, 
+                               const BasicBlock *PredBB) {
+  PHINode *PN = dyn_cast<PHINode>(this);
+  if (PN && PN->getParent() == CurBB)
+    return PN->getIncomingValueForBlock(PredBB);
+  return this;
+}
+
+
 //===----------------------------------------------------------------------===//
 //                                 User Class
 //===----------------------------------------------------------------------===//