Added LLVM copyright header.
[oota-llvm.git] / lib / Analysis / LiveVar / BBLiveVar.h
1 //===-- BBLiveVar.h - Live Variable Analysis for a BasicBlock ---*- 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 a BasicBlock annotation class that is used by live var analysis to
11 // hold data flow information for a basic block.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LIVE_VAR_BB_H
16 #define LIVE_VAR_BB_H
17
18 #include "llvm/CodeGen/ValueSet.h"
19 #include "Support/hash_map"
20 class BasicBlock;
21 class Value;
22 class MachineBasicBlock;
23
24 enum LiveVarDebugLevel_t {
25   LV_DEBUG_None,
26   LV_DEBUG_Normal,
27   LV_DEBUG_Instr,
28   LV_DEBUG_Verbose
29 };
30
31 extern LiveVarDebugLevel_t DEBUG_LV;
32
33 class BBLiveVar {
34   const BasicBlock &BB;         // pointer to BasicBlock
35   MachineBasicBlock &MBB;       // Pointer to MachineBasicBlock
36   unsigned POID;                // Post-Order ID
37
38   ValueSet DefSet;           // Def set (with no preceding uses) for LV analysis
39   ValueSet InSet, OutSet;       // In & Out for LV analysis
40   bool InSetChanged, OutSetChanged;   // set if the InSet/OutSet is modified
41
42                                 // map that contains PredBB -> Phi arguments
43                                 // coming in on that edge.  such uses have to be
44                                 // treated differently from ordinary uses.
45   hash_map<const BasicBlock *, ValueSet> PredToEdgeInSetMap;
46   
47   // method to propagate an InSet to OutSet of a predecessor
48   bool setPropagate(ValueSet *OutSetOfPred, 
49                     const ValueSet *InSetOfThisBB,
50                     const BasicBlock *PredBB);
51
52   // To add an operand which is a def
53   void addDef(const Value *Op); 
54
55   // To add an operand which is a use
56   void addUse(const Value *Op);
57
58   void calcDefUseSets();         // calculates the Def & Use sets for this BB
59 public:
60
61   BBLiveVar(const BasicBlock &BB, MachineBasicBlock &MBB, unsigned POID);
62
63   inline bool isInSetChanged() const  { return InSetChanged; }    
64   inline bool isOutSetChanged() const { return OutSetChanged; }
65
66   MachineBasicBlock &getMachineBasicBlock() const { return MBB; }
67
68   inline unsigned getPOId() const { return POID; }
69
70   bool applyTransferFunc();      // calcultes the In in terms of Out 
71
72   // calculates Out set using In sets of the predecessors
73   bool applyFlowFunc(hash_map<const BasicBlock*, BBLiveVar*> &BBLiveVarInfo);
74
75   inline const ValueSet &getOutSet() const { return OutSet; }
76   inline       ValueSet &getOutSet()       { return OutSet; }
77
78   inline const ValueSet  &getInSet() const { return InSet; }
79   inline       ValueSet  &getInSet()       { return InSet; }
80
81   void printAllSets() const;      // for printing Def/In/Out sets
82   void printInOutSets() const;    // for printing In/Out sets
83 };
84
85 #endif