Jlm
Loading...
Searching...
No Matches
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
 
Graph & GetGraph () override
 
Writer & GetWriter ()
 
const Writer & GetWriter () const
 
bool IsSubgraph () const
 
Node & CreateNode ()
 
InOutNode & CreateInOutNode (size_t inputPorts, size_t outputPorts)
 
size_t NumNodes () const noexcept
 
Node & GetNode (size_t index)
 
ArgumentNode & CreateArgumentNode ()
 
size_t NumArgumentNodes () const noexcept
 
Node & GetArgumentNode (size_t index)
 
ResultNode & CreateResultNode ()
 
size_t NumResultNodes () const noexcept
 
Node & GetResultNode (size_t index)
 
Edge & CreateEdge (Port &from, Port &to, bool directed)
 
Edge & CreateDirectedEdge (Port &from, Port &to)
 
Edge & CreateUndirectedEdge (Port &a, Port &b)
 
size_t NumEdges () const noexcept
 
Edge & GetEdge (size_t index)
 
Edge * GetEdgeBetween (Port &a, Port &b)
 
GraphElement * GetElementFromProgramObject (uintptr_t object) const
 
template<typename T >
GraphElement * GetElementFromProgramObject (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) const
 
- Public Member Functions inherited from jlm::util::graph::GraphElement
virtual ~GraphElement ()=default
 
 GraphElement ()
 
 GraphElement (const GraphElement &other)=delete
 
 GraphElement (GraphElement &&other)=delete
 
GraphElement & operator= (const GraphElement &other)=delete
 
GraphElement & operator= (GraphElement &&other)=delete
 
void PrintFullId (std::ostream &out) const
 
std::string GetFullId () const
 
const Graph & GetGraph () 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 GraphElement * GetAttributeGraphElement (const std::string &attribute) const
 
bool RemoveAttribute (const std::string &attribute)
 
bool IsFinalized () const
 
void OutputAttributes (std::ostream &out, AttributeOutputFormat format) const
 
void outputJsonObjectOpening (std::ostream &out, size_t indent, bool &firstField) 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 outputJson (std::ostream &out, size_t indent) const
 
void MapProgramObjectToElement (GraphElement &element)
 
void RemoveProgramObjectMapping (GraphElement &element)
 

Private Attributes

friend Writer
 
friend GraphElement
 
Writer & Writer_
 
Node * ParentNode_
 
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 826 of file GraphWriter.hpp.

Constructor & Destructor Documentation

◆ Graph() [1/2]

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

Definition at line 1378 of file GraphWriter.cpp.

◆ Graph() [2/2]

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

Definition at line 1384 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 1450 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 943 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 1492 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 1429 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 1421 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 1471 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 955 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 1570 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 1464 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 1511 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 1518 of file GraphWriter.cpp.

◆ GetElementFromProgramObject() [1/2]

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

Definition at line 993 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 1531 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 1010 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 1397 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 1391 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 1443 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 1485 of file GraphWriter.cpp.

◆ GetWriter() [1/2]

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

Definition at line 1403 of file GraphWriter.cpp.

◆ GetWriter() [2/2]

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

Definition at line 1409 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 1415 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 1539 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 1458 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 1505 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 1437 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 1479 of file GraphWriter.cpp.

◆ Output()

void jlm::util::graph::Graph::Output ( std::ostream &  out,
OutputFormat  format,
size_t  indent 
) 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 1742 of file GraphWriter.cpp.

◆ OutputASCII()

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

Definition at line 1586 of file GraphWriter.cpp.

◆ OutputDot()

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

Definition at line 1631 of file GraphWriter.cpp.

◆ outputJson()

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

Definition at line 1689 of file GraphWriter.cpp.

◆ RemoveProgramObjectMapping()

void jlm::util::graph::Graph::RemoveProgramObjectMapping ( GraphElement &  element)
private

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

Parameters
elementthe element that is currently mapped to a program object, whose mapping should be removed.

Definition at line 1556 of file GraphWriter.cpp.

Member Data Documentation

◆ ArgumentNodes_

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

Definition at line 1073 of file GraphWriter.hpp.

◆ Edges_

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

Definition at line 1076 of file GraphWriter.hpp.

◆ GraphElement

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

Definition at line 829 of file GraphWriter.hpp.

◆ Nodes_

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

Definition at line 1070 of file GraphWriter.hpp.

◆ ParentNode_

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

Definition at line 1067 of file GraphWriter.hpp.

◆ ProgramObjectMapping_

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

Definition at line 1079 of file GraphWriter.hpp.

◆ ResultNodes_

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

Definition at line 1074 of file GraphWriter.hpp.

◆ Writer

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

Definition at line 828 of file GraphWriter.hpp.

◆ Writer_

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

Definition at line 1063 of file GraphWriter.hpp.


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