[llvm-commits] [llvm] r90518 - in /llvm/trunk: include/llvm/Analysis/PHITransAddr.h lib/Analysis/PHITransAddr.cpp
Chris Lattner
sabre at nondot.org
Thu Dec 3 18:10:17 PST 2009
Author: lattner
Date: Thu Dec 3 20:10:16 2009
New Revision: 90518
URL: http://llvm.org/viewvc/llvm-project?rev=90518&view=rev
Log:
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.
Added:
llvm/trunk/include/llvm/Analysis/PHITransAddr.h
llvm/trunk/lib/Analysis/PHITransAddr.cpp
Added: llvm/trunk/include/llvm/Analysis/PHITransAddr.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/PHITransAddr.h?rev=90518&view=auto
==============================================================================
--- llvm/trunk/include/llvm/Analysis/PHITransAddr.h (added)
+++ llvm/trunk/include/llvm/Analysis/PHITransAddr.h Thu Dec 3 20:10:16 2009
@@ -0,0 +1,91 @@
+//===- PHITransAddr.h - PHI Translation for Addresses -----------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file declares the PHITransAddr class.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_ANALYSIS_PHITRANSADDR_H
+#define LLVM_ANALYSIS_PHITRANSADDR_H
+
+#include "llvm/Instruction.h"
+#include "llvm/ADT/SmallVector.h"
+
+namespace llvm {
+ class DominatorTree;
+ class TargetData;
+
+/// PHITransAddr - An address value which tracks and handles phi translation.
+/// As we walk "up" the CFG through predecessors, we need to ensure that the
+/// address we're tracking is kept up to date. For example, if we're analyzing
+/// an address of "&A[i]" and walk through the definition of 'i' which is a PHI
+/// node, we *must* phi translate i to get "&A[j]" or else we will analyze an
+/// incorrect pointer in the predecessor block.
+///
+/// This is designed to be a relatively small object that lives on the stack and
+/// is copyable.
+///
+class PHITransAddr {
+ /// Addr - The actual address we're analyzing.
+ Value *Addr;
+
+ /// InstInputs - The inputs for our symbolic address.
+ SmallVector<Instruction*, 4> InstInputs;
+public:
+ PHITransAddr(Value *addr) : Addr(addr) {
+ // If the address is an instruction, the whole thing is considered an input.
+ if (Instruction *I = dyn_cast<Instruction>(Addr))
+ InstInputs.push_back(I);
+ }
+
+ /// NeedsPHITranslationFromBlock - Return true if moving from the specified
+ /// BasicBlock to its predecessors requires PHI translation.
+ bool NeedsPHITranslationFromBlock(BasicBlock *BB) const {
+ // We do need translation if one of our input instructions is defined in
+ // this block.
+ for (unsigned i = 0, e = InstInputs.size(); i != e; ++i)
+ if (InstInputs[i]->getParent() == BB)
+ return true;
+ return false;
+ }
+
+ /// 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 IsPHITranslatable() const;
+
+ /// 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 *GetPHITranslatedValue(Value *InVal, BasicBlock *CurBB,
+ BasicBlock *Pred, const TargetData *TD) const;
+
+ /// GetAvailablePHITranslatePointer - Return the value computed by
+ /// PHITranslatePointer if it dominates PredBB, otherwise return null.
+ Value *GetAvailablePHITranslatedValue(Value *V,
+ BasicBlock *CurBB, BasicBlock *PredBB,
+ const TargetData *TD,
+ const DominatorTree &DT) const;
+
+ /// 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 *InsertPHITranslatedPointer(Value *InVal, BasicBlock *CurBB,
+ BasicBlock *PredBB, const TargetData *TD,
+ const DominatorTree &DT,
+ SmallVectorImpl<Instruction*> &NewInsts) const;
+
+};
+
+} // end namespace llvm
+
+#endif
Added: llvm/trunk/lib/Analysis/PHITransAddr.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/PHITransAddr.cpp?rev=90518&view=auto
==============================================================================
--- llvm/trunk/lib/Analysis/PHITransAddr.cpp (added)
+++ llvm/trunk/lib/Analysis/PHITransAddr.cpp Thu Dec 3 20:10:16 2009
@@ -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;
+}
More information about the llvm-commits
mailing list