Added LLVM copyright header (for lack of a better term).
[oota-llvm.git] / include / llvm / CodeGen / FunctionLiveVarInfo.h
1 //===-- CodeGen/FunctionLiveVarInfo.h - LiveVar Analysis --------*- C++ -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 // This is the interface for live variable info of a function that is required 
11 // by any other part of the compiler
12 //
13 // After the analysis, getInSetOfBB or getOutSetofBB can be called to get 
14 // live var info of a BB.
15 //
16 // The live var set before an instruction can be obtained in 2 ways:
17 //
18 // 1. Use the method getLiveVarSetAfterInst(Instruction *) to get the LV Info 
19 //    just after an instruction. (also exists getLiveVarSetBeforeInst(..))
20 //
21 //    This function caluclates the LV info for a BB only once and caches that 
22 //    info. If the cache does not contain the LV info of the instruction, it 
23 //    calculates the LV info for the whole BB and caches them.
24 //
25 //    Getting liveVar info this way uses more memory since, LV info should be 
26 //    cached. However, if you need LV info of nearly all the instructions of a
27 //    BB, this is the best and simplest interfrace.
28 //
29 // 2. Use the OutSet and applyTranferFuncForInst(const Instruction *const Inst) 
30 //    declared in LiveVarSet and  traverse the instructions of a basic block in 
31 //    reverse (using const_reverse_iterator in the BB class). 
32 //
33 //===----------------------------------------------------------------------===//
34
35 #ifndef FUNCTION_LIVE_VAR_INFO_H
36 #define FUNCTION_LIVE_VAR_INFO_H
37
38 #include "Support/hash_map"
39 #include "llvm/Pass.h"
40 #include "llvm/CodeGen/ValueSet.h"
41
42 class BBLiveVar;
43 class MachineInstr;
44
45 class FunctionLiveVarInfo : public FunctionPass {
46   // Machine Instr to LiveVarSet Map for providing LVset BEFORE each inst
47   // These sets are owned by this map and will be freed in releaseMemory().
48   hash_map<const MachineInstr *, ValueSet *> MInst2LVSetBI; 
49
50   // Machine Instr to LiveVarSet Map for providing LVset AFTER each inst.
51   // These sets are just pointers to sets in MInst2LVSetBI or BBLiveVar.
52   hash_map<const MachineInstr *, ValueSet *> MInst2LVSetAI; 
53
54   // Stored Function that the data is computed with respect to
55   const Function *M;
56
57   // --------- private methods -----------------------------------------
58
59   // constructs BBLiveVars and init Def and In sets
60   void constructBBs(const Function *F);
61     
62   // do one backward pass over the CFG
63   bool doSingleBackwardPass(const Function *F, unsigned int iter); 
64
65   // calculates live var sets for instructions in a BB
66   void calcLiveVarSetsForBB(const BasicBlock *BB);
67   
68 public:
69   // --------- Implement the FunctionPass interface ----------------------
70
71   // runOnFunction - Perform analysis, update internal data structures.
72   virtual bool runOnFunction(Function &F);
73
74   // releaseMemory - After LiveVariable analysis has been used, forget!
75   virtual void releaseMemory();
76
77   // getAnalysisUsage - Provide self!
78   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
79     AU.setPreservesAll();
80   }
81
82   // --------- Functions to access analysis results -------------------
83
84   // get OutSet of a BB
85   const ValueSet &getOutSetOfBB(const BasicBlock *BB) const;
86         ValueSet &getOutSetOfBB(const BasicBlock *BB)      ;
87
88   // get InSet of a BB
89   const ValueSet &getInSetOfBB(const BasicBlock *BB) const;
90         ValueSet &getInSetOfBB(const BasicBlock *BB)      ;
91
92   // gets the Live var set BEFORE an instruction.
93   // if BB is specified and the live var set has not yet been computed,
94   // it will be computed on demand.
95   const ValueSet &getLiveVarSetBeforeMInst(const MachineInstr *MI,
96                                            const BasicBlock *BB = 0);
97
98   // gets the Live var set AFTER an instruction
99   // if BB is specified and the live var set has not yet been computed,
100   // it will be computed on demand.
101   const ValueSet &getLiveVarSetAfterMInst(const MachineInstr *MI,
102                                           const BasicBlock *BB = 0);
103 };
104
105 #endif