blob: 112e8151d971b6222c5badb949cba59f4002882a [file] [log] [blame]
Chris Lattner01744102002-02-05 00:33:19 +00001//===-- BBLiveVar.h - Live Variable Analysis for a BasicBlock ----*- C++ -*--=//
2//
3// This is a wrapper class for BasicBlock which is used by live var analysis.
4//
5//===----------------------------------------------------------------------===//
Ruchira Sasanka683847f2001-07-24 17:14:13 +00006
7#ifndef LIVE_VAR_BB_H
8#define LIVE_VAR_BB_H
9
10#include "LiveVarSet.h"
Chris Lattner01744102002-02-05 00:33:19 +000011#include <map>
Chris Lattner65b1ad92002-02-04 16:31:03 +000012class Method;
Chris Lattner01744102002-02-05 00:33:19 +000013class BasicBlock;
14class Value;
Ruchira Sasanka683847f2001-07-24 17:14:13 +000015
Chris Lattner65b1ad92002-02-04 16:31:03 +000016class BBLiveVar {
Chris Lattner01744102002-02-05 00:33:19 +000017 const BasicBlock *BB; // pointer to BasicBlock
18 unsigned POID; // Post-Order ID
Ruchira Sasanka683847f2001-07-24 17:14:13 +000019
20 LiveVarSet DefSet; // Def set for LV analysis
21 LiveVarSet InSet, OutSet; // In & Out for LV analysis
22 bool InSetChanged, OutSetChanged; // set if the InSet/OutSet is modified
23
24 // map that contains phi args->BB they came
Ruchira Sasanka91661812001-08-20 21:11:01 +000025 // set by calcDefUseSets & used by setPropagate
Chris Lattner01744102002-02-05 00:33:19 +000026 std::map<const Value *, const BasicBlock *> PhiArgMap;
Ruchira Sasanka683847f2001-07-24 17:14:13 +000027
Ruchira Sasanka91661812001-08-20 21:11:01 +000028 // method to propogate an InSet to OutSet of a predecessor
Chris Lattner01744102002-02-05 00:33:19 +000029 bool setPropagate(LiveVarSet *OutSetOfPred,
30 const LiveVarSet *InSetOfThisBB,
31 const BasicBlock *PredBB);
Ruchira Sasanka683847f2001-07-24 17:14:13 +000032
Ruchira Sasanka598641b2001-10-12 17:46:27 +000033 // To add an operand which is a def
34 void addDef(const Value *Op);
35
36 // To add an operand which is a use
37 void addUse(const Value *Op);
38
Ruchira Sasanka683847f2001-07-24 17:14:13 +000039 public:
Chris Lattner01744102002-02-05 00:33:19 +000040 BBLiveVar(const BasicBlock *BB, unsigned POID);
Ruchira Sasanka683847f2001-07-24 17:14:13 +000041
Chris Lattner01744102002-02-05 00:33:19 +000042 inline bool isInSetChanged() const { return InSetChanged; }
Ruchira Sasanka683847f2001-07-24 17:14:13 +000043 inline bool isOutSetChanged() const { return OutSetChanged; }
44
Chris Lattner01744102002-02-05 00:33:19 +000045 inline unsigned getPOId() const { return POID; }
Ruchira Sasanka683847f2001-07-24 17:14:13 +000046
Chris Lattner01744102002-02-05 00:33:19 +000047 void calcDefUseSets(); // calculates the Def & Use sets for this BB
48 bool applyTransferFunc(); // calcultes the In in terms of Out
Ruchira Sasanka683847f2001-07-24 17:14:13 +000049
Ruchira Sasanka91661812001-08-20 21:11:01 +000050 // calculates Out set using In sets of the predecessors
Chris Lattner01744102002-02-05 00:33:19 +000051 bool applyFlowFunc(std::map<const BasicBlock *, BBLiveVar *> &LVMap);
Ruchira Sasanka683847f2001-07-24 17:14:13 +000052
Chris Lattner01744102002-02-05 00:33:19 +000053 inline const LiveVarSet *getOutSet() const { return &OutSet; }
54 inline const LiveVarSet *getInSet() const { return &InSet; }
Ruchira Sasanka683847f2001-07-24 17:14:13 +000055
Ruchira Sasanka91661812001-08-20 21:11:01 +000056 void printAllSets() const; // for printing Def/In/Out sets
57 void printInOutSets() const; // for printing In/Out sets
Ruchira Sasanka683847f2001-07-24 17:14:13 +000058};
59
Ruchira Sasanka683847f2001-07-24 17:14:13 +000060#endif
61