andykaylor wrote:

> > The results look right here, but it isn't clear to me how we are getting 
> > there. Can you elaborate on that?
> 
> ```c++
> int x;
> unsigned long gx = (unsigned long)&x;
> ```
> 
> Here the base of x is int so tryEmitBase gives us `#cir.global_view<@x>` then 
> in tryEmit we retag that to `#cir.global_view<@x> : !u64i` similarly for 
> offset adjustment like for arrays we get `#cir.global_view<@arr, [2 : i32]> : 
> !u64i`.
> 
> Then lowering CIR to LLVM emits
> 
> ```llvm
> llvm.mlir.global external @gx() : i64 {
>   %0 = llvm.mlir.addressof @x : !llvm.ptr
>   %1 = llvm.ptrtoint %0 : !llvm.ptr to i64
>   llvm.return %1 : i64
> }
> ```
> 
> and the final IR is
> 
> ```
> @x = global i32 0, align 4
> @gx = global i64 ptrtoint (ptr @x to i64), align 8
> ```

Thanks for the explanation. It's unfortunate that we're still lowering this to 
a region-based initializer, but I can live with that for now.

https://github.com/llvm/llvm-project/pull/220643
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to