Jlm
Public Member Functions | Private Member Functions | Private Attributes | List of all members
jlm::util::graph::Graph Class Reference

#include <GraphWriter.hpp>

Inheritance diagram for jlm::util::graph::Graph:
Inheritance graph
[legend]
Collaboration diagram for jlm::util::graph::Graph:
Collaboration graph
[legend]

Public Member Functions

 ~Graph () override=default
 
const char * GetIdPrefix () const override
 
GraphGetGraph () override
 
WriterGetWriter ()
 
const WriterGetWriter () const
 
bool IsSubgraph () const
 
NodeCreateNode ()
 
InOutNodeCreateInOutNode (size_t inputPorts, size_t outputPorts)
 
size_t NumNodes () const noexcept
 
NodeGetNode (size_t index)
 
ArgumentNodeCreateArgumentNode ()
 
size_t NumArgumentNodes () const noexcept
 
NodeGetArgumentNode (size_t index)
 
ResultNodeCreateResultNode ()
 
size_t NumResultNodes () const noexcept
 
NodeGetResultNode (size_t index)
 
EdgeCreateEdge (Port &from, Port &to, bool directed)
 
EdgeCreateDirectedEdge (Port &from, Port &to)
 
EdgeCreateUndirectedEdge (Port &a, Port &b)
 
size_t NumEdges () const noexcept
 
EdgeGetEdge (size_t index)
 
EdgeGetEdgeBetween (Port &a, Port &b)
 
GraphElementGetElementFromProgramObject (uintptr_t object) const
 
template<typename T >
GraphElementGetElementFromProgramObject (const T &object) const
 
template<typename Element , typename ProgramObject >
Element & GetFromProgramObject (const ProgramObject &object) const
 
void Finalize () override
 
void Output (std::ostream &out, OutputFormat format, size_t indent=0) const
 
- Public Member Functions inherited from jlm::util::graph::GraphElement
virtual ~GraphElement ()=default
 
 GraphElement ()
 
 GraphElement (const GraphElement &other)=delete
 
 GraphElement (GraphElement &&other)=delete
 
GraphElementoperator= (const GraphElement &other)=delete
 
GraphElementoperator= (GraphElement &&other)=delete
 
std::string GetFullId () const
 
const GraphGetGraph () const
 
void SetLabel (std::string label)
 
void AppendToLabel (std::string_view text, std::string_view sep="\n")
 
bool HasLabel () const
 
const std::string & GetLabel () const
 
std::string_view GetLabelOr (std::string_view otherwise) const
 
size_t GetUniqueIdSuffix () const
 
template<typename T >
void SetProgramObject (const T &object)
 
void RemoveProgramObject ()
 
bool HasProgramObject () const noexcept
 
uintptr_t GetProgramObject () const noexcept
 
void SetAttribute (const std::string &attribute, std::string value)
 
void SetAttributeObject (const std::string &attribute, uintptr_t object)
 
template<typename T >
void SetAttributeObject (const std::string &attribute, const T &object)
 
void SetAttributeGraphElement (const std::string &attribute, const GraphElement &element)
 
bool HasAttribute (const std::string &attribute) const
 
std::optional< std::string_view > GetAttributeString (const std::string &attribute) const
 
std::optional< uintptr_t > GetAttributeObject (const std::string &attribute) const
 
const GraphElementGetAttributeGraphElement (const std::string &attribute) const
 
bool RemoveAttribute (const std::string &attribute)
 
bool IsFinalized () const
 
void OutputAttributes (std::ostream &out, AttributeOutputFormat format) const
 

Private Member Functions

 Graph (Writer &writer)
 
 Graph (Writer &writer, Node &parentNode)
 
void OutputASCII (std::ostream &out, size_t indent) const
 
void OutputDot (std::ostream &out, size_t indent) const
 
void MapProgramObjectToElement (GraphElement &element)
 
void RemoveProgramObjectMapping (uintptr_t object)
 

Private Attributes

friend Writer
 
friend GraphElement
 
WriterWriter_
 
NodeParentNode_
 
std::vector< std::unique_ptr< Node > > Nodes_
 
std::vector< std::unique_ptr< ArgumentNode > > ArgumentNodes_
 
std::vector< std::unique_ptr< ResultNode > > ResultNodes_
 
std::vector< std::unique_ptr< Edge > > Edges_
 
std::unordered_map< uintptr_t, GraphElement * > ProgramObjectMapping_
 

Detailed Description

Definition at line 768 of file GraphWriter.hpp.

Constructor & Destructor Documentation

◆ Graph() [1/2]

jlm::util::graph::Graph::Graph ( Writer writer)
explicitprivate

Definition at line 1102 of file GraphWriter.cpp.

◆ Graph() [2/2]

jlm::util::graph::Graph::Graph ( Writer writer,
Node parentNode 
)
private

Definition at line 1108 of file GraphWriter.cpp.

◆ ~Graph()

jlm::util::graph::Graph::~Graph ( )
overridedefault

Member Function Documentation

◆ CreateArgumentNode()

ArgumentNode & jlm::util::graph::Graph::CreateArgumentNode ( )

Adds a new argument node to the graph.

Returns
a reference to the new argument node

Definition at line 1174 of file GraphWriter.cpp.

◆ CreateDirectedEdge()

Edge& jlm::util::graph::Graph::CreateDirectedEdge ( Port from,
Port to 
)
inline

Creates a new directed edge from from to to.

Returns
a reference to the newly created edge.
See also
CreateEdge

Definition at line 885 of file GraphWriter.hpp.

◆ CreateEdge()

Edge & jlm::util::graph::Graph::CreateEdge ( Port from,
Port to,
bool  directed 
)

Creates a new edge between from and to. Both ports must belong to this graph. If the edge is directed, the ports must support being the tail and head of an edge.

Parameters
fromthe port the edge goes from.
tothe port the edge goes to.
directedif true, the edge is a directed edge, otherwise undirected
Returns
a reference to the newly created edge.

Definition at line 1216 of file GraphWriter.cpp.

◆ CreateInOutNode()

InOutNode & jlm::util::graph::Graph::CreateInOutNode ( size_t  inputPorts,
size_t  outputPorts 
)

Creates an InOutNode in the graph with the given number of input and output ports.

Parameters
inputPortsthe number of input ports.
outputPortsthe number of output ports.
Returns
a reference to the newly added node.

Definition at line 1153 of file GraphWriter.cpp.

◆ CreateNode()

Node & jlm::util::graph::Graph::CreateNode ( )

Creates a basic Node in the graph. It has a single port: itself.

Returns
a reference to the newly added node.

Definition at line 1145 of file GraphWriter.cpp.

◆ CreateResultNode()

ResultNode & jlm::util::graph::Graph::CreateResultNode ( )

Adds a new result node to the graph.

Returns
a reference to the new result node

Definition at line 1195 of file GraphWriter.cpp.

◆ CreateUndirectedEdge()

Edge& jlm::util::graph::Graph::CreateUndirectedEdge ( Port a,
Port b 
)
inline

Creates a new undirected edge between a and b. The ordering of a and b may affect graph layout.

Returns
a reference to the newly created edge.
See also
CreateEdge

Definition at line 897 of file GraphWriter.hpp.

◆ Finalize()

void jlm::util::graph::Graph::Finalize ( )
overridevirtual

Assigns unique IDs to all graph elements. Finalizing is recursive, visiting all sub graphs.

Reimplemented from jlm::util::graph::GraphElement.

Definition at line 1283 of file GraphWriter.cpp.

◆ GetArgumentNode()

Node & jlm::util::graph::Graph::GetArgumentNode ( size_t  index)

Retrieves the argument node with the given index, which must be less than NumArgumentNodes()

Returns
a reference to the argument node

Definition at line 1188 of file GraphWriter.cpp.

◆ GetEdge()

Edge & jlm::util::graph::Graph::GetEdge ( size_t  index)

Retrieves the edge with the given index, which must be lower than NumEdges()

Returns
a reference to the edge

Definition at line 1235 of file GraphWriter.cpp.

◆ GetEdgeBetween()

Edge * jlm::util::graph::Graph::GetEdgeBetween ( Port a,
Port b 
)

Retrieves an edge connecting ports a and b. If the edge is directed, it must go from a, to b.

Parameters
athe first port
bthe second port
Returns
a reference to an edge connecting a and b, or nullptr if no such edge exists.

Definition at line 1242 of file GraphWriter.cpp.

◆ GetElementFromProgramObject() [1/2]

template<typename T >
GraphElement* jlm::util::graph::Graph::GetElementFromProgramObject ( const T &  object) const
inline

Definition at line 935 of file GraphWriter.hpp.

◆ GetElementFromProgramObject() [2/2]

GraphElement * jlm::util::graph::Graph::GetElementFromProgramObject ( uintptr_t  object) const

Retrieves the GraphElement in this graph associated with a given ProgramObject. This function does not look for graph elements inside sub graphs.

Parameters
objectthe program object that is possibly mapped to a GraphElement in the graph
Returns
the GraphElement mapped to the given object, or nullptr if none exists in this graph.

Definition at line 1255 of file GraphWriter.cpp.

◆ GetFromProgramObject()

template<typename Element , typename ProgramObject >
Element& jlm::util::graph::Graph::GetFromProgramObject ( const ProgramObject &  object) const
inline

Retrieves the GraphElement in this graph associated with the given program object. Requires the program object to be mapped to a GraphElement in this graph, and that the graph element is of type T.

Parameters
objectthe program object mapped to a GraphElement
Returns
a reference to the T mapped to the given object.

Definition at line 952 of file GraphWriter.hpp.

◆ GetGraph()

Graph & jlm::util::graph::Graph::GetGraph ( )
overridevirtual

Gets a reference to the graph this GraphElement belongs to

Implements jlm::util::graph::GraphElement.

Definition at line 1121 of file GraphWriter.cpp.

◆ GetIdPrefix()

const char * jlm::util::graph::Graph::GetIdPrefix ( ) const
overridevirtual

Gets a short string that will serve as the base for a unique ID. This base should be a valid C-like identifier.

Returns
a string, such as "node", "i", "o", "graph"

Implements jlm::util::graph::GraphElement.

Definition at line 1115 of file GraphWriter.cpp.

◆ GetNode()

Node & jlm::util::graph::Graph::GetNode ( size_t  index)

Retrieves the node with the given index, which must be lower than NumNodes(). Argument nodes and result nodes are not accessed through this function.

Returns
a reference to the node

Definition at line 1167 of file GraphWriter.cpp.

◆ GetResultNode()

Node & jlm::util::graph::Graph::GetResultNode ( size_t  index)

Retrieves the result node with the given index, which must be less than NumResultNodes()

Returns
a reference to the result node

Definition at line 1209 of file GraphWriter.cpp.

◆ GetWriter() [1/2]

Writer & jlm::util::graph::Graph::GetWriter ( )

Definition at line 1127 of file GraphWriter.cpp.

◆ GetWriter() [2/2]

const Writer & jlm::util::graph::Graph::GetWriter ( ) const

Definition at line 1133 of file GraphWriter.cpp.

◆ IsSubgraph()

bool jlm::util::graph::Graph::IsSubgraph ( ) const
Returns
true if this graph is a subgraph of another graph, false if it is top-level

Definition at line 1139 of file GraphWriter.cpp.

◆ MapProgramObjectToElement()

void jlm::util::graph::Graph::MapProgramObjectToElement ( GraphElement element)
private

Creates a mapping from a GraphElement's assigned program object to the GraphElement. The GraphElement must be a direct member of this graph.

Parameters
elementthe graph element to map

Definition at line 1263 of file GraphWriter.cpp.

◆ NumArgumentNodes()

size_t jlm::util::graph::Graph::NumArgumentNodes ( ) const
noexcept
Returns
the number of argument nodes in the graph

Definition at line 1182 of file GraphWriter.cpp.

◆ NumEdges()

size_t jlm::util::graph::Graph::NumEdges ( ) const
noexcept
Returns
the number of edges in the graph

Definition at line 1229 of file GraphWriter.cpp.

◆ NumNodes()

size_t jlm::util::graph::Graph::NumNodes ( ) const
noexcept
Returns
the number of nodes in the graph, excluding argument and result nodes.

Definition at line 1161 of file GraphWriter.cpp.

◆ NumResultNodes()

size_t jlm::util::graph::Graph::NumResultNodes ( ) const
noexcept
Returns
the number of result nodes in the graph

Definition at line 1203 of file GraphWriter.cpp.

◆ Output()

void jlm::util::graph::Graph::Output ( std::ostream &  out,
OutputFormat  format,
size_t  indent = 0 
) const

Prints the graph to the given ostream, in the specified format. Requires the graph to be finalized first.

Parameters
outthe stream to which output is written
formatthe format to output the graph in
indentthe amount of indentation levels the graph should be printed with

Definition at line 1408 of file GraphWriter.cpp.

◆ OutputASCII()

void jlm::util::graph::Graph::OutputASCII ( std::ostream &  out,
size_t  indent 
) const
private

Definition at line 1299 of file GraphWriter.cpp.

◆ OutputDot()

void jlm::util::graph::Graph::OutputDot ( std::ostream &  out,
size_t  indent 
) const
private

Definition at line 1344 of file GraphWriter.cpp.

◆ RemoveProgramObjectMapping()

void jlm::util::graph::Graph::RemoveProgramObjectMapping ( uintptr_t  object)
private

Removes the mapping of a program object to a graph element in the graph.

Parameters
objectthe program object that should no longer be mapped.

Definition at line 1276 of file GraphWriter.cpp.

Member Data Documentation

◆ ArgumentNodes_

std::vector<std::unique_ptr<ArgumentNode> > jlm::util::graph::Graph::ArgumentNodes_
private

Definition at line 1011 of file GraphWriter.hpp.

◆ Edges_

std::vector<std::unique_ptr<Edge> > jlm::util::graph::Graph::Edges_
private

Definition at line 1014 of file GraphWriter.hpp.

◆ GraphElement

friend jlm::util::graph::Graph::GraphElement
private

Definition at line 771 of file GraphWriter.hpp.

◆ Nodes_

std::vector<std::unique_ptr<Node> > jlm::util::graph::Graph::Nodes_
private

Definition at line 1008 of file GraphWriter.hpp.

◆ ParentNode_

Node* jlm::util::graph::Graph::ParentNode_
private

Definition at line 1005 of file GraphWriter.hpp.

◆ ProgramObjectMapping_

std::unordered_map<uintptr_t, GraphElement *> jlm::util::graph::Graph::ProgramObjectMapping_
private

Definition at line 1017 of file GraphWriter.hpp.

◆ ResultNodes_

std::vector<std::unique_ptr<ResultNode> > jlm::util::graph::Graph::ResultNodes_
private

Definition at line 1012 of file GraphWriter.hpp.

◆ Writer

friend jlm::util::graph::Graph::Writer
private

Definition at line 770 of file GraphWriter.hpp.

◆ Writer_

Writer& jlm::util::graph::Graph::Writer_
private

Definition at line 1001 of file GraphWriter.hpp.


The documentation for this class was generated from the following files: