[llvm-commits] [llvm] r60405 - in /llvm/trunk: include/llvm/Value.h lib/VMCore/Value.cpp
Chris Lattner
sabre at nondot.org
Mon Dec 1 23:16:47 PST 2008
Author: lattner
Date: Tue Dec 2 01:16:45 2008
New Revision: 60405
URL: http://llvm.org/viewvc/llvm-project?rev=60405&view=rev
Log:
add a little helper function that does PHI translation.
Modified:
llvm/trunk/include/llvm/Value.h
llvm/trunk/lib/VMCore/Value.cpp
Modified: llvm/trunk/include/llvm/Value.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Value.h?rev=60405&r1=60404&r2=60405&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Value.h (original)
+++ llvm/trunk/include/llvm/Value.h Tue Dec 2 01:16:45 2008
@@ -242,6 +242,17 @@
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) {
Modified: llvm/trunk/lib/VMCore/Value.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Value.cpp?rev=60405&r1=60404&r2=60405&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Value.cpp (original)
+++ llvm/trunk/lib/VMCore/Value.cpp Tue Dec 2 01:16:45 2008
@@ -358,6 +358,19 @@
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
//===----------------------------------------------------------------------===//
More information about the llvm-commits
mailing list