LLVM  3.7.0
PHITransAddr.h
Go to the documentation of this file.
1 //===- PHITransAddr.h - PHI Translation for Addresses -----------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares the PHITransAddr class.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_ANALYSIS_PHITRANSADDR_H
15 #define LLVM_ANALYSIS_PHITRANSADDR_H
16 
17 #include "llvm/ADT/SmallVector.h"
18 #include "llvm/IR/Instruction.h"
19 
20 namespace llvm {
21  class AssumptionCache;
22  class DominatorTree;
23  class DataLayout;
24  class TargetLibraryInfo;
25 
26 /// PHITransAddr - An address value which tracks and handles phi translation.
27 /// As we walk "up" the CFG through predecessors, we need to ensure that the
28 /// address we're tracking is kept up to date. For example, if we're analyzing
29 /// an address of "&A[i]" and walk through the definition of 'i' which is a PHI
30 /// node, we *must* phi translate i to get "&A[j]" or else we will analyze an
31 /// incorrect pointer in the predecessor block.
32 ///
33 /// This is designed to be a relatively small object that lives on the stack and
34 /// is copyable.
35 ///
36 class PHITransAddr {
37  /// Addr - The actual address we're analyzing.
38  Value *Addr;
39 
40  /// The DataLayout we are playing with.
41  const DataLayout &DL;
42 
43  /// TLI - The target library info if known, otherwise null.
44  const TargetLibraryInfo *TLI;
45 
46  /// A cache of @llvm.assume calls used by SimplifyInstruction.
47  AssumptionCache *AC;
48 
49  /// InstInputs - The inputs for our symbolic address.
51 public:
53  : Addr(addr), DL(DL), TLI(nullptr), AC(AC) {
54  // If the address is an instruction, the whole thing is considered an input.
55  if (Instruction *I = dyn_cast<Instruction>(Addr))
56  InstInputs.push_back(I);
57  }
58 
59  Value *getAddr() const { return Addr; }
60 
61  /// NeedsPHITranslationFromBlock - Return true if moving from the specified
62  /// BasicBlock to its predecessors requires PHI translation.
64  // We do need translation if one of our input instructions is defined in
65  // this block.
66  for (unsigned i = 0, e = InstInputs.size(); i != e; ++i)
67  if (InstInputs[i]->getParent() == BB)
68  return true;
69  return false;
70  }
71 
72  /// IsPotentiallyPHITranslatable - If this needs PHI translation, return true
73  /// if we have some hope of doing it. This should be used as a filter to
74  /// avoid calling PHITranslateValue in hopeless situations.
75  bool IsPotentiallyPHITranslatable() const;
76 
77  /// PHITranslateValue - PHI translate the current address up the CFG from
78  /// CurBB to Pred, updating our state to reflect any needed changes. If
79  /// 'MustDominate' is true, the translated value must dominate
80  /// PredBB. This returns true on failure and sets Addr to null.
81  bool PHITranslateValue(BasicBlock *CurBB, BasicBlock *PredBB,
82  const DominatorTree *DT, bool MustDominate);
83 
84  /// PHITranslateWithInsertion - PHI translate this value into the specified
85  /// predecessor block, inserting a computation of the value if it is
86  /// unavailable.
87  ///
88  /// All newly created instructions are added to the NewInsts list. This
89  /// returns null on failure.
90  ///
92  const DominatorTree &DT,
94 
95  void dump() const;
96 
97  /// Verify - Check internal consistency of this data structure. If the
98  /// structure is valid, it returns true. If invalid, it prints errors and
99  /// returns false.
100  bool Verify() const;
101 private:
102  Value *PHITranslateSubExpr(Value *V, BasicBlock *CurBB, BasicBlock *PredBB,
103  const DominatorTree *DT);
104 
105  /// InsertPHITranslatedSubExpr - Insert a computation of the PHI translated
106  /// version of 'V' for the edge PredBB->CurBB into the end of the PredBB
107  /// block. All newly created instructions are added to the NewInsts list.
108  /// This returns null on failure.
109  ///
110  Value *InsertPHITranslatedSubExpr(Value *InVal, BasicBlock *CurBB,
111  BasicBlock *PredBB, const DominatorTree &DT,
113 
114  /// AddAsInput - If the specified value is an instruction, add it as an input.
115  Value *AddAsInput(Value *V) {
116  // If V is an instruction, it is now an input.
117  if (Instruction *VI = dyn_cast<Instruction>(V))
118  InstInputs.push_back(VI);
119  return V;
120  }
121 
122 };
123 
124 } // end namespace llvm
125 
126 #endif
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:104
Value * PHITranslateWithInsertion(BasicBlock *CurBB, BasicBlock *PredBB, const DominatorTree &DT, SmallVectorImpl< Instruction * > &NewInsts)
PHITranslateWithInsertion - PHI translate this value into the specified predecessor block...
A cache of .assume calls within a function.
bool NeedsPHITranslationFromBlock(BasicBlock *BB) const
NeedsPHITranslationFromBlock - Return true if moving from the specified BasicBlock to its predecessor...
Definition: PHITransAddr.h:63
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APInt.h:33
void dump() const
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Definition: Dominators.h:67
LLVM Basic Block Representation.
Definition: BasicBlock.h:65
PHITransAddr - An address value which tracks and handles phi translation.
Definition: PHITransAddr.h:36
PHITransAddr(Value *addr, const DataLayout &DL, AssumptionCache *AC)
Definition: PHITransAddr.h:52
bool IsPotentiallyPHITranslatable() const
IsPotentiallyPHITranslatable - If this needs PHI translation, return true if we have some hope of doi...
bool PHITranslateValue(BasicBlock *CurBB, BasicBlock *PredBB, const DominatorTree *DT, bool MustDominate)
PHITranslateValue - PHI translate the current address up the CFG from CurBB to Pred, updating our state to reflect any needed changes.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:861
Provides information about what library functions are available for the current target.
#define I(x, y, z)
Definition: MD5.cpp:54
LLVM Value Representation.
Definition: Value.h:69
static const Function * getParent(const Value *V)
bool Verify() const
Verify - Check internal consistency of this data structure.
Value * getAddr() const
Definition: PHITransAddr.h:59
void * addr