ir.h#

Lightweight in-memory intermediate representation (IR) for ONNX graphs.

Provides the core graph data structures used by the ONNX version converter and related tools:

All raw pointers returned by this API are non-owning; the Graph is the sole owner of every Node and Value it creates. Destroying a Graph invalidates all pointers into it.

Defines

ONNX_DISALLOW_COPY_AND_ASSIGN(TypeName)#
CREATE_ACCESSOR(Kind, method)#
namespace ONNX_LIGHT_NAMESPACE

Typedefs

using FloatAttr = ScalarAttributeValue<double, AttributeKind::f>#

Scalar float attribute (double storage, kind f).

using FloatsAttr = VectorAttributeValue<double, AttributeKind::fs>#

Float-list attribute (double element storage, kind fs).

using IntAttr = ScalarAttributeValue<int64_t, AttributeKind::i>#

Scalar integer attribute (int64_t storage, kind i).

using IntsAttr = VectorAttributeValue<int64_t, AttributeKind::is>#

Integer-list attribute (int64_t element storage, kind is).

using StringAttr = ScalarAttributeValue<std::string, AttributeKind::s>#

Scalar string attribute (std::string storage, kind s).

using StringsAttr = VectorAttributeValue<std::string, AttributeKind::ss>#

String-list attribute (std::string element storage, kind ss).

using TensorAttr = ScalarAttributeValue<Tensor, AttributeKind::t>#

Scalar tensor attribute (kind t).

using TensorsAttr = VectorAttributeValue<Tensor, AttributeKind::ts>#

Tensor-list attribute (kind ts).

using GraphAttr = ScalarAttributeValue<std::shared_ptr<Graph>, AttributeKind::g>#

Scalar subgraph attribute (kind g).

using GraphsAttr = VectorAttributeValue<std::shared_ptr<Graph>, AttributeKind::gs>#

Subgraph-list attribute (kind gs).

using TypeProtoAttr = ScalarAttributeValue<TypeProto, AttributeKind::tp>#

Scalar type-proto attribute (kind tp).

using TypeProtosAttr = VectorAttributeValue<TypeProto, AttributeKind::tps>#

Type-proto-list attribute (kind tps).

using node_list = std::vector<Node*>#

Ordered list of Node pointers.

using value_list = std::vector<Value*>#

Ordered list of Value pointers.

using use_list = std::vector<Use>#

List of Use records for a value.

using NodeKind = Symbol#

Symbolic kind identifier for a Node.

Enums

enum class AttributeKind : uint8_t#

Discriminator tag for the concrete type of an attribute value.

Each enumerator corresponds to a scalar or vector ONNX attribute type: float (f), float list (fs), integer (i), integer list (is), string (s), string list (ss), tensor (t), tensor list (ts), subgraph (g), subgraph list (gs), type-proto (tp), and type-proto list (tps).

Values:

enumerator f#
enumerator fs#
enumerator i#
enumerator is#
enumerator s#
enumerator ss#
enumerator t#
enumerator ts#
enumerator g#
enumerator gs#
enumerator tp#
enumerator tps#

Functions

static inline std::string toVarName(size_t i)#
static inline const char *toString(AttributeKind kind)#

Converts an AttributeKind enumerator to its string name.

Parameters:

kind – The attribute kind.

Returns:

A null-terminated string such as "f", "fs", "i", etc.

static inline bool operator==(const Use &a, const Use &b)#

Returns true if two Use records refer to the same (node, offset) pair.

template<typename Derived>
struct Attributes#
#include <ir.h>

CRTP mixin that adds typed attribute storage to a node class.

Enables method chaining via a Derived* return type, e.g.:

Node *n = g->create(kSelect)->i_(kOffset, 3)->f_(kValue, 3.5f);

Attribute lookup is O(n) in the number of attributes to keep deterministic ordering; nodes are not expected to carry a large number of attributes.

Template Parameters:

Derived – The concrete node type that inherits this mixin.

Subclassed by ONNX_LIGHT_NAMESPACE::Node

Public Functions

Attributes() = default#
inline void copyAttributes(const Attributes &rhs)#

Replaces all attributes of this object with deep copies from rhs.

Parameters:

rhs – Source object whose attributes are cloned.

inline bool hasAttribute(Symbol name) const#

Returns true if an attribute with the given name exists.

Parameters:

name – Attribute symbol to look up.

inline AttributeKind kindOf(Symbol name) const#

Returns the kind of the attribute with the given name.

Parameters:

name – Attribute symbol (must exist).

inline Derived *removeAttribute(Symbol name)#

Removes the attribute with the given name and returns this.

Parameters:

name – Attribute symbol (must exist).

inline bool hasAttributes() const#

Returns true if any attributes are set.

inline std::vector<Symbol> attributeNames() const#

Returns the names of all set attributes in insertion order.

Private Types

using AVPtr = AttributeValue::Ptr#
using iterator = std::vector<AVPtr>::iterator#
using const_iterator = std::vector<AVPtr>::const_iterator#

Private Functions

inline Derived *This()#
template<typename T>
inline Derived *set(Symbol name, typename T::ConstructorType v)#
template<typename T>
inline T::ValueType &get(Symbol name) const#
inline iterator find(Symbol name, bool required)#
inline const_iterator find(Symbol name, bool required) const#

Private Members

std::vector<AVPtr> values_#
struct AttributeValue#
#include <ir.h>

Abstract base class for a named attribute value stored on a Node.

Concrete subtypes are ScalarAttributeValue and VectorAttributeValue, instantiated for each supported ONNX attribute kind.

Subclassed by ONNX_LIGHT_NAMESPACE::ScalarAttributeValue< T, Kind >, ONNX_LIGHT_NAMESPACE::VectorAttributeValue< T, Kind >

Public Types

using Ptr = std::unique_ptr<AttributeValue>#

Owning pointer alias for convenience.

Public Functions

inline explicit AttributeValue(Symbol name)#

Constructs an attribute with the given name.

Parameters:

nameSymbol identifying the attribute.

virtual AttributeKind kind() const = 0#

Returns the discriminator kind of this attribute.

virtual Ptr clone() const = 0#

Returns a deep copy of this attribute.

virtual ~AttributeValue() = default#

Public Members

Symbol name#

The attribute’s symbolic name.

struct Dimension#
#include <ir.h>

Represents a single dimension of a tensor shape.

A dimension is one of:

  • unknown – neither an integer nor a symbolic parameter (default).

  • symbolic – a named parameter string (e.g. "batch_size").

  • static – a concrete non-negative int64_t value.

Public Functions

inline Dimension()#

Constructs an unknown dimension.

inline explicit Dimension(std::string param)#

Constructs a symbolic dimension.

Parameters:

param – Symbolic parameter name.

inline explicit Dimension(int64_t dim)#

Constructs a static integer dimension.

Parameters:

dim – Non-negative size of this dimension.

Public Members

bool is_unknown#

True when the dimension is completely unknown.

bool is_int#

True when dim holds a concrete integer value.

int64_t dim#

The concrete size; meaningful only when is_int is true.

std::string param#

The symbolic parameter name; meaningful only when is_int and is_unknown are both false.

struct Graph#
#include <ir.h>

Computation graph owning all its nodes and values.

A Graph owns every Node and Value it creates. All pointers returned by its API are non-owning; destroying the graph invalidates them.

The graph maintains two pseudo-nodes:

  • input_ — its outputs represent the graph’s formal input Value objects.

  • output_ — its inputs represent the graph’s output Value objects; also serves as the sentinel for the circular topological node list.

A separate initializer_node_ holds Value objects for IR ≥ 4 initializers that are not required to appear in the input list.

Public Functions

ONNX_DISALLOW_COPY_AND_ASSIGN(Graph)#
inline Graph()#

Constructs an empty graph with input, output, and initializer sentinel nodes.

inline bool has_doc_string() const#

Returns true if a documentation string is set.

inline const std::string &docString() const#

Returns the graph documentation string.

inline void setDocString(std::string doc_string)#

Sets the graph documentation string.

Parameters:

doc_string – Documentation text.

inline void addInitializer(Tensor &initializer)#

Adds initializer to the graph’s initializer list.

If the initializer has no name, a unique name is generated automatically.

Parameters:

initializerTensor to register as an initializer.

inline Value *addInitializerAndCreateValue(Tensor &initializer)#

Adds initializer to the initializer list and returns a corresponding Value.

For IR ≥ 4, initializers are not required to appear in the graph input list. This method registers the initializer and creates a Value in the internal initializer node list.

Parameters:

initializerTensor to register.

Returns:

The new Value representing the initializer.

inline void eraseInitializer(const std::string &name)#

Removes the initializer with the given name from all lists.

Parameters:

name – Name of the initializer to remove.

inline void clearInitializers()#

Removes all initializers and clears the initializer name list.

inline const std::vector<Tensor> &initializers() const#

Returns the list of initializer tensors.

inline const std::vector<std::string> &initializer_names() const#

Returns the list of initializer names.

inline std::vector<Tensor>::const_iterator getInitializer(const std::string &name) const#

Returns a const iterator to the initializer with the given name, or initializers().end() if not found.

Parameters:

name – Initializer name to search for.

inline bool is_constant_initializer(const Value *value) const#

Returns true if value originates from the internal initializer node (i.e. it is an IR ≥ 4 initializer not present in the input list).

Parameters:

valueValue to test.

inline ArrayRef<Value*> inputs()#

Returns an ArrayRef over the graph’s formal input values.

inline ArrayRef<const Value*> inputs() const#

Returns a const ArrayRef over the graph’s formal input values.

inline ArrayRef<Value*> outputs()#

Returns an ArrayRef over the graph’s output values.

inline ArrayRef<const Value*> outputs() const#

Returns a const ArrayRef over the graph’s output values.

inline graph_node_list nodes()#

Returns a forward-iterable view over the computation nodes in topological order.

inline const_graph_node_list nodes() const#

Returns a const forward-iterable view over the computation nodes.

inline std::vector<OpSetID> &opset_versions_mutable()#

Returns a mutable reference to the operator-set version list.

inline size_t getNextUnique()#

Allocates and returns the next graph-unique integer identifier.

Skips any integers whose generated name (_v_N) is already in use.

inline std::string getNextUniqueName()#

Returns a unique name string of the form "_v_N".

Equivalent to toVarName(getNextUnique()).

inline graph_node_list_iterator begin()#

Returns a forward iterator to the first computation node.

Safe to call on the temporary graph_node_list returned by nodes() because the list is non-owning.

inline const_graph_node_list_iterator begin() const#

Returns a const forward iterator to the first computation node.

inline graph_node_list_iterator end()#

Returns a forward sentinel iterator (one past the last node).

inline const_graph_node_list_iterator end() const#

Returns a const forward sentinel iterator.

inline graph_node_list_iterator rbegin()#

Returns a reverse iterator to the last computation node.

inline const_graph_node_list_iterator rbegin() const#

Returns a const reverse iterator to the last computation node.

inline graph_node_list_iterator rend()#

Returns a reverse sentinel iterator.

inline const_graph_node_list_iterator rend() const#

Returns a const reverse sentinel iterator.

inline Node *return_node()#

Returns the sentinel return node (also the circular list head/tail).

inline const Node *return_node() const#

Returns the sentinel return node (const overload).

inline Value *addInput()#

Appends a new formal input Value and returns it.

inline void eraseInput(size_t i)#

Removes the formal input at index i.

Parameters:

i – Zero-based input index.

inline void advanceStage()#

Increments the current node-stage counter.

inline void setStage(size_t new_stage)#

Sets the current node-stage counter.

Parameters:

new_stage – New stage value.

inline size_t stage() const#

Returns the current node-stage counter.

inline ResourceGuard setStageTemporary(size_t s)#

Temporarily sets the stage to s and returns a ResourceGuard that restores the previous value on destruction.

Parameters:

s – Temporary stage value.

inline size_t registerOutput(Value *n)#

Registers n as a graph output and returns its output index.

Parameters:

nValue to register as a graph output.

Returns:

Zero-based index of the newly registered output.

inline Node *create(NodeKind kind, size_t num_outputs = 1)#

Creates and returns a new unattached node with num_outputs outputs.

The node is added to the graph’s allocation set but not yet in the topological node list. Use appendNode or Node::insertBefore / Node::insertAfter to place it.

Parameters:
  • kind – Symbolic operation kind.

  • num_outputs – Number of output values to allocate (default: 1).

Returns:

The new node.

inline Node *create(NodeKind kind, ArrayRef<Value*> inputs, size_t num_outputs = 1)#

Creates a new unattached node with the given inputs and outputs.

Parameters:
  • kind – Symbolic operation kind.

  • inputs – Input values to wire up immediately.

  • num_outputs – Number of output values to allocate (default: 1).

Returns:

The new node.

inline Node *appendNode(Node *n)#

Appends n at the end of the topological node list and returns it.

Parameters:

n – Unattached node belonging to this graph.

inline Node *prependNode(Node *n)#

Prepends n at the beginning of the topological node list and returns it.

Parameters:

n – Unattached node belonging to this graph.

inline Value *addInitializerAndInput(const Tensor &initializer, const std::string &name)#

Adds initializer as both a graph input and an initializer entry.

Registers the initializer in the initializer list, creates a formal input Value, and synchronises the initializer name, tensor name, and value name.

Parameters:
  • initializer – Source tensor (copied internally).

  • name – Name to assign to the initializer and its value.

Returns:

The new input Value.

inline Value *addInitializerAndInput(const Tensor &initializer)#

Adds initializer as both a graph input and an initializer entry, generating a unique name automatically.

Parameters:

initializer – Source tensor (copied internally).

Returns:

The new input Value.

inline void eraseInitializerAndInput(Value *v)#

Removes v from the initializer list and, if it is a graph input, from the input list as well.

Parameters:

v – The initializer value to erase.

Pre:

v must have no remaining uses.

inline ~Graph()#

Destroys all owned nodes and values.

inline std::string toString() const#

Returns a textual representation of the graph for debugging.

inline bool has_name() const#

Returns true if a graph name is set.

inline const std::string &name() const#

Returns the graph name (meaningful only when has_name() is true).

inline void setName(std::string name)#

Sets the graph name.

Parameters:

name – Name string.

inline void forSelfAndEachSubGraph(const std::function<void(Graph*)> &fn)#

Calls fn on this graph and recursively on every subgraph in node attributes.

Parameters:

fn – Callable accepting a Graph* pointer.

inline void forSelfAndEachSubGraph(const std::function<void(const Graph*)> &fn) const#

Const overload of forSelfAndEachSubGraph.

inline void forEachNode(const std::function<void(Node*)> &fn)#

Calls fn on every node in this graph and all subgraphs.

Parameters:

fn – Callable accepting a Node* pointer.

inline void forEachNode(const std::function<void(const Node*)> &fn) const#

Const overload of forEachNode.

Private Functions

inline bool isNameUnique(const std::string &name) const#
inline Node *initOutput(Node *p)#
inline void freeNode(Node *n)#
inline void freeValue(Value *v)#

Private Members

std::unordered_set<const Node*> all_nodes#
std::unordered_set<const Value*> all_values#
size_t next_unique_ = {0}#
size_t new_node_stage_ = {0}#
Node *const output_#
Node *const input_#
Node *const initializer_node_#
std::vector<Tensor> initializers_#
std::vector<std::string> initializer_names_#
bool has_name_ = {false}#
std::string name_#
bool has_doc_string_ = {false}#
std::string doc_string_#
std::vector<OpSetID> opset_versions_#

Friends

friend struct Node
friend struct Value
friend std::ostream &operator<<(std::ostream &out, const Graph &g)#

Streams a textual representation of the graph to out.

struct Node : public ONNX_LIGHT_NAMESPACE::Attributes<Node>#
#include <ir.h>

A single computation node in the IR graph.

A Node has a symbolic kind() that identifies the operation, an ordered list of input Value pointers, and a list of output Value objects it produces. It also inherits typed attribute storage from Attributes<Node>.

Nodes are maintained in topological order via an intrusive doubly-linked list (next_in_graph). The Return / Param pseudo-nodes serve as sentinels and are not part of the logical computation.

Node objects are owned by their Graph; never delete them manually — use destroy() instead.

Public Functions

ONNX_DISALLOW_COPY_AND_ASSIGN(Node)#
inline Node *&next_in_graph(size_t i)#

Returns a reference to the linked-list pointer in direction i.

Parameters:

i – 0 for next, 1 for prev (see kNextDirection / kPrevDirection).

inline Node *const &next_in_graph(size_t i) const#

Returns a const reference to the linked-list pointer in direction i.

inline Node *&next()#

Returns a mutable reference to the forward (next) linked-list pointer.

inline Node *&prev()#

Returns a mutable reference to the backward (prev) linked-list pointer.

inline Node *const &next() const#

Returns a const reference to the forward (next) linked-list pointer.

inline Node *const &prev() const#

Returns a const reference to the backward (prev) linked-list pointer.

inline bool has_name() const#

Returns true if a node name is set.

inline const std::string &name() const#

Returns the node name (meaningful only when has_name() is true).

inline void setName(std::string name)#

Sets the node name.

Parameters:

nameNode name string.

inline bool has_domain() const#

Returns true if an operator domain is set.

inline const std::string &domain() const#

Returns the operator domain (meaningful only when has_domain() is true).

inline void setDomain(std::string domain)#

Sets the operator domain.

Parameters:

domain – Domain string (e.g. "" for the default ONNX domain).

inline bool has_overload() const#

Returns true if an overload string is set.

inline const std::string &overload() const#

Returns the overload string (meaningful only when has_overload() is true).

inline void setOverload(std::string overload)#

Sets the overload string.

Parameters:

overload – Overload identifier.

inline bool has_doc_string() const#

Returns true if a documentation string is set.

inline const std::string &docString() const#

Returns the documentation string.

inline void setDocString(std::string doc_string)#

Sets the documentation string.

Parameters:

doc_string – Documentation text.

inline NodeKind kind() const#

Returns the symbolic kind of this node (e.g. kAdd, kConv).

inline Graph *owningGraph()#

Returns the owning graph.

inline const Graph *owningGraph() const#

Returns the owning graph (const overload).

inline size_t stage() const#

Returns the current stage index of this node.

inline Node *setStage(size_t s)#

Sets the stage index and returns this.

Parameters:

s – New stage index (0 = forward, 1 = backward, …).

inline ArrayRef<Value*> inputs()#

Returns an ArrayRef over this node’s input values.

Warning

The returned reference is invalidated if the input list is resized (e.g. via addInput).

inline ArrayRef<const Value*> inputs() const#

Returns a const ArrayRef over this node’s input values.

inline ArrayRef<Value*> outputs()#

Returns an ArrayRef over this node’s output values.

Warning

The returned reference is invalidated if the output list is resized.

inline ArrayRef<const Value*> outputs() const#

Returns a const ArrayRef over this node’s output values.

inline bool hasUses() const#

Returns true if any output of this node has at least one use.

inline void replaceAllUsesWith(Node *n)#

Replaces all uses of every output of this with the corresponding output of n.

n must have the same number of outputs as this.

Parameters:

n – Replacement node.

inline Value *input()#

Returns the sole input of this node.

Asserts that the node has exactly one input.

inline Value *output()#

Returns the sole output of this node.

Asserts that the node has exactly one output.

inline const Value *input() const#

Returns the sole input of this node (const overload).

inline const Value *output() const#

Returns the sole output of this node (const overload).

inline Value *input(size_t i)#

Returns the input at index i (bounds-checked).

Parameters:

i – Zero-based input index.

inline const Value *input(size_t i) const#

Returns the input at index i (const overload).

inline Value *addInput(Value *node)#

Appends node as an input to this and returns it for chaining.

Given: %3 = f(%1, %2) Execute: %3.addInput(%4) Result: %3 = f(%1, %2, %4)

Parameters:

node – Input value to append (must belong to the same graph).

Returns:

The appended value node.

inline Value *replaceInput(size_t i, Value *newValue)#

Replaces the input at position i with newValue.

Given: %3 = f(%1, %2) Execute: %3.replaceInput(1, %4) Result: %3 = f(%1, %4)

Parameters:
  • i – Zero-based index of the input to replace.

  • newValue – Replacement value (must belong to the same graph).

Returns:

The old input value at position i.

inline void replaceInputWith(Value *from, Value *to)#

Replaces all occurrences of from in the input list with to.

Corresponds to LLVM’s replaceUsesOfWith.

Given: %3 = f(%1, %2, %1) Execute: %3.replaceInputWith(%1, %4) Result: %3 = f(%4, %2, %4)

Parameters:
  • fromValue to replace (must belong to the same graph).

  • to – Replacement value (must belong to the same graph).

inline Value *addOutput()#

Appends a new output Value to this node and returns it.

inline void eraseOutput(size_t i)#

Removes the output at index i.

Parameters:

i – Zero-based output index (the output must have no uses).

inline Node *insertBefore(Node *n)#

Inserts an unattached node before n in topological order.

Given: %3 = f(%1, %2) %4 = g(%3) and unattached: %5 = h(%1) Execute: %5.insertBefore(%4) Result: %3 = f(%1, %2) %5 = h(%1) %4 = g(%3)

Parameters:

n – An existing node already in the graph list.

Returns:

this for chaining.

inline Node *insertAfter(Node *n)#

Inserts an unattached node after n in topological order.

Given: %3 = f(%1, %2) %4 = g(%3) and unattached: %5 = h(%1) Execute: %5.insertAfter(%4) Result: %3 = f(%1, %2) %4 = g(%3) %5 = h(%1)

Parameters:

n – An existing node already in the graph list.

Returns:

this for chaining.

inline void moveAfter(Node *n)#

Moves this (already in the graph) to appear after n.

Given: %2 = f(%1) %3 = g(%1) Execute: %2.moveAfter(%3) Result: %3 = g(%1) %2 = f(%1)

Parameters:

n – Target node (must be in the graph).

inline void moveBefore(Node *n)#

Moves this (already in the graph) to appear before n.

Given: %2 = f(%1) %3 = g(%1) Execute: %3.moveBefore(%2) Result: %3 = g(%1) %2 = f(%1)

Parameters:

n – Target node (must be in the graph).

inline void removeInput(size_t i)#

Removes the input at index i.

Given: %3 = f(%1, %2) Execute: %3.removeInput(1) Result: %3 = f(%1)

Warning

This is O(n) in the number of inputs; avoid calling it in a loop.

Parameters:

i – Zero-based index of the input to remove.

inline void removeAllInputs()#

Removes all inputs from this node.

Given: %3 = f(%1, %2) Execute: %3.removeAllInputs() Result: %3 = f()

inline bool isBefore(const Node *n)#

Returns true if this appears before n in topological order.

Parameters:

nNode to compare against.

inline graph_node_list_iterator iterator()#

Returns a forward iterator to the node-list position of this.

Useful for resuming a graph traversal starting at a known node.

inline graph_node_list_iterator reverseIterator()#

Returns a reverse iterator to the node-list position of this.

inline const_graph_node_list_iterator iterator() const#

Returns a const forward iterator to the node-list position of this.

inline const_graph_node_list_iterator reverseIterator() const#

Returns a const reverse iterator to the node-list position of this.

inline void destroy()#

Removes this from the node list and deallocates it.

Given: %2 = f(%1) %3 = g(%1) Execute: %2.destroy() Result: %3 = g(%1)

Pre:

No outputs of this may have any remaining uses.

template<typename T>
inline T *cast()#

Dynamically casts this to T; returns nullptr if the kind does not match.

Example:

if (auto *s = n->cast<Select>()) { ... } 

Template Parameters:

T – Subclass with a static Kind member to compare against.

template<typename T>
inline const T *cast() const#

Const overload of cast().

template<typename T>
inline T *expect()#

Asserts that the kind matches T and returns a typed pointer.

Aborts with a descriptive message if the kind does not match.

Template Parameters:

T – Subclass with a static Kind member.

template<typename T>
inline const T *expect() const#

Const overload of expect().

virtual ~Node() = default#

Protected Functions

inline Node(Graph *graph_, NodeKind kind_)#
inline virtual Node *allocNewInstance(Graph *g)#

Allocates a new node of the same concrete type in graph g.

Used by createClone to create a fresh instance in a different graph. Subclasses must override if they introduce additional state.

inline virtual void cloneFrom(Node *s)#

Copies all attribute values from s into this.

Subclasses should extend to also copy any additional state they introduce. this will have been allocated via s->allocNewInstance(g).

Note

Stage information is not cloned; set it explicitly if needed.

Parameters:

s – Source node (same concrete type as this).

Private Functions

inline use_list::iterator findUseForInput(size_t i)#
inline Value *dropInput(size_t i)#
inline bool inGraphList() const#
inline void removeFromList()#

Private Members

std::array<Node*, 2> next_in_graph_ = {nullptr, nullptr}#
const NodeKind kind_#
std::vector<Value*> inputs_#
std::vector<Value*> outputs_#
Graph *graph_#
size_t stage_#
bool has_name_ = {false}#
std::string name_#
bool has_domain_ = {false}#
std::string domain_#
bool has_doc_string_ = {false}#
std::string doc_string_#
bool has_overload_ = {false}#
std::string overload_#

Friends

friend struct Graph
friend struct Value
class OpSetID#
#include <ir.h>

Lightweight (domain, version) pair identifying an ONNX operator set.

Provides the same information as OperatorSetIdProto but without protobuf overhead, resulting in simpler and more readable code.

Public Functions

inline explicit OpSetID(const OperatorSetIdProto &proto)#

Constructs an OpSetID from a protobuf OperatorSetIdProto.

Parameters:

proto – Source protobuf message.

inline explicit OpSetID(const int64_t version)#

Constructs an OpSetID for the default ONNX domain at the given version.

Parameters:

version – Operator-set version number.

inline explicit OpSetID(std::string domain, int64_t version)#

Constructs an OpSetID for the specified domain and version.

Parameters:
  • domain – Domain string (e.g. "" or "ai.onnx.ml").

  • version – Operator-set version number.

inline std::string toString() const#

Returns a string representation in the form "<domain>$<version>".

inline const std::string &domain() const#

Returns the operator set domain.

inline int64_t version() const#

Returns the operator set version number.

inline void incrementVersion(int64_t step)#

Increments the version by step.

Parameters:

step – Amount to add to the current version.

inline void setVersion(int64_t newVal)#

Sets the version to newVal.

Parameters:

newVal – New version number.

Public Static Functions

static inline OpSetID fromString(const std::string &target)#

Parses a string in the form "<domain>$<version>" into an OpSetID.

Parameters:

target – String to parse; must contain exactly one '$' separator.

Throws:

std::runtime_error – if the format is invalid.

Private Members

std::string domain_#
int64_t version_#
class ResourceGuard#
#include <ir.h>

RAII guard that invokes a callable destructor when it goes out of scope.

Non-copyable and non-movable. Typically used to restore transient graph state (e.g. stage number) set for the duration of a code region.

Public Functions

ONNX_DISALLOW_COPY_AND_ASSIGN(ResourceGuard)#
ResourceGuard(ResourceGuard&&) = delete#
ResourceGuard &operator=(ResourceGuard&&) = delete#
inline explicit ResourceGuard(std::function<void()> destructor)#
inline ~ResourceGuard()#

Invokes the destructor callable function.

Private Members

std::function<void()> destructor_#
template<typename T, AttributeKind Kind>
struct ScalarAttributeValue : public ONNX_LIGHT_NAMESPACE::AttributeValue#
#include <ir.h>

Holds a single scalar attribute value of type T and kind Kind.

Template Parameters:
  • T – The C++ value type (e.g. double, int64_t, std::string).

  • Kind – The AttributeKind tag for this type.

Public Types

using ConstructorType = const T&#
using ValueType = T#

Public Functions

inline ScalarAttributeValue(Symbol name, ConstructorType value_)#
inline ValueType &value()#

Returns a mutable reference to the stored scalar value.

inline virtual Ptr clone() const override#

Returns a deep copy wrapped in a Ptr.

inline virtual AttributeKind kind() const override#

Returns Kind.

Private Members

ValueType value_#
struct Use#
#include <ir.h>

Records a single use of a Value by a Node.

A Use links a producer Value to the Node that consumes it and the position (offset) in that node’s input list where the value appears.

Public Functions

inline Use(Node *user, size_t offset)#

Constructs a use record.

Parameters:
  • user – The node that consumes the value.

  • offset – Index into user's input list.

Public Members

Node *user#

The consuming node.

size_t offset#

Index of this value in user’s input list.

struct Value#
#include <ir.h>

A typed SSA value (edge) in the IR graph.

Each Value is produced by exactly one Node (its node()) and may be consumed by zero or more nodes, tracked via uses(). The value carries optional type information: ONNX element type (elemType()) and shape (sizes()).

Value objects are owned by their Graph; do not delete them manually.

Public Functions

ONNX_DISALLOW_COPY_AND_ASSIGN(Value)#
inline Value(Node *node_, size_t offset_)#

Constructs a value produced by node_ at output position offset_.

Value(Value&&) = default#
Value &operator=(Value&&) = default#
~Value() = default#
inline Value *setElemType(int32_t elem_type)#

Sets the ONNX element type and returns this for chaining.

Parameters:

elem_type – ONNX DataType enum value.

inline int32_t elemType() const#

Returns the ONNX element type.

inline bool has_sizes() const#

Returns true if shape information has been set.

inline Value *setSizes(std::vector<Dimension> sizes)#

Sets the shape of this value and returns this for chaining.

Parameters:

sizes – Per-dimension size descriptors.

inline Value *wipeSizes()#

Clears any previously set shape information and returns this.

inline const std::vector<Dimension> &sizes() const#

Returns the shape dimensions (may be empty if shape is unknown).

inline size_t unique() const#

Returns the graph-unique numeric identifier of this value.

inline bool has_unique_name() const#

Returns true if an explicit string name has been assigned.

inline std::string uniqueName() const#

Returns the string name of this value.

If no explicit name has been set, returns a generated name of the form "_v_N" where N is unique().

inline Value *setUniqueName(const std::string &name, bool update_related_names = true)#

Sets the string name of this value.

Parameters:
  • name – New name for this value.

  • update_related_names – When true, propagates the rename to initializer entries and captured nodes in subgraphs.

inline Value *setStage(size_t s)#

Sets the stage index (forward=0, backward=1, …) and returns this.

Parameters:

s – New stage index.

inline size_t stage() const#

Returns the stage index.

inline Node *node()#

Returns the node that produces this value.

inline size_t offset() const#

Returns the output offset within the producing node.

inline const Node *node() const#

Returns the node that produces this value (const overload).

inline Graph *owningGraph()#

Returns the owning graph.

inline const Graph *owningGraph() const#

Returns the owning graph (const overload).

inline use_list uses() const#

Returns all recorded uses of this value in the current graph.

inline void replaceAllUsesWith(Value *newValue)#

Replaces all uses of this value with newValue.

Also propagates element type and size information to newValue, and renames captured references in subgraphs if this value is a graph output.

Given: %3 = f(%1, %2) %4 = g(%3) %5 = h(%3, %3) Execute: %3.replaceAllUsesWith(%6) Result: %3 = f(%1, %2) %4 = g(%6) %5 = h(%6, %6)

Parameters:

newValue – The replacement value (must belong to the same graph).

inline Value *copyMetadata(const Value *from)#

Copies element type, shape, and optional name from from.

Parameters:

from – Source value whose metadata is copied.

Returns:

this for chaining.

inline std::unique_ptr<TypeProto> &type()#

Returns a mutable reference to the optional TypeProto for this value.

Private Members

Node *node_#
size_t offset_#
size_t unique_ = 0#
size_t stage_ = 0#
use_list uses_in_current_graph_#
bool has_unique_name_ = {false}#
std::string unique_name_#
int32_t elem_type_ = {TensorProto::DataType::UNDEFINED}#
bool has_sizes_ = {false}#
std::vector<Dimension> sizes_#
std::unique_ptr<TypeProto> type_#

Friends

friend struct Node
friend struct Graph
template<typename T, AttributeKind Kind>
struct VectorAttributeValue : public ONNX_LIGHT_NAMESPACE::AttributeValue#
#include <ir.h>

Holds a vector attribute value of element type T and kind Kind.

Template Parameters:
  • T – The C++ element type (e.g. double, int64_t).

  • Kind – The AttributeKind tag for this list type.

Public Types

using ConstructorType = const std::vector<T>&&#
using ValueType = std::vector<T>#

Public Functions

inline VectorAttributeValue(Symbol name, ValueType value_)#
inline ValueType &value()#

Returns a mutable reference to the stored vector.

inline virtual AttributeKind kind() const override#

Returns Kind.

inline virtual std::unique_ptr<AttributeValue> clone() const override#

Returns a deep copy wrapped in a unique_ptr.

Private Members

ValueType value_#