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][LLVMLowering] Add LLVM lowering for data member pointers #612

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

Conversation

Lancern
Copy link
Collaborator

@Lancern Lancern commented May 16, 2024

This PR adds LLVM lowering support for data member pointers. It includes the following changes:

  • The #cir.data_member attribute now has a new parameter named memberOffset. When the data member pointer is not null, this parameter gives the offset of the pointed-to member within its containing object. This offset is calculated by target ABI.
  • A new attribute #cir.data_member_ptr_layout is added. It contains ABI-specific layout information about a data member pointer that is required to lower it to LLVM IR. This attribute is attached to the module op, and it is queried during LLVMIR lowering to obtain the lowering information in it.
  • Some CIRGen of the data member pointers is refactored to follow the upstream CodeGen skeleton.

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 adding lowering!

clang/include/clang/CIR/Dialect/IR/CIRAttrs.td Outdated Show resolved Hide resolved
clang/test/CIR/CodeGen/pointer-to-data-member.cpp Outdated Show resolved Hide resolved
clang/include/clang/CIR/Dialect/IR/CIRAttrs.td Outdated Show resolved Hide resolved

uint64_t memberOffset;
if (attr.isNullPtr())
memberOffset = -1ull;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This constant value for null pointers is actually ABI-specific. Should we move this to some ABI-specific part?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we elevate lowerDataMemberAttr as a whole to LoweringPrepareCXXABI, so that the codes are centralized?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should we elevate lowerDataMemberAttr as a whole to LoweringPrepareCXXABI, so that the codes are centralized?

Transforming data member pointers to member offsets during lowering prepare sounds reasonable at first, but the tricky part here is you also have to change every occurrences of !cir.data_member type to !cir.int type, which can be hard to implement during lowering prepare.

Copy link
Member

Choose a reason for hiding this comment

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

Work that @sitio-couto is doing in #643 should provide us a way to ask those queries at LLVM lowering stage as well, since the information should be available at any time post CIRGen. I think it's fine to leave this as is and add a missing feature so that @sitio-couto can patch this when he lands his work. @sitio-couto any extra thoughts?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@bcardosolopes sounds good to me. But the "tricky part" that @Lancern pointed out will still be an issue on the ABI lowering stage. AFAIK, there's no way for passes to iterate on specific attrs. We would either need to walk through every op or have a well-defined set of ops that may use the DataMemberAttr.

Copy link
Member

Choose a reason for hiding this comment

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

This seems to be the same thing from https://github.com/llvm/clangir/pull/652/files#r1625515020. To be more clear, I'm not suggesting we do it in LoweringPrepare, what I'm suggesting is that since @sitio-couto ABI library is independent of CIRGen, it should also be usable from LowerToLLVM.cpp. A missing feature check here works for now (perhaps you wait for @seven-mile to land it and use it here?)


uint64_t memberOffset;
if (attr.isNullPtr())
memberOffset = -1ull;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we elevate lowerDataMemberAttr as a whole to LoweringPrepareCXXABI, so that the codes are centralized?

This patch adds LLVM lowering support for data member pointers. It also
refactors some CIRGen of the data member pointers to follow the upstream CodeGen
skeleton.
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.

None yet

4 participants