llvm.org GIT mirror llvm / 1b7f7dc
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 Chris Lattner 18 years ago
14 changed file(s) with 110 addition(s) and 120 deletion(s). Raw diff Collapse all Expand all
2626 using analysis::ExprType;
2727
2828
29 static bool isLoopInvariant(const Value *V, const cfg::Loop *L) {
29 static bool isLoopInvariant(const Value *V, const Loop *L) {
3030 if (isa(V) || isa(V) || isa(V))
3131 return true;
3232
3838
3939 enum InductionVariable::iType
4040 InductionVariable::Classify(const Value *Start, const Value *Step,
41 const cfg::Loop *L = 0) {
41 const Loop *L = 0) {
4242 // Check for cannonical and simple linear expressions now...
4343 if (ConstantInt *CStart = dyn_cast(Start))
4444 if (ConstantInt *CStep = dyn_cast(Step)) {
5959 // Create an induction variable for the specified value. If it is a PHI, and
6060 // if it's recognizable, classify it and fill in instance variables.
6161 //
62 InductionVariable::InductionVariable(PHINode *P, cfg::LoopInfo *LoopInfo) {
62 InductionVariable::InductionVariable(PHINode *P, LoopInfo *LoopInfo) {
6363 InductionType = Unknown; // Assume the worst
6464 Phi = P;
6565
7575 // If we have loop information, make sure that this PHI node is in the header
7676 // of a loop...
7777 //
78 const cfg::Loop *L = LoopInfo ? LoopInfo->getLoopFor(Phi->getParent()) : 0;
78 const Loop *L = LoopInfo ? LoopInfo->getLoopFor(Phi->getParent()) : 0;
7979 if (L && L->getHeader() != Phi->getParent())
8080 return;
8181
0 //===- Interval.cpp - Interval class code ------------------------*- C++ -*--=//
11 //
2 // This file contains the definition of the cfg::Interval class, which
3 // represents a partition of a control flow graph of some kind.
2 // This file contains the definition of the Interval class, which represents a
3 // partition of a control flow graph of some kind.
44 //
55 //===----------------------------------------------------------------------===//
66
1414
1515 // isLoop - Find out if there is a back edge in this interval...
1616 //
17 bool cfg::Interval::isLoop() const {
17 bool Interval::isLoop() const {
1818 // There is a loop in this interval iff one of the predecessors of the header
1919 // node lives in the interval.
2020 for (::pred_iterator I = ::pred_begin(HeaderNode), E = ::pred_end(HeaderNode);
0 //===- IntervalPartition.cpp - Interval Partition module code ----*- C++ -*--=//
11 //
2 // This file contains the definition of the cfg::IntervalPartition class, which
2 // This file contains the definition of the IntervalPartition class, which
33 // calculates and represent the interval partition of a function.
44 //
55 //===----------------------------------------------------------------------===//
77 #include "llvm/Analysis/IntervalIterator.h"
88 #include "Support/STLExtras.h"
99
10 using namespace cfg;
1110 using std::make_pair;
1211
1312 AnalysisID IntervalPartition::ID(AnalysisID::create());
1817
1918 // destroy - Reset state back to before function was analyzed
2019 void IntervalPartition::destroy() {
21 for_each(begin(), end(), deleter<cfg::Interval>);
20 for_each(begin(), end(), deleter<Interval>);
2221 IntervalMap.clear();
2322 RootInterval = 0;
2423 }
4140 // run through all of the intervals and propogate successor info as
4241 // predecessor info.
4342 //
44 void IntervalPartition::updatePredecessors(cfg::Interval *Int) {
43 void IntervalPartition::updatePredecessors(Interval *Int) {
4544 BasicBlock *Header = Int->getHeaderNode();
4645 for (Interval::succ_iterator I = Int->Successors.begin(),
4746 E = Int->Successors.end(); I != E; ++I)
1212 #include "Support/DepthFirstIterator.h"
1313 #include
1414
15 AnalysisID cfg::LoopInfo::ID(AnalysisID::createLoopInfo>());
15 AnalysisID LoopInfo::ID(AnalysisID::create<LoopInfo>());
1616
1717 //===----------------------------------------------------------------------===//
18 // cfg::Loop implementation
18 // Loop implementation
1919 //
20 bool cfg::Loop::contains(BasicBlock *BB) const {
20 bool Loop::contains(BasicBlock *BB) const {
2121 return find(Blocks.begin(), Blocks.end(), BB) != Blocks.end();
2222 }
2323
24 void cfg::LoopInfo::releaseMemory() {
24 void LoopInfo::releaseMemory() {
2525 for (std::vector::iterator I = TopLevelLoops.begin(),
2626 E = TopLevelLoops.end(); I != E; ++I)
2727 delete *I; // Delete all of the loops...
3232
3333
3434 //===----------------------------------------------------------------------===//
35 // cfg::LoopInfo implementation
35 // LoopInfo implementation
3636 //
37 bool cfg::LoopInfo::runOnFunction(Function *F) {
37 bool LoopInfo::runOnFunction(Function *F) {
3838 releaseMemory();
3939 Calculate(getAnalysis()); // Update
4040 return false;
4141 }
4242
43 void cfg::LoopInfo::Calculate(const DominatorSet &DS) {
43 void LoopInfo::Calculate(const DominatorSet &DS) {
4444 BasicBlock *RootNode = DS.getRoot();
4545
4646 for (df_iterator NI = df_begin(RootNode),
5252 TopLevelLoops[i]->setLoopDepth(1);
5353 }
5454
55 void cfg::LoopInfo::getAnalysisUsage(AnalysisUsage &AU) const {
55 void LoopInfo::getAnalysisUsage(AnalysisUsage &AU) const {
5656 AU.setPreservesAll();
5757 AU.addRequired(DominatorSet::ID);
5858 AU.addProvided(ID);
5959 }
6060
6161
62 cfg::Loop *cfg::LoopInfo::ConsiderForLoop(BasicBlock *BB,
63 const DominatorSet &DS) {
62 Loop *LoopInfo::ConsiderForLoop(BasicBlock *BB, const DominatorSet &DS) {
6463 if (BBMap.find(BB) != BBMap.end()) return 0; // Havn't processed this node?
6564
6665 std::vector TodoStack;
1818 // DominatorSet Implementation
1919 //===----------------------------------------------------------------------===//
2020
21 AnalysisID cfg::DominatorSet::ID(AnalysisID::create());
22 AnalysisID cfg::DominatorSet::PostDomID(AnalysisID::create());
23
24 bool cfg::DominatorSet::runOnFunction(Function *F) {
21 AnalysisID DominatorSet::ID(AnalysisID::create());
22 AnalysisID DominatorSet::PostDomID(AnalysisID::create());
23
24 bool DominatorSet::runOnFunction(Function *F) {
2525 Doms.clear(); // Reset from the last time we were run...
2626
2727 if (isPostDominator())
3535 // calcForwardDominatorSet - This method calculates the forward dominator sets
3636 // for the specified function.
3737 //
38 void cfg::DominatorSet::calcForwardDominatorSet(Function *M) {
38 void DominatorSet::calcForwardDominatorSet(Function *M) {
3939 Root = M->getEntryNode();
4040 assert(pred_begin(Root) == pred_end(Root) &&
4141 "Root node has predecessors in function!");
7979 // only have a single exit node (return stmt), then calculates the post
8080 // dominance sets for the function.
8181 //
82 void cfg::DominatorSet::calcPostDominatorSet(Function *F) {
82 void DominatorSet::calcPostDominatorSet(Function *F) {
8383 // Since we require that the unify all exit nodes pass has been run, we know
8484 // that there can be at most one return instruction in the function left.
8585 // Get it.
131131 // getAnalysisUsage - This obviously provides a dominator set, but it also
132132 // uses the UnifyFunctionExitNodes pass if building post-dominators
133133 //
134 void cfg::DominatorSet::getAnalysisUsage(AnalysisUsage &AU) const {
134 void DominatorSet::getAnalysisUsage(AnalysisUsage &AU) const {
135135 AU.setPreservesAll();
136136 if (isPostDominator()) {
137137 AU.addProvided(PostDomID);
146146 // ImmediateDominators Implementation
147147 //===----------------------------------------------------------------------===//
148148
149 AnalysisID cfg::ImmediateDominators::ID(AnalysisID::create());
150 AnalysisID cfg::ImmediateDominators::PostDomID(AnalysisID::createImmediateDominators>());
149 AnalysisID ImmediateDominators::ID(AnalysisID::create<ImmediateDominators>());
150 AnalysisID ImmediateDominators::PostDomID(AnalysisID::create());
151151
152152 // calcIDoms - Calculate the immediate dominator mapping, given a set of
153153 // dominators for every basic block.
154 void cfg::ImmediateDominators::calcIDoms(const DominatorSet &DS) {
154 void ImmediateDominators::calcIDoms(const DominatorSet &DS) {
155155 // Loop over all of the nodes that have dominators... figuring out the IDOM
156156 // for each node...
157157 //
190190 // DominatorTree Implementation
191191 //===----------------------------------------------------------------------===//
192192
193 AnalysisID cfg::DominatorTree::ID(AnalysisID::create());
194 AnalysisID cfg::DominatorTree::PostDomID(AnalysisID::createDominatorTree>());
193 AnalysisID DominatorTree::ID(AnalysisID::create<DominatorTree>());
194 AnalysisID DominatorTree::PostDomID(AnalysisID::create());
195195
196196 // DominatorTree::reset - Free all of the tree node memory.
197197 //
198 void cfg::DominatorTree::reset() {
198 void DominatorTree::reset() {
199199 for (NodeMapType::iterator I = Nodes.begin(), E = Nodes.end(); I != E; ++I)
200200 delete I->second;
201201 Nodes.clear();
204204
205205 #if 0
206206 // Given immediate dominators, we can also calculate the dominator tree
207 cfg::DominatorTree::DominatorTree(const ImmediateDominators &IDoms)
207 DominatorTree::DominatorTree(const ImmediateDominators &IDoms)
208208 : DominatorBase(IDoms.getRoot()) {
209209 const Function *M = Root->getParent();
210210
229229 }
230230 #endif
231231
232 void cfg::DominatorTree::calculate(const DominatorSet &DS) {
232 void DominatorTree::calculate(const DominatorSet &DS) {
233233 Nodes[Root] = new Node(Root, 0); // Add a node for the root...
234234
235235 if (!isPostDominator()) {
324324 // DominanceFrontier Implementation
325325 //===----------------------------------------------------------------------===//
326326
327 AnalysisID cfg::DominanceFrontier::ID(AnalysisID::create());
328 AnalysisID cfg::DominanceFrontier::PostDomID(AnalysisID::create());
329
330 const cfg::DominanceFrontier::DomSetType &
331 cfg::DominanceFrontier::calcDomFrontier(const DominatorTree &DT,
332 const DominatorTree::Node *Node) {
327 AnalysisID DominanceFrontier::ID(AnalysisID::create());
328 AnalysisID DominanceFrontier::PostDomID(AnalysisID::create());
329
330 const DominanceFrontier::DomSetType &
331 DominanceFrontier::calcDomFrontier(const DominatorTree &DT,
332 const DominatorTree::Node *Node) {
333333 // Loop over CFG successors to calculate DFlocal[Node]
334334 BasicBlock *BB = Node->getNode();
335335 DomSetType &S = Frontiers[BB]; // The new set to fill in...
360360 return S;
361361 }
362362
363 const cfg::DominanceFrontier::DomSetType &
364 cfg::DominanceFrontier::calcPostDomFrontier(const DominatorTree &DT,
365 const DominatorTree::Node *Node) {
363 const DominanceFrontier::DomSetType &
364 DominanceFrontier::calcPostDomFrontier(const DominatorTree &DT,
365 const DominatorTree::Node *Node) {
366366 // Loop over CFG successors to calculate DFlocal[Node]
367367 BasicBlock *BB = Node->getNode();
368368 DomSetType &S = Frontiers[BB]; // The new set to fill in...
2222 // Interval Printing Routines
2323 //===----------------------------------------------------------------------===//
2424
25 void cfg::WriteToOutput(const Interval *I, ostream &o) {
25 void WriteToOutput(const Interval *I, ostream &o) {
2626 o << "-------------------------------------------------------------\n"
2727 << "Interval Contents:\n";
2828
3939 std::ostream_iterator(o, "\n"));
4040 }
4141
42 void cfg::WriteToOutput(const IntervalPartition &IP, ostream &o) {
42 void WriteToOutput(const IntervalPartition &IP, ostream &o) {
4343 copy(IP.begin(), IP.end(), std::ostream_iterator(o, "\n"));
4444 }
4545
5454 return o;
5555 }
5656
57 void cfg::WriteToOutput(const DominatorSet &DS, ostream &o) {
57 void WriteToOutput(const DominatorSet &DS, ostream &o) {
5858 for (DominatorSet::const_iterator I = DS.begin(), E = DS.end(); I != E; ++I) {
5959 o << "=============================--------------------------------\n"
6060 << "\nDominator Set For Basic Block\n" << I->first
6363 }
6464
6565
66 void cfg::WriteToOutput(const ImmediateDominators &ID, ostream &o) {
66 void WriteToOutput(const ImmediateDominators &ID, ostream &o) {
6767 for (ImmediateDominators::const_iterator I = ID.begin(), E = ID.end();
6868 I != E; ++I) {
6969 o << "=============================--------------------------------\n"
7373 }
7474
7575
76 static ostream &operator<<(ostream &o, const cfg::DominatorTree::Node *Node) {
76 static ostream &operator<<(ostream &o, const DominatorTree::Node *Node) {
7777 return o << Node->getNode() << "\n------------------------------------------\n";
7878
7979 }
8080
81 static void PrintDomTree(const cfg::DominatorTree::Node *N, ostream &o,
82 unsigned Lev) {
81 static void PrintDomTree(const DominatorTree::Node *N, ostream &o,
82 unsigned Lev) {
8383 o << "Level #" << Lev << ": " << N;
84 for (cfg::DominatorTree::Node::const_iterator I = N->begin(), E = N->end();
84 for (DominatorTree::Node::const_iterator I = N->begin(), E = N->end();
8585 I != E; ++I) {
8686 PrintDomTree(*I, o, Lev+1);
8787 }
8888 }
8989
90 void cfg::WriteToOutput(const DominatorTree &DT, ostream &o) {
90 void WriteToOutput(const DominatorTree &DT, ostream &o) {
9191 o << "=============================--------------------------------\n"
9292 << "Inorder Dominator Tree:\n";
9393 PrintDomTree(DT[DT.getRoot()], o, 1);
9494 }
9595
96 void cfg::WriteToOutput(const DominanceFrontier &DF, ostream &o) {
96 void WriteToOutput(const DominanceFrontier &DF, ostream &o) {
9797 for (DominanceFrontier::const_iterator I = DF.begin(), E = DF.end();
9898 I != E; ++I) {
9999 o << "=============================--------------------------------\n"
107107 // Loop Printing Routines
108108 //===----------------------------------------------------------------------===//
109109
110 void cfg::WriteToOutput(const Loop *L, ostream &o) {
110 void WriteToOutput(const Loop *L, ostream &o) {
111111 o << string(L->getLoopDepth()*2, ' ') << "Loop Containing: ";
112112
113113 for (unsigned i = 0; i < L->getBlocks().size(); ++i) {
120120 std::ostream_iterator(o, "\n"));
121121 }
122122
123 void cfg::WriteToOutput(const LoopInfo &LI, ostream &o) {
123 void WriteToOutput(const LoopInfo &LI, ostream &o) {
124124 copy(LI.getTopLevelLoops().begin(), LI.getTopLevelLoops().end(),
125125 std::ostream_iterator(o, "\n"));
126126 }
5050 << " ********************\n";
5151
5252 PhyRegAlloc PRA(F, Target, &getAnalysis(),
53 &getAnalysis<cfg::LoopInfo>());
53 &getAnalysis<LoopInfo>());
5454 PRA.allocateRegisters();
5555
5656 if (DEBUG_RA) cerr << "\nRegister allocation complete!\n";
5858 }
5959
6060 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
61 AU.addRequired(cfg::LoopInfo::ID);
61 AU.addRequired(LoopInfo::ID);
6262 AU.addRequired(FunctionLiveVarInfo::ID);
6363 }
6464 };
7171 //----------------------------------------------------------------------------
7272 // Constructor: Init local composite objects and create register classes.
7373 //----------------------------------------------------------------------------
74 PhyRegAlloc::PhyRegAlloc(Function *F,
75 const TargetMachine& tm,
76 FunctionLiveVarInfo *Lvi,
77 cfg::LoopInfo *LDC)
74 PhyRegAlloc::PhyRegAlloc(Function *F, const TargetMachine& tm,
75 FunctionLiveVarInfo *Lvi, LoopInfo *LDC)
7876 : TM(tm), Meth(F),
7977 mcInfo(MachineCodeForMethod::get(F)),
8078 LVI(Lvi), LRI(F, tm, RegClassList),
5050 << " ********************\n";
5151
5252 PhyRegAlloc PRA(F, Target, &getAnalysis(),
53 &getAnalysis<cfg::LoopInfo>());
53 &getAnalysis<LoopInfo>());
5454 PRA.allocateRegisters();
5555
5656 if (DEBUG_RA) cerr << "\nRegister allocation complete!\n";
5858 }
5959
6060 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
61 AU.addRequired(cfg::LoopInfo::ID);
61 AU.addRequired(LoopInfo::ID);
6262 AU.addRequired(FunctionLiveVarInfo::ID);
6363 }
6464 };
7171 //----------------------------------------------------------------------------
7272 // Constructor: Init local composite objects and create register classes.
7373 //----------------------------------------------------------------------------
74 PhyRegAlloc::PhyRegAlloc(Function *F,
75 const TargetMachine& tm,
76 FunctionLiveVarInfo *Lvi,
77 cfg::LoopInfo *LDC)
74 PhyRegAlloc::PhyRegAlloc(Function *F, const TargetMachine& tm,
75 FunctionLiveVarInfo *Lvi, LoopInfo *LDC)
7876 : TM(tm), Meth(F),
7977 mcInfo(MachineCodeForMethod::get(F)),
8078 LVI(Lvi), LRI(F, tm, RegClassList),
4242
4343 // doADCE() - Run the Agressive Dead Code Elimination algorithm, returning
4444 // true if the function was modified.
45 bool doADCE(cfg::DominanceFrontier &CDG);
45 bool doADCE(DominanceFrontier &CDG);
4646
4747 //===--------------------------------------------------------------------===//
4848 // The implementation of this class
7676 // doADCE() - Run the Agressive Dead Code Elimination algorithm, returning
7777 // true if the function was modified.
7878 //
79 bool ADCE::doADCE(cfg::DominanceFrontier &CDG) {
79 bool ADCE::doADCE(DominanceFrontier &CDG) {
8080 #ifdef DEBUG_ADCE
8181 cerr << "Function: " << M;
8282 #endif
133133 // this block is control dependant on as being alive also...
134134 //
135135 AliveBlocks.insert(BB); // Block is now ALIVE!
136 cfg::DominanceFrontier::const_iterator It = CDG.find(BB);
136 DominanceFrontier::const_iterator It = CDG.find(BB);
137137 if (It != CDG.end()) {
138138 // Get the blocks that this node is control dependant on...
139 const cfg::DominanceFrontier::DomSetType &CDB = It->second;
139 const DominanceFrontier::DomSetType &CDB = It->second;
140140 for_each(CDB.begin(), CDB.end(), // Mark all their terminators as live
141141 bind_obj(this, &ADCE::markTerminatorLive));
142142 }
293293 //
294294 virtual bool runOnFunction(Function *F) {
295295 return ADCE(F).doADCE(
296 getAnalysis(cfg::DominanceFrontier::PostDomID));
296 getAnalysis(DominanceFrontier::PostDomID));
297297 }
298298 // getAnalysisUsage - We require post dominance frontiers (aka Control
299299 // Dependence Graph)
300300 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
301 AU.addRequired(cfg::DominanceFrontier::PostDomID);
301 AU.addRequired(DominanceFrontier::PostDomID);
302302 }
303303 };
304304 }
2222 #include "llvm/Support/InstIterator.h"
2323 #include
2424 #include
25 using namespace cfg;
2625
2726 namespace {
2827 class GCSE : public FunctionPass, public InstVisitor {
3232 return Cast;
3333 }
3434
35 static bool TransformLoop(cfg::LoopInfo *Loops, cfg::Loop *Loop) {
35 static bool TransformLoop(LoopInfo *Loops, Loop *Loop) {
3636 // Transform all subloops before this loop...
3737 bool Changed = reduce_apply_bool(Loop->getSubLoops().begin(),
3838 Loop->getSubLoops().end(),
186186 return Changed;
187187 }
188188
189 static bool doit(Function *M, cfg::LoopInfo &Loops) {
189 static bool doit(Function *M, LoopInfo &Loops) {
190190 // Induction Variables live in the header nodes of the loops of the function
191191 return reduce_apply_bool(Loops.getTopLevelLoops().begin(),
192192 Loops.getTopLevelLoops().end(),
197197 namespace {
198198 struct InductionVariableSimplify : public FunctionPass {
199199 virtual bool runOnFunction(Function *F) {
200 return doit(F, getAnalysis<cfg::LoopInfo>());
200 return doit(F, getAnalysis<LoopInfo>());
201201 }
202202
203203 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
204 AU.addRequired(cfg::LoopInfo::ID);
204 AU.addRequired(LoopInfo::ID);
205205 }
206206 };
207207 }
3535 // isLoopInvariant - Return true if the specified value/basic block source is
3636 // an interval invariant computation.
3737 //
38 static bool isLoopInvariant(cfg::Interval *Int, Value *V) {
38 static bool isLoopInvariant(Interval *Int, Value *V) {
3939 assert(isa(V) || isa(V) || isa(V));
4040
4141 if (!isa(V))
7070 return T == isLIV ? isNLIV : isLIV;
7171 }
7272 //
73 static LIVType isLinearInductionVariableH(cfg::Interval *Int, Value *V,
73 static LIVType isLinearInductionVariableH(Interval *Int, Value *V,
7474 PHINode *PN) {
7575 if (V == PN) { return isLIV; } // PHI node references are (0+PHI)
7676 if (isLoopInvariant(Int, V)) return isLIC;
120120 // instance of the PHI node and a loop invariant value that is added or
121121 // subtracted to the PHI node. This is calculated by walking the SSA graph
122122 //
123 static inline bool isLinearInductionVariable(cfg::Interval *Int, Value *V,
123 static inline bool isLinearInductionVariable(Interval *Int, Value *V,
124124 PHINode *PN) {
125125 return isLinearInductionVariableH(Int, V, PN) == isLIV;
126126 }
175175 // TODO: This should inherit the largest type that is being used by the already
176176 // present induction variables (instead of always using uint)
177177 //
178 static PHINode *InjectSimpleInductionVariable(cfg::Interval *Int) {
178 static PHINode *InjectSimpleInductionVariable(Interval *Int) {
179179 std::string PHIName, AddName;
180180
181181 BasicBlock *Header = Int->getHeaderNode();
247247 // One a simple induction variable is known, all other induction variables are
248248 // modified to refer to the "simple" induction variable.
249249 //
250 static bool ProcessInterval(cfg::Interval *Int) {
250 static bool ProcessInterval(Interval *Int) {
251251 if (!Int->isLoop()) return false; // Not a loop? Ignore it!
252252
253253 std::vector InductionVars;
350350 // ProcessIntervalPartition - This function loops over the interval partition
351351 // processing each interval with ProcessInterval
352352 //
353 static bool ProcessIntervalPartition(cfg::IntervalPartition &IP) {
353 static bool ProcessIntervalPartition(IntervalPartition &IP) {
354354 // This currently just prints out information about the interval structure
355355 // of the function...
356356 #if 0
357357 static unsigned N = 0;
358358 cerr << "\n***********Interval Partition #" << (++N) << "************\n\n";
359 copy(IP.begin(), IP.end(), ostream_iterator<cfg::Interval*>(cerr, "\n"));
359 copy(IP.begin(), IP.end(), ostream_iterator<Interval*>(cerr, "\n"));
360360
361361 cerr << "\n*********** PERFORMING WORK ************\n\n";
362362 #endif
371371 // This function loops over an interval partition of a program, reducing it
372372 // until the graph is gone.
373373 //
374 bool InductionVariableCannonicalize::doIt(Function *M,
375 cfg::IntervalPartition &IP) {
374 bool InductionVariableCannonicalize::doIt(Function *M, IntervalPartition &IP) {
375
376376 bool Changed = false;
377377
378378 #if 0
382382 // Calculate the reduced version of this graph until we get to an
383383 // irreducible graph or a degenerate graph...
384384 //
385 cfg::IntervalPartition *NewIP = new cfg::IntervalPartition(*IP, false);
385 IntervalPartition *NewIP = new IntervalPartition(*IP, false);
386386 if (NewIP->size() == IP->size()) {
387387 cerr << "IRREDUCIBLE GRAPH FOUND!!!\n";
388388 return Changed;
398398
399399
400400 bool InductionVariableCannonicalize::runOnFunction(Function *F) {
401 return doIt(F, getAnalysis<cfg::IntervalPartition>());
401 return doIt(F, getAnalysis<IntervalPartition>());
402402 }
403403
404404 // getAnalysisUsage - This function works on the call graph of a module.
406406 // module.
407407 //
408408 void InductionVariableCannonicalize::getAnalysisUsage(AnalysisUsage &AU) const {
409 AU.addRequired(cfg::IntervalPartition::ID);
410 }
409 AU.addRequired(IntervalPartition::ID);
410 }
2727 #include "llvm/ConstantVals.h"
2828
2929 using namespace std;
30
31
32 using cfg::DominanceFrontier;
3330
3431 namespace {
3532
1818 // DominatorSet Implementation
1919 //===----------------------------------------------------------------------===//
2020
21 AnalysisID cfg::DominatorSet::ID(AnalysisID::create());
22 AnalysisID cfg::DominatorSet::PostDomID(AnalysisID::create());
23
24 bool cfg::DominatorSet::runOnFunction(Function *F) {
21 AnalysisID DominatorSet::ID(AnalysisID::create());
22 AnalysisID DominatorSet::PostDomID(AnalysisID::create());
23
24 bool DominatorSet::runOnFunction(Function *F) {
2525 Doms.clear(); // Reset from the last time we were run...
2626
2727 if (isPostDominator())
3535 // calcForwardDominatorSet - This method calculates the forward dominator sets
3636 // for the specified function.
3737 //
38 void cfg::DominatorSet::calcForwardDominatorSet(Function *M) {
38 void DominatorSet::calcForwardDominatorSet(Function *M) {
3939 Root = M->getEntryNode();
4040 assert(pred_begin(Root) == pred_end(Root) &&
4141 "Root node has predecessors in function!");
7979 // only have a single exit node (return stmt), then calculates the post
8080 // dominance sets for the function.
8181 //
82 void cfg::DominatorSet::calcPostDominatorSet(Function *F) {
82 void DominatorSet::calcPostDominatorSet(Function *F) {
8383 // Since we require that the unify all exit nodes pass has been run, we know
8484 // that there can be at most one return instruction in the function left.
8585 // Get it.
131131 // getAnalysisUsage - This obviously provides a dominator set, but it also
132132 // uses the UnifyFunctionExitNodes pass if building post-dominators
133133 //
134 void cfg::DominatorSet::getAnalysisUsage(AnalysisUsage &AU) const {
134 void DominatorSet::getAnalysisUsage(AnalysisUsage &AU) const {
135135 AU.setPreservesAll();
136136 if (isPostDominator()) {
137137 AU.addProvided(PostDomID);
146146 // ImmediateDominators Implementation
147147 //===----------------------------------------------------------------------===//
148148
149 AnalysisID cfg::ImmediateDominators::ID(AnalysisID::create());
150 AnalysisID cfg::ImmediateDominators::PostDomID(AnalysisID::createImmediateDominators>());
149 AnalysisID ImmediateDominators::ID(AnalysisID::create<ImmediateDominators>());
150 AnalysisID ImmediateDominators::PostDomID(AnalysisID::create());
151151
152152 // calcIDoms - Calculate the immediate dominator mapping, given a set of
153153 // dominators for every basic block.
154 void cfg::ImmediateDominators::calcIDoms(const DominatorSet &DS) {
154 void ImmediateDominators::calcIDoms(const DominatorSet &DS) {
155155 // Loop over all of the nodes that have dominators... figuring out the IDOM
156156 // for each node...
157157 //
190190 // DominatorTree Implementation
191191 //===----------------------------------------------------------------------===//
192192
193 AnalysisID cfg::DominatorTree::ID(AnalysisID::create());
194 AnalysisID cfg::DominatorTree::PostDomID(AnalysisID::createDominatorTree>());
193 AnalysisID DominatorTree::ID(AnalysisID::create<DominatorTree>());
194 AnalysisID DominatorTree::PostDomID(AnalysisID::create());
195195
196196 // DominatorTree::reset - Free all of the tree node memory.
197197 //
198 void cfg::DominatorTree::reset() {
198 void DominatorTree::reset() {
199199 for (NodeMapType::iterator I = Nodes.begin(), E = Nodes.end(); I != E; ++I)
200200 delete I->second;
201201 Nodes.clear();
204204
205205 #if 0
206206 // Given immediate dominators, we can also calculate the dominator tree
207 cfg::DominatorTree::DominatorTree(const ImmediateDominators &IDoms)
207 DominatorTree::DominatorTree(const ImmediateDominators &IDoms)
208208 : DominatorBase(IDoms.getRoot()) {
209209 const Function *M = Root->getParent();
210210
229229 }
230230 #endif
231231
232 void cfg::DominatorTree::calculate(const DominatorSet &DS) {
232 void DominatorTree::calculate(const DominatorSet &DS) {
233233 Nodes[Root] = new Node(Root, 0); // Add a node for the root...
234234
235235 if (!isPostDominator()) {
324324 // DominanceFrontier Implementation
325325 //===----------------------------------------------------------------------===//
326326
327 AnalysisID cfg::DominanceFrontier::ID(AnalysisID::create());
328 AnalysisID cfg::DominanceFrontier::PostDomID(AnalysisID::create());
329
330 const cfg::DominanceFrontier::DomSetType &
331 cfg::DominanceFrontier::calcDomFrontier(const DominatorTree &DT,
332 const DominatorTree::Node *Node) {
327 AnalysisID DominanceFrontier::ID(AnalysisID::create());
328 AnalysisID DominanceFrontier::PostDomID(AnalysisID::create());
329
330 const DominanceFrontier::DomSetType &
331 DominanceFrontier::calcDomFrontier(const DominatorTree &DT,
332 const DominatorTree::Node *Node) {
333333 // Loop over CFG successors to calculate DFlocal[Node]
334334 BasicBlock *BB = Node->getNode();
335335 DomSetType &S = Frontiers[BB]; // The new set to fill in...
360360 return S;
361361 }
362362
363 const cfg::DominanceFrontier::DomSetType &
364 cfg::DominanceFrontier::calcPostDomFrontier(const DominatorTree &DT,
365 const DominatorTree::Node *Node) {
363 const DominanceFrontier::DomSetType &
364 DominanceFrontier::calcPostDomFrontier(const DominatorTree &DT,
365 const DominatorTree::Node *Node) {
366366 // Loop over CFG successors to calculate DFlocal[Node]
367367 BasicBlock *BB = Node->getNode();
368368 DomSetType &S = Frontiers[BB]; // The new set to fill in...