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" |
Chris Lattner | 65b1ad9 | 2002-02-04 16:31:03 +0000 | [diff] [blame] | 13 | class Method; |
Ruchira Sasanka | 683847f | 2001-07-24 17:14:13 +0000 | [diff] [blame] | 14 | |
Chris Lattner | 65b1ad9 | 2002-02-04 16:31:03 +0000 | [diff] [blame] | 15 | class BBLiveVar { |
Ruchira Sasanka | 683847f | 2001-07-24 17:14:13 +0000 | [diff] [blame] | 16 | const BasicBlock* BaseBB; // pointer to BasicBlock |
Chris Lattner | 65b1ad9 | 2002-02-04 16:31:03 +0000 | [diff] [blame] | 17 | unsigned POId; // Post-Order ID |
Ruchira Sasanka | 683847f | 2001-07-24 17:14:13 +0000 | [diff] [blame] | 18 | |
| 19 | LiveVarSet DefSet; // Def set for LV analysis |
| 20 | LiveVarSet InSet, OutSet; // In & Out for LV analysis |
| 21 | bool InSetChanged, OutSetChanged; // set if the InSet/OutSet is modified |
| 22 | |
| 23 | // map that contains phi args->BB they came |
Ruchira Sasanka | 9166181 | 2001-08-20 21:11:01 +0000 | [diff] [blame] | 24 | // set by calcDefUseSets & used by setPropagate |
Chris Lattner | 697954c | 2002-01-20 22:54:45 +0000 | [diff] [blame] | 25 | std::hash_map<const Value *, const BasicBlock *> PhiArgMap; |
Ruchira Sasanka | 683847f | 2001-07-24 17:14:13 +0000 | [diff] [blame] | 26 | |
Ruchira Sasanka | 9166181 | 2001-08-20 21:11:01 +0000 | [diff] [blame] | 27 | // method to propogate an InSet to OutSet of a predecessor |
Chris Lattner | 65b1ad9 | 2002-02-04 16:31:03 +0000 | [diff] [blame] | 28 | bool setPropagate( LiveVarSet *OutSetOfPred, |
| 29 | const LiveVarSet *InSetOfThisBB, |
| 30 | const BasicBlock *PredBB); |
Ruchira Sasanka | 683847f | 2001-07-24 17:14:13 +0000 | [diff] [blame] | 31 | |
Ruchira Sasanka | 598641b | 2001-10-12 17:46:27 +0000 | [diff] [blame] | 32 | // To add an operand which is a def |
| 33 | void addDef(const Value *Op); |
| 34 | |
| 35 | // To add an operand which is a use |
| 36 | void addUse(const Value *Op); |
| 37 | |
Ruchira Sasanka | 683847f | 2001-07-24 17:14:13 +0000 | [diff] [blame] | 38 | public: |
Chris Lattner | 65b1ad9 | 2002-02-04 16:31:03 +0000 | [diff] [blame] | 39 | BBLiveVar(const BasicBlock* baseBB, unsigned POId); |
Ruchira Sasanka | 683847f | 2001-07-24 17:14:13 +0000 | [diff] [blame] | 40 | |
| 41 | inline bool isInSetChanged() const { return InSetChanged; } |
| 42 | inline bool isOutSetChanged() const { return OutSetChanged; } |
| 43 | |
Chris Lattner | 65b1ad9 | 2002-02-04 16:31:03 +0000 | [diff] [blame] | 44 | inline unsigned getPOId() const { return POId; } |
Ruchira Sasanka | 683847f | 2001-07-24 17:14:13 +0000 | [diff] [blame] | 45 | |
| 46 | void calcDefUseSets() ; // calculates the Def & Use sets for this BB |
| 47 | bool applyTransferFunc(); // calcultes the In in terms of Out |
| 48 | |
Ruchira Sasanka | 9166181 | 2001-08-20 21:11:01 +0000 | [diff] [blame] | 49 | // calculates Out set using In sets of the predecessors |
Ruchira Sasanka | 683847f | 2001-07-24 17:14:13 +0000 | [diff] [blame] | 50 | bool applyFlowFunc(BBToBBLiveVarMapType LVMap); |
| 51 | |
| 52 | inline const LiveVarSet* getOutSet() const { return &OutSet; } |
| 53 | inline const LiveVarSet* getInSet() const { return &InSet; } |
| 54 | |
Ruchira Sasanka | 9166181 | 2001-08-20 21:11:01 +0000 | [diff] [blame] | 55 | void printAllSets() const; // for printing Def/In/Out sets |
| 56 | void printInOutSets() const; // for printing In/Out sets |
Ruchira Sasanka | 683847f | 2001-07-24 17:14:13 +0000 | [diff] [blame] | 57 | }; |
| 58 | |
Ruchira Sasanka | 683847f | 2001-07-24 17:14:13 +0000 | [diff] [blame] | 59 | #endif |
| 60 | |