================
@@ -653,13 +631,13 @@ def CIR_AllocaOp : CIR_Op<"alloca", [
}];
let assemblyFormat = [{
- $allocaType `,` qualified(type($addr)) `,`
+ $name
+ `align` `(` $alignment `)`
+ oilist( `init` $init
+ | `const` $constant
+ | `cleanup_dest_slot` $cleanup_dest_slot)
($dynAllocSize^ `:` type($dynAllocSize) `,`)?
- `[` $name
- (`,` `init` $init^)?
- (`,` `const` $constant^)?
- (`,` `cleanup_dest_slot` $cleanup_dest_slot^)?
- `]`
+ $allocaType `->` qualified(type($addr))
----------------
xlauko wrote:
> I explored this a bit more and found that `InferTypeOpInterface` could be
> used here. One advantage is that callers would no longer need to explicitly
> construct the pointer type. For example, instead of:
>
> ```c++
> mlir::Type itrTy = cgf.cgm.convertType(cgf.getContext().UnsignedLongLongTy);
> auto itrPtrTy = cir::PointerType::get(itrTy);
> cir::AllocaOp::create(builder, loc, itrPtrTy, itrTy, "itr", itrAlign);
> ```
>
> we could just pass the allocated type and let the result type be inferred.
>
> That said, it doesn't actually address the storage redundancy you mentioned.
> Even with `inferReturnTypes` building `cir::PointerType::get(ctx,
> adaptor.getAllocaType())`, both the allocated type and the pointer result
> type still end up stored in the operation.
>
> I also noticed that `llvm.alloca` follows the same approach and stores both
> `elem_type` and the pointer result type separately.
The difference is that LLVM does not repeat the type, because return type is
opaque pointer type, so you need separate element type. Whereas in our case we
have the element type as part of the pointer type.
I would suggest:
- keep only return type?
- add extra class method `getElementType`?
>
> Following your suggestion, the format would look something like:
>
> `%0 = cir.alloca "n" align(4) init -> !cir.ptr<!s32i>`
>
> and for dynamic allocations:
>
> `%0 = cir.alloca "n" align(4) init %sz : !u64i -> !cir.ptr<!s32i>`
>
> Does that look good to you?😊
I guess this would work, it is not really what we have at other places, as `->`
always has some preceeding arguments. When there are none, we would use only:
```
%0 = cir.alloca "n" align(4) init : !cir.ptr<!s32i>`
```
but this would collide with size in second case :/
does size need to be any int type? if it was deterministic i64, we don't need
to print it's size anf get something like:
```
%0 = cir.alloca "n" align(4) init size(%sz) : !cir.ptr<!s32i>
```
https://github.com/llvm/llvm-project/pull/198962
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits