@@ -111,6 +111,57 @@ static Reloc::Model getEffectiveRelocModel(std::optional<Reloc::Model> RM,
111
111
return *RM;
112
112
}
113
113
114
+ using WebAssembly::WasmEnableEH;
115
+ using WebAssembly::WasmEnableEmEH;
116
+ using WebAssembly::WasmEnableEmSjLj;
117
+ using WebAssembly::WasmEnableSjLj;
118
+
119
+ static void basicCheckForEHAndSjLj (TargetMachine *TM) {
120
+
121
+ // You can't enable two modes of EH at the same time
122
+ if (WasmEnableEmEH && WasmEnableEH)
123
+ report_fatal_error (
124
+ " -enable-emscripten-cxx-exceptions not allowed with -wasm-enable-eh" );
125
+ // You can't enable two modes of SjLj at the same time
126
+ if (WasmEnableEmSjLj && WasmEnableSjLj)
127
+ report_fatal_error (
128
+ " -enable-emscripten-sjlj not allowed with -wasm-enable-sjlj" );
129
+ // You can't mix Emscripten EH with Wasm SjLj.
130
+ if (WasmEnableEmEH && WasmEnableSjLj)
131
+ report_fatal_error (
132
+ " -enable-emscripten-cxx-exceptions not allowed with -wasm-enable-sjlj" );
133
+
134
+ if (TM->Options .ExceptionModel == ExceptionHandling::None) {
135
+ // FIXME: These flags should be removed in favor of directly using the
136
+ // generically configured ExceptionsType
137
+ if (WebAssembly::WasmEnableEH || WebAssembly::WasmEnableSjLj)
138
+ TM->Options .ExceptionModel = ExceptionHandling::Wasm;
139
+ }
140
+
141
+ // Basic Correctness checking related to -exception-model
142
+ if (TM->Options .ExceptionModel != ExceptionHandling::None &&
143
+ TM->Options .ExceptionModel != ExceptionHandling::Wasm)
144
+ report_fatal_error (" -exception-model should be either 'none' or 'wasm'" );
145
+ if (WasmEnableEmEH && TM->Options .ExceptionModel == ExceptionHandling::Wasm)
146
+ report_fatal_error (" -exception-model=wasm not allowed with "
147
+ " -enable-emscripten-cxx-exceptions" );
148
+ if (WasmEnableEH && TM->Options .ExceptionModel != ExceptionHandling::Wasm)
149
+ report_fatal_error (
150
+ " -wasm-enable-eh only allowed with -exception-model=wasm" );
151
+ if (WasmEnableSjLj && TM->Options .ExceptionModel != ExceptionHandling::Wasm)
152
+ report_fatal_error (
153
+ " -wasm-enable-sjlj only allowed with -exception-model=wasm" );
154
+ if ((!WasmEnableEH && !WasmEnableSjLj) &&
155
+ TM->Options .ExceptionModel == ExceptionHandling::Wasm)
156
+ report_fatal_error (
157
+ " -exception-model=wasm only allowed with at least one of "
158
+ " -wasm-enable-eh or -wasm-enable-sjlj" );
159
+
160
+ // Currently it is allowed to mix Wasm EH with Emscripten SjLj as an interim
161
+ // measure, but some code will error out at compile time in this combination.
162
+ // See WebAssemblyLowerEmscriptenEHSjLj pass for details.
163
+ }
164
+
114
165
// / Create an WebAssembly architecture model.
115
166
// /
116
167
WebAssemblyTargetMachine::WebAssemblyTargetMachine (
@@ -149,7 +200,7 @@ WebAssemblyTargetMachine::WebAssemblyTargetMachine(
149
200
this ->Options .UniqueSectionNames = true ;
150
201
151
202
initAsmInfo ();
152
-
203
+ basicCheckForEHAndSjLj ( this );
153
204
// Note that we don't use setRequiresStructuredCFG(true). It disables
154
205
// optimizations than we're ok with, and want, such as critical edge
155
206
// splitting and tail merging.
@@ -400,61 +451,6 @@ FunctionPass *WebAssemblyPassConfig::createTargetRegisterAllocator(bool) {
400
451
return nullptr ; // No reg alloc
401
452
}
402
453
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
-
458
454
// ===----------------------------------------------------------------------===//
459
455
// The following functions are called from lib/CodeGen/Passes.cpp to modify
460
456
// the CodeGen pass sequence.
@@ -475,8 +471,6 @@ void WebAssemblyPassConfig::addIRPasses() {
475
471
if (getOptLevel () != CodeGenOptLevel::None)
476
472
addPass (createWebAssemblyOptimizeReturned ());
477
473
478
- basicCheckForEHAndSjLj (TM);
479
-
480
474
// If exception handling is not enabled and setjmp/longjmp handling is
481
475
// enabled, we lower invokes into calls and delete unreachable landingpad
482
476
// blocks. Lowering invokes when there is no EH support is done in
0 commit comments