llvm.org GIT mirror llvm / 55b2eb3
Rename TarjanSCCIterator -> scc_iterator * Increases consistency with other iterators (e.g. df_iterator, po_iterator...) * It's shorter * We don't name classes by the implementation, we name it for the interface! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8273 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 16 years ago
9 changed file(s) with 86 addition(s) and 86 deletion(s). Raw diff Collapse all Expand all
None //===-- Support/TarjanSCCIterator.h - Tarjan SCC iterator -------*- C++ -*-===//
0 //===-- Support/SCCIterator.h - SCC iterator --------------------*- C++ -*-===//
11 //
2 // This builds on the Support/GraphTraits.h file to find the strongly
3 // connected components (SCCs) of a graph in O(N+E) time using
4 // Tarjan's DFS algorithm.
2 // This builds on the Support/GraphTraits.h file to find the strongly connected
3 // components (SCCs) of a graph in O(N+E) time using Tarjan's DFS algorithm.
54 //
6 // The SCC iterator has the important property that if a node in SCC S1
7 // has an edge to a node in SCC S2, then it visits S1 *after* S2.
5 // The SCC iterator has the important property that if a node in SCC S1 has an
6 // edge to a node in SCC S2, then it visits S1 *after* S2.
87 //
9 // To visit S1 *before* S2, use the TarjanSCCIterator on the Inverse graph.
8 // To visit S1 *before* S2, use the scc_iterator on the Inverse graph.
109 // (NOTE: This requires some simple wrappers and is not supported yet.)
1110 //
1211 //===----------------------------------------------------------------------===//
1312
14 #ifndef SUPPORT_TARJANSCCITERATOR_H
15 #define SUPPORT_TARJANSCCITERATOR_H
13 #ifndef SUPPORT_SCCITERATOR_H
14 #define SUPPORT_SCCITERATOR_H
1615
1716 #include "Support/GraphTraits.h"
1817 #include "Support/iterator"
2120
2221 //===----------------------------------------------------------------------===//
2322 ///
24 /// TarjanSCC_iterator - Enumerate the SCCs of a directed graph, in
23 /// scc_iterator - Enumerate the SCCs of a directed graph, in
2524 /// reverse topological order of the SCC DAG.
2625 ///
2726 template >
28 class TarjanSCC_iterator
27 class scc_iterator
2928 : public forward_iterator, ptrdiff_t> {
3029 typedef typename GT::NodeType NodeType;
3130 typedef typename GT::ChildIteratorType ChildItTy;
121120 }
122121 }
123122
124 inline TarjanSCC_iterator(NodeType *entryN) : visitNum(0) {
123 inline scc_iterator(NodeType *entryN) : visitNum(0) {
125124 DFSVisitOne(entryN);
126125 GetNextSCC();
127126 }
128 inline TarjanSCC_iterator() { /* End is when DFS stack is empty */ }
127 inline scc_iterator() { /* End is when DFS stack is empty */ }
129128
130129 public:
131 typedef TarjanSCC_iterator _Self;
130 typedef scc_iterator _Self;
132131
133132 // Provide static "constructors"...
134133 static inline _Self begin(GraphT& G) { return _Self(GT::getEntryNode(G)); }
179178 };
180179
181180
182 // Global constructor for the Tarjan SCC iterator.
181 // Global constructor for the SCC iterator.
183182 template
184 TarjanSCC_iterator tarj_begin(T G) {
185 return TarjanSCC_iterator::begin(G);
183 scc_iterator scc_begin(T G) {
184 return scc_iterator::begin(G);
186185 }
187186
188187 template
189 TarjanSCC_iterator tarj_end(T G) {
190 return TarjanSCC_iterator::end(G);
188 scc_iterator scc_end(T G) {
189 return scc_iterator::end(G);
191190 }
192191
193192 #endif
None //===-- Support/TarjanSCCIterator.h - Tarjan SCC iterator -------*- C++ -*-===//
0 //===-- Support/SCCIterator.h - SCC iterator --------------------*- C++ -*-===//
11 //
2 // This builds on the Support/GraphTraits.h file to find the strongly
3 // connected components (SCCs) of a graph in O(N+E) time using
4 // Tarjan's DFS algorithm.
2 // This builds on the Support/GraphTraits.h file to find the strongly connected
3 // components (SCCs) of a graph in O(N+E) time using Tarjan's DFS algorithm.
54 //
6 // The SCC iterator has the important property that if a node in SCC S1
7 // has an edge to a node in SCC S2, then it visits S1 *after* S2.
5 // The SCC iterator has the important property that if a node in SCC S1 has an
6 // edge to a node in SCC S2, then it visits S1 *after* S2.
87 //
9 // To visit S1 *before* S2, use the TarjanSCCIterator on the Inverse graph.
8 // To visit S1 *before* S2, use the scc_iterator on the Inverse graph.
109 // (NOTE: This requires some simple wrappers and is not supported yet.)
1110 //
1211 //===----------------------------------------------------------------------===//
1312
14 #ifndef SUPPORT_TARJANSCCITERATOR_H
15 #define SUPPORT_TARJANSCCITERATOR_H
13 #ifndef SUPPORT_SCCITERATOR_H
14 #define SUPPORT_SCCITERATOR_H
1615
1716 #include "Support/GraphTraits.h"
1817 #include "Support/iterator"
2120
2221 //===----------------------------------------------------------------------===//
2322 ///
24 /// TarjanSCC_iterator - Enumerate the SCCs of a directed graph, in
23 /// scc_iterator - Enumerate the SCCs of a directed graph, in
2524 /// reverse topological order of the SCC DAG.
2625 ///
2726 template >
28 class TarjanSCC_iterator
27 class scc_iterator
2928 : public forward_iterator, ptrdiff_t> {
3029 typedef typename GT::NodeType NodeType;
3130 typedef typename GT::ChildIteratorType ChildItTy;
121120 }
122121 }
123122
124 inline TarjanSCC_iterator(NodeType *entryN) : visitNum(0) {
123 inline scc_iterator(NodeType *entryN) : visitNum(0) {
125124 DFSVisitOne(entryN);
126125 GetNextSCC();
127126 }
128 inline TarjanSCC_iterator() { /* End is when DFS stack is empty */ }
127 inline scc_iterator() { /* End is when DFS stack is empty */ }
129128
130129 public:
131 typedef TarjanSCC_iterator _Self;
130 typedef scc_iterator _Self;
132131
133132 // Provide static "constructors"...
134133 static inline _Self begin(GraphT& G) { return _Self(GT::getEntryNode(G)); }
179178 };
180179
181180
182 // Global constructor for the Tarjan SCC iterator.
181 // Global constructor for the SCC iterator.
183182 template
184 TarjanSCC_iterator tarj_begin(T G) {
185 return TarjanSCC_iterator::begin(G);
183 scc_iterator scc_begin(T G) {
184 return scc_iterator::begin(G);
186185 }
187186
188187 template
189 TarjanSCC_iterator tarj_end(T G) {
190 return TarjanSCC_iterator::end(G);
188 scc_iterator scc_end(T G) {
189 return scc_iterator::end(G);
191190 }
192191
193192 #endif
1717 #include "llvm/iOther.h"
1818 #include "llvm/Support/InstVisitor.h"
1919 #include "llvm/Support/CFG.h"
20 #include "Support/TarjanSCCIterator.h"
20 #include "Support/SCCIterator.h"
2121 #include "Support/Statistic.h"
2222 #include "Support/STLExtras.h"
2323 #include "Support/hash_map"
207207 }
208208
209209
210 /// Basic dependence gathering algorithm, using TarjanSCCIterator on CFG:
210 /// Basic dependence gathering algorithm, using scc_iterator on CFG:
211211 ///
212212 /// for every SCC S in the CFG in PostOrder on the SCC DAG
213213 /// {
289289 ModRefInfoBuilder builder(*funcGraph, *funcModRef, ModRefCurrent);
290290 for (std::vector::iterator BI = S.begin(), BE = S.end();
291291 BI != BE; ++BI)
292 // Note: BBs in the SCC<> created by TarjanSCCIterator are in postorder.
292 // Note: BBs in the SCC<> created by scc_iterator are in postorder.
293293 for (BasicBlock::reverse_iterator II=(*BI)->rbegin(), IE=(*BI)->rend();
294294 II != IE; ++II)
295295 builder.visit(*II);
437437
438438 ModRefTable ModRefAfter;
439439
440 for (TarjanSCC_iterator I = tarj_begin(&F), E = tarj_end(&F);
441 I != E; ++I)
440 for (scc_iterator I = scc_begin(&F), E = scc_end(&F); I != E; ++I)
442441 ProcessSCC(*I, ModRefAfter, I.hasLoop());
443442
444443 return true;
99
1010 #include "llvm/CallGraphSCCPass.h"
1111 #include "llvm/Analysis/CallGraph.h"
12 #include "Support/TarjanSCCIterator.h"
12 #include "Support/SCCIterator.h"
1313
1414 /// getAnalysisUsage - For this class, we declare that we require and preserve
1515 /// the call graph. If the derived class implements this method, it should
2222 bool CallGraphSCCPass::run(Module &M) {
2323 CallGraph &CG = getAnalysis();
2424 bool Changed = false;
25 for (TarjanSCC_iterator I = tarj_begin(&CG), E = tarj_end(&CG);
25 for (scc_iterator I = scc_begin(&CG), E = scc_end(&CG);
2626 I != E; ++I)
2727 Changed = runOnSCC(*I);
2828 return Changed;
1717 #include "llvm/iOther.h"
1818 #include "llvm/Support/InstVisitor.h"
1919 #include "llvm/Support/CFG.h"
20 #include "Support/TarjanSCCIterator.h"
20 #include "Support/SCCIterator.h"
2121 #include "Support/Statistic.h"
2222 #include "Support/STLExtras.h"
2323 #include "Support/hash_map"
207207 }
208208
209209
210 /// Basic dependence gathering algorithm, using TarjanSCCIterator on CFG:
210 /// Basic dependence gathering algorithm, using scc_iterator on CFG:
211211 ///
212212 /// for every SCC S in the CFG in PostOrder on the SCC DAG
213213 /// {
289289 ModRefInfoBuilder builder(*funcGraph, *funcModRef, ModRefCurrent);
290290 for (std::vector::iterator BI = S.begin(), BE = S.end();
291291 BI != BE; ++BI)
292 // Note: BBs in the SCC<> created by TarjanSCCIterator are in postorder.
292 // Note: BBs in the SCC<> created by scc_iterator are in postorder.
293293 for (BasicBlock::reverse_iterator II=(*BI)->rbegin(), IE=(*BI)->rend();
294294 II != IE; ++II)
295295 builder.visit(*II);
437437
438438 ModRefTable ModRefAfter;
439439
440 for (TarjanSCC_iterator I = tarj_begin(&F), E = tarj_end(&F);
441 I != E; ++I)
440 for (scc_iterator I = scc_begin(&F), E = scc_end(&F); I != E; ++I)
442441 ProcessSCC(*I, ModRefAfter, I.hasLoop());
443442
444443 return true;
11 //
22 // This file provides passes to print out SCCs in a CFG or a CallGraph.
33 // Normally, you would not use these passes; instead, you would use the
4 // TarjanSCCIterator directly to enumerate SCCs and process them in some way.
5 // These passes serve three purposes:
6 // (1) As a reference for how to use the TarjanSCCIterator.
4 // scc_iterator directly to enumerate SCCs and process them in some way. These
5 // passes serve three purposes:
6 //
7 // (1) As a reference for how to use the scc_iterator.
78 // (2) To print out the SCCs for a CFG or a CallGraph:
89 // analyze -cfgscc to print the SCCs in each CFG of a module.
910 // analyze -cfgscc -stats to print the #SCCs and the maximum SCC size.
1213 // and similarly:
1314 // analyze -callscc [-stats] [-debug] to print SCCs in the CallGraph
1415 //
15 // (3) To test the TarjanSCCIterator.
16 // (3) To test the scc_iterator.
1617 //
1718 //===----------------------------------------------------------------------===//
1819
2021 #include "llvm/Module.h"
2122 #include "llvm/Analysis/CallGraph.h"
2223 #include "llvm/Support/CFG.h"
23 #include "Support/TarjanSCCIterator.h"
24 #include "Support/SCCIterator.h"
2425
2526 namespace {
2627 struct CFGSCC : public FunctionPass {
5657 bool CFGSCC::runOnFunction(Function &F) {
5758 unsigned sccNum = 0;
5859 std::cout << "SCCs for Function " << F.getName() << " in PostOrder:";
59 for (TarjanSCC_iterator SCCI = tarj_begin(&F),
60 E = tarj_end(&F); SCCI != E; ++SCCI) {
60 for (scc_iterator SCCI = scc_begin(&F),
61 E = scc_end(&F); SCCI != E; ++SCCI) {
6162 std::vector &nextSCC = *SCCI;
6263 std::cout << "\nSCC #" << ++sccNum << " : ";
6364 for (std::vector::const_iterator I = nextSCC.begin(),
7778 CallGraphNode* rootNode = getAnalysis().getRoot();
7879 unsigned sccNum = 0;
7980 std::cout << "SCCs for the program in PostOrder:";
80 for (TarjanSCC_iterator SCCI = tarj_begin(rootNode),
81 E = tarj_end(rootNode); SCCI != E; ++SCCI) {
81 for (scc_iterator SCCI = scc_begin(rootNode),
82 E = scc_end(rootNode); SCCI != E; ++SCCI) {
8283 const std::vector &nextSCC = *SCCI;
8384 std::cout << "\nSCC #" << ++sccNum << " : ";
8485 for (std::vector::const_iterator I = nextSCC.begin(),
11 //
22 // This file provides passes to print out SCCs in a CFG or a CallGraph.
33 // Normally, you would not use these passes; instead, you would use the
4 // TarjanSCCIterator directly to enumerate SCCs and process them in some way.
5 // These passes serve three purposes:
6 // (1) As a reference for how to use the TarjanSCCIterator.
4 // scc_iterator directly to enumerate SCCs and process them in some way. These
5 // passes serve three purposes:
6 //
7 // (1) As a reference for how to use the scc_iterator.
78 // (2) To print out the SCCs for a CFG or a CallGraph:
89 // analyze -cfgscc to print the SCCs in each CFG of a module.
910 // analyze -cfgscc -stats to print the #SCCs and the maximum SCC size.
1213 // and similarly:
1314 // analyze -callscc [-stats] [-debug] to print SCCs in the CallGraph
1415 //
15 // (3) To test the TarjanSCCIterator.
16 // (3) To test the scc_iterator.
1617 //
1718 //===----------------------------------------------------------------------===//
1819
2021 #include "llvm/Module.h"
2122 #include "llvm/Analysis/CallGraph.h"
2223 #include "llvm/Support/CFG.h"
23 #include "Support/TarjanSCCIterator.h"
24 #include "Support/SCCIterator.h"
2425
2526 namespace {
2627 struct CFGSCC : public FunctionPass {
5657 bool CFGSCC::runOnFunction(Function &F) {
5758 unsigned sccNum = 0;
5859 std::cout << "SCCs for Function " << F.getName() << " in PostOrder:";
59 for (TarjanSCC_iterator SCCI = tarj_begin(&F),
60 E = tarj_end(&F); SCCI != E; ++SCCI) {
60 for (scc_iterator SCCI = scc_begin(&F),
61 E = scc_end(&F); SCCI != E; ++SCCI) {
6162 std::vector &nextSCC = *SCCI;
6263 std::cout << "\nSCC #" << ++sccNum << " : ";
6364 for (std::vector::const_iterator I = nextSCC.begin(),
7778 CallGraphNode* rootNode = getAnalysis().getRoot();
7879 unsigned sccNum = 0;
7980 std::cout << "SCCs for the program in PostOrder:";
80 for (TarjanSCC_iterator SCCI = tarj_begin(rootNode),
81 E = tarj_end(rootNode); SCCI != E; ++SCCI) {
81 for (scc_iterator SCCI = scc_begin(rootNode),
82 E = scc_end(rootNode); SCCI != E; ++SCCI) {
8283 const std::vector &nextSCC = *SCCI;
8384 std::cout << "\nSCC #" << ++sccNum << " : ";
8485 for (std::vector::const_iterator I = nextSCC.begin(),
11 //
22 // This file provides passes to print out SCCs in a CFG or a CallGraph.
33 // Normally, you would not use these passes; instead, you would use the
4 // TarjanSCCIterator directly to enumerate SCCs and process them in some way.
5 // These passes serve three purposes:
6 // (1) As a reference for how to use the TarjanSCCIterator.
4 // scc_iterator directly to enumerate SCCs and process them in some way. These
5 // passes serve three purposes:
6 //
7 // (1) As a reference for how to use the scc_iterator.
78 // (2) To print out the SCCs for a CFG or a CallGraph:
89 // analyze -cfgscc to print the SCCs in each CFG of a module.
910 // analyze -cfgscc -stats to print the #SCCs and the maximum SCC size.
1213 // and similarly:
1314 // analyze -callscc [-stats] [-debug] to print SCCs in the CallGraph
1415 //
15 // (3) To test the TarjanSCCIterator.
16 // (3) To test the scc_iterator.
1617 //
1718 //===----------------------------------------------------------------------===//
1819
2021 #include "llvm/Module.h"
2122 #include "llvm/Analysis/CallGraph.h"
2223 #include "llvm/Support/CFG.h"
23 #include "Support/TarjanSCCIterator.h"
24 #include "Support/SCCIterator.h"
2425
2526 namespace {
2627 struct CFGSCC : public FunctionPass {
5657 bool CFGSCC::runOnFunction(Function &F) {
5758 unsigned sccNum = 0;
5859 std::cout << "SCCs for Function " << F.getName() << " in PostOrder:";
59 for (TarjanSCC_iterator SCCI = tarj_begin(&F),
60 E = tarj_end(&F); SCCI != E; ++SCCI) {
60 for (scc_iterator SCCI = scc_begin(&F),
61 E = scc_end(&F); SCCI != E; ++SCCI) {
6162 std::vector &nextSCC = *SCCI;
6263 std::cout << "\nSCC #" << ++sccNum << " : ";
6364 for (std::vector::const_iterator I = nextSCC.begin(),
7778 CallGraphNode* rootNode = getAnalysis().getRoot();
7879 unsigned sccNum = 0;
7980 std::cout << "SCCs for the program in PostOrder:";
80 for (TarjanSCC_iterator SCCI = tarj_begin(rootNode),
81 E = tarj_end(rootNode); SCCI != E; ++SCCI) {
81 for (scc_iterator SCCI = scc_begin(rootNode),
82 E = scc_end(rootNode); SCCI != E; ++SCCI) {
8283 const std::vector &nextSCC = *SCCI;
8384 std::cout << "\nSCC #" << ++sccNum << " : ";
8485 for (std::vector::const_iterator I = nextSCC.begin(),
11 //
22 // This file provides passes to print out SCCs in a CFG or a CallGraph.
33 // Normally, you would not use these passes; instead, you would use the
4 // TarjanSCCIterator directly to enumerate SCCs and process them in some way.
5 // These passes serve three purposes:
6 // (1) As a reference for how to use the TarjanSCCIterator.
4 // scc_iterator directly to enumerate SCCs and process them in some way. These
5 // passes serve three purposes:
6 //
7 // (1) As a reference for how to use the scc_iterator.
78 // (2) To print out the SCCs for a CFG or a CallGraph:
89 // analyze -cfgscc to print the SCCs in each CFG of a module.
910 // analyze -cfgscc -stats to print the #SCCs and the maximum SCC size.
1213 // and similarly:
1314 // analyze -callscc [-stats] [-debug] to print SCCs in the CallGraph
1415 //
15 // (3) To test the TarjanSCCIterator.
16 // (3) To test the scc_iterator.
1617 //
1718 //===----------------------------------------------------------------------===//
1819
2021 #include "llvm/Module.h"
2122 #include "llvm/Analysis/CallGraph.h"
2223 #include "llvm/Support/CFG.h"
23 #include "Support/TarjanSCCIterator.h"
24 #include "Support/SCCIterator.h"
2425
2526 namespace {
2627 struct CFGSCC : public FunctionPass {
5657 bool CFGSCC::runOnFunction(Function &F) {
5758 unsigned sccNum = 0;
5859 std::cout << "SCCs for Function " << F.getName() << " in PostOrder:";
59 for (TarjanSCC_iterator SCCI = tarj_begin(&F),
60 E = tarj_end(&F); SCCI != E; ++SCCI) {
60 for (scc_iterator SCCI = scc_begin(&F),
61 E = scc_end(&F); SCCI != E; ++SCCI) {
6162 std::vector &nextSCC = *SCCI;
6263 std::cout << "\nSCC #" << ++sccNum << " : ";
6364 for (std::vector::const_iterator I = nextSCC.begin(),
7778 CallGraphNode* rootNode = getAnalysis().getRoot();
7879 unsigned sccNum = 0;
7980 std::cout << "SCCs for the program in PostOrder:";
80 for (TarjanSCC_iterator SCCI = tarj_begin(rootNode),
81 E = tarj_end(rootNode); SCCI != E; ++SCCI) {
81 for (scc_iterator SCCI = scc_begin(rootNode),
82 E = scc_end(rootNode); SCCI != E; ++SCCI) {
8283 const std::vector &nextSCC = *SCCI;
8384 std::cout << "\nSCC #" << ++sccNum << " : ";
8485 for (std::vector::const_iterator I = nextSCC.begin(),