Skip to content

Commit 9868f97

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. Additionally, this was enforcing some rules about the combinations of flags at a random point in the IR pass pipeline configuration. This is a module property that should be handled at TargetMachine construction time at the latest. This required adding flags to a few mir and clang tests which never got this far to avoid hitting the errors.
1 parent bd2f148 commit 9868f97

16 files changed

+113
-124
lines changed

clang/test/CodeGen/WebAssembly/wasm-exception-model-flag-parse-ir-input.ll

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22

33
; Check all the options parse
44
; RUN: %clang_cc1 -triple wasm32 -o - -emit-llvm -exception-model=none %s | FileCheck %s
5-
; RUN: %clang_cc1 -triple wasm32 -o - -emit-llvm -exception-model=wasm %s | FileCheck %s
6-
; RUN: %clang_cc1 -triple wasm32 -o - -emit-llvm -exception-model=dwarf %s | FileCheck %s
7-
; RUN: %clang_cc1 -triple wasm32 -o - -emit-llvm -exception-model=sjlj %s | FileCheck %s
5+
; RUN: %clang_cc1 -triple wasm32 -o - -emit-llvm -exception-model=wasm -mllvm -wasm-enable-eh %s | FileCheck %s
86

97
; RUN: not %clang_cc1 -triple wasm32 -o - -emit-llvm -exception-model=invalid %s 2>&1 | FileCheck -check-prefix=ERR %s
8+
; RUN: not %clang_cc1 -triple wasm32 -o - -emit-llvm -exception-model=dwarf %s 2>&1 | FileCheck -check-prefix=ERR-BE %s
9+
; RUN: not %clang_cc1 -triple wasm32 -o - -emit-llvm -exception-model=sjlj %s 2>&1 | FileCheck -check-prefix=ERR-BE %s
1010

1111
; CHECK-LABEL: define void @test(
1212

1313
; ERR: error: invalid value 'invalid' in '-exception-model=invalid'
14+
; ERR-BE: fatal error: error in backend: -exception-model should be either 'none' or 'wasm'
1415
define void @test() {
1516
ret void
1617
}

clang/test/CodeGenCXX/builtins-eh-wasm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -triple wasm32-unknown-unknown -fexceptions -fcxx-exceptions -target-feature +reference-types -target-feature +exception-handling -target-feature +multivalue -exception-model=wasm -emit-llvm -o - %s | FileCheck %s
1+
// RUN: %clang_cc1 -triple wasm32-unknown-unknown -fexceptions -fcxx-exceptions -target-feature +reference-types -target-feature +exception-handling -target-feature +multivalue -mllvm -wasm-enable-eh -exception-model=wasm -emit-llvm -o - %s | FileCheck %s
22

33
// Check if __builtin_wasm_throw and __builtin_wasm_rethrow are correctly
44
// invoked when placed in try-catch.

clang/test/CodeGenCXX/wasm-eh.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,9 +393,9 @@ void noexcept_throw() noexcept {
393393
// CHECK-NEXT: call void @_ZSt9terminatev()
394394

395395

396-
// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -exception-model=wasm -target-feature +exception-handling -emit-llvm -o - -std=c++11 2>&1 | FileCheck %s --check-prefix=WARNING-DEFAULT
397-
// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -exception-model=wasm -target-feature +exception-handling -Wwasm-exception-spec -emit-llvm -o - -std=c++11 2>&1 | FileCheck %s --check-prefix=WARNING-ON
398-
// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -exception-model=wasm -target-feature +exception-handling -Wno-wasm-exception-spec -emit-llvm -o - -std=c++11 2>&1 | FileCheck %s --check-prefix=WARNING-OFF
396+
// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -mllvm -wasm-enable-eh -exception-model=wasm -target-feature +exception-handling -emit-llvm -o - -std=c++11 2>&1 | FileCheck %s --check-prefix=WARNING-DEFAULT
397+
// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -mllvm -wasm-enable-eh -exception-model=wasm -target-feature +exception-handling -Wwasm-exception-spec -emit-llvm -o - -std=c++11 2>&1 | FileCheck %s --check-prefix=WARNING-ON
398+
// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fms-extensions -fexceptions -fcxx-exceptions -mllvm -wasm-enable-eh -exception-model=wasm -target-feature +exception-handling -Wno-wasm-exception-spec -emit-llvm -o - -std=c++11 2>&1 | FileCheck %s --check-prefix=WARNING-OFF
399399
// RUN: %clang_cc1 %s -triple wasm32-unknown-unknown -fexceptions -fcxx-exceptions -emit-llvm -o - -std=c++11 2>&1 | FileCheck %s --check-prefix=EM-EH-WARNING
400400

401401
// Wasm EH ignores dynamic exception specifications with types at the moment.

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: 81 additions & 58 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.
@@ -111,6 +140,57 @@ static Reloc::Model getEffectiveRelocModel(std::optional<Reloc::Model> RM,
111140
return *RM;
112141
}
113142

143+
using WebAssembly::WasmEnableEH;
144+
using WebAssembly::WasmEnableEmEH;
145+
using WebAssembly::WasmEnableEmSjLj;
146+
using WebAssembly::WasmEnableSjLj;
147+
148+
static void basicCheckForEHAndSjLj(TargetMachine *TM) {
149+
150+
// You can't enable two modes of EH at the same time
151+
if (WasmEnableEmEH && WasmEnableEH)
152+
report_fatal_error(
153+
"-enable-emscripten-cxx-exceptions not allowed with -wasm-enable-eh");
154+
// You can't enable two modes of SjLj at the same time
155+
if (WasmEnableEmSjLj && WasmEnableSjLj)
156+
report_fatal_error(
157+
"-enable-emscripten-sjlj not allowed with -wasm-enable-sjlj");
158+
// You can't mix Emscripten EH with Wasm SjLj.
159+
if (WasmEnableEmEH && WasmEnableSjLj)
160+
report_fatal_error(
161+
"-enable-emscripten-cxx-exceptions not allowed with -wasm-enable-sjlj");
162+
163+
if (TM->Options.ExceptionModel == ExceptionHandling::None) {
164+
// FIXME: These flags should be removed in favor of directly using the
165+
// generically configured ExceptionsType
166+
if (WebAssembly::WasmEnableEH || WebAssembly::WasmEnableSjLj)
167+
TM->Options.ExceptionModel = ExceptionHandling::Wasm;
168+
}
169+
170+
// Basic Correctness checking related to -exception-model
171+
if (TM->Options.ExceptionModel != ExceptionHandling::None &&
172+
TM->Options.ExceptionModel != ExceptionHandling::Wasm)
173+
report_fatal_error("-exception-model should be either 'none' or 'wasm'");
174+
if (WasmEnableEmEH && TM->Options.ExceptionModel == ExceptionHandling::Wasm)
175+
report_fatal_error("-exception-model=wasm not allowed with "
176+
"-enable-emscripten-cxx-exceptions");
177+
if (WasmEnableEH && TM->Options.ExceptionModel != ExceptionHandling::Wasm)
178+
report_fatal_error(
179+
"-wasm-enable-eh only allowed with -exception-model=wasm");
180+
if (WasmEnableSjLj && TM->Options.ExceptionModel != ExceptionHandling::Wasm)
181+
report_fatal_error(
182+
"-wasm-enable-sjlj only allowed with -exception-model=wasm");
183+
if ((!WasmEnableEH && !WasmEnableSjLj) &&
184+
TM->Options.ExceptionModel == ExceptionHandling::Wasm)
185+
report_fatal_error(
186+
"-exception-model=wasm only allowed with at least one of "
187+
"-wasm-enable-eh or -wasm-enable-sjlj");
188+
189+
// Currently it is allowed to mix Wasm EH with Emscripten SjLj as an interim
190+
// measure, but some code will error out at compile time in this combination.
191+
// See WebAssemblyLowerEmscriptenEHSjLj pass for details.
192+
}
193+
114194
/// Create an WebAssembly architecture model.
115195
///
116196
WebAssemblyTargetMachine::WebAssemblyTargetMachine(
@@ -149,7 +229,7 @@ WebAssemblyTargetMachine::WebAssemblyTargetMachine(
149229
this->Options.UniqueSectionNames = true;
150230

151231
initAsmInfo();
152-
232+
basicCheckForEHAndSjLj(this);
153233
// Note that we don't use setRequiresStructuredCFG(true). It disables
154234
// optimizations than we're ok with, and want, such as critical edge
155235
// splitting and tail merging.
@@ -400,61 +480,6 @@ FunctionPass *WebAssemblyPassConfig::createTargetRegisterAllocator(bool) {
400480
return nullptr; // No reg alloc
401481
}
402482

403-
using WebAssembly::WasmEnableEH;
404-
using WebAssembly::WasmEnableEmEH;
405-
using WebAssembly::WasmEnableEmSjLj;
406-
using WebAssembly::WasmEnableSjLj;
407-
408-
static void basicCheckForEHAndSjLj(TargetMachine *TM) {
409-
410-
// You can't enable two modes of EH at the same time
411-
if (WasmEnableEmEH && WasmEnableEH)
412-
report_fatal_error(
413-
"-enable-emscripten-cxx-exceptions not allowed with -wasm-enable-eh");
414-
// You can't enable two modes of SjLj at the same time
415-
if (WasmEnableEmSjLj && WasmEnableSjLj)
416-
report_fatal_error(
417-
"-enable-emscripten-sjlj not allowed with -wasm-enable-sjlj");
418-
// You can't mix Emscripten EH with Wasm SjLj.
419-
if (WasmEnableEmEH && WasmEnableSjLj)
420-
report_fatal_error(
421-
"-enable-emscripten-cxx-exceptions not allowed with -wasm-enable-sjlj");
422-
423-
// Here we make sure TargetOptions.ExceptionModel is the same as
424-
// MCAsmInfo.ExceptionsType. Normally these have to be the same, because clang
425-
// stores the exception model info in LangOptions, which is later transferred
426-
// to TargetOptions and MCAsmInfo. But when clang compiles bitcode directly,
427-
// clang's LangOptions is not used and thus the exception model info is not
428-
// correctly transferred to TargetOptions and MCAsmInfo, so we make sure we
429-
// have the correct exception model in WebAssemblyMCAsmInfo constructor. But
430-
// in this case TargetOptions is still not updated, so we make sure they are
431-
// the same.
432-
TM->Options.ExceptionModel = TM->getMCAsmInfo()->getExceptionHandlingType();
433-
434-
// Basic Correctness checking related to -exception-model
435-
if (TM->Options.ExceptionModel != ExceptionHandling::None &&
436-
TM->Options.ExceptionModel != ExceptionHandling::Wasm)
437-
report_fatal_error("-exception-model should be either 'none' or 'wasm'");
438-
if (WasmEnableEmEH && TM->Options.ExceptionModel == ExceptionHandling::Wasm)
439-
report_fatal_error("-exception-model=wasm not allowed with "
440-
"-enable-emscripten-cxx-exceptions");
441-
if (WasmEnableEH && TM->Options.ExceptionModel != ExceptionHandling::Wasm)
442-
report_fatal_error(
443-
"-wasm-enable-eh only allowed with -exception-model=wasm");
444-
if (WasmEnableSjLj && TM->Options.ExceptionModel != ExceptionHandling::Wasm)
445-
report_fatal_error(
446-
"-wasm-enable-sjlj only allowed with -exception-model=wasm");
447-
if ((!WasmEnableEH && !WasmEnableSjLj) &&
448-
TM->Options.ExceptionModel == ExceptionHandling::Wasm)
449-
report_fatal_error(
450-
"-exception-model=wasm only allowed with at least one of "
451-
"-wasm-enable-eh or -wasm-enable-sjlj");
452-
453-
// Currently it is allowed to mix Wasm EH with Emscripten SjLj as an interim
454-
// measure, but some code will error out at compile time in this combination.
455-
// See WebAssemblyLowerEmscriptenEHSjLj pass for details.
456-
}
457-
458483
//===----------------------------------------------------------------------===//
459484
// The following functions are called from lib/CodeGen/Passes.cpp to modify
460485
// the CodeGen pass sequence.
@@ -475,8 +500,6 @@ void WebAssemblyPassConfig::addIRPasses() {
475500
if (getOptLevel() != CodeGenOptLevel::None)
476501
addPass(createWebAssemblyOptimizeReturned());
477502

478-
basicCheckForEHAndSjLj(TM);
479-
480503
// If exception handling is not enabled and setjmp/longjmp handling is
481504
// enabled, we lower invokes into calls and delete unreachable landingpad
482505
// blocks. Lowering invokes when there is no EH support is done in

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;

llvm/test/CodeGen/WebAssembly/cfg-stackify-eh-legacy.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# RUN: llc -mtriple=wasm32-unknown-unknown -wasm-use-legacy-eh -exception-model=wasm -mattr=+exception-handling -run-pass wasm-cfg-stackify %s -o - | FileCheck %s
1+
# RUN: llc -mtriple=wasm32-unknown-unknown -wasm-use-legacy-eh -wasm-enable-sjlj -exception-model=wasm -mattr=+exception-handling -run-pass wasm-cfg-stackify %s -o - | FileCheck %s
22

33
--- |
44
target triple = "wasm32-unknown-unknown"

0 commit comments

Comments
 (0)