mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-05-28 00:40:54 +00:00
Change the Dominator info and LoopInfo classes to keep track of BasicBlock's, not
const BasicBlocks git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2337 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
483e14ee04
commit
a298d27808
@ -35,8 +35,7 @@ protected:
|
|||||||
|
|
||||||
inline DominatorBase(bool isPostDom) : Root(0), IsPostDominators(isPostDom) {}
|
inline DominatorBase(bool isPostDom) : Root(0), IsPostDominators(isPostDom) {}
|
||||||
public:
|
public:
|
||||||
inline const BasicBlock *getRoot() const { return Root; }
|
inline BasicBlock *getRoot() const { return Root; }
|
||||||
inline BasicBlock *getRoot() { return Root; }
|
|
||||||
|
|
||||||
// Returns true if analysis based of postdoms
|
// Returns true if analysis based of postdoms
|
||||||
bool isPostDominator() const { return IsPostDominators; }
|
bool isPostDominator() const { return IsPostDominators; }
|
||||||
@ -44,14 +43,14 @@ public:
|
|||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
//
|
//
|
||||||
// DominatorSet - Maintain a set<const BasicBlock*> for every basic block in a
|
// DominatorSet - Maintain a set<BasicBlock*> for every basic block in a
|
||||||
// function, that represents the blocks that dominate the block.
|
// function, that represents the blocks that dominate the block.
|
||||||
//
|
//
|
||||||
class DominatorSet : public DominatorBase {
|
class DominatorSet : public DominatorBase {
|
||||||
public:
|
public:
|
||||||
typedef std::set<const BasicBlock*> DomSetType; // Dom set for a bb
|
typedef std::set<BasicBlock*> DomSetType; // Dom set for a bb
|
||||||
// Map of dom sets
|
// Map of dom sets
|
||||||
typedef std::map<const BasicBlock*, DomSetType> DomSetMapType;
|
typedef std::map<BasicBlock*, DomSetType> DomSetMapType;
|
||||||
private:
|
private:
|
||||||
DomSetMapType Doms;
|
DomSetMapType Doms;
|
||||||
|
|
||||||
@ -75,13 +74,13 @@ public:
|
|||||||
inline iterator begin() { return Doms.begin(); }
|
inline iterator begin() { return Doms.begin(); }
|
||||||
inline const_iterator end() const { return Doms.end(); }
|
inline const_iterator end() const { return Doms.end(); }
|
||||||
inline iterator end() { return Doms.end(); }
|
inline iterator end() { return Doms.end(); }
|
||||||
inline const_iterator find(const BasicBlock* B) const { return Doms.find(B); }
|
inline const_iterator find(BasicBlock* B) const { return Doms.find(B); }
|
||||||
inline iterator find(BasicBlock* B) { return Doms.find(B); }
|
inline iterator find(BasicBlock* B) { return Doms.find(B); }
|
||||||
|
|
||||||
// getDominators - Return the set of basic blocks that dominate the specified
|
// getDominators - Return the set of basic blocks that dominate the specified
|
||||||
// block.
|
// block.
|
||||||
//
|
//
|
||||||
inline const DomSetType &getDominators(const BasicBlock *BB) const {
|
inline const DomSetType &getDominators(BasicBlock *BB) const {
|
||||||
const_iterator I = find(BB);
|
const_iterator I = find(BB);
|
||||||
assert(I != end() && "BB not in function!");
|
assert(I != end() && "BB not in function!");
|
||||||
return I->second;
|
return I->second;
|
||||||
@ -89,7 +88,7 @@ public:
|
|||||||
|
|
||||||
// dominates - Return true if A dominates B.
|
// dominates - Return true if A dominates B.
|
||||||
//
|
//
|
||||||
inline bool dominates(const BasicBlock *A, const BasicBlock *B) const {
|
inline bool dominates(BasicBlock *A, BasicBlock *B) const {
|
||||||
return getDominators(B).count(A) != 0;
|
return getDominators(B).count(A) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,7 +105,7 @@ public:
|
|||||||
// function.
|
// function.
|
||||||
//
|
//
|
||||||
class ImmediateDominators : public DominatorBase {
|
class ImmediateDominators : public DominatorBase {
|
||||||
std::map<const BasicBlock*, const BasicBlock*> IDoms;
|
std::map<BasicBlock*, BasicBlock*> IDoms;
|
||||||
void calcIDoms(const DominatorSet &DS);
|
void calcIDoms(const DominatorSet &DS);
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -132,18 +131,17 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Accessor interface:
|
// Accessor interface:
|
||||||
typedef std::map<const BasicBlock*, const BasicBlock*> IDomMapType;
|
typedef std::map<BasicBlock*, BasicBlock*> IDomMapType;
|
||||||
typedef IDomMapType::const_iterator const_iterator;
|
typedef IDomMapType::const_iterator const_iterator;
|
||||||
inline const_iterator begin() const { return IDoms.begin(); }
|
inline const_iterator begin() const { return IDoms.begin(); }
|
||||||
inline const_iterator end() const { return IDoms.end(); }
|
inline const_iterator end() const { return IDoms.end(); }
|
||||||
inline const_iterator find(const BasicBlock* B) const { return IDoms.find(B);}
|
inline const_iterator find(BasicBlock* B) const { return IDoms.find(B);}
|
||||||
|
|
||||||
// operator[] - Return the idom for the specified basic block. The start
|
// operator[] - Return the idom for the specified basic block. The start
|
||||||
// node returns null, because it does not have an immediate dominator.
|
// node returns null, because it does not have an immediate dominator.
|
||||||
//
|
//
|
||||||
inline const BasicBlock *operator[](const BasicBlock *BB) const {
|
inline BasicBlock *operator[](BasicBlock *BB) const {
|
||||||
std::map<const BasicBlock*, const BasicBlock*>::const_iterator I =
|
std::map<BasicBlock*, BasicBlock*>::const_iterator I = IDoms.find(BB);
|
||||||
IDoms.find(BB);
|
|
||||||
return I != IDoms.end() ? I->second : 0;
|
return I != IDoms.end() ? I->second : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,17 +170,17 @@ class DominatorTree : public DominatorBase {
|
|||||||
public:
|
public:
|
||||||
typedef Node2 Node;
|
typedef Node2 Node;
|
||||||
private:
|
private:
|
||||||
std::map<const BasicBlock*, Node*> Nodes;
|
std::map<BasicBlock*, Node*> Nodes;
|
||||||
void calculate(const DominatorSet &DS);
|
void calculate(const DominatorSet &DS);
|
||||||
void reset();
|
void reset();
|
||||||
typedef std::map<const BasicBlock*, Node*> NodeMapType;
|
typedef std::map<BasicBlock*, Node*> NodeMapType;
|
||||||
public:
|
public:
|
||||||
class Node2 : public std::vector<Node*> {
|
class Node2 : public std::vector<Node*> {
|
||||||
friend class DominatorTree;
|
friend class DominatorTree;
|
||||||
const BasicBlock *TheNode;
|
BasicBlock *TheNode;
|
||||||
Node2 * const IDom;
|
Node2 *IDom;
|
||||||
public:
|
public:
|
||||||
inline const BasicBlock *getNode() const { return TheNode; }
|
inline BasicBlock *getNode() const { return TheNode; }
|
||||||
inline Node2 *getIDom() const { return IDom; }
|
inline Node2 *getIDom() const { return IDom; }
|
||||||
inline const std::vector<Node*> &getChildren() const { return *this; }
|
inline const std::vector<Node*> &getChildren() const { return *this; }
|
||||||
|
|
||||||
@ -196,7 +194,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
inline Node2(const BasicBlock *node, Node *iDom)
|
inline Node2(BasicBlock *node, Node *iDom)
|
||||||
: TheNode(node), IDom(iDom) {}
|
: TheNode(node), IDom(iDom) {}
|
||||||
inline Node2 *addChild(Node *C) { push_back(C); return C; }
|
inline Node2 *addChild(Node *C) { push_back(C); return C; }
|
||||||
};
|
};
|
||||||
@ -222,7 +220,7 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const Node *operator[](const BasicBlock *BB) const {
|
inline Node *operator[](BasicBlock *BB) const {
|
||||||
NodeMapType::const_iterator i = Nodes.find(BB);
|
NodeMapType::const_iterator i = Nodes.find(BB);
|
||||||
return (i != Nodes.end()) ? i->second : 0;
|
return (i != Nodes.end()) ? i->second : 0;
|
||||||
}
|
}
|
||||||
@ -249,8 +247,8 @@ public:
|
|||||||
//
|
//
|
||||||
class DominanceFrontier : public DominatorBase {
|
class DominanceFrontier : public DominatorBase {
|
||||||
public:
|
public:
|
||||||
typedef std::set<const BasicBlock*> DomSetType; // Dom set for a bb
|
typedef std::set<BasicBlock*> DomSetType; // Dom set for a bb
|
||||||
typedef std::map<const BasicBlock*, DomSetType> DomSetMapType; // Dom set map
|
typedef std::map<BasicBlock*, DomSetType> DomSetMapType; // Dom set map
|
||||||
private:
|
private:
|
||||||
DomSetMapType Frontiers;
|
DomSetMapType Frontiers;
|
||||||
const DomSetType &calcDomFrontier(const DominatorTree &DT,
|
const DomSetType &calcDomFrontier(const DominatorTree &DT,
|
||||||
@ -286,7 +284,7 @@ public:
|
|||||||
typedef DomSetMapType::const_iterator const_iterator;
|
typedef DomSetMapType::const_iterator const_iterator;
|
||||||
inline const_iterator begin() const { return Frontiers.begin(); }
|
inline const_iterator begin() const { return Frontiers.begin(); }
|
||||||
inline const_iterator end() const { return Frontiers.end(); }
|
inline const_iterator end() const { return Frontiers.end(); }
|
||||||
inline const_iterator find(const BasicBlock* B) const { return Frontiers.find(B); }
|
inline const_iterator find(BasicBlock* B) const { return Frontiers.find(B); }
|
||||||
|
|
||||||
// getAnalysisUsage - This obviously provides the dominance frontier, but it
|
// getAnalysisUsage - This obviously provides the dominance frontier, but it
|
||||||
// uses dominator sets
|
// uses dominator sets
|
||||||
|
@ -23,7 +23,7 @@ namespace cfg {
|
|||||||
//
|
//
|
||||||
class Loop {
|
class Loop {
|
||||||
Loop *ParentLoop;
|
Loop *ParentLoop;
|
||||||
std::vector<const BasicBlock *> Blocks; // First entry is the header node
|
std::vector<BasicBlock *> Blocks; // First entry is the header node
|
||||||
std::vector<Loop*> SubLoops; // Loops contained entirely within this one
|
std::vector<Loop*> SubLoops; // Loops contained entirely within this one
|
||||||
unsigned LoopDepth; // Nesting depth of this loop
|
unsigned LoopDepth; // Nesting depth of this loop
|
||||||
|
|
||||||
@ -32,20 +32,18 @@ class Loop {
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
inline unsigned getLoopDepth() const { return LoopDepth; }
|
inline unsigned getLoopDepth() const { return LoopDepth; }
|
||||||
inline const BasicBlock *getHeader() const { return Blocks.front(); }
|
inline BasicBlock *getHeader() const { return Blocks.front(); }
|
||||||
|
|
||||||
// contains - Return true of the specified basic block is in this loop
|
// contains - Return true of the specified basic block is in this loop
|
||||||
bool contains(const BasicBlock *BB) const;
|
bool contains(BasicBlock *BB) const;
|
||||||
|
|
||||||
// getSubLoops - Return the loops contained entirely within this loop
|
// getSubLoops - Return the loops contained entirely within this loop
|
||||||
inline const std::vector<Loop*> &getSubLoops() const { return SubLoops; }
|
inline const std::vector<Loop*> &getSubLoops() const { return SubLoops; }
|
||||||
inline const std::vector<const BasicBlock*> &getBlocks() const {
|
inline const std::vector<BasicBlock*> &getBlocks() const { return Blocks; }
|
||||||
return Blocks;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class LoopInfo;
|
friend class LoopInfo;
|
||||||
inline Loop(const BasicBlock *BB) { Blocks.push_back(BB); LoopDepth = 0; }
|
inline Loop(BasicBlock *BB) { Blocks.push_back(BB); LoopDepth = 0; }
|
||||||
~Loop() {
|
~Loop() {
|
||||||
for (unsigned i = 0, e = SubLoops.size(); i != e; ++i)
|
for (unsigned i = 0, e = SubLoops.size(); i != e; ++i)
|
||||||
delete SubLoops[i];
|
delete SubLoops[i];
|
||||||
@ -66,7 +64,7 @@ private:
|
|||||||
//
|
//
|
||||||
class LoopInfo : public FunctionPass {
|
class LoopInfo : public FunctionPass {
|
||||||
// BBMap - Mapping of basic blocks to the inner most loop they occur in
|
// BBMap - Mapping of basic blocks to the inner most loop they occur in
|
||||||
std::map<const BasicBlock *, Loop*> BBMap;
|
std::map<BasicBlock*, Loop*> BBMap;
|
||||||
std::vector<Loop*> TopLevelLoops;
|
std::vector<Loop*> TopLevelLoops;
|
||||||
public:
|
public:
|
||||||
static AnalysisID ID; // cfg::LoopInfo Analysis ID
|
static AnalysisID ID; // cfg::LoopInfo Analysis ID
|
||||||
@ -80,29 +78,29 @@ public:
|
|||||||
// getLoopFor - Return the inner most loop that BB lives in. If a basic block
|
// getLoopFor - Return the inner most loop that BB lives in. If a basic block
|
||||||
// is in no loop (for example the entry node), null is returned.
|
// is in no loop (for example the entry node), null is returned.
|
||||||
//
|
//
|
||||||
const Loop *getLoopFor(const BasicBlock *BB) const {
|
const Loop *getLoopFor(BasicBlock *BB) const {
|
||||||
std::map<const BasicBlock *, Loop*>::const_iterator I = BBMap.find(BB);
|
std::map<BasicBlock *, Loop*>::const_iterator I = BBMap.find(BB);
|
||||||
return I != BBMap.end() ? I->second : 0;
|
return I != BBMap.end() ? I->second : 0;
|
||||||
}
|
}
|
||||||
inline const Loop *operator[](const BasicBlock *BB) const {
|
inline const Loop *operator[](BasicBlock *BB) const {
|
||||||
return getLoopFor(BB);
|
return getLoopFor(BB);
|
||||||
}
|
}
|
||||||
|
|
||||||
// getLoopDepth - Return the loop nesting level of the specified block...
|
// getLoopDepth - Return the loop nesting level of the specified block...
|
||||||
unsigned getLoopDepth(const BasicBlock *BB) const {
|
unsigned getLoopDepth(BasicBlock *BB) const {
|
||||||
const Loop *L = getLoopFor(BB);
|
const Loop *L = getLoopFor(BB);
|
||||||
return L ? L->getLoopDepth() : 0;
|
return L ? L->getLoopDepth() : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
// isLoopHeader - True if the block is a loop header node
|
// isLoopHeader - True if the block is a loop header node
|
||||||
bool isLoopHeader(const BasicBlock *BB) const {
|
bool isLoopHeader(BasicBlock *BB) const {
|
||||||
return getLoopFor(BB)->getHeader() == BB;
|
return getLoopFor(BB)->getHeader() == BB;
|
||||||
}
|
}
|
||||||
// isLoopEnd - True if block jumps to loop entry
|
// isLoopEnd - True if block jumps to loop entry
|
||||||
bool isLoopEnd(const BasicBlock *BB) const;
|
bool isLoopEnd(BasicBlock *BB) const;
|
||||||
// isLoopExit - True if block is the loop exit
|
// isLoopExit - True if block is the loop exit
|
||||||
bool isLoopExit(const BasicBlock *BB) const;
|
bool isLoopExit(BasicBlock *BB) const;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// runOnFunction - Pass framework implementation
|
// runOnFunction - Pass framework implementation
|
||||||
@ -116,7 +114,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void Calculate(const DominatorSet &DS);
|
void Calculate(const DominatorSet &DS);
|
||||||
Loop *ConsiderForLoop(const BasicBlock *BB, const DominatorSet &DS);
|
Loop *ConsiderForLoop(BasicBlock *BB, const DominatorSet &DS);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // End namespace cfg
|
} // End namespace cfg
|
||||||
|
@ -31,8 +31,8 @@ static bool isLoopInvariant(const Value *V, const cfg::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;
|
||||||
|
|
||||||
const Instruction *I = cast<Instruction>(V);
|
Instruction *I = cast<Instruction>(V);
|
||||||
const BasicBlock *BB = I->getParent();
|
BasicBlock *BB = I->getParent();
|
||||||
|
|
||||||
return !L->contains(BB);
|
return !L->contains(BB);
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ AnalysisID cfg::LoopInfo::ID(AnalysisID::create<cfg::LoopInfo>());
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// cfg::Loop implementation
|
// cfg::Loop implementation
|
||||||
//
|
//
|
||||||
bool cfg::Loop::contains(const BasicBlock *BB) const {
|
bool cfg::Loop::contains(BasicBlock *BB) const {
|
||||||
return find(Blocks.begin(), Blocks.end(), BB) != Blocks.end();
|
return find(Blocks.begin(), Blocks.end(), BB) != Blocks.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,9 +42,9 @@ bool cfg::LoopInfo::runOnFunction(Function *F) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void cfg::LoopInfo::Calculate(const DominatorSet &DS) {
|
void cfg::LoopInfo::Calculate(const DominatorSet &DS) {
|
||||||
const BasicBlock *RootNode = DS.getRoot();
|
BasicBlock *RootNode = DS.getRoot();
|
||||||
|
|
||||||
for (df_iterator<const BasicBlock*> NI = df_begin(RootNode),
|
for (df_iterator<BasicBlock*> NI = df_begin(RootNode),
|
||||||
NE = df_end(RootNode); NI != NE; ++NI)
|
NE = df_end(RootNode); NI != NE; ++NI)
|
||||||
if (Loop *L = ConsiderForLoop(*NI, DS))
|
if (Loop *L = ConsiderForLoop(*NI, DS))
|
||||||
TopLevelLoops.push_back(L);
|
TopLevelLoops.push_back(L);
|
||||||
@ -60,15 +60,15 @@ void cfg::LoopInfo::getAnalysisUsage(AnalysisUsage &AU) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
cfg::Loop *cfg::LoopInfo::ConsiderForLoop(const BasicBlock *BB,
|
cfg::Loop *cfg::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<const BasicBlock *> TodoStack;
|
std::vector<BasicBlock *> TodoStack;
|
||||||
|
|
||||||
// Scan the predecessors of BB, checking to see if BB dominates any of
|
// Scan the predecessors of BB, checking to see if BB dominates any of
|
||||||
// them.
|
// them.
|
||||||
for (pred_const_iterator I = pred_begin(BB), E = pred_end(BB); I != E; ++I)
|
for (pred_iterator I = pred_begin(BB), E = pred_end(BB); I != E; ++I)
|
||||||
if (DS.dominates(BB, *I)) // If BB dominates it's predecessor...
|
if (DS.dominates(BB, *I)) // If BB dominates it's predecessor...
|
||||||
TodoStack.push_back(*I);
|
TodoStack.push_back(*I);
|
||||||
|
|
||||||
@ -79,7 +79,7 @@ cfg::Loop *cfg::LoopInfo::ConsiderForLoop(const BasicBlock *BB,
|
|||||||
BBMap[BB] = L;
|
BBMap[BB] = L;
|
||||||
|
|
||||||
while (!TodoStack.empty()) { // Process all the nodes in the loop
|
while (!TodoStack.empty()) { // Process all the nodes in the loop
|
||||||
const BasicBlock *X = TodoStack.back();
|
BasicBlock *X = TodoStack.back();
|
||||||
TodoStack.pop_back();
|
TodoStack.pop_back();
|
||||||
|
|
||||||
if (!L->contains(X)) { // As of yet unprocessed??
|
if (!L->contains(X)) { // As of yet unprocessed??
|
||||||
@ -94,7 +94,7 @@ cfg::Loop *cfg::LoopInfo::ConsiderForLoop(const BasicBlock *BB,
|
|||||||
// loop can be found for them. Also check subsidary basic blocks to see if
|
// loop can be found for them. Also check subsidary basic blocks to see if
|
||||||
// they start subloops of their own.
|
// they start subloops of their own.
|
||||||
//
|
//
|
||||||
for (std::vector<const BasicBlock*>::reverse_iterator I = L->Blocks.rbegin(),
|
for (std::vector<BasicBlock*>::reverse_iterator I = L->Blocks.rbegin(),
|
||||||
E = L->Blocks.rend(); I != E; ++I) {
|
E = L->Blocks.rend(); I != E; ++I) {
|
||||||
|
|
||||||
// Check to see if this block starts a new loop
|
// Check to see if this block starts a new loop
|
||||||
|
@ -48,8 +48,8 @@ void cfg::DominatorSet::calcForwardDominatorSet(Function *M) {
|
|||||||
DomSetType WorkingSet;
|
DomSetType WorkingSet;
|
||||||
df_iterator<Function*> It = df_begin(M), End = df_end(M);
|
df_iterator<Function*> It = df_begin(M), End = df_end(M);
|
||||||
for ( ; It != End; ++It) {
|
for ( ; It != End; ++It) {
|
||||||
const BasicBlock *BB = *It;
|
BasicBlock *BB = *It;
|
||||||
pred_const_iterator PI = pred_begin(BB), PEnd = pred_end(BB);
|
pred_iterator PI = pred_begin(BB), PEnd = pred_end(BB);
|
||||||
if (PI != PEnd) { // Is there SOME predecessor?
|
if (PI != PEnd) { // Is there SOME predecessor?
|
||||||
// Loop until we get to a predecessor that has had it's dom set filled
|
// Loop until we get to a predecessor that has had it's dom set filled
|
||||||
// in at least once. We are guaranteed to have this because we are
|
// in at least once. We are guaranteed to have this because we are
|
||||||
@ -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 *M) {
|
void cfg::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.
|
||||||
@ -88,8 +88,8 @@ void cfg::DominatorSet::calcPostDominatorSet(Function *M) {
|
|||||||
Root = getAnalysis<UnifyFunctionExitNodes>().getExitNode();
|
Root = getAnalysis<UnifyFunctionExitNodes>().getExitNode();
|
||||||
|
|
||||||
if (Root == 0) { // No exit node for the function? Postdomsets are all empty
|
if (Root == 0) { // No exit node for the function? Postdomsets are all empty
|
||||||
for (Function::const_iterator MI = M->begin(), ME = M->end(); MI!=ME; ++MI)
|
for (Function::iterator FI = F->begin(), FE = F->end(); FI != FE; ++FI)
|
||||||
Doms[*MI] = DomSetType();
|
Doms[*FI] = DomSetType();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,8 +101,8 @@ void cfg::DominatorSet::calcPostDominatorSet(Function *M) {
|
|||||||
DomSetType WorkingSet;
|
DomSetType WorkingSet;
|
||||||
idf_iterator<BasicBlock*> It = idf_begin(Root), End = idf_end(Root);
|
idf_iterator<BasicBlock*> It = idf_begin(Root), End = idf_end(Root);
|
||||||
for ( ; It != End; ++It) {
|
for ( ; It != End; ++It) {
|
||||||
const BasicBlock *BB = *It;
|
BasicBlock *BB = *It;
|
||||||
succ_const_iterator PI = succ_begin(BB), PEnd = succ_end(BB);
|
succ_iterator PI = succ_begin(BB), PEnd = succ_end(BB);
|
||||||
if (PI != PEnd) { // Is there SOME predecessor?
|
if (PI != PEnd) { // Is there SOME predecessor?
|
||||||
// Loop until we get to a successor that has had it's dom set filled
|
// Loop until we get to a successor that has had it's dom set filled
|
||||||
// in at least once. We are guaranteed to have this because we are
|
// in at least once. We are guaranteed to have this because we are
|
||||||
@ -158,7 +158,7 @@ void cfg::ImmediateDominators::calcIDoms(const DominatorSet &DS) {
|
|||||||
//
|
//
|
||||||
for (DominatorSet::const_iterator DI = DS.begin(), DEnd = DS.end();
|
for (DominatorSet::const_iterator DI = DS.begin(), DEnd = DS.end();
|
||||||
DI != DEnd; ++DI) {
|
DI != DEnd; ++DI) {
|
||||||
const BasicBlock *BB = DI->first;
|
BasicBlock *BB = DI->first;
|
||||||
const DominatorSet::DomSetType &Dominators = DI->second;
|
const DominatorSet::DomSetType &Dominators = DI->second;
|
||||||
unsigned DomSetSize = Dominators.size();
|
unsigned DomSetSize = Dominators.size();
|
||||||
if (DomSetSize == 1) continue; // Root node... IDom = null
|
if (DomSetSize == 1) continue; // Root node... IDom = null
|
||||||
@ -237,7 +237,7 @@ void cfg::DominatorTree::calculate(const DominatorSet &DS) {
|
|||||||
// Iterate over all nodes in depth first order...
|
// Iterate over all nodes in depth first order...
|
||||||
for (df_iterator<BasicBlock*> I = df_begin(Root), E = df_end(Root);
|
for (df_iterator<BasicBlock*> I = df_begin(Root), E = df_end(Root);
|
||||||
I != E; ++I) {
|
I != E; ++I) {
|
||||||
const BasicBlock *BB = *I;
|
BasicBlock *BB = *I;
|
||||||
const DominatorSet::DomSetType &Dominators = DS.getDominators(BB);
|
const DominatorSet::DomSetType &Dominators = DS.getDominators(BB);
|
||||||
unsigned DomSetSize = Dominators.size();
|
unsigned DomSetSize = Dominators.size();
|
||||||
if (DomSetSize == 1) continue; // Root node... IDom = null
|
if (DomSetSize == 1) continue; // Root node... IDom = null
|
||||||
@ -278,7 +278,7 @@ void cfg::DominatorTree::calculate(const DominatorSet &DS) {
|
|||||||
// Iterate over all nodes in depth first order...
|
// Iterate over all nodes in depth first order...
|
||||||
for (idf_iterator<BasicBlock*> I = idf_begin(Root), E = idf_end(Root);
|
for (idf_iterator<BasicBlock*> I = idf_begin(Root), E = idf_end(Root);
|
||||||
I != E; ++I) {
|
I != E; ++I) {
|
||||||
const BasicBlock *BB = *I;
|
BasicBlock *BB = *I;
|
||||||
const DominatorSet::DomSetType &Dominators = DS.getDominators(BB);
|
const DominatorSet::DomSetType &Dominators = DS.getDominators(BB);
|
||||||
unsigned DomSetSize = Dominators.size();
|
unsigned DomSetSize = Dominators.size();
|
||||||
if (DomSetSize == 1) continue; // Root node... IDom = null
|
if (DomSetSize == 1) continue; // Root node... IDom = null
|
||||||
@ -332,10 +332,10 @@ const cfg::DominanceFrontier::DomSetType &
|
|||||||
cfg::DominanceFrontier::calcDomFrontier(const DominatorTree &DT,
|
cfg::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]
|
||||||
const 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...
|
||||||
|
|
||||||
for (succ_const_iterator SI = succ_begin(BB), SE = succ_end(BB);
|
for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB);
|
||||||
SI != SE; ++SI) {
|
SI != SE; ++SI) {
|
||||||
// Does Node immediately dominate this successor?
|
// Does Node immediately dominate this successor?
|
||||||
if (DT[*SI]->getIDom() != Node)
|
if (DT[*SI]->getIDom() != Node)
|
||||||
@ -365,11 +365,11 @@ const cfg::DominanceFrontier::DomSetType &
|
|||||||
cfg::DominanceFrontier::calcPostDomFrontier(const DominatorTree &DT,
|
cfg::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]
|
||||||
const 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...
|
||||||
if (!Root) return S;
|
if (!Root) return S;
|
||||||
|
|
||||||
for (pred_const_iterator SI = pred_begin(BB), SE = pred_end(BB);
|
for (pred_iterator SI = pred_begin(BB), SE = pred_end(BB);
|
||||||
SI != SE; ++SI) {
|
SI != SE; ++SI) {
|
||||||
// Does Node immediately dominate this predeccessor?
|
// Does Node immediately dominate this predeccessor?
|
||||||
if (DT[*SI]->getIDom() != Node)
|
if (DT[*SI]->getIDom() != Node)
|
||||||
|
@ -50,8 +50,8 @@ void cfg::WriteToOutput(const IntervalPartition &IP, ostream &o) {
|
|||||||
// Dominator Printing Routines
|
// Dominator Printing Routines
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
ostream &operator<<(ostream &o, const set<const BasicBlock*> &BBs) {
|
ostream &operator<<(ostream &o, const set<BasicBlock*> &BBs) {
|
||||||
copy(BBs.begin(),BBs.end(), std::ostream_iterator<const BasicBlock*>(o,"\n"));
|
copy(BBs.begin(),BBs.end(), std::ostream_iterator<BasicBlock*>(o, "\n"));
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,8 +141,8 @@ bool PromoteInstance::PromoteFunction(Function *F, DominanceFrontier & DF) {
|
|||||||
DominanceFrontier::DomSetType s = (*it).second;
|
DominanceFrontier::DomSetType s = (*it).second;
|
||||||
for (DominanceFrontier::DomSetType::iterator p = s.begin();p!=s.end(); ++p)
|
for (DominanceFrontier::DomSetType::iterator p = s.begin();p!=s.end(); ++p)
|
||||||
{
|
{
|
||||||
if (queuePhiNode((BasicBlock *)*p, i))
|
if (queuePhiNode(*p, i))
|
||||||
PhiNodes[i].push_back((BasicBlock *)*p);
|
PhiNodes[i].push_back(*p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// perform iterative step
|
// perform iterative step
|
||||||
@ -152,8 +152,8 @@ bool PromoteInstance::PromoteFunction(Function *F, DominanceFrontier & DF) {
|
|||||||
DominanceFrontier::DomSetType s = it->second;
|
DominanceFrontier::DomSetType s = it->second;
|
||||||
for (DominanceFrontier::DomSetType::iterator p = s.begin(); p!=s.end(); ++p)
|
for (DominanceFrontier::DomSetType::iterator p = s.begin(); p!=s.end(); ++p)
|
||||||
{
|
{
|
||||||
if (queuePhiNode((BasicBlock *)*p,i))
|
if (queuePhiNode(*p,i))
|
||||||
PhiNodes[i].push_back((BasicBlock*)*p);
|
PhiNodes[i].push_back(*p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,8 +48,8 @@ void cfg::DominatorSet::calcForwardDominatorSet(Function *M) {
|
|||||||
DomSetType WorkingSet;
|
DomSetType WorkingSet;
|
||||||
df_iterator<Function*> It = df_begin(M), End = df_end(M);
|
df_iterator<Function*> It = df_begin(M), End = df_end(M);
|
||||||
for ( ; It != End; ++It) {
|
for ( ; It != End; ++It) {
|
||||||
const BasicBlock *BB = *It;
|
BasicBlock *BB = *It;
|
||||||
pred_const_iterator PI = pred_begin(BB), PEnd = pred_end(BB);
|
pred_iterator PI = pred_begin(BB), PEnd = pred_end(BB);
|
||||||
if (PI != PEnd) { // Is there SOME predecessor?
|
if (PI != PEnd) { // Is there SOME predecessor?
|
||||||
// Loop until we get to a predecessor that has had it's dom set filled
|
// Loop until we get to a predecessor that has had it's dom set filled
|
||||||
// in at least once. We are guaranteed to have this because we are
|
// in at least once. We are guaranteed to have this because we are
|
||||||
@ -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 *M) {
|
void cfg::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.
|
||||||
@ -88,8 +88,8 @@ void cfg::DominatorSet::calcPostDominatorSet(Function *M) {
|
|||||||
Root = getAnalysis<UnifyFunctionExitNodes>().getExitNode();
|
Root = getAnalysis<UnifyFunctionExitNodes>().getExitNode();
|
||||||
|
|
||||||
if (Root == 0) { // No exit node for the function? Postdomsets are all empty
|
if (Root == 0) { // No exit node for the function? Postdomsets are all empty
|
||||||
for (Function::const_iterator MI = M->begin(), ME = M->end(); MI!=ME; ++MI)
|
for (Function::iterator FI = F->begin(), FE = F->end(); FI != FE; ++FI)
|
||||||
Doms[*MI] = DomSetType();
|
Doms[*FI] = DomSetType();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,8 +101,8 @@ void cfg::DominatorSet::calcPostDominatorSet(Function *M) {
|
|||||||
DomSetType WorkingSet;
|
DomSetType WorkingSet;
|
||||||
idf_iterator<BasicBlock*> It = idf_begin(Root), End = idf_end(Root);
|
idf_iterator<BasicBlock*> It = idf_begin(Root), End = idf_end(Root);
|
||||||
for ( ; It != End; ++It) {
|
for ( ; It != End; ++It) {
|
||||||
const BasicBlock *BB = *It;
|
BasicBlock *BB = *It;
|
||||||
succ_const_iterator PI = succ_begin(BB), PEnd = succ_end(BB);
|
succ_iterator PI = succ_begin(BB), PEnd = succ_end(BB);
|
||||||
if (PI != PEnd) { // Is there SOME predecessor?
|
if (PI != PEnd) { // Is there SOME predecessor?
|
||||||
// Loop until we get to a successor that has had it's dom set filled
|
// Loop until we get to a successor that has had it's dom set filled
|
||||||
// in at least once. We are guaranteed to have this because we are
|
// in at least once. We are guaranteed to have this because we are
|
||||||
@ -158,7 +158,7 @@ void cfg::ImmediateDominators::calcIDoms(const DominatorSet &DS) {
|
|||||||
//
|
//
|
||||||
for (DominatorSet::const_iterator DI = DS.begin(), DEnd = DS.end();
|
for (DominatorSet::const_iterator DI = DS.begin(), DEnd = DS.end();
|
||||||
DI != DEnd; ++DI) {
|
DI != DEnd; ++DI) {
|
||||||
const BasicBlock *BB = DI->first;
|
BasicBlock *BB = DI->first;
|
||||||
const DominatorSet::DomSetType &Dominators = DI->second;
|
const DominatorSet::DomSetType &Dominators = DI->second;
|
||||||
unsigned DomSetSize = Dominators.size();
|
unsigned DomSetSize = Dominators.size();
|
||||||
if (DomSetSize == 1) continue; // Root node... IDom = null
|
if (DomSetSize == 1) continue; // Root node... IDom = null
|
||||||
@ -237,7 +237,7 @@ void cfg::DominatorTree::calculate(const DominatorSet &DS) {
|
|||||||
// Iterate over all nodes in depth first order...
|
// Iterate over all nodes in depth first order...
|
||||||
for (df_iterator<BasicBlock*> I = df_begin(Root), E = df_end(Root);
|
for (df_iterator<BasicBlock*> I = df_begin(Root), E = df_end(Root);
|
||||||
I != E; ++I) {
|
I != E; ++I) {
|
||||||
const BasicBlock *BB = *I;
|
BasicBlock *BB = *I;
|
||||||
const DominatorSet::DomSetType &Dominators = DS.getDominators(BB);
|
const DominatorSet::DomSetType &Dominators = DS.getDominators(BB);
|
||||||
unsigned DomSetSize = Dominators.size();
|
unsigned DomSetSize = Dominators.size();
|
||||||
if (DomSetSize == 1) continue; // Root node... IDom = null
|
if (DomSetSize == 1) continue; // Root node... IDom = null
|
||||||
@ -278,7 +278,7 @@ void cfg::DominatorTree::calculate(const DominatorSet &DS) {
|
|||||||
// Iterate over all nodes in depth first order...
|
// Iterate over all nodes in depth first order...
|
||||||
for (idf_iterator<BasicBlock*> I = idf_begin(Root), E = idf_end(Root);
|
for (idf_iterator<BasicBlock*> I = idf_begin(Root), E = idf_end(Root);
|
||||||
I != E; ++I) {
|
I != E; ++I) {
|
||||||
const BasicBlock *BB = *I;
|
BasicBlock *BB = *I;
|
||||||
const DominatorSet::DomSetType &Dominators = DS.getDominators(BB);
|
const DominatorSet::DomSetType &Dominators = DS.getDominators(BB);
|
||||||
unsigned DomSetSize = Dominators.size();
|
unsigned DomSetSize = Dominators.size();
|
||||||
if (DomSetSize == 1) continue; // Root node... IDom = null
|
if (DomSetSize == 1) continue; // Root node... IDom = null
|
||||||
@ -332,10 +332,10 @@ const cfg::DominanceFrontier::DomSetType &
|
|||||||
cfg::DominanceFrontier::calcDomFrontier(const DominatorTree &DT,
|
cfg::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]
|
||||||
const 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...
|
||||||
|
|
||||||
for (succ_const_iterator SI = succ_begin(BB), SE = succ_end(BB);
|
for (succ_iterator SI = succ_begin(BB), SE = succ_end(BB);
|
||||||
SI != SE; ++SI) {
|
SI != SE; ++SI) {
|
||||||
// Does Node immediately dominate this successor?
|
// Does Node immediately dominate this successor?
|
||||||
if (DT[*SI]->getIDom() != Node)
|
if (DT[*SI]->getIDom() != Node)
|
||||||
@ -365,11 +365,11 @@ const cfg::DominanceFrontier::DomSetType &
|
|||||||
cfg::DominanceFrontier::calcPostDomFrontier(const DominatorTree &DT,
|
cfg::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]
|
||||||
const 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...
|
||||||
if (!Root) return S;
|
if (!Root) return S;
|
||||||
|
|
||||||
for (pred_const_iterator SI = pred_begin(BB), SE = pred_end(BB);
|
for (pred_iterator SI = pred_begin(BB), SE = pred_end(BB);
|
||||||
SI != SE; ++SI) {
|
SI != SE; ++SI) {
|
||||||
// Does Node immediately dominate this predeccessor?
|
// Does Node immediately dominate this predeccessor?
|
||||||
if (DT[*SI]->getIDom() != Node)
|
if (DT[*SI]->getIDom() != Node)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user