1 //===- PHITransAddr.h - PHI Translation for Addresses -----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the PHITransAddr class.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_ANALYSIS_PHITRANSADDR_H
15 #define LLVM_ANALYSIS_PHITRANSADDR_H
17 #include "llvm/Instruction.h"
18 #include "llvm/ADT/SmallVector.h"
24 /// PHITransAddr - An address value which tracks and handles phi translation.
25 /// As we walk "up" the CFG through predecessors, we need to ensure that the
26 /// address we're tracking is kept up to date. For example, if we're analyzing
27 /// an address of "&A[i]" and walk through the definition of 'i' which is a PHI
28 /// node, we *must* phi translate i to get "&A[j]" or else we will analyze an
29 /// incorrect pointer in the predecessor block.
31 /// This is designed to be a relatively small object that lives on the stack and
35 /// Addr - The actual address we're analyzing.
38 /// InstInputs - The inputs for our symbolic address.
39 SmallVector<Instruction*, 4> InstInputs;
41 PHITransAddr(Value *addr) : Addr(addr) {
42 // If the address is an instruction, the whole thing is considered an input.
43 if (Instruction *I = dyn_cast<Instruction>(Addr))
44 InstInputs.push_back(I);
47 /// NeedsPHITranslationFromBlock - Return true if moving from the specified
48 /// BasicBlock to its predecessors requires PHI translation.
49 bool NeedsPHITranslationFromBlock(BasicBlock *BB) const {
50 // We do need translation if one of our input instructions is defined in
52 for (unsigned i = 0, e = InstInputs.size(); i != e; ++i)
53 if (InstInputs[i]->getParent() == BB)
58 /// IsPHITranslatable - If this needs PHI translation, return true if we have
59 /// some hope of doing it. This should be used as a filter to avoid calling
60 /// GetPHITranslatedValue in hopeless situations.
61 bool IsPHITranslatable() const;
63 /// GetPHITranslatedValue - Given a computation that satisfied the
64 /// isPHITranslatable predicate, see if we can translate the computation into
65 /// the specified predecessor block. If so, return that value, otherwise
67 Value *GetPHITranslatedValue(Value *InVal, BasicBlock *CurBB,
68 BasicBlock *Pred, const TargetData *TD) const;
70 /// GetAvailablePHITranslatePointer - Return the value computed by
71 /// PHITranslatePointer if it dominates PredBB, otherwise return null.
72 Value *GetAvailablePHITranslatedValue(Value *V,
73 BasicBlock *CurBB, BasicBlock *PredBB,
75 const DominatorTree &DT) const;
77 /// InsertPHITranslatedPointer - Insert a computation of the PHI translated
78 /// version of 'V' for the edge PredBB->CurBB into the end of the PredBB
79 /// block. All newly created instructions are added to the NewInsts list.
80 /// This returns null on failure.
82 Value *InsertPHITranslatedPointer(Value *InVal, BasicBlock *CurBB,
83 BasicBlock *PredBB, const TargetData *TD,
84 const DominatorTree &DT,
85 SmallVectorImpl<Instruction*> &NewInsts) const;
89 } // end namespace llvm