6eac8fb7c470a61a96a2f7a36359e58488c546e9
[oota-llvm.git] / lib / Target / SparcV9 / LiveVar / BBLiveVar.h
1 //===-- BBLiveVar.h - Live Variable Analysis for a BasicBlock ----*- C++ -*--=//
2 //
3 // This is a BasicBlock annotation class that is used by live var analysis to
4 // hold data flow information for a basic block.
5 //
6 //===----------------------------------------------------------------------===//
7
8 #ifndef LIVE_VAR_BB_H
9 #define LIVE_VAR_BB_H
10
11 #include "llvm/Analysis/LiveVar/ValueSet.h"
12 #include "llvm/Annotation.h"
13 #include <map>
14 class Method;
15 class BasicBlock;
16 class Value;
17
18 class BBLiveVar : public Annotation {
19   const BasicBlock *BB;         // pointer to BasicBlock
20   unsigned POID;                // Post-Order ID
21
22   ValueSet DefSet;              // Def set (with no preceding uses) for LV analysis
23   ValueSet InSet, OutSet;       // In & Out for LV analysis
24   bool InSetChanged, OutSetChanged;   // set if the InSet/OutSet is modified
25
26                                 // map that contains PredBB -> Phi arguments
27                                 // coming in on that edge.  such uses have to be
28                                 // treated differently from ordinary uses.
29   std::map<const BasicBlock *, ValueSet> PredToEdgeInSetMap;
30   
31   // method to propogate an InSet to OutSet of a predecessor
32   bool setPropagate(ValueSet *OutSetOfPred, 
33                     const ValueSet *InSetOfThisBB,
34                     const BasicBlock *PredBB);
35
36   // To add an operand which is a def
37   void addDef(const Value *Op); 
38
39   // To add an operand which is a use
40   void addUse(const Value *Op);
41
42   void calcDefUseSets();         // calculates the Def & Use sets for this BB
43
44   BBLiveVar(const BasicBlock *BB, unsigned POID);
45   ~BBLiveVar() {}                // make dtor private
46  public:
47   static BBLiveVar *CreateOnBB(const BasicBlock *BB, unsigned POID);
48   static BBLiveVar *GetFromBB(const BasicBlock *BB);
49   static void RemoveFromBB(const BasicBlock *BB);
50
51   inline bool isInSetChanged() const  { return InSetChanged; }    
52   inline bool isOutSetChanged() const { return OutSetChanged; }
53
54   inline unsigned getPOId() const { return POID; }
55
56   bool applyTransferFunc();      // calcultes the In in terms of Out 
57
58   // calculates Out set using In sets of the predecessors
59   bool applyFlowFunc();
60
61   inline const ValueSet &getOutSet() const { return OutSet; }
62   inline const ValueSet  &getInSet() const { return InSet; }
63
64   void printAllSets() const;      // for printing Def/In/Out sets
65   void printInOutSets() const;    // for printing In/Out sets
66 };
67
68 #endif