Be a bit more efficient when processing the active and inactive
[oota-llvm.git] / lib / Target / SparcV9 / 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
21 namespace llvm {
22
23 class BasicBlock;
24 class Value;
25 class MachineBasicBlock;
26
27 enum LiveVarDebugLevel_t {
28   LV_DEBUG_None,
29   LV_DEBUG_Normal,
30   LV_DEBUG_Instr,
31   LV_DEBUG_Verbose
32 };
33
34 extern LiveVarDebugLevel_t DEBUG_LV;
35
36 class BBLiveVar {
37   const BasicBlock &BB;         // pointer to BasicBlock
38   const MachineBasicBlock &MBB; // Pointer to MachineBasicBlock
39   unsigned POID;                // Post-Order ID
40
41   ValueSet DefSet;           // Def set (with no preceding uses) for LV analysis
42   ValueSet InSet, OutSet;       // In & Out for LV analysis
43   bool InSetChanged, OutSetChanged;   // set if the InSet/OutSet is modified
44
45                                 // map that contains PredBB -> Phi arguments
46                                 // coming in on that edge.  such uses have to be
47                                 // treated differently from ordinary uses.
48   hash_map<const BasicBlock *, ValueSet> PredToEdgeInSetMap;
49   
50   // method to propagate an InSet to OutSet of a predecessor
51   bool setPropagate(ValueSet *OutSetOfPred, 
52                     const ValueSet *InSetOfThisBB,
53                     const BasicBlock *PredBB);
54
55   // To add an operand which is a def
56   void addDef(const Value *Op); 
57
58   // To add an operand which is a use
59   void addUse(const Value *Op);
60
61   void calcDefUseSets();         // calculates the Def & Use sets for this BB
62 public:
63
64   BBLiveVar(const BasicBlock &BB, const MachineBasicBlock &MBB, unsigned POID);
65
66   inline bool isInSetChanged() const  { return InSetChanged; }    
67   inline bool isOutSetChanged() const { return OutSetChanged; }
68
69   const MachineBasicBlock &getMachineBasicBlock() const { return MBB; }
70
71   inline unsigned getPOId() const { return POID; }
72
73   bool applyTransferFunc();      // calcultes the In in terms of Out 
74
75   // calculates Out set using In sets of the predecessors
76   bool applyFlowFunc(hash_map<const BasicBlock*, BBLiveVar*> &BBLiveVarInfo);
77
78   inline const ValueSet &getOutSet() const { return OutSet; }
79   inline       ValueSet &getOutSet()       { return OutSet; }
80
81   inline const ValueSet  &getInSet() const { return InSet; }
82   inline       ValueSet  &getInSet()       { return InSet; }
83
84   void printAllSets() const;      // for printing Def/In/Out sets
85   void printInOutSets() const;    // for printing In/Out sets
86 };
87
88 } // End llvm namespace
89
90 #endif