CGRA-ME
Classes | Public Types | Public Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
OpGraph Class Reference

#include <OpGraph.h>

Classes

struct  EdgeDescriptor
 
struct  OpOpInsertResult
 
struct  VerifyMessage
 

Public Types

using NodeDescriptor = const OpGraphNode *
 
using OpDescriptor = const OpGraphOp *
 
using ValDescriptor = const OpGraphVal *
 
using Walk = std::vector< EdgeDescriptor >
 

Public Member Functions

 OpGraph ()
 
 OpGraph (const OpGraph &)
 
 OpGraph (OpGraph &&)=default
 
OpGraphoperator= (const OpGraph &)
 
OpGraphoperator= (OpGraph &&)=default
 
 ~OpGraph ()
 
OpDescriptor insert (OpGraphOp op)
 
template<typename... Args>
OpDescriptor emplace (Args &&... args)
 
OpOpInsertResult insert (OpDescriptor driver, OpGraphOp fanout, std::string operand_group, int bitwidth=32, int dist=0, EdgeKind kind=EdgeKind::kDataFlow)
 
ValDescriptor link (OpDescriptor driver, OpDescriptor fanout, std::string operand_group, int bitwidth=32, int dist=0, EdgeKind kind=EdgeKind::kDataFlow, bool predicate=false)
 
ValDescriptor link (ValDescriptor val, OpDescriptor fanout, std::string operand_group)
 
ValDescriptor link_like (OpDescriptor driver, OpDescriptor fanout, EdgeDescriptor base)
 
void unLink (ValDescriptor driver_val, OpDescriptor fanout)
 
void erase (OpDescriptor op)
 
auto & opNodes () const
 
auto & valNodes () const
 
auto & aliasNodes () const
 
ValDescriptor outputVal (OpDescriptor op) const
 
std::vector< ValDescriptoroutputVals (OpDescriptor op_desc) const
 
const std::vector< OpGraphVal * > & inputVals (OpDescriptor op) const
 
const std::vector< OpGraphOp * > & outputOps (ValDescriptor op) const
 
const std::vector< OpGraphOp * > & outputOps (OpDescriptor op) const
 
std::vector< OpDescriptorinputOps (OpDescriptor op) const
 
const std::vector< OpGraphOp * > & fanout (OpDescriptor op) const
 
OpDescriptor inputOp (ValDescriptor val) const
 
const OperandTaggetOperandTag (EdgeDescriptor edge) const
 
const int getDist (EdgeDescriptor edge) const
 
const int getBitwidth (EdgeDescriptor edge) const
 
const EdgeKind getKind (EdgeDescriptor edge) const
 
OpDescriptor targetOfEdge (EdgeDescriptor ed) const
 
std::vector< EdgeDescriptoroutEdges (const OpDescriptor &op) const
 
std::vector< EdgeDescriptorinEdges (const OpDescriptor &op) const
 
decltype(auto) fanout (const EdgeDescriptor &ed) const
 
decltype(auto) fanin (const EdgeDescriptor &ed) const
 
OpGraphOpgetNodeRef (OpDescriptor ndesc)
 
const OpGraphOpgetNodeRef (OpDescriptor ndesc) const
 
OpGraphValgetNodeRef (ValDescriptor ndesc)
 
const OpGraphValgetNodeRef (ValDescriptor ndesc) const
 
OpGraphNodegetNodeRef (NodeDescriptor ndesc)
 
const OpGraphNodegetNodeRef (NodeDescriptor ndesc) const
 
OpDescriptor getOp (const std::string &name) const
 
ValDescriptor getVal (const std::string &name) const
 
OpGraphOpgetOpRef (const std::string &name)
 
const OpGraphOpgetOpRef (const std::string &name) const
 
OpGraphValgetValRef (const std::string &name)
 
const OpGraphValgetValRef (const std::string &name) const
 
int getOpIndex (OpGraphOp *op) const
 
int getValIndex (OpGraphVal *op) const
 
int getAliasIndex (OpGraphVal *op) const
 
const OpGraphOpgetOpByIndex (int index) const
 
const OpGraphValgetValByIndex (int index) const
 
OpDescriptor asOp (NodeDescriptor ndesc) const
 
ValDescriptor asVal (NodeDescriptor ndesc) const
 
int getMaxCycle ()
 
std::map< EdgeDescriptor, int > edgeLatencies () const
 
void print_dot (std::ostream &s) const
 
void printDOTwithOps (std::ostream &s) const
 
void serialize (std::ostream &s) const
 
void serialize (std::ostream &s, const std::map< OpDescriptor, int > &op_print_ranking) const
 
void clear ()
 
std::vector< VerifyMessageverify () const
 

Private Attributes

std::vector< OpGraphOp * > op_nodes
 
std::vector< OpGraphVal * > val_nodes
 
std::vector< OpGraphVal * > alias_nodes
 
std::unordered_map< std::string, OpDescriptorops_by_name
 
std::unordered_map< std::string, ValDescriptorvals_by_name
 
std::vector< std::unique_ptr< OpGraphNode > > defunct_nodes = {}
 

Static Private Attributes

static const std::vector< OpGraphOp * > empty_op_vector = {}
 
static const std::vector< OpGraphVal * > empty_val_vector = {}
 
static const std::vector< EdgeDescriptorempty_edge_vector = {}
 
static constexpr ValDescriptor null_val = nullptr
 
static constexpr OpDescriptor null_op = nullptr
 
static constexpr EdgeDescriptor null_edge = {nullptr, -1}
 

Friends

bool operator== (const OpGraph &lhs, const OpGraph &rhs)
 
bool operator!= (const OpGraph &lhs, const OpGraph &rhs)
 
std::ostream & operator<< (std::ostream &os, const OpGraph &og)
 

Detailed Description

Definition at line 215 of file OpGraph.h.

Member Typedef Documentation

◆ NodeDescriptor

Definition at line 218 of file OpGraph.h.

◆ OpDescriptor

Definition at line 219 of file OpGraph.h.

◆ ValDescriptor

Definition at line 220 of file OpGraph.h.

◆ Walk

using OpGraph::Walk = std::vector<EdgeDescriptor>

Definition at line 231 of file OpGraph.h.

Constructor & Destructor Documentation

◆ OpGraph() [1/3]

OpGraph::OpGraph ( )

Create an empty graph. see also createOpGraphFromConfig in OpGraphProcedures.h

Definition at line 282 of file OpGraph.cpp.

◆ OpGraph() [2/3]

OpGraph::OpGraph ( const OpGraph src)

Move-only for now, as copying unimplemented.

Definition at line 310 of file OpGraph.cpp.

◆ OpGraph() [3/3]

OpGraph::OpGraph ( OpGraph &&  )
default

◆ ~OpGraph()

OpGraph::~OpGraph ( )

Assumes ownership of all nodes

Definition at line 294 of file OpGraph.cpp.

Member Function Documentation

◆ aliasNodes()

auto& OpGraph::aliasNodes ( ) const
inline

Definition at line 315 of file OpGraph.h.

◆ asOp()

auto OpGraph::asOp ( NodeDescriptor  ndesc) const

Cast to descriptor subtype May crash if called from no-RTTI code, eg LLVM plugins

Definition at line 1275 of file OpGraph.cpp.

◆ asVal()

auto OpGraph::asVal ( NodeDescriptor  ndesc) const

Definition at line 1276 of file OpGraph.cpp.

◆ clear()

void OpGraph::clear ( )

Make this graph empty, free all memory.

Definition at line 296 of file OpGraph.cpp.

◆ edgeLatencies()

auto OpGraph::edgeLatencies ( ) const

A hold-over until this information is annotated directly on the OpGraph. Finds edges that cause cycles, and assumes that they require a latency of 1. All other edges are assumed to have latency 0. The returned map is surjective; it covers the entire domain of edges.

Definition at line 906 of file OpGraph.cpp.

◆ emplace()

template<typename... Args>
OpDescriptor OpGraph::emplace ( Args &&...  args)
inline

Like insert, but directly construct a Op

Definition at line 263 of file OpGraph.h.

◆ erase()

void OpGraph::erase ( OpDescriptor  op)

Remove op from this DFG, as well as connecting edges Does not affect existing operand indexes

Definition at line 453 of file OpGraph.cpp.

◆ fanin()

decltype(auto) OpGraph::fanin ( const EdgeDescriptor ed) const
inline

Definition at line 369 of file OpGraph.h.

◆ fanout() [1/2]

decltype(auto) OpGraph::fanout ( const EdgeDescriptor ed) const
inline

Allows you to treat an OpGraph as a multi-graph instead of a hyper-graph

Definition at line 368 of file OpGraph.h.

◆ fanout() [2/2]

const std::vector<OpGraphOp*>& OpGraph::fanout ( OpDescriptor  op) const
inline

same as the above, but uses a standard name for compatibility with generic algorithms

Definition at line 334 of file OpGraph.h.

◆ getAliasIndex()

int OpGraph::getAliasIndex ( OpGraphVal op) const

Definition at line 765 of file OpGraph.cpp.

◆ getBitwidth()

const int OpGraph::getBitwidth ( EdgeDescriptor  edge) const

Definition at line 517 of file OpGraph.cpp.

◆ getDist()

const int OpGraph::getDist ( EdgeDescriptor  edge) const

Get the dist output of val

Definition at line 513 of file OpGraph.cpp.

◆ getKind()

const EdgeKind OpGraph::getKind ( EdgeDescriptor  edge) const

Definition at line 521 of file OpGraph.cpp.

◆ getMaxCycle()

int OpGraph::getMaxCycle ( )

Definition at line 867 of file OpGraph.cpp.

◆ getNodeRef() [1/6]

OpGraphNode& OpGraph::getNodeRef ( NodeDescriptor  ndesc)
inline

Definition at line 380 of file OpGraph.h.

◆ getNodeRef() [2/6]

const OpGraphNode& OpGraph::getNodeRef ( NodeDescriptor  ndesc) const
inline

Definition at line 381 of file OpGraph.h.

◆ getNodeRef() [3/6]

OpGraphOp& OpGraph::getNodeRef ( OpDescriptor  ndesc)
inline

Get an actual node object from your descriptor. Useful for "laundering" your const pointer if you have a non-const OpGraph. Undefined Behaviour if this node is not in this OpGraph.

Definition at line 376 of file OpGraph.h.

◆ getNodeRef() [4/6]

const OpGraphOp& OpGraph::getNodeRef ( OpDescriptor  ndesc) const
inline

Definition at line 377 of file OpGraph.h.

◆ getNodeRef() [5/6]

OpGraphVal& OpGraph::getNodeRef ( ValDescriptor  ndesc)
inline

Definition at line 378 of file OpGraph.h.

◆ getNodeRef() [6/6]

const OpGraphVal& OpGraph::getNodeRef ( ValDescriptor  ndesc) const
inline

Definition at line 379 of file OpGraph.h.

◆ getOp()

OpDescriptor OpGraph::getOp ( const std::string &  name) const
inline

Get node by it's name. Throws it it doesn't exist.

Definition at line 386 of file OpGraph.h.

◆ getOpByIndex()

const OpGraphOp * OpGraph::getOpByIndex ( int  index) const

Get the operation at index x within the vector

Definition at line 774 of file OpGraph.cpp.

◆ getOperandTag()

const OperandTag & OpGraph::getOperandTag ( EdgeDescriptor  edge) const

Get the operand group name that is associated with the i'th output of val

Definition at line 509 of file OpGraph.cpp.

◆ getOpIndex()

int OpGraph::getOpIndex ( OpGraphOp op) const

Get the index of the operation within the vector

Definition at line 747 of file OpGraph.cpp.

◆ getOpRef() [1/2]

OpGraphOp& OpGraph::getOpRef ( const std::string &  name)
inline

Definition at line 388 of file OpGraph.h.

◆ getOpRef() [2/2]

const OpGraphOp& OpGraph::getOpRef ( const std::string &  name) const
inline

Definition at line 389 of file OpGraph.h.

◆ getVal()

ValDescriptor OpGraph::getVal ( const std::string &  name) const
inline

Definition at line 387 of file OpGraph.h.

◆ getValByIndex()

const OpGraphVal * OpGraph::getValByIndex ( int  index) const

Definition at line 782 of file OpGraph.cpp.

◆ getValIndex()

int OpGraph::getValIndex ( OpGraphVal op) const

Definition at line 756 of file OpGraph.cpp.

◆ getValRef() [1/2]

OpGraphVal& OpGraph::getValRef ( const std::string &  name)
inline

Definition at line 390 of file OpGraph.h.

◆ getValRef() [2/2]

const OpGraphVal& OpGraph::getValRef ( const std::string &  name) const
inline

Definition at line 391 of file OpGraph.h.

◆ inEdges()

auto OpGraph::inEdges ( const OpDescriptor op) const

Definition at line 540 of file OpGraph.cpp.

◆ inputOp()

auto OpGraph::inputOp ( ValDescriptor  val) const

Get the op that drives val. May return null op

Definition at line 504 of file OpGraph.cpp.

◆ inputOps()

auto OpGraph::inputOps ( OpDescriptor  op) const

Definition at line 497 of file OpGraph.cpp.

◆ inputVals()

const std::vector< OpGraphVal * > & OpGraph::inputVals ( OpDescriptor  op) const

Definition at line 551 of file OpGraph.cpp.

◆ insert() [1/2]

OpGraph::OpOpInsertResult OpGraph::insert ( OpDescriptor  driver,
OpGraphOp  fanout,
std::string  operand_group,
int  bitwidth = 32,
int  dist = 0,
EdgeKind  kind = EdgeKind::kDataFlow 
)

Definition at line 352 of file OpGraph.cpp.

◆ insert() [2/2]

OpGraph::OpDescriptor OpGraph::insert ( OpGraphOp  op)

Move op into the graph, returning it's descriptor. The op will have no fanout. Returns the op's descriptor.

Definition at line 338 of file OpGraph.cpp.

◆ link() [1/2]

OpGraph::ValDescriptor OpGraph::link ( OpDescriptor  driver,
OpDescriptor  fanout,
std::string  operand_group,
int  bitwidth = 32,
int  dist = 0,
EdgeKind  kind = EdgeKind::kDataFlow,
bool  predicate = false 
)

Makes fanout a fanout of diver, creating the val if necessary. Returns the linking vals's descriptor.

Definition at line 364 of file OpGraph.cpp.

◆ link() [2/2]

OpGraph::ValDescriptor OpGraph::link ( ValDescriptor  val,
OpDescriptor  fanout,
std::string  operand_group 
)

Definition at line 408 of file OpGraph.cpp.

◆ link_like()

auto OpGraph::link_like ( OpDescriptor  driver,
OpDescriptor  fanout,
EdgeDescriptor  base 
)

Same as the regular link, but get the edge properties from base

Definition at line 418 of file OpGraph.cpp.

◆ operator=() [1/2]

OpGraph & OpGraph::operator= ( const OpGraph src)

Definition at line 319 of file OpGraph.cpp.

◆ operator=() [2/2]

OpGraph& OpGraph::operator= ( OpGraph &&  )
default

◆ opNodes()

auto& OpGraph::opNodes ( ) const
inline

Access to a range containing each input type or class

Definition at line 313 of file OpGraph.h.

◆ outEdges()

auto OpGraph::outEdges ( const OpDescriptor op) const

Hyper-edge output pins that originate from/terminate at op

Definition at line 530 of file OpGraph.cpp.

◆ outputOps() [1/2]

const std::vector< OpGraphOp * > & OpGraph::outputOps ( OpDescriptor  op) const

Definition at line 493 of file OpGraph.cpp.

◆ outputOps() [2/2]

const std::vector< OpGraphOp * > & OpGraph::outputOps ( ValDescriptor  op) const

Get the ops that op drives. (looks through val node) Returns an empty range if this op drives no val

Definition at line 488 of file OpGraph.cpp.

◆ outputVal()

OpGraph::ValDescriptor OpGraph::outputVal ( OpDescriptor  op) const

Get the val that this op drives/vals that drive this op. May return the null descriptor or an empty list

Definition at line 476 of file OpGraph.cpp.

◆ outputVals()

std::vector< OpGraph::ValDescriptor > OpGraph::outputVals ( OpDescriptor  op_desc) const

Definition at line 483 of file OpGraph.cpp.

◆ print_dot()

void OpGraph::print_dot ( std::ostream &  s) const

Definition at line 1040 of file OpGraph.cpp.

◆ printDOTwithOps()

void OpGraph::printDOTwithOps ( std::ostream &  s) const

Definition at line 1000 of file OpGraph.cpp.

◆ serialize() [1/2]

void OpGraph::serialize ( std::ostream &  s) const

Print this graph in a way that looses no information. Reading it back should produce the same logical graph

The second overload allows you to specify an order to the ops. Lower means print earlier. Is also used for edge ordering.

Definition at line 1070 of file OpGraph.cpp.

◆ serialize() [2/2]

void OpGraph::serialize ( std::ostream &  s,
const std::map< OpDescriptor, int > &  op_print_ranking 
) const

Definition at line 1091 of file OpGraph.cpp.

◆ targetOfEdge()

auto OpGraph::targetOfEdge ( EdgeDescriptor  ed) const

Get the op that is at the target end of this edge. null edge gives null op

Definition at line 525 of file OpGraph.cpp.

◆ unLink()

void OpGraph::unLink ( ValDescriptor  driver_val,
OpDescriptor  fanout 
)

Remove this link Does not affect existing operand indexes

Definition at line 422 of file OpGraph.cpp.

◆ valNodes()

auto& OpGraph::valNodes ( ) const
inline

Definition at line 314 of file OpGraph.h.

◆ verify()

auto OpGraph::verify ( ) const

Definition at line 684 of file OpGraph.cpp.

Friends And Related Function Documentation

◆ operator!=

bool operator!= ( const OpGraph lhs,
const OpGraph rhs 
)
friend

Definition at line 455 of file OpGraph.h.

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
const OpGraph og 
)
friend

Definition at line 456 of file OpGraph.h.

◆ operator==

bool operator== ( const OpGraph lhs,
const OpGraph rhs 
)
friend

Definition at line 1159 of file OpGraph.cpp.

Member Data Documentation

◆ alias_nodes

std::vector<OpGraphVal*> OpGraph::alias_nodes
private

Definition at line 462 of file OpGraph.h.

◆ defunct_nodes

std::vector<std::unique_ptr<OpGraphNode> > OpGraph::defunct_nodes = {}
private

Definition at line 478 of file OpGraph.h.

◆ empty_edge_vector

const std::vector< OpGraph::EdgeDescriptor > OpGraph::empty_edge_vector = {}
staticprivate

Definition at line 471 of file OpGraph.h.

◆ empty_op_vector

const std::vector< OpGraphOp * > OpGraph::empty_op_vector = {}
staticprivate

Definition at line 469 of file OpGraph.h.

◆ empty_val_vector

const std::vector< OpGraphVal * > OpGraph::empty_val_vector = {}
staticprivate

Definition at line 470 of file OpGraph.h.

◆ null_edge

constexpr EdgeDescriptor OpGraph::null_edge = {nullptr, -1}
staticconstexprprivate

Definition at line 475 of file OpGraph.h.

◆ null_op

constexpr OpDescriptor OpGraph::null_op = nullptr
staticconstexprprivate

Definition at line 474 of file OpGraph.h.

◆ null_val

constexpr ValDescriptor OpGraph::null_val = nullptr
staticconstexprprivate

Definition at line 473 of file OpGraph.h.

◆ op_nodes

std::vector<OpGraphOp*> OpGraph::op_nodes
private

Definition at line 460 of file OpGraph.h.

◆ ops_by_name

std::unordered_map<std::string, OpDescriptor> OpGraph::ops_by_name
private

Definition at line 465 of file OpGraph.h.

◆ val_nodes

std::vector<OpGraphVal*> OpGraph::val_nodes
private

Definition at line 461 of file OpGraph.h.

◆ vals_by_name

std::unordered_map<std::string, ValDescriptor> OpGraph::vals_by_name
private

Definition at line 466 of file OpGraph.h.


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