Skip to content

Commit 5b772cb

Browse files
author
Simon Camphausen
committed
Fix examples in op descriptions
1 parent 5f41378 commit 5b772cb

File tree

1 file changed

+26
-12
lines changed
  • mlir/include/mlir/Dialect/EmitC/IR

1 file changed

+26
-12
lines changed

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

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ def EmitC_ApplyOp : EmitC_Op<"apply", [CExpression]> {
8888

8989
```mlir
9090
// Custom form of applying the & operator.
91-
%0 = emitc.apply "&"(%arg0) : (i32) -> !emitc.ptr<i32>
91+
%0 = emitc.apply "&"(%arg0) : (!emitc.lvalue<i32>) -> !emitc.ptr<i32>
9292

9393
// Generic form of the same operation.
9494
%0 = "emitc.apply"(%arg0) {applicableOperator = "&"}
95-
: (i32) -> !emitc.ptr<i32>
95+
: (!emitc.lvalue<i32>) -> !emitc.ptr<i32>
9696

9797
```
9898
}];
@@ -846,6 +846,16 @@ def EmitC_LoadOp : EmitC_Op<"load", [
846846
This operation loads the content of a modifiable lvalue into an SSA value.
847847
Modifications of the lvalue executed after the load are not observable on
848848
the produced value.
849+
850+
Example:
851+
852+
```mlir
853+
%1 = emitc.load %0 : !emitc.lvalue<i32>
854+
```
855+
```c++
856+
// Code emitted for the operation above.
857+
int32_t v2 = v1;
858+
```
849859
}];
850860

851861
let arguments = (ins
@@ -937,7 +947,7 @@ def EmitC_MemberOp : EmitC_Op<"member"> {
937947

938948
```mlir
939949
%0 = "emitc.member" (%arg0) {member = "a"}
940-
: (!emitc.opaque<"mystruct">) -> i32
950+
: (!emitc.lvalue<!emitc.opaque<"mystruct">>) -> !emitc.lvalue<i32>
941951
```
942952
}];
943953

@@ -958,7 +968,8 @@ def EmitC_MemberOfPtrOp : EmitC_Op<"member_of_ptr"> {
958968

959969
```mlir
960970
%0 = "emitc.member_of_ptr" (%arg0) {member = "a"}
961-
: (!emitc.ptr<!emitc.opaque<"mystruct">>) -> i32
971+
: (!emitc.lvalue<!emitc.ptr<!emitc.opaque<"mystruct">>>)
972+
-> !emitc.lvalue<i32>
962973
```
963974
}];
964975

@@ -1061,10 +1072,10 @@ def EmitC_VariableOp : EmitC_Op<"variable", []> {
10611072
As an example, it is valid to create pointers to `variable` operations
10621073
by using `apply` operations and pass these to a `call` operation.
10631074
```mlir
1064-
%0 = "emitc.variable"() {value = 0 : i32} : () -> i32
1065-
%1 = "emitc.variable"() {value = 0 : i32} : () -> i32
1066-
%2 = emitc.apply "&"(%0) : (i32) -> !emitc.ptr<i32>
1067-
%3 = emitc.apply "&"(%1) : (i32) -> !emitc.ptr<i32>
1075+
%0 = "emitc.variable"() {value = 0 : i32} : () -> !emitc.lvalue<i32>
1076+
%1 = "emitc.variable"() {value = 0 : i32} : () -> !emitc.lvalue<i32>
1077+
%2 = emitc.apply "&"(%0) : (!emitc.lvalue<i32>) -> !emitc.ptr<i32>
1078+
%3 = emitc.apply "&"(%1) : (!emitc.lvalue<i32>) -> !emitc.ptr<i32>
10681079
emitc.call_opaque "write"(%2, %3)
10691080
: (!emitc.ptr<i32>, !emitc.ptr<i32>) -> ()
10701081
```
@@ -1138,6 +1149,7 @@ def EmitC_GetGlobalOp : EmitC_Op<"get_global",
11381149

11391150
```mlir
11401151
%x = emitc.get_global @foo : !emitc.array<2xf32>
1152+
%y = emitc.get_global @bar : !emitc.lvalue<i32>
11411153
```
11421154
}];
11431155

@@ -1192,11 +1204,11 @@ def EmitC_AssignOp : EmitC_Op<"assign", []> {
11921204

11931205
```mlir
11941206
// Integer variable
1195-
%0 = "emitc.variable"(){value = 42 : i32} : () -> i32
1207+
%0 = "emitc.variable"(){value = 42 : i32} : () -> !emitc.lvalue<i32>
11961208
%1 = emitc.call_opaque "foo"() : () -> (i32)
11971209

11981210
// Assign emitted as `... = ...;`
1199-
"emitc.assign"(%0, %1) : (i32, i32) -> ()
1211+
"emitc.assign"(%0, %1) : (!emitc.lvalue<i32>, i32) -> ()
12001212
```
12011213
}];
12021214

@@ -1298,8 +1310,10 @@ def EmitC_SubscriptOp : EmitC_Op<"subscript", []> {
12981310
```mlir
12991311
%i = index.constant 1
13001312
%j = index.constant 7
1301-
%0 = emitc.subscript %arg0[%i, %j] : !emitc.array<4x8xf32>, index, index
1302-
%1 = emitc.subscript %arg1[%i] : !emitc.ptr<i32>, index
1313+
%0 = emitc.subscript %arg0[%i, %j] : (!emitc.array<4x8xf32>, index, index)
1314+
-> !emitc.lvalue<f32>
1315+
%1 = emitc.subscript %arg1[%i] : (!emitc.ptr<i32>, index)
1316+
-> !emitc.lvalue<i32>
13031317
```
13041318
}];
13051319
let arguments = (ins Arg<AnyTypeOf<[

0 commit comments

Comments
 (0)