[llvm] r274740 - [LCG] Hoist the definitions of the stream operator friends to be inline

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 7 10:20:27 PDT 2016


On Thu, Jul 7, 2016 at 12:52 AM, Chandler Carruth via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> Author: chandlerc
> Date: Thu Jul  7 02:52:07 2016
> New Revision: 274740
>
> URL: http://llvm.org/viewvc/llvm-project?rev=274740&view=rev
> Log:
> [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.

Thanks!

>
> Modified:
>     llvm/trunk/include/llvm/Analysis/LazyCallGraph.h
>     llvm/trunk/lib/Analysis/LazyCallGraph.cpp
>
> Modified: llvm/trunk/include/llvm/Analysis/LazyCallGraph.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/LazyCallGraph.h?rev=274740&r1=274739&r2=274740&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/Analysis/LazyCallGraph.h (original)
> +++ llvm/trunk/include/llvm/Analysis/LazyCallGraph.h Thu Jul  7 02:52:07 2016
> @@ -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;
>
> Modified: llvm/trunk/lib/Analysis/LazyCallGraph.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/LazyCallGraph.cpp?rev=274740&r1=274739&r2=274740&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Analysis/LazyCallGraph.cpp (original)
> +++ llvm/trunk/lib/Analysis/LazyCallGraph.cpp Thu Jul  7 02:52:07 2016
> @@ -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::removeEdgeInte
>    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=(
>    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';
>  }
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits

-- 
Davide

"There are no solved problems; there are only problems that are more
or less solved" -- Henri Poincare


More information about the llvm-commits mailing list