add the start of a class used to handle phi translation in memdep and
[oota-llvm.git] / include / llvm / Analysis / PHITransAddr.h
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/Instruction.h"
18 #include "llvm/ADT/SmallVector.h"
19
20 namespace llvm {
21   class DominatorTree;
22   class TargetData;
23   
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.
30 ///
31 /// This is designed to be a relatively small object that lives on the stack and
32 /// is copyable.
33 ///
34 class PHITransAddr {
35   /// Addr - The actual address we're analyzing.
36   Value *Addr;
37   
38   /// InstInputs - The inputs for our symbolic address.
39   SmallVector<Instruction*, 4> InstInputs;
40 public:
41   PHITransAddr(Value *addr) : Addr(addr) {
42     // If the address is an instruction, the whole thing is considered an input.
43     if (Instruction *I = dyn_cast<Instruction>(Addr))
44       InstInputs.push_back(I);
45   }
46   
47   /// NeedsPHITranslationFromBlock - Return true if moving from the specified
48   /// BasicBlock to its predecessors requires PHI translation.
49   bool NeedsPHITranslationFromBlock(BasicBlock *BB) const {
50     // We do need translation if one of our input instructions is defined in
51     // this block.
52     for (unsigned i = 0, e = InstInputs.size(); i != e; ++i)
53       if (InstInputs[i]->getParent() == BB)
54         return true;
55     return false;
56   }
57   
58   /// IsPHITranslatable - If this needs PHI translation, return true if we have
59   /// some hope of doing it.  This should be used as a filter to avoid calling
60   /// GetPHITranslatedValue in hopeless situations.
61   bool IsPHITranslatable() const;
62   
63   /// GetPHITranslatedValue - Given a computation that satisfied the
64   /// isPHITranslatable predicate, see if we can translate the computation into
65   /// the specified predecessor block.  If so, return that value, otherwise
66   /// return null.
67   Value *GetPHITranslatedValue(Value *InVal, BasicBlock *CurBB,
68                                BasicBlock *Pred, const TargetData *TD) const;
69   
70   /// GetAvailablePHITranslatePointer - Return the value computed by
71   /// PHITranslatePointer if it dominates PredBB, otherwise return null.
72   Value *GetAvailablePHITranslatedValue(Value *V,
73                                         BasicBlock *CurBB, BasicBlock *PredBB,
74                                         const TargetData *TD,
75                                         const DominatorTree &DT) const;
76   
77   /// InsertPHITranslatedPointer - Insert a computation of the PHI translated
78   /// version of 'V' for the edge PredBB->CurBB into the end of the PredBB
79   /// block.  All newly created instructions are added to the NewInsts list.
80   /// This returns null on failure.
81   ///
82   Value *InsertPHITranslatedPointer(Value *InVal, BasicBlock *CurBB,
83                                     BasicBlock *PredBB, const TargetData *TD,
84                                     const DominatorTree &DT,
85                                  SmallVectorImpl<Instruction*> &NewInsts) const;
86     
87 };
88
89 } // end namespace llvm
90
91 #endif