Chris Lattner | f0604b8 | 2001-10-01 13:19:53 +0000 | [diff] [blame] | 1 | /* Title: BBLiveVar.h -*- C++ -*- |
Ruchira Sasanka | 683847f | 2001-07-24 17:14:13 +0000 | [diff] [blame] | 2 | Author: Ruchira Sasanka |
| 3 | Date: Jun 30, 01 |
| 4 | Purpose: This is a wrapper class for BasicBlock which is used by live |
Ruchira Sasanka | 9166181 | 2001-08-20 21:11:01 +0000 | [diff] [blame] | 5 | variable anaysis. |
Ruchira Sasanka | 683847f | 2001-07-24 17:14:13 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef LIVE_VAR_BB_H |
| 9 | #define LIVE_VAR_BB_H |
| 10 | |
| 11 | #include "LiveVarSet.h" |
| 12 | #include "LiveVarMap.h" |
| 13 | |
| 14 | #include "llvm/BasicBlock.h" |
| 15 | #include "llvm/Instruction.h" |
Ruchira Sasanka | 683847f | 2001-07-24 17:14:13 +0000 | [diff] [blame] | 16 | #include "llvm/Type.h" |
| 17 | #include "llvm/iOther.h" |
| 18 | |
| 19 | |
| 20 | class BBLiveVar |
| 21 | { |
| 22 | const BasicBlock* BaseBB; // pointer to BasicBlock |
| 23 | unsigned int POId; // Post-Order ID |
| 24 | |
| 25 | LiveVarSet DefSet; // Def set for LV analysis |
| 26 | LiveVarSet InSet, OutSet; // In & Out for LV analysis |
| 27 | bool InSetChanged, OutSetChanged; // set if the InSet/OutSet is modified |
| 28 | |
| 29 | // map that contains phi args->BB they came |
Ruchira Sasanka | 9166181 | 2001-08-20 21:11:01 +0000 | [diff] [blame] | 30 | // set by calcDefUseSets & used by setPropagate |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame^] | 31 | std::hash_map<const Value *, const BasicBlock *> PhiArgMap; |
Ruchira Sasanka | 683847f | 2001-07-24 17:14:13 +0000 | [diff] [blame] | 32 | |
Ruchira Sasanka | 9166181 | 2001-08-20 21:11:01 +0000 | [diff] [blame] | 33 | // method to propogate an InSet to OutSet of a predecessor |
Ruchira Sasanka | 683847f | 2001-07-24 17:14:13 +0000 | [diff] [blame] | 34 | bool setPropagate( LiveVarSet *const OutSetOfPred, |
| 35 | const LiveVarSet *const InSetOfThisBB, |
| 36 | const BasicBlock *const PredBB); |
| 37 | |
Ruchira Sasanka | 598641b | 2001-10-12 17:46:27 +0000 | [diff] [blame] | 38 | // To add an operand which is a def |
| 39 | void addDef(const Value *Op); |
| 40 | |
| 41 | // To add an operand which is a use |
| 42 | void addUse(const Value *Op); |
| 43 | |
Ruchira Sasanka | 683847f | 2001-07-24 17:14:13 +0000 | [diff] [blame] | 44 | public: |
| 45 | |
| 46 | BBLiveVar( const BasicBlock* baseBB, unsigned int POId); |
| 47 | |
| 48 | inline bool isInSetChanged() const { return InSetChanged; } |
| 49 | inline bool isOutSetChanged() const { return OutSetChanged; } |
| 50 | |
| 51 | inline unsigned int getPOId() const { return POId; } |
| 52 | |
| 53 | void calcDefUseSets() ; // calculates the Def & Use sets for this BB |
| 54 | bool applyTransferFunc(); // calcultes the In in terms of Out |
| 55 | |
Ruchira Sasanka | 9166181 | 2001-08-20 21:11:01 +0000 | [diff] [blame] | 56 | // calculates Out set using In sets of the predecessors |
Ruchira Sasanka | 683847f | 2001-07-24 17:14:13 +0000 | [diff] [blame] | 57 | bool applyFlowFunc(BBToBBLiveVarMapType LVMap); |
| 58 | |
| 59 | inline const LiveVarSet* getOutSet() const { return &OutSet; } |
| 60 | inline const LiveVarSet* getInSet() const { return &InSet; } |
| 61 | |
Ruchira Sasanka | 9166181 | 2001-08-20 21:11:01 +0000 | [diff] [blame] | 62 | void printAllSets() const; // for printing Def/In/Out sets |
| 63 | void printInOutSets() const; // for printing In/Out sets |
Ruchira Sasanka | 683847f | 2001-07-24 17:14:13 +0000 | [diff] [blame] | 64 | |
Ruchira Sasanka | 9166181 | 2001-08-20 21:11:01 +0000 | [diff] [blame] | 65 | ~BBLiveVar() { } // nothing to do since only composite objects |
| 66 | |
| 67 | |
Ruchira Sasanka | 683847f | 2001-07-24 17:14:13 +0000 | [diff] [blame] | 68 | |
| 69 | }; |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
Ruchira Sasanka | 9166181 | 2001-08-20 21:11:01 +0000 | [diff] [blame] | 76 | |
Ruchira Sasanka | 683847f | 2001-07-24 17:14:13 +0000 | [diff] [blame] | 77 | #endif |
| 78 | |