Index: llvm/trunk/include/llvm/CodeGen/CommandFlags.def =================================================================== --- llvm/trunk/include/llvm/CodeGen/CommandFlags.def +++ llvm/trunk/include/llvm/CodeGen/CommandFlags.def @@ -98,7 +98,9 @@ clEnumValN(ExceptionHandling::SjLj, "sjlj", "SjLj exception handling"), clEnumValN(ExceptionHandling::ARM, "arm", "ARM EHABI exceptions"), clEnumValN(ExceptionHandling::WinEH, "wineh", - "Windows exception model"))); + "Windows exception model"), + clEnumValN(ExceptionHandling::Wasm, "wasm", + "WebAssembly exception handling"))); static cl::opt FileType( "filetype", cl::init(TargetMachine::CGFT_AssemblyFile), Index: llvm/trunk/include/llvm/MC/MCTargetOptions.h =================================================================== --- llvm/trunk/include/llvm/MC/MCTargetOptions.h +++ llvm/trunk/include/llvm/MC/MCTargetOptions.h @@ -21,6 +21,7 @@ SjLj, /// setjmp/longjmp based exceptions ARM, /// ARM EHABI WinEH, /// Windows Exception Handling + Wasm, /// WebAssembly Exception Handling }; enum class DebugCompressionType { Index: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp =================================================================== --- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -353,6 +353,9 @@ break; } break; + case ExceptionHandling::Wasm: + // TODO to prevent warning + break; } if (ES) Handlers.push_back(HandlerInfo(ES, EHTimerName, EHTimerDescription, Index: llvm/trunk/lib/CodeGen/TargetPassConfig.cpp =================================================================== --- llvm/trunk/lib/CodeGen/TargetPassConfig.cpp +++ llvm/trunk/lib/CodeGen/TargetPassConfig.cpp @@ -653,6 +653,9 @@ addPass(createWinEHPass()); addPass(createDwarfEHPass()); break; + case ExceptionHandling::Wasm: + // TODO to prevent warning + break; case ExceptionHandling::None: addPass(createLowerInvokePass()); Index: llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCAsmInfo.cpp =================================================================== --- llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCAsmInfo.cpp +++ llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCAsmInfo.cpp @@ -43,9 +43,6 @@ SupportsDebugInformation = true; - // For now, WebAssembly does not support exceptions. - ExceptionsType = ExceptionHandling::None; - // TODO: UseIntegratedAssembler? // WebAssembly's stack is never executable. @@ -76,8 +73,5 @@ SupportsDebugInformation = true; - // For now, WebAssembly does not support exceptions. - ExceptionsType = ExceptionHandling::None; - // TODO: UseIntegratedAssembler? } Index: llvm/trunk/lib/Target/WebAssembly/WebAssembly.td =================================================================== --- llvm/trunk/lib/Target/WebAssembly/WebAssembly.td +++ llvm/trunk/lib/Target/WebAssembly/WebAssembly.td @@ -37,6 +37,10 @@ "HasSignExt", "true", "Enable sign extension operators">; +def FeatureExceptionHandling : + SubtargetFeature<"exception-handling", "HasExceptionHandling", "true", + "Enable Wasm exception handling">; + //===----------------------------------------------------------------------===// // Architectures. //===----------------------------------------------------------------------===// Index: llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrInfo.td =================================================================== --- llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrInfo.td +++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyInstrInfo.td @@ -39,6 +39,16 @@ AssemblerPredicate<"!FeatureSignExt", "sign-ext">; +def HasExceptionHandling : + Predicate<"Subtarget->hasExceptionHandling()">, + AssemblerPredicate<"FeatureExceptionHandling", + "exception-handling">; + +def NotHasExceptionHandling : + Predicate<"!Subtarget->hasExceptionHandling()">, + AssemblerPredicate<"!FeatureExceptionHandling", + "exception-handling">; + //===----------------------------------------------------------------------===// // WebAssembly-specific DAG Node Types. //===----------------------------------------------------------------------===// Index: llvm/trunk/lib/Target/WebAssembly/WebAssemblySubtarget.h =================================================================== --- llvm/trunk/lib/Target/WebAssembly/WebAssemblySubtarget.h +++ llvm/trunk/lib/Target/WebAssembly/WebAssemblySubtarget.h @@ -33,6 +33,7 @@ bool HasAtomics; bool HasNontrappingFPToInt; bool HasSignExt; + bool HasExceptionHandling; /// String name of used CPU. std::string CPUString; @@ -80,6 +81,7 @@ bool hasAtomics() const { return HasAtomics; } bool hasNontrappingFPToInt() const { return HasNontrappingFPToInt; } bool hasSignExt() const { return HasSignExt; } + bool hasExceptionHandling() const { return HasExceptionHandling; } /// Parses features string setting specified subtarget options. Definition of /// function is auto generated by tblgen. Index: llvm/trunk/lib/Target/WebAssembly/WebAssemblySubtarget.cpp =================================================================== --- llvm/trunk/lib/Target/WebAssembly/WebAssemblySubtarget.cpp +++ llvm/trunk/lib/Target/WebAssembly/WebAssemblySubtarget.cpp @@ -42,8 +42,8 @@ const TargetMachine &TM) : WebAssemblyGenSubtargetInfo(TT, CPU, FS), HasSIMD128(false), HasAtomics(false), HasNontrappingFPToInt(false), HasSignExt(false), - CPUString(CPU), TargetTriple(TT), FrameLowering(), - InstrInfo(initializeSubtargetDependencies(FS)), TSInfo(), + HasExceptionHandling(false), CPUString(CPU), TargetTriple(TT), + FrameLowering(), InstrInfo(initializeSubtargetDependencies(FS)), TSInfo(), TLInfo(TM, *this) {} bool WebAssemblySubtarget::enableMachineScheduler() const { Index: llvm/trunk/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp =================================================================== --- llvm/trunk/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp +++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp @@ -190,7 +190,8 @@ // blocks. Lowering invokes when there is no EH support is done in // TargetPassConfig::addPassesToHandleExceptions, but this runs after this // function and SjLj handling expects all invokes to be lowered before. - if (!EnableEmException) { + if (!EnableEmException && + TM->Options.ExceptionModel == ExceptionHandling::None) { addPass(createLowerInvokePass()); // The lower invoke pass may create unreachable code. Remove it in order not // to process dead blocks in setjmp/longjmp handling.