@@ -1587,29 +1587,21 @@ def EmitC_ClassOp
15871587
15881588 Example:
15891589 ```mlir
1590- emitc.class @mainClass {
1591- emitc.field @another_feature : !emitc.array<1xf32> = {emitc.opaque = ["another_feature"]}
1592- emitc.field @some_feature : !emitc.array<1xf32> = {emitc.opaque = ["some_feature"]}
1593- emitc.field @output_0 : !emitc.array<1xf32> = {emitc.opaque = ["output_0"]}
1594-
1590+ emitc.func @model(%input_data : !emitc.array<1xf32> {emitc.opaque = ["input_tensor"]}) attributes { } {
1591+ %0 = "emitc.constant"() <{value = 0 : index}> : () -> !emitc.size_t
1592+ %1 = subscript %input_data[%0] : (!emitc.array<1xf32>, !emitc.size_t) -> !emitc.lvalue<f32>
1593+ return
1594+ }
1595+ // becomes
1596+ emitc.class @modelClass {
1597+ emitc.field @input_tensor : !emitc.array<1xf32> = {emitc.opaque = ["input_tensor"]}
15951598 emitc.func @execute() {
15961599 %0 = "emitc.constant"() <{value = 0 : index}> : () -> !emitc.size_t
1597-
1598- %1 = get_field @another_feature : !emitc.array<1xf32>
1599- %2 = get_field @some_feature : !emitc.array<1xf32>
1600- %3 = get_field @output_0 : !emitc.array<1xf32>
1601-
1602- %4 = subscript %2[%0] : (!emitc.array<1xf32>, !emitc.size_t) -> !emitc.lvalue<f32>
1603- %5 = load %4 : <f32>
1604- %6 = subscript %1[%0] : (!emitc.array<1xf32>, !emitc.size_t) -> !emitc.lvalue<f32>
1605- %7 = load %6 : <f32>
1606- %8 = add %5, %7 : (f32, f32) -> f32
1607- %9 = subscript %3[%0] : (!emitc.array<1xf32>, !emitc.size_t) -> !emitc.lvalue<f32>
1608- assign %8 : f32 to %9 : <f32>
1600+ %1 = get_field @input_tensor : !emitc.array<1xf32>
1601+ %2 = subscript %1[%0] : (!emitc.array<1xf32>, !emitc.size_t) -> !emitc.lvalue<f32>
16091602 return
16101603 }
1611- }
1612-
1604+ }
16131605 ```
16141606 }];
16151607
@@ -1633,23 +1625,22 @@ def EmitC_FieldOp : EmitC_Op<"field", [Symbol]> {
16331625 let summary = "A field within a class";
16341626 let description = [{
16351627 The `emitc.field` operation declares a named field within an `emitc.class`
1636- operation. The field's type must be an EmitC type. The initial value is optional.
1637- If the argument has attributes, these become the initial value, else we end up with no initial value.
1638-
1639- Example with initial values:
1628+ operation. The field's type must be an EmitC type.
1629+ If the corresponding function argument has attributes (accessed via `argAttrs`),
1630+ these attributes are attached to the field operation.
1631+ Otherwise, the field is created without additional attributes.
16401632
1633+ Example of func argument with attributes:
16411634 ```mlir
1642- emitc.class @modelClass {
1643- emitc.field @another_feature : !emitc.array<1xf32> = {emitc.opaque = ["another_feature"]}
1644- emitc.field @some_feature : !emitc.array<1xf32> = {emitc.opaque = ["some_feature"]}
1645- emitc.field @output_0 : !emitc.array<1xf32> = {emitc.opaque = ["output_0"]}
1646- }
1635+ %arg0: !emitc.array<1xf32> {emitc.opaque = ["another_feature"]}
1636+ // becomes
1637+ emitc.field @another_feature : !emitc.array<1xf32> = {emitc.opaque = ["another_feature"]}
16471638 ```
1648- Example with no initial value :
1639+ Example of func argument without attributes :
16491640 ```mlir
1650- emitc.class @modelClass {
1651- emitc.field @another_feature : !emitc.array<1xf32>
1652- }
1641+ %arg0 : ! emitc.array<1xf32>
1642+ // becomes
1643+ emitc.field @fieldName0 : !emitc.array<1xf32>
16531644 ```
16541645 }];
16551646
@@ -1673,9 +1664,7 @@ def EmitC_GetFieldOp
16731664 Example:
16741665
16751666 ```mlir
1676- %some_ptr = emitc.get_field @some_feature : !emitc.array<1xf32>
1677- %another_ptr = emitc.get_field @another_feature : !emitc.array<1xf32>
1678- %output_ptr = emitc.get_field @output_0 : !emitc.array<1xf32>
1667+ %0 = get_field @fieldName0 : !emitc.array<1xf32>
16791668 ```
16801669 }];
16811670
0 commit comments