/// BROKEN: Should not include sparc stuff directly into here
#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)
- : Annotation(AID), BB(bb), MBB(mbb), POID(id) {
+ : BB(bb), MBB(mbb), POID(id) {
InSetChanged = OutSetChanged = false;
calcDefUseSets();
// 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
// (else no point in calling)
for (pred_const_iterator PI = pred_begin(&BB), PE = pred_end(&BB);
PI != PE ; ++PI) {
- BBLiveVar *PredLVBB = BBLiveVar::GetFromBB(**PI);
+ BBLiveVar *PredLVBB = BBLiveVarInfo[*PI];
// do set union
if (setPropagate(&PredLVBB->OutSet, &InSet, *PI)) {
#define LIVE_VAR_BB_H
#include "llvm/CodeGen/ValueSet.h"
-#include "Support/Annotation.h"
-#include <map>
+#include "Support/hash_map"
class BasicBlock;
class Value;
class MachineBasicBlock;
extern LiveVarDebugLevel_t DEBUG_LV;
-class BBLiveVar : public Annotation {
+class BBLiveVar {
const BasicBlock &BB; // pointer to BasicBlock
MachineBasicBlock &MBB; // Pointer to MachineBasicBlock
unsigned POID; // Post-Order ID
// map that contains PredBB -> Phi arguments
// coming in on that edge. such uses have to be
// 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
bool setPropagate(ValueSet *OutSetOfPred,
void addUse(const Value *Op);
void calcDefUseSets(); // calculates the Def & Use sets for this BB
+public:
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 isOutSetChanged() const { return OutSetChanged; }
bool applyTransferFunc(); // calcultes the In in terms of Out
// 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 ValueSet &getOutSet() { return OutSet; }
// gets OutSet of a BB
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) {
- return BBLiveVar::GetFromBB(*BB)->getOutSet();
+ return BBLiveVarInfo[BB]->getOutSet();
}
// gets InSet of a BB
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) {
- return BBLiveVar::GetFromBB(*BB)->getInSet();
+ValueSet &FunctionLiveVarInfo::getInSetOfBB(const BasicBlock *BB) {
+ return BBLiveVarInfo[BB]->getInSet();
}
std::map<const BasicBlock*, unsigned>::iterator POI = PONumbering.find(&BB);
if (POI != PONumbering.end()) {
// create a new BBLiveVar
- LVBB = BBLiveVar::CreateOnBB(BB, *I, POId);
+ LVBB = new BBLiveVar(BB, *I, POId);
} else {
// The PO iterator does not discover unreachable blocks, but the random
// iterator later may access these blocks. We must make sure to
// initialize unreachable blocks as well. However, LV info is not correct
// 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)
LVBB->printAllSets();
bool NeedAnotherIteration = false;
for (po_iterator<const Function*> BBI = po_begin(M), BBE = po_end(M);
BBI != BBE; ++BBI) {
- BBLiveVar *LVBB = BBLiveVar::GetFromBB(**BBI);
+ BBLiveVar *LVBB = BBLiveVarInfo[*BBI];
assert(LVBB && "BasicBlock information not set for block!");
if (DEBUG_LV) std::cerr << " For BB " << (*BBI)->getName() << ":\n";
// OutSets are initialized to EMPTY. Recompute on first iter or if InSet
// changed.
if (iter == 0 || LVBB->isInSetChanged()) // to calc Outsets of preds
- NeedAnotherIteration |= LVBB->applyFlowFunc();
+ NeedAnotherIteration |= LVBB->applyFlowFunc(BBLiveVarInfo);
if (DEBUG_LV) LVBB->printInOutSets();
}
void FunctionLiveVarInfo::releaseMemory() {
- // First remove all BBLiveVar annotations created in constructBBs().
- if (M)
+ // First remove all BBLiveVars created in constructBBs().
+ if (M) {
for (Function::const_iterator I = M->begin(), E = M->end(); I != E; ++I)
- BBLiveVar::RemoveFromBB(*I);
+ delete BBLiveVarInfo[I];
+ BBLiveVarInfo.clear();
+ }
M = 0;
// Then delete all objects of type ValueSet created in calcLiveVarSetsForBB
//-----------------------------------------------------------------------------
void FunctionLiveVarInfo::calcLiveVarSetsForBB(const BasicBlock *BB) {
- BBLiveVar *BBLV = BBLiveVar::GetFromBB(*BB);
+ BBLiveVar *BBLV = BBLiveVarInfo[BB];
assert(BBLV && "BBLiveVar annotation doesn't exist?");
const MachineBasicBlock &MIVec = BBLV->getMachineBasicBlock();
const MachineFunction &MF = MachineFunction::get(M);