Repository navigation
Conversation
|
|
|
|
||
| fn start_phi(&mut self, value: Self::Value) -> Self::PhiBuilder; | ||
| fn add_phi_input(&mut self, phi: &mut Self::PhiBuilder, value: Self::Value); | ||
| fn phi_output(&mut self, phi: Self::PhiBuilder) -> Self::Value; |
There was a problem hiding this comment.
I removed all uses of phi from cg_ssa a while ago as Cranelift doesn't use phi nodes, but instead uses basic block params.
There was a problem hiding this comment.
The builder API exposed in this PR can be implemented by just creating an alloca in start_phi, writing to it in add_phi_input, and reading from it in phi_output, so it should be implementable in any codegen backend regardless of what mechanism is used to transfer values between basic blocks. That said, I think it would be possible to implement this in a Cranelift backend using basic block params - at most the destination basic block would need to be passed as an argument to start_phi. The PhiBuilder would then store the destination block and the index of the basic block parameter. add_phi_input would track the parameters for each destination block in the builder, which the terminating br/cond_br (or similar) would pass as appropriate.
There was a problem hiding this comment.
Would it make sense to use other names than names containing phi then?
Or is phi the correct name here?
There was a problem hiding this comment.
The builder API exposed in this PR can be implemented by just creating an alloca in start_phi, writing to it in add_phi_input, and reading from it in phi_output, so it should be implementable in any codegen backend regardless of what mechanism is used to transfer values between basic blocks.
Cranelift isn't capable of optimizing that away currently.
One thing that may work is to require add_phi_input to be called while the builder points to the basic block in which a jump to the block that will contain the phi_output should result in the phi node giving that value. In that case I could use declare_var in start_phi (requires passing in the type rather than a value to start_phi), def_var in add_phi_output and use_var in phi_output. Then the SSA construction algorithm in cranelift-frontend should produce the right basic block parameter.
Or is phi the correct name here?
SSA calls this phi functions/nodes.
There was a problem hiding this comment.
With declare_var/def_var/use_var a Cranelift backend should be able to use an implementation similar to the GCC one, replacing new_temp with declare_var, assign with def_var and to_rvalue with use_var.
|
|
||
| // Just to be safe we error out explicitly here, instead of crossing our fingers that | ||
| // the default LLVM implementation has the correct behavior for this target. | ||
| bug!("c-variadic functions are not currently implemented for custom target {arch}") |
There was a problem hiding this comment.
If I understand correctly, some GCC targets that used to work will stop working in this PR since they will now hit this bug!. Is this correct?
If yes, could there be a way for the backend to provide its own implementation (like calling self.context.new_va_arg directly)?
There was a problem hiding this comment.
It seems unlikely that that would come up in practice. This is a match on the architecture, so it would only fail on architectures that the compiler truly has no support for. That will probably fail way before c-variadic becomes a problem?
We can/should just add a variant to the architecture enum for such targets I think?
There was a problem hiding this comment.
By "GCC targets", I meant targets not supported by LLVM (so by official rustc).
So, it's possible other issues come up before variadics.
There was a problem hiding this comment.
We currently have Spirv in the enum, which isn't otherwise really supported either. So, there is precedent for adding variants to the enum.
There was a problem hiding this comment.
There's been some chicken-and-egg problem (rustc vs libc) in the past. Do you know if this concerns this enum?
There was a problem hiding this comment.
I don't think that'll be a problem here. Also if a convincing exception comes up we can use GCC's va_arg of course, but by default we want to error so that we can explicitly consider it.
|
Overall I'm in favor of this change for @rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
|
Also now that bors is back in business maybe there are parts that can be pre-committed if this takes a while? |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| // Adding inputs to a phi is done as part of the branch as some backends (like | ||
| // rustc_codegen_gcc) need to insert statements before the basic block terminator. Having a | ||
| // combined `br_with_phi` operation prevents incorrect usage of the API even on backends that | ||
| // don't need to insert any statements, like rustc_codegen_llvm. |
There was a problem hiding this comment.
Nit: please use a doc-comment here to that it appears in the doc.
I'm good with this API and the cg_gcc part.
This comment has been minimized.
This comment has been minimized.
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
View all comments
This allows the
va_argcodegen to be shared between backends. Methods for emittingptr_maskandphiare added toBuilderMethods, ensuring that there are no changes to the emitted LLVM IR.r? @folkertdev