Skip to content

Print constants in a comment in CLIF output#4725

Merged
jameysharp merged 2 commits into
bytecodealliance:mainfrom
jameysharp:print-consts
Aug 17, 2022
Merged

Print constants in a comment in CLIF output#4725
jameysharp merged 2 commits into
bytecodealliance:mainfrom
jameysharp:print-consts

Conversation

@jameysharp
Copy link
Copy Markdown
Contributor

When trying to read generated CLIF, it's nice to be able to see at a glance that some of the operands are defined by iconst instructions, without having to go find each operand's definition manually.

@afonso360 suggested this in #4721 (and @bjorn3 seconded the idea) but I think it's a good idea independent of that issue.

I'm not sure if this is the right implementation, though: I don't understand the intent of the FuncWriter trait well enough to know if adding this to the shared write_operands function is the best place. Perhaps only some implementations of FuncWriter should do this?

Because of that uncertainty, I haven't fixed up any of the tests which fail due to not expecting these extra comments. So I expect that CI should currently be failing.

Copy link
Copy Markdown
Member

@cfallin cfallin left a comment

Choose a reason for hiding this comment

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

This is a reasonable change, thanks!

Comment thread cranelift/codegen/src/write.rs Outdated
let mut sep = " ; ";
for &arg in dfg.inst_args(inst) {
if let ValueDef::Result(src, _) = dfg.value_def(arg) {
if let UnaryImm { imm, .. } = dfg[src] {
Copy link
Copy Markdown
Contributor

@afonso360 afonso360 Aug 16, 2022

Choose a reason for hiding this comment

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

Thanks for following up on this! What do you think about expanding this to UnaryIeee{32, 64} and UnaryBool? I think that would cover the f{32,64}const and bconst cases.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Okay, done! That still leaves vconst but that's more complicated since those constants aren't inline in the instruction. I don't feel like figuring out how that works right now since it was enough of a pain fixing the tests for these changes already. I'd be happy to review a PR on top of this one if somebody feels like taking that on though.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I changed my mind: it's good enough to just print which element of the constant pool is in a vector-typed value, and that was easy to do. I think that might actually be more useful than printing giant vector literals. So now there's output for vconst as well.

When trying to read generated CLIF, it's nice to be able to see at a
glance that some of the operands are defined by `iconst` and similar
instructions, without having to go find each operand's definition
manually.
@jameysharp jameysharp marked this pull request as ready for review August 16, 2022 23:12
@github-actions github-actions Bot added the cranelift Issues related to the Cranelift code generator label Aug 17, 2022
@jameysharp jameysharp merged commit 3629bbb into bytecodealliance:main Aug 17, 2022
@jameysharp jameysharp deleted the print-consts branch August 17, 2022 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cranelift Issues related to the Cranelift code generator

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants