clangir icon indicating copy to clipboard operation
clangir copied to clipboard

Use `void (ptr)` on `LLVM::GlobalOp` when available in LLVM dialect to represent aliased functions

Open bcardosolopes opened this issue 1 year ago • 4 comments

Similar issue from https://github.com/llvm/clangir/issues/1065, we cannot use globals at all (even if we ignore the absence of alias) to start representing aliases. llvm.mlir.globals don't seem to accept anything besides !llvm.ptr as it's types and there are no existing casts to use in its initializers that can allows us to map from llvm.mlir.addressof.

To be more concrete, I want to generate this following LLVM IR code:

@_ZN1BD1Ev = dso_local unnamed_addr alias void (ptr), ptr @_ZN1BD2Ev
@_ZN1CD2Ev = dso_local unnamed_addr alias void (ptr), ptr @_ZN1BD2Ev
@_ZN1CD1Ev = dso_local unnamed_addr alias void (ptr), ptr @_ZN1BD2Ev

define dso_local void @_ZN1BD2Ev(ptr noundef nonnull align 8 dereferenceable(9) %this) unnamed_addr #0 {
...

This also needs to be filed against upstream MLIR.

bcardosolopes avatar Nov 07 '24 23:11 bcardosolopes

Filed upstream: https://github.com/llvm/llvm-project/issues/115392

bcardosolopes avatar Nov 07 '24 23:11 bcardosolopes

It looks like you implemented the necessary support in the LLVM dialect, but we still aren't lowering to aliases in CIR. I'm working on a patch that implements this for function aliases. I'll put up a PR as soon as I get it cleaned up. I haven't looked at non-function aliases yet.

andykaylor avatar Jul 08 '25 23:07 andykaylor

I think https://github.com/llvm/clangir/pull/1739 addresses this issue.

andykaylor avatar Jul 09 '25 20:07 andykaylor

Great, thanks Andy!

bcardosolopes avatar Jul 14 '25 19:07 bcardosolopes