mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-09-28 22:55:52 +00:00
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
This commit is contained in:
parent
5c288becab
commit
e9d3c6b919
@ -21,27 +21,9 @@
|
|||||||
/// BROKEN: Should not include sparc stuff directly into here
|
/// BROKEN: Should not include sparc stuff directly into here
|
||||||
#include "../../Target/Sparc/SparcInternals.h" // Only for PHI defn
|
#include "../../Target/Sparc/SparcInternals.h" // Only for PHI defn
|
||||||
|
|
||||||
static AnnotationID AID(AnnotationManager::getID("Analysis::BBLiveVar"));
|
|
||||||
|
|
||||||
BBLiveVar *BBLiveVar::CreateOnBB(const BasicBlock &BB, MachineBasicBlock &MBB,
|
|
||||||
unsigned POID) {
|
|
||||||
BBLiveVar *Result = new BBLiveVar(BB, MBB, POID);
|
|
||||||
BB.addAnnotation(Result);
|
|
||||||
return Result;
|
|
||||||
}
|
|
||||||
|
|
||||||
BBLiveVar *BBLiveVar::GetFromBB(const BasicBlock &BB) {
|
|
||||||
return (BBLiveVar*)BB.getAnnotation(AID);
|
|
||||||
}
|
|
||||||
|
|
||||||
void BBLiveVar::RemoveFromBB(const BasicBlock &BB) {
|
|
||||||
bool Deleted = BB.deleteAnnotation(AID);
|
|
||||||
assert(Deleted && "BBLiveVar annotation did not exist!");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
BBLiveVar::BBLiveVar(const BasicBlock &bb, MachineBasicBlock &mbb, unsigned id)
|
BBLiveVar::BBLiveVar(const BasicBlock &bb, MachineBasicBlock &mbb, unsigned id)
|
||||||
: Annotation(AID), BB(bb), MBB(mbb), POID(id) {
|
: BB(bb), MBB(mbb), POID(id) {
|
||||||
InSetChanged = OutSetChanged = false;
|
InSetChanged = OutSetChanged = false;
|
||||||
|
|
||||||
calcDefUseSets();
|
calcDefUseSets();
|
||||||
@ -205,7 +187,8 @@ bool BBLiveVar::setPropagate(ValueSet *OutSet, const ValueSet *InSet,
|
|||||||
// propagates in set to OutSets of PREDECESSORs
|
// propagates in set to OutSets of PREDECESSORs
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BBLiveVar::applyFlowFunc() {
|
bool BBLiveVar::applyFlowFunc(hash_map<const BasicBlock*,
|
||||||
|
BBLiveVar*> &BBLiveVarInfo) {
|
||||||
// IMPORTANT: caller should check whether inset changed
|
// IMPORTANT: caller should check whether inset changed
|
||||||
// (else no point in calling)
|
// (else no point in calling)
|
||||||
|
|
||||||
@ -216,7 +199,7 @@ bool BBLiveVar::applyFlowFunc() {
|
|||||||
|
|
||||||
for (pred_const_iterator PI = pred_begin(&BB), PE = pred_end(&BB);
|
for (pred_const_iterator PI = pred_begin(&BB), PE = pred_end(&BB);
|
||||||
PI != PE ; ++PI) {
|
PI != PE ; ++PI) {
|
||||||
BBLiveVar *PredLVBB = BBLiveVar::GetFromBB(**PI);
|
BBLiveVar *PredLVBB = BBLiveVarInfo[*PI];
|
||||||
|
|
||||||
// do set union
|
// do set union
|
||||||
if (setPropagate(&PredLVBB->OutSet, &InSet, *PI)) {
|
if (setPropagate(&PredLVBB->OutSet, &InSet, *PI)) {
|
||||||
|
@ -9,8 +9,7 @@
|
|||||||
#define LIVE_VAR_BB_H
|
#define LIVE_VAR_BB_H
|
||||||
|
|
||||||
#include "llvm/CodeGen/ValueSet.h"
|
#include "llvm/CodeGen/ValueSet.h"
|
||||||
#include "Support/Annotation.h"
|
#include "Support/hash_map"
|
||||||
#include <map>
|
|
||||||
class BasicBlock;
|
class BasicBlock;
|
||||||
class Value;
|
class Value;
|
||||||
class MachineBasicBlock;
|
class MachineBasicBlock;
|
||||||
@ -24,7 +23,7 @@ enum LiveVarDebugLevel_t {
|
|||||||
|
|
||||||
extern LiveVarDebugLevel_t DEBUG_LV;
|
extern LiveVarDebugLevel_t DEBUG_LV;
|
||||||
|
|
||||||
class BBLiveVar : public Annotation {
|
class BBLiveVar {
|
||||||
const BasicBlock &BB; // pointer to BasicBlock
|
const BasicBlock &BB; // pointer to BasicBlock
|
||||||
MachineBasicBlock &MBB; // Pointer to MachineBasicBlock
|
MachineBasicBlock &MBB; // Pointer to MachineBasicBlock
|
||||||
unsigned POID; // Post-Order ID
|
unsigned POID; // Post-Order ID
|
||||||
@ -36,7 +35,7 @@ class BBLiveVar : public Annotation {
|
|||||||
// map that contains PredBB -> Phi arguments
|
// map that contains PredBB -> Phi arguments
|
||||||
// coming in on that edge. such uses have to be
|
// coming in on that edge. such uses have to be
|
||||||
// treated differently from ordinary uses.
|
// treated differently from ordinary uses.
|
||||||
std::map<const BasicBlock *, ValueSet> PredToEdgeInSetMap;
|
hash_map<const BasicBlock *, ValueSet> PredToEdgeInSetMap;
|
||||||
|
|
||||||
// method to propagate an InSet to OutSet of a predecessor
|
// method to propagate an InSet to OutSet of a predecessor
|
||||||
bool setPropagate(ValueSet *OutSetOfPred,
|
bool setPropagate(ValueSet *OutSetOfPred,
|
||||||
@ -50,14 +49,9 @@ class BBLiveVar : public Annotation {
|
|||||||
void addUse(const Value *Op);
|
void addUse(const Value *Op);
|
||||||
|
|
||||||
void calcDefUseSets(); // calculates the Def & Use sets for this BB
|
void calcDefUseSets(); // calculates the Def & Use sets for this BB
|
||||||
|
public:
|
||||||
|
|
||||||
BBLiveVar(const BasicBlock &BB, MachineBasicBlock &MBB, unsigned POID);
|
BBLiveVar(const BasicBlock &BB, MachineBasicBlock &MBB, unsigned POID);
|
||||||
~BBLiveVar() {} // make dtor private
|
|
||||||
public:
|
|
||||||
static BBLiveVar *CreateOnBB(const BasicBlock &BB, MachineBasicBlock &MBB,
|
|
||||||
unsigned POID);
|
|
||||||
static BBLiveVar *GetFromBB(const BasicBlock &BB);
|
|
||||||
static void RemoveFromBB(const BasicBlock &BB);
|
|
||||||
|
|
||||||
inline bool isInSetChanged() const { return InSetChanged; }
|
inline bool isInSetChanged() const { return InSetChanged; }
|
||||||
inline bool isOutSetChanged() const { return OutSetChanged; }
|
inline bool isOutSetChanged() const { return OutSetChanged; }
|
||||||
@ -69,7 +63,7 @@ class BBLiveVar : public Annotation {
|
|||||||
bool applyTransferFunc(); // calcultes the In in terms of Out
|
bool applyTransferFunc(); // calcultes the In in terms of Out
|
||||||
|
|
||||||
// calculates Out set using In sets of the predecessors
|
// calculates Out set using In sets of the predecessors
|
||||||
bool applyFlowFunc();
|
bool applyFlowFunc(hash_map<const BasicBlock*, BBLiveVar*> &BBLiveVarInfo);
|
||||||
|
|
||||||
inline const ValueSet &getOutSet() const { return OutSet; }
|
inline const ValueSet &getOutSet() const { return OutSet; }
|
||||||
inline ValueSet &getOutSet() { return OutSet; }
|
inline ValueSet &getOutSet() { return OutSet; }
|
||||||
|
@ -47,18 +47,18 @@ clEnumValN(LV_DEBUG_Verbose, "v", "print def, use sets for every instrn also"),
|
|||||||
|
|
||||||
// gets OutSet of a BB
|
// gets OutSet of a BB
|
||||||
const ValueSet &FunctionLiveVarInfo::getOutSetOfBB(const BasicBlock *BB) const {
|
const ValueSet &FunctionLiveVarInfo::getOutSetOfBB(const BasicBlock *BB) const {
|
||||||
return BBLiveVar::GetFromBB(*BB)->getOutSet();
|
return BBLiveVarInfo.find(BB)->second->getOutSet();
|
||||||
}
|
}
|
||||||
ValueSet &FunctionLiveVarInfo::getOutSetOfBB(const BasicBlock *BB) {
|
ValueSet &FunctionLiveVarInfo::getOutSetOfBB(const BasicBlock *BB) {
|
||||||
return BBLiveVar::GetFromBB(*BB)->getOutSet();
|
return BBLiveVarInfo[BB]->getOutSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
// gets InSet of a BB
|
// gets InSet of a BB
|
||||||
const ValueSet &FunctionLiveVarInfo::getInSetOfBB(const BasicBlock *BB) const {
|
const ValueSet &FunctionLiveVarInfo::getInSetOfBB(const BasicBlock *BB) const {
|
||||||
return BBLiveVar::GetFromBB(*BB)->getInSet();
|
return BBLiveVarInfo.find(BB)->second->getInSet();
|
||||||
}
|
}
|
||||||
ValueSet &FunctionLiveVarInfo::getInSetOfBB(const BasicBlock *BB) {
|
ValueSet &FunctionLiveVarInfo::getInSetOfBB(const BasicBlock *BB) {
|
||||||
return BBLiveVar::GetFromBB(*BB)->getInSet();
|
return BBLiveVarInfo[BB]->getInSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -103,15 +103,16 @@ void FunctionLiveVarInfo::constructBBs(const Function *F) {
|
|||||||
std::map<const BasicBlock*, unsigned>::iterator POI = PONumbering.find(&BB);
|
std::map<const BasicBlock*, unsigned>::iterator POI = PONumbering.find(&BB);
|
||||||
if (POI != PONumbering.end()) {
|
if (POI != PONumbering.end()) {
|
||||||
// create a new BBLiveVar
|
// create a new BBLiveVar
|
||||||
LVBB = BBLiveVar::CreateOnBB(BB, *I, POId);
|
LVBB = new BBLiveVar(BB, *I, POId);
|
||||||
} else {
|
} else {
|
||||||
// The PO iterator does not discover unreachable blocks, but the random
|
// The PO iterator does not discover unreachable blocks, but the random
|
||||||
// iterator later may access these blocks. We must make sure to
|
// iterator later may access these blocks. We must make sure to
|
||||||
// initialize unreachable blocks as well. However, LV info is not correct
|
// initialize unreachable blocks as well. However, LV info is not correct
|
||||||
// for those blocks (they are not analyzed)
|
// for those blocks (they are not analyzed)
|
||||||
//
|
//
|
||||||
LVBB = BBLiveVar::CreateOnBB(BB, *I, ++POId);
|
LVBB = new BBLiveVar(BB, *I, ++POId);
|
||||||
}
|
}
|
||||||
|
BBLiveVarInfo[&BB] = LVBB;
|
||||||
|
|
||||||
if (DEBUG_LV)
|
if (DEBUG_LV)
|
||||||
LVBB->printAllSets();
|
LVBB->printAllSets();
|
||||||
@ -130,7 +131,7 @@ bool FunctionLiveVarInfo::doSingleBackwardPass(const Function *M,
|
|||||||
bool NeedAnotherIteration = false;
|
bool NeedAnotherIteration = false;
|
||||||
for (po_iterator<const Function*> BBI = po_begin(M), BBE = po_end(M);
|
for (po_iterator<const Function*> BBI = po_begin(M), BBE = po_end(M);
|
||||||
BBI != BBE; ++BBI) {
|
BBI != BBE; ++BBI) {
|
||||||
BBLiveVar *LVBB = BBLiveVar::GetFromBB(**BBI);
|
BBLiveVar *LVBB = BBLiveVarInfo[*BBI];
|
||||||
assert(LVBB && "BasicBlock information not set for block!");
|
assert(LVBB && "BasicBlock information not set for block!");
|
||||||
|
|
||||||
if (DEBUG_LV) std::cerr << " For BB " << (*BBI)->getName() << ":\n";
|
if (DEBUG_LV) std::cerr << " For BB " << (*BBI)->getName() << ":\n";
|
||||||
@ -142,7 +143,7 @@ bool FunctionLiveVarInfo::doSingleBackwardPass(const Function *M,
|
|||||||
// OutSets are initialized to EMPTY. Recompute on first iter or if InSet
|
// OutSets are initialized to EMPTY. Recompute on first iter or if InSet
|
||||||
// changed.
|
// changed.
|
||||||
if (iter == 0 || LVBB->isInSetChanged()) // to calc Outsets of preds
|
if (iter == 0 || LVBB->isInSetChanged()) // to calc Outsets of preds
|
||||||
NeedAnotherIteration |= LVBB->applyFlowFunc();
|
NeedAnotherIteration |= LVBB->applyFlowFunc(BBLiveVarInfo);
|
||||||
|
|
||||||
if (DEBUG_LV) LVBB->printInOutSets();
|
if (DEBUG_LV) LVBB->printInOutSets();
|
||||||
}
|
}
|
||||||
@ -153,10 +154,12 @@ bool FunctionLiveVarInfo::doSingleBackwardPass(const Function *M,
|
|||||||
|
|
||||||
|
|
||||||
void FunctionLiveVarInfo::releaseMemory() {
|
void FunctionLiveVarInfo::releaseMemory() {
|
||||||
// First remove all BBLiveVar annotations created in constructBBs().
|
// First remove all BBLiveVars created in constructBBs().
|
||||||
if (M)
|
if (M) {
|
||||||
for (Function::const_iterator I = M->begin(), E = M->end(); I != E; ++I)
|
for (Function::const_iterator I = M->begin(), E = M->end(); I != E; ++I)
|
||||||
BBLiveVar::RemoveFromBB(*I);
|
delete BBLiveVarInfo[I];
|
||||||
|
BBLiveVarInfo.clear();
|
||||||
|
}
|
||||||
M = 0;
|
M = 0;
|
||||||
|
|
||||||
// Then delete all objects of type ValueSet created in calcLiveVarSetsForBB
|
// Then delete all objects of type ValueSet created in calcLiveVarSetsForBB
|
||||||
@ -263,7 +266,7 @@ static void applyTranferFuncForMInst(ValueSet &LVS, const MachineInstr *MInst) {
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
void FunctionLiveVarInfo::calcLiveVarSetsForBB(const BasicBlock *BB) {
|
void FunctionLiveVarInfo::calcLiveVarSetsForBB(const BasicBlock *BB) {
|
||||||
BBLiveVar *BBLV = BBLiveVar::GetFromBB(*BB);
|
BBLiveVar *BBLV = BBLiveVarInfo[BB];
|
||||||
assert(BBLV && "BBLiveVar annotation doesn't exist?");
|
assert(BBLV && "BBLiveVar annotation doesn't exist?");
|
||||||
const MachineBasicBlock &MIVec = BBLV->getMachineBasicBlock();
|
const MachineBasicBlock &MIVec = BBLV->getMachineBasicBlock();
|
||||||
const MachineFunction &MF = MachineFunction::get(M);
|
const MachineFunction &MF = MachineFunction::get(M);
|
||||||
|
@ -21,27 +21,9 @@
|
|||||||
/// BROKEN: Should not include sparc stuff directly into here
|
/// BROKEN: Should not include sparc stuff directly into here
|
||||||
#include "../../Target/Sparc/SparcInternals.h" // Only for PHI defn
|
#include "../../Target/Sparc/SparcInternals.h" // Only for PHI defn
|
||||||
|
|
||||||
static AnnotationID AID(AnnotationManager::getID("Analysis::BBLiveVar"));
|
|
||||||
|
|
||||||
BBLiveVar *BBLiveVar::CreateOnBB(const BasicBlock &BB, MachineBasicBlock &MBB,
|
|
||||||
unsigned POID) {
|
|
||||||
BBLiveVar *Result = new BBLiveVar(BB, MBB, POID);
|
|
||||||
BB.addAnnotation(Result);
|
|
||||||
return Result;
|
|
||||||
}
|
|
||||||
|
|
||||||
BBLiveVar *BBLiveVar::GetFromBB(const BasicBlock &BB) {
|
|
||||||
return (BBLiveVar*)BB.getAnnotation(AID);
|
|
||||||
}
|
|
||||||
|
|
||||||
void BBLiveVar::RemoveFromBB(const BasicBlock &BB) {
|
|
||||||
bool Deleted = BB.deleteAnnotation(AID);
|
|
||||||
assert(Deleted && "BBLiveVar annotation did not exist!");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
BBLiveVar::BBLiveVar(const BasicBlock &bb, MachineBasicBlock &mbb, unsigned id)
|
BBLiveVar::BBLiveVar(const BasicBlock &bb, MachineBasicBlock &mbb, unsigned id)
|
||||||
: Annotation(AID), BB(bb), MBB(mbb), POID(id) {
|
: BB(bb), MBB(mbb), POID(id) {
|
||||||
InSetChanged = OutSetChanged = false;
|
InSetChanged = OutSetChanged = false;
|
||||||
|
|
||||||
calcDefUseSets();
|
calcDefUseSets();
|
||||||
@ -205,7 +187,8 @@ bool BBLiveVar::setPropagate(ValueSet *OutSet, const ValueSet *InSet,
|
|||||||
// propagates in set to OutSets of PREDECESSORs
|
// propagates in set to OutSets of PREDECESSORs
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BBLiveVar::applyFlowFunc() {
|
bool BBLiveVar::applyFlowFunc(hash_map<const BasicBlock*,
|
||||||
|
BBLiveVar*> &BBLiveVarInfo) {
|
||||||
// IMPORTANT: caller should check whether inset changed
|
// IMPORTANT: caller should check whether inset changed
|
||||||
// (else no point in calling)
|
// (else no point in calling)
|
||||||
|
|
||||||
@ -216,7 +199,7 @@ bool BBLiveVar::applyFlowFunc() {
|
|||||||
|
|
||||||
for (pred_const_iterator PI = pred_begin(&BB), PE = pred_end(&BB);
|
for (pred_const_iterator PI = pred_begin(&BB), PE = pred_end(&BB);
|
||||||
PI != PE ; ++PI) {
|
PI != PE ; ++PI) {
|
||||||
BBLiveVar *PredLVBB = BBLiveVar::GetFromBB(**PI);
|
BBLiveVar *PredLVBB = BBLiveVarInfo[*PI];
|
||||||
|
|
||||||
// do set union
|
// do set union
|
||||||
if (setPropagate(&PredLVBB->OutSet, &InSet, *PI)) {
|
if (setPropagate(&PredLVBB->OutSet, &InSet, *PI)) {
|
||||||
|
@ -9,8 +9,7 @@
|
|||||||
#define LIVE_VAR_BB_H
|
#define LIVE_VAR_BB_H
|
||||||
|
|
||||||
#include "llvm/CodeGen/ValueSet.h"
|
#include "llvm/CodeGen/ValueSet.h"
|
||||||
#include "Support/Annotation.h"
|
#include "Support/hash_map"
|
||||||
#include <map>
|
|
||||||
class BasicBlock;
|
class BasicBlock;
|
||||||
class Value;
|
class Value;
|
||||||
class MachineBasicBlock;
|
class MachineBasicBlock;
|
||||||
@ -24,7 +23,7 @@ enum LiveVarDebugLevel_t {
|
|||||||
|
|
||||||
extern LiveVarDebugLevel_t DEBUG_LV;
|
extern LiveVarDebugLevel_t DEBUG_LV;
|
||||||
|
|
||||||
class BBLiveVar : public Annotation {
|
class BBLiveVar {
|
||||||
const BasicBlock &BB; // pointer to BasicBlock
|
const BasicBlock &BB; // pointer to BasicBlock
|
||||||
MachineBasicBlock &MBB; // Pointer to MachineBasicBlock
|
MachineBasicBlock &MBB; // Pointer to MachineBasicBlock
|
||||||
unsigned POID; // Post-Order ID
|
unsigned POID; // Post-Order ID
|
||||||
@ -36,7 +35,7 @@ class BBLiveVar : public Annotation {
|
|||||||
// map that contains PredBB -> Phi arguments
|
// map that contains PredBB -> Phi arguments
|
||||||
// coming in on that edge. such uses have to be
|
// coming in on that edge. such uses have to be
|
||||||
// treated differently from ordinary uses.
|
// treated differently from ordinary uses.
|
||||||
std::map<const BasicBlock *, ValueSet> PredToEdgeInSetMap;
|
hash_map<const BasicBlock *, ValueSet> PredToEdgeInSetMap;
|
||||||
|
|
||||||
// method to propagate an InSet to OutSet of a predecessor
|
// method to propagate an InSet to OutSet of a predecessor
|
||||||
bool setPropagate(ValueSet *OutSetOfPred,
|
bool setPropagate(ValueSet *OutSetOfPred,
|
||||||
@ -50,14 +49,9 @@ class BBLiveVar : public Annotation {
|
|||||||
void addUse(const Value *Op);
|
void addUse(const Value *Op);
|
||||||
|
|
||||||
void calcDefUseSets(); // calculates the Def & Use sets for this BB
|
void calcDefUseSets(); // calculates the Def & Use sets for this BB
|
||||||
|
public:
|
||||||
|
|
||||||
BBLiveVar(const BasicBlock &BB, MachineBasicBlock &MBB, unsigned POID);
|
BBLiveVar(const BasicBlock &BB, MachineBasicBlock &MBB, unsigned POID);
|
||||||
~BBLiveVar() {} // make dtor private
|
|
||||||
public:
|
|
||||||
static BBLiveVar *CreateOnBB(const BasicBlock &BB, MachineBasicBlock &MBB,
|
|
||||||
unsigned POID);
|
|
||||||
static BBLiveVar *GetFromBB(const BasicBlock &BB);
|
|
||||||
static void RemoveFromBB(const BasicBlock &BB);
|
|
||||||
|
|
||||||
inline bool isInSetChanged() const { return InSetChanged; }
|
inline bool isInSetChanged() const { return InSetChanged; }
|
||||||
inline bool isOutSetChanged() const { return OutSetChanged; }
|
inline bool isOutSetChanged() const { return OutSetChanged; }
|
||||||
@ -69,7 +63,7 @@ class BBLiveVar : public Annotation {
|
|||||||
bool applyTransferFunc(); // calcultes the In in terms of Out
|
bool applyTransferFunc(); // calcultes the In in terms of Out
|
||||||
|
|
||||||
// calculates Out set using In sets of the predecessors
|
// calculates Out set using In sets of the predecessors
|
||||||
bool applyFlowFunc();
|
bool applyFlowFunc(hash_map<const BasicBlock*, BBLiveVar*> &BBLiveVarInfo);
|
||||||
|
|
||||||
inline const ValueSet &getOutSet() const { return OutSet; }
|
inline const ValueSet &getOutSet() const { return OutSet; }
|
||||||
inline ValueSet &getOutSet() { return OutSet; }
|
inline ValueSet &getOutSet() { return OutSet; }
|
||||||
|
@ -47,18 +47,18 @@ clEnumValN(LV_DEBUG_Verbose, "v", "print def, use sets for every instrn also"),
|
|||||||
|
|
||||||
// gets OutSet of a BB
|
// gets OutSet of a BB
|
||||||
const ValueSet &FunctionLiveVarInfo::getOutSetOfBB(const BasicBlock *BB) const {
|
const ValueSet &FunctionLiveVarInfo::getOutSetOfBB(const BasicBlock *BB) const {
|
||||||
return BBLiveVar::GetFromBB(*BB)->getOutSet();
|
return BBLiveVarInfo.find(BB)->second->getOutSet();
|
||||||
}
|
}
|
||||||
ValueSet &FunctionLiveVarInfo::getOutSetOfBB(const BasicBlock *BB) {
|
ValueSet &FunctionLiveVarInfo::getOutSetOfBB(const BasicBlock *BB) {
|
||||||
return BBLiveVar::GetFromBB(*BB)->getOutSet();
|
return BBLiveVarInfo[BB]->getOutSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
// gets InSet of a BB
|
// gets InSet of a BB
|
||||||
const ValueSet &FunctionLiveVarInfo::getInSetOfBB(const BasicBlock *BB) const {
|
const ValueSet &FunctionLiveVarInfo::getInSetOfBB(const BasicBlock *BB) const {
|
||||||
return BBLiveVar::GetFromBB(*BB)->getInSet();
|
return BBLiveVarInfo.find(BB)->second->getInSet();
|
||||||
}
|
}
|
||||||
ValueSet &FunctionLiveVarInfo::getInSetOfBB(const BasicBlock *BB) {
|
ValueSet &FunctionLiveVarInfo::getInSetOfBB(const BasicBlock *BB) {
|
||||||
return BBLiveVar::GetFromBB(*BB)->getInSet();
|
return BBLiveVarInfo[BB]->getInSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -103,15 +103,16 @@ void FunctionLiveVarInfo::constructBBs(const Function *F) {
|
|||||||
std::map<const BasicBlock*, unsigned>::iterator POI = PONumbering.find(&BB);
|
std::map<const BasicBlock*, unsigned>::iterator POI = PONumbering.find(&BB);
|
||||||
if (POI != PONumbering.end()) {
|
if (POI != PONumbering.end()) {
|
||||||
// create a new BBLiveVar
|
// create a new BBLiveVar
|
||||||
LVBB = BBLiveVar::CreateOnBB(BB, *I, POId);
|
LVBB = new BBLiveVar(BB, *I, POId);
|
||||||
} else {
|
} else {
|
||||||
// The PO iterator does not discover unreachable blocks, but the random
|
// The PO iterator does not discover unreachable blocks, but the random
|
||||||
// iterator later may access these blocks. We must make sure to
|
// iterator later may access these blocks. We must make sure to
|
||||||
// initialize unreachable blocks as well. However, LV info is not correct
|
// initialize unreachable blocks as well. However, LV info is not correct
|
||||||
// for those blocks (they are not analyzed)
|
// for those blocks (they are not analyzed)
|
||||||
//
|
//
|
||||||
LVBB = BBLiveVar::CreateOnBB(BB, *I, ++POId);
|
LVBB = new BBLiveVar(BB, *I, ++POId);
|
||||||
}
|
}
|
||||||
|
BBLiveVarInfo[&BB] = LVBB;
|
||||||
|
|
||||||
if (DEBUG_LV)
|
if (DEBUG_LV)
|
||||||
LVBB->printAllSets();
|
LVBB->printAllSets();
|
||||||
@ -130,7 +131,7 @@ bool FunctionLiveVarInfo::doSingleBackwardPass(const Function *M,
|
|||||||
bool NeedAnotherIteration = false;
|
bool NeedAnotherIteration = false;
|
||||||
for (po_iterator<const Function*> BBI = po_begin(M), BBE = po_end(M);
|
for (po_iterator<const Function*> BBI = po_begin(M), BBE = po_end(M);
|
||||||
BBI != BBE; ++BBI) {
|
BBI != BBE; ++BBI) {
|
||||||
BBLiveVar *LVBB = BBLiveVar::GetFromBB(**BBI);
|
BBLiveVar *LVBB = BBLiveVarInfo[*BBI];
|
||||||
assert(LVBB && "BasicBlock information not set for block!");
|
assert(LVBB && "BasicBlock information not set for block!");
|
||||||
|
|
||||||
if (DEBUG_LV) std::cerr << " For BB " << (*BBI)->getName() << ":\n";
|
if (DEBUG_LV) std::cerr << " For BB " << (*BBI)->getName() << ":\n";
|
||||||
@ -142,7 +143,7 @@ bool FunctionLiveVarInfo::doSingleBackwardPass(const Function *M,
|
|||||||
// OutSets are initialized to EMPTY. Recompute on first iter or if InSet
|
// OutSets are initialized to EMPTY. Recompute on first iter or if InSet
|
||||||
// changed.
|
// changed.
|
||||||
if (iter == 0 || LVBB->isInSetChanged()) // to calc Outsets of preds
|
if (iter == 0 || LVBB->isInSetChanged()) // to calc Outsets of preds
|
||||||
NeedAnotherIteration |= LVBB->applyFlowFunc();
|
NeedAnotherIteration |= LVBB->applyFlowFunc(BBLiveVarInfo);
|
||||||
|
|
||||||
if (DEBUG_LV) LVBB->printInOutSets();
|
if (DEBUG_LV) LVBB->printInOutSets();
|
||||||
}
|
}
|
||||||
@ -153,10 +154,12 @@ bool FunctionLiveVarInfo::doSingleBackwardPass(const Function *M,
|
|||||||
|
|
||||||
|
|
||||||
void FunctionLiveVarInfo::releaseMemory() {
|
void FunctionLiveVarInfo::releaseMemory() {
|
||||||
// First remove all BBLiveVar annotations created in constructBBs().
|
// First remove all BBLiveVars created in constructBBs().
|
||||||
if (M)
|
if (M) {
|
||||||
for (Function::const_iterator I = M->begin(), E = M->end(); I != E; ++I)
|
for (Function::const_iterator I = M->begin(), E = M->end(); I != E; ++I)
|
||||||
BBLiveVar::RemoveFromBB(*I);
|
delete BBLiveVarInfo[I];
|
||||||
|
BBLiveVarInfo.clear();
|
||||||
|
}
|
||||||
M = 0;
|
M = 0;
|
||||||
|
|
||||||
// Then delete all objects of type ValueSet created in calcLiveVarSetsForBB
|
// Then delete all objects of type ValueSet created in calcLiveVarSetsForBB
|
||||||
@ -263,7 +266,7 @@ static void applyTranferFuncForMInst(ValueSet &LVS, const MachineInstr *MInst) {
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
void FunctionLiveVarInfo::calcLiveVarSetsForBB(const BasicBlock *BB) {
|
void FunctionLiveVarInfo::calcLiveVarSetsForBB(const BasicBlock *BB) {
|
||||||
BBLiveVar *BBLV = BBLiveVar::GetFromBB(*BB);
|
BBLiveVar *BBLV = BBLiveVarInfo[BB];
|
||||||
assert(BBLV && "BBLiveVar annotation doesn't exist?");
|
assert(BBLV && "BBLiveVar annotation doesn't exist?");
|
||||||
const MachineBasicBlock &MIVec = BBLV->getMachineBasicBlock();
|
const MachineBasicBlock &MIVec = BBLV->getMachineBasicBlock();
|
||||||
const MachineFunction &MF = MachineFunction::get(M);
|
const MachineFunction &MF = MachineFunction::get(M);
|
||||||
|
Loading…
Reference in New Issue
Block a user