Beaver.MLIR.Dialect.EmitC (beaver v0.4.8)

Copy Markdown

Summary

Functions

Return op name emitc.add as a bitstring.

emitc.add - Addition operation

Return op name emitc.add_assign as a bitstring.

emitc.add_assign - Addition assignment operation

Return op name emitc.address_of as a bitstring.

emitc.address_of - Address operation

Return op name emitc.assign as a bitstring.

emitc.assign - Assign operation

Return op name emitc.bitwise_and as a bitstring.

emitc.bitwise_and - Bitwise and operation

Return op name emitc.bitwise_left_shift as a bitstring.

emitc.bitwise_left_shift - Bitwise left shift operation

Return op name emitc.bitwise_not as a bitstring.

emitc.bitwise_not - Bitwise not operation

Return op name emitc.bitwise_or as a bitstring.

emitc.bitwise_or - Bitwise or operation

Return op name emitc.bitwise_right_shift as a bitstring.

emitc.bitwise_right_shift - Bitwise right shift operation

Return op name emitc.bitwise_xor as a bitstring.

emitc.bitwise_xor - Bitwise xor operation

Return op name emitc.call as a bitstring.

emitc.call - Call operation

Return op name emitc.call_opaque as a bitstring.

emitc.call_opaque - Opaque call operation

Return op name emitc.cast as a bitstring.

emitc.cast - Cast operation

Return op name emitc.class as a bitstring.

emitc.class - Represents a C++ class definition, encapsulating fields and methods.

Return op name emitc.cmp as a bitstring.

emitc.cmp - Comparison operation

Return op name emitc.conditional as a bitstring.

emitc.conditional - Conditional (ternary) operation

Return op name emitc.constant as a bitstring.

emitc.constant - Constant operation

Return op name emitc.declare_func as a bitstring.

emitc.declare_func - An operation to declare a function

Return op name emitc.dereference as a bitstring.

emitc.dereference - Dereference operation

Return op name emitc.div as a bitstring.

emitc.div - Division operation

Return op name emitc.div_assign as a bitstring.

emitc.div_assign - Division assignment operation

Return op name emitc.do as a bitstring.

emitc.do - Do-while operation

Return op name emitc.expression as a bitstring.

emitc.expression - Expression operation

Return op name emitc.field as a bitstring.

emitc.field - A field within a class

Return op name emitc.file as a bitstring.

emitc.file - A file container operation

Return op name emitc.for as a bitstring.

emitc.for - For operation

Return op name emitc.func as a bitstring.

emitc.func - An operation with a name containing a single SSACFG region

Return op name emitc.get_field as a bitstring.

emitc.get_field - Obtain access to a field within a class instance

Return op name emitc.get_global as a bitstring.

emitc.get_global - Obtain access to a global variable

Return op name emitc.global as a bitstring.

emitc.global - A global variable

Return op name emitc.if as a bitstring.

emitc.if - If-then-else operation

Return op name emitc.include as a bitstring.

emitc.include - Include operation

Return op name emitc.literal as a bitstring.

emitc.literal - Literal operation

Return op name emitc.load as a bitstring.

emitc.load - Load an lvalue into an SSA value.

Return op name emitc.logical_and as a bitstring.

emitc.logical_and - Logical and operation

Return op name emitc.logical_not as a bitstring.

emitc.logical_not - Logical not operation

Return op name emitc.logical_or as a bitstring.

emitc.logical_or - Logical or operation

Return op name emitc.member as a bitstring.

emitc.member - Member operation

Return op name emitc.member_call_opaque as a bitstring.

emitc.member_call_opaque - Opaque member call operation

Return op name emitc.member_of_ptr as a bitstring.

emitc.member_of_ptr - Member of pointer operation

Return op name emitc.mul as a bitstring.

emitc.mul - Multiplication operation

Return op name emitc.mul_assign as a bitstring.

emitc.mul_assign - Multiplication assignment operation

Return op name emitc.post_decrement as a bitstring.

emitc.post_decrement - Post-decrement operation

Return op name emitc.post_increment as a bitstring.

emitc.post_increment - Post-increment operation

Return op name emitc.pre_decrement as a bitstring.

emitc.pre_decrement - Pre-decrement operation

Return op name emitc.pre_increment as a bitstring.

emitc.pre_increment - Pre-increment operation

Return op name emitc.rem as a bitstring.

emitc.rem - Remainder operation

Return op name emitc.rem_assign as a bitstring.

emitc.rem_assign - Remainder assignment operation

Return op name emitc.return as a bitstring.

emitc.return - Function return operation

Return op name emitc.sub as a bitstring.

emitc.sub - Subtraction operation

Return op name emitc.sub_assign as a bitstring.

emitc.sub_assign - Subtraction assignment operation

Return op name emitc.subscript as a bitstring.

emitc.subscript - Subscript operation

Return op name emitc.switch as a bitstring.

emitc.switch - Switch operation

Return op name emitc.unary_minus as a bitstring.

emitc.unary_minus - Unary minus operation

Return op name emitc.unary_plus as a bitstring.

emitc.unary_plus - Unary plus operation

Return op name emitc.variable as a bitstring.

emitc.variable - Variable operation

Return op name emitc.verbatim as a bitstring.

emitc.verbatim - Verbatim operation

Return op name emitc.yield as a bitstring.

emitc.yield - Block termination operation

Functions

add()

Return op name emitc.add as a bitstring.

add(ssa)

emitc.add - Addition operation

Operands

  • lhs - Single, EmitCType, type supported by EmitC
  • rhs - Single, EmitCType, type supported by EmitC

Results

  • anonymous - Single, EmitCType, type supported by EmitC

Description

With the emitc.add operation the arithmetic operator + (addition) can be applied.

Example:

// Custom form of the addition operation.
%0 = emitc.add %arg0, %arg1 : (i32, i32) -> i32
%1 = emitc.add %arg2, %arg3 : (!emitc.ptr<f32>, i32) -> !emitc.ptr<f32>
// Code emitted for the operations above.
int32_t v5 = v1 + v2;
float* v6 = v3 + v4;

add_assign()

Return op name emitc.add_assign as a bitstring.

add_assign(ssa)

emitc.add_assign - Addition assignment operation

Operands

  • var - Single, EmitC_LValueType, EmitC lvalue type
  • value - Single, EmitCType, type supported by EmitC

Description

The emitc.add_assign operation applies the C/C++ += operator to an lvalue.

Example:

emitc.add_assign %value : i32 to %var : !emitc.lvalue<i32>

address_of()

Return op name emitc.address_of as a bitstring.

address_of(ssa)

emitc.address_of - Address operation

Operands

  • reference - Single, EmitC_LValueType, EmitC lvalue type

Results

  • result - Single, EmitC_PointerType, EmitC pointer type

Description

This operation models the C & (address of) operator for a single operand, which must be an emitc.lvalue, and returns an emitc pointer to its location.

Example:

// Custom form of applying the & operator.
%0 = emitc.address_of %arg0 : (!emitc.lvalue<i32>) -> !emitc.ptr<i32>

assign()

Return op name emitc.assign as a bitstring.

assign(ssa)

emitc.assign - Assign operation

Operands

  • var - Single, EmitC_LValueType, EmitC lvalue type
  • value - Single, EmitCType, type supported by EmitC

Description

The emitc.assign operation stores an SSA value to the location designated by an EmitC variable. This operation doesn't return any value. The assigned value must be of the same type as the variable being assigned. The operation is emitted as a C/C++ '=' operator.

Example:

// Integer variable
%0 = "emitc.variable"(){value = 42 : i32} : () -> !emitc.lvalue<i32>
%1 = emitc.call_opaque "foo"() : () -> (i32)

// Assign emitted as `... = ...;`
"emitc.assign"(%0, %1) : (!emitc.lvalue<i32>, i32) -> ()

bitwise_and()

Return op name emitc.bitwise_and as a bitstring.

bitwise_and(ssa)

emitc.bitwise_and - Bitwise and operation

Operands

  • lhs - Single, EmitCType, type supported by EmitC
  • rhs - Single, EmitCType, type supported by EmitC

Results

  • anonymous - Single, EmitCType, type supported by EmitC

Description

With the emitc.bitwise_and operation the bitwise operator & (and) can be applied.

Example:

%0 = emitc.bitwise_and %arg0, %arg1 : (i32, i32) -> i32
// Code emitted for the operation above.
int32_t v3 = v1 & v2;

bitwise_left_shift()

Return op name emitc.bitwise_left_shift as a bitstring.

bitwise_left_shift(ssa)

emitc.bitwise_left_shift - Bitwise left shift operation

Operands

  • lhs - Single, EmitCType, type supported by EmitC
  • rhs - Single, EmitCType, type supported by EmitC

Results

  • anonymous - Single, EmitCType, type supported by EmitC

Description

With the emitc.bitwise_left_shift operation the bitwise operator << (left shift) can be applied.

Example:

%0 = emitc.bitwise_left_shift %arg0, %arg1 : (i32, i32) -> i32
// Code emitted for the operation above.
int32_t v3 = v1 << v2;

bitwise_not()

Return op name emitc.bitwise_not as a bitstring.

bitwise_not(ssa)

emitc.bitwise_not - Bitwise not operation

Operands

  • anonymous - Single, EmitCType, type supported by EmitC

Results

  • anonymous - Single, EmitCType, type supported by EmitC

Description

With the emitc.bitwise_not operation the bitwise operator ~ (not) can be applied.

Example:

%0 = emitc.bitwise_not %arg0 : (i32) -> i32
// Code emitted for the operation above.
int32_t v2 = ~v1;

bitwise_or()

Return op name emitc.bitwise_or as a bitstring.

bitwise_or(ssa)

emitc.bitwise_or - Bitwise or operation

Operands

  • lhs - Single, EmitCType, type supported by EmitC
  • rhs - Single, EmitCType, type supported by EmitC

Results

  • anonymous - Single, EmitCType, type supported by EmitC

Description

With the emitc.bitwise_or operation the bitwise operator | (or) can be applied.

Example:

%0 = emitc.bitwise_or %arg0, %arg1 : (i32, i32) -> i32
// Code emitted for the operation above.
int32_t v3 = v1 | v2;

bitwise_right_shift()

Return op name emitc.bitwise_right_shift as a bitstring.

bitwise_right_shift(ssa)

emitc.bitwise_right_shift - Bitwise right shift operation

Operands

  • lhs - Single, EmitCType, type supported by EmitC
  • rhs - Single, EmitCType, type supported by EmitC

Results

  • anonymous - Single, EmitCType, type supported by EmitC

Description

With the emitc.bitwise_right_shift operation the bitwise operator >> (right shift) can be applied.

Example:

%0 = emitc.bitwise_right_shift %arg0, %arg1 : (i32, i32) -> i32
// Code emitted for the operation above.
int32_t v3 = v1 >> v2;

bitwise_xor()

Return op name emitc.bitwise_xor as a bitstring.

bitwise_xor(ssa)

emitc.bitwise_xor - Bitwise xor operation

Operands

  • lhs - Single, EmitCType, type supported by EmitC
  • rhs - Single, EmitCType, type supported by EmitC

Results

  • anonymous - Single, EmitCType, type supported by EmitC

Description

With the emitc.bitwise_xor operation the bitwise operator ^ (xor) can be applied.

Example:

%0 = emitc.bitwise_xor %arg0, %arg1 : (i32, i32) -> i32
// Code emitted for the operation above.
int32_t v3 = v1 ^ v2;

call()

Return op name emitc.call as a bitstring.

call(ssa)

emitc.call - Call operation

Attributes

  • callee - Single, FlatSymbolRefAttr, flat symbol reference attribute
  • arg_attrs - Optional, DictArrayAttr, Array of dictionary attributes
  • res_attrs - Optional, DictArrayAttr, Array of dictionary attributes

Operands

  • operands - Variadic, EmitCType, variadic of type supported by EmitC

Results

  • anonymous - Variadic, EmitCType, variadic of type supported by EmitC

Description

The emitc.call operation represents a direct call to an emitc.func that is within the same symbol scope as the call. The operands and result type of the call must match the specified function type. The callee is encoded as a symbol reference attribute named "callee".

Example:

%2 = emitc.call @my_add(%0, %1) : (f32, f32) -> f32

call_opaque()

Return op name emitc.call_opaque as a bitstring.

call_opaque(ssa)

emitc.call_opaque - Opaque call operation

Attributes

  • callee - Single, StrAttr, string attribute
  • args - Optional, ArrayAttr, array attribute
  • template_args - Optional, ArrayAttr, array attribute

Operands

  • arg_operands - Variadic, anonymous/composite constraint, variadic of type supported by EmitC or EmitC lvalue type

Results

  • anonymous - Variadic, EmitCType, variadic of type supported by EmitC

Description

The emitc.call_opaque operation represents a C++ function call. The callee can be an arbitrary non-empty string. The call allows specifying order of operands and attributes in the call as follows:

  • integer value of index type refers to an operand;
  • attribute which will get lowered to constant value in call;

Example:

// Custom form defining a call to `foo()`.
%0 = emitc.call_opaque "foo" () : () -> i32

// Generic form of the same operation.
%0 = "emitc.call_opaque"() {callee = "foo"} : () -> i32

cast()

Return op name emitc.cast as a bitstring.

cast(ssa)

emitc.cast - Cast operation

Attributes

  • pure - Optional, UnitAttr, unit attribute

Operands

  • source - Single, EmitCType, type supported by EmitC

Results

  • dest - Single, EmitCType, type supported by EmitC

Description

The emitc.cast operation performs an explicit type conversion and is emitted as a C-style cast expression. It can be applied to integer, float, index and EmitC types.

Example:

// Cast from `int32_t` to `float`
%0 = emitc.cast %arg0: i32 to f32

// Cast from `void` to `int32_t` pointer
%1 = emitc.cast %arg1 :
    !emitc.ptr<!emitc.opaque<"void">> to !emitc.ptr<i32>

In general, C++ cast expressions cannot always be assumed to be pure: they may invoke user-defined conversions or be affected by floating-point environment settings. However, in many practical cases, such as integer casts without operator overloading, the cast is pure and can be treated as speculatable and side-effect-free. For such cases, the pure attribute may be used.

When pure attribute is set, getSpeculatability() returns Speculatable and getEffects() reports no effects. It is UB if the pure attribute is set and the actual conversion is not pure, e.g. when the user-defined conversion has memory effects.

class()

Return op name emitc.class as a bitstring.

class(ssa)

emitc.class - Represents a C++ class definition, encapsulating fields and methods.

Attributes

  • sym_name - Single, SymbolNameAttr, string attribute
  • final_specifier - Optional, UnitAttr, unit attribute
  • class_type - Single, EmitC_ClassTypeAttr, C++ aggregate type keyword

Description

The emitc.class operation defines a C++ class, acting as a container for its data fields (emitc.field) and methods (emitc.func). It creates a distinct scope, isolating its contents from the surrounding MLIR region, similar to how C++ classes encapsulate their internals.

Example:

emitc.class @modelClass {
  emitc.field @fieldName0 : !emitc.array<1xf32> = {emitc.opaque = "input_tensor"}
  emitc.func @execute() {
    %0 = "emitc.constant"() <{value = 0 : index}> : () -> !emitc.size_t
    %1 = get_field @fieldName0 : !emitc.array<1xf32>
    %2 = subscript %1[%0] : (!emitc.array<1xf32>, !emitc.size_t) -> !emitc.lvalue<f32>
    return
  }
}
// Class with a final specifer
emitc.class final @modelClass {
  emitc.field @fieldName0 : !emitc.array<1xf32> = {emitc.opaque = "input_tensor"}
  emitc.func @execute() {
    %0 = "emitc.constant"() <{value = 0 : index}> : () -> !emitc.size_t
    %1 = get_field @fieldName0 : !emitc.array<1xf32>
    %2 = subscript %1[%0] : (!emitc.array<1xf32>, !emitc.size_t) -> !emitc.lvalue<f32>
    return
  }
}

cmp()

Return op name emitc.cmp as a bitstring.

cmp(ssa)

emitc.cmp - Comparison operation

Attributes

  • predicate - Single, EmitC_CmpPredicateAttr, allowed 64-bit signless integer cases: 0, 1, 2, 3, 4, 5, 6

Operands

  • lhs - Single, EmitCType, type supported by EmitC
  • rhs - Single, EmitCType, type supported by EmitC

Results

  • anonymous - Single, EmitCType, type supported by EmitC

Description

With the emitc.cmp operation the comparison operators ==, !=, <, <=, >, >=, <=> can be applied.

Its first argument is an attribute that defines the comparison operator:

  • equal to (mnemonic: "eq"; integer value: 0)
  • not equal to (mnemonic: "ne"; integer value: 1)
  • less than (mnemonic: "lt"; integer value: 2)
  • less than or equal to (mnemonic: "le"; integer value: 3)
  • greater than (mnemonic: "gt"; integer value: 4)
  • greater than or equal to (mnemonic: "ge"; integer value: 5)
  • three-way-comparison (mnemonic: "three_way"; integer value: 6)

Example:

// Custom form of the cmp operation.
%0 = emitc.cmp eq, %arg0, %arg1 : (i32, i32) -> i1
%1 = emitc.cmp lt, %arg2, %arg3 :
    (
      !emitc.opaque<"std::valarray<float>">,
      !emitc.opaque<"std::valarray<float>">
    ) -> !emitc.opaque<"std::valarray<bool>">
// Code emitted for the operations above.
bool v5 = v1 == v2;
std::valarray<bool> v6 = v3 < v4;

conditional()

Return op name emitc.conditional as a bitstring.

conditional(ssa)

emitc.conditional - Conditional (ternary) operation

Operands

  • condition - Single, I1, 1-bit signless integer
  • true_value - Single, EmitCType, type supported by EmitC
  • false_value - Single, EmitCType, type supported by EmitC

Results

  • result - Single, EmitCType, type supported by EmitC

Description

With the emitc.conditional operation the ternary conditional operator can be applied.

Example:

%0 = emitc.cmp gt, %arg0, %arg1 : (i32, i32) -> i1

%c0 = "emitc.constant"() {value = 10 : i32} : () -> i32
%c1 = "emitc.constant"() {value = 11 : i32} : () -> i32

%1 = emitc.conditional %0, %c0, %c1 : i32
// Code emitted for the operations above.
bool v3 = v1 > v2;
int32_t v4 = 10;
int32_t v5 = 11;
int32_t v6 = v3 ? v4 : v5;

constant()

Return op name emitc.constant as a bitstring.

constant(ssa)

emitc.constant - Constant operation

Attributes

  • value - Single, EmitC_OpaqueOrTypedAttr, An opaque attribute or TypedAttr instance

Results

  • anonymous - Single, EmitCType, type supported by EmitC

Description

The emitc.constant operation produces an SSA value equal to some constant specified by an attribute. This can be used to form simple integer and floating point constants, as well as more exotic things like tensor constants. The emitc.constant operation also supports the EmitC opaque attribute and the EmitC opaque type. Since folding is supported, it should not be used with pointers.

Example:

// Integer constant
%0 = "emitc.constant"(){value = 42 : i32} : () -> i32

// Constant emitted as `char = CHAR_MIN;`
%1 = "emitc.constant"() {value = #emitc.opaque<"CHAR_MIN">}
  : () -> !emitc.opaque<"char">

declare_func()

Return op name emitc.declare_func as a bitstring.

declare_func(ssa)

emitc.declare_func - An operation to declare a function

Attributes

  • sym_name - Single, FlatSymbolRefAttr, flat symbol reference attribute

Description

The emitc.declare_func operation allows to insert a function declaration for an emitc.func at a specific position. The operation only requires the "callee" of the emitc.func to be specified as an attribute.

Example:

emitc.declare_func @bar
emitc.func @foo(%arg0: i32) -> i32 {
  %0 = emitc.call @bar(%arg0) : (i32) -> (i32)
  emitc.return %0 : i32
}

emitc.func @bar(%arg0: i32) -> i32 {
  emitc.return %arg0 : i32
}
// Code emitted for the operations above.
int32_t bar(int32_t v1);
int32_t foo(int32_t v1) {
  int32_t v2 = bar(v1);
  return v2;
}

int32_t bar(int32_t v1) {
  return v1;
}

dereference()

Return op name emitc.dereference as a bitstring.

dereference(ssa)

emitc.dereference - Dereference operation

Operands

  • pointer - Single, EmitC_PointerType, EmitC pointer type

Results

  • result - Single, EmitC_LValueType, EmitC lvalue type

Description

This operation models the C * (dereference) operator, which must be of !emitc.ptr<> type, returning an !emitc.lvalue<> the value pointed to by the pointer.

Example:

// Custom form of the dereference operator.
%0 = emitc.dereference %arg0 : (!emitc.ptr<i32>) -> !emitc.lvalue<i32>

div()

Return op name emitc.div as a bitstring.

div(ssa)

emitc.div - Division operation

Operands

  • anonymous - Single, FloatIntegerIndexOrOpaqueType, floating-point type supported by EmitC or integer, index or opaque type supported by EmitC
  • anonymous - Single, FloatIntegerIndexOrOpaqueType, floating-point type supported by EmitC or integer, index or opaque type supported by EmitC

Results

  • anonymous - Single, FloatIntegerIndexOrOpaqueType, floating-point type supported by EmitC or integer, index or opaque type supported by EmitC

Description

With the emitc.div operation the arithmetic operator / (division) can be applied.

Example:

// Custom form of the division operation.
%0 = emitc.div %arg0, %arg1 : (i32, i32) -> i32
%1 = emitc.div %arg2, %arg3 : (f32, f32) -> f32
// Code emitted for the operations above.
int32_t v5 = v1 / v2;
float v6 = v3 / v4;

div_assign()

Return op name emitc.div_assign as a bitstring.

div_assign(ssa)

emitc.div_assign - Division assignment operation

Operands

  • var - Single, EmitC_LValueType, EmitC lvalue type
  • value - Single, EmitCType, type supported by EmitC

Description

The emitc.div_assign operation applies the C/C++ /= operator to an lvalue.

Example:

emitc.div_assign %value : i32 to %var : !emitc.lvalue<i32>

do()

Return op name emitc.do as a bitstring.

do(ssa)

emitc.do - Do-while operation

Description

The emitc.do operation represents a C/C++ do-while loop construct that repeatedly executes a body region as long as a condition region evaluates to true. The operation has two regions:

  1. A body region that contains the loop body
  2. A condition region that must yield a boolean value (i1)

The condition is evaluated before each iteration as follows:

  • The condition region must contain exactly one block with:
    1. An emitc.expression operation producing an i1 value
    2. An emitc.yield passing through the expression result
  • The expression's body contains the actual condition logic

The body region is executed before the first evaluation of the condition. Thus, there is a guarantee that the loop will be executed at least once. The loop terminates when the condition yields false.

The canonical structure of emitc.do is:

emitc.do {
  // Body region (no terminator required).
  // Loop body operations...
} while {
  // Condition region (must yield i1)
  %condition = emitc.expression : () -> i1 {
    // Condition computation...
    %result = ... : i1  // Last operation must produce i1
    emitc.yield %result : i1
  }
  // Forward expression result
  emitc.yield %condition : i1
}

Example:

emitc.func @do_example() {
  %counter = "emitc.variable"() <{value = 0 : i32}> : () -> !emitc.lvalue<i32>
  %end = emitc.literal "10" : i32
  %step = emitc.literal "1" : i32

  emitc.do {
    // Print current value
    %val = emitc.load %counter : !emitc.lvalue<i32>
    emitc.verbatim "printf(\"%d\\n\", {});" args %val : i32

    // Increment counter
    %new_val = emitc.add %val, %step : (i32, i32) -> i32
    "emitc.assign"(%counter, %new_val) : (!emitc.lvalue<i32>, i32) -> ()
  } while {
    %condition = emitc.expression %counter, %end : (!emitc.lvalue<i32>, i32) -> i1 {
      %current = emitc.load %counter : !emitc.lvalue<i32>
      %cmp_res = emitc.cmp lt, %current, %end : (i32, i32) -> i1
      emitc.yield %cmp_res : i1
    }
    emitc.yield %condition : i1
  }
  return
}
// Code emitted for the operation above.
void do_example() {
  int32_t v1 = 0;
  do {
    int32_t v2 = v1;
    printf("%d\n", v2);
    int32_t v3 = v2 + 1;
    v1 = v3;
  } while (v1 < 10);
  return;
}

expression()

Return op name emitc.expression as a bitstring.

expression(ssa)

emitc.expression - Expression operation

Attributes

  • do_not_inline - Optional, UnitAttr, unit attribute

Operands

  • defs - Variadic, anonymous/composite constraint, variadic of type supported by EmitC or EmitC lvalue type

Results

  • result - Single, anonymous/composite constraint, type supported by EmitC or EmitC lvalue type

Description

The emitc.expression operation returns a single SSA value which is yielded by its single-basic-block region. The operation takes zero or more input operands that are passed as block arguments to the region.

As the operation is to be emitted as a C expression, the operations within its body must form a single Def-Use tree, or a DAG trivially expandable to one, i.e. a DAG where each operation with side effects is only reachable once from the expression root.

Input operands can be of both value types (EmitCType) and lvalue types (EmitC_LValueType).

Example:

%r = emitc.expression %a, %b, %c : (i32, i32, i32) -> i32 {
  %0 = emitc.call_opaque "foo"(%a) : (i32) -> i32
  %1 = emitc.add %b, %c : (i32, i32) -> i32
  %2 = emitc.mul %0, %1 : (i32, i32) -> i32
  emitc.yield %2 : i32
}

May be emitted as:

int32_t v4 = foo(v1) * (v2 + v3);

When specified, the optional noinline indicates that the expression is to be emitted as seen above, i.e. as the rhs of an EmitC SSA value definition. Otherwise, the expression may be emitted inline, i.e. directly at its use.

field()

Return op name emitc.field as a bitstring.

field(ssa)

emitc.field - A field within a class

Attributes

  • sym_name - Single, SymbolNameAttr, string attribute
  • type - Single, TypeAttr, any type attribute
  • initial_value - Optional, EmitC_OpaqueOrTypedAttr, An opaque attribute or TypedAttr instance

Description

The emitc.field operation declares a named field within an emitc.class operation. The field's type must be an EmitC type.

Example:

// Example with an attribute:
emitc.field @fieldName0 : !emitc.array<1xf32>  {emitc.opaque = "another_feature"}
// Example with no attribute:
emitc.field @fieldName0 : !emitc.array<1xf32>
// Example with an initial value:
emitc.field @fieldName0 : !emitc.array<1xf32> = dense<0.0>
// Example with an initial value and attributes:
emitc.field @fieldName0 : !emitc.array<1xf32> = dense<0.0> {
  emitc.opaque = "input_tensor"}

file()

Return op name emitc.file as a bitstring.

file(ssa)

emitc.file - A file container operation

Attributes

  • id - Single, Builtin_StringAttr, An Attribute containing a string

Description

A file represents a single C/C++ file.

mlir-translate ignores the body of all emitc.file ops unless the -file-id=id flag is used. With that flag, all emitc.file ops with matching id are emitted.

Example:

emitc.file "main" {
  emitc.func @func_one() {
    emitc.return
  }
}

for()

Return op name emitc.for as a bitstring.

for(ssa)

emitc.for - For operation

Operands

  • lowerBound - Single, IntegerIndexOrOpaqueType, integer, index or opaque type supported by EmitC
  • upperBound - Single, IntegerIndexOrOpaqueType, integer, index or opaque type supported by EmitC
  • step - Single, IntegerIndexOrOpaqueType, integer, index or opaque type supported by EmitC

Description

The emitc.for operation represents a C loop of the following form:

for (T i = lb; i < ub; i += step) { /* ... */ } // where T is typeof(lb)

The operation takes 3 SSA values as operands that represent the lower bound, upper bound and step respectively, and defines an SSA value for its induction variable. It has one region capturing the loop body. The induction variable is represented as an argument of this region. This SSA value is a signless integer, or an index. The step is a value of same type.

This operation has no result. The body region must contain exactly one block that terminates with emitc.yield. Calling ForOp::build will create such a region and insert the terminator implicitly if none is defined, so will the parsing even in cases when it is absent from the custom format. For example:

// Index case.
emitc.for %iv = %lb to %ub step %step {
  ... // body
}
...
// Integer case.
emitc.for %iv_32 = %lb_32 to %ub_32 step %step_32 : i32 {
  ... // body
}

func()

Return op name emitc.func as a bitstring.

func(ssa)

emitc.func - An operation with a name containing a single SSACFG region

Attributes

  • sym_name - Single, SymbolNameAttr, string attribute
  • function_type - Single, anonymous/composite constraint, type attribute of function type
  • specifiers - Optional, StrArrayAttr, string array attribute
  • arg_attrs - Optional, DictArrayAttr, Array of dictionary attributes
  • res_attrs - Optional, DictArrayAttr, Array of dictionary attributes

Description

Operations within the function cannot implicitly capture values defined outside of the function, i.e. Functions are IsolatedFromAbove. All external references must use function arguments or attributes that establish a symbolic connection (e.g. symbols referenced by name via a string attribute like SymbolRefAttr). While the MLIR textual form provides a nice inline syntax for function arguments, they are internally represented as “block arguments” to the first block in the region.

Only dialect attribute names may be specified in the attribute dictionaries for function arguments, results, or the function itself.

Example:

// A function with no results:
emitc.func @foo(%arg0 : i32) {
  emitc.call_opaque "bar" (%arg0) : (i32) -> ()
  emitc.return
}

// A function with its argument as single result:
emitc.func @foo(%arg0 : i32) -> i32 {
  emitc.return %arg0 : i32
}

// A function with specifiers attribute:
emitc.func @example_specifiers_fn_attr() -> i32
            attributes {specifiers = ["static","inline"]} {
  %0 = emitc.call_opaque "foo" (): () -> i32
  emitc.return %0 : i32
}

// An external function definition:
emitc.func private @extern_func(i32)
                    attributes {specifiers = ["extern"]}

get_field()

Return op name emitc.get_field as a bitstring.

get_field(ssa)

emitc.get_field - Obtain access to a field within a class instance

Attributes

  • field_name - Single, FlatSymbolRefAttr, flat symbol reference attribute

Results

  • result - Single, EmitCType, type supported by EmitC

Description

The emitc.get_field operation retrieves the lvalue of a named field from a given class instance.

Example:

%0 = get_field @fieldName0 : !emitc.array<1xf32>

get_global()

Return op name emitc.get_global as a bitstring.

get_global(ssa)

emitc.get_global - Obtain access to a global variable

Attributes

  • name - Single, FlatSymbolRefAttr, flat symbol reference attribute

Results

  • result - Single, anonymous/composite constraint, EmitC array type or EmitC lvalue type

Description

The emitc.get_global operation retrieves the lvalue of a named global variable. If the global variable is marked constant, assigning to that lvalue is undefined.

Example:

%x = emitc.get_global @foo : !emitc.array<2xf32>
%y = emitc.get_global @bar : !emitc.lvalue<i32>

global()

Return op name emitc.global as a bitstring.

global(ssa)

emitc.global - A global variable

Attributes

  • sym_name - Single, SymbolNameAttr, string attribute
  • type - Single, TypeAttr, any type attribute
  • initial_value - Optional, EmitC_OpaqueOrTypedAttr, An opaque attribute or TypedAttr instance
  • extern_specifier - Optional, UnitAttr, unit attribute
  • static_specifier - Optional, UnitAttr, unit attribute
  • const_specifier - Optional, UnitAttr, unit attribute

Description

The emitc.global operation declares or defines a named global variable. The backing memory for the variable is allocated statically and described by the variable's type, which must be an EmitC type. Optionally, an initial_value can be provided. Internal linkage can be specified using the static_specifier unit attribute and external linkage can be specified using the extern_specifier unit attribute. Note that the default linkage without those two keywords depends on whether the target is C or C++ and whether the global variable is const. The global variable can also be marked constant using the const_specifier unit attribute. Writing to such constant global variables is undefined.

The global variable can be accessed by using the emitc.get_global to retrieve the value for the global variable.

Example:

// Global variable with an initial value.
emitc.global @x : !emitc.array<2xf32> = dense<0.0>
// Global variable with an initial values.
emitc.global @x : !emitc.array<3xi32> = dense<[0, 1, 2]>
// Global variable with an opaque initial value.
emitc.global @x : !emitc.opaque<"char"> = #emitc.opaque<"CHAR_MIN">
// External global variable
emitc.global extern @x : !emitc.array<2xf32>
// Constant global variable with internal linkage
emitc.global static const @x : i32 = 0

if()

Return op name emitc.if as a bitstring.

if(ssa)

emitc.if - If-then-else operation

Operands

  • condition - Single, I1, 1-bit signless integer

Description

The emitc.if operation represents an if-then-else construct for conditionally executing two regions of code. The operand to an if operation is a boolean value. For example:

emitc.if %b  {
  ...
} else {
  ...
}

The "then" region has exactly 1 block. The "else" region may have 0 or 1 blocks. The blocks are always terminated with emitc.yield, which can be left out to be inserted implicitly. This operation doesn't produce any results.

include()

Return op name emitc.include as a bitstring.

include(ssa)

emitc.include - Include operation

Attributes

  • include - Single, StrAttr, string attribute
  • is_standard_include - Optional, UnitAttr, unit attribute

Description

The emitc.include operation allows to define a source file inclusion via the #include directive.

Example:

// Custom form defining the inclusion of `<myheader>`.
emitc.include <"myheader.h">

// Generic form of the same operation.
"emitc.include" (){include = "myheader.h", is_standard_include} : () -> ()

// Custom form defining the inclusion of `"myheader"`.
emitc.include "myheader.h"

// Generic form of the same operation.
"emitc.include" (){include = "myheader.h"} : () -> ()

literal()

Return op name emitc.literal as a bitstring.

literal(ssa)

emitc.literal - Literal operation

Attributes

  • value - Single, StrAttr, string attribute

Results

  • result - Single, EmitCType, type supported by EmitC

Description

The emitc.literal operation produces an SSA value equal to some constant specified by an attribute.

Example:

%p0 = emitc.literal "M_PI" : f32
%1 = "emitc.add" (%arg0, %p0) : (f32, f32) -> f32
// Code emitted for the operation above.
float v2 = v1 + M_PI;

load()

Return op name emitc.load as a bitstring.

load(ssa)

emitc.load - Load an lvalue into an SSA value.

Operands

  • operand - Single, EmitC_LValueType, EmitC lvalue type

Results

  • result - Single, AnyType, any non-token type

Description

This operation loads the content of a modifiable lvalue into an SSA value. Modifications of the lvalue executed after the load are not observable on the produced value.

Example:

%1 = emitc.load %0 : !emitc.lvalue<i32>
// Code emitted for the operation above.
int32_t v2 = v1;

logical_and()

Return op name emitc.logical_and as a bitstring.

logical_and(ssa)

emitc.logical_and - Logical and operation

Operands

  • lhs - Single, EmitCType, type supported by EmitC
  • rhs - Single, EmitCType, type supported by EmitC

Results

  • anonymous - Single, I1, 1-bit signless integer

Description

With the emitc.logical_and operation the logical operator && (and) can be applied.

Example:

%0 = emitc.logical_and %arg0, %arg1 : i32, i32
// Code emitted for the operation above.
bool v3 = v1 && v2;

logical_not()

Return op name emitc.logical_not as a bitstring.

logical_not(ssa)

emitc.logical_not - Logical not operation

Operands

  • anonymous - Single, EmitCType, type supported by EmitC

Results

  • anonymous - Single, I1, 1-bit signless integer

Description

With the emitc.logical_not operation the logical operator ! (negation) can be applied.

Example:

%0 = emitc.logical_not %arg0 : i32
// Code emitted for the operation above.
bool v2 = !v1;

logical_or()

Return op name emitc.logical_or as a bitstring.

logical_or(ssa)

emitc.logical_or - Logical or operation

Operands

  • lhs - Single, EmitCType, type supported by EmitC
  • rhs - Single, EmitCType, type supported by EmitC

Results

  • anonymous - Single, I1, 1-bit signless integer

Description

With the emitc.logical_or operation the logical operator || (inclusive or) can be applied.

Example:

%0 = emitc.logical_or %arg0, %arg1 : i32, i32
// Code emitted for the operation above.
bool v3 = v1 || v2;

member()

Return op name emitc.member as a bitstring.

member(ssa)

emitc.member - Member operation

Attributes

  • member - Single, StrAttr, string attribute

Operands

  • operand - Single, anonymous/composite constraint, EmitC opaque type or emitc.lvalue of EmitC opaque type values

Results

  • anonymous - Single, anonymous/composite constraint, type supported by EmitC or EmitC lvalue type

Description

With the emitc.member operation the member access operator . can be applied.

Example:

%0 = "emitc.member" (%arg0) {member = "a"}
    : (!emitc.opaque<"mystruct">) -> i32
%0 = "emitc.member" (%arg0) {member = "a"}
    : (!emitc.lvalue<!emitc.opaque<"mystruct">>) -> !emitc.lvalue<i32>
%1 = "emitc.member" (%arg0) {member = "b"}
    : (!emitc.lvalue<!emitc.opaque<"mystruct">>) -> !emitc.array<2xi32>

member_call_opaque()

Return op name emitc.member_call_opaque as a bitstring.

member_call_opaque(ssa)

emitc.member_call_opaque - Opaque member call operation

Attributes

  • callee - Single, StrAttr, string attribute
  • args - Optional, ArrayAttr, array attribute
  • template_args - Optional, ArrayAttr, array attribute

Operands

  • receiver - Single, EmitCType, type supported by EmitC
  • arg_operands - Variadic, anonymous/composite constraint, variadic of type supported by EmitC or EmitC lvalue type

Results

  • anonymous - Variadic, EmitCType, variadic of type supported by EmitC

Description

The emitc.member_call_opaque operation represents a C++ member function call. It takes a receiver operand, a callee string attribute (the method name), and variadic operands for arguments.

The call allows specifying order of operands and attributes in the call as follows:

  • integer value of index type refers to an argument operand;
  • attribute which will get lowered to constant value in call;

Example:

%0 = emitc.member_call_opaque %receiver "method" (%arg0, %arg1) : !emitc.opaque<"MyClass">, (i32, i32) -> i32

member_of_ptr()

Return op name emitc.member_of_ptr as a bitstring.

member_of_ptr(ssa)

emitc.member_of_ptr - Member of pointer operation

Attributes

  • member - Single, StrAttr, string attribute

Operands

  • operand - Single, anonymous/composite constraint, emitc.lvalue of EmitC opaque type or EmitC pointer type values

Results

  • anonymous - Single, anonymous/composite constraint, EmitC array type or EmitC lvalue type

Description

With the emitc.member_of_ptr operation the member access operator -> can be applied.

Example:

%0 = "emitc.member_of_ptr" (%arg0) {member = "a"}
    : (!emitc.lvalue<!emitc.ptr<!emitc.opaque<"mystruct">>>)
    -> !emitc.lvalue<i32>
%1 = "emitc.member_of_ptr" (%arg0) {member = "b"}
    : (!emitc.lvalue<!emitc.ptr<!emitc.opaque<"mystruct">>>)
    -> !emitc.array<2xi32>

mul()

Return op name emitc.mul as a bitstring.

mul(ssa)

emitc.mul - Multiplication operation

Operands

  • anonymous - Single, FloatIntegerIndexOrOpaqueType, floating-point type supported by EmitC or integer, index or opaque type supported by EmitC
  • anonymous - Single, FloatIntegerIndexOrOpaqueType, floating-point type supported by EmitC or integer, index or opaque type supported by EmitC

Results

  • anonymous - Single, FloatIntegerIndexOrOpaqueType, floating-point type supported by EmitC or integer, index or opaque type supported by EmitC

Description

With the emitc.mul operation the arithmetic operator * (multiplication) can be applied.

Example:

// Custom form of the multiplication operation.
%0 = emitc.mul %arg0, %arg1 : (i32, i32) -> i32
%1 = emitc.mul %arg2, %arg3 : (f32, f32) -> f32
// Code emitted for the operations above.
int32_t v5 = v1 * v2;
float v6 = v3 * v4;

mul_assign()

Return op name emitc.mul_assign as a bitstring.

mul_assign(ssa)

emitc.mul_assign - Multiplication assignment operation

Operands

  • var - Single, EmitC_LValueType, EmitC lvalue type
  • value - Single, EmitCType, type supported by EmitC

Description

The emitc.mul_assign operation applies the C/C++ *= operator to an lvalue.

Example:

emitc.mul_assign %value : i32 to %var : !emitc.lvalue<i32>

post_decrement()

Return op name emitc.post_decrement as a bitstring.

post_decrement(ssa)

emitc.post_decrement - Post-decrement operation

Operands

  • operand - Single, EmitC_LValueType, EmitC lvalue type

Results

  • result - Single, EmitCType, type supported by EmitC

Description

This operation models the C/C++ post-decrement operator on an lvalue.

Example:

%0 = emitc.post_decrement %arg0 : !emitc.lvalue<i32>

post_increment()

Return op name emitc.post_increment as a bitstring.

post_increment(ssa)

emitc.post_increment - Post-increment operation

Operands

  • operand - Single, EmitC_LValueType, EmitC lvalue type

Results

  • result - Single, EmitCType, type supported by EmitC

Description

This operation models the C/C++ post-increment operator on an lvalue.

Example:

%0 = emitc.post_increment %arg0 : !emitc.lvalue<i32>

pre_decrement()

Return op name emitc.pre_decrement as a bitstring.

pre_decrement(ssa)

emitc.pre_decrement - Pre-decrement operation

Operands

  • operand - Single, EmitC_LValueType, EmitC lvalue type

Results

  • result - Single, EmitCType, type supported by EmitC

Description

This operation models the C/C++ pre-decrement operator on an lvalue.

Example:

%0 = emitc.pre_decrement %arg0 : !emitc.lvalue<i32>

pre_increment()

Return op name emitc.pre_increment as a bitstring.

pre_increment(ssa)

emitc.pre_increment - Pre-increment operation

Operands

  • operand - Single, EmitC_LValueType, EmitC lvalue type

Results

  • result - Single, EmitCType, type supported by EmitC

Description

This operation models the C/C++ pre-increment operator on an lvalue.

Example:

%0 = emitc.pre_increment %arg0 : !emitc.lvalue<i32>

rem()

Return op name emitc.rem as a bitstring.

rem(ssa)

emitc.rem - Remainder operation

Operands

  • anonymous - Single, IntegerIndexOrOpaqueType, integer, index or opaque type supported by EmitC
  • anonymous - Single, IntegerIndexOrOpaqueType, integer, index or opaque type supported by EmitC

Results

  • anonymous - Single, IntegerIndexOrOpaqueType, integer, index or opaque type supported by EmitC

Description

With the emitc.rem operation the arithmetic operator % (remainder) can be applied.

Example:

// Custom form of the remainder operation.
%0 = emitc.rem %arg0, %arg1 : (i32, i32) -> i32
// Code emitted for the operation above.
int32_t v5 = v1 % v2;

rem_assign()

Return op name emitc.rem_assign as a bitstring.

rem_assign(ssa)

emitc.rem_assign - Remainder assignment operation

Operands

  • var - Single, EmitC_LValueType, EmitC lvalue type
  • value - Single, EmitCType, type supported by EmitC

Description

The emitc.rem_assign operation applies the C/C++ %= operator to an lvalue.

Example:

emitc.rem_assign %value : i32 to %var : !emitc.lvalue<i32>

return()

Return op name emitc.return as a bitstring.

return(ssa)

emitc.return - Function return operation

Operands

  • operand - Optional, EmitCType, type supported by EmitC

Description

The emitc.return operation represents a return operation within a function. The operation takes zero or exactly one operand and produces no results. The operand number and type must match the signature of the function that contains the operation.

Example:

emitc.func @foo() -> (i32) {
  ...
  emitc.return %0 : i32
}

sub()

Return op name emitc.sub as a bitstring.

sub(ssa)

emitc.sub - Subtraction operation

Operands

  • lhs - Single, EmitCType, type supported by EmitC
  • rhs - Single, EmitCType, type supported by EmitC

Results

  • anonymous - Single, EmitCType, type supported by EmitC

Description

With the emitc.sub operation the arithmetic operator - (subtraction) can be applied.

Example:

// Custom form of the substraction operation.
%0 = emitc.sub %arg0, %arg1 : (i32, i32) -> i32
%1 = emitc.sub %arg2, %arg3 : (!emitc.ptr<f32>, i32) -> !emitc.ptr<f32>
%2 = emitc.sub %arg4, %arg5 : (!emitc.ptr<i32>, !emitc.ptr<i32>)
    -> !emitc.ptrdiff_t
// Code emitted for the operations above.
int32_t v7 = v1 - v2;
float* v8 = v3 - v4;
ptrdiff_t v9 = v5 - v6;

sub_assign()

Return op name emitc.sub_assign as a bitstring.

sub_assign(ssa)

emitc.sub_assign - Subtraction assignment operation

Operands

  • var - Single, EmitC_LValueType, EmitC lvalue type
  • value - Single, EmitCType, type supported by EmitC

Description

The emitc.sub_assign operation applies the C/C++ -= operator to an lvalue.

Example:

emitc.sub_assign %value : i32 to %var : !emitc.lvalue<i32>

subscript()

Return op name emitc.subscript as a bitstring.

subscript(ssa)

emitc.subscript - Subscript operation

Operands

  • value - Single, anonymous/composite constraint, EmitC array type or EmitC opaque type or EmitC pointer type
  • indices - Variadic, EmitCType, variadic of type supported by EmitC

Results

  • result - Single, EmitC_LValueType, EmitC lvalue type

Description

With the emitc.subscript operation the subscript operator [] can be applied to variables or arguments of array, pointer and opaque type.

Example:

%i = index.constant 1
%j = index.constant 7
%0 = emitc.subscript %arg0[%i, %j] : (!emitc.array<4x8xf32>, index, index)
       -> !emitc.lvalue<f32>
%1 = emitc.subscript %arg1[%i] : (!emitc.ptr<i32>, index)
       -> !emitc.lvalue<i32>

switch()

Return op name emitc.switch as a bitstring.

switch(ssa)

emitc.switch - Switch operation

Attributes

  • cases - Single, DenseI64ArrayAttr, i64 dense array attribute

Operands

  • arg - Single, IntegerIndexOrOpaqueType, integer, index or opaque type supported by EmitC

Description

The emitc.switch is a control-flow operation that branches to one of the given regions based on the values of the argument and the cases. The operand to a switch operation is a opaque, integral or pointer wide types.

The operation always has a "default" region and any number of case regions denoted by integer constants. Control-flow transfers to the case region whose constant value equals the value of the argument. If the argument does not equal any of the case values, control-flow transfer to the "default" region.

The operation does not return any value. Moreover, case regions must be explicitly terminated using the emitc.yield operation. Default region is yielded implicitly.

Example:

// Example:
emitc.switch %0 : i32
case 2 {
  %1 = emitc.call_opaque "func_b" () : () -> i32
  emitc.yield
}
case 5 {
  %2 = emitc.call_opaque "func_a" () : () -> i32
  emitc.yield
}
default {
  %3 = "emitc.constant"(){value = 42.0 : f32} : () -> f32
  emitc.call_opaque "func2" (%3) : (f32) -> ()
}
// Code emitted for the operations above.
switch (v1) {
case 2: {
  int32_t v2 = func_b();
  break;
}
case 5: {
  int32_t v3 = func_a();
  break;
}
default: {
  float v4 = 4.200000000e+01f;
  func2(v4);
  break;
}
}

unary_minus()

Return op name emitc.unary_minus as a bitstring.

unary_minus(ssa)

emitc.unary_minus - Unary minus operation

Operands

  • anonymous - Single, EmitCType, type supported by EmitC

Results

  • anonymous - Single, EmitCType, type supported by EmitC

Description

With the emitc.unary_minus operation the unary operator - (minus) can be applied.

Example:

%0 = emitc.unary_minus %arg0 : (i32) -> i32
// Code emitted for the operation above.
int32_t v2 = -v1;

unary_plus()

Return op name emitc.unary_plus as a bitstring.

unary_plus(ssa)

emitc.unary_plus - Unary plus operation

Operands

  • anonymous - Single, EmitCType, type supported by EmitC

Results

  • anonymous - Single, EmitCType, type supported by EmitC

Description

With the emitc.unary_plus operation the unary operator + (plus) can be applied.

Example:

%0 = emitc.unary_plus %arg0 : (i32) -> i32
// Code emitted for the operation above.
int32_t v2 = +v1;

variable()

Return op name emitc.variable as a bitstring.

variable(ssa)

emitc.variable - Variable operation

Attributes

  • value - Single, EmitC_OpaqueOrTypedAttr, An opaque attribute or TypedAttr instance

Results

  • anonymous - Single, anonymous/composite constraint, EmitC array type or EmitC lvalue type

Description

The emitc.variable operation produces an SSA value equal to some value specified by an attribute. This can be used to form simple integer and floating point variables, as well as more exotic things like tensor variables. The emitc.variable operation also supports the EmitC opaque attribute and the EmitC opaque type. If further supports the EmitC pointer type, whereas folding is not supported. The emitc.variable is emitted as a C/C++ local variable.

Example:

// Integer variable
%0 = "emitc.variable"(){value = 42 : i32} : () -> !emitc.lvalue<i32>

// Variable emitted as `int32_t* = NULL;`
%1 = "emitc.variable"() {value = #emitc.opaque<"NULL">}
  : () -> !emitc.lvalue<!emitc.ptr<!emitc.opaque<"int32_t">>>

Since folding is not supported, it can be used with pointers. As an example, it is valid to create pointers to variable operations by using address_of operations and pass these to a call operation.

%0 = "emitc.variable"() {value = 0 : i32} : () -> !emitc.lvalue<i32>
%1 = "emitc.variable"() {value = 0 : i32} : () -> !emitc.lvalue<i32>
%2 = emitc.address_of %0 : !emitc.lvalue<i32>
%3 = emitc.address_of %1 : !emitc.lvalue<i32>
emitc.call_opaque "write"(%2, %3)
  : (!emitc.ptr<i32>, !emitc.ptr<i32>) -> ()

verbatim()

Return op name emitc.verbatim as a bitstring.

verbatim(ssa)

emitc.verbatim - Verbatim operation

Attributes

  • value - Single, StrAttr, string attribute

Operands

  • fmtArgs - Variadic, anonymous/composite constraint, variadic of type supported by EmitC or EmitC lvalue type

Description

The emitc.verbatim operation produces no results and the value is emitted as is followed by a line break ('\n' character) during translation.

Note: Use with caution. This operation can have arbitrary effects on the semantics of the emitted code. Use semantically more meaningful operations whenever possible. Additionally this op is NOT intended to be used to inject large snippets of code.

This operation can be used in situations where a more suitable operation is not yet implemented in the dialect or where preprocessor directives interfere with the structure of the code. One example of this is to declare the linkage of external symbols to make the generated code usable in both C and C++ contexts:

#ifdef __cplusplus
extern "C" {
#endif

...

#ifdef __cplusplus
}
#endif

If the emitc.verbatim op has operands, then the value is interpreted as format string, where {} is a placeholder for an operand in their order. For example, emitc.verbatim "#pragma my src={} dst={}" %src, %dest : i32, i32 would be emitted as #pragma my src=a dst=b if %src became a and %dest became b in the C code. {{ in the format string is interpreted as a single { and doesn't introduce a placeholder.

Example:

emitc.verbatim "typedef float f32;"
emitc.verbatim "#pragma my var={} property" args %arg : f32
// Code emitted for the operation above.
typedef float f32;
#pragma my var=v1 property

yield()

Return op name emitc.yield as a bitstring.

yield(ssa)

emitc.yield - Block termination operation

Operands

  • result - Optional, anonymous/composite constraint, type supported by EmitC or EmitC lvalue type

Description

The emitc.yield terminates its parent EmitC op's region, optionally yielding an SSA value. The semantics of how the values are yielded is defined by the parent operation. If emitc.yield has an operand, the operand must match the parent operation's result. If the parent operation defines no values, then the emitc.yield may be left out in the custom syntax and the builders will insert one implicitly. Otherwise, it has to be present in the syntax to indicate which value is yielded.