@@ -1608,29 +1608,21 @@ def EmitC_ClassOp
1608
1608
1609
1609
Example:
1610
1610
```mlir
1611
- emitc.class @mainClass {
1612
- emitc.field @another_feature : !emitc.array<1xf32> = {emitc.opaque = ["another_feature"]}
1613
- emitc.field @some_feature : !emitc.array<1xf32> = {emitc.opaque = ["some_feature"]}
1614
- emitc.field @output_0 : !emitc.array<1xf32> = {emitc.opaque = ["output_0"]}
1615
-
1611
+ emitc.func @model(%input_data : !emitc.array<1xf32> {emitc.opaque = ["input_tensor"]}) attributes { } {
1612
+ %0 = "emitc.constant"() <{value = 0 : index}> : () -> !emitc.size_t
1613
+ %1 = subscript %input_data[%0] : (!emitc.array<1xf32>, !emitc.size_t) -> !emitc.lvalue<f32>
1614
+ return
1615
+ }
1616
+ // becomes
1617
+ emitc.class @modelClass {
1618
+ emitc.field @input_tensor : !emitc.array<1xf32> = {emitc.opaque = ["input_tensor"]}
1616
1619
emitc.func @execute() {
1617
1620
%0 = "emitc.constant"() <{value = 0 : index}> : () -> !emitc.size_t
1618
-
1619
- %1 = get_field @another_feature : !emitc.array<1xf32>
1620
- %2 = get_field @some_feature : !emitc.array<1xf32>
1621
- %3 = get_field @output_0 : !emitc.array<1xf32>
1622
-
1623
- %4 = subscript %2[%0] : (!emitc.array<1xf32>, !emitc.size_t) -> !emitc.lvalue<f32>
1624
- %5 = load %4 : <f32>
1625
- %6 = subscript %1[%0] : (!emitc.array<1xf32>, !emitc.size_t) -> !emitc.lvalue<f32>
1626
- %7 = load %6 : <f32>
1627
- %8 = add %5, %7 : (f32, f32) -> f32
1628
- %9 = subscript %3[%0] : (!emitc.array<1xf32>, !emitc.size_t) -> !emitc.lvalue<f32>
1629
- assign %8 : f32 to %9 : <f32>
1621
+ %1 = get_field @input_tensor : !emitc.array<1xf32>
1622
+ %2 = subscript %1[%0] : (!emitc.array<1xf32>, !emitc.size_t) -> !emitc.lvalue<f32>
1630
1623
return
1631
1624
}
1632
- }
1633
-
1625
+ }
1634
1626
```
1635
1627
}];
1636
1628
@@ -1654,23 +1646,22 @@ def EmitC_FieldOp : EmitC_Op<"field", [Symbol]> {
1654
1646
let summary = "A field within a class";
1655
1647
let description = [{
1656
1648
The `emitc.field` operation declares a named field within an `emitc.class`
1657
- operation. The field's type must be an EmitC type. The initial value is optional.
1658
- If the argument has attributes, these become the initial value, else we end up with no initial value.
1659
-
1660
- Example with initial values:
1649
+ operation. The field's type must be an EmitC type.
1650
+ If the corresponding function argument has attributes (accessed via `argAttrs`),
1651
+ these attributes are attached to the field operation.
1652
+ Otherwise, the field is created without additional attributes.
1661
1653
1654
+ Example of func argument with attributes:
1662
1655
```mlir
1663
- emitc.class @modelClass {
1664
- emitc.field @another_feature : !emitc.array<1xf32> = {emitc.opaque = ["another_feature"]}
1665
- emitc.field @some_feature : !emitc.array<1xf32> = {emitc.opaque = ["some_feature"]}
1666
- emitc.field @output_0 : !emitc.array<1xf32> = {emitc.opaque = ["output_0"]}
1667
- }
1656
+ %arg0: !emitc.array<1xf32> {emitc.opaque = ["another_feature"]}
1657
+ // becomes
1658
+ emitc.field @another_feature : !emitc.array<1xf32> = {emitc.opaque = ["another_feature"]}
1668
1659
```
1669
- Example with no initial value :
1660
+ Example of func argument without attributes :
1670
1661
```mlir
1671
- emitc.class @modelClass {
1672
- emitc.field @another_feature : !emitc.array<1xf32>
1673
- }
1662
+ %arg0 : ! emitc.array<1xf32>
1663
+ // becomes
1664
+ emitc.field @fieldName0 : !emitc.array<1xf32>
1674
1665
```
1675
1666
}];
1676
1667
@@ -1694,9 +1685,7 @@ def EmitC_GetFieldOp
1694
1685
Example:
1695
1686
1696
1687
```mlir
1697
- %some_ptr = emitc.get_field @some_feature : !emitc.array<1xf32>
1698
- %another_ptr = emitc.get_field @another_feature : !emitc.array<1xf32>
1699
- %output_ptr = emitc.get_field @output_0 : !emitc.array<1xf32>
1688
+ %0 = get_field @fieldName0 : !emitc.array<1xf32>
1700
1689
```
1701
1690
}];
1702
1691
0 commit comments