aheejin [WebAssembly] Add '.eventtype' directive support
This patch supports `.eventtype` directive printing and parsing in the
same syntax with `.functype`.

Reviewers: aardappel, sbc100

Subscribers: dschuff, sbc100, jgravelle-google, sunfish, llvm-commits

Differential Revision: https://reviews.llvm.org/D55353

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@348818 91177308-0d34-0410-b5e6-96231b3b80d8
Latest commit a0ed820 Dec 11, 2018
Type Name Latest commit message Commit time
Failed to load latest commit information.
AsmParser [WebAssembly] Add '.eventtype' directive support Dec 11, 2018
Disassembler [WebAssembly] Fix return type of nextByte Nov 15, 2018
InstPrinter [WebAssembly] Fix bugs in rethrow depth counting and InstPrinter Nov 2, 2018
MCTargetDesc [WebAssembly] Add '.eventtype' directive support Dec 11, 2018
TargetInfo Remove \brief commands from doxygen comments. May 1, 2018
CMakeLists.txt [WebAssembly][NFC] Remove WebAssemblyStackifier TableGen backend Oct 22, 2018
LLVMBuild.txt [WebAssembly] Added initial AsmParser implementation. Mar 20, 2018
README.txt [WebAssembly] Update README.txt. Jan 15, 2018
WebAssembly.h [WebAssembly] Restore __stack_pointer after catch instructions Aug 21, 2018
WebAssembly.td [WebAssembly] Update bleeding-edge cpu features Nov 10, 2018
WebAssemblyAddMissingPrototypes.cpp [WebAssembly] Fix broken assumption that all bitcasts are to function… Nov 13, 2018
WebAssemblyArgumentMove.cpp Rename DEBUG macro to LLVM_DEBUG. May 14, 2018
WebAssemblyAsmPrinter.cpp [WebAssembly] TargetStreamer cleanup (NFC) Dec 11, 2018
WebAssemblyAsmPrinter.h [WebAssembly] Refactor WasmSignature and use it for MCSymbolWasm Oct 3, 2018
WebAssemblyCFGSort.cpp [WebAssembly] Fix wasm backend compilation on gcc 5.4: variable name … Aug 9, 2018
WebAssemblyCFGStackify.cpp Delete registerScope function Dec 7, 2018
WebAssemblyCallIndirectFixup.cpp [WebAssembly] clang-format (NFC) Sep 5, 2018
WebAssemblyEHRestoreStackPointer.cpp [WebAssembly] Don't write SP back when prolog is generated only for EH Aug 22, 2018
WebAssemblyExceptionInfo.cpp [WebAssembly] clang-format (NFC) Sep 5, 2018
WebAssemblyExceptionInfo.h [WebAssembly] Add WebAssemblyException information analysis Jun 25, 2018
WebAssemblyExplicitLocals.cpp [WebAssembly] Handle V128 register class in explicit locals pass Oct 9, 2018
WebAssemblyFastISel.cpp Fix clang -Wimplicit-fallthrough warnings across llvm, NFC Nov 1, 2018
WebAssemblyFixFunctionBitcasts.cpp Revert "[WebAssembly] Fixup `main` signature by default" Nov 6, 2018
WebAssemblyFixIrreducibleControlFlow.cpp Rename DEBUG macro to LLVM_DEBUG. May 14, 2018
WebAssemblyFrameLowering.cpp [WebAssembly] clang-format (NFC) Sep 5, 2018
WebAssemblyFrameLowering.h [WebAssembly] clang-format (NFC) Sep 5, 2018
WebAssemblyISD.def [WebAssembly] Add support for the event section Nov 14, 2018
WebAssemblyISelDAGToDAG.cpp [WebAssembly] Comment out a switch block in ISelDAGToDAG Jun 29, 2018
WebAssemblyISelLowering.cpp [WebAssembly] Expand unavailable integer operations for vectors Nov 29, 2018
WebAssemblyISelLowering.h [WebAssembly] Add support for the event section Nov 14, 2018
WebAssemblyInstrAtomics.td [WebAssembly][NFC] Remove repetition of Defs = [ARGUMENTS] (fixed) Oct 11, 2018
WebAssemblyInstrCall.td [WebAssembly][NFC] Remove repetition of Defs = [ARGUMENTS] (fixed) Oct 11, 2018
WebAssemblyInstrControl.td [WebAssembly] Add support for the event section Nov 14, 2018
WebAssemblyInstrConv.td [WebAssembly][NFC] Remove repetition of Defs = [ARGUMENTS] (fixed) Oct 11, 2018
WebAssemblyInstrExceptRef.td [WebAssembly][NFC] Remove repetition of Defs = [ARGUMENTS] (fixed) Oct 11, 2018
WebAssemblyInstrFloat.td [WebAssembly] Lower away condition truncations for scalar selects Oct 29, 2018
WebAssemblyInstrFormats.td [WebAssembly][NFC] Remove WebAssemblyStackifier TableGen backend Oct 22, 2018
WebAssemblyInstrInfo.cpp [WebAssembly] Add V128 to WebAssemblyInstrInfo::copyPhysReg Nov 8, 2018
WebAssemblyInstrInfo.h Remove \brief commands from doxygen comments. May 1, 2018
WebAssemblyInstrInfo.td [WebAssembly] Add support for the event section Nov 14, 2018
WebAssemblyInstrInteger.td [WebAssembly] Lower away condition truncations for scalar selects Oct 29, 2018
WebAssemblyInstrMemory.td [WebAssembly][NFC] Remove repetition of Defs = [ARGUMENTS] (fixed) Oct 11, 2018
WebAssemblyInstrSIMD.td [WebAssembly] Renumber SIMD bitwise instructions Nov 15, 2018
WebAssemblyLateEHPrepare.cpp [WebAssembly] Split BBs after throw instructions Nov 16, 2018
WebAssemblyLowerBrUnless.cpp [WebAssembly] clang-format (NFC) Sep 5, 2018
WebAssemblyLowerEmscriptenEHSjLj.cpp [WebAssembly] WebAssemblyLowerEmscriptenEHSjLj: use getter/setter for… Nov 20, 2018
WebAssemblyLowerGlobalDtors.cpp [WebAssembly] clang-format (NFC) Sep 5, 2018
WebAssemblyMCInstLower.cpp [WebAssembly] Add support for the event section Nov 14, 2018
WebAssemblyMCInstLower.h [WebAssembly] Add support for the event section Nov 14, 2018
WebAssemblyMachineFunctionInfo.cpp [WebAssembly] replaced .param/.result by .functype Nov 19, 2018
WebAssemblyMachineFunctionInfo.h [WebAssembly] replaced .param/.result by .functype Nov 19, 2018
WebAssemblyOptimizeLiveIntervals.cpp [WebAssembly] clang-format (NFC) Sep 5, 2018
WebAssemblyOptimizeReturned.cpp Remove \brief commands from doxygen comments. May 1, 2018
WebAssemblyPeephole.cpp [WebAssembly] Update SIMD binary arithmetic Aug 7, 2018
WebAssemblyPrepareForLiveIntervals.cpp [WebAssembly] clang-format (NFC) Sep 5, 2018
WebAssemblyRegColoring.cpp llvm::sort(C.begin(), C.end(), ...) -> llvm::sort(C, ...) Sep 27, 2018
WebAssemblyRegNumbering.cpp Rename DEBUG macro to LLVM_DEBUG. May 14, 2018
WebAssemblyRegStackify.cpp [WebAssembly] Handle vector IMPLICIT_DEFs. Oct 31, 2018
WebAssemblyRegisterInfo.cpp [WebAssembly] clang-format (NFC) Sep 5, 2018
WebAssemblyRegisterInfo.h [WebAssembly] Support instruction selection for catching exceptions May 31, 2018
WebAssemblyRegisterInfo.td [WebAssembly] Update SIMD binary arithmetic Aug 7, 2018
WebAssemblyReplacePhysRegs.cpp [WebAssembly] clang-format (NFC) Sep 5, 2018
WebAssemblyRuntimeLibcallSignatures.cpp WebAssembly: Rename GetSignature to GetLibcallSignature [NFC] Sep 27, 2018
WebAssemblyRuntimeLibcallSignatures.h WebAssembly: Rename GetSignature to GetLibcallSignature [NFC] Sep 27, 2018
WebAssemblySelectionDAGInfo.cpp Remove \brief commands from doxygen comments. May 1, 2018
WebAssemblySelectionDAGInfo.h Remove \brief commands from doxygen comments. May 1, 2018
WebAssemblySetP2AlignOperands.cpp [WebAssembly] Process p2align operands for SIMD loads and stores Oct 31, 2018
WebAssemblyStoreResults.cpp [WebAssembly] clang-format (NFC) Sep 5, 2018
WebAssemblySubtarget.cpp Remove \brief commands from doxygen comments. May 1, 2018
WebAssemblySubtarget.h Remove \brief commands from doxygen comments. May 1, 2018
WebAssemblyTargetMachine.cpp [Targets] Add errors for tiny and kernel codemodel on targets that do… Dec 7, 2018
WebAssemblyTargetMachine.h Remove \brief commands from doxygen comments. May 1, 2018
WebAssemblyTargetObjectFile.cpp [WebAssembly] Remove ELF file support. Jul 16, 2018
WebAssemblyTargetObjectFile.h [WebAssembly] Remove ELF file support. Jul 16, 2018
WebAssemblyTargetTransformInfo.cpp Remove \brief commands from doxygen comments. May 1, 2018
WebAssemblyTargetTransformInfo.h Remove \brief commands from doxygen comments. May 1, 2018
WebAssemblyUtilities.cpp [WebAssembly][NFC] Unify ARGUMENT classes Oct 13, 2018
WebAssemblyUtilities.h [WebAssembly] Add more utility functions Jun 19, 2018
known_gcc_test_failures.txt [WebAssembly] Disable a test that violates DR1696 Jul 20, 2018


//===-- README.txt - Notes for WebAssembly code gen -----------------------===//

This WebAssembly backend is presently under development.

The most notable feature which is not yet stable is the ".o" file format.
".o" file support is needed for many common ways of using LLVM, such as
using it through "clang -c", so this backend is not yet considered widely
usable. However, this backend is usable within some language toolchain

Emscripten provides a C/C++ compilation environment that includes standard
libraries, tools, and packaging for producing WebAssembly applications that
can run in browsers and other environments. For more information, see the
Emscripten documentation in general, and this page in particular:

  * https://github.com/kripken/emscripten/wiki/New-WebAssembly-Backend
Rust provides WebAssembly support integrated into Cargo. There are two
main options:
 - wasm32-unknown-unknown, which provides a relatively minimal environment
   that has an emphasis on being "native"
 - wasm32-unknown-emscripten, which uses Emscripten internally and
   provides standard C/C++ libraries, filesystem emulation, GL and SDL
For more information, see:
  * https://www.hellorust.com/

This backend does not yet support debug info. Full DWARF support needs a
design for how DWARF should be represented in WebAssembly. Sourcemap support
has an existing design and some corresponding browser implementations, so it
just needs implementing in LLVM.

Work-in-progress documentation for the ".o" file format is here:

  * https://github.com/WebAssembly/tool-conventions/blob/master/Linking.md

A corresponding linker implementation is also under development:

  * https://lld.llvm.org/WebAssembly.html

For more information on WebAssembly itself, see the home page:
  * https://webassembly.github.io/

The following documents contain some information on the semantics and binary
encoding of WebAssembly itself:
  * https://github.com/WebAssembly/design/blob/master/Semantics.md
  * https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md

The backend is built, tested and archived on the following waterfall:

The backend's bringup is done in part by using the GCC torture test suite, since
it doesn't require C library support. Current known failures are in
known_gcc_test_failures.txt, all other tests should pass. The waterfall will
turn red if not. Once most of these pass, further testing will use LLVM's own
test suite. The tests can be run locally using:

Some notes on ways that the generated code could be improved follow:


Br, br_if, and br_table instructions can support having a value on the value
stack across the jump (sometimes). We should (a) model this, and (b) extend
the stackifier to utilize it.


The min/max instructions aren't exactly a<b?a:b because of NaN and negative zero
behavior. The ARM target has the same kind of min/max instructions and has
implemented optimizations for them; we should do similar optimizations for


AArch64 runs SeparateConstOffsetFromGEPPass, followed by EarlyCSE and LICM.
Would these be useful to run for WebAssembly too? Also, it has an option to
run SimplifyCFG after running the AtomicExpand pass. Would this be useful for
us too?


Register stackification uses the VALUE_STACK physical register to impose
ordering dependencies on instructions with stack operands. This is pessimistic;
we should consider alternate ways to model stack dependencies.


Lots of things could be done in WebAssemblyTargetTransformInfo.cpp. Similarly,
there are numerous optimization-related hooks that can be overridden in


Instead of the OptimizeReturned pass, which should consider preserving the
"returned" attribute through to MachineInstrs and extending the StoreResults
pass to do this optimization on calls too. That would also let the
WebAssemblyPeephole pass clean up dead defs for such calls, as it does for


Consider implementing optimizeSelect, optimizeCompareInstr, optimizeCondBranch,
optimizeLoadInstr, and/or getMachineCombinerPatterns.


Find a clean way to fix the problem which leads to the Shrink Wrapping pass
being run after the WebAssembly PEI pass.


When setting multiple local variables to the same constant, we currently get
code like this:

    i32.const   $4=, 0
    i32.const   $3=, 0

It could be done with a smaller encoding like this:

    i32.const   $push5=, 0
    tee_local   $push6=, $4=, $pop5
    copy_local  $3=, $pop6


WebAssembly registers are implicitly initialized to zero. Explicit zeroing is
therefore often redundant and could be optimized away.


Small indices may use smaller encodings than large indices.
WebAssemblyRegColoring and/or WebAssemblyRegRenumbering should sort registers
according to their usage frequency to maximize the usage of smaller encodings.


Many cases of irreducible control flow could be transformed more optimally
than via the transform in WebAssemblyFixIrreducibleControlFlow.cpp.

It may also be worthwhile to do transforms before register coloring,
particularly when duplicating code, to allow register coloring to be aware of
the duplication.


WebAssemblyRegStackify could use AliasAnalysis to reorder loads and stores more


WebAssemblyRegStackify is currently a greedy algorithm. This means that, for
example, a binary operator will stackify with its user before its operands.
However, if moving the binary operator to its user moves it to a place where
its operands can't be moved to, it would be better to leave it in place, or
perhaps move it up, so that it can stackify its operands. A binary operator
has two operands and one result, so in such cases there could be a net win by
preferring the operands.


Instruction ordering has a significant influence on register stackification and
coloring. Consider experimenting with the MachineScheduler (enable via
enableMachineScheduler) and determine if it can be configured to schedule
instructions advantageously for this purpose.


WebAssemblyRegStackify currently assumes that the stack must be empty after
an instruction with no return values, however wasm doesn't actually require
this. WebAssemblyRegStackify could be extended, or possibly rewritten, to take
full advantage of what WebAssembly permits.


Add support for mergeable sections in the Wasm writer, such as for strings and
floating-point constants.


The function @dynamic_alloca_redzone in test/CodeGen/WebAssembly/userstack.ll
ends up with a tee_local in its prolog which has an unused result, requiring
an extra drop:

    get_global  $push8=, 0
    tee_local   $push9=, 1, $pop8
    drop        $pop9

The prologue code initially thinks it needs an FP register, but later it
turns out to be unneeded, so one could either approach this by being more
clever about not inserting code for an FP in the first place, or optimizing
away the copy later.