Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CIR] Add integer result type for cir.global_view #1248

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Lancern
Copy link
Member

@Lancern Lancern commented Dec 19, 2024

This PR updates the #cir.global_view attribute and make it accept integer types as its result type.

@@ -198,4 +205,17 @@ module {
}
// MLIR: %0 = llvm.mlir.addressof @zero_array

cir.func @const_global_addr() -> !u64i {
%0 = cir.const #cir.global_addr<@".str"> : !u64i
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like this is equivalent to a global view with zero index? Why can't this be modeled ash cir.const #cir.global_view<@".str"> ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cir.global_addr is of integer types, and I'm not sure if it's appropriate to make cir.global_view an integer type. If it's OK I could just update cir.global_view instead of introducing a new one.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My take is that we want here is a constant pointer coming out of cir.const, followed up by a cast to integer?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My take is that we want here is a constant pointer coming out of cir.const, followed up by a cast to integer?

In this case, yes. But I'm actually proposing this attribute for the following scenario where you don't have space for additional operations:

%0 = cir.const #cir.const_struct {
  #cir.global_addr @aaa,
  #cir.global_addr @bbb
}

And I'm looking at this scenario because recently I'm working on the LLVM lowering of member function pointers. Upon ABI lowering, a member function pointer is lowered to a struct with two fields of type ptrdiff_t. When the member function pointer represents a non-virtual member function, the first field stores the address of the target function as an integer. Thus to represent constant member function pointers I need an attribute that works like #cir.global_addr.

@Lancern Lancern changed the title [CIR] Add cir.global_addr attribute [CIR] Add integer result type for cir.global_view Dec 30, 2024
@Lancern
Copy link
Member Author

Lancern commented Dec 30, 2024

I have updated this PR and removed the #cir.global_addr attribute. Instead, I just updated the existing #cir.global_view attribute and make it accept integer types as its result type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants