aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2008-12-02 07:16:45 +0000
committerChris Lattner <sabre@nondot.org>2008-12-02 07:16:45 +0000
commitc7f7c1dc5067a36c8ae337610dcbbe55d525c80c (patch)
tree3c3c3533894c244adec9ccfdaae3d8e990804d01
parent88d84b245cf3e09d41f7b1d2520dd6011a87f7b6 (diff)
add a little helper function that does PHI translation.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60405 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Value.h11
-rw-r--r--lib/VMCore/Value.cpp13
2 files changed, 24 insertions, 0 deletions
diff --git a/include/llvm/Value.h b/include/llvm/Value.h
index ee7e25ac76..bc741f27b0 100644
--- a/include/llvm/Value.h
+++ b/include/llvm/Value.h
@@ -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) {
diff --git a/lib/VMCore/Value.cpp b/lib/VMCore/Value.cpp
index 0976a74599..1b023e2fee 100644
--- a/lib/VMCore/Value.cpp
+++ b/lib/VMCore/Value.cpp
@@ -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
//===----------------------------------------------------------------------===//