WebAssembly / binaryen

Optimizer and compiler/toolchain library for WebAssembly
Apache License 2.0
7.49k stars 741 forks source link

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

Open zapashcanon opened 20 hours ago

zapashcanon commented 20 hours ago

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 commented 15 hours ago

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 commented 14 hours ago

Thanks!

zapashcanon commented 14 hours ago

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

kripken commented 13 hours ago

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 commented 13 hours ago

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 commented 13 hours ago

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 commented 13 hours ago

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

kripken commented 13 hours ago

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