This CL is small, but the description can be a little long because I'm
trying to sum up the status quo for Emscripten/Wasm EH/SjLj options.
First, this CL adds an option for Wasm SjLj (`-wasm-enable-sjlj`), which
handles SjLj using Wasm EH. The implementation for this will be added as
a followup CL, but this adds the option first to do error checking.
This also adds an option for Wasm EH (`-wasm-enable-eh`), which has been
already implemented. Before we used `-exception-model=wasm` as the same
meaning as enabling Wasm EH, but after we add Wasm SjLj, it will be
possible to use Wasm EH instructions for Wasm SjLj while not enabling
EH, so going forward, to use Wasm EH, `opt` and `llc` will need this
option. This only affects `opt` and `llc` command lines and does not
affect Emscripten user interface.
Now we have two modes of EH (Emscripten/Wasm) and also two modes of SjLj
(also Emscripten/Wasm). The options corresponding to each of are:
- Emscripten EH: `-enable-emscripten-cxx-exceptions`
- Emscripten SjLj: `-enable-emscripten-sjlj`
- Wasm EH: `-wasm-enable-eh -exception-model=wasm`
`-mattr=+exception-handling`
- Wasm SjLj: `-wasm-enable-sjlj -exception-model=wasm`
`-mattr=+exception-handling`
The reason Wasm EH/SjLj's options are a little complicated are
`-exception-model` and `-mattr` are common LLVM options ane not under
our control. (`-mattr` can be omitted if it is embedded within the
bitcode file.)
And we have the following rules of the option composition:
- Emscripten EH and Wasm EH cannot be turned on at the same itme
- Emscripten SjLj and Wasm SjLj cannot be turned on at the same time
- Wasm SjLj should be used with Wasm EH
Which means we now allow these combinations:
- Emscripten EH + Emscripten SjLj: the current default in `emcc`
- Wasm EH + Emscripten SjLj:
This is allowed, but only as an interim step in which we are testing
Wasm EH but not yet have a working implementation of Wasm SjLj. This
will error out (D107687) in compile time if `setjmp` is called in a
function in which Wasm exception is used.
- Wasm EH + Wasm SjLj:
This will be the default mode later when using Wasm EH. Currently Wasm
SjLj implementation doesn't exist, so it doesn't work.
- Emscripten EH + Wasm SjLj will not work.
This CL moves these error checking routines to
`WebAssemblyPassConfig::addIRPasses`. Not sure if this is an ideal place
to do this, but I couldn't find elsewhere. Currently some checking is
done within LowerEmscriptenEHSjLj, but these checks only run if
LowerEmscriptenEHSjLj runs so it may not run when Wasm EH is used. This
moves that to `addIRPasses` and adds some more checks.
Currently LowerEmscriptenEHSjLj pass is responsible for Emscripten EH
and Emscripten SjLj. Wasm EH transformations are done in multiple
places, including WasmEHPrepare, LateEHPrepare, and CFGStackify. But in
the followup CL, LowerEmscriptenEHSjLj pass will be also responsible for
a part of Wasm SjLj transformation, because WasmSjLj will also be using
several Emscripten library functions, and we will be sharing more than
half of the transformation to do that between Emscripten SjLj and Wasm
SjLj.
Currently we have `-enable-emscripten-cxx-exceptions` and
`-enable-emscripten-sjlj` but these only work for `llc`, because for
`llc` we feed these options to the pass but when we run the pass using
`opt` the pass will be created with no options and the default options
will be used, which turns both Emscripten EH and Emscripten SjLj on.
Now we have one more SjLj option to care for, LowerEmscriptenEHSjLj pass
needs a finer way to control these options. This CL removes those
default parameters and make LowerEmscriptenEHSjLj pass read directly
from command line options specified. So if we only run
`opt -wasm-lower-em-ehsjlj`, currently both Emscripten EH and Emscripten
SjLj will run, but with this CL, none will run unless we additionally
pass `-enable-emscripten-cxx-exceptions` or `-enable-emscripten-sjlj`,
or both. This does not affect users; this only affects our `opt` tests
because `emcc` will not call either `opt` or `llc`. As a result of this,
our existing Emscripten EH/SjLj tests gained one or both of those
options in their `RUN` lines.
Reviewed By: dschuff
Differential Revision: https://reviews.llvm.org/D107685
110 lines
4.6 KiB
C++
110 lines
4.6 KiB
C++
//===-- WebAssembly.h - Top-level interface for WebAssembly ----*- C++ -*-===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
///
|
|
/// \file
|
|
/// This file contains the entry points for global functions defined in
|
|
/// the LLVM WebAssembly back-end.
|
|
///
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLY_H
|
|
#define LLVM_LIB_TARGET_WEBASSEMBLY_WEBASSEMBLY_H
|
|
|
|
#include "llvm/PassRegistry.h"
|
|
#include "llvm/Support/CodeGen.h"
|
|
|
|
namespace llvm {
|
|
|
|
class WebAssemblyTargetMachine;
|
|
class ModulePass;
|
|
class FunctionPass;
|
|
|
|
// LLVM IR passes.
|
|
ModulePass *createWebAssemblyLowerEmscriptenEHSjLj();
|
|
ModulePass *createWebAssemblyLowerGlobalDtors();
|
|
ModulePass *createWebAssemblyAddMissingPrototypes();
|
|
ModulePass *createWebAssemblyFixFunctionBitcasts();
|
|
FunctionPass *createWebAssemblyOptimizeReturned();
|
|
FunctionPass *createWebAssemblyLowerRefTypesIntPtrConv();
|
|
|
|
// ISel and immediate followup passes.
|
|
FunctionPass *createWebAssemblyISelDag(WebAssemblyTargetMachine &TM,
|
|
CodeGenOpt::Level OptLevel);
|
|
FunctionPass *createWebAssemblyArgumentMove();
|
|
FunctionPass *createWebAssemblySetP2AlignOperands();
|
|
|
|
// Late passes.
|
|
FunctionPass *createWebAssemblyReplacePhysRegs();
|
|
FunctionPass *createWebAssemblyNullifyDebugValueLists();
|
|
FunctionPass *createWebAssemblyPrepareForLiveIntervals();
|
|
FunctionPass *createWebAssemblyOptimizeLiveIntervals();
|
|
FunctionPass *createWebAssemblyMemIntrinsicResults();
|
|
FunctionPass *createWebAssemblyRegStackify();
|
|
FunctionPass *createWebAssemblyRegColoring();
|
|
FunctionPass *createWebAssemblyFixBrTableDefaults();
|
|
FunctionPass *createWebAssemblyFixIrreducibleControlFlow();
|
|
FunctionPass *createWebAssemblyLateEHPrepare();
|
|
FunctionPass *createWebAssemblyCFGSort();
|
|
FunctionPass *createWebAssemblyCFGStackify();
|
|
FunctionPass *createWebAssemblyExplicitLocals();
|
|
FunctionPass *createWebAssemblyLowerBrUnless();
|
|
FunctionPass *createWebAssemblyRegNumbering();
|
|
FunctionPass *createWebAssemblyDebugFixup();
|
|
FunctionPass *createWebAssemblyPeephole();
|
|
FunctionPass *createWebAssemblyMCLowerPrePass();
|
|
|
|
// PassRegistry initialization declarations.
|
|
void initializeWebAssemblyAddMissingPrototypesPass(PassRegistry &);
|
|
void initializeWebAssemblyLowerEmscriptenEHSjLjPass(PassRegistry &);
|
|
void initializeLowerGlobalDtorsPass(PassRegistry &);
|
|
void initializeFixFunctionBitcastsPass(PassRegistry &);
|
|
void initializeOptimizeReturnedPass(PassRegistry &);
|
|
void initializeWebAssemblyArgumentMovePass(PassRegistry &);
|
|
void initializeWebAssemblySetP2AlignOperandsPass(PassRegistry &);
|
|
void initializeWebAssemblyReplacePhysRegsPass(PassRegistry &);
|
|
void initializeWebAssemblyNullifyDebugValueListsPass(PassRegistry &);
|
|
void initializeWebAssemblyPrepareForLiveIntervalsPass(PassRegistry &);
|
|
void initializeWebAssemblyOptimizeLiveIntervalsPass(PassRegistry &);
|
|
void initializeWebAssemblyMemIntrinsicResultsPass(PassRegistry &);
|
|
void initializeWebAssemblyRegStackifyPass(PassRegistry &);
|
|
void initializeWebAssemblyRegColoringPass(PassRegistry &);
|
|
void initializeWebAssemblyFixBrTableDefaultsPass(PassRegistry &);
|
|
void initializeWebAssemblyFixIrreducibleControlFlowPass(PassRegistry &);
|
|
void initializeWebAssemblyLateEHPreparePass(PassRegistry &);
|
|
void initializeWebAssemblyExceptionInfoPass(PassRegistry &);
|
|
void initializeWebAssemblyCFGSortPass(PassRegistry &);
|
|
void initializeWebAssemblyCFGStackifyPass(PassRegistry &);
|
|
void initializeWebAssemblyExplicitLocalsPass(PassRegistry &);
|
|
void initializeWebAssemblyLowerBrUnlessPass(PassRegistry &);
|
|
void initializeWebAssemblyRegNumberingPass(PassRegistry &);
|
|
void initializeWebAssemblyDebugFixupPass(PassRegistry &);
|
|
void initializeWebAssemblyPeepholePass(PassRegistry &);
|
|
void initializeWebAssemblyMCLowerPrePassPass(PassRegistry &);
|
|
void initializeWebAssemblyLowerRefTypesIntPtrConvPass(PassRegistry &);
|
|
|
|
namespace WebAssembly {
|
|
enum TargetIndex {
|
|
// Followed by a local index (ULEB).
|
|
TI_LOCAL,
|
|
// Followed by an absolute global index (ULEB). DEPRECATED.
|
|
TI_GLOBAL_FIXED,
|
|
// Followed by the index from the bottom of the Wasm stack.
|
|
TI_OPERAND_STACK,
|
|
// Followed by a compilation unit relative global index (uint32_t)
|
|
// that will have an associated relocation.
|
|
TI_GLOBAL_RELOC,
|
|
// Like TI_LOCAL, but indicates an indirect value (e.g. byval arg
|
|
// passed by pointer).
|
|
TI_LOCAL_INDIRECT
|
|
};
|
|
} // end namespace WebAssembly
|
|
|
|
} // end namespace llvm
|
|
|
|
#endif
|