Skip to content

Commit 1a3e23f

Browse files
committed
WebAssembly: Stop changing MCAsmInfo's ExceptionsType based on flags
Currently wasm adds an extra level of options that work backwards from the standard options, and overwrites them. The ExceptionModel field in TM->Options is the standard user configuration option for the exception model to use. MCAsmInfo's ExceptionsType is a constant for the default to use for the triple if not explicitly set in the TargetOptions ExceptionModel. This was adding 2 custom flags, changing the MCAsmInfo default, and overwriting the ExceptionModel from the custom flags. These comments about compiling bitcode with clang are describing a toolchain bug or user error. TargetOptions is bad, and we should move to eliminating it. It is module state not captured in the IR. Ideally the exception model should either come implied from the triple, or a module flag and not depend on this side state. Currently it is the responsibility of the toolchain and/or user to ensure the same command line flags are used at each phase of the compilation. It is not the backend's responsibilty to try to second guess these options. -wasm-enable-eh and -wasm-enable-sjlj should also be removed in favor of the standard exception control. I'm a bit confused by how all of these fields are supposed to interact, but there are a few uses in the backend that are directly looking at these flags instead of the already parsed ExceptionModel which need to be cleaned up.
1 parent 4e26801 commit 1a3e23f

10 files changed

+50
-56
lines changed

llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCAsmInfo.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,7 @@ WebAssemblyMCAsmInfo::WebAssemblyMCAsmInfo(const Triple &T,
5555
LCOMMDirectiveAlignmentType = LCOMM::Log2Alignment;
5656

5757
SupportsDebugInformation = true;
58-
59-
// When compilation is done on a cpp file by clang, the exception model info
60-
// is stored in LangOptions, which is later used to set the info in
61-
// TargetOptions and then MCAsmInfo in CodeGenTargetMachine::initAsmInfo().
62-
// But this process does not happen when compiling bitcode directly with
63-
// clang, so we make sure this info is set correctly.
64-
if (WebAssembly::WasmEnableEH || WebAssembly::WasmEnableSjLj)
65-
ExceptionsType = ExceptionHandling::Wasm;
58+
ExceptionsType = ExceptionHandling::None;
6659

6760
initializeAtSpecifiers(atSpecifiers);
6861
}

llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.cpp

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -36,35 +36,6 @@ using namespace llvm;
3636
#define GET_REGINFO_MC_DESC
3737
#include "WebAssemblyGenRegisterInfo.inc"
3838

39-
// Exception handling & setjmp-longjmp handling related options.
40-
41-
// Emscripten's asm.js-style exception handling
42-
cl::opt<bool> WebAssembly::WasmEnableEmEH(
43-
"enable-emscripten-cxx-exceptions",
44-
cl::desc("WebAssembly Emscripten-style exception handling"),
45-
cl::init(false));
46-
// Emscripten's asm.js-style setjmp/longjmp handling
47-
cl::opt<bool> WebAssembly::WasmEnableEmSjLj(
48-
"enable-emscripten-sjlj",
49-
cl::desc("WebAssembly Emscripten-style setjmp/longjmp handling"),
50-
cl::init(false));
51-
// Exception handling using wasm EH instructions
52-
cl::opt<bool>
53-
WebAssembly::WasmEnableEH("wasm-enable-eh",
54-
cl::desc("WebAssembly exception handling"));
55-
// setjmp/longjmp handling using wasm EH instrutions
56-
cl::opt<bool> WebAssembly::WasmEnableSjLj(
57-
"wasm-enable-sjlj", cl::desc("WebAssembly setjmp/longjmp handling"));
58-
// If true, use the legacy Wasm EH proposal:
59-
// https://github.com/WebAssembly/exception-handling/blob/main/proposals/exception-handling/legacy/Exceptions.md
60-
// And if false, use the standardized Wasm EH proposal:
61-
// https://github.com/WebAssembly/exception-handling/blob/main/proposals/exception-handling/Exceptions.md
62-
// Currently set to true by default because not all major web browsers turn on
63-
// the new standard proposal by default, but will later change to false.
64-
cl::opt<bool> WebAssembly::WasmUseLegacyEH(
65-
"wasm-use-legacy-eh", cl::desc("WebAssembly exception handling (legacy)"),
66-
cl::init(true));
67-
6839
static MCAsmInfo *createMCAsmInfo(const MCRegisterInfo & /*MRI*/,
6940
const Triple &TT,
7041
const MCTargetOptions &Options) {

llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,6 @@ createWebAssemblyWasmObjectWriter(bool Is64Bit, bool IsEmscripten);
3939

4040
namespace WebAssembly {
4141

42-
// Exception handling / setjmp-longjmp handling command-line options
43-
extern cl::opt<bool> WasmEnableEmEH; // asm.js-style EH
44-
extern cl::opt<bool> WasmEnableEmSjLj; // asm.js-style SjLJ
45-
extern cl::opt<bool> WasmEnableEH; // EH using Wasm EH instructions
46-
extern cl::opt<bool> WasmEnableSjLj; // SjLj using Wasm EH instructions
47-
extern cl::opt<bool> WasmUseLegacyEH; // Legacy Wasm EH
48-
4942
enum OperandType {
5043
/// Basic block label in a branch construct.
5144
OPERAND_BASIC_BLOCK = MCOI::OPERAND_FIRST_TARGET,

llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "WebAssemblyMachineFunctionInfo.h"
2525
#include "WebAssemblyRegisterInfo.h"
2626
#include "WebAssemblyRuntimeLibcallSignatures.h"
27+
#include "WebAssemblyTargetMachine.h"
2728
#include "WebAssemblyUtilities.h"
2829
#include "llvm/ADT/MapVector.h"
2930
#include "llvm/ADT/SmallSet.h"
@@ -155,9 +156,11 @@ static std::string getEmscriptenInvokeSymbolName(wasm::WasmSignature *Sig) {
155156
//===----------------------------------------------------------------------===//
156157

157158
MCSymbolWasm *WebAssemblyAsmPrinter::getMCSymbolForFunction(
158-
const Function *F, bool EnableEmEH, wasm::WasmSignature *Sig,
159-
bool &InvokeDetected) {
159+
const Function *F, wasm::WasmSignature *Sig, bool &InvokeDetected) {
160160
MCSymbolWasm *WasmSym = nullptr;
161+
162+
const bool EnableEmEH =
163+
WebAssembly::WasmEnableEmEH || WebAssembly::WasmEnableEmSjLj;
161164
if (EnableEmEH && isEmscriptenInvokeName(F->getName())) {
162165
assert(Sig);
163166
InvokeDetected = true;
@@ -344,9 +347,7 @@ void WebAssemblyAsmPrinter::emitDecls(const Module &M) {
344347
// will discard it later if it turns out not to be necessary.
345348
auto Signature = signatureFromMVTs(OutContext, Results, Params);
346349
bool InvokeDetected = false;
347-
auto *Sym = getMCSymbolForFunction(
348-
&F, WebAssembly::WasmEnableEmEH || WebAssembly::WasmEnableEmSjLj,
349-
Signature, InvokeDetected);
350+
auto *Sym = getMCSymbolForFunction(&F, Signature, InvokeDetected);
350351

351352
// Multiple functions can be mapped to the same invoke symbol. For
352353
// example, two IR functions '__invoke_void_i8*' and '__invoke_void_i32'
@@ -404,7 +405,7 @@ void WebAssemblyAsmPrinter::emitEndOfAsmFile(Module &M) {
404405
if (!F.isIntrinsic() && F.hasAddressTaken()) {
405406
MCSymbolWasm *FunctionTable =
406407
WebAssembly::getOrCreateFunctionTableSymbol(OutContext, Subtarget);
407-
OutStreamer->emitSymbolAttribute(FunctionTable, MCSA_NoDeadStrip);
408+
OutStreamer->emitSymbolAttribute(FunctionTable, MCSA_NoDeadStrip);
408409
break;
409410
}
410411
}

llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class LLVM_LIBRARY_VISIBILITY WebAssemblyAsmPrinter final : public AsmPrinter {
7373
MVT getRegType(unsigned RegNo) const;
7474
std::string regToString(const MachineOperand &MO);
7575
WebAssemblyTargetStreamer *getTargetStreamer();
76-
MCSymbolWasm *getMCSymbolForFunction(const Function *F, bool EnableEmEH,
76+
MCSymbolWasm *getMCSymbolForFunction(const Function *F,
7777
wasm::WasmSignature *Sig,
7878
bool &InvokeDetected);
7979
MCSymbol *getOrCreateWasmSymbol(StringRef Name);

llvm/lib/Target/WebAssembly/WebAssemblyCFGStackify.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
///
2222
//===----------------------------------------------------------------------===//
2323

24-
#include "MCTargetDesc/WebAssemblyMCTargetDesc.h"
2524
#include "Utils/WebAssemblyTypeUtilities.h"
2625
#include "WebAssembly.h"
2726
#include "WebAssemblyExceptionInfo.h"
2827
#include "WebAssemblyMachineFunctionInfo.h"
2928
#include "WebAssemblySortRegion.h"
3029
#include "WebAssemblySubtarget.h"
30+
#include "WebAssemblyTargetMachine.h"
3131
#include "WebAssemblyUtilities.h"
3232
#include "llvm/ADT/Statistic.h"
3333
#include "llvm/BinaryFormat/Wasm.h"

llvm/lib/Target/WebAssembly/WebAssemblyLateEHPrepare.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
///
1212
//===----------------------------------------------------------------------===//
1313

14-
#include "MCTargetDesc/WebAssemblyMCTargetDesc.h"
1514
#include "WebAssembly.h"
1615
#include "WebAssemblySubtarget.h"
16+
#include "WebAssemblyTargetMachine.h"
1717
#include "WebAssemblyUtilities.h"
1818
#include "llvm/ADT/SmallPtrSet.h"
1919
#include "llvm/CodeGen/MachineFunctionPass.h"

llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,7 @@ WebAssemblyMCInstLower::GetGlobalAddressSymbol(const MachineOperand &MO) const {
7777
auto Signature = signatureFromMVTs(Ctx, ResultMVTs, ParamMVTs);
7878

7979
bool InvokeDetected = false;
80-
auto *WasmSym = Printer.getMCSymbolForFunction(
81-
F, WebAssembly::WasmEnableEmEH || WebAssembly::WasmEnableEmSjLj,
82-
Signature, InvokeDetected);
80+
auto *WasmSym = Printer.getMCSymbolForFunction(F, Signature, InvokeDetected);
8381
WasmSym->setSignature(Signature);
8482
WasmSym->setType(wasm::WASM_SYMBOL_TYPE_FUNCTION);
8583
return WasmSym;

llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,35 @@ static cl::opt<bool> WasmDisableFixIrreducibleControlFlowPass(
5454
" irreducible control flow optimization pass"),
5555
cl::init(false));
5656

57+
// Exception handling & setjmp-longjmp handling related options.
58+
59+
// Emscripten's asm.js-style exception handling
60+
cl::opt<bool> WebAssembly::WasmEnableEmEH(
61+
"enable-emscripten-cxx-exceptions",
62+
cl::desc("WebAssembly Emscripten-style exception handling"),
63+
cl::init(false));
64+
// Emscripten's asm.js-style setjmp/longjmp handling
65+
cl::opt<bool> WebAssembly::WasmEnableEmSjLj(
66+
"enable-emscripten-sjlj",
67+
cl::desc("WebAssembly Emscripten-style setjmp/longjmp handling"),
68+
cl::init(false));
69+
// Exception handling using wasm EH instructions
70+
cl::opt<bool>
71+
WebAssembly::WasmEnableEH("wasm-enable-eh",
72+
cl::desc("WebAssembly exception handling"));
73+
// setjmp/longjmp handling using wasm EH instrutions
74+
cl::opt<bool> WebAssembly::WasmEnableSjLj(
75+
"wasm-enable-sjlj", cl::desc("WebAssembly setjmp/longjmp handling"));
76+
// If true, use the legacy Wasm EH proposal:
77+
// https://github.com/WebAssembly/exception-handling/blob/main/proposals/exception-handling/legacy/Exceptions.md
78+
// And if false, use the standardized Wasm EH proposal:
79+
// https://github.com/WebAssembly/exception-handling/blob/main/proposals/exception-handling/Exceptions.md
80+
// Currently set to true by default because not all major web browsers turn on
81+
// the new standard proposal by default, but will later change to false.
82+
cl::opt<bool> WebAssembly::WasmUseLegacyEH(
83+
"wasm-use-legacy-eh", cl::desc("WebAssembly exception handling (legacy)"),
84+
cl::init(true));
85+
5786
extern "C" LLVM_ABI LLVM_EXTERNAL_VISIBILITY void
5887
LLVMInitializeWebAssemblyTarget() {
5988
// Register the target.

llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@
2121

2222
namespace llvm {
2323

24+
namespace WebAssembly {
25+
// Exception handling / setjmp-longjmp handling command-line options
26+
extern cl::opt<bool> WasmEnableEmEH; // asm.js-style EH
27+
extern cl::opt<bool> WasmEnableEmSjLj; // asm.js-style SjLJ
28+
extern cl::opt<bool> WasmEnableEH; // EH using Wasm EH instructions
29+
extern cl::opt<bool> WasmEnableSjLj; // SjLj using Wasm EH instructions
30+
extern cl::opt<bool> WasmUseLegacyEH; // Legacy Wasm EH
31+
} // namespace WebAssembly
32+
2433
class WebAssemblyTargetMachine final : public CodeGenTargetMachineImpl {
2534
std::unique_ptr<TargetLoweringObjectFile> TLOF;
2635
mutable StringMap<std::unique_ptr<WebAssemblySubtarget>> SubtargetMap;

0 commit comments

Comments
 (0)