Skip to content

[CIR] Use cir.get_vptr to initialize vptr members #1784

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

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

Conversation

andykaylor
Copy link
Collaborator

Previously, following classic codegen, we were using a bitcast to get the address of the vptr member when initializing the vptr in a constructor. This change updates the handling to use cir.get_vptr instead.

This is functionally equivalent because the vptr is always at offset zero for the CXXABIs we currently support, but using cir.get_vptr makes what we are doing more explicit.

@andykaylor
Copy link
Collaborator Author

@tommymcm As previously discussed

// CIR: %{{[0-9]+}} = cir.load align(8) %{{[0-9]+}} : !cir.ptr<!cir.ptr<!void>>, !cir.ptr<!void>
// CIR: %{{[0-9]+}} = cir.cast(bitcast, %{{[0-9]+}} : !cir.ptr<!rec_B>), !cir.ptr<!cir.ptr<!void>>
// CIR: cir.store{{.*}} %{{[0-9]+}}, %{{[0-9]+}} : !cir.ptr<!void>, !cir.ptr<!cir.ptr<!void>>
// CIR: %{{[0-9]+}} = cir.cast(bitcast, %{{[0-9]+}} : !cir.ptr<!cir.ptr<!void>>), !cir.ptr<!cir.vptr>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ideally, cir.vtt.address_point would return !cir.ptr<!cir.vptr> but that introduces a problem with creating the argument list for constructors that require a VTT parameter. We're using QualType extensively in the argument list handling, and there is no QualType that corresponds to !cir.vptr. We use 'pointer-to-pointer-to-void', which is a close equivalent.

I think I can update cir.vtt.address_point and just insert bitcasts when it's used as an argument, but until then, it's 'pointer-to-pointer-to-void'.

@bcardosolopes
Copy link
Member

Sorry for the rebase churn, this PR needs updating!

Previously, following classic codegen, we were using a bitcast to get
the address of the vptr member when initializing the vptr in a constructor.
This change updates the handling to use cir.get_vptr instead.

This is functionally equivalent because the vptr is always at offset zero
for the CXXABIs we currently support, but using cir.get_vptr makes what we
are doing more explicit.
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