forked from OSchip/llvm-project
Abstract out the Nodes collection. Instead of providing a getNodes() method,
provide node_begin/end iterators, which are only guaranteed to be bidirectional, not random access. llvm-svn: 11165
This commit is contained in:
parent
6e69a5aa5d
commit
7b3d404e28
|
@ -92,6 +92,7 @@ struct DSGraph {
|
||||||
typedef DSScalarMap ScalarMapTy;
|
typedef DSScalarMap ScalarMapTy;
|
||||||
typedef hash_map<Function*, DSNodeHandle> ReturnNodesTy;
|
typedef hash_map<Function*, DSNodeHandle> ReturnNodesTy;
|
||||||
typedef hash_set<GlobalValue*> GlobalSetTy;
|
typedef hash_set<GlobalValue*> GlobalSetTy;
|
||||||
|
typedef std::vector<DSNode*> NodeListTy;
|
||||||
|
|
||||||
/// NodeMapTy - This data type is used when cloning one graph into another to
|
/// NodeMapTy - This data type is used when cloning one graph into another to
|
||||||
/// keep track of the correspondence between the nodes in the old and new
|
/// keep track of the correspondence between the nodes in the old and new
|
||||||
|
@ -101,7 +102,7 @@ private:
|
||||||
DSGraph *GlobalsGraph; // Pointer to the common graph of global objects
|
DSGraph *GlobalsGraph; // Pointer to the common graph of global objects
|
||||||
bool PrintAuxCalls; // Should this graph print the Aux calls vector?
|
bool PrintAuxCalls; // Should this graph print the Aux calls vector?
|
||||||
|
|
||||||
std::vector<DSNode*> Nodes;
|
NodeListTy Nodes;
|
||||||
ScalarMapTy ScalarMap;
|
ScalarMapTy ScalarMap;
|
||||||
|
|
||||||
// ReturnNodes - A return value for every function merged into this graph.
|
// ReturnNodes - A return value for every function merged into this graph.
|
||||||
|
@ -170,8 +171,9 @@ public:
|
||||||
|
|
||||||
/// getNodes - Get a vector of all the nodes in the graph
|
/// getNodes - Get a vector of all the nodes in the graph
|
||||||
///
|
///
|
||||||
const std::vector<DSNode*> &getNodes() const { return Nodes; }
|
typedef NodeListTy::const_iterator node_iterator;
|
||||||
std::vector<DSNode*> &getNodes() { return Nodes; }
|
node_iterator node_begin() const { return Nodes.begin(); }
|
||||||
|
node_iterator node_end() const { return Nodes.end(); }
|
||||||
|
|
||||||
/// getFunctionNames - Return a space separated list of the name of the
|
/// getFunctionNames - Return a space separated list of the name of the
|
||||||
/// functions in this graph (if any)
|
/// functions in this graph (if any)
|
||||||
|
|
|
@ -115,13 +115,12 @@ template <> struct GraphTraits<DSGraph*> {
|
||||||
typedef std::pointer_to_unary_function<DSNode *, DSNode&> DerefFun;
|
typedef std::pointer_to_unary_function<DSNode *, DSNode&> DerefFun;
|
||||||
|
|
||||||
// nodes_iterator/begin/end - Allow iteration over all nodes in the graph
|
// nodes_iterator/begin/end - Allow iteration over all nodes in the graph
|
||||||
typedef mapped_iterator<std::vector<DSNode*>::iterator,
|
typedef mapped_iterator<DSGraph::node_iterator, DerefFun> nodes_iterator;
|
||||||
DerefFun> nodes_iterator;
|
|
||||||
static nodes_iterator nodes_begin(DSGraph *G) {
|
static nodes_iterator nodes_begin(DSGraph *G) {
|
||||||
return map_iterator(G->getNodes().begin(), DerefFun(dereference));
|
return map_iterator(G->node_begin(), DerefFun(dereference));
|
||||||
}
|
}
|
||||||
static nodes_iterator nodes_end(DSGraph *G) {
|
static nodes_iterator nodes_end(DSGraph *G) {
|
||||||
return map_iterator(G->getNodes().end(), DerefFun(dereference));
|
return map_iterator(G->node_end(), DerefFun(dereference));
|
||||||
}
|
}
|
||||||
|
|
||||||
static ChildIteratorType child_begin(NodeType *N) { return N->begin(); }
|
static ChildIteratorType child_begin(NodeType *N) { return N->begin(); }
|
||||||
|
@ -135,13 +134,12 @@ template <> struct GraphTraits<const DSGraph*> {
|
||||||
typedef std::pointer_to_unary_function<const DSNode *,const DSNode&> DerefFun;
|
typedef std::pointer_to_unary_function<const DSNode *,const DSNode&> DerefFun;
|
||||||
|
|
||||||
// nodes_iterator/begin/end - Allow iteration over all nodes in the graph
|
// nodes_iterator/begin/end - Allow iteration over all nodes in the graph
|
||||||
typedef mapped_iterator<std::vector<DSNode*>::const_iterator,
|
typedef mapped_iterator<DSGraph::node_iterator, DerefFun> nodes_iterator;
|
||||||
DerefFun> nodes_iterator;
|
|
||||||
static nodes_iterator nodes_begin(const DSGraph *G) {
|
static nodes_iterator nodes_begin(const DSGraph *G) {
|
||||||
return map_iterator(G->getNodes().begin(), DerefFun(dereferenceC));
|
return map_iterator(G->node_begin(), DerefFun(dereferenceC));
|
||||||
}
|
}
|
||||||
static nodes_iterator nodes_end(const DSGraph *G) {
|
static nodes_iterator nodes_end(const DSGraph *G) {
|
||||||
return map_iterator(G->getNodes().end(), DerefFun(dereferenceC));
|
return map_iterator(G->node_end(), DerefFun(dereferenceC));
|
||||||
}
|
}
|
||||||
|
|
||||||
static ChildIteratorType child_begin(const NodeType *N) { return N->begin(); }
|
static ChildIteratorType child_begin(const NodeType *N) { return N->begin(); }
|
||||||
|
|
Loading…
Reference in New Issue