[PATCH] D64088: [DDG] DirectedGraph as a base class for various dependence graphs such as DDG and PDG.

Bardia via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 4 13:08:10 PDT 2019


bmahjour added a comment.

In D64088#1570392 <https://reviews.llvm.org/D64088#1570392>, @myhsu wrote:

> Is there any plan on supporting `GraphTraits` in this patch?


Not in this patch, but subsequent patches where subclasses of DGNode, DGEdge and DirectedGraph are implemented will have corresponding graph-trait specializations.

> I understand that sometimes it probably will be more suitable for derived class of `DirectedGraph` to implement `GraphTraits`. But I see no problem on providing a basic implementation of `GraphTraits` for  `DirectedGraph` here.

The classes defined in this file are really meant to be used as base classes in an inheritance relationship that complete the CRTP idiom started here. In fact it's not possible to construct an object of type DirectedGraph with DGNode and DGEdge types, because each type requires a node type and an edge type as template parameters, and without corresponding subclasses their definitions would be recursive. When client nodes and edges are derived from DGNode and DGEdge, the CRTP idiom can be completed and the concrete node and edge types can be instantiated. For example the DDG implementation will define the graph nodes, edges and the graph-trait specialization as follows:

  class DDGNode;
  class DDGEdge;
  using DDGNodeBase = DGNode<DDGNode, DDGEdge>;
  using DDGEdgeBase = DGEdge<DDGNode, DDGEdge>;
  using DDGBase = DirectedGraph<DDGNode, DDGEdge>;
  
  class DDGNode : public DDGNodeBase { ... };
  class DDGEdge : public DDGEdgeBase {...};
  class DataDependenceGraph : public DDGBase {...};
  
  template <> struct GraphTraits<DDGNode *> {...};
  template <> struct GraphTraits<DataDependenceGraph *> : public GraphTraits<DDGNode *> {...};

The choice of the CRTP idiom is made to avoid introducing too many virtual function dispatches when interacting with the nodes and edges of the graph.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64088/new/

https://reviews.llvm.org/D64088





More information about the llvm-commits mailing list