Skip to content

Commit 7ac1dc5

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 7502af8 commit 7ac1dc5

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"

0 commit comments

Comments
 (0)