Skip to content
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

emited text contains tuple instructions even when using --intrinsic-lowering #7028

Open
zapashcanon opened this issue Oct 23, 2024 · 10 comments

Comments

@zapashcanon
Copy link

Hi,

I'm running Binaryen with -S (because I'm using a combination of proposals not handled by other tools yet) in order to debug some code. I added the --intrinsic-lowering flag, hoping it would remove the tuples and use locals or whatever instead but it seems this is not the case.

Is there a way to get rid of them in the text format generated by Binaryen? Binaryen is able to produce a binary file so what I'd like is to get the equivalent text format.

This is related to #6016 but it's really not helping me.

Thanks!

@kripken
Copy link
Member

kripken commented Oct 23, 2024

Tuples are not intrinsic functions, they are a normal part of the IR, so that pass does not affect them.

You can print StackIR, --print-stack-ir, which is after tuples are lowered away. For debugging that might be enough, depending on what you want to do with it (I'm not sure which tools can read it).

@zapashcanon
Copy link
Author

Thanks!

@zapashcanon
Copy link
Author

Acutally, when using --print-stack-ir the output is different but still contains tuples, I guess this is not expected ?

@kripken
Copy link
Member

kripken commented Oct 23, 2024

Hmm, yeah, I suppose it doesn't remove them entirely, e.g. this

(module
 (type $0 (func (result i32 f64)))
 (func $foo (type $0) (result i32 f64)
  (tuple.make 2
   (i32.const 42)
   (f64.const 3.14159)
  )
 )
)

is printed as this Stack IR:

(module
 (type $0 (func (result i32 f64)))
 (func $foo (type $0) (result i32 f64)
  i32.const 42
  f64.const 3.14159
  tuple.make 2
 )
)

This is in the flat format that doesn't need tuples, so we could skip printing tuple.make there. We do skip those in the binary writing, but Stack IR printing is mainly for debug reasons so this wasn't noticed. It would make sense to fix this.

@zapashcanon
Copy link
Author

Yes, it would be nice to get rid of them. I'm trying to run Binaryen generated file in the reference interpreter and in Owi and it complicates things.

@kripken
Copy link
Member

kripken commented Oct 23, 2024

If this is for manual debugging, you can ignore the tuple.* instructions in the output. But if you want some other tool to consume this format, that might require more work, I'm not sure how much offhand.

@tlively
Copy link
Member

tlively commented Oct 23, 2024

We could print the tuple instructions as comments in Stack IR, perhaps.

@kripken
Copy link
Member

kripken commented Oct 23, 2024

@zapashcanon You may also want to look at other tools for printing the wasm, such as wasm-tools or v8's wami.

@zapashcanon
Copy link
Author

We could print the tuple instructions as comments in Stack IR, perhaps.

I think this would solve the issue for me.

@tlively
Copy link
Member

tlively commented Oct 28, 2024

Oh, it looks like Stack IR still contains tuple.extract instructions that would require scratch locals to lower away, so just printing tuple.make as a comment would not be enough. That's enough complexity that it might warrant a completely new printing mode based on the binary writer if we want to support it at all.

Your best bet for now would be to have Binaryen emit a binary module, then use a separate tool (probably https://github.com/bytecodealliance/wasm-tools) to disassemble it back to text.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants