elliottt opened PR #5731 from trevor/br-table-block-args
to main
:
Rework
br_table
to useBlockCall
, allowing us to avoid adding new nodes during ssa construction to hold block arguments.<!--
Please ensure that the following steps are all taken care of before submitting
the PR.
[ ] This has been discussed in issue #..., or if not, please tell us why
here.[ ] A short description of what this does, why it is needed; if the
description becomes long, the matter should probably be discussed in an issue
first.[ ] This PR contains test cases, if meaningful.
- [ ] A reviewer from the core maintainer team has been assigned for this PR.
If you don't know who could review this, please indicate so. The list of
suggested reviewers on the right can help you.Please ensure all communication adheres to the code of conduct.
-->
elliottt edited PR #5731 from trevor/br-table-block-args
to main
:
Rework
br_table
to useBlockCall
, allowing us to avoid adding new nodes during ssa construction to hold block arguments.
- [ ] Figure out how to adapt
branch_destination
andbranch_destination_mut
<!--
Please ensure that the following steps are all taken care of before submitting
the PR.
[ ] This has been discussed in issue #..., or if not, please tell us why
here.[ ] A short description of what this does, why it is needed; if the
description becomes long, the matter should probably be discussed in an issue
first.[ ] This PR contains test cases, if meaningful.
- [ ] A reviewer from the core maintainer team has been assigned for this PR.
If you don't know who could review this, please indicate so. The list of
suggested reviewers on the right can help you.Please ensure all communication adheres to the code of conduct.
-->
elliottt updated PR #5731 from trevor/br-table-block-args
to main
.
bjorn3 submitted PR review.
bjorn3 submitted PR review.
bjorn3 created PR review comment:
Is there some limitation in the code generator that requires this change?
elliottt submitted PR review.
elliottt created PR review comment:
Yes, with the introduction of
BlockCall
, block arguments got floated to the end of instruction builders. I think that's fixable, but in the interest of getting something building I switched it locally. I'll add a TODO to investigate fixing this.
elliottt edited PR #5731 from trevor/br-table-block-args
to main
:
Rework
br_table
to useBlockCall
, allowing us to avoid adding new nodes during ssa construction to hold block arguments.
- [ ] Figure out how to adapt
branch_destination
andbranch_destination_mut
- [ ] Determine if it's possible to keep the existing
br_table
builder argument order<!--
Please ensure that the following steps are all taken care of before submitting
the PR.
[ ] This has been discussed in issue #..., or if not, please tell us why
here.[ ] A short description of what this does, why it is needed; if the
description becomes long, the matter should probably be discussed in an issue
first.[ ] This PR contains test cases, if meaningful.
- [ ] A reviewer from the core maintainer team has been assigned for this PR.
If you don't know who could review this, please indicate so. The list of
suggested reviewers on the right can help you.Please ensure all communication adheres to the code of conduct.
-->
elliottt updated PR #5731 from trevor/br-table-block-args
to main
.
elliottt updated PR #5731 from trevor/br-table-block-args
to main
.
elliottt updated PR #5731 from trevor/br-table-block-args
to main
.
bjorn3 submitted PR review.
bjorn3 submitted PR review.
bjorn3 created PR review comment:
This code may need to be preserved for
invoke
depending on how it will be implemented. The exception path gets some block arguments from the personality function, so either those would be added to the block arguments listed inBlockCall
of theinvoke
instruction, or theinvoke
instruction would only list aBlock
and synthesize the full block argument list internally. What do you think would be cleaner?
elliottt submitted PR review.
elliottt created PR review comment:
I like the idea of using a
BlockCall
on theinvoke
instruction. I think the path for doing that should be pretty well worn after addingbrif
, but if you run into any problems usingBlockCall
I'd be happy to help work through them :)
bjorn3 submitted PR review.
bjorn3 created PR review comment:
The difference between
brif
andinvoke
is thatbrif
passes all block arguments in the instruction to the destination block, but forinvoke
there would be some extra block arguments not specified in theBlockCall
. Do you add those at the start or the end? And is there any code that expects there to be no block arguments added? The following is pseudocode to demonstrate the issue:block0: v1 = iconst.i64 42 invoke fn0(), block1, block2(v1) block1: trap user0 block2(v2: i64, v3: i64): ; this is the landingpad ; either v2 or v3 is the extra argument containing a value passed by the personality function. which one should be the extra argument? trap user0
elliottt submitted PR review.
elliottt created PR review comment:
Ah, interesting! I would add them to the end and still use a
BlockCall
. It's sort of like a partially applied function that way.
bjorn3 submitted PR review.
bjorn3 created PR review comment:
Sure, will try that once I get to adding the invoke instruction.
elliottt updated PR #5731 from trevor/br-table-block-args
to main
.
elliottt updated PR #5731 from trevor/br-table-block-args
to main
.
elliottt updated PR #5731 from trevor/br-table-block-args
to main
.
elliottt updated PR #5731 from trevor/br-table-block-args
to main
.
elliottt updated PR #5731 from trevor/br-table-block-args
to main
.
elliottt edited PR #5731 from trevor/br-table-block-args
to main
:
Rework
br_table
to useBlockCall
, allowing us to avoid adding new nodes during ssa construction to hold block arguments.
- [x] Figure out how to adapt
branch_destination
andbranch_destination_mut
- [ ] Determine if it's possible to keep the existing
br_table
builder argument order<!--
Please ensure that the following steps are all taken care of before submitting
the PR.
[ ] This has been discussed in issue #..., or if not, please tell us why
here.[ ] A short description of what this does, why it is needed; if the
description becomes long, the matter should probably be discussed in an issue
first.[ ] This PR contains test cases, if meaningful.
- [ ] A reviewer from the core maintainer team has been assigned for this PR.
If you don't know who could review this, please indicate so. The list of
suggested reviewers on the right can help you.Please ensure all communication adheres to the code of conduct.
-->
elliottt updated PR #5731 from trevor/br-table-block-args
to main
.
elliottt updated PR #5731 from trevor/br-table-block-args
to main
.
elliottt updated PR #5731 from trevor/br-table-block-args
to main
.
elliottt updated PR #5731 from trevor/br-table-block-args
to main
.
elliottt updated PR #5731 from trevor/br-table-block-args
to main
.
elliottt updated PR #5731 from trevor/br-table-block-args
to main
.
elliottt edited PR #5731 from trevor/br-table-block-args
to main
:
Rework
br_table
to useBlockCall
, allowing us to avoid adding new nodes during ssa construction to hold block arguments.
- [x] Figure out how to adapt
branch_destination
andbranch_destination_mut
- [x] Determine if it's possible to keep the existing
br_table
builder argument order<!--
Please ensure that the following steps are all taken care of before submitting
the PR.
[ ] This has been discussed in issue #..., or if not, please tell us why
here.[ ] A short description of what this does, why it is needed; if the
description becomes long, the matter should probably be discussed in an issue
first.[ ] This PR contains test cases, if meaningful.
- [ ] A reviewer from the core maintainer team has been assigned for this PR.
If you don't know who could review this, please indicate so. The list of
suggested reviewers on the right can help you.Please ensure all communication adheres to the code of conduct.
-->
elliottt updated PR #5731 from trevor/br-table-block-args
to main
.
elliottt updated PR #5731 from trevor/br-table-block-args
to main
.
elliottt edited PR #5731 from trevor/br-table-block-args
to main
:
Rework
br_table
to useBlockCall
, allowing us to avoid adding new nodes during ssa construction to hold block arguments.<!--
Please ensure that the following steps are all taken care of before submitting
the PR.
[ ] This has been discussed in issue #..., or if not, please tell us why
here.[ ] A short description of what this does, why it is needed; if the
description becomes long, the matter should probably be discussed in an issue
first.[ ] This PR contains test cases, if meaningful.
- [ ] A reviewer from the core maintainer team has been assigned for this PR.
If you don't know who could review this, please indicate so. The list of
suggested reviewers on the right can help you.Please ensure all communication adheres to the code of conduct.
-->
elliottt submitted PR review.
elliottt created PR review comment:
This change is due to the layout of
JumpTableData
, which keeps the defaultBlockCall
last. The reason for mirroring the order here is so that inmachinst::lower
we can traverse the slice ofBlockCall
values directly when building up targets for branch lowering.
elliottt edited PR review comment.
elliottt submitted PR review.
elliottt created PR review comment:
This is due to the change in traversal order of the jump table: traversing the default label last means that it is emitted last.
elliottt updated PR #5731 from trevor/br-table-block-args
to main
.
elliottt updated PR #5731 from trevor/br-table-block-args
to main
.
elliottt updated PR #5731 from trevor/br-table-block-args
to main
.
elliottt edited PR #5731 from trevor/br-table-block-args
to main
:
Rework
br_table
to useBlockCall
, allowing us to avoid adding new nodes during ssa construction to hold block arguments. Additionally, many places where we previously matched onInstructionData
to extract branch destinations can be replaced with a use ofbranch_destination
orbranch_destination_mut
.<!--
Please ensure that the following steps are all taken care of before submitting
the PR.
[ ] This has been discussed in issue #..., or if not, please tell us why
here.[ ] A short description of what this does, why it is needed; if the
description becomes long, the matter should probably be discussed in an issue
first.[ ] This PR contains test cases, if meaningful.
- [ ] A reviewer from the core maintainer team has been assigned for this PR.
If you don't know who could review this, please indicate so. The list of
suggested reviewers on the right can help you.Please ensure all communication adheres to the code of conduct.
-->
elliottt updated PR #5731 from trevor/br-table-block-args
to main
.
elliottt updated PR #5731 from trevor/br-table-block-args
to main
.
elliottt submitted PR review.
elliottt created PR review comment:
The changes in this file aren't necessary for this PR, but did show up as necessary when making changes to the old form of
br_table
.
elliottt submitted PR review.
elliottt created PR review comment:
This isn't necessary for the
br_table
changes, but it seemed nice to avoid the slice creation.
elliottt updated PR #5731 from trevor/br-table-block-args
to main
.
elliottt has marked PR #5731 as ready for review.
elliottt requested jameysharp for a review on PR #5731.
bjorn3 submitted PR review.
bjorn3 created PR review comment:
Maybe also add a test using block arguments?
elliottt submitted PR review.
elliottt created PR review comment:
I've added both runtests and x64 compile tests for uses of
br_table
with block arguments. My feeling was that those would be sufficient as this PR stops splitting critical edges in ssa construction, was there an additional case you were thinking of here?
bjorn3 submitted PR review.
bjorn3 created PR review comment:
I guess that works too. I was thinking that we have a test of creating jump tables here, so we might as well add the new case of having block arguments here.
elliottt updated PR #5731 from trevor/br-table-block-args
to main
.
elliottt submitted PR review.
elliottt created PR review comment:
I'll add different arguments to the two uses of
e1
, and assert that they're the same.
elliottt edited PR review comment.
elliottt updated PR #5731 from trevor/br-table-block-args
to main
.
jameysharp submitted PR review.
jameysharp submitted PR review.
jameysharp created PR review comment:
After reading this comment, I was left wondering why this whole function can't just be replaced with a loop over
branch_destination
. I forgot the boolean argument to the closure depends on these details. Could you add that detail to the comment, for the next time I forget how everything works?Of course, I think all but one caller of this function ignore the boolean argument, and with this PR, all except that one could be replaced with a small loop over
branch_destination
. Maybe we should look at whether the call incranelift/codegen/src/machinst/blockorder.rs
really needs to know this distinction, and see if we can eliminate this function entirely now...
jameysharp created PR review comment:
This appears to have been the only use of
arrayvec
in this entire git repository. Let's remove it.
jameysharp created PR review comment:
For slices,
iter
andinto_iter
are identical. So I'd use the shorter version here. Bonus points if that gets rustfmt to put this back on one line, though I'm not betting on that..iter()
jameysharp created PR review comment:
Can
rewrite_branch_destination
become a small loop overbranch_destination_mut
now every case usesBlockCall
?
jameysharp created PR review comment:
I think it's a good assertion to add regardless, so I'm glad you kept this in.
jameysharp created PR review comment:
This isn't sufficient to generate br_table with block params. We also need to update the match on
BlockTerminatorKind::BrTable
elsewhere to usegenerate_target_block
instead of selecting fromforward_blocks_without_params
. Also that should be the last use of the latter as well as a variety of other machinery which can all be removed now. Hooray!
afonso360 submitted PR review.
afonso360 created PR review comment:
Alongside what @jameysharp is saying above, we can now select
Switch
andBrTable
more often, since they no longer require a special block without params.Could you also update this: https://github.com/bytecodealliance/wasmtime/blob/e10094dcd6d0354628255a6f2e69c1e4c327d6e7/cranelift/fuzzgen/src/function_generator.rs#L1806-L1815 So that we allow
BrTable
andSwitch
alongsideJump
andBr
?The only other places where we use
forward_blocks_without_params
, is when selecting blocks forSwitch
targets, and those can also now carry params, so I agree, lets remove it!
afonso360 edited PR review comment.
elliottt submitted PR review.
elliottt created PR review comment:
Yep, good call!
elliottt submitted PR review.
elliottt created PR review comment:
It uses it to record those branch targets as indirect. We might be able to do something gross to recover that information some other way, but I feel like it's fine to duplicate the matching logic here. I'll add the additional comment you mentioned :)
elliottt submitted PR review.
elliottt created PR review comment:
Unfortunately that didn't bring us back to a single line :(
elliottt updated PR #5731 from trevor/br-table-block-args
to main
.
elliottt submitted PR review.
elliottt created PR review comment:
I believe I've made the changes you both requested, could you take a quick look and make sure?
elliottt requested jameysharp for a review on PR #5731.
afonso360 submitted PR review.
afonso360 created PR review comment:
LGTM! :+1:
jameysharp submitted PR review.
jameysharp submitted PR review.
jameysharp created PR review comment:
I have a mild preference for the iterator chain approach here, mostly to avoid thinking about allocation capacity. A neat Rust trick is that
Result
implementsFromIterator
: if any element of the iterator isErr
then that's returned, otherwise all theOk
values are collected into the underlying collection type. So I believe this should work:let targets = (0..target_count).map(|_| self.generate_target_block(block)).collect()?;
elliottt submitted PR review.
elliottt created PR review comment:
Very nice! I started with the iterator chain and went back to a for loop when I couldn't think of an elegant way to handle the
Result
. I'll give this a try :)
elliottt updated PR #5731 from trevor/br-table-block-args
to main
.
elliottt updated PR #5731 from trevor/br-table-block-args
to main
.
elliottt updated PR #5731 from trevor/br-table-block-args
to main
.
elliottt submitted PR review.
elliottt created PR review comment:
This is a bit unfortunate: the table throws off capstone, which causes it to not see the
movl $4, %edx
and the label for offset 0x39. I have a fix in #5798 that I've confirmed locally outputs the mov and label.
elliottt updated PR #5731 from trevor/br-table-block-args
to main
.
elliottt merged PR #5731.
Last updated: Dec 23 2024 at 12:05 UTC