summaryrefslogtreecommitdiff
path: root/lib/Analysis/PHITransAddr.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-12-04 02:10:16 +0000
committerChris Lattner <sabre@nondot.org>2009-12-04 02:10:16 +0000
commit210e45af3a579beeefb001c8f13c94e80407aad5 (patch)
tree9fb75f217cde4b99f8710f09744f87acc24630e8 /lib/Analysis/PHITransAddr.cpp
parent9b195eaefd1fbffe2df5cd7378182eb836505240 (diff)
downloadllvm-210e45af3a579beeefb001c8f13c94e80407aad5.tar.gz
llvm-210e45af3a579beeefb001c8f13c94e80407aad5.tar.bz2
llvm-210e45af3a579beeefb001c8f13c94e80407aad5.tar.xz
add the start of a class used to handle phi translation in memdep and
gvn (this is just a skeleton so far). This will ultimately be used to fix a nasty miscompilation with GVN. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@90518 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/PHITransAddr.cpp')
-rw-r--r--lib/Analysis/PHITransAddr.cpp71
1 files changed, 71 insertions, 0 deletions
diff --git a/lib/Analysis/PHITransAddr.cpp b/lib/Analysis/PHITransAddr.cpp
new file mode 100644
index 0000000000..ce7eca5d27
--- /dev/null
+++ b/lib/Analysis/PHITransAddr.cpp
@@ -0,0 +1,71 @@
+//===- PHITransAddr.cpp - PHI Translation for Addresses -------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements the PHITransAddr class.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Analysis/PHITransAddr.h"
+#include "llvm/Analysis/Dominators.h"
+using namespace llvm;
+
+/// IsPHITranslatable - If this needs PHI translation, return true if we have
+/// some hope of doing it. This should be used as a filter to avoid calling
+/// GetPHITranslatedValue in hopeless situations.
+bool PHITransAddr::IsPHITranslatable() const {
+ return true; // not a good filter.
+}
+
+/// GetPHITranslatedValue - Given a computation that satisfied the
+/// isPHITranslatable predicate, see if we can translate the computation into
+/// the specified predecessor block. If so, return that value, otherwise
+/// return null.
+Value *PHITransAddr::GetPHITranslatedValue(Value *InVal, BasicBlock *CurBB,
+ BasicBlock *Pred,
+ const TargetData *TD) const {
+ // Not a great implementation.
+ return 0;
+}
+
+/// GetAvailablePHITranslatePointer - Return the value computed by
+/// PHITranslatePointer if it dominates PredBB, otherwise return null.
+Value *PHITransAddr::
+GetAvailablePHITranslatedValue(Value *V,
+ BasicBlock *CurBB, BasicBlock *PredBB,
+ const TargetData *TD,
+ const DominatorTree &DT) const {
+ // See if PHI translation succeeds.
+ V = GetPHITranslatedValue(V, CurBB, PredBB, TD);
+ if (V == 0) return 0;
+
+ // Make sure the value is live in the predecessor.
+ if (Instruction *Inst = dyn_cast_or_null<Instruction>(V))
+ if (!DT.dominates(Inst->getParent(), PredBB))
+ return 0;
+ return V;
+}
+
+/// InsertPHITranslatedPointer - Insert a computation of the PHI translated
+/// version of 'V' for the edge PredBB->CurBB into the end of the PredBB
+/// block. All newly created instructions are added to the NewInsts list.
+/// This returns null on failure.
+///
+Value *PHITransAddr::
+InsertPHITranslatedPointer(Value *InVal, BasicBlock *CurBB,
+ BasicBlock *PredBB, const TargetData *TD,
+ const DominatorTree &DT,
+ SmallVectorImpl<Instruction*> &NewInsts) const {
+ // See if we have a version of this value already available and dominating
+ // PredBB. If so, there is no need to insert a new copy.
+ if (Value *Res = GetAvailablePHITranslatedValue(InVal, CurBB, PredBB, TD, DT))
+ return Res;
+
+ // Not a great implementation.
+ return 0;
+}