[llvm-branch-commits] [clang] [llvm] CodeGen: Remove TargetOptions::ExceptionModel (PR #232977)
Matt Arsenault via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Oct 16 16:05:30 PDT 2026
https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/232977
The exception model now comes only from the "exception-model" module
flag. Remove the TargetOptions field and its copy into MCAsmInfo, so
MCAsmInfo only knows the target's default model.
The WebAssembly model checks move from the TargetMachine constructor
into the Emscripten EH/SjLj lowering pass. Clang relied on the backend
to reject non-wasm models for wasm targets, so it now rejects them
itself.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
>From dbf490f538a54616132fd7c0a1bf93820628998d Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Wed, 14 Oct 2026 21:52:32 +0200
Subject: [PATCH] CodeGen: Remove TargetOptions::ExceptionModel
The exception model now comes only from the "exception-model" module
flag. Remove the TargetOptions field and its copy into MCAsmInfo, so
MCAsmInfo only knows the target's default model.
The WebAssembly model checks move from the TargetMachine constructor
into the Emscripten EH/SjLj lowering pass. Clang relied on the backend
to reject non-wasm models for wasm targets, so it now rejects them
itself.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
---
clang/lib/CodeGen/BackendUtil.cpp | 11 -------
clang/lib/Frontend/CompilerInvocation.cpp | 6 ++++
...asm-exception-model-flag-parse-ir-input.ll | 7 ++--
llvm/include/llvm/MC/MCAsmInfo.h | 30 ++++++++---------
llvm/include/llvm/Target/TargetOptions.h | 3 --
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 9 +++--
.../CodeGen/AsmPrinter/DwarfCFIException.cpp | 7 ++--
llvm/lib/CodeGen/AsmPrinter/EHStreamer.cpp | 2 +-
llvm/lib/CodeGen/CFIInstrInserter.cpp | 4 +++
llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp | 3 --
llvm/lib/CodeGen/CommandFlags.cpp | 1 -
llvm/lib/CodeGen/MachineFunction.cpp | 7 ++--
.../SelectionDAG/SelectionDAGBuilder.cpp | 3 +-
llvm/lib/CodeGen/TargetLoweringBase.cpp | 2 +-
.../CodeGen/TargetLoweringObjectFileImpl.cpp | 2 +-
llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp | 4 +--
llvm/lib/Target/ARM/ARMAsmPrinter.cpp | 4 +--
llvm/lib/Target/ARM/ARMTargetObjectFile.cpp | 3 +-
llvm/lib/Target/ARM/ARMTargetObjectFile.h | 2 ++
.../WebAssemblyLowerEmscriptenEHSjLj.cpp | 11 +++++--
.../WebAssembly/WebAssemblyTargetMachine.cpp | 33 ++-----------------
llvm/lib/Target/X86/X86CodeGenPassBuilder.cpp | 8 ++---
llvm/lib/Target/X86/X86MCInstLower.cpp | 2 +-
llvm/lib/Target/X86/X86TargetMachine.cpp | 8 ++---
llvm/test/CodeGen/AMDGPU/exception-model.ll | 26 ++++++++++++---
llvm/test/CodeGen/X86/llc-pipeline-npm.ll | 2 ++
26 files changed, 93 insertions(+), 107 deletions(-)
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 77c53c612df8f..7b993f08280c2 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -392,17 +392,6 @@ static bool initTargetOptions(const CompilerInstance &CI,
Options.UseInitArray = CodeGenOpts.UseInitArray;
Options.MCOptions.DisableIntegratedAS = CodeGenOpts.DisableIntegratedAS;
- if (CodeGenOpts.hasSjLjExceptions())
- Options.ExceptionModel = llvm::ExceptionHandling::SjLj;
- if (CodeGenOpts.hasSEHExceptions())
- Options.ExceptionModel = llvm::ExceptionHandling::WinEH;
- if (CodeGenOpts.hasDWARFExceptions())
- Options.ExceptionModel = llvm::ExceptionHandling::DwarfCFI;
- if (CodeGenOpts.hasWasmExceptions())
- Options.ExceptionModel = llvm::ExceptionHandling::Wasm;
- if (CodeGenOpts.hasEmscriptenExceptions())
- Options.ExceptionModel = llvm::ExceptionHandling::Emscripten;
-
Options.NoZerosInBSS = CodeGenOpts.NoZeroInitializedInBSS;
Options.BBAddrMap = CodeGenOpts.BBAddrMap;
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index c9281c2a6d6b4..91378a8436a95 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -577,6 +577,12 @@ static bool FixupInvocation(CompilerInvocation &Invocation,
Diags.Report(diag::err_fe_invalid_exception_model)
<< static_cast<unsigned>(CodeGenOpts.getExceptionHandling()) << T.str();
+ if (T.isWasm() &&
+ (CodeGenOpts.hasSjLjExceptions() || CodeGenOpts.hasSEHExceptions() ||
+ CodeGenOpts.hasDWARFExceptions()))
+ Diags.Report(diag::err_fe_invalid_exception_model)
+ << static_cast<unsigned>(CodeGenOpts.getExceptionHandling()) << T.str();
+
if (LangOpts.AppleKext && !LangOpts.CPlusPlus)
Diags.Report(diag::warn_c_kext);
diff --git a/clang/test/CodeGen/WebAssembly/wasm-exception-model-flag-parse-ir-input.ll b/clang/test/CodeGen/WebAssembly/wasm-exception-model-flag-parse-ir-input.ll
index b3ac28b472267..ada198e466f4f 100644
--- a/clang/test/CodeGen/WebAssembly/wasm-exception-model-flag-parse-ir-input.ll
+++ b/clang/test/CodeGen/WebAssembly/wasm-exception-model-flag-parse-ir-input.ll
@@ -5,8 +5,8 @@
; RUN: %clang_cc1 -triple wasm32 -o - -emit-llvm -exception-model=wasm %s | FileCheck -check-prefixes=CHECK,WASM %s
; RUN: not %clang_cc1 -triple wasm32 -o - -emit-llvm -exception-model=invalid %s 2>&1 | FileCheck -check-prefix=ERR %s
-; RUN: not %clang_cc1 -triple wasm32 -o - -emit-llvm -exception-model=dwarf %s 2>&1 | FileCheck -check-prefix=ERR-BE %s
-; RUN: not %clang_cc1 -triple wasm32 -o - -emit-llvm -exception-model=sjlj %s 2>&1 | FileCheck -check-prefix=ERR-BE %s
+; RUN: not %clang_cc1 -triple wasm32 -o - -emit-llvm -exception-model=dwarf %s 2>&1 | FileCheck -check-prefix=ERR-DWARF %s
+; RUN: not %clang_cc1 -triple wasm32 -o - -emit-llvm -exception-model=sjlj %s 2>&1 | FileCheck -check-prefix=ERR-SJLJ %s
; CHECK-LABEL: define void @test(
@@ -15,7 +15,8 @@
; WASM: !{i32 1, !"exception-model", !"wasm"}
; ERR: error: invalid value 'invalid' in '-exception-model=invalid'
-; ERR-BE: fatal error: error in backend: -exception-model should be either 'none', 'wasm', or 'emscripten'
+; ERR-DWARF: error: invalid exception model 'dwarf' for target 'wasm32'
+; ERR-SJLJ: error: invalid exception model 'sjlj' for target 'wasm32'
define void @test() {
ret void
}
diff --git a/llvm/include/llvm/MC/MCAsmInfo.h b/llvm/include/llvm/MC/MCAsmInfo.h
index 3a9f3c3264bc8..6e7b6f1b06c58 100644
--- a/llvm/include/llvm/MC/MCAsmInfo.h
+++ b/llvm/include/llvm/MC/MCAsmInfo.h
@@ -353,11 +353,12 @@ class LLVM_ABI MCAsmInfo {
/// false.
bool SupportsDebugInformation = false;
- /// Exception handling format for the target. Defaults to None.
+ /// Default exception handling model for the target. Defaults to None.
ExceptionHandling ExceptionsType = ExceptionHandling::None;
/// True if target uses CFI unwind information for other purposes than EH
- /// (debugging / sanitizers) when `ExceptionsType == ExceptionHandling::None`.
+ /// (debugging / sanitizers) when the exception model is
+ /// `ExceptionHandling::None`.
bool UsesCFIWithoutEH = false;
/// Windows exception handling data (.pdata) encoding. Defaults to Invalid.
@@ -656,21 +657,16 @@ class LLVM_ABI MCAsmInfo {
ExceptionHandling getExceptionHandlingType() const { return ExceptionsType; }
WinEH::EncodingType getWinEHEncodingType() const { return WinEHEncodingType; }
- void setExceptionsType(ExceptionHandling EH) {
- ExceptionsType = EH;
+ bool usesCFIWithoutEH(ExceptionHandling EH) const {
+ return EH == ExceptionHandling::None && UsesCFIWithoutEH;
}
- bool usesCFIWithoutEH() const {
- return ExceptionsType == ExceptionHandling::None && UsesCFIWithoutEH;
- }
-
- /// Returns true if the exception handling method for the platform uses call
- /// frame information to unwind.
- bool usesCFIForEH() const {
- return (ExceptionsType == ExceptionHandling::DwarfCFI ||
- ExceptionsType == ExceptionHandling::ARM ||
- ExceptionsType == ExceptionHandling::ZOS ||
- (ExceptionsType == ExceptionHandling::WinEH && usesWindowsCFI()));
+ /// Returns true if the exception handling method \p EH uses call frame
+ /// information to unwind.
+ bool usesCFIForEH(ExceptionHandling EH) const {
+ return EH == ExceptionHandling::DwarfCFI || EH == ExceptionHandling::ARM ||
+ EH == ExceptionHandling::ZOS ||
+ (EH == ExceptionHandling::WinEH && usesWindowsCFI());
}
/// Returns true if the object format describes unwind information with
@@ -684,8 +680,8 @@ class LLVM_ABI MCAsmInfo {
/// Returns true if the exception tables reference the per-invoke EH labels
/// emitted around invokes. 32-bit x86 SEH and Wasm do not.
- bool usesPerInvokeEHLabels() const {
- switch (ExceptionsType) {
+ bool usesPerInvokeEHLabels(ExceptionHandling EH) const {
+ switch (EH) {
case ExceptionHandling::WinEH:
// 32-bit x86 SEH uses a state table, not per-invoke IP-to-state ranges.
return WinEHEncodingType != WinEH::EncodingType::X86;
diff --git a/llvm/include/llvm/Target/TargetOptions.h b/llvm/include/llvm/Target/TargetOptions.h
index 264db07ded991..31decfe069eac 100644
--- a/llvm/include/llvm/Target/TargetOptions.h
+++ b/llvm/include/llvm/Target/TargetOptions.h
@@ -311,9 +311,6 @@ class TargetOptions {
VectorLibrary VecLib = VectorLibrary::NoLibrary;
public:
- /// What exception model to use
- ExceptionHandling ExceptionModel = ExceptionHandling::Default;
-
/// Machine level options.
MCTargetOptions MCOptions;
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index bb1c27d86c2e8..35e9d3388a487 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -1419,13 +1419,11 @@ AsmPrinter::getFunctionCFISectionType(const Function &F) const {
if (F.isDeclarationForLinker())
return CFISection::None;
- // A DwarfCFI module only carries EH unwind info if the target actually uses
- // CFI for exceptions.
if (ModuleExceptionModel == ExceptionHandling::DwarfCFI &&
- MAI.usesCFIForEH() && F.needsUnwindTableEntry())
+ F.needsUnwindTableEntry())
return CFISection::EH;
- if (MAI.usesCFIWithoutEH() && F.hasUWTable())
+ if (MAI.usesCFIWithoutEH(ModuleExceptionModel) && F.hasUWTable())
return CFISection::EH;
if (hasDebugInfo() || TM.Options.ForceDwarfFrameSection)
@@ -1440,7 +1438,8 @@ AsmPrinter::getFunctionCFISectionType(const MachineFunction &MF) const {
}
bool AsmPrinter::usesCFIWithoutEH() const {
- return MAI.usesCFIWithoutEH() && ModuleCFISection != CFISection::None;
+ return MAI.usesCFIWithoutEH(ModuleExceptionModel) &&
+ ModuleCFISection != CFISection::None;
}
void AsmPrinter::emitCFIInstruction(const MachineInstr &MI) {
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp
index 3b2feb876eadb..cfd539265012c 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp
@@ -37,7 +37,7 @@ void DwarfCFIException::addPersonality(const GlobalValue *Personality) {
/// content.
void DwarfCFIException::endModule() {
// SjLj uses this pass and it doesn't need this info.
- if (!Asm->MAI.usesCFIForEH())
+ if (!Asm->MAI.usesCFIForEH(Asm->getModuleExceptionModel()))
return;
const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
@@ -92,9 +92,10 @@ void DwarfCFIException::beginFunction(const MachineFunction *MF) {
LSDAEncoding != dwarf::DW_EH_PE_omit;
const MCAsmInfo &MAI = MF->getContext().getAsmInfo();
- if (Asm->getModuleExceptionModel() != ExceptionHandling::None)
+ ExceptionHandling EH = Asm->getModuleExceptionModel();
+ if (EH != ExceptionHandling::None)
shouldEmitCFI =
- MAI.usesCFIForEH() && (shouldEmitPersonality || shouldEmitMoves);
+ (shouldEmitPersonality || shouldEmitMoves) && MAI.usesCFIForEH(EH);
else
shouldEmitCFI = Asm->usesCFIWithoutEH() && shouldEmitMoves;
}
diff --git a/llvm/lib/CodeGen/AsmPrinter/EHStreamer.cpp b/llvm/lib/CodeGen/AsmPrinter/EHStreamer.cpp
index 3fd4494a53ffc..fb4b21b5d8c6a 100644
--- a/llvm/lib/CodeGen/AsmPrinter/EHStreamer.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/EHStreamer.cpp
@@ -297,7 +297,7 @@ void EHStreamer::computeCallSiteTable(
// throw, create a call-site entry with no landing pad for the region
// between the try-ranges.
if (SawPotentiallyThrowing &&
- (Asm->MAI.usesCFIForEH() ||
+ (Asm->MAI.usesCFIForEH(Asm->getModuleExceptionModel()) ||
Asm->getModuleExceptionModel() == ExceptionHandling::AIX)) {
CallSites.push_back({LastLabel, BeginLabel, nullptr, 0});
PreviousIsInvoke = false;
diff --git a/llvm/lib/CodeGen/CFIInstrInserter.cpp b/llvm/lib/CodeGen/CFIInstrInserter.cpp
index a415dee9f3938..da3501330f7b8 100644
--- a/llvm/lib/CodeGen/CFIInstrInserter.cpp
+++ b/llvm/lib/CodeGen/CFIInstrInserter.cpp
@@ -42,6 +42,10 @@ class CFIInstrInserterImpl {
if (!MF.needsFrameMoves())
return false;
+ // Functions with Windows unwind info have no DWARF CFI to fix up.
+ if (MF.usesWindowsUnwindInfo())
+ return false;
+
MBBVector.resize(MF.getNumBlockIDs());
calculateCFAInfo(MF);
diff --git a/llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp b/llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp
index d32895d47369d..f61ab04b04e21 100644
--- a/llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp
+++ b/llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp
@@ -84,9 +84,6 @@ void CodeGenTargetMachineImpl::initAsmInfo() {
getTargetTriple().getDefaultExceptionHandling() &&
"MCAsmInfo and Triple disagree on default exception handling type");
- if (Options.ExceptionModel != ExceptionHandling::Default)
- TmpAsmInfo->setExceptionsType(Options.ExceptionModel);
-
AsmInfo.reset(TmpAsmInfo);
}
diff --git a/llvm/lib/CodeGen/CommandFlags.cpp b/llvm/lib/CodeGen/CommandFlags.cpp
index 3c4652405cb6a..a780abce7e5bb 100644
--- a/llvm/lib/CodeGen/CommandFlags.cpp
+++ b/llvm/lib/CodeGen/CommandFlags.cpp
@@ -539,7 +539,6 @@ codegen::InitTargetOptionsFromCodeGenFlags(const Triple &TheTriple) {
getExplicitEmulatedTLS().value_or(TheTriple.hasDefaultEmulatedTLS());
Options.EnableTLSDESC =
getExplicitEnableTLSDESC().value_or(TheTriple.hasDefaultTLSDESC());
- Options.ExceptionModel = getExceptionModel();
Options.VecLib = getVectorLibrary();
Options.EmitStackSizeSection = getEnableStackSizeSection();
Options.EnableStaticDataPartitioning = getEnableStaticDataPartitioning();
diff --git a/llvm/lib/CodeGen/MachineFunction.cpp b/llvm/lib/CodeGen/MachineFunction.cpp
index b0f06907ef9da..8eca698cc7bee 100644
--- a/llvm/lib/CodeGen/MachineFunction.cpp
+++ b/llvm/lib/CodeGen/MachineFunction.cpp
@@ -749,13 +749,12 @@ bool MachineFunction::needsFrameMoves() const {
}
bool MachineFunction::usesWindowsUnwindInfo() const {
- const MCAsmInfo &MAI = getTarget().getMCAsmInfo();
- return MAI.getExceptionHandlingType() == ExceptionHandling::WinEH &&
- MAI.usesWindowsCFI();
+ return getTarget().getMCAsmInfo().usesWindowsCFI() &&
+ F.getParent()->getExceptionModel() == ExceptionHandling::WinEH;
}
bool MachineFunction::needsWinCFI() const {
- return usesWindowsUnwindInfo() && getFunction().needsUnwindTableEntry();
+ return getFunction().needsUnwindTableEntry() && usesWindowsUnwindInfo();
}
bool MachineFunction::disableFramePointerElim() const {
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index 7ed3ed4ae9b8e..2ef082a432ce5 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -9291,7 +9291,8 @@ SDValue SelectionDAGBuilder::lowerStartEH(SDValue Chain,
// Skip emitting EH_LABEL on targets whose exception tables don't reference
// them (32-bit x86 SEH, Wasm).
- if (!MF.getContext().getAsmInfo().usesPerInvokeEHLabels()) {
+ if (!MF.getContext().getAsmInfo().usesPerInvokeEHLabels(
+ FuncInfo.ExceptionModel)) {
BeginLabel = nullptr;
return Chain;
}
diff --git a/llvm/lib/CodeGen/TargetLoweringBase.cpp b/llvm/lib/CodeGen/TargetLoweringBase.cpp
index 8064f993e0a4e..c7f8a2e1b8915 100644
--- a/llvm/lib/CodeGen/TargetLoweringBase.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringBase.cpp
@@ -717,7 +717,7 @@ RTLIB::Libcall RTLIB::getMEMSET_ELEMENT_UNORDERED_ATOMIC(uint64_t ElementSize) {
TargetLoweringBase::TargetLoweringBase(const TargetMachine &tm,
const TargetSubtargetInfo &STI)
: TM(tm),
- RuntimeLibcallInfo(TM.getTargetTriple(), TM.Options.ExceptionModel,
+ RuntimeLibcallInfo(TM.getTargetTriple(), ExceptionHandling::Default,
TM.getTargetTriple().getDefaultFloatABI(),
TM.Options.MCOptions.getABIName(), TM.Options.VecLib),
Libcalls(RuntimeLibcallInfo, [&STI](LibcallLoweringInfo &Info) {
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index acff5e19b06d7..fa46420336bcc 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -133,7 +133,7 @@ void TargetLoweringObjectFileELF::initialize(MCContext &Ctx,
case Triple::armeb:
case Triple::thumb:
case Triple::thumbeb:
- if (Ctx.getAsmInfo().getExceptionHandlingType() == ExceptionHandling::ARM)
+ if (M.getExceptionModel() == ExceptionHandling::ARM)
break;
// Fallthrough if not using EHABI
[[fallthrough]];
diff --git a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
index 683b8ffb94e43..eb7b3228df9b1 100644
--- a/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
+++ b/llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
@@ -3589,7 +3589,7 @@ void AArch64AsmPrinter::emitInstruction(const MachineInstr *MI) {
return;
case AArch64::EMITBKEY: {
- ExceptionHandling ExceptionHandlingType = MAI.getExceptionHandlingType();
+ ExceptionHandling ExceptionHandlingType = getModuleExceptionModel();
if (ExceptionHandlingType != ExceptionHandling::DwarfCFI &&
ExceptionHandlingType != ExceptionHandling::ARM)
return;
@@ -3602,7 +3602,7 @@ void AArch64AsmPrinter::emitInstruction(const MachineInstr *MI) {
}
case AArch64::EMITMTETAGGED: {
- ExceptionHandling ExceptionHandlingType = MAI.getExceptionHandlingType();
+ ExceptionHandling ExceptionHandlingType = getModuleExceptionModel();
if (ExceptionHandlingType != ExceptionHandling::DwarfCFI &&
ExceptionHandlingType != ExceptionHandling::ARM)
return;
diff --git a/llvm/lib/Target/ARM/ARMAsmPrinter.cpp b/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
index 9bbd029495a79..d118a21d56001 100644
--- a/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
+++ b/llvm/lib/Target/ARM/ARMAsmPrinter.cpp
@@ -1411,7 +1411,7 @@ void ARMAsmPrinter::EmitUnwindingInstruction(const MachineInstr *MI) {
PadBefore = -MI->getOperand(4).getImm() - 8;
break;
}
- if (MAI.getExceptionHandlingType() == ExceptionHandling::ARM) {
+ if (getModuleExceptionModel() == ExceptionHandling::ARM) {
if (PadBefore)
ATS.emitPad(PadBefore);
ATS.emitRegSave(RegList, Opc == ARM::VSTMDDB_UPD);
@@ -1462,7 +1462,7 @@ void ARMAsmPrinter::EmitUnwindingInstruction(const MachineInstr *MI) {
break;
}
- if (MAI.getExceptionHandlingType() == ExceptionHandling::ARM) {
+ if (getModuleExceptionModel() == ExceptionHandling::ARM) {
if (DstReg == FramePtr && FramePtr != ARM::SP)
// Set-up of the frame pointer. Positive values correspond to "add"
// instruction.
diff --git a/llvm/lib/Target/ARM/ARMTargetObjectFile.cpp b/llvm/lib/Target/ARM/ARMTargetObjectFile.cpp
index 6e0606f9d9d5c..2b92c9e29a463 100644
--- a/llvm/lib/Target/ARM/ARMTargetObjectFile.cpp
+++ b/llvm/lib/Target/ARM/ARMTargetObjectFile.cpp
@@ -41,6 +41,7 @@ void ARMElfTargetObjectFile::initialize(MCContext &Ctx, const TargetMachine &TM,
ARM_TM.getMCSubtargetInfo().hasFeature(ARM::FeatureExecuteOnly);
TargetLoweringObjectFileELF::initialize(Ctx, TM, M);
+ UsesARMEH = M.getExceptionModel() == ExceptionHandling::ARM;
// Make code section unreadable when in execute-only mode
if (genExecuteOnly) {
@@ -81,7 +82,7 @@ getIndirectSymViaRWPI(const MCSymbol *Sym) const {
const MCExpr *ARMElfTargetObjectFile::getTTypeGlobalReference(
const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
MachineModuleInfo *MMI, MCStreamer &Streamer) const {
- if (TM.getMCAsmInfo().getExceptionHandlingType() != ExceptionHandling::ARM)
+ if (!UsesARMEH)
return TargetLoweringObjectFileELF::getTTypeGlobalReference(
GV, Encoding, TM, MMI, Streamer);
diff --git a/llvm/lib/Target/ARM/ARMTargetObjectFile.h b/llvm/lib/Target/ARM/ARMTargetObjectFile.h
index 221a4be6579c6..b4b6777480fd2 100644
--- a/llvm/lib/Target/ARM/ARMTargetObjectFile.h
+++ b/llvm/lib/Target/ARM/ARMTargetObjectFile.h
@@ -16,6 +16,8 @@
namespace llvm {
class ARMElfTargetObjectFile : public TargetLoweringObjectFileELF {
+ bool UsesARMEH = false;
+
public:
ARMElfTargetObjectFile();
void initialize(MCContext &Ctx, const TargetMachine &TM,
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
index 81f9e5603e57b..e8ac89570741f 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
@@ -918,9 +918,16 @@ bool WebAssemblyLowerEmscriptenEHSjLjImpl::runOnModule(Module &M) {
LLVM_DEBUG(dbgs() << "********** Lower Emscripten EH & SjLj **********\n");
ExceptionHandling EH = M.getExceptionModel();
+ if (EH != ExceptionHandling::None && EH != ExceptionHandling::Wasm &&
+ EH != ExceptionHandling::Emscripten)
+ report_fatal_error(
+ "-exception-model should be either 'none', 'wasm', or 'emscripten'");
+
EnableEmEH = EH == ExceptionHandling::Emscripten;
- assert((!EnableEmEH || !EnableWasmSjLj) &&
- "Wasm SjLj should be only used with Wasm EH");
+ // You can't mix Emscripten EH with Wasm SjLj.
+ if (EnableEmEH && EnableWasmSjLj)
+ report_fatal_error(
+ "-exception-model=emscripten not allowed with -wasm-enable-sjlj");
bool Changed = false;
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
index cd3ae6215746a..742c2541a2d58 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
@@ -128,40 +128,11 @@ using WebAssembly::WasmDisableExplicitLocals;
using WebAssembly::WasmEnableEmSjLj;
using WebAssembly::WasmEnableSjLj;
-static void basicCheckForEHAndSjLj(TargetMachine *TM) {
-
- bool EnableEmEH = TM->Options.ExceptionModel == ExceptionHandling::Emscripten;
-
+static void basicCheckForEHAndSjLj() {
// 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 (EnableEmEH && WasmEnableSjLj)
- report_fatal_error(
- "-exception-model=emscripten not allowed with -wasm-enable-sjlj");
-
- if (TM->Options.ExceptionModel == ExceptionHandling::Default) {
- // FIXME: This flag should be removed in favor of directly using the
- // generically configured ExceptionsType.
- if (WebAssembly::WasmEnableSjLj)
- TM->Options.ExceptionModel = ExceptionHandling::Wasm;
- }
-
- // Basic Correctness checking related to -exception-model
- if (TM->Options.ExceptionModel != ExceptionHandling::Default &&
- TM->Options.ExceptionModel != ExceptionHandling::None &&
- TM->Options.ExceptionModel != ExceptionHandling::Wasm &&
- TM->Options.ExceptionModel != ExceptionHandling::Emscripten)
- report_fatal_error(
- "-exception-model should be either 'none', 'wasm', or 'emscripten'");
- if (WasmEnableSjLj && TM->Options.ExceptionModel != ExceptionHandling::Wasm)
- report_fatal_error(
- "-wasm-enable-sjlj only allowed with -exception-model=wasm");
-
- // 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.
@@ -190,7 +161,7 @@ WebAssemblyTargetMachine::WebAssemblyTargetMachine(
this->Options.DataSections = true;
this->Options.UniqueSectionNames = true;
- basicCheckForEHAndSjLj(this);
+ basicCheckForEHAndSjLj();
initAsmInfo();
// WebAssembly does not run RegAllocFast; tied operands must be lowered by
diff --git a/llvm/lib/Target/X86/X86CodeGenPassBuilder.cpp b/llvm/lib/Target/X86/X86CodeGenPassBuilder.cpp
index 058fc04bb9f59..b83d1c8547ff4 100644
--- a/llvm/lib/Target/X86/X86CodeGenPassBuilder.cpp
+++ b/llvm/lib/Target/X86/X86CodeGenPassBuilder.cpp
@@ -243,7 +243,6 @@ void X86CodeGenPassBuilder::addPreEmitPass(PassManagerWrapper &PMW) {
void X86CodeGenPassBuilder::addPreEmitPass2(PassManagerWrapper &PMW) {
const Triple &TT = TM.getTargetTriple();
- const MCAsmInfo &MAI = TM.getMCAsmInfo();
// The X86 Speculative Execution Pass must run after all control
// flow graph modifying passes. As a result it was listed to run right before
@@ -267,10 +266,9 @@ void X86CodeGenPassBuilder::addPreEmitPass2(PassManagerWrapper &PMW) {
// Verify basic block incoming and outgoing cfa offset and register values and
// correct CFA calculation rule where needed by inserting appropriate CFI
- // instructions.
- if (!TT.isOSDarwin() &&
- (!TT.isOSWindows() ||
- MAI.getExceptionHandlingType() == ExceptionHandling::DwarfCFI))
+ // instructions. CFIInstrInserter self-skips targets that do not use DWARF
+ // CFI.
+ if (!TT.isOSDarwin())
addMachineFunctionPass(CFIInstrInserterPass(), PMW);
if (TT.isOSWindows()) {
diff --git a/llvm/lib/Target/X86/X86MCInstLower.cpp b/llvm/lib/Target/X86/X86MCInstLower.cpp
index b18329082cfdb..43f515857c6c0 100644
--- a/llvm/lib/Target/X86/X86MCInstLower.cpp
+++ b/llvm/lib/Target/X86/X86MCInstLower.cpp
@@ -2772,7 +2772,7 @@ void X86AsmPrinter::maybeEmitNopAfterCallForWindowsEH(const MachineInstr *MI) {
// We only need to insert NOPs after CALLs when targeting Windows on AMD64.
// (Don't let the name fool you: Itanium refers to table-based exception
// handling, not the Itanium architecture.)
- if (MAI.getExceptionHandlingType() != ExceptionHandling::WinEH ||
+ if (getModuleExceptionModel() != ExceptionHandling::WinEH ||
MAI.getWinEHEncodingType() != WinEH::EncodingType::Itanium) {
return;
}
diff --git a/llvm/lib/Target/X86/X86TargetMachine.cpp b/llvm/lib/Target/X86/X86TargetMachine.cpp
index ad498dd498d0c..b1d2fab82a563 100644
--- a/llvm/lib/Target/X86/X86TargetMachine.cpp
+++ b/llvm/lib/Target/X86/X86TargetMachine.cpp
@@ -573,7 +573,6 @@ void X86PassConfig::addPreEmitPass() {
void X86PassConfig::addPreEmitPass2() {
const Triple &TT = TM->getTargetTriple();
- const MCAsmInfo &MAI = TM->getMCAsmInfo();
// The X86 Speculative Execution Pass must run after all control
// flow graph modifying passes. As a result it was listed to run right before
@@ -595,10 +594,9 @@ void X86PassConfig::addPreEmitPass2() {
// Verify basic block incoming and outgoing cfa offset and register values and
// correct CFA calculation rule where needed by inserting appropriate CFI
- // instructions.
- if (!TT.isOSDarwin() &&
- (!TT.isOSWindows() ||
- MAI.getExceptionHandlingType() == ExceptionHandling::DwarfCFI))
+ // instructions. CFIInstrInserter self-skips targets that do not use DWARF
+ // CFI.
+ if (!TT.isOSDarwin())
addPass(createCFIInstrInserterLegacy());
if (TT.isOSWindows()) {
diff --git a/llvm/test/CodeGen/AMDGPU/exception-model.ll b/llvm/test/CodeGen/AMDGPU/exception-model.ll
index 1494b8eea8d15..bb3a7bc27fe40 100644
--- a/llvm/test/CodeGen/AMDGPU/exception-model.ll
+++ b/llvm/test/CodeGen/AMDGPU/exception-model.ll
@@ -1,13 +1,14 @@
; AMDGPU supports no exception model, so the invoke is lowered to a call and
-; even a "dwarf" model emits no EH tables or CFI.
+; even a "dwarf" model emits no EH tables. The functions still get CFI, without
+; a personality or LSDA.
; RUN: llc -mtriple=amdgpu9.00-amd-amdhsa < %s | FileCheck %s
; CHECK-LABEL: f:
-; CHECK-NOT: .cfi_startproc
+; CHECK: .cfi_startproc
+; CHECK-NOT: .cfi_personality
; CHECK-NOT: .cfi_lsda
-; CHECK-NOT: gcc_except_table
-; CHECK-NOT: _Unwind
+; CHECK: .cfi_endproc
declare void @g()
declare i32 @__gxx_personality_v0(...)
@@ -21,5 +22,22 @@ lpad:
resume { ptr, i32 } %p
}
+; CHECK-LABEL: f_uwtable:
+; CHECK: .cfi_startproc
+; CHECK-NOT: .cfi_personality
+; CHECK-NOT: .cfi_lsda
+; CHECK: .cfi_endproc
+; CHECK-NOT: gcc_except_table
+; CHECK-NOT: _Unwind
+
+define void @f_uwtable() uwtable personality ptr @__gxx_personality_v0 {
+ invoke void @g() to label %cont unwind label %lpad
+cont:
+ ret void
+lpad:
+ %p = landingpad { ptr, i32 } cleanup
+ resume { ptr, i32 } %p
+}
+
!llvm.module.flags = !{!0}
!0 = !{i32 1, !"exception-model", !"dwarf"}
diff --git a/llvm/test/CodeGen/X86/llc-pipeline-npm.ll b/llvm/test/CodeGen/X86/llc-pipeline-npm.ll
index 1cd2d3f9b7b33..9f0b2eb40c17c 100644
--- a/llvm/test/CodeGen/X86/llc-pipeline-npm.ll
+++ b/llvm/test/CodeGen/X86/llc-pipeline-npm.ll
@@ -280,6 +280,7 @@
; O0-WINDOWS-NEXT: x86-seses
; O0-WINDOWS-NEXT: x86-return-thunks
; O0-WINDOWS-NEXT: x86-avoid-trailing-call
+; O0-WINDOWS-NEXT: cfi-instr-inserter
; O0-WINDOWS-NEXT: eh-cont-guard-targets
; O0-WINDOWS-NEXT: x86-lvi-ret
; O0-WINDOWS-NEXT: unpack-mi-bundles
@@ -414,6 +415,7 @@
; O3-WINDOWS-NEXT: x86-seses
; O3-WINDOWS-NEXT: x86-return-thunks
; O3-WINDOWS-NEXT: x86-avoid-trailing-call
+; O3-WINDOWS-NEXT: cfi-instr-inserter
; O3-WINDOWS-NEXT: eh-cont-guard-targets
; O3-WINDOWS-NEXT: x86-lvi-ret
; O3-WINDOWS-NEXT: unpack-mi-bundles
More information about the llvm-branch-commits
mailing list