-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Prepare GEP building for opaque pointers #87695
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,12 +103,13 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> { | |
if offset == a.value.size(bx.cx()).align_to(b.value.align(bx.cx()).abi) => | ||
{ | ||
// Offset matches second field. | ||
bx.struct_gep(self.llval, 1) | ||
let ty = bx.backend_type(self.layout); | ||
bx.struct_gep(ty, self.llval, 1) | ||
} | ||
Abi::Scalar(_) | Abi::ScalarPair(..) | Abi::Vector { .. } if field.is_zst() => { | ||
// ZST fields are not included in Scalar, ScalarPair, and Vector layouts, so manually offset the pointer. | ||
let byte_ptr = bx.pointercast(self.llval, bx.cx().type_i8p()); | ||
bx.gep(byte_ptr, &[bx.const_usize(offset.bytes())]) | ||
bx.gep(bx.cx().type_i8(), byte_ptr, &[bx.const_usize(offset.bytes())]) | ||
} | ||
Abi::Scalar(_) | Abi::ScalarPair(..) => { | ||
// All fields of Scalar and ScalarPair layouts must have been handled by this point. | ||
|
@@ -119,7 +120,10 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> { | |
self.layout | ||
); | ||
} | ||
_ => bx.struct_gep(self.llval, bx.cx().backend_field_index(self.layout, ix)), | ||
_ => { | ||
let ty = bx.backend_type(self.layout); | ||
bx.struct_gep(ty, self.llval, bx.cx().backend_field_index(self.layout, ix)) | ||
} | ||
}; | ||
PlaceRef { | ||
// HACK(eddyb): have to bitcast pointers until LLVM removes pointee types. | ||
|
@@ -185,7 +189,7 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> { | |
|
||
// Cast and adjust pointer. | ||
let byte_ptr = bx.pointercast(self.llval, bx.cx().type_i8p()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly here. |
||
let byte_ptr = bx.gep(byte_ptr, &[offset]); | ||
let byte_ptr = bx.gep(bx.cx().type_i8(), byte_ptr, &[offset]); | ||
|
||
// Finally, cast back to the type expected. | ||
let ll_fty = bx.cx().backend_type(field); | ||
|
@@ -380,7 +384,11 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> { | |
}; | ||
|
||
PlaceRef { | ||
llval: bx.inbounds_gep(self.llval, &[bx.cx().const_usize(0), llindex]), | ||
llval: bx.inbounds_gep( | ||
bx.cx().backend_type(self.layout), | ||
self.llval, | ||
&[bx.cx().const_usize(0), llindex], | ||
), | ||
llextra: None, | ||
layout, | ||
align: self.align.restrict_for_offset(offset), | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary to pointercast this
self.llval
anymore?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When an explicit pointee type is provided it must be equal to the pointer element type, so this will have to wait until migration to opaque pointers is complete:
https://github.com/rust-lang/llvm-project/blob/260e0f8682098faab68af9c608534756ad378365/llvm/include/llvm/IR/Instructions.h#L956-L958