//===- 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; /// TD - The target data we are playing with if known, otherwise null. const TargetData *TD; /// InstInputs - The inputs for our symbolic address. SmallVector InstInputs; public: PHITransAddr(Value *addr, const TargetData *td) : Addr(addr), TD(td) { // If the address is an instruction, the whole thing is considered an input. if (Instruction *I = dyn_cast(Addr)) InstInputs.push_back(I); } Value *getAddr() const { return Addr; } /// 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; } /// IsPotentiallyPHITranslatable - 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 PHITranslateValue in hopeless situations. bool IsPotentiallyPHITranslatable() const; /// PHITranslateValue - PHI translate the current address up the CFG from /// CurBB to Pred, updating our state the reflect any needed changes. This /// returns true on failure and sets Addr to null. bool PHITranslateValue(BasicBlock *CurBB, BasicBlock *PredBB); /// PHITranslateWithInsertion - PHI translate this value into the specified /// predecessor block, inserting a computation of the value if it is /// unavailable. /// /// All newly created instructions are added to the NewInsts list. This /// returns null on failure. /// Value *PHITranslateWithInsertion(BasicBlock *CurBB, BasicBlock *PredBB, const DominatorTree &DT, SmallVectorImpl &NewInsts); void dump() const; /// Verify - Check internal consistency of this data structure. Though it /// claims to return a bool, it actually aborts on error and always returns /// true. bool Verify() const; private: Value *PHITranslateSubExpr(Value *V, BasicBlock *CurBB, BasicBlock *PredBB); /// GetAvailablePHITranslatedSubExpr - Return the value computed by /// PHITranslateSubExpr if it dominates PredBB, otherwise return null. Value *GetAvailablePHITranslatedSubExpr(Value *V, BasicBlock *CurBB, BasicBlock *PredBB, const DominatorTree &DT) const; /// InsertPHITranslatedSubExpr - 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 *InsertPHITranslatedSubExpr(Value *InVal, BasicBlock *CurBB, BasicBlock *PredBB, const DominatorTree &DT, SmallVectorImpl &NewInsts); /// ReplaceInstWithValue - Remove any instruction inputs in the InstInputs /// array that are due to the specified instruction that is about to be /// removed from the address, and add any corresponding to V. This returns V. Value *ReplaceInstWithValue(Instruction *I, Value *V); }; } // end namespace llvm #endif