blob: 08ccd2fe5c00aa211d6bd7a6a1732b66b403b049 [file] [log] [blame]
Chris Lattnerf0604b82001-10-01 13:19:53 +00001/* Title: BBLiveVar.h -*- C++ -*-
Ruchira Sasanka683847f2001-07-24 17:14:13 +00002 Author: Ruchira Sasanka
3 Date: Jun 30, 01
4 Purpose: This is a wrapper class for BasicBlock which is used by live
Ruchira Sasanka91661812001-08-20 21:11:01 +00005 variable anaysis.
Ruchira Sasanka683847f2001-07-24 17:14:13 +00006*/
7
8#ifndef LIVE_VAR_BB_H
9#define LIVE_VAR_BB_H
10
11#include "LiveVarSet.h"
12#include "LiveVarMap.h"
Chris Lattner65b1ad92002-02-04 16:31:03 +000013class Method;
Ruchira Sasanka683847f2001-07-24 17:14:13 +000014
Chris Lattner65b1ad92002-02-04 16:31:03 +000015class BBLiveVar {
Ruchira Sasanka683847f2001-07-24 17:14:13 +000016 const BasicBlock* BaseBB; // pointer to BasicBlock
Chris Lattner65b1ad92002-02-04 16:31:03 +000017 unsigned POId; // Post-Order ID
Ruchira Sasanka683847f2001-07-24 17:14:13 +000018
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 Sasanka91661812001-08-20 21:11:01 +000024 // set by calcDefUseSets & used by setPropagate
Chris Lattner697954c2002-01-20 22:54:45 +000025 std::hash_map<const Value *, const BasicBlock *> PhiArgMap;
Ruchira Sasanka683847f2001-07-24 17:14:13 +000026
Ruchira Sasanka91661812001-08-20 21:11:01 +000027 // method to propogate an InSet to OutSet of a predecessor
Chris Lattner65b1ad92002-02-04 16:31:03 +000028 bool setPropagate( LiveVarSet *OutSetOfPred,
29 const LiveVarSet *InSetOfThisBB,
30 const BasicBlock *PredBB);
Ruchira Sasanka683847f2001-07-24 17:14:13 +000031
Ruchira Sasanka598641b2001-10-12 17:46:27 +000032 // 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 Sasanka683847f2001-07-24 17:14:13 +000038 public:
Chris Lattner65b1ad92002-02-04 16:31:03 +000039 BBLiveVar(const BasicBlock* baseBB, unsigned POId);
Ruchira Sasanka683847f2001-07-24 17:14:13 +000040
41 inline bool isInSetChanged() const { return InSetChanged; }
42 inline bool isOutSetChanged() const { return OutSetChanged; }
43
Chris Lattner65b1ad92002-02-04 16:31:03 +000044 inline unsigned getPOId() const { return POId; }
Ruchira Sasanka683847f2001-07-24 17:14:13 +000045
46 void calcDefUseSets() ; // calculates the Def & Use sets for this BB
47 bool applyTransferFunc(); // calcultes the In in terms of Out
48
Ruchira Sasanka91661812001-08-20 21:11:01 +000049 // calculates Out set using In sets of the predecessors
Ruchira Sasanka683847f2001-07-24 17:14:13 +000050 bool applyFlowFunc(BBToBBLiveVarMapType LVMap);
51
52 inline const LiveVarSet* getOutSet() const { return &OutSet; }
53 inline const LiveVarSet* getInSet() const { return &InSet; }
54
Ruchira Sasanka91661812001-08-20 21:11:01 +000055 void printAllSets() const; // for printing Def/In/Out sets
56 void printInOutSets() const; // for printing In/Out sets
Ruchira Sasanka683847f2001-07-24 17:14:13 +000057};
58
Ruchira Sasanka683847f2001-07-24 17:14:13 +000059#endif
60