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][NFC] move data member pointer lowering to CXXABI #1130

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

Conversation

Lancern
Copy link
Member

@Lancern Lancern commented Nov 15, 2024

This PR moves the lowering code for data member pointers from the conversion patterns to the implementation of CXXABI because this part should be ABI-specific.

mlir::Value loweredAddr, mlir::Value loweredMember,
mlir::OpBuilder &builder) const {
auto llvmElementTy = mlir::IntegerType::get(op.getContext(), 8);
return builder.create<mlir::LLVM::GEPOp>(
Copy link
Member

Choose a reason for hiding this comment

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

We should not assume LLVM lowering at this level and emit a GEP here, target lowering is supposed to understand CIR to CIR. In theory CIR types and etc should be already on the right ABI, so that LLVM lowering has no extra work. Have you tried only returning the necessary information for lower to LLVM to emit the GEP?

Copy link
Member Author

Choose a reason for hiding this comment

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

In theory CIR types and etc should be already on the right ABI, so that LLVM lowering has no extra work.

Basically this PR does ABI lowering work. Thus I'm thinking that I should move the changes here to some prior pass that do ABI lowering works. LoweringPrepare seems good to me at first but I found it a bit difficult to lower type, attributes, and ops all at the same time there, and I'm not sure whether it's conceptually right to do ABI lowering during LoweringPrepare. Should we invent a new ABI lowering pass for this kind of stuff? CallConvLowering already does some ABI related lowering but that's for function calls and function signatures only.

Copy link
Member

Choose a reason for hiding this comment

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

It's still fine if these things return CIR-only operations to LowerToLLVM, my understanding is that those will get scheduled to be lowered when the pass continues. Did you try that? Example: when lowering casts we call the rewriter to emit cir::CmpOp, etc.

Copy link
Member Author

Choose a reason for hiding this comment

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

Did you try that? Example: when lowering casts we call the rewriter to emit cir::CmpOp, etc.

Wow didn't try this. This is indeed a good way to resolve this if it works. Will try later.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated.

// the class object containing it, represented as a ptrdiff_t
const clang::TargetInfo &target = LM.getTarget();
unsigned width =
target.getTypeWidth(target.getPtrDiffType(clang::LangAS::Default));
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 method should be about returning width instead? Answering LLVM type questions at this point sounds like layer violation?

@Lancern Lancern force-pushed the data-member-lowering branch 2 times, most recently from a564ce0 to 02e6c13 Compare November 22, 2024 02:29
Copy link

github-actions bot commented Nov 22, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@Lancern
Copy link
Member Author

Lancern commented Nov 22, 2024

Fixed format issues and rebased.

This patch moves the lowering code for data member pointers from the conversion
patterns to the implementation of CXXABI because this part should be ABI-
specific.
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