@@ -1572,46 +1572,45 @@ def EmitC_SwitchOp : EmitC_Op<"switch", [RecursiveMemoryEffects,
15721572 let hasVerifier = 1;
15731573}
15741574
1575- def EmitC_ClassOp : EmitC_Op<"class", [AutomaticAllocationScope,
1576- IsolatedFromAbove, OpAsmOpInterface]> {
1575+ def EmitC_ClassOp
1576+ : EmitC_Op<"class", [AutomaticAllocationScope, IsolatedFromAbove,
1577+ OpAsmOpInterface, SymbolTable,
1578+ Symbol]#GraphRegionNoTerminator.traits> {
15771579 let summary =
15781580 "Represents a C++ class definition, encapsulating fields and methods.";
15791581
1582+ // FIX WORDING
15801583 let description = [{
15811584 The `emitc.class` operation defines a C++ class, acting as a container
15821585 for its data fields (`emitc.variable`) and methods (`emitc.func`).
15831586 It creates a distinct scope, isolating its contents from the surrounding
15841587 MLIR region, similar to how C++ classes encapsulate their internals.
1588+ All the class memebrs need to be default initalizable.
15851589
15861590 Example:
15871591 ```mlir
1588- emitc.class @MyModelClass {
1589- emitc.field @another_feature : !emitc.lvalue<!emitc.ptr<f32>>
1590- emitc.field @some_feature : !emitc.lvalue<!emitc.ptr<f32>>
1591- emitc.field @output_0 : !emitc.lvalue<!emitc.ptr<f32>>
1592-
1593- emitc.func @main() attributes {tf.entry_function = {inputs = "serving_default_another_feature:0,serving_default_some_feature:0", outputs = "PartitionedCall:0"}, tf_saved_model.exported_names = ["serving_default"]} {
1594- %c0 = "emitc.constant"() <{value = 0 : index}> : () -> !emitc.size_t
1595-
1596- %some_ptr = emitc.get_field %self : @MyModelClass, @some_feature -> !emitc.ptr<f32>
1597- %another_ptr = emitc.get_field %self : @MyModelClass, @another_feature -> !emitc.ptr<f32>
1598- %output_ptr = emitc.get_field %self : @MyModelClass, @output_0 -> !emitc.ptr<f32>
1599-
1600- %v1 = subscript %some_ptr[%c0] : (!emitc.ptr<f32>, !emitc.size_t) -> !emitc.lvalue<f32>
1601- %v1_val = load %v1 : !emitc.lvalue<f32> -> f32
1602-
1603- %v2 = subscript %another_ptr[%c0] : (!emitc.ptr<f32>, !emitc.size_t) -> !emitc.lvalue<f32>
1604- %v2_val = load %v2 : !emitc.lvalue<f32> -> f32
1605-
1606- %v3_val = add %v1_val, %v2_val : (f32, f32) -> f32
1607-
1608- %output_lvalue = subscript %output_ptr[%c0] : (!emitc.ptr<f32>, !emitc.size_t) -> !emitc.lvalue<f32>
1609- assign %v3_val, %output_lvalue : (f32, !emitc.lvalue<f32>) -> ()
1610-
1611- return
1612- }
1592+ emitc.class @MymainClass {
1593+ emitc.field @another_feature : !emitc.array<1xf32> = {tf_saved_model.index_path = ["another_feature"]}
1594+ emitc.field @some_feature : !emitc.array<1xf32> = {tf_saved_model.index_path = ["some_feature"]}
1595+ emitc.field @output_0 : !emitc.array<1xf32> = {tf_saved_model.index_path = ["output_0"]}
1596+
1597+ emitc.func @execute() {
1598+ %0 = "emitc.constant"() <{value = 0 : index}> : () -> !emitc.size_t
1599+
1600+ %1 = get_field @another_feature : !emitc.array<1xf32>
1601+ %2 = get_field @some_feature : !emitc.array<1xf32>
1602+ %3 = get_field @output_0 : !emitc.array<1xf32>
1603+
1604+ %4 = subscript %2[%0] : (!emitc.array<1xf32>, !emitc.size_t) -> !emitc.lvalue<f32>
1605+ %5 = load %4 : <f32>
1606+ %6 = subscript %1[%0] : (!emitc.array<1xf32>, !emitc.size_t) -> !emitc.lvalue<f32>
1607+ %7 = load %6 : <f32>
1608+ %8 = add %5, %7 : (f32, f32) -> f32
1609+ %9 = subscript %3[%0] : (!emitc.array<1xf32>, !emitc.size_t) -> !emitc.lvalue<f32>
1610+ assign %8 : f32 to %9 : <f32>
1611+ return
16131612 }
1614- }
1613+ }
16151614
16161615 ```
16171616 }];
@@ -1629,7 +1628,7 @@ def EmitC_ClassOp : EmitC_Op<"class", [AutomaticAllocationScope,
16291628
16301629 let hasCustomAssemblyFormat = 1;
16311630
1632- let assemblyFormat = "`class` $sym_name attr-dict-with-keyword $body" ;
1631+ let assemblyFormat = [{ $sym_name attr-dict-with-keyword $body }] ;
16331632}
16341633
16351634def EmitC_FieldOp : EmitC_Op<"field", [Symbol]> {
@@ -1642,23 +1641,18 @@ def EmitC_FieldOp : EmitC_Op<"field", [Symbol]> {
16421641
16431642 ```mlir
16441643 emitc.class @MyModelClass {
1645- emitc.field @another_feature : !emitc.lvalue<!emitc.ptr<f32>> = #emitc.value<0.0> : !emitc.f32
1646- emitc.field @some_feature : !emitc.lvalue<!emitc.ptr<f32>> = #emitc.value<1.0> : !emitc.f32
1647- emitc.field @output_0 : !emitc.lvalue<!emitc.ptr<f32>>
1648- }
1649- ```
1650- Example without initial value:
1651- ```mlir
1652- emitc.class @MyModelClass {
1653- emitc.field @another_feature : !emitc.lvalue<!emitc.ptr<f32>>
1644+ emitc.field @another_feature : !emitc.array<1xf32> = {tf_saved_model.index_path = ["another_feature"]}
1645+ emitc.field @some_feature : !emitc.array<1xf32> = {tf_saved_model.index_path = ["some_feature"]}
1646+ emitc.field @output_0 : !emitc.array<1xf32> = {tf_saved_model.index_path = ["output_0"]}
16541647 }
16551648 ```
16561649 }];
16571650
16581651 let arguments = (ins SymbolNameAttr:$sym_name, TypeAttr:$type,
16591652 OptionalAttr<AnyAttr>:$initial_value);
16601653
1661- let assemblyFormat = "$sym_name `:` $type (`=` $initial_value^)? attr-dict";
1654+ let assemblyFormat =
1655+ [{ $sym_name `:` $type (`=` $initial_value^)? attr-dict}];
16621656
16631657 let hasVerifier = 1;
16641658}
@@ -1674,18 +1668,15 @@ def EmitC_GetFieldOp
16741668 Example:
16751669
16761670 ```mlir
1677- %some_ptr = emitc.get_field %self : @MyModelClass, @ some_feature -> !emitc.ptr<f32>
1678- %another_ptr = emitc.get_field %self : @MyModelClass, @ another_feature -> !emitc.ptr<f32>
1679- %output_ptr = emitc.get_field %self : @MyModelClass, @ output_0 -> !emitc.ptr<f32>
1671+ %some_ptr = emitc.get_field @ some_feature : !emitc.array<1xf32>
1672+ %another_ptr = emitc.get_field @ another_feature : !emitc.array<1xf32>
1673+ %output_ptr = emitc.get_field @ output_0 : !emitc.array<1xf32>
16801674 ```
16811675 }];
16821676
1683- let arguments = (ins AnyTypeOf<[EmitC_LValueType, EmitC_PointerType]>:$base,
1684- FlatSymbolRefAttr:$class_name, FlatSymbolRefAttr:$field_name);
1685-
1686- let results = (outs AnyTypeOf<[EmitC_LValueType, EmitC_PointerType]>:$result);
1687- let assemblyFormat = "$base `:` type($base) $class_name `,` $field_name `->` "
1688- "type($result) attr-dict";
1677+ let arguments = (ins FlatSymbolRefAttr:$field_name);
1678+ let results = (outs AnyTypeOf<[EmitC_ArrayType, EmitC_LValueType]>:$result);
1679+ let assemblyFormat = "$field_name `:` type($result) attr-dict";
16891680}
16901681
16911682#endif // MLIR_DIALECT_EMITC_IR_EMITC
0 commit comments