diff options
author | Matt Arsenault <Matthew.Arsenault@amd.com> | 2025-07-03 07:25:38 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-07-03 07:25:38 +0900 |
commit | 6ab7e52dd80dc2ece12cc7f1924a71f1a58e2a8a (patch) | |
tree | 0fc7a95432af03055873fc4914cb4c80f38ad2ec /llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp | |
parent | d4331344ac45979f5bc58508d7e186f86fe907bd (diff) | |
download | llvm-6ab7e52dd80dc2ece12cc7f1924a71f1a58e2a8a.zip llvm-6ab7e52dd80dc2ece12cc7f1924a71f1a58e2a8a.tar.gz llvm-6ab7e52dd80dc2ece12cc7f1924a71f1a58e2a8a.tar.bz2 |
WebAssembly: Move validation of EH flags to TargetMachine construct time (#146634)
Diffstat (limited to 'llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp')
-rw-r--r-- | llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp | 110 |
1 files changed, 52 insertions, 58 deletions
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp index 378af22..3e964be 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp @@ -111,6 +111,57 @@ static Reloc::Model getEffectiveRelocModel(std::optional<Reloc::Model> RM, return *RM; } +using WebAssembly::WasmEnableEH; +using WebAssembly::WasmEnableEmEH; +using WebAssembly::WasmEnableEmSjLj; +using WebAssembly::WasmEnableSjLj; + +static void basicCheckForEHAndSjLj(TargetMachine *TM) { + + // You can't enable two modes of EH at the same time + if (WasmEnableEmEH && WasmEnableEH) + report_fatal_error( + "-enable-emscripten-cxx-exceptions not allowed with -wasm-enable-eh"); + // You can't enable two modes of SjLj at the same time + if (WasmEnableEmSjLj && WasmEnableSjLj) + report_fatal_error( + "-enable-emscripten-sjlj not allowed with -wasm-enable-sjlj"); + // You can't mix Emscripten EH with Wasm SjLj. + if (WasmEnableEmEH && WasmEnableSjLj) + report_fatal_error( + "-enable-emscripten-cxx-exceptions not allowed with -wasm-enable-sjlj"); + + if (TM->Options.ExceptionModel == ExceptionHandling::None) { + // FIXME: These flags should be removed in favor of directly using the + // generically configured ExceptionsType + if (WebAssembly::WasmEnableEH || WebAssembly::WasmEnableSjLj) + TM->Options.ExceptionModel = ExceptionHandling::Wasm; + } + + // Basic Correctness checking related to -exception-model + if (TM->Options.ExceptionModel != ExceptionHandling::None && + TM->Options.ExceptionModel != ExceptionHandling::Wasm) + report_fatal_error("-exception-model should be either 'none' or 'wasm'"); + if (WasmEnableEmEH && TM->Options.ExceptionModel == ExceptionHandling::Wasm) + report_fatal_error("-exception-model=wasm not allowed with " + "-enable-emscripten-cxx-exceptions"); + if (WasmEnableEH && TM->Options.ExceptionModel != ExceptionHandling::Wasm) + report_fatal_error( + "-wasm-enable-eh only allowed with -exception-model=wasm"); + if (WasmEnableSjLj && TM->Options.ExceptionModel != ExceptionHandling::Wasm) + report_fatal_error( + "-wasm-enable-sjlj only allowed with -exception-model=wasm"); + if ((!WasmEnableEH && !WasmEnableSjLj) && + TM->Options.ExceptionModel == ExceptionHandling::Wasm) + report_fatal_error( + "-exception-model=wasm only allowed with at least one of " + "-wasm-enable-eh or -wasm-enable-sjlj"); + + // Currently it is allowed to mix Wasm EH with Emscripten SjLj as an interim + // measure, but some code will error out at compile time in this combination. + // See WebAssemblyLowerEmscriptenEHSjLj pass for details. +} + /// Create an WebAssembly architecture model. /// WebAssemblyTargetMachine::WebAssemblyTargetMachine( @@ -149,7 +200,7 @@ WebAssemblyTargetMachine::WebAssemblyTargetMachine( this->Options.UniqueSectionNames = true; initAsmInfo(); - + basicCheckForEHAndSjLj(this); // Note that we don't use setRequiresStructuredCFG(true). It disables // optimizations than we're ok with, and want, such as critical edge // splitting and tail merging. @@ -400,61 +451,6 @@ FunctionPass *WebAssemblyPassConfig::createTargetRegisterAllocator(bool) { return nullptr; // No reg alloc } -using WebAssembly::WasmEnableEH; -using WebAssembly::WasmEnableEmEH; -using WebAssembly::WasmEnableEmSjLj; -using WebAssembly::WasmEnableSjLj; - -static void basicCheckForEHAndSjLj(TargetMachine *TM) { - - // You can't enable two modes of EH at the same time - if (WasmEnableEmEH && WasmEnableEH) - report_fatal_error( - "-enable-emscripten-cxx-exceptions not allowed with -wasm-enable-eh"); - // You can't enable two modes of SjLj at the same time - if (WasmEnableEmSjLj && WasmEnableSjLj) - report_fatal_error( - "-enable-emscripten-sjlj not allowed with -wasm-enable-sjlj"); - // You can't mix Emscripten EH with Wasm SjLj. - if (WasmEnableEmEH && WasmEnableSjLj) - report_fatal_error( - "-enable-emscripten-cxx-exceptions not allowed with -wasm-enable-sjlj"); - - // Here we make sure TargetOptions.ExceptionModel is the same as - // MCAsmInfo.ExceptionsType. Normally these have to be the same, because clang - // stores the exception model info in LangOptions, which is later transferred - // to TargetOptions and MCAsmInfo. But when clang compiles bitcode directly, - // clang's LangOptions is not used and thus the exception model info is not - // correctly transferred to TargetOptions and MCAsmInfo, so we make sure we - // have the correct exception model in WebAssemblyMCAsmInfo constructor. But - // in this case TargetOptions is still not updated, so we make sure they are - // the same. - TM->Options.ExceptionModel = TM->getMCAsmInfo()->getExceptionHandlingType(); - - // Basic Correctness checking related to -exception-model - if (TM->Options.ExceptionModel != ExceptionHandling::None && - TM->Options.ExceptionModel != ExceptionHandling::Wasm) - report_fatal_error("-exception-model should be either 'none' or 'wasm'"); - if (WasmEnableEmEH && TM->Options.ExceptionModel == ExceptionHandling::Wasm) - report_fatal_error("-exception-model=wasm not allowed with " - "-enable-emscripten-cxx-exceptions"); - if (WasmEnableEH && TM->Options.ExceptionModel != ExceptionHandling::Wasm) - report_fatal_error( - "-wasm-enable-eh only allowed with -exception-model=wasm"); - if (WasmEnableSjLj && TM->Options.ExceptionModel != ExceptionHandling::Wasm) - report_fatal_error( - "-wasm-enable-sjlj only allowed with -exception-model=wasm"); - if ((!WasmEnableEH && !WasmEnableSjLj) && - TM->Options.ExceptionModel == ExceptionHandling::Wasm) - report_fatal_error( - "-exception-model=wasm only allowed with at least one of " - "-wasm-enable-eh or -wasm-enable-sjlj"); - - // Currently it is allowed to mix Wasm EH with Emscripten SjLj as an interim - // measure, but some code will error out at compile time in this combination. - // See WebAssemblyLowerEmscriptenEHSjLj pass for details. -} - //===----------------------------------------------------------------------===// // The following functions are called from lib/CodeGen/Passes.cpp to modify // the CodeGen pass sequence. @@ -475,8 +471,6 @@ void WebAssemblyPassConfig::addIRPasses() { if (getOptLevel() != CodeGenOptLevel::None) addPass(createWebAssemblyOptimizeReturned()); - basicCheckForEHAndSjLj(TM); - // If exception handling is not enabled and setjmp/longjmp handling is // enabled, we lower invokes into calls and delete unreachable landingpad // blocks. Lowering invokes when there is no EH support is done in |