*** empty log message ***
[oota-llvm.git] / include / llvm / CodeGen / FunctionLiveVarInfo.h
1 /* Title:   MethodLiveVarInfo.h
2    Author:  Ruchira Sasanka
3    Date:    Jun 30, 01
4    Purpose: 
5
6    This is the interface for live variable info of a method that is required by 
7    any other part of the compiler
8
9    It should be called like:
10
11        MethodLiveVarInfo MLVI( Mehtod *);  // initializes data structures
12        MLVI.analyze();                    // do the actural live variable anal
13
14  After the analysis, getInSetOfBB or getOutSetofBB can be called to get 
15  live var info of a BB
16
17  The live var set before an instruction can be constructed in several ways:
18
19  1. Use the OutSet and applyTranferFuncForInst(const Instruction *const Inst) 
20     declared in LiveVarSet and  traverse the instructions of a basic block in 
21     reverse (using const_reverse_iterator in the BB class). 
22
23     This is the most efficient method if you need LV info for several (all) 
24     instructions in a BasicBlock. An example is given below:
25
26
27     LiveVarSet LVSet;  // this will be the set used to traverse through each BB
28
29                    // Initialize LVSet so that it is the same as OutSet of the BB
30     LVSet.setUnion( LVI->getOutSetOfBB( *BBI ) );  
31  
32     BasicBlock::InstListType::const_reverse_iterator 
33       InstIterator = InstListInBB.rbegin();  // get the reverse it for inst in BB
34
35                             // iterate over all the instructions in BB in reverse
36     for( ; InstIterator != InstListInBB.rend(); InstIterator++) {  
37
38       //...... all  code here which uses LVSet ........
39
40       LVSet.applyTranferFuncForInst(*InstIterator);
41
42       // Now LVSet contains live vars ABOVE the current instrution
43     }
44
45     See buildInterferenceGraph() for the above example.
46
47
48  2. Use the function getLiveVarSetBeforeInst(Instruction *) to get the LV Info 
49     just before an instruction.
50
51     This function caluclates the LV info for a BB only once and caches that 
52     info. If the cache does not contain the LV info of the instruction, it 
53     calculates the LV info for the whole BB and caches them.
54
55     Getting liveVar info this way uses more memory since, LV info should be 
56     cached.
57
58
59  **BUGS: Cannot be called on a method prototype because the BB front() 
60    iterator causes a seg fault in CFG.h (Chris will fix this)
61    So, currently, DO NOT call this for method prototypes. 
62
63 */
64
65
66 #ifndef METH_LIVE_VAR_INFO_H
67 #define METH_LIVE_VAR_INFO_H
68
69         // for printing out debug messages
70 #define DEBUG_LV (1)
71
72 #include "LiveVarSet.h"
73 #include "llvm/BasicBlock.h"
74 #include "llvm/Instruction.h"
75 #include "llvm/Method.h"
76 #include "llvm/CFG.h"
77
78 #include "LiveVarMap.h"
79 #include "BBLiveVar.h"
80
81
82 class MethodLiveVarInfo
83 {
84  private:
85   const Method *Meth;   // Live var anal is done on this method 
86                         // set by constructor
87
88   BBToBBLiveVarMapType  BB2BBLVMap;  // A map betwn the BasicBlock and BBLiveVar
89
90   InstToLiveVarSetMapType Inst2LVSetMap; // Instruction to LiveVarSet Map 
91                                          //- for providing LV info for each inst
92
93   void constructBBs();          // constructs BBLiveVars and init Def and In sets
94   bool  doSingleBackwardPass(); // do one backward pass over the CFG
95
96   
97
98  public:
99   MethodLiveVarInfo(Method *const Meth);    // constructor 
100
101   ~MethodLiveVarInfo();                     // destructor
102
103   void analyze();             // performs a liver var analysis of a single method
104
105                                                            // gets OutSet of a BB
106   inline const LiveVarSet *getOutSetOfBB( const BasicBlock *const BB)  const {   
107     return (   (* (BB2BBLVMap.find(BB)) ).second  )->getOutSet();
108   }
109
110                                                             // gets InSet of a BB
111   inline const LiveVarSet *getInSetOfBB( const BasicBlock *const BB)  const { 
112     return (   (* (BB2BBLVMap.find(BB)) ).second  )->getInSet();
113   }
114                                    // gets the Live var set before an instruction
115   const LiveVarSet * 
116     MethodLiveVarInfo::getLiveVarSetBeforeInst(const Instruction *const Inst);
117
118  
119 };
120
121
122
123
124
125 #endif
126
127
128
129