Skip to content

Commit 19aa606

Browse files
committed
Cleaning up descriptions
1 parent 0fc0c71 commit 19aa606

File tree

5 files changed

+42
-56
lines changed

5 files changed

+42
-56
lines changed

mlir/include/mlir/Dialect/EmitC/IR/EmitC.td

Lines changed: 24 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,29 +1608,21 @@ def EmitC_ClassOp
16081608

16091609
Example:
16101610
```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"]}
16161619
emitc.func @execute() {
16171620
%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>
16301623
return
16311624
}
1632-
}
1633-
1625+
}
16341626
```
16351627
}];
16361628

@@ -1654,23 +1646,22 @@ def EmitC_FieldOp : EmitC_Op<"field", [Symbol]> {
16541646
let summary = "A field within a class";
16551647
let description = [{
16561648
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.
16611653

1654+
Example of func argument with attributes:
16621655
```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"]}
16681659
```
1669-
Example with no initial value:
1660+
Example of func argument without attributes:
16701661
```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>
16741665
```
16751666
}];
16761667

@@ -1694,9 +1685,7 @@ def EmitC_GetFieldOp
16941685
Example:
16951686

16961687
```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>
17001689
```
17011690
}];
17021691

mlir/include/mlir/Dialect/EmitC/Transforms/Passes.td

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ def WrapFuncInClassPass : Pass<"wrap-emitc-func-in-class"> {
2929
}];
3030
let dependentDialects = ["emitc::EmitCDialect"];
3131
let options = [Option<
32-
"namedAttribute", "named-attribute", "std::string", "\"\"",
33-
"Name of the attribute to look for field names on function arguments">];
32+
"namedAttribute", "named-attribute", "std::string",
33+
/*default=*/"",
34+
"Attribute key used to extract field names from function argument's "
35+
"dictionary attributes">];
3436
}
3537

3638
#endif // MLIR_DIALECT_EMITC_TRANSFORMS_PASSES

mlir/lib/Dialect/EmitC/Transforms/WrapFuncInClass.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,7 @@ class WrapFuncInClass : public OpRewritePattern<emitc::FuncOp> {
8080
rewriter.setInsertionPointToStart(&newClassOp.getBody().front());
8181

8282
auto argAttrs = funcOp.getArgAttrs();
83-
size_t idx = 0;
84-
85-
for (const BlockArgument &val : funcOp.getArguments()) {
83+
for (auto [idx, val] : llvm::enumerate(funcOp.getArguments())) {
8684
StringAttr fieldName;
8785
Attribute argAttr = nullptr;
8886

@@ -105,8 +103,6 @@ class WrapFuncInClass : public OpRewritePattern<emitc::FuncOp> {
105103
fields.push_back({fieldName, typeAttr});
106104
rewriter.create<emitc::FieldOp>(funcOp.getLoc(), fieldName, typeAttr,
107105
argAttr);
108-
109-
++idx;
110106
}
111107

112108
rewriter.setInsertionPointToEnd(&newClassOp.getBody().front());
@@ -123,7 +119,7 @@ class WrapFuncInClass : public OpRewritePattern<emitc::FuncOp> {
123119

124120
rewriter.setInsertionPointToStart(&newFuncOp.getBody().front());
125121
std::vector<Value> newArguments;
126-
for (auto [fieldName, attr] : fields) {
122+
for (auto &[fieldName, attr] : fields) {
127123
GetFieldOp arg =
128124
rewriter.create<emitc::GetFieldOp>(loc, attr.getValue(), fieldName);
129125
newArguments.push_back(arg);

mlir/test/Dialect/EmitC/wrap_emitc_func_in_class.mlir

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,18 @@ module attributes { } {
2121
// CHECK-NEXT: emitc.field @some_feature : !emitc.array<1xf32> = {emitc.opaque = ["some_feature"]}
2222
// CHECK-NEXT: emitc.field @output_0 : !emitc.array<1xf32> = {emitc.opaque = ["output_0"]}
2323
// CHECK-NEXT: emitc.func @execute() {
24-
// CHECK-NEXT: %{{[0-9]+}} = "emitc.constant"() <{value = 0 : index}> : () -> !emitc.size_t
25-
// CHECK-NEXT: %{{[0-9]+}} = get_field @another_feature : !emitc.array<1xf32>
26-
// CHECK-NEXT: %{{[0-9]+}} = get_field @some_feature : !emitc.array<1xf32>
27-
// CHECK-NEXT: %{{[0-9]+}} = get_field @output_0 : !emitc.array<1xf32>
28-
// CHECK-NEXT: %{{[0-9]+}} = subscript %{{[0-9]+}}[%{{[0-9]+}}] : (!emitc.array<1xf32>, !emitc.size_t) -> !emitc.lvalue<f32>
29-
// CHECK-NEXT: %{{[0-9]+}} = load %{{[0-9]+}} : <f32>
30-
// CHECK-NEXT: %{{[0-9]+}} = subscript %{{[0-9]+}}[%{{[0-9]+}}] : (!emitc.array<1xf32>, !emitc.size_t) -> !emitc.lvalue<f32>
31-
// CHECK-NEXT: %{{[0-9]+}} = load %{{[0-9]+}} : <f32>
32-
// CHECK-NEXT: %{{[0-9]+}} = add %{{[0-9]+}}, %{{[0-9]+}} : (f32, f32) -> f32
33-
// CHECK-NEXT: %{{[0-9]+}} = subscript %{{[0-9]+}}[%{{[0-9]+}}] : (!emitc.array<1xf32>, !emitc.size_t) -> !emitc.lvalue<f32>
34-
// CHECK-NEXT: assign %{{[0-9]+}} : f32 to %{{[0-9]+}} : <f32>
24+
// CHECK-NEXT: "emitc.constant"() <{value = 0 : index}> : () -> !emitc.size_t
25+
// CHECK-NEXT: get_field @another_feature : !emitc.array<1xf32>
26+
// CHECK-NEXT: get_field @some_feature : !emitc.array<1xf32>
27+
// CHECK-NEXT: get_field @output_0 : !emitc.array<1xf32>
28+
// CHECK-NEXT: subscript {{.*}}[{{.*}}] : (!emitc.array<1xf32>, !emitc.size_t) -> !emitc.lvalue<f32>
29+
// CHECK-NEXT: load {{.*}} : <f32>
30+
// CHECK-NEXT: subscript {{.*}}[{{.*}}] : (!emitc.array<1xf32>, !emitc.size_t) -> !emitc.lvalue<f32>
31+
// CHECK-NEXT: load {{.*}} : <f32>
32+
// CHECK-NEXT: add {{.*}}, {{.*}} : (f32, f32) -> f32
33+
// CHECK-NEXT: subscript {{.*}}[{{.*}}] : (!emitc.array<1xf32>, !emitc.size_t) -> !emitc.lvalue<f32>
34+
// CHECK-NEXT: assign {{.*}} : f32 to {{.*}} : <f32>
3535
// CHECK-NEXT: return
3636
// CHECK-NEXT: }
3737
// CHECK-NEXT: }
3838
// CHECK-NEXT: }
39-

mlir/test/Dialect/EmitC/wrap_emitc_func_in_class_noAttr.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: mlir-opt --wrap-emitc-func-in-class='named-attribute=emitc.opaque' %s | FileCheck %s
1+
// RUN: mlir-opt --wrap-emitc-func-in-class %s | FileCheck %s
22

33
emitc.func @foo(%arg0 : !emitc.array<1xf32>) {
44
emitc.call_opaque "bar" (%arg0) : (!emitc.array<1xf32>) -> ()

0 commit comments

Comments
 (0)