================
@@ -2694,6 +2694,69 @@ def CIR_GetMemberOp : CIR_Op<"get_member"> {
let hasVerifier = 1;
}
+//===----------------------------------------------------------------------===//
+
+
+// GetElementOp
+
+
+//===----------------------------------------------------------------------===//
+
+
+
+
+
+def CIR_GetElementOp : CIR_Op<"get_element"> {
+ let summary = "Get the address of an array element";
+
+ let description = [{
+ The `cir.get_element` operation gets the address of a particular element
+ from the `base` array.
+
+ It expects a pointer to the `base` array and the `index` of the element.
+
+ Example:
+ ```mlir
+ // Suppose we have a array.
+ !s32i = !cir.int<s, 32>
+ !arr_ty = !cir.array<!s32i x 4>
+
+ // Get the address of the element at index 1.
+ %elem_1 = cir.get_element %0[1] : (!cir.ptr<!array_ty>, !s32i) ->
!cir.ptr<!s32i>
+
+ // Get the address of the element at index %i.
+ %i = ...
+ %elem_i = cir.get_element %0[%i] : (!cir.ptr<!array_ty>, !s32i) ->
!cir.ptr<!s32i>
+
+ ```
+ }];
+
+ let arguments = (ins
+ Arg<CIR_PtrToArray, "the base address of the array ">:$base,
+ Arg<CIR_AnyFundamentalIntType, "the index of the element">:$index
+ );
+
+ let results = (outs CIR_PointerType:$result);
+
+ let assemblyFormat = [{
+ $base `[` $index `]` `:` `(` qualified(type($base)) `,`
qualified(type($index)) `)`
----------------
erichkeane wrote:
Actually, GetMemberOp:
` $addr `[` $index_attr `]` attr-dict `:` qualified(type($addr)) `->`
qualified(type($result))`
Seems perhaps even better?
https://github.com/llvm/llvm-project/pull/172897
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits