From: Chandler Carruth Date: Thu, 7 Jul 2016 07:52:07 +0000 (+0000) Subject: [LCG] Hoist the definitions of the stream operator friends to be inline X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=954c015f8a1c7ba74da53d6b1451d1c4212bf348;p=llvm [LCG] Hoist the definitions of the stream operator friends to be inline friend definitions. Based on the experiments Sean Silva and Reid did, this seems the safest course of action and also will work around a questionable warning provided by GCC6 on the old form of the code. Thanks for Davide pointing out the issue and other suggesting ways to fix. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@274740 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Analysis/LazyCallGraph.h b/include/llvm/Analysis/LazyCallGraph.h index 47cb3101ba3..9f62eaa2e9f 100644 --- a/include/llvm/Analysis/LazyCallGraph.h +++ b/include/llvm/Analysis/LazyCallGraph.h @@ -224,7 +224,9 @@ public: void removeEdgeInternal(Function &ChildF); /// Print the name of this node's function. - friend raw_ostream &operator<<(raw_ostream &OS, const Node &N); + friend raw_ostream &operator<<(raw_ostream &OS, const Node &N) { + return OS << N.F.getName(); + } /// Dump the name of this node's function to stderr. void dump() const; @@ -364,7 +366,26 @@ public: /// /// We print the function names in the SCC wrapped in '()'s and skipping /// the middle functions if there are a large number. - friend raw_ostream &operator<<(raw_ostream &OS, const SCC &C); + // + // Note: this is defined inline to dodge issues with GCC's interpretation + // of enclosing namespaces for friend function declarations. + friend raw_ostream &operator<<(raw_ostream &OS, const SCC &C) { + OS << '('; + int i = 0; + for (LazyCallGraph::Node &N : C) { + if (i > 0) + OS << ", "; + // Elide the inner elements if there are too many. + if (i > 8) { + OS << "..., " << *C.Nodes.back(); + break; + } + OS << N; + ++i; + } + OS << ')'; + return OS; + } /// Dump a short description of this SCC to stderr. void dump() const; @@ -436,7 +457,26 @@ public: /// /// We print the SCCs wrapped in '[]'s and skipping the middle SCCs if /// there are a large number. - friend raw_ostream &operator<<(raw_ostream &OS, const RefSCC &RC); + // + // Note: this is defined inline to dodge issues with GCC's interpretation + // of enclosing namespaces for friend function declarations. + friend raw_ostream &operator<<(raw_ostream &OS, const RefSCC &RC) { + OS << '['; + int i = 0; + for (LazyCallGraph::SCC &C : RC) { + if (i > 0) + OS << ", "; + // Elide the inner elements if there are too many. + if (i > 4) { + OS << "..., " << *RC.SCCs.back(); + break; + } + OS << C; + ++i; + } + OS << ']'; + return OS; + } /// Dump a short description of this RefSCC to stderr. void dump() const; diff --git a/lib/Analysis/LazyCallGraph.cpp b/lib/Analysis/LazyCallGraph.cpp index 2d34a243f47..acff8529b15 100644 --- a/lib/Analysis/LazyCallGraph.cpp +++ b/lib/Analysis/LazyCallGraph.cpp @@ -15,7 +15,6 @@ #include "llvm/IR/PassManager.h" #include "llvm/Support/Debug.h" #include "llvm/Support/GraphWriter.h" -#include "llvm/Support/raw_ostream.h" using namespace llvm; @@ -120,10 +119,6 @@ void LazyCallGraph::Node::removeEdgeInternal(Function &Target) { EdgeIndexMap.erase(IndexMapI); } -raw_ostream &llvm::operator<<(raw_ostream &OS, const LazyCallGraph::Node &N) { - return OS << N.F.getName(); -} - void LazyCallGraph::Node::dump() const { dbgs() << *this << '\n'; } @@ -181,24 +176,6 @@ LazyCallGraph &LazyCallGraph::operator=(LazyCallGraph &&G) { return *this; } -raw_ostream &llvm::operator<<(raw_ostream &OS, const LazyCallGraph::SCC &C) { - OS << '('; - int i = 0; - for (LazyCallGraph::Node &N : C) { - if (i > 0) - OS << ", "; - // Elide the inner elements if there are too many. - if (i > 8) { - OS << "..., " << *C.Nodes.back(); - break; - } - OS << N; - ++i; - } - OS << ')'; - return OS; -} - void LazyCallGraph::SCC::dump() const { dbgs() << *this << '\n'; } @@ -224,25 +201,6 @@ void LazyCallGraph::SCC::verify() { LazyCallGraph::RefSCC::RefSCC(LazyCallGraph &G) : G(&G) {} -raw_ostream &llvm::operator<<(raw_ostream &OS, - const LazyCallGraph::RefSCC &RC) { - OS << '['; - int i = 0; - for (LazyCallGraph::SCC &C : RC) { - if (i > 0) - OS << ", "; - // Elide the inner elements if there are too many. - if (i > 4) { - OS << "..., " << *RC.SCCs.back(); - break; - } - OS << C; - ++i; - } - OS << ']'; - return OS; -} - void LazyCallGraph::RefSCC::dump() const { dbgs() << *this << '\n'; }