[clang] e7ffa95 - CodeGen: Remove TargetOptions::ExceptionModel (#232977)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 23 10:49:38 PDT 2026
Author: Matt Arsenault
Date: 2026-10-23T10:49:33-07:00
New Revision: e7ffa953f8db48706b4f470e680951cb92c43ed8
URL: https://github.com/llvm/llvm-project/commit/e7ffa953f8db48706b4f470e680951cb92c43ed8
DIFF: https://github.com/llvm/llvm-project/commit/e7ffa953f8db48706b4f470e680951cb92c43ed8.diff
LOG: CodeGen: Remove TargetOptions::ExceptionModel (#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>
Added:
Modified:
clang/lib/CodeGen/BackendUtil.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/test/CodeGen/WebAssembly/wasm-exception-model-flag-parse-ir-input.ll
llvm/docs/ReleaseNotes.md
llvm/include/llvm/MC/MCAsmInfo.h
llvm/include/llvm/Target/TargetOptions.h
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
llvm/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp
llvm/lib/CodeGen/AsmPrinter/EHStreamer.cpp
llvm/lib/CodeGen/CFIInstrInserter.cpp
llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp
llvm/lib/CodeGen/CommandFlags.cpp
llvm/lib/CodeGen/MachineFunction.cpp
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
llvm/lib/CodeGen/TargetLoweringBase.cpp
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
llvm/lib/Target/AArch64/AArch64AsmPrinter.cpp
llvm/lib/Target/ARM/ARMAsmPrinter.cpp
llvm/lib/Target/ARM/ARMTargetObjectFile.cpp
llvm/lib/Target/ARM/ARMTargetObjectFile.h
llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
llvm/lib/Target/X86/X86CodeGenPassBuilder.cpp
llvm/lib/Target/X86/X86MCInstLower.cpp
llvm/lib/Target/X86/X86TargetMachine.cpp
llvm/test/CodeGen/AMDGPU/exception-model.ll
llvm/test/CodeGen/X86/llc-pipeline-npm.ll
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 9fcfb6373b14e2..8331ad64df3dff 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -395,17 +395,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 225962359129b3..9c4e4c1b7359b8 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 b3ac28b4722672..ada198e466f4f4 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/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md
index 1fe73727a79587..48bd91c2598601 100644
--- a/llvm/docs/ReleaseNotes.md
+++ b/llvm/docs/ReleaseNotes.md
@@ -177,6 +177,9 @@ Makes programs 10x faster by doing Special New Thing.
* Removed `TargetOptions::FloatABIType`. The soft float ABI should be
controlled by setting the `"float-abi"` module flag.
+* Removed `TargetOptions::ExceptionModel`. The exception model should
+ be controlled by setting the `"exception-model"` module flag.
+
* Removed `TargetOptions::EABIVersion` and the `llc`/`opt` `-meabi` flag. The
GNU-vs-EABI distinction is now derived entirely from the target triple's
environment (e.g. `arm-none-gnueabi` vs `arm-none-eabi`).
diff --git a/llvm/include/llvm/MC/MCAsmInfo.h b/llvm/include/llvm/MC/MCAsmInfo.h
index 3a9f3c3264bc8c..6e7b6f1b06c58e 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 0bec4ba6203d30..501666f60a0bc0 100644
--- a/llvm/include/llvm/Target/TargetOptions.h
+++ b/llvm/include/llvm/Target/TargetOptions.h
@@ -310,9 +310,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 523892d991b4eb..d925e274a6a841 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 3b2feb876eadb9..cfd539265012cd 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 3fd4494a53ffc2..fb4b21b5d8c6ac 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 a415dee9f39385..da3501330f7b8b 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 d32895d47369d7..f61ab04b04e21d 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 3c4652405cb6a6..a780abce7e5bb5 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 2e1521346f67a5..725def7767ea09 100644
--- a/llvm/lib/CodeGen/MachineFunction.cpp
+++ b/llvm/lib/CodeGen/MachineFunction.cpp
@@ -751,13 +751,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 30b1fee7410d76..58be54855abdea 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -9292,7 +9292,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 9fa86b1faa5d67..ff918d982b1d9d 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.getTargetTriple().getDefaultLongDoubleFormat(),
TM.Options.MCOptions.getABIName(), TM.Options.VecLib),
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index acff5e19b06d79..fa46420336bcc3 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 683b8ffb94e433..eb7b3228df9b19 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 9bbd029495a79f..d118a21d560015 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 6e0606f9d9d5c1..b3cc1ce0e77c60 100644
--- a/llvm/lib/Target/ARM/ARMTargetObjectFile.cpp
+++ b/llvm/lib/Target/ARM/ARMTargetObjectFile.cpp
@@ -12,6 +12,7 @@
#include "MCTargetDesc/ARMMCAsmInfo.h"
#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/BinaryFormat/ELF.h"
+#include "llvm/IR/Module.h"
#include "llvm/MC/MCAsmInfo.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCExpr.h"
@@ -41,6 +42,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 +83,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 221a4be6579c64..b4b6777480fd2e 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 096f57ee540d20..4e1a66686f39b5 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
@@ -918,11 +918,20 @@ 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");
- assert((EH != ExceptionHandling::Wasm || !EnableEmSjLj) &&
- "Emscripten SjLj cannot be 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");
+ // You can't mix Wasm EH with Emscripten SjLj.
+ if (EH == ExceptionHandling::Wasm && EnableEmSjLj)
+ report_fatal_error(
+ "-exception-model=wasm not allowed with -enable-emscripten-sjlj");
bool Changed = false;
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
index 2d9eaf7705e123..742c2541a2d58e 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
@@ -128,41 +128,11 @@ using WebAssembly::WasmDisableExplicitLocals;
using WebAssembly::WasmEnableEmSjLj;
using WebAssembly::WasmEnableSjLj;
-static void basicCheckForEHAndSjLj(TargetMachine *TM) {
-
- bool EnableEmEH = TM->Options.ExceptionModel == ExceptionHandling::Emscripten;
- bool EnableWasmEH = TM->Options.ExceptionModel == ExceptionHandling::Wasm;
-
+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");
- // You can't mix Wasm EH with Emscripten SjLj.
- if (EnableWasmEH && WasmEnableEmSjLj)
- report_fatal_error(
- "-exception-model=wasm not allowed with -enable-emscripten-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");
}
/// Create an WebAssembly architecture model.
@@ -191,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 12d20c88166862..324179e2a8ae35 100644
--- a/llvm/lib/Target/X86/X86CodeGenPassBuilder.cpp
+++ b/llvm/lib/Target/X86/X86CodeGenPassBuilder.cpp
@@ -246,7 +246,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
@@ -270,10 +269,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 54fb24e7a06f33..00a752a81bc772 100644
--- a/llvm/lib/Target/X86/X86MCInstLower.cpp
+++ b/llvm/lib/Target/X86/X86MCInstLower.cpp
@@ -2794,7 +2794,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 ebe61c1f11791a..fb7cadd2878a8c 100644
--- a/llvm/lib/Target/X86/X86TargetMachine.cpp
+++ b/llvm/lib/Target/X86/X86TargetMachine.cpp
@@ -579,7 +579,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
@@ -601,10 +600,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 1494b8eea8d15b..bb3a7bc27fe40f 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 97f48eee6f93d1..ad7f99a82fb619 100644
--- a/llvm/test/CodeGen/X86/llc-pipeline-npm.ll
+++ b/llvm/test/CodeGen/X86/llc-pipeline-npm.ll
@@ -284,6 +284,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: cfguard-longjmp
; O0-WINDOWS-NEXT: eh-cont-guard-targets
; O0-WINDOWS-NEXT: x86-lvi-ret
@@ -420,6 +421,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: cfguard-longjmp
; O3-WINDOWS-NEXT: eh-cont-guard-targets
; O3-WINDOWS-NEXT: x86-lvi-ret
More information about the cfe-commits
mailing list