llvm.org GIT mirror llvm / e9d3c6b
Convert this code from using annotations to using a local map git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@9310 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 16 years ago
6 changed file(s) with 52 addition(s) and 92 deletion(s). Raw diff Collapse all Expand all
2020 /// BROKEN: Should not include sparc stuff directly into here
2121 #include "../../Target/Sparc/SparcInternals.h" // Only for PHI defn
2222
23 static AnnotationID AID(AnnotationManager::getID("Analysis::BBLiveVar"));
24
25 BBLiveVar *BBLiveVar::CreateOnBB(const BasicBlock &BB, MachineBasicBlock &MBB,
26 unsigned POID) {
27 BBLiveVar *Result = new BBLiveVar(BB, MBB, POID);
28 BB.addAnnotation(Result);
29 return Result;
30 }
31
32 BBLiveVar *BBLiveVar::GetFromBB(const BasicBlock &BB) {
33 return (BBLiveVar*)BB.getAnnotation(AID);
34 }
35
36 void BBLiveVar::RemoveFromBB(const BasicBlock &BB) {
37 bool Deleted = BB.deleteAnnotation(AID);
38 assert(Deleted && "BBLiveVar annotation did not exist!");
39 }
40
4123
4224 BBLiveVar::BBLiveVar(const BasicBlock &bb, MachineBasicBlock &mbb, unsigned id)
43 : Annotation(AID), BB(bb), MBB(mbb), POID(id) {
25 : BB(bb), MBB(mbb), POID(id) {
4426 InSetChanged = OutSetChanged = false;
4527
4628 calcDefUseSets();
204186 // propagates in set to OutSets of PREDECESSORs
205187 //-----------------------------------------------------------------------------
206188
207 bool BBLiveVar::applyFlowFunc() {
189 bool BBLiveVar::applyFlowFunc(hash_map
190 BBLiveVar*> &BBLiveVarInfo) {
208191 // IMPORTANT: caller should check whether inset changed
209192 // (else no point in calling)
210193
215198
216199 for (pred_const_iterator PI = pred_begin(&BB), PE = pred_end(&BB);
217200 PI != PE ; ++PI) {
218 BBLiveVar *PredLVBB = BBLiveVar::GetFromBB(**PI);
201 BBLiveVar *PredLVBB = BBLiveVarInfo[*PI];
219202
220203 // do set union
221204 if (setPropagate(&PredLVBB->OutSet, &InSet, *PI)) {
88 #define LIVE_VAR_BB_H
99
1010 #include "llvm/CodeGen/ValueSet.h"
11 #include "Support/Annotation.h"
12 #include
11 #include "Support/hash_map"
1312 class BasicBlock;
1413 class Value;
1514 class MachineBasicBlock;
2322
2423 extern LiveVarDebugLevel_t DEBUG_LV;
2524
26 class BBLiveVar : public Annotation {
25 class BBLiveVar {
2726 const BasicBlock &BB; // pointer to BasicBlock
2827 MachineBasicBlock &MBB; // Pointer to MachineBasicBlock
2928 unsigned POID; // Post-Order ID
3534 // map that contains PredBB -> Phi arguments
3635 // coming in on that edge. such uses have to be
3736 // treated differently from ordinary uses.
38 std::map PredToEdgeInSetMap;
37 hash_map PredToEdgeInSetMap;
3938
4039 // method to propagate an InSet to OutSet of a predecessor
4140 bool setPropagate(ValueSet *OutSetOfPred,
4948 void addUse(const Value *Op);
5049
5150 void calcDefUseSets(); // calculates the Def & Use sets for this BB
51 public:
5252
5353 BBLiveVar(const BasicBlock &BB, MachineBasicBlock &MBB, unsigned POID);
54 ~BBLiveVar() {} // make dtor private
55 public:
56 static BBLiveVar *CreateOnBB(const BasicBlock &BB, MachineBasicBlock &MBB,
57 unsigned POID);
58 static BBLiveVar *GetFromBB(const BasicBlock &BB);
59 static void RemoveFromBB(const BasicBlock &BB);
6054
6155 inline bool isInSetChanged() const { return InSetChanged; }
6256 inline bool isOutSetChanged() const { return OutSetChanged; }
6862 bool applyTransferFunc(); // calcultes the In in terms of Out
6963
7064 // calculates Out set using In sets of the predecessors
71 bool applyFlowFunc();
65 bool applyFlowFunc(hash_map &BBLiveVarInfo);
7266
7367 inline const ValueSet &getOutSet() const { return OutSet; }
7468 inline ValueSet &getOutSet() { return OutSet; }
4646
4747 // gets OutSet of a BB
4848 const ValueSet &FunctionLiveVarInfo::getOutSetOfBB(const BasicBlock *BB) const {
49 return BBLiveVar::GetFromBB(*BB)->getOutSet();
49 return BBLiveVarInfo.find(BB)->second->getOutSet();
5050 }
5151 ValueSet &FunctionLiveVarInfo::getOutSetOfBB(const BasicBlock *BB) {
52 return BBLiveVar::GetFromBB(*BB)->getOutSet();
52 return BBLiveVarInfo[BB]->getOutSet();
5353 }
5454
5555 // gets InSet of a BB
5656 const ValueSet &FunctionLiveVarInfo::getInSetOfBB(const BasicBlock *BB) const {
57 return BBLiveVar::GetFromBB(*BB)->getInSet();
58 }
59 ValueSet &FunctionLiveVarInfo::getInSetOfBB(const BasicBlock *BB) {
60 return BBLiveVar::GetFromBB(*BB)->getInSet();
57 return BBLiveVarInfo.find(BB)->second->getInSet();
58 }
59 ValueSet &FunctionLiveVarInfo::getInSetOfBB(const BasicBlock *BB) {
60 return BBLiveVarInfo[BB]->getInSet();
6161 }
6262
6363
102102 std::map::iterator POI = PONumbering.find(&BB);
103103 if (POI != PONumbering.end()) {
104104 // create a new BBLiveVar
105 LVBB = BBLiveVar::CreateOnBB(BB, *I, POId);
105 LVBB = new BBLiveVar(BB, *I, POId);
106106 } else {
107107 // The PO iterator does not discover unreachable blocks, but the random
108108 // iterator later may access these blocks. We must make sure to
109109 // initialize unreachable blocks as well. However, LV info is not correct
110110 // for those blocks (they are not analyzed)
111111 //
112 LVBB = BBLiveVar::CreateOnBB(BB, *I, ++POId);
112 LVBB = new BBLiveVar(BB, *I, ++POId);
113113 }
114 BBLiveVarInfo[&BB] = LVBB;
114115
115116 if (DEBUG_LV)
116117 LVBB->printAllSets();
129130 bool NeedAnotherIteration = false;
130131 for (po_iterator BBI = po_begin(M), BBE = po_end(M);
131132 BBI != BBE; ++BBI) {
132 BBLiveVar *LVBB = BBLiveVar::GetFromBB(**BBI);
133 BBLiveVar *LVBB = BBLiveVarInfo[*BBI];
133134 assert(LVBB && "BasicBlock information not set for block!");
134135
135136 if (DEBUG_LV) std::cerr << " For BB " << (*BBI)->getName() << ":\n";
141142 // OutSets are initialized to EMPTY. Recompute on first iter or if InSet
142143 // changed.
143144 if (iter == 0 || LVBB->isInSetChanged()) // to calc Outsets of preds
144 NeedAnotherIteration |= LVBB->applyFlowFunc();
145 NeedAnotherIteration |= LVBB->applyFlowFunc(BBLiveVarInfo);
145146
146147 if (DEBUG_LV) LVBB->printInOutSets();
147148 }
152153
153154
154155 void FunctionLiveVarInfo::releaseMemory() {
155 // First remove all BBLiveVar annotations created in constructBBs().
156 if (M)
156 // First remove all BBLiveVars created in constructBBs().
157 if (M) {
157158 for (Function::const_iterator I = M->begin(), E = M->end(); I != E; ++I)
158 BBLiveVar::RemoveFromBB(*I);
159 delete BBLiveVarInfo[I];
160 BBLiveVarInfo.clear();
161 }
159162 M = 0;
160163
161164 // Then delete all objects of type ValueSet created in calcLiveVarSetsForBB
262265 //-----------------------------------------------------------------------------
263266
264267 void FunctionLiveVarInfo::calcLiveVarSetsForBB(const BasicBlock *BB) {
265 BBLiveVar *BBLV = BBLiveVar::GetFromBB(*BB);
268 BBLiveVar *BBLV = BBLiveVarInfo[BB];
266269 assert(BBLV && "BBLiveVar annotation doesn't exist?");
267270 const MachineBasicBlock &MIVec = BBLV->getMachineBasicBlock();
268271 const MachineFunction &MF = MachineFunction::get(M);
2020 /// BROKEN: Should not include sparc stuff directly into here
2121 #include "../../Target/Sparc/SparcInternals.h" // Only for PHI defn
2222
23 static AnnotationID AID(AnnotationManager::getID("Analysis::BBLiveVar"));
24
25 BBLiveVar *BBLiveVar::CreateOnBB(const BasicBlock &BB, MachineBasicBlock &MBB,
26 unsigned POID) {
27 BBLiveVar *Result = new BBLiveVar(BB, MBB, POID);
28 BB.addAnnotation(Result);
29 return Result;
30 }
31
32 BBLiveVar *BBLiveVar::GetFromBB(const BasicBlock &BB) {
33 return (BBLiveVar*)BB.getAnnotation(AID);
34 }
35
36 void BBLiveVar::RemoveFromBB(const BasicBlock &BB) {
37 bool Deleted = BB.deleteAnnotation(AID);
38 assert(Deleted && "BBLiveVar annotation did not exist!");
39 }
40
4123
4224 BBLiveVar::BBLiveVar(const BasicBlock &bb, MachineBasicBlock &mbb, unsigned id)
43 : Annotation(AID), BB(bb), MBB(mbb), POID(id) {
25 : BB(bb), MBB(mbb), POID(id) {
4426 InSetChanged = OutSetChanged = false;
4527
4628 calcDefUseSets();
204186 // propagates in set to OutSets of PREDECESSORs
205187 //-----------------------------------------------------------------------------
206188
207 bool BBLiveVar::applyFlowFunc() {
189 bool BBLiveVar::applyFlowFunc(hash_map
190 BBLiveVar*> &BBLiveVarInfo) {
208191 // IMPORTANT: caller should check whether inset changed
209192 // (else no point in calling)
210193
215198
216199 for (pred_const_iterator PI = pred_begin(&BB), PE = pred_end(&BB);
217200 PI != PE ; ++PI) {
218 BBLiveVar *PredLVBB = BBLiveVar::GetFromBB(**PI);
201 BBLiveVar *PredLVBB = BBLiveVarInfo[*PI];
219202
220203 // do set union
221204 if (setPropagate(&PredLVBB->OutSet, &InSet, *PI)) {
88 #define LIVE_VAR_BB_H
99
1010 #include "llvm/CodeGen/ValueSet.h"
11 #include "Support/Annotation.h"
12 #include
11 #include "Support/hash_map"
1312 class BasicBlock;
1413 class Value;
1514 class MachineBasicBlock;
2322
2423 extern LiveVarDebugLevel_t DEBUG_LV;
2524
26 class BBLiveVar : public Annotation {
25 class BBLiveVar {
2726 const BasicBlock &BB; // pointer to BasicBlock
2827 MachineBasicBlock &MBB; // Pointer to MachineBasicBlock
2928 unsigned POID; // Post-Order ID
3534 // map that contains PredBB -> Phi arguments
3635 // coming in on that edge. such uses have to be
3736 // treated differently from ordinary uses.
38 std::map PredToEdgeInSetMap;
37 hash_map PredToEdgeInSetMap;
3938
4039 // method to propagate an InSet to OutSet of a predecessor
4140 bool setPropagate(ValueSet *OutSetOfPred,
4948 void addUse(const Value *Op);
5049
5150 void calcDefUseSets(); // calculates the Def & Use sets for this BB
51 public:
5252
5353 BBLiveVar(const BasicBlock &BB, MachineBasicBlock &MBB, unsigned POID);
54 ~BBLiveVar() {} // make dtor private
55 public:
56 static BBLiveVar *CreateOnBB(const BasicBlock &BB, MachineBasicBlock &MBB,
57 unsigned POID);
58 static BBLiveVar *GetFromBB(const BasicBlock &BB);
59 static void RemoveFromBB(const BasicBlock &BB);
6054
6155 inline bool isInSetChanged() const { return InSetChanged; }
6256 inline bool isOutSetChanged() const { return OutSetChanged; }
6862 bool applyTransferFunc(); // calcultes the In in terms of Out
6963
7064 // calculates Out set using In sets of the predecessors
71 bool applyFlowFunc();
65 bool applyFlowFunc(hash_map &BBLiveVarInfo);
7266
7367 inline const ValueSet &getOutSet() const { return OutSet; }
7468 inline ValueSet &getOutSet() { return OutSet; }
4646
4747 // gets OutSet of a BB
4848 const ValueSet &FunctionLiveVarInfo::getOutSetOfBB(const BasicBlock *BB) const {
49 return BBLiveVar::GetFromBB(*BB)->getOutSet();
49 return BBLiveVarInfo.find(BB)->second->getOutSet();
5050 }
5151 ValueSet &FunctionLiveVarInfo::getOutSetOfBB(const BasicBlock *BB) {
52 return BBLiveVar::GetFromBB(*BB)->getOutSet();
52 return BBLiveVarInfo[BB]->getOutSet();
5353 }
5454
5555 // gets InSet of a BB
5656 const ValueSet &FunctionLiveVarInfo::getInSetOfBB(const BasicBlock *BB) const {
57 return BBLiveVar::GetFromBB(*BB)->getInSet();
58 }
59 ValueSet &FunctionLiveVarInfo::getInSetOfBB(const BasicBlock *BB) {
60 return BBLiveVar::GetFromBB(*BB)->getInSet();
57 return BBLiveVarInfo.find(BB)->second->getInSet();
58 }
59 ValueSet &FunctionLiveVarInfo::getInSetOfBB(const BasicBlock *BB) {
60 return BBLiveVarInfo[BB]->getInSet();
6161 }
6262
6363
102102 std::map::iterator POI = PONumbering.find(&BB);
103103 if (POI != PONumbering.end()) {
104104 // create a new BBLiveVar
105 LVBB = BBLiveVar::CreateOnBB(BB, *I, POId);
105 LVBB = new BBLiveVar(BB, *I, POId);
106106 } else {
107107 // The PO iterator does not discover unreachable blocks, but the random
108108 // iterator later may access these blocks. We must make sure to
109109 // initialize unreachable blocks as well. However, LV info is not correct
110110 // for those blocks (they are not analyzed)
111111 //
112 LVBB = BBLiveVar::CreateOnBB(BB, *I, ++POId);
112 LVBB = new BBLiveVar(BB, *I, ++POId);
113113 }
114 BBLiveVarInfo[&BB] = LVBB;
114115
115116 if (DEBUG_LV)
116117 LVBB->printAllSets();
129130 bool NeedAnotherIteration = false;
130131 for (po_iterator BBI = po_begin(M), BBE = po_end(M);
131132 BBI != BBE; ++BBI) {
132 BBLiveVar *LVBB = BBLiveVar::GetFromBB(**BBI);
133 BBLiveVar *LVBB = BBLiveVarInfo[*BBI];
133134 assert(LVBB && "BasicBlock information not set for block!");
134135
135136 if (DEBUG_LV) std::cerr << " For BB " << (*BBI)->getName() << ":\n";
141142 // OutSets are initialized to EMPTY. Recompute on first iter or if InSet
142143 // changed.
143144 if (iter == 0 || LVBB->isInSetChanged()) // to calc Outsets of preds
144 NeedAnotherIteration |= LVBB->applyFlowFunc();
145 NeedAnotherIteration |= LVBB->applyFlowFunc(BBLiveVarInfo);
145146
146147 if (DEBUG_LV) LVBB->printInOutSets();
147148 }
152153
153154
154155 void FunctionLiveVarInfo::releaseMemory() {
155 // First remove all BBLiveVar annotations created in constructBBs().
156 if (M)
156 // First remove all BBLiveVars created in constructBBs().
157 if (M) {
157158 for (Function::const_iterator I = M->begin(), E = M->end(); I != E; ++I)
158 BBLiveVar::RemoveFromBB(*I);
159 delete BBLiveVarInfo[I];
160 BBLiveVarInfo.clear();
161 }
159162 M = 0;
160163
161164 // Then delete all objects of type ValueSet created in calcLiveVarSetsForBB
262265 //-----------------------------------------------------------------------------
263266
264267 void FunctionLiveVarInfo::calcLiveVarSetsForBB(const BasicBlock *BB) {
265 BBLiveVar *BBLV = BBLiveVar::GetFromBB(*BB);
268 BBLiveVar *BBLV = BBLiveVarInfo[BB];
266269 assert(BBLV && "BBLiveVar annotation doesn't exist?");
267270 const MachineBasicBlock &MIVec = BBLV->getMachineBasicBlock();
268271 const MachineFunction &MF = MachineFunction::get(M);