summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-10-28 18:01:21 +0000
committerChris Lattner <sabre@nondot.org>2002-10-28 18:01:21 +0000
commit601fc7c71c252e7d5748ecb64a1600ab1e333b5d (patch)
tree86fc4aaed895ff71a6c87496a984b8484233fca4
parentb84a2ba877c670af013056c514fc80a56845fb87 (diff)
downloadllvm-601fc7c71c252e7d5748ecb64a1600ab1e333b5d.tar.gz
llvm-601fc7c71c252e7d5748ecb64a1600ab1e333b5d.tar.bz2
llvm-601fc7c71c252e7d5748ecb64a1600ab1e333b5d.tar.xz
Eliminate uses of MachineBasicBlock::get
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4340 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Analysis/LiveVar/BBLiveVar.cpp18
-rw-r--r--lib/Analysis/LiveVar/BBLiveVar.h11
-rw-r--r--lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp47
-rw-r--r--lib/Target/SparcV9/LiveVar/BBLiveVar.cpp18
-rw-r--r--lib/Target/SparcV9/LiveVar/BBLiveVar.h11
-rw-r--r--lib/Target/SparcV9/LiveVar/FunctionLiveVarInfo.cpp47
6 files changed, 86 insertions, 66 deletions
diff --git a/lib/Analysis/LiveVar/BBLiveVar.cpp b/lib/Analysis/LiveVar/BBLiveVar.cpp
index 54de63e58f..4b07ebc632 100644
--- a/lib/Analysis/LiveVar/BBLiveVar.cpp
+++ b/lib/Analysis/LiveVar/BBLiveVar.cpp
@@ -18,8 +18,9 @@ using std::cerr;
static AnnotationID AID(AnnotationManager::getID("Analysis::BBLiveVar"));
-BBLiveVar *BBLiveVar::CreateOnBB(const BasicBlock &BB, unsigned POID) {
- BBLiveVar *Result = new BBLiveVar(BB, POID);
+BBLiveVar *BBLiveVar::CreateOnBB(const BasicBlock &BB, MachineBasicBlock &MBB,
+ unsigned POID) {
+ BBLiveVar *Result = new BBLiveVar(BB, MBB, POID);
BB.addAnnotation(Result);
return Result;
}
@@ -34,8 +35,8 @@ void BBLiveVar::RemoveFromBB(const BasicBlock &BB) {
}
-BBLiveVar::BBLiveVar(const BasicBlock &bb, unsigned id)
- : Annotation(AID), BB(bb), POID(id) {
+BBLiveVar::BBLiveVar(const BasicBlock &bb, MachineBasicBlock &mbb, unsigned id)
+ : Annotation(AID), BB(bb), MBB(mbb), POID(id) {
InSetChanged = OutSetChanged = false;
calcDefUseSets();
@@ -49,15 +50,12 @@ BBLiveVar::BBLiveVar(const BasicBlock &bb, unsigned id)
//-----------------------------------------------------------------------------
void BBLiveVar::calcDefUseSets() {
- // get the iterator for machine instructions
- const MachineBasicBlock &MIVec = MachineBasicBlock::get(&BB);
-
// iterate over all the machine instructions in BB
- for (MachineBasicBlock::const_reverse_iterator MII = MIVec.rbegin(),
- MIE = MIVec.rend(); MII != MIE; ++MII) {
+ for (MachineBasicBlock::const_reverse_iterator MII = MBB.rbegin(),
+ MIE = MBB.rend(); MII != MIE; ++MII) {
const MachineInstr *MI = *MII;
- if (DEBUG_LV >= LV_DEBUG_Verbose) { // debug msg
+ if (DEBUG_LV >= LV_DEBUG_Verbose) {
cerr << " *Iterating over machine instr ";
MI->dump();
cerr << "\n";
diff --git a/lib/Analysis/LiveVar/BBLiveVar.h b/lib/Analysis/LiveVar/BBLiveVar.h
index 0eed3375ab..eada3a7f08 100644
--- a/lib/Analysis/LiveVar/BBLiveVar.h
+++ b/lib/Analysis/LiveVar/BBLiveVar.h
@@ -13,6 +13,7 @@
#include <map>
class BasicBlock;
class Value;
+class MachineBasicBlock;
enum LiveVarDebugLevel_t {
LV_DEBUG_None,
@@ -25,9 +26,10 @@ extern LiveVarDebugLevel_t DEBUG_LV;
class BBLiveVar : public Annotation {
const BasicBlock &BB; // pointer to BasicBlock
+ MachineBasicBlock &MBB; // Pointer to MachineBasicBlock
unsigned POID; // Post-Order ID
- ValueSet DefSet; // Def set (with no preceding uses) for LV analysis
+ ValueSet DefSet; // Def set (with no preceding uses) for LV analysis
ValueSet InSet, OutSet; // In & Out for LV analysis
bool InSetChanged, OutSetChanged; // set if the InSet/OutSet is modified
@@ -49,16 +51,19 @@ class BBLiveVar : public Annotation {
void calcDefUseSets(); // calculates the Def & Use sets for this BB
- BBLiveVar(const BasicBlock &BB, unsigned POID);
+ BBLiveVar(const BasicBlock &BB, MachineBasicBlock &MBB, unsigned POID);
~BBLiveVar() {} // make dtor private
public:
- static BBLiveVar *CreateOnBB(const BasicBlock &BB, unsigned POID);
+ 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; }
+ MachineBasicBlock &getMachineBasicBlock() const { return MBB; }
+
inline unsigned getPOId() const { return POID; }
bool applyTransferFunc(); // calcultes the In in terms of Out
diff --git a/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp b/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp
index 198afed537..962afa44a1 100644
--- a/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp
+++ b/lib/Analysis/LiveVar/FunctionLiveVarInfo.cpp
@@ -8,7 +8,7 @@
#include "llvm/Analysis/LiveVar/FunctionLiveVarInfo.h"
#include "BBLiveVar.h"
#include "llvm/CodeGen/MachineInstr.h"
-#include "llvm/CodeGen/MachineBasicBlock.h"
+#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/Support/CFG.h"
#include "Support/PostOrderIterator.h"
#include "Support/SetOperations.h"
@@ -71,31 +71,36 @@ bool FunctionLiveVarInfo::runOnFunction(Function &F) {
// constructs BBLiveVars and init Def and In sets
//-----------------------------------------------------------------------------
-void FunctionLiveVarInfo::constructBBs(const Function *M) {
- unsigned int POId = 0; // Reverse Depth-first Order ID
-
- for(po_iterator<const Function*> BBI = po_begin(M), BBE = po_end(M);
- BBI != BBE; ++BBI, ++POId) {
- const BasicBlock &BB = **BBI; // get the current BB
+void FunctionLiveVarInfo::constructBBs(const Function *F) {
+ unsigned POId = 0; // Reverse Depth-first Order ID
+ std::map<const BasicBlock*, unsigned> PONumbering;
+
+ for (po_iterator<const Function*> BBI = po_begin(M), BBE = po_end(M);
+ BBI != BBE; ++BBI)
+ PONumbering[*BBI] = POId++;
+ MachineFunction &MF = MachineFunction::get(F);
+ for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) {
+ const BasicBlock &BB = *I->getBasicBlock(); // get the current BB
if (DEBUG_LV) std::cerr << " For BB " << RAV(BB) << ":\n";
- // create a new BBLiveVar
- BBLiveVar *LVBB = BBLiveVar::CreateOnBB(BB, POId);
+ BBLiveVar *LVBB;
+ std::map<const BasicBlock*, unsigned>::iterator POI = PONumbering.find(&BB);
+ if (POI != PONumbering.end()) {
+ // create a new BBLiveVar
+ LVBB = BBLiveVar::CreateOnBB(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);
+ }
if (DEBUG_LV)
LVBB->printAllSets();
}
-
- // Since the PO iterator does not discover unreachable blocks,
- // go over the random iterator and init those blocks as well.
- // However, LV info is not correct for those blocks (they are not
- // analyzed)
- //
- for (Function::const_iterator BBRI = M->begin(), BBRE = M->end();
- BBRI != BBRE; ++BBRI, ++POId)
- if (!BBLiveVar::GetFromBB(*BBRI)) // Not yet processed?
- BBLiveVar::CreateOnBB(*BBRI, POId);
}
@@ -240,7 +245,9 @@ static void applyTranferFuncForMInst(ValueSet &LVS, const MachineInstr *MInst) {
//-----------------------------------------------------------------------------
void FunctionLiveVarInfo::calcLiveVarSetsForBB(const BasicBlock *BB) {
- const MachineBasicBlock &MIVec = MachineBasicBlock::get(BB);
+ BBLiveVar *BBLV = BBLiveVar::GetFromBB(*BB);
+ assert(BBLV && "BBLiveVar annotation doesn't exist?");
+ const MachineBasicBlock &MIVec = BBLV->getMachineBasicBlock();
if (DEBUG_LV >= LV_DEBUG_Instr)
std::cerr << "\n======For BB " << BB->getName()
diff --git a/lib/Target/SparcV9/LiveVar/BBLiveVar.cpp b/lib/Target/SparcV9/LiveVar/BBLiveVar.cpp
index 54de63e58f..4b07ebc632 100644
--- a/lib/Target/SparcV9/LiveVar/BBLiveVar.cpp
+++ b/lib/Target/SparcV9/LiveVar/BBLiveVar.cpp
@@ -18,8 +18,9 @@ using std::cerr;
static AnnotationID AID(AnnotationManager::getID("Analysis::BBLiveVar"));
-BBLiveVar *BBLiveVar::CreateOnBB(const BasicBlock &BB, unsigned POID) {
- BBLiveVar *Result = new BBLiveVar(BB, POID);
+BBLiveVar *BBLiveVar::CreateOnBB(const BasicBlock &BB, MachineBasicBlock &MBB,
+ unsigned POID) {
+ BBLiveVar *Result = new BBLiveVar(BB, MBB, POID);
BB.addAnnotation(Result);
return Result;
}
@@ -34,8 +35,8 @@ void BBLiveVar::RemoveFromBB(const BasicBlock &BB) {
}
-BBLiveVar::BBLiveVar(const BasicBlock &bb, unsigned id)
- : Annotation(AID), BB(bb), POID(id) {
+BBLiveVar::BBLiveVar(const BasicBlock &bb, MachineBasicBlock &mbb, unsigned id)
+ : Annotation(AID), BB(bb), MBB(mbb), POID(id) {
InSetChanged = OutSetChanged = false;
calcDefUseSets();
@@ -49,15 +50,12 @@ BBLiveVar::BBLiveVar(const BasicBlock &bb, unsigned id)
//-----------------------------------------------------------------------------
void BBLiveVar::calcDefUseSets() {
- // get the iterator for machine instructions
- const MachineBasicBlock &MIVec = MachineBasicBlock::get(&BB);
-
// iterate over all the machine instructions in BB
- for (MachineBasicBlock::const_reverse_iterator MII = MIVec.rbegin(),
- MIE = MIVec.rend(); MII != MIE; ++MII) {
+ for (MachineBasicBlock::const_reverse_iterator MII = MBB.rbegin(),
+ MIE = MBB.rend(); MII != MIE; ++MII) {
const MachineInstr *MI = *MII;
- if (DEBUG_LV >= LV_DEBUG_Verbose) { // debug msg
+ if (DEBUG_LV >= LV_DEBUG_Verbose) {
cerr << " *Iterating over machine instr ";
MI->dump();
cerr << "\n";
diff --git a/lib/Target/SparcV9/LiveVar/BBLiveVar.h b/lib/Target/SparcV9/LiveVar/BBLiveVar.h
index 0eed3375ab..eada3a7f08 100644
--- a/lib/Target/SparcV9/LiveVar/BBLiveVar.h
+++ b/lib/Target/SparcV9/LiveVar/BBLiveVar.h
@@ -13,6 +13,7 @@
#include <map>
class BasicBlock;
class Value;
+class MachineBasicBlock;
enum LiveVarDebugLevel_t {
LV_DEBUG_None,
@@ -25,9 +26,10 @@ extern LiveVarDebugLevel_t DEBUG_LV;
class BBLiveVar : public Annotation {
const BasicBlock &BB; // pointer to BasicBlock
+ MachineBasicBlock &MBB; // Pointer to MachineBasicBlock
unsigned POID; // Post-Order ID
- ValueSet DefSet; // Def set (with no preceding uses) for LV analysis
+ ValueSet DefSet; // Def set (with no preceding uses) for LV analysis
ValueSet InSet, OutSet; // In & Out for LV analysis
bool InSetChanged, OutSetChanged; // set if the InSet/OutSet is modified
@@ -49,16 +51,19 @@ class BBLiveVar : public Annotation {
void calcDefUseSets(); // calculates the Def & Use sets for this BB
- BBLiveVar(const BasicBlock &BB, unsigned POID);
+ BBLiveVar(const BasicBlock &BB, MachineBasicBlock &MBB, unsigned POID);
~BBLiveVar() {} // make dtor private
public:
- static BBLiveVar *CreateOnBB(const BasicBlock &BB, unsigned POID);
+ 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; }
+ MachineBasicBlock &getMachineBasicBlock() const { return MBB; }
+
inline unsigned getPOId() const { return POID; }
bool applyTransferFunc(); // calcultes the In in terms of Out
diff --git a/lib/Target/SparcV9/LiveVar/FunctionLiveVarInfo.cpp b/lib/Target/SparcV9/LiveVar/FunctionLiveVarInfo.cpp
index 198afed537..962afa44a1 100644
--- a/lib/Target/SparcV9/LiveVar/FunctionLiveVarInfo.cpp
+++ b/lib/Target/SparcV9/LiveVar/FunctionLiveVarInfo.cpp
@@ -8,7 +8,7 @@
#include "llvm/Analysis/LiveVar/FunctionLiveVarInfo.h"
#include "BBLiveVar.h"
#include "llvm/CodeGen/MachineInstr.h"
-#include "llvm/CodeGen/MachineBasicBlock.h"
+#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/Support/CFG.h"
#include "Support/PostOrderIterator.h"
#include "Support/SetOperations.h"
@@ -71,31 +71,36 @@ bool FunctionLiveVarInfo::runOnFunction(Function &F) {
// constructs BBLiveVars and init Def and In sets
//-----------------------------------------------------------------------------
-void FunctionLiveVarInfo::constructBBs(const Function *M) {
- unsigned int POId = 0; // Reverse Depth-first Order ID
-
- for(po_iterator<const Function*> BBI = po_begin(M), BBE = po_end(M);
- BBI != BBE; ++BBI, ++POId) {
- const BasicBlock &BB = **BBI; // get the current BB
+void FunctionLiveVarInfo::constructBBs(const Function *F) {
+ unsigned POId = 0; // Reverse Depth-first Order ID
+ std::map<const BasicBlock*, unsigned> PONumbering;
+
+ for (po_iterator<const Function*> BBI = po_begin(M), BBE = po_end(M);
+ BBI != BBE; ++BBI)
+ PONumbering[*BBI] = POId++;
+ MachineFunction &MF = MachineFunction::get(F);
+ for (MachineFunction::iterator I = MF.begin(), E = MF.end(); I != E; ++I) {
+ const BasicBlock &BB = *I->getBasicBlock(); // get the current BB
if (DEBUG_LV) std::cerr << " For BB " << RAV(BB) << ":\n";
- // create a new BBLiveVar
- BBLiveVar *LVBB = BBLiveVar::CreateOnBB(BB, POId);
+ BBLiveVar *LVBB;
+ std::map<const BasicBlock*, unsigned>::iterator POI = PONumbering.find(&BB);
+ if (POI != PONumbering.end()) {
+ // create a new BBLiveVar
+ LVBB = BBLiveVar::CreateOnBB(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);
+ }
if (DEBUG_LV)
LVBB->printAllSets();
}
-
- // Since the PO iterator does not discover unreachable blocks,
- // go over the random iterator and init those blocks as well.
- // However, LV info is not correct for those blocks (they are not
- // analyzed)
- //
- for (Function::const_iterator BBRI = M->begin(), BBRE = M->end();
- BBRI != BBRE; ++BBRI, ++POId)
- if (!BBLiveVar::GetFromBB(*BBRI)) // Not yet processed?
- BBLiveVar::CreateOnBB(*BBRI, POId);
}
@@ -240,7 +245,9 @@ static void applyTranferFuncForMInst(ValueSet &LVS, const MachineInstr *MInst) {
//-----------------------------------------------------------------------------
void FunctionLiveVarInfo::calcLiveVarSetsForBB(const BasicBlock *BB) {
- const MachineBasicBlock &MIVec = MachineBasicBlock::get(BB);
+ BBLiveVar *BBLV = BBLiveVar::GetFromBB(*BB);
+ assert(BBLV && "BBLiveVar annotation doesn't exist?");
+ const MachineBasicBlock &MIVec = BBLV->getMachineBasicBlock();
if (DEBUG_LV >= LV_DEBUG_Instr)
std::cerr << "\n======For BB " << BB->getName()