Eliminate the cfg namespace, moving LoopInfo, Dominators, Interval* classes

to the global namespace


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2370 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2002-04-28 16:21:30 +00:00
parent 8fc2f2072d
commit 1b7f7dc4b4
14 changed files with 105 additions and 115 deletions

View File

@@ -27,7 +27,7 @@
using analysis::ExprType; using analysis::ExprType;
static bool isLoopInvariant(const Value *V, const cfg::Loop *L) { static bool isLoopInvariant(const Value *V, const Loop *L) {
if (isa<Constant>(V) || isa<Argument>(V) || isa<GlobalValue>(V)) if (isa<Constant>(V) || isa<Argument>(V) || isa<GlobalValue>(V))
return true; return true;
@@ -39,7 +39,7 @@ static bool isLoopInvariant(const Value *V, const cfg::Loop *L) {
enum InductionVariable::iType enum InductionVariable::iType
InductionVariable::Classify(const Value *Start, const Value *Step, InductionVariable::Classify(const Value *Start, const Value *Step,
const cfg::Loop *L = 0) { const Loop *L = 0) {
// Check for cannonical and simple linear expressions now... // Check for cannonical and simple linear expressions now...
if (ConstantInt *CStart = dyn_cast<ConstantInt>(Start)) if (ConstantInt *CStart = dyn_cast<ConstantInt>(Start))
if (ConstantInt *CStep = dyn_cast<ConstantInt>(Step)) { if (ConstantInt *CStep = dyn_cast<ConstantInt>(Step)) {
@@ -60,7 +60,7 @@ InductionVariable::Classify(const Value *Start, const Value *Step,
// Create an induction variable for the specified value. If it is a PHI, and // Create an induction variable for the specified value. If it is a PHI, and
// if it's recognizable, classify it and fill in instance variables. // if it's recognizable, classify it and fill in instance variables.
// //
InductionVariable::InductionVariable(PHINode *P, cfg::LoopInfo *LoopInfo) { InductionVariable::InductionVariable(PHINode *P, LoopInfo *LoopInfo) {
InductionType = Unknown; // Assume the worst InductionType = Unknown; // Assume the worst
Phi = P; Phi = P;
@@ -76,7 +76,7 @@ InductionVariable::InductionVariable(PHINode *P, cfg::LoopInfo *LoopInfo) {
// If we have loop information, make sure that this PHI node is in the header // If we have loop information, make sure that this PHI node is in the header
// of a loop... // of a loop...
// //
const cfg::Loop *L = LoopInfo ? LoopInfo->getLoopFor(Phi->getParent()) : 0; const Loop *L = LoopInfo ? LoopInfo->getLoopFor(Phi->getParent()) : 0;
if (L && L->getHeader() != Phi->getParent()) if (L && L->getHeader() != Phi->getParent())
return; return;

View File

@@ -1,7 +1,7 @@
//===- Interval.cpp - Interval class code ------------------------*- C++ -*--=// //===- Interval.cpp - Interval class code ------------------------*- C++ -*--=//
// //
// This file contains the definition of the cfg::Interval class, which // This file contains the definition of the Interval class, which represents a
// represents a partition of a control flow graph of some kind. // partition of a control flow graph of some kind.
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
@@ -15,7 +15,7 @@
// isLoop - Find out if there is a back edge in this interval... // isLoop - Find out if there is a back edge in this interval...
// //
bool cfg::Interval::isLoop() const { bool Interval::isLoop() const {
// There is a loop in this interval iff one of the predecessors of the header // There is a loop in this interval iff one of the predecessors of the header
// node lives in the interval. // node lives in the interval.
for (::pred_iterator I = ::pred_begin(HeaderNode), E = ::pred_end(HeaderNode); for (::pred_iterator I = ::pred_begin(HeaderNode), E = ::pred_end(HeaderNode);

View File

@@ -1,6 +1,6 @@
//===- IntervalPartition.cpp - Interval Partition module code ----*- C++ -*--=// //===- IntervalPartition.cpp - Interval Partition module code ----*- C++ -*--=//
// //
// This file contains the definition of the cfg::IntervalPartition class, which // This file contains the definition of the IntervalPartition class, which
// calculates and represent the interval partition of a function. // calculates and represent the interval partition of a function.
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
@@ -8,7 +8,6 @@
#include "llvm/Analysis/IntervalIterator.h" #include "llvm/Analysis/IntervalIterator.h"
#include "Support/STLExtras.h" #include "Support/STLExtras.h"
using namespace cfg;
using std::make_pair; using std::make_pair;
AnalysisID IntervalPartition::ID(AnalysisID::create<IntervalPartition>()); AnalysisID IntervalPartition::ID(AnalysisID::create<IntervalPartition>());
@@ -19,7 +18,7 @@ AnalysisID IntervalPartition::ID(AnalysisID::create<IntervalPartition>());
// destroy - Reset state back to before function was analyzed // destroy - Reset state back to before function was analyzed
void IntervalPartition::destroy() { void IntervalPartition::destroy() {
for_each(begin(), end(), deleter<cfg::Interval>); for_each(begin(), end(), deleter<Interval>);
IntervalMap.clear(); IntervalMap.clear();
RootInterval = 0; RootInterval = 0;
} }
@@ -42,7 +41,7 @@ void IntervalPartition::addIntervalToPartition(Interval *I) {
// run through all of the intervals and propogate successor info as // run through all of the intervals and propogate successor info as
// predecessor info. // predecessor info.
// //
void IntervalPartition::updatePredecessors(cfg::Interval *Int) { void IntervalPartition::updatePredecessors(Interval *Int) {
BasicBlock *Header = Int->getHeaderNode(); BasicBlock *Header = Int->getHeaderNode();
for (Interval::succ_iterator I = Int->Successors.begin(), for (Interval::succ_iterator I = Int->Successors.begin(),
E = Int->Successors.end(); I != E; ++I) E = Int->Successors.end(); I != E; ++I)

View File

@@ -13,16 +13,16 @@
#include "Support/DepthFirstIterator.h" #include "Support/DepthFirstIterator.h"
#include <algorithm> #include <algorithm>
AnalysisID cfg::LoopInfo::ID(AnalysisID::create<cfg::LoopInfo>()); AnalysisID LoopInfo::ID(AnalysisID::create<LoopInfo>());
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// cfg::Loop implementation // Loop implementation
// //
bool cfg::Loop::contains(BasicBlock *BB) const { bool Loop::contains(BasicBlock *BB) const {
return find(Blocks.begin(), Blocks.end(), BB) != Blocks.end(); return find(Blocks.begin(), Blocks.end(), BB) != Blocks.end();
} }
void cfg::LoopInfo::releaseMemory() { void LoopInfo::releaseMemory() {
for (std::vector<Loop*>::iterator I = TopLevelLoops.begin(), for (std::vector<Loop*>::iterator I = TopLevelLoops.begin(),
E = TopLevelLoops.end(); I != E; ++I) E = TopLevelLoops.end(); I != E; ++I)
delete *I; // Delete all of the loops... delete *I; // Delete all of the loops...
@@ -33,15 +33,15 @@ void cfg::LoopInfo::releaseMemory() {
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// cfg::LoopInfo implementation // LoopInfo implementation
// //
bool cfg::LoopInfo::runOnFunction(Function *F) { bool LoopInfo::runOnFunction(Function *F) {
releaseMemory(); releaseMemory();
Calculate(getAnalysis<DominatorSet>()); // Update Calculate(getAnalysis<DominatorSet>()); // Update
return false; return false;
} }
void cfg::LoopInfo::Calculate(const DominatorSet &DS) { void LoopInfo::Calculate(const DominatorSet &DS) {
BasicBlock *RootNode = DS.getRoot(); BasicBlock *RootNode = DS.getRoot();
for (df_iterator<BasicBlock*> NI = df_begin(RootNode), for (df_iterator<BasicBlock*> NI = df_begin(RootNode),
@@ -53,15 +53,14 @@ void cfg::LoopInfo::Calculate(const DominatorSet &DS) {
TopLevelLoops[i]->setLoopDepth(1); TopLevelLoops[i]->setLoopDepth(1);
} }
void cfg::LoopInfo::getAnalysisUsage(AnalysisUsage &AU) const { void LoopInfo::getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll(); AU.setPreservesAll();
AU.addRequired(DominatorSet::ID); AU.addRequired(DominatorSet::ID);
AU.addProvided(ID); AU.addProvided(ID);
} }
cfg::Loop *cfg::LoopInfo::ConsiderForLoop(BasicBlock *BB, Loop *LoopInfo::ConsiderForLoop(BasicBlock *BB, const DominatorSet &DS) {
const DominatorSet &DS) {
if (BBMap.find(BB) != BBMap.end()) return 0; // Havn't processed this node? if (BBMap.find(BB) != BBMap.end()) return 0; // Havn't processed this node?
std::vector<BasicBlock *> TodoStack; std::vector<BasicBlock *> TodoStack;

View File

@@ -19,10 +19,10 @@ using std::set;
// DominatorSet Implementation // DominatorSet Implementation
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
AnalysisID cfg::DominatorSet::ID(AnalysisID::create<cfg::DominatorSet>()); AnalysisID DominatorSet::ID(AnalysisID::create<DominatorSet>());
AnalysisID cfg::DominatorSet::PostDomID(AnalysisID::create<cfg::DominatorSet>()); AnalysisID DominatorSet::PostDomID(AnalysisID::create<DominatorSet>());
bool cfg::DominatorSet::runOnFunction(Function *F) { bool DominatorSet::runOnFunction(Function *F) {
Doms.clear(); // Reset from the last time we were run... Doms.clear(); // Reset from the last time we were run...
if (isPostDominator()) if (isPostDominator())
@@ -36,7 +36,7 @@ bool cfg::DominatorSet::runOnFunction(Function *F) {
// calcForwardDominatorSet - This method calculates the forward dominator sets // calcForwardDominatorSet - This method calculates the forward dominator sets
// for the specified function. // for the specified function.
// //
void cfg::DominatorSet::calcForwardDominatorSet(Function *M) { void DominatorSet::calcForwardDominatorSet(Function *M) {
Root = M->getEntryNode(); Root = M->getEntryNode();
assert(pred_begin(Root) == pred_end(Root) && assert(pred_begin(Root) == pred_end(Root) &&
"Root node has predecessors in function!"); "Root node has predecessors in function!");
@@ -80,7 +80,7 @@ void cfg::DominatorSet::calcForwardDominatorSet(Function *M) {
// only have a single exit node (return stmt), then calculates the post // only have a single exit node (return stmt), then calculates the post
// dominance sets for the function. // dominance sets for the function.
// //
void cfg::DominatorSet::calcPostDominatorSet(Function *F) { void DominatorSet::calcPostDominatorSet(Function *F) {
// Since we require that the unify all exit nodes pass has been run, we know // Since we require that the unify all exit nodes pass has been run, we know
// that there can be at most one return instruction in the function left. // that there can be at most one return instruction in the function left.
// Get it. // Get it.
@@ -132,7 +132,7 @@ void cfg::DominatorSet::calcPostDominatorSet(Function *F) {
// getAnalysisUsage - This obviously provides a dominator set, but it also // getAnalysisUsage - This obviously provides a dominator set, but it also
// uses the UnifyFunctionExitNodes pass if building post-dominators // uses the UnifyFunctionExitNodes pass if building post-dominators
// //
void cfg::DominatorSet::getAnalysisUsage(AnalysisUsage &AU) const { void DominatorSet::getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll(); AU.setPreservesAll();
if (isPostDominator()) { if (isPostDominator()) {
AU.addProvided(PostDomID); AU.addProvided(PostDomID);
@@ -147,12 +147,12 @@ void cfg::DominatorSet::getAnalysisUsage(AnalysisUsage &AU) const {
// ImmediateDominators Implementation // ImmediateDominators Implementation
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
AnalysisID cfg::ImmediateDominators::ID(AnalysisID::create<cfg::ImmediateDominators>()); AnalysisID ImmediateDominators::ID(AnalysisID::create<ImmediateDominators>());
AnalysisID cfg::ImmediateDominators::PostDomID(AnalysisID::create<cfg::ImmediateDominators>()); AnalysisID ImmediateDominators::PostDomID(AnalysisID::create<ImmediateDominators>());
// calcIDoms - Calculate the immediate dominator mapping, given a set of // calcIDoms - Calculate the immediate dominator mapping, given a set of
// dominators for every basic block. // dominators for every basic block.
void cfg::ImmediateDominators::calcIDoms(const DominatorSet &DS) { void ImmediateDominators::calcIDoms(const DominatorSet &DS) {
// Loop over all of the nodes that have dominators... figuring out the IDOM // Loop over all of the nodes that have dominators... figuring out the IDOM
// for each node... // for each node...
// //
@@ -191,12 +191,12 @@ void cfg::ImmediateDominators::calcIDoms(const DominatorSet &DS) {
// DominatorTree Implementation // DominatorTree Implementation
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
AnalysisID cfg::DominatorTree::ID(AnalysisID::create<cfg::DominatorTree>()); AnalysisID DominatorTree::ID(AnalysisID::create<DominatorTree>());
AnalysisID cfg::DominatorTree::PostDomID(AnalysisID::create<cfg::DominatorTree>()); AnalysisID DominatorTree::PostDomID(AnalysisID::create<DominatorTree>());
// DominatorTree::reset - Free all of the tree node memory. // DominatorTree::reset - Free all of the tree node memory.
// //
void cfg::DominatorTree::reset() { void DominatorTree::reset() {
for (NodeMapType::iterator I = Nodes.begin(), E = Nodes.end(); I != E; ++I) for (NodeMapType::iterator I = Nodes.begin(), E = Nodes.end(); I != E; ++I)
delete I->second; delete I->second;
Nodes.clear(); Nodes.clear();
@@ -205,7 +205,7 @@ void cfg::DominatorTree::reset() {
#if 0 #if 0
// Given immediate dominators, we can also calculate the dominator tree // Given immediate dominators, we can also calculate the dominator tree
cfg::DominatorTree::DominatorTree(const ImmediateDominators &IDoms) DominatorTree::DominatorTree(const ImmediateDominators &IDoms)
: DominatorBase(IDoms.getRoot()) { : DominatorBase(IDoms.getRoot()) {
const Function *M = Root->getParent(); const Function *M = Root->getParent();
@@ -230,7 +230,7 @@ cfg::DominatorTree::DominatorTree(const ImmediateDominators &IDoms)
} }
#endif #endif
void cfg::DominatorTree::calculate(const DominatorSet &DS) { void DominatorTree::calculate(const DominatorSet &DS) {
Nodes[Root] = new Node(Root, 0); // Add a node for the root... Nodes[Root] = new Node(Root, 0); // Add a node for the root...
if (!isPostDominator()) { if (!isPostDominator()) {
@@ -325,12 +325,12 @@ void cfg::DominatorTree::calculate(const DominatorSet &DS) {
// DominanceFrontier Implementation // DominanceFrontier Implementation
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
AnalysisID cfg::DominanceFrontier::ID(AnalysisID::create<cfg::DominanceFrontier>()); AnalysisID DominanceFrontier::ID(AnalysisID::create<DominanceFrontier>());
AnalysisID cfg::DominanceFrontier::PostDomID(AnalysisID::create<cfg::DominanceFrontier>()); AnalysisID DominanceFrontier::PostDomID(AnalysisID::create<DominanceFrontier>());
const cfg::DominanceFrontier::DomSetType & const DominanceFrontier::DomSetType &
cfg::DominanceFrontier::calcDomFrontier(const DominatorTree &DT, DominanceFrontier::calcDomFrontier(const DominatorTree &DT,
const DominatorTree::Node *Node) { const DominatorTree::Node *Node) {
// Loop over CFG successors to calculate DFlocal[Node] // Loop over CFG successors to calculate DFlocal[Node]
BasicBlock *BB = Node->getNode(); BasicBlock *BB = Node->getNode();
DomSetType &S = Frontiers[BB]; // The new set to fill in... DomSetType &S = Frontiers[BB]; // The new set to fill in...
@@ -361,9 +361,9 @@ cfg::DominanceFrontier::calcDomFrontier(const DominatorTree &DT,
return S; return S;
} }
const cfg::DominanceFrontier::DomSetType & const DominanceFrontier::DomSetType &
cfg::DominanceFrontier::calcPostDomFrontier(const DominatorTree &DT, DominanceFrontier::calcPostDomFrontier(const DominatorTree &DT,
const DominatorTree::Node *Node) { const DominatorTree::Node *Node) {
// Loop over CFG successors to calculate DFlocal[Node] // Loop over CFG successors to calculate DFlocal[Node]
BasicBlock *BB = Node->getNode(); BasicBlock *BB = Node->getNode();
DomSetType &S = Frontiers[BB]; // The new set to fill in... DomSetType &S = Frontiers[BB]; // The new set to fill in...

View File

@@ -23,7 +23,7 @@ using std::string;
// Interval Printing Routines // Interval Printing Routines
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
void cfg::WriteToOutput(const Interval *I, ostream &o) { void WriteToOutput(const Interval *I, ostream &o) {
o << "-------------------------------------------------------------\n" o << "-------------------------------------------------------------\n"
<< "Interval Contents:\n"; << "Interval Contents:\n";
@@ -40,7 +40,7 @@ void cfg::WriteToOutput(const Interval *I, ostream &o) {
std::ostream_iterator<BasicBlock*>(o, "\n")); std::ostream_iterator<BasicBlock*>(o, "\n"));
} }
void cfg::WriteToOutput(const IntervalPartition &IP, ostream &o) { void WriteToOutput(const IntervalPartition &IP, ostream &o) {
copy(IP.begin(), IP.end(), std::ostream_iterator<const Interval *>(o, "\n")); copy(IP.begin(), IP.end(), std::ostream_iterator<const Interval *>(o, "\n"));
} }
@@ -55,7 +55,7 @@ ostream &operator<<(ostream &o, const set<BasicBlock*> &BBs) {
return o; return o;
} }
void cfg::WriteToOutput(const DominatorSet &DS, ostream &o) { void WriteToOutput(const DominatorSet &DS, ostream &o) {
for (DominatorSet::const_iterator I = DS.begin(), E = DS.end(); I != E; ++I) { for (DominatorSet::const_iterator I = DS.begin(), E = DS.end(); I != E; ++I) {
o << "=============================--------------------------------\n" o << "=============================--------------------------------\n"
<< "\nDominator Set For Basic Block\n" << I->first << "\nDominator Set For Basic Block\n" << I->first
@@ -64,7 +64,7 @@ void cfg::WriteToOutput(const DominatorSet &DS, ostream &o) {
} }
void cfg::WriteToOutput(const ImmediateDominators &ID, ostream &o) { void WriteToOutput(const ImmediateDominators &ID, ostream &o) {
for (ImmediateDominators::const_iterator I = ID.begin(), E = ID.end(); for (ImmediateDominators::const_iterator I = ID.begin(), E = ID.end();
I != E; ++I) { I != E; ++I) {
o << "=============================--------------------------------\n" o << "=============================--------------------------------\n"
@@ -74,27 +74,27 @@ void cfg::WriteToOutput(const ImmediateDominators &ID, ostream &o) {
} }
static ostream &operator<<(ostream &o, const cfg::DominatorTree::Node *Node) { static ostream &operator<<(ostream &o, const DominatorTree::Node *Node) {
return o << Node->getNode() << "\n------------------------------------------\n"; return o << Node->getNode() << "\n------------------------------------------\n";
} }
static void PrintDomTree(const cfg::DominatorTree::Node *N, ostream &o, static void PrintDomTree(const DominatorTree::Node *N, ostream &o,
unsigned Lev) { unsigned Lev) {
o << "Level #" << Lev << ": " << N; o << "Level #" << Lev << ": " << N;
for (cfg::DominatorTree::Node::const_iterator I = N->begin(), E = N->end(); for (DominatorTree::Node::const_iterator I = N->begin(), E = N->end();
I != E; ++I) { I != E; ++I) {
PrintDomTree(*I, o, Lev+1); PrintDomTree(*I, o, Lev+1);
} }
} }
void cfg::WriteToOutput(const DominatorTree &DT, ostream &o) { void WriteToOutput(const DominatorTree &DT, ostream &o) {
o << "=============================--------------------------------\n" o << "=============================--------------------------------\n"
<< "Inorder Dominator Tree:\n"; << "Inorder Dominator Tree:\n";
PrintDomTree(DT[DT.getRoot()], o, 1); PrintDomTree(DT[DT.getRoot()], o, 1);
} }
void cfg::WriteToOutput(const DominanceFrontier &DF, ostream &o) { void WriteToOutput(const DominanceFrontier &DF, ostream &o) {
for (DominanceFrontier::const_iterator I = DF.begin(), E = DF.end(); for (DominanceFrontier::const_iterator I = DF.begin(), E = DF.end();
I != E; ++I) { I != E; ++I) {
o << "=============================--------------------------------\n" o << "=============================--------------------------------\n"
@@ -108,7 +108,7 @@ void cfg::WriteToOutput(const DominanceFrontier &DF, ostream &o) {
// Loop Printing Routines // Loop Printing Routines
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
void cfg::WriteToOutput(const Loop *L, ostream &o) { void WriteToOutput(const Loop *L, ostream &o) {
o << string(L->getLoopDepth()*2, ' ') << "Loop Containing: "; o << string(L->getLoopDepth()*2, ' ') << "Loop Containing: ";
for (unsigned i = 0; i < L->getBlocks().size(); ++i) { for (unsigned i = 0; i < L->getBlocks().size(); ++i) {
@@ -121,7 +121,7 @@ void cfg::WriteToOutput(const Loop *L, ostream &o) {
std::ostream_iterator<const Loop*>(o, "\n")); std::ostream_iterator<const Loop*>(o, "\n"));
} }
void cfg::WriteToOutput(const LoopInfo &LI, ostream &o) { void WriteToOutput(const LoopInfo &LI, ostream &o) {
copy(LI.getTopLevelLoops().begin(), LI.getTopLevelLoops().end(), copy(LI.getTopLevelLoops().begin(), LI.getTopLevelLoops().end(),
std::ostream_iterator<const Loop*>(o, "\n")); std::ostream_iterator<const Loop*>(o, "\n"));
} }

View File

@@ -51,7 +51,7 @@ namespace {
<< " ********************\n"; << " ********************\n";
PhyRegAlloc PRA(F, Target, &getAnalysis<FunctionLiveVarInfo>(), PhyRegAlloc PRA(F, Target, &getAnalysis<FunctionLiveVarInfo>(),
&getAnalysis<cfg::LoopInfo>()); &getAnalysis<LoopInfo>());
PRA.allocateRegisters(); PRA.allocateRegisters();
if (DEBUG_RA) cerr << "\nRegister allocation complete!\n"; if (DEBUG_RA) cerr << "\nRegister allocation complete!\n";
@@ -59,7 +59,7 @@ namespace {
} }
virtual void getAnalysisUsage(AnalysisUsage &AU) const { virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired(cfg::LoopInfo::ID); AU.addRequired(LoopInfo::ID);
AU.addRequired(FunctionLiveVarInfo::ID); AU.addRequired(FunctionLiveVarInfo::ID);
} }
}; };
@@ -72,10 +72,8 @@ Pass *getRegisterAllocator(TargetMachine &T) {
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// Constructor: Init local composite objects and create register classes. // Constructor: Init local composite objects and create register classes.
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
PhyRegAlloc::PhyRegAlloc(Function *F, PhyRegAlloc::PhyRegAlloc(Function *F, const TargetMachine& tm,
const TargetMachine& tm, FunctionLiveVarInfo *Lvi, LoopInfo *LDC)
FunctionLiveVarInfo *Lvi,
cfg::LoopInfo *LDC)
: TM(tm), Meth(F), : TM(tm), Meth(F),
mcInfo(MachineCodeForMethod::get(F)), mcInfo(MachineCodeForMethod::get(F)),
LVI(Lvi), LRI(F, tm, RegClassList), LVI(Lvi), LRI(F, tm, RegClassList),

View File

@@ -51,7 +51,7 @@ namespace {
<< " ********************\n"; << " ********************\n";
PhyRegAlloc PRA(F, Target, &getAnalysis<FunctionLiveVarInfo>(), PhyRegAlloc PRA(F, Target, &getAnalysis<FunctionLiveVarInfo>(),
&getAnalysis<cfg::LoopInfo>()); &getAnalysis<LoopInfo>());
PRA.allocateRegisters(); PRA.allocateRegisters();
if (DEBUG_RA) cerr << "\nRegister allocation complete!\n"; if (DEBUG_RA) cerr << "\nRegister allocation complete!\n";
@@ -59,7 +59,7 @@ namespace {
} }
virtual void getAnalysisUsage(AnalysisUsage &AU) const { virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired(cfg::LoopInfo::ID); AU.addRequired(LoopInfo::ID);
AU.addRequired(FunctionLiveVarInfo::ID); AU.addRequired(FunctionLiveVarInfo::ID);
} }
}; };
@@ -72,10 +72,8 @@ Pass *getRegisterAllocator(TargetMachine &T) {
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// Constructor: Init local composite objects and create register classes. // Constructor: Init local composite objects and create register classes.
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
PhyRegAlloc::PhyRegAlloc(Function *F, PhyRegAlloc::PhyRegAlloc(Function *F, const TargetMachine& tm,
const TargetMachine& tm, FunctionLiveVarInfo *Lvi, LoopInfo *LDC)
FunctionLiveVarInfo *Lvi,
cfg::LoopInfo *LDC)
: TM(tm), Meth(F), : TM(tm), Meth(F),
mcInfo(MachineCodeForMethod::get(F)), mcInfo(MachineCodeForMethod::get(F)),
LVI(Lvi), LRI(F, tm, RegClassList), LVI(Lvi), LRI(F, tm, RegClassList),

View File

@@ -43,7 +43,7 @@ public:
// doADCE() - Run the Agressive Dead Code Elimination algorithm, returning // doADCE() - Run the Agressive Dead Code Elimination algorithm, returning
// true if the function was modified. // true if the function was modified.
bool doADCE(cfg::DominanceFrontier &CDG); bool doADCE(DominanceFrontier &CDG);
//===--------------------------------------------------------------------===// //===--------------------------------------------------------------------===//
// The implementation of this class // The implementation of this class
@@ -77,7 +77,7 @@ private:
// doADCE() - Run the Agressive Dead Code Elimination algorithm, returning // doADCE() - Run the Agressive Dead Code Elimination algorithm, returning
// true if the function was modified. // true if the function was modified.
// //
bool ADCE::doADCE(cfg::DominanceFrontier &CDG) { bool ADCE::doADCE(DominanceFrontier &CDG) {
#ifdef DEBUG_ADCE #ifdef DEBUG_ADCE
cerr << "Function: " << M; cerr << "Function: " << M;
#endif #endif
@@ -134,10 +134,10 @@ bool ADCE::doADCE(cfg::DominanceFrontier &CDG) {
// this block is control dependant on as being alive also... // this block is control dependant on as being alive also...
// //
AliveBlocks.insert(BB); // Block is now ALIVE! AliveBlocks.insert(BB); // Block is now ALIVE!
cfg::DominanceFrontier::const_iterator It = CDG.find(BB); DominanceFrontier::const_iterator It = CDG.find(BB);
if (It != CDG.end()) { if (It != CDG.end()) {
// Get the blocks that this node is control dependant on... // Get the blocks that this node is control dependant on...
const cfg::DominanceFrontier::DomSetType &CDB = It->second; const DominanceFrontier::DomSetType &CDB = It->second;
for_each(CDB.begin(), CDB.end(), // Mark all their terminators as live for_each(CDB.begin(), CDB.end(), // Mark all their terminators as live
bind_obj(this, &ADCE::markTerminatorLive)); bind_obj(this, &ADCE::markTerminatorLive));
} }
@@ -294,12 +294,12 @@ namespace {
// //
virtual bool runOnFunction(Function *F) { virtual bool runOnFunction(Function *F) {
return ADCE(F).doADCE( return ADCE(F).doADCE(
getAnalysis<cfg::DominanceFrontier>(cfg::DominanceFrontier::PostDomID)); getAnalysis<DominanceFrontier>(DominanceFrontier::PostDomID));
} }
// getAnalysisUsage - We require post dominance frontiers (aka Control // getAnalysisUsage - We require post dominance frontiers (aka Control
// Dependence Graph) // Dependence Graph)
virtual void getAnalysisUsage(AnalysisUsage &AU) const { virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired(cfg::DominanceFrontier::PostDomID); AU.addRequired(DominanceFrontier::PostDomID);
} }
}; };
} }

View File

@@ -23,7 +23,6 @@
#include "llvm/Support/InstIterator.h" #include "llvm/Support/InstIterator.h"
#include <set> #include <set>
#include <algorithm> #include <algorithm>
using namespace cfg;
namespace { namespace {
class GCSE : public FunctionPass, public InstVisitor<GCSE, bool> { class GCSE : public FunctionPass, public InstVisitor<GCSE, bool> {

View File

@@ -33,7 +33,7 @@ static Instruction *InsertCast(Instruction *Val, const Type *Ty,
return Cast; return Cast;
} }
static bool TransformLoop(cfg::LoopInfo *Loops, cfg::Loop *Loop) { static bool TransformLoop(LoopInfo *Loops, Loop *Loop) {
// Transform all subloops before this loop... // Transform all subloops before this loop...
bool Changed = reduce_apply_bool(Loop->getSubLoops().begin(), bool Changed = reduce_apply_bool(Loop->getSubLoops().begin(),
Loop->getSubLoops().end(), Loop->getSubLoops().end(),
@@ -187,7 +187,7 @@ static bool TransformLoop(cfg::LoopInfo *Loops, cfg::Loop *Loop) {
return Changed; return Changed;
} }
static bool doit(Function *M, cfg::LoopInfo &Loops) { static bool doit(Function *M, LoopInfo &Loops) {
// Induction Variables live in the header nodes of the loops of the function // Induction Variables live in the header nodes of the loops of the function
return reduce_apply_bool(Loops.getTopLevelLoops().begin(), return reduce_apply_bool(Loops.getTopLevelLoops().begin(),
Loops.getTopLevelLoops().end(), Loops.getTopLevelLoops().end(),
@@ -198,11 +198,11 @@ static bool doit(Function *M, cfg::LoopInfo &Loops) {
namespace { namespace {
struct InductionVariableSimplify : public FunctionPass { struct InductionVariableSimplify : public FunctionPass {
virtual bool runOnFunction(Function *F) { virtual bool runOnFunction(Function *F) {
return doit(F, getAnalysis<cfg::LoopInfo>()); return doit(F, getAnalysis<LoopInfo>());
} }
virtual void getAnalysisUsage(AnalysisUsage &AU) const { virtual void getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired(cfg::LoopInfo::ID); AU.addRequired(LoopInfo::ID);
} }
}; };
} }

View File

@@ -36,7 +36,7 @@ using std::cerr;
// isLoopInvariant - Return true if the specified value/basic block source is // isLoopInvariant - Return true if the specified value/basic block source is
// an interval invariant computation. // an interval invariant computation.
// //
static bool isLoopInvariant(cfg::Interval *Int, Value *V) { static bool isLoopInvariant(Interval *Int, Value *V) {
assert(isa<Constant>(V) || isa<Instruction>(V) || isa<Argument>(V)); assert(isa<Constant>(V) || isa<Instruction>(V) || isa<Argument>(V));
if (!isa<Instruction>(V)) if (!isa<Instruction>(V))
@@ -71,7 +71,7 @@ inline LIVType neg(LIVType T) {
return T == isLIV ? isNLIV : isLIV; return T == isLIV ? isNLIV : isLIV;
} }
// //
static LIVType isLinearInductionVariableH(cfg::Interval *Int, Value *V, static LIVType isLinearInductionVariableH(Interval *Int, Value *V,
PHINode *PN) { PHINode *PN) {
if (V == PN) { return isLIV; } // PHI node references are (0+PHI) if (V == PN) { return isLIV; } // PHI node references are (0+PHI)
if (isLoopInvariant(Int, V)) return isLIC; if (isLoopInvariant(Int, V)) return isLIC;
@@ -121,7 +121,7 @@ static LIVType isLinearInductionVariableH(cfg::Interval *Int, Value *V,
// instance of the PHI node and a loop invariant value that is added or // instance of the PHI node and a loop invariant value that is added or
// subtracted to the PHI node. This is calculated by walking the SSA graph // subtracted to the PHI node. This is calculated by walking the SSA graph
// //
static inline bool isLinearInductionVariable(cfg::Interval *Int, Value *V, static inline bool isLinearInductionVariable(Interval *Int, Value *V,
PHINode *PN) { PHINode *PN) {
return isLinearInductionVariableH(Int, V, PN) == isLIV; return isLinearInductionVariableH(Int, V, PN) == isLIV;
} }
@@ -176,7 +176,7 @@ static inline bool isSimpleInductionVar(PHINode *PN) {
// TODO: This should inherit the largest type that is being used by the already // TODO: This should inherit the largest type that is being used by the already
// present induction variables (instead of always using uint) // present induction variables (instead of always using uint)
// //
static PHINode *InjectSimpleInductionVariable(cfg::Interval *Int) { static PHINode *InjectSimpleInductionVariable(Interval *Int) {
std::string PHIName, AddName; std::string PHIName, AddName;
BasicBlock *Header = Int->getHeaderNode(); BasicBlock *Header = Int->getHeaderNode();
@@ -248,7 +248,7 @@ static PHINode *InjectSimpleInductionVariable(cfg::Interval *Int) {
// One a simple induction variable is known, all other induction variables are // One a simple induction variable is known, all other induction variables are
// modified to refer to the "simple" induction variable. // modified to refer to the "simple" induction variable.
// //
static bool ProcessInterval(cfg::Interval *Int) { static bool ProcessInterval(Interval *Int) {
if (!Int->isLoop()) return false; // Not a loop? Ignore it! if (!Int->isLoop()) return false; // Not a loop? Ignore it!
std::vector<PHINode *> InductionVars; std::vector<PHINode *> InductionVars;
@@ -351,13 +351,13 @@ static bool ProcessInterval(cfg::Interval *Int) {
// ProcessIntervalPartition - This function loops over the interval partition // ProcessIntervalPartition - This function loops over the interval partition
// processing each interval with ProcessInterval // processing each interval with ProcessInterval
// //
static bool ProcessIntervalPartition(cfg::IntervalPartition &IP) { static bool ProcessIntervalPartition(IntervalPartition &IP) {
// This currently just prints out information about the interval structure // This currently just prints out information about the interval structure
// of the function... // of the function...
#if 0 #if 0
static unsigned N = 0; static unsigned N = 0;
cerr << "\n***********Interval Partition #" << (++N) << "************\n\n"; cerr << "\n***********Interval Partition #" << (++N) << "************\n\n";
copy(IP.begin(), IP.end(), ostream_iterator<cfg::Interval*>(cerr, "\n")); copy(IP.begin(), IP.end(), ostream_iterator<Interval*>(cerr, "\n"));
cerr << "\n*********** PERFORMING WORK ************\n\n"; cerr << "\n*********** PERFORMING WORK ************\n\n";
#endif #endif
@@ -372,8 +372,8 @@ static bool ProcessIntervalPartition(cfg::IntervalPartition &IP) {
// This function loops over an interval partition of a program, reducing it // This function loops over an interval partition of a program, reducing it
// until the graph is gone. // until the graph is gone.
// //
bool InductionVariableCannonicalize::doIt(Function *M, bool InductionVariableCannonicalize::doIt(Function *M, IntervalPartition &IP) {
cfg::IntervalPartition &IP) {
bool Changed = false; bool Changed = false;
#if 0 #if 0
@@ -383,7 +383,7 @@ bool InductionVariableCannonicalize::doIt(Function *M,
// Calculate the reduced version of this graph until we get to an // Calculate the reduced version of this graph until we get to an
// irreducible graph or a degenerate graph... // irreducible graph or a degenerate graph...
// //
cfg::IntervalPartition *NewIP = new cfg::IntervalPartition(*IP, false); IntervalPartition *NewIP = new IntervalPartition(*IP, false);
if (NewIP->size() == IP->size()) { if (NewIP->size() == IP->size()) {
cerr << "IRREDUCIBLE GRAPH FOUND!!!\n"; cerr << "IRREDUCIBLE GRAPH FOUND!!!\n";
return Changed; return Changed;
@@ -399,7 +399,7 @@ bool InductionVariableCannonicalize::doIt(Function *M,
bool InductionVariableCannonicalize::runOnFunction(Function *F) { bool InductionVariableCannonicalize::runOnFunction(Function *F) {
return doIt(F, getAnalysis<cfg::IntervalPartition>()); return doIt(F, getAnalysis<IntervalPartition>());
} }
// getAnalysisUsage - This function works on the call graph of a module. // getAnalysisUsage - This function works on the call graph of a module.
@@ -407,5 +407,5 @@ bool InductionVariableCannonicalize::runOnFunction(Function *F) {
// module. // module.
// //
void InductionVariableCannonicalize::getAnalysisUsage(AnalysisUsage &AU) const { void InductionVariableCannonicalize::getAnalysisUsage(AnalysisUsage &AU) const {
AU.addRequired(cfg::IntervalPartition::ID); AU.addRequired(IntervalPartition::ID);
} }

View File

@@ -29,9 +29,6 @@
using namespace std; using namespace std;
using cfg::DominanceFrontier;
namespace { namespace {
//instance of the promoter -- to keep all the local function data. //instance of the promoter -- to keep all the local function data.

View File

@@ -19,10 +19,10 @@ using std::set;
// DominatorSet Implementation // DominatorSet Implementation
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
AnalysisID cfg::DominatorSet::ID(AnalysisID::create<cfg::DominatorSet>()); AnalysisID DominatorSet::ID(AnalysisID::create<DominatorSet>());
AnalysisID cfg::DominatorSet::PostDomID(AnalysisID::create<cfg::DominatorSet>()); AnalysisID DominatorSet::PostDomID(AnalysisID::create<DominatorSet>());
bool cfg::DominatorSet::runOnFunction(Function *F) { bool DominatorSet::runOnFunction(Function *F) {
Doms.clear(); // Reset from the last time we were run... Doms.clear(); // Reset from the last time we were run...
if (isPostDominator()) if (isPostDominator())
@@ -36,7 +36,7 @@ bool cfg::DominatorSet::runOnFunction(Function *F) {
// calcForwardDominatorSet - This method calculates the forward dominator sets // calcForwardDominatorSet - This method calculates the forward dominator sets
// for the specified function. // for the specified function.
// //
void cfg::DominatorSet::calcForwardDominatorSet(Function *M) { void DominatorSet::calcForwardDominatorSet(Function *M) {
Root = M->getEntryNode(); Root = M->getEntryNode();
assert(pred_begin(Root) == pred_end(Root) && assert(pred_begin(Root) == pred_end(Root) &&
"Root node has predecessors in function!"); "Root node has predecessors in function!");
@@ -80,7 +80,7 @@ void cfg::DominatorSet::calcForwardDominatorSet(Function *M) {
// only have a single exit node (return stmt), then calculates the post // only have a single exit node (return stmt), then calculates the post
// dominance sets for the function. // dominance sets for the function.
// //
void cfg::DominatorSet::calcPostDominatorSet(Function *F) { void DominatorSet::calcPostDominatorSet(Function *F) {
// Since we require that the unify all exit nodes pass has been run, we know // Since we require that the unify all exit nodes pass has been run, we know
// that there can be at most one return instruction in the function left. // that there can be at most one return instruction in the function left.
// Get it. // Get it.
@@ -132,7 +132,7 @@ void cfg::DominatorSet::calcPostDominatorSet(Function *F) {
// getAnalysisUsage - This obviously provides a dominator set, but it also // getAnalysisUsage - This obviously provides a dominator set, but it also
// uses the UnifyFunctionExitNodes pass if building post-dominators // uses the UnifyFunctionExitNodes pass if building post-dominators
// //
void cfg::DominatorSet::getAnalysisUsage(AnalysisUsage &AU) const { void DominatorSet::getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll(); AU.setPreservesAll();
if (isPostDominator()) { if (isPostDominator()) {
AU.addProvided(PostDomID); AU.addProvided(PostDomID);
@@ -147,12 +147,12 @@ void cfg::DominatorSet::getAnalysisUsage(AnalysisUsage &AU) const {
// ImmediateDominators Implementation // ImmediateDominators Implementation
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
AnalysisID cfg::ImmediateDominators::ID(AnalysisID::create<cfg::ImmediateDominators>()); AnalysisID ImmediateDominators::ID(AnalysisID::create<ImmediateDominators>());
AnalysisID cfg::ImmediateDominators::PostDomID(AnalysisID::create<cfg::ImmediateDominators>()); AnalysisID ImmediateDominators::PostDomID(AnalysisID::create<ImmediateDominators>());
// calcIDoms - Calculate the immediate dominator mapping, given a set of // calcIDoms - Calculate the immediate dominator mapping, given a set of
// dominators for every basic block. // dominators for every basic block.
void cfg::ImmediateDominators::calcIDoms(const DominatorSet &DS) { void ImmediateDominators::calcIDoms(const DominatorSet &DS) {
// Loop over all of the nodes that have dominators... figuring out the IDOM // Loop over all of the nodes that have dominators... figuring out the IDOM
// for each node... // for each node...
// //
@@ -191,12 +191,12 @@ void cfg::ImmediateDominators::calcIDoms(const DominatorSet &DS) {
// DominatorTree Implementation // DominatorTree Implementation
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
AnalysisID cfg::DominatorTree::ID(AnalysisID::create<cfg::DominatorTree>()); AnalysisID DominatorTree::ID(AnalysisID::create<DominatorTree>());
AnalysisID cfg::DominatorTree::PostDomID(AnalysisID::create<cfg::DominatorTree>()); AnalysisID DominatorTree::PostDomID(AnalysisID::create<DominatorTree>());
// DominatorTree::reset - Free all of the tree node memory. // DominatorTree::reset - Free all of the tree node memory.
// //
void cfg::DominatorTree::reset() { void DominatorTree::reset() {
for (NodeMapType::iterator I = Nodes.begin(), E = Nodes.end(); I != E; ++I) for (NodeMapType::iterator I = Nodes.begin(), E = Nodes.end(); I != E; ++I)
delete I->second; delete I->second;
Nodes.clear(); Nodes.clear();
@@ -205,7 +205,7 @@ void cfg::DominatorTree::reset() {
#if 0 #if 0
// Given immediate dominators, we can also calculate the dominator tree // Given immediate dominators, we can also calculate the dominator tree
cfg::DominatorTree::DominatorTree(const ImmediateDominators &IDoms) DominatorTree::DominatorTree(const ImmediateDominators &IDoms)
: DominatorBase(IDoms.getRoot()) { : DominatorBase(IDoms.getRoot()) {
const Function *M = Root->getParent(); const Function *M = Root->getParent();
@@ -230,7 +230,7 @@ cfg::DominatorTree::DominatorTree(const ImmediateDominators &IDoms)
} }
#endif #endif
void cfg::DominatorTree::calculate(const DominatorSet &DS) { void DominatorTree::calculate(const DominatorSet &DS) {
Nodes[Root] = new Node(Root, 0); // Add a node for the root... Nodes[Root] = new Node(Root, 0); // Add a node for the root...
if (!isPostDominator()) { if (!isPostDominator()) {
@@ -325,12 +325,12 @@ void cfg::DominatorTree::calculate(const DominatorSet &DS) {
// DominanceFrontier Implementation // DominanceFrontier Implementation
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
AnalysisID cfg::DominanceFrontier::ID(AnalysisID::create<cfg::DominanceFrontier>()); AnalysisID DominanceFrontier::ID(AnalysisID::create<DominanceFrontier>());
AnalysisID cfg::DominanceFrontier::PostDomID(AnalysisID::create<cfg::DominanceFrontier>()); AnalysisID DominanceFrontier::PostDomID(AnalysisID::create<DominanceFrontier>());
const cfg::DominanceFrontier::DomSetType & const DominanceFrontier::DomSetType &
cfg::DominanceFrontier::calcDomFrontier(const DominatorTree &DT, DominanceFrontier::calcDomFrontier(const DominatorTree &DT,
const DominatorTree::Node *Node) { const DominatorTree::Node *Node) {
// Loop over CFG successors to calculate DFlocal[Node] // Loop over CFG successors to calculate DFlocal[Node]
BasicBlock *BB = Node->getNode(); BasicBlock *BB = Node->getNode();
DomSetType &S = Frontiers[BB]; // The new set to fill in... DomSetType &S = Frontiers[BB]; // The new set to fill in...
@@ -361,9 +361,9 @@ cfg::DominanceFrontier::calcDomFrontier(const DominatorTree &DT,
return S; return S;
} }
const cfg::DominanceFrontier::DomSetType & const DominanceFrontier::DomSetType &
cfg::DominanceFrontier::calcPostDomFrontier(const DominatorTree &DT, DominanceFrontier::calcPostDomFrontier(const DominatorTree &DT,
const DominatorTree::Node *Node) { const DominatorTree::Node *Node) {
// Loop over CFG successors to calculate DFlocal[Node] // Loop over CFG successors to calculate DFlocal[Node]
BasicBlock *BB = Node->getNode(); BasicBlock *BB = Node->getNode();
DomSetType &S = Frontiers[BB]; // The new set to fill in... DomSetType &S = Frontiers[BB]; // The new set to fill in...