From ffe9e63c4a11352fd6437588fad516efdb46aa40 Mon Sep 17 00:00:00 2001 From: Anton Korobeynikov Date: Sat, 15 Dec 2007 22:23:24 +0000 Subject: [PATCH] Use references in DF iterators. This eliminates copy-ctor calls on huge objects (graphs) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@45063 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/ADT/DepthFirstIterator.h | 36 +++++++++++++++------------ include/llvm/ADT/GraphTraits.h | 4 +-- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/include/llvm/ADT/DepthFirstIterator.h b/include/llvm/ADT/DepthFirstIterator.h index 0cdd79b3c96..0806aa42513 100644 --- a/include/llvm/ADT/DepthFirstIterator.h +++ b/include/llvm/ADT/DepthFirstIterator.h @@ -96,16 +96,16 @@ public: typedef df_iterator _Self; // Provide static begin and end methods as our public "constructors" - static inline _Self begin(GraphT G) { + static inline _Self begin(const GraphT& G) { return _Self(GT::getEntryNode(G)); } - static inline _Self end(GraphT G) { return _Self(); } + static inline _Self end(const GraphT& G) { return _Self(); } // Static begin and end methods as our public ctors for external iterators - static inline _Self begin(GraphT G, SetType &S) { + static inline _Self begin(const GraphT& G, SetType &S) { return _Self(GT::getEntryNode(G), S); } - static inline _Self end(GraphT G, SetType &S) { return _Self(S); } + static inline _Self end(const GraphT& G, SetType &S) { return _Self(S); } inline bool operator==(const _Self& x) const { return VisitStack.size() == x.VisitStack.size() && @@ -162,12 +162,12 @@ public: // Provide global constructors that automatically figure out correct types... // template -df_iterator df_begin(T G) { +df_iterator df_begin(const T& G) { return df_iterator::begin(G); } template -df_iterator df_end(T G) { +df_iterator df_end(const T& G) { return df_iterator::end(G); } @@ -179,12 +179,12 @@ struct df_ext_iterator : public df_iterator { }; template -df_ext_iterator df_ext_begin(T G, SetTy &S) { +df_ext_iterator df_ext_begin(const T& G, SetTy &S) { return df_ext_iterator::begin(G, S); } template -df_ext_iterator df_ext_end(T G, SetTy &S) { +df_ext_iterator df_ext_end(const T& G, SetTy &S) { return df_ext_iterator::end(G, S); } @@ -199,13 +199,15 @@ struct idf_iterator : public df_iterator, SetTy, External> { }; template -idf_iterator idf_begin(T G) { - return idf_iterator::begin(G); +idf_iterator idf_begin(const T& G) { + Inverse DummyG; + return idf_iterator::begin(DummyG); } template -idf_iterator idf_end(T G){ - return idf_iterator::end(G); +idf_iterator idf_end(const T& G){ + Inverse DummyG; + return idf_iterator::end(DummyG); } // Provide global definitions of external inverse depth first iterators... @@ -218,13 +220,15 @@ struct idf_ext_iterator : public idf_iterator { }; template -idf_ext_iterator idf_ext_begin(T G, SetTy &S) { - return idf_ext_iterator::begin(G, S); +idf_ext_iterator idf_ext_begin(const T& G, SetTy &S) { + Inverse DummyG(G); + return idf_ext_iterator::begin(DummyG, S); } template -idf_ext_iterator idf_ext_end(T G, SetTy &S) { - return idf_ext_iterator::end(G, S); +idf_ext_iterator idf_ext_end(const T& G, SetTy &S) { + Inverse DummyG(G); + return idf_ext_iterator::end(DummyG, S); } } // End llvm namespace diff --git a/include/llvm/ADT/GraphTraits.h b/include/llvm/ADT/GraphTraits.h index 2d56064a89e..2b3a78b336c 100644 --- a/include/llvm/ADT/GraphTraits.h +++ b/include/llvm/ADT/GraphTraits.h @@ -73,9 +73,9 @@ struct GraphTraits { // template struct Inverse { - GraphType &Graph; + const GraphType &Graph; - inline Inverse(GraphType &G) : Graph(G) {} + inline Inverse(const GraphType &G) : Graph(G) {} }; // Provide a partial specialization of GraphTraits so that the inverse of an inverse -- 2.34.1