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