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][CIRGen] Add support for global named registers #741

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

Conversation

566hub
Copy link
Contributor

@566hub 566hub commented Jul 15, 2024

Realize RG and GET_RG op which are copied from cir.Global
op. The concept is that the same asm label means a unique abstract memory
address with u64i type, and get_rg will return ptr. We could use
cir.cast(bitcast) to transform ptr to ptr.

@566hub 566hub changed the title Realize RG and GET_RG op [CIR]Realize RG and GET_RG op Jul 15, 2024
Copy link
Member

@bcardosolopes bcardosolopes left a comment

Choose a reason for hiding this comment

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

Thanks for working on this, it's a nice feature addition!

We can achieve the same by re-using existing ClangIR components. The suggested approach:

  • Create/use a regular global.
  • Use regular cir.get_global to retrieve the address.
  • Add a new attribute #cir.asm_reg that holds a StringAttr. This should be used to initialize the global.
  • Add a isGlobalRegister method to cir.global's extraClassDeclaration, which checks if the global has an initializer and whether that is a #cir.asm_reg.
  • Add support in LowerToLLVM.cpp to materialize cir.get_globals into metadata !<whatever>. cir.{load,store} referring to these globals should be converted to the proper intrinsic calls.
  • Use a more complete usecase that exercise both intrinsics: https://godbolt.org/z/deGs17rox
  • Use clang/test/CIR/CodeGen/abstract-cond.c as an example for testing both CIR and LLVM output in the same test.

// cir.func no_proto @main() extra(#fn_attr) {
// %0 = cir.const #cir.int<1> : !s32i
// %1 = cir.cast(integral, %0 : !s32i), !s64i
// %2 = cir.get_RG @llvm.named.register.x20 : !cir.ptr<!u64i>
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for trying to improve this! We don't eagerly lower things to LLVM right away though, this is done in LowerToLLVM.cpp.

@bcardosolopes bcardosolopes changed the title [CIR]Realize RG and GET_RG op [CIR][CIRGen] Add support for global named registers Jul 15, 2024
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