Minor change: Methods that return ValueSet's that are guaranteed to be valid
return references instead of pointers.
llvm-svn: 1719
diff --git a/llvm/lib/Analysis/LiveVar/BBLiveVar.cpp b/llvm/lib/Analysis/LiveVar/BBLiveVar.cpp
index dc0cbc1..35548f6 100644
--- a/llvm/lib/Analysis/LiveVar/BBLiveVar.cpp
+++ b/llvm/lib/Analysis/LiveVar/BBLiveVar.cpp
@@ -18,6 +18,8 @@
BBLiveVar::BBLiveVar(const BasicBlock *bb, unsigned id)
: BB(bb), POID(id) {
InSetChanged = OutSetChanged = false;
+
+ calcDefUseSets();
}
//-----------------------------------------------------------------------------
diff --git a/llvm/lib/Analysis/LiveVar/BBLiveVar.h b/llvm/lib/Analysis/LiveVar/BBLiveVar.h
index 1fc91f1..442eb22 100644
--- a/llvm/lib/Analysis/LiveVar/BBLiveVar.h
+++ b/llvm/lib/Analysis/LiveVar/BBLiveVar.h
@@ -31,11 +31,12 @@
const BasicBlock *PredBB);
// To add an operand which is a def
- void addDef(const Value *Op);
+ void addDef(const Value *Op);
// To add an operand which is a use
- void addUse(const Value *Op);
+ void addUse(const Value *Op);
+ void calcDefUseSets(); // calculates the Def & Use sets for this BB
public:
BBLiveVar(const BasicBlock *BB, unsigned POID);
@@ -44,18 +45,16 @@
inline unsigned getPOId() const { return POID; }
- void calcDefUseSets(); // calculates the Def & Use sets for this BB
bool applyTransferFunc(); // calcultes the In in terms of Out
// calculates Out set using In sets of the predecessors
bool applyFlowFunc(std::map<const BasicBlock *, BBLiveVar *> &LVMap);
- inline const ValueSet *getOutSet() const { return &OutSet; }
- inline const ValueSet *getInSet() const { return &InSet; }
+ inline const ValueSet &getOutSet() const { return OutSet; }
+ inline const ValueSet &getInSet() const { return InSet; }
void printAllSets() const; // for printing Def/In/Out sets
void printInOutSets() const; // for printing In/Out sets
};
#endif
-
diff --git a/llvm/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp b/llvm/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp
index a4dbef1..5205a19 100644
--- a/llvm/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp
+++ b/llvm/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp
@@ -20,12 +20,12 @@
//-----------------------------------------------------------------------------
// gets OutSet of a BB
-const ValueSet *MethodLiveVarInfo::getOutSetOfBB(const BasicBlock *BB) const {
+const ValueSet &MethodLiveVarInfo::getOutSetOfBB(const BasicBlock *BB) const {
return BB2BBLVMap.find(BB)->second->getOutSet();
}
// gets InSet of a BB
-const ValueSet *MethodLiveVarInfo::getInSetOfBB(const BasicBlock *BB) const {
+const ValueSet &MethodLiveVarInfo::getInSetOfBB(const BasicBlock *BB) const {
return BB2BBLVMap.find(BB)->second->getInSet();
}
@@ -65,8 +65,6 @@
BBLiveVar *LVBB = new BBLiveVar(BB, POId);
BB2BBLVMap[BB] = LVBB; // insert the pair to Map
- LVBB->calcDefUseSets(); // calculates the def and in set
-
if (DEBUG_LV)
LVBB->printAllSets();
}
@@ -155,14 +153,14 @@
// Gives live variable information before a machine instruction
//-----------------------------------------------------------------------------
-const ValueSet *
+const ValueSet &
MethodLiveVarInfo::getLiveVarSetBeforeMInst(const MachineInstr *MInst,
const BasicBlock *BB) {
if (const ValueSet *LVSet = MInst2LVSetBI[MInst]) {
- return LVSet; // if found, just return the set
+ return *LVSet; // if found, just return the set
} else {
calcLiveVarSetsForBB(BB); // else, calc for all instrs in BB
- return MInst2LVSetBI[MInst];
+ return *MInst2LVSetBI[MInst];
}
}
@@ -170,15 +168,15 @@
//-----------------------------------------------------------------------------
// Gives live variable information after a machine instruction
//-----------------------------------------------------------------------------
-const ValueSet *
+const ValueSet &
MethodLiveVarInfo::getLiveVarSetAfterMInst(const MachineInstr *MI,
const BasicBlock *BB) {
if (const ValueSet *LVSet = MInst2LVSetAI[MI]) {
- return LVSet; // if found, just return the set
+ return *LVSet; // if found, just return the set
} else {
calcLiveVarSetsForBB(BB); // else, calc for all instrs in BB
- return MInst2LVSetAI[MI];
+ return *MInst2LVSetAI[MI];
}
}
@@ -224,7 +222,7 @@
const MachineCodeForBasicBlock &MIVec = BB->getMachineInstrVec();
ValueSet *CurSet = new ValueSet();
- const ValueSet *SetAI = getOutSetOfBB(BB); // init SetAI with OutSet
+ const ValueSet *SetAI = &getOutSetOfBB(BB); // init SetAI with OutSet
set_union(*CurSet, *SetAI); // CurSet now contains OutSet
// iterate over all the machine instructions in BB