-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Move scalar_to_backend
to ssa
#142960
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
base: master
Are you sure you want to change the base?
Move scalar_to_backend
to ssa
#142960
Conversation
Some changes occurred in compiler/rustc_codegen_gcc Some changes occurred in compiler/rustc_codegen_ssa These commits modify the If this was unintentional then you should revert the changes before this PR is merged. |
|
||
fn get_value_name(&self, _val: Self::Value) -> &[u8] { | ||
// TODO(antoyo) | ||
&[] |
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.
I should really finish to add this API in libgccjit. ^^'
Thanks a lot, it will help making our life easier in the GCC backend! Just waiting for @antoyo to confirm it's good for him as well then we can r+. |
Scalar::Int(int) => { | ||
let data = int.to_bits(layout.size(self)); | ||
let llval = self.const_uint_big(self.type_ix(bitsize), data); | ||
if matches!(layout.primitive(), Primitive::Pointer(_)) { | ||
self.const_int_to_ptr(llval, llty) | ||
} else { | ||
self.const_bitcast(llval, llty) | ||
} | ||
} |
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.
This is very likely to break cg_gcc since the bitcast doesn't work in const context (see comment in the original implementation).
I can check if I could make it work in const context in libgccjit if needed.
Nice refactor, btw!
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.
can we cheat and do the bitsize > 1 && ty.is_integral() && bytesize as u32 == ty.get_size()
check within the cg_gcc const_bitcast
impl?
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.
I'll have to thing about whether this could break other things: if that ever gets called with a value of a struct type, for instance, I assume this would break.
Would you have access to bytesize
?
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.
we can very readily provide it, we're in control of this method and llvm will just ignore it
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.
Let me try locally since I'm concerned that this will break other things.
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.
we can very readily provide it, we're in control of this method and llvm will just ignore it
So, your plan would be to change all other calls and possibly the API of the functions calling const_bitcast
to add the missing parameters if needed?
Or will you change the other calls so that they call another function than const_bitcast
?
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.
no rush, we can let this PR sit for a while.
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.
So, your plan would be to change all other calls and possibly the API of the functions calling
const_bitcast
to add the missing parameters if needed?
Or will you change the other calls so that they call another function thanconst_bitcast
?
ah yea we should probably just add a new function for this specific case and have llvm forward to const_bitcast
and gcc do the checks and fallback logic
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.
Ok, good.
We're in the process of adding more tests for cg_gcc in the Rust CI (will try to open an MCP for this soon), so this should make this kind of refactor much easier.
/// Create a global constant. | ||
/// | ||
/// The returned global variable is a pointer in the default address space for globals. | ||
fn static_addr_of_impl(&self, cv: Self::Value, align: Align, kind: Option<&str>) |
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.
Maybe call this static_addr_of_const
?
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.
Also it looks like the kind
argument is always None
, so you can remove it.
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.
unfortunately vtables need this at present to achieve
rust/tests/codegen/debug-vtable.rs
Line 16 in a5fa12b
// Make sure that vtables don't have the unnamed_addr attribute when debuginfo is enabled. |
and since vtables are const, and that logic calls the mut
logic before marking the alloc as const, we need to keep it around everywhere. There's likely things to improve here, but that should probably be its own PR
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.
ah fun, we only do that in some vtable paths, but not in the one in scalar_to_backend
-> Self::Value; | ||
|
||
/// Same as `static_addr_of_impl`, but does not mark the static as immutable | ||
fn static_addr_of_mut(&self, cv: Self::Value, align: Align, kind: Option<&str>) -> Self::Value; |
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.
Same here. kind
is always None
.
r? @GuillaumeGomez @antoyo
I think that should make it much more maintainable going forward