This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly] Revise the strategy for inline asm.
AbandonedPublic

Authored by sunfish on Sep 28 2017, 9:01 AM.

Details

Reviewers
dschuff
Summary

Previously, an "r" constraint would mean the compiler provides a value on WebAssembly's operand stack. This was tricky to use properly, particularly since it isn't possible to declare a new local from within an inline asm string.

With this patch, "r" provides the value in a WebAssembly local, and the local index is provided to the inline asm string. This requires inline asm to use get_local and set_local to read the register. This does potentially result in larger code size, however inline asm should hopefully be quite rare in WebAssembly.

This also means that the "m" constraint can no longer be supported, as WebAssembly has nothing like a "memory operand" that includes an implicit get_local.

This fixes PR34599 for the wasm32-unknown-unknown-wasm target (though not for the ELF target).

Diff Detail

Repository
rL LLVM

Event Timeline

sunfish created this revision.Sep 28 2017, 9:01 AM

This strategy seems fine to me.
How would this CL be different if it also affected the ELF flavor though? I don't mind fixing s2wasm if it makes LLVM simper.

Patches are welcome for the ELF/s2wasm path :-). I haven't thought about how they'd work, because they're still using the confusing implicit get/set_local scheme.

dschuff accepted this revision.Sep 28 2017, 9:40 AM

Oh, right, implicit locals. Yeah I don't think it's really worth thinking about too much.

This revision is now accepted and ready to land.Sep 28 2017, 9:40 AM
sunfish abandoned this revision.Nov 8 2017, 11:20 AM

Landed in r317707.