LLVM API Documentation
00001 //===- PHITransAddr.h - PHI Translation for Addresses -----------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file declares the PHITransAddr class. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef LLVM_ANALYSIS_PHITRANSADDR_H 00015 #define LLVM_ANALYSIS_PHITRANSADDR_H 00016 00017 #include "llvm/ADT/SmallVector.h" 00018 #include "llvm/IR/Instruction.h" 00019 00020 namespace llvm { 00021 class AssumptionTracker; 00022 class DominatorTree; 00023 class DataLayout; 00024 class TargetLibraryInfo; 00025 00026 /// PHITransAddr - An address value which tracks and handles phi translation. 00027 /// As we walk "up" the CFG through predecessors, we need to ensure that the 00028 /// address we're tracking is kept up to date. For example, if we're analyzing 00029 /// an address of "&A[i]" and walk through the definition of 'i' which is a PHI 00030 /// node, we *must* phi translate i to get "&A[j]" or else we will analyze an 00031 /// incorrect pointer in the predecessor block. 00032 /// 00033 /// This is designed to be a relatively small object that lives on the stack and 00034 /// is copyable. 00035 /// 00036 class PHITransAddr { 00037 /// Addr - The actual address we're analyzing. 00038 Value *Addr; 00039 00040 /// The DataLayout we are playing with if known, otherwise null. 00041 const DataLayout *DL; 00042 00043 /// TLI - The target library info if known, otherwise null. 00044 const TargetLibraryInfo *TLI; 00045 00046 /// A cache of @llvm.assume calls used by SimplifyInstruction. 00047 AssumptionTracker *AT; 00048 00049 /// InstInputs - The inputs for our symbolic address. 00050 SmallVector<Instruction*, 4> InstInputs; 00051 public: 00052 PHITransAddr(Value *addr, const DataLayout *DL, AssumptionTracker *AT) 00053 : Addr(addr), DL(DL), TLI(nullptr), AT(AT) { 00054 // If the address is an instruction, the whole thing is considered an input. 00055 if (Instruction *I = dyn_cast<Instruction>(Addr)) 00056 InstInputs.push_back(I); 00057 } 00058 00059 Value *getAddr() const { return Addr; } 00060 00061 /// NeedsPHITranslationFromBlock - Return true if moving from the specified 00062 /// BasicBlock to its predecessors requires PHI translation. 00063 bool NeedsPHITranslationFromBlock(BasicBlock *BB) const { 00064 // We do need translation if one of our input instructions is defined in 00065 // this block. 00066 for (unsigned i = 0, e = InstInputs.size(); i != e; ++i) 00067 if (InstInputs[i]->getParent() == BB) 00068 return true; 00069 return false; 00070 } 00071 00072 /// IsPotentiallyPHITranslatable - If this needs PHI translation, return true 00073 /// if we have some hope of doing it. This should be used as a filter to 00074 /// avoid calling PHITranslateValue in hopeless situations. 00075 bool IsPotentiallyPHITranslatable() const; 00076 00077 /// PHITranslateValue - PHI translate the current address up the CFG from 00078 /// CurBB to Pred, updating our state to reflect any needed changes. If the 00079 /// dominator tree DT is non-null, the translated value must dominate 00080 /// PredBB. This returns true on failure and sets Addr to null. 00081 bool PHITranslateValue(BasicBlock *CurBB, BasicBlock *PredBB, 00082 const DominatorTree *DT); 00083 00084 /// PHITranslateWithInsertion - PHI translate this value into the specified 00085 /// predecessor block, inserting a computation of the value if it is 00086 /// unavailable. 00087 /// 00088 /// All newly created instructions are added to the NewInsts list. This 00089 /// returns null on failure. 00090 /// 00091 Value *PHITranslateWithInsertion(BasicBlock *CurBB, BasicBlock *PredBB, 00092 const DominatorTree &DT, 00093 SmallVectorImpl<Instruction*> &NewInsts); 00094 00095 void dump() const; 00096 00097 /// Verify - Check internal consistency of this data structure. If the 00098 /// structure is valid, it returns true. If invalid, it prints errors and 00099 /// returns false. 00100 bool Verify() const; 00101 private: 00102 Value *PHITranslateSubExpr(Value *V, BasicBlock *CurBB, BasicBlock *PredBB, 00103 const DominatorTree *DT); 00104 00105 /// InsertPHITranslatedSubExpr - Insert a computation of the PHI translated 00106 /// version of 'V' for the edge PredBB->CurBB into the end of the PredBB 00107 /// block. All newly created instructions are added to the NewInsts list. 00108 /// This returns null on failure. 00109 /// 00110 Value *InsertPHITranslatedSubExpr(Value *InVal, BasicBlock *CurBB, 00111 BasicBlock *PredBB, const DominatorTree &DT, 00112 SmallVectorImpl<Instruction*> &NewInsts); 00113 00114 /// AddAsInput - If the specified value is an instruction, add it as an input. 00115 Value *AddAsInput(Value *V) { 00116 // If V is an instruction, it is now an input. 00117 if (Instruction *VI = dyn_cast<Instruction>(V)) 00118 InstInputs.push_back(VI); 00119 return V; 00120 } 00121 00122 }; 00123 00124 } // end namespace llvm 00125 00126 #endif