Skip to content

Commit 4780ab3

Browse files
committed
Cleaning up descriptions
1 parent b064a9c commit 4780ab3

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
@@ -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

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)