[PATCH] D64758: [WebAssembly] Assembler/InstPrinter: support call_indirect type index.

Wouter van Oortmerssen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 15 10:12:09 PDT 2019


aardappel created this revision.
aardappel added reviewers: sbc100, dschuff, aheejin, jgravelle-google, sunfish, tlively.
Herald added subscribers: llvm-commits, arphaman.
Herald added a project: LLVM.

WIP - this likely needs to be done differently - discuss.

A TYPE_INDEX operand (as used by call_indirect) is represented in MC as
a symbol (in assembly as e.g. .Ltype_index0 at TYPE_INDEX) which the
WasmObjectWriter then turns into a reloc. Now the regular backend path
(in WebAssemblyMCInstLower) creates a temporary unnamed symbol for this
(presumably because we don't actually want this to be emitted as a
symbol), and WasmObjectWriter tests for this specifically.
The assembler however goes thru a generic (non-wasm) expr parser that
creates a named symbol, which makes WasmObjectWriter not function
correctly.

Now I could fix this in one of 3 ways that I see:
a) make the assembler mimic what the backend does, which generally seems
preferrable. But that means adding funny options to non-wasm code,
and/or detecting we just parsed the wrong kind of symbol and patching it
afterwards.
b) skipping the generic parsing, attempting to parse it myself, and if
I recognize a TYPE_INDEX, create my own kind of symbol
c) rewrite the logic in WasmObjectWriter to be less fragile so it
accepts my symbol just fine. The logic in there selects for different
kind of symbols in 3 locations in 3 different ways, which makes it very
hard to verify that all cases are covered, and indeed it is easy to make
it blow up if you are not the backend. See e.g. the logic in isInSymtab
which is used in only one of the 3 cases.

This patch attempts solution a) - patching it afterwards. This is
fairly hacky, not only does it need new method to delete the name of
an existing symbol, it doesn't work well when round-tripped thru the
assembler (see type-index.s test).

So we may need one of the other options above.


Repository:
  rL LLVM

https://reviews.llvm.org/D64758

Files:
  include/llvm/MC/MCSymbol.h
  lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
  lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.cpp
  lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.h
  lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.cpp
  lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.h
  test/CodeGen/WebAssembly/reg-stackify.ll
  test/MC/WebAssembly/type-index.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64758.209900.patch
Type: text/x-patch
Size: 10881 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190715/af36c41b/attachment.bin>


More information about the llvm-commits mailing list