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 /// TD - The target data we are playing with if known, otherwise null.
41 /// InstInputs - The inputs for our symbolic address.
42 SmallVector<Instruction*, 4> InstInputs;
44 PHITransAddr(Value *addr, const TargetData *td) : Addr(addr), TD(td) {
45 // If the address is an instruction, the whole thing is considered an input.
46 if (Instruction *I = dyn_cast<Instruction>(Addr))
47 InstInputs.push_back(I);
50 /// NeedsPHITranslationFromBlock - Return true if moving from the specified
51 /// BasicBlock to its predecessors requires PHI translation.
52 bool NeedsPHITranslationFromBlock(BasicBlock *BB) const {
53 // We do need translation if one of our input instructions is defined in
55 for (unsigned i = 0, e = InstInputs.size(); i != e; ++i)
56 if (InstInputs[i]->getParent() == BB)
61 /// IsPotentiallyPHITranslatable - If this needs PHI translation, return true
62 /// if we have some hope of doing it. This should be used as a filter to
63 /// avoid calling PHITranslateValue in hopeless situations.
64 bool IsPotentiallyPHITranslatable() const;
66 /// PHITranslateValue - PHI translate the current address up the CFG from
67 /// CurBB to Pred, updating our state the reflect any needed changes. This
68 /// returns true on failure.
69 bool PHITranslateValue(BasicBlock *CurBB, BasicBlock *PredBB);
71 /// PHITranslateWithInsertion - PHI translate this value into the specified
72 /// predecessor block, inserting a computation of the value if it is
75 /// All newly created instructions are added to the NewInsts list. This
76 /// returns null on failure.
78 Value *PHITranslateWithInsertion(BasicBlock *CurBB, BasicBlock *PredBB,
79 const DominatorTree &DT,
80 SmallVectorImpl<Instruction*> &NewInsts);
82 Value *PHITranslateSubExpr(Value *V, BasicBlock *CurBB, BasicBlock *PredBB);
85 /// GetAvailablePHITranslatedSubExpr - Return the value computed by
86 /// PHITranslateSubExpr if it dominates PredBB, otherwise return null.
87 Value *GetAvailablePHITranslatedSubExpr(Value *V,
88 BasicBlock *CurBB, BasicBlock *PredBB,
89 const DominatorTree &DT);
91 /// InsertPHITranslatedSubExpr - Insert a computation of the PHI translated
92 /// version of 'V' for the edge PredBB->CurBB into the end of the PredBB
93 /// block. All newly created instructions are added to the NewInsts list.
94 /// This returns null on failure.
96 Value *InsertPHITranslatedSubExpr(Value *InVal, BasicBlock *CurBB,
97 BasicBlock *PredBB, const DominatorTree &DT,
98 SmallVectorImpl<Instruction*> &NewInsts);
101 } // end namespace llvm