@@ -347,9 +347,8 @@ def EmitC_ConstantOp : EmitC_Op<"constant", [ConstantLike]> {
347347 %0 = "emitc.constant"(){value = 42 : i32} : () -> i32
348348
349349 // Constant emitted as `char = CHAR_MIN;`
350- %1 = "emitc.constant"()
351- {value = #emitc.opaque<"CHAR_MIN"> : !emitc.opaque<"char">}
352- : () -> !emitc.opaque<"char">
350+ %1 = "emitc.constant"() {value = #emitc.opaque<"CHAR_MIN">}
351+ : () -> !emitc.opaque<"char">
353352 ```
354353 }];
355354
@@ -992,9 +991,8 @@ def EmitC_VariableOp : EmitC_Op<"variable", []> {
992991 %0 = "emitc.variable"(){value = 42 : i32} : () -> i32
993992
994993 // Variable emitted as `int32_t* = NULL;`
995- %1 = "emitc.variable"()
996- {value = #emitc.opaque<"NULL"> : !emitc.opaque<"int32_t*">}
997- : () -> !emitc.opaque<"int32_t*">
994+ %1 = "emitc.variable"() {value = #emitc.opaque<"NULL">}
995+ : () -> !emitc.ptr<!emitc.opaque<"int32_t">>
998996 ```
999997
1000998 Since folding is not supported, it can be used with pointers.
@@ -1022,12 +1020,12 @@ def EmitC_GlobalOp : EmitC_Op<"global", [Symbol]> {
10221020 The `emitc.global` operation declares or defines a named global variable.
10231021 The backing memory for the variable is allocated statically and is
10241022 described by the type of the variable.
1025- Optionally, and `initial_value` can be provided.
1026- Internal linkage can be specified using the `staticSpecifier ` unit attribute
1027- and external linkage can be specified using the `externSpecifier ` unit attribute.
1023+ Optionally, an `initial_value` can be provided.
1024+ Internal linkage can be specified using the `static_specifier ` unit attribute
1025+ and external linkage can be specified using the `extern_specifier ` unit attribute.
10281026 Note that the default linkage without those two keywords depends on whether
10291027 the target is C or C++ and whether the global variable is `const`.
1030- The global variable can also be marked constant using the `constSpecifier `
1028+ The global variable can also be marked constant using the `const_specifier `
10311029 unit attribute. Writing to such constant global variables is
10321030 undefined.
10331031
@@ -1049,14 +1047,14 @@ def EmitC_GlobalOp : EmitC_Op<"global", [Symbol]> {
10491047 let arguments = (ins SymbolNameAttr:$sym_name,
10501048 TypeAttr:$type,
10511049 OptionalAttr<EmitC_OpaqueOrTypedAttr>:$initial_value,
1052- UnitAttr:$externSpecifier ,
1053- UnitAttr:$staticSpecifier ,
1054- UnitAttr:$constSpecifier );
1050+ UnitAttr:$extern_specifier ,
1051+ UnitAttr:$static_specifier ,
1052+ UnitAttr:$const_specifier );
10551053
10561054 let assemblyFormat = [{
1057- (`extern` $externSpecifier ^)?
1058- (`static` $staticSpecifier ^)?
1059- (`const` $constSpecifier ^)?
1055+ (`extern` $extern_specifier ^)?
1056+ (`static` $static_specifier ^)?
1057+ (`const` $const_specifier ^)?
10601058 $sym_name
10611059 `:` custom<EmitCGlobalOpTypeAndInitialValue>($type, $initial_value)
10621060 attr-dict
@@ -1224,35 +1222,41 @@ def EmitC_IfOp : EmitC_Op<"if",
12241222 let hasCustomAssemblyFormat = 1;
12251223}
12261224
1227- def EmitC_SubscriptOp : EmitC_Op<"subscript",
1228- [TypesMatchWith<"result type matches element type of 'array'",
1229- "array", "result",
1230- "::llvm::cast<ArrayType>($_self).getElementType()">]> {
1231- let summary = "Array subscript operation";
1225+ def EmitC_SubscriptOp : EmitC_Op<"subscript", []> {
1226+ let summary = "Subscript operation";
12321227 let description = [{
12331228 With the `subscript` operation the subscript operator `[]` can be applied
1234- to variables or arguments of array type.
1229+ to variables or arguments of array, pointer and opaque type.
12351230
12361231 Example:
12371232
12381233 ```mlir
12391234 %i = index.constant 1
12401235 %j = index.constant 7
1241- %0 = emitc.subscript %arg0[%i, %j] : <4x8xf32>, index, index
1236+ %0 = emitc.subscript %arg0[%i, %j] : !emitc.array<4x8xf32>, index, index
1237+ %1 = emitc.subscript %arg1[%i] : !emitc.ptr<i32>, index
12421238 ```
12431239 }];
1244- let arguments = (ins Arg<EmitC_ArrayType, "the reference to load from">:$array,
1245- Variadic<IntegerIndexOrOpaqueType>:$indices);
1240+ let arguments = (ins Arg<AnyTypeOf<[
1241+ EmitC_ArrayType,
1242+ EmitC_OpaqueType,
1243+ EmitC_PointerType]>,
1244+ "the value to subscript">:$value,
1245+ Variadic<EmitCType>:$indices);
12461246 let results = (outs EmitCType:$result);
12471247
12481248 let builders = [
1249- OpBuilder<(ins "Value":$array, "ValueRange":$indices), [{
1250- build($_builder, $_state, cast<ArrayType>(array.getType()).getElementType(), array, indices);
1249+ OpBuilder<(ins "TypedValue<ArrayType>":$array, "ValueRange":$indices), [{
1250+ build($_builder, $_state, array.getType().getElementType(), array, indices);
1251+ }]>,
1252+ OpBuilder<(ins "TypedValue<PointerType>":$pointer, "Value":$index), [{
1253+ build($_builder, $_state, pointer.getType().getPointee(), pointer,
1254+ ValueRange{index});
12511255 }]>
12521256 ];
12531257
12541258 let hasVerifier = 1;
1255- let assemblyFormat = "$array `[` $indices `]` attr-dict `:` type($array) `,` type($indices )";
1259+ let assemblyFormat = "$value `[` $indices `]` attr-dict `:` functional- type(operands, results )";
12561260}
12571261
12581262
0 commit comments