[flang-commits] [flang] 73c8b54 - RuntimeLibcalls: Read exception model from the module flag (#223971)
via flang-commits
flang-commits at lists.llvm.org
Wed Sep 16 23:07:57 PDT 2026
Author: Matt Arsenault
Date: 2026-09-17T08:07:49+02:00
New Revision: 73c8b54ee341d1fa625575913179c6475a4a4e42
URL: https://github.com/llvm/llvm-project/commit/73c8b54ee341d1fa625575913179c6475a4a4e42
DIFF: https://github.com/llvm/llvm-project/commit/73c8b54ee341d1fa625575913179c6475a4a4e42.diff
LOG: RuntimeLibcalls: Read exception model from the module flag (#223971)
Source the exception model in the RuntimeLibcallsInfo(Module)
constructor from the "exception-model" module flag via
Module::getExceptionModel(), instead of forwarding it from TargetOptions.
An absent flag resolves to Default and then to the triple default; an explicit "none"
disables exceptions.
Since the model now comes from the module, drop the ExceptionModel that
RuntimeLibraryAnalysis carried and forwarded, and its argument at every
construction site.
Co-authored-by: Claude (Claude-Opus-4.8) <noreply at anthropic.com>
Added:
Modified:
flang/lib/Frontend/FrontendActions.cpp
llvm/include/llvm/Analysis/RuntimeLibcallInfo.h
llvm/include/llvm/IR/RuntimeLibcalls.h
llvm/lib/Analysis/RuntimeLibcallInfo.cpp
llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp
llvm/lib/CodeGen/CommandFlags.cpp
llvm/lib/IR/RuntimeLibcalls.cpp
llvm/lib/LTO/LTOBackend.cpp
llvm/lib/Passes/RunCodeGen.cpp
llvm/tools/llc/lib/NewPMDriver.cpp
llvm/tools/llc/lib/llcdriver.cpp
llvm/tools/opt/NewPMDriver.cpp
llvm/tools/opt/optdriver.cpp
Removed:
################################################################################
diff --git a/flang/lib/Frontend/FrontendActions.cpp b/flang/lib/Frontend/FrontendActions.cpp
index 6757549af7e51..32796ced70d9f 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -1040,7 +1040,6 @@ void CodeGenAction::runOptimizationPipeline(llvm::raw_pwrite_stream &os) {
fam.registerPass([&] { return llvm::TargetLibraryAnalysis(*tlii); });
mam.registerPass([&] {
return llvm::RuntimeLibraryAnalysis(
- targetMachine->Options.ExceptionModel,
targetMachine->Options.MCOptions.ABIName,
targetMachine->Options.VecLib);
});
diff --git a/llvm/include/llvm/Analysis/RuntimeLibcallInfo.h b/llvm/include/llvm/Analysis/RuntimeLibcallInfo.h
index 2742e5ba4a348..b7e0f69c3f7b1 100644
--- a/llvm/include/llvm/Analysis/RuntimeLibcallInfo.h
+++ b/llvm/include/llvm/Analysis/RuntimeLibcallInfo.h
@@ -22,11 +22,9 @@ class LLVM_ABI RuntimeLibraryAnalysis
using Result = RTLIB::RuntimeLibcallsInfo;
RuntimeLibraryAnalysis() = default;
- RuntimeLibraryAnalysis(ExceptionHandling ExceptionModel,
- StringRef ABIName = "",
+ RuntimeLibraryAnalysis(StringRef ABIName,
VectorLibrary VecLib = VectorLibrary::NoLibrary)
- : ExceptionModel(ExceptionModel), ABIName(ABIName.str()), VecLib(VecLib) {
- }
+ : ABIName(ABIName.str()), VecLib(VecLib) {}
RTLIB::RuntimeLibcallsInfo run(const Module &M, ModuleAnalysisManager &);
@@ -37,7 +35,6 @@ class LLVM_ABI RuntimeLibraryAnalysis
// FIXME: These are TargetOptions values that are not yet represented in the
// IR, copied here so run() can forward them to the RuntimeLibcallsInfo Module
// constructor. Delete each one as they are migrated to module flags.
- ExceptionHandling ExceptionModel = ExceptionHandling::None;
std::string ABIName;
VectorLibrary VecLib = VectorLibrary::NoLibrary;
};
@@ -49,8 +46,7 @@ class LLVM_ABI RuntimeLibraryInfoWrapper : public ImmutablePass {
public:
static char ID;
RuntimeLibraryInfoWrapper();
- RuntimeLibraryInfoWrapper(ExceptionHandling ExceptionModel,
- StringRef ABIName = "",
+ RuntimeLibraryInfoWrapper(StringRef ABIName,
VectorLibrary VecLib = VectorLibrary::NoLibrary);
const RTLIB::RuntimeLibcallsInfo &getRTLCI(const Module &M) {
diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.h b/llvm/include/llvm/IR/RuntimeLibcalls.h
index 3227583f23430..4ea0a7854f825 100644
--- a/llvm/include/llvm/IR/RuntimeLibcalls.h
+++ b/llvm/include/llvm/IR/RuntimeLibcalls.h
@@ -91,14 +91,14 @@ struct RuntimeLibcallsInfo {
FloatABI::ABIType FloatABI = FloatABI::Default, StringRef ABIName = "",
VectorLibrary VecLib = VectorLibrary::NoLibrary);
- // FIXME: The floating-point ABI is read from the "float-abi" module flag, but
- // the ExceptionModel/ABIName/VecLib parameters are still TargetOptions values
- // that are not yet represented in the IR. Delete these parameters (and build
- // everything from the Module) once those fields are migrated to module flags.
+ // FIXME: The exception model and floating-point ABI are read from the
+ // "exception-model" and "float-abi" module flags, but the ABIName/VecLib
+ // parameters are still TargetOptions values that are not yet represented in
+ // the IR. Delete these parameters (and build everything from the Module) once
+ // those fields are migrated to module flags.
LLVM_ABI explicit RuntimeLibcallsInfo(
- const Module &M,
- ExceptionHandling ExceptionModel = ExceptionHandling::None,
- StringRef ABIName = "", VectorLibrary VecLib = VectorLibrary::NoLibrary);
+ const Module &M, StringRef ABIName = "",
+ VectorLibrary VecLib = VectorLibrary::NoLibrary);
LLVM_ABI bool invalidate(Module &M, const PreservedAnalyses &PA,
ModuleAnalysisManager::Invalidator &);
diff --git a/llvm/lib/Analysis/RuntimeLibcallInfo.cpp b/llvm/lib/Analysis/RuntimeLibcallInfo.cpp
index ce79008539ca3..a226e6b4128ea 100644
--- a/llvm/lib/Analysis/RuntimeLibcallInfo.cpp
+++ b/llvm/lib/Analysis/RuntimeLibcallInfo.cpp
@@ -15,7 +15,7 @@ AnalysisKey RuntimeLibraryAnalysis::Key;
RTLIB::RuntimeLibcallsInfo
RuntimeLibraryAnalysis::run(const Module &M, ModuleAnalysisManager &) {
- return RTLIB::RuntimeLibcallsInfo(M, ExceptionModel, ABIName, VecLib);
+ return RTLIB::RuntimeLibcallsInfo(M, ABIName, VecLib);
}
INITIALIZE_PASS(RuntimeLibraryInfoWrapper, "runtime-library-info",
@@ -23,9 +23,9 @@ INITIALIZE_PASS(RuntimeLibraryInfoWrapper, "runtime-library-info",
RuntimeLibraryInfoWrapper::RuntimeLibraryInfoWrapper() : ImmutablePass(ID) {}
-RuntimeLibraryInfoWrapper::RuntimeLibraryInfoWrapper(
- ExceptionHandling ExceptionModel, StringRef ABIName, VectorLibrary VecLib)
- : ImmutablePass(ID), RTLA(ExceptionModel, ABIName, VecLib) {}
+RuntimeLibraryInfoWrapper::RuntimeLibraryInfoWrapper(StringRef ABIName,
+ VectorLibrary VecLib)
+ : ImmutablePass(ID), RTLA(ABIName, VecLib) {}
char RuntimeLibraryInfoWrapper::ID = 0;
diff --git a/llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp b/llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp
index f4b4cf9d893fe..6e65091c408b3 100644
--- a/llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp
+++ b/llvm/lib/CodeGen/CodeGenTargetMachineImpl.cpp
@@ -126,8 +126,8 @@ addPassesToGenerateCode(CodeGenTargetMachineImpl &TM, PassManagerBase &PM,
const TargetOptions &Options = TM.Options;
TargetLibraryInfoImpl TLII(TM.getTargetTriple(), Options.VecLib);
PM.add(new TargetLibraryInfoWrapperPass(TLII));
- PM.add(new RuntimeLibraryInfoWrapper(
- Options.ExceptionModel, Options.MCOptions.ABIName, Options.VecLib));
+ PM.add(
+ new RuntimeLibraryInfoWrapper(Options.MCOptions.ABIName, Options.VecLib));
invokeGlobalTargetPassConfigCallbacks(TM, PM, PassConfig);
diff --git a/llvm/lib/CodeGen/CommandFlags.cpp b/llvm/lib/CodeGen/CommandFlags.cpp
index 906ce855c3dee..4ab005f11e0e0 100644
--- a/llvm/lib/CodeGen/CommandFlags.cpp
+++ b/llvm/lib/CodeGen/CommandFlags.cpp
@@ -727,6 +727,26 @@ void codegen::setFunctionAttributes(Module &M, StringRef CPU,
}
}
+ // Synthesize the "exception-model" module flag from the -exception-model
+ // option.
+ ExceptionHandling EH = getExceptionModel();
+ if (EH != ExceptionHandling::Default) {
+ if (auto *Existing =
+ dyn_cast_or_null<MDString>(M.getModuleFlag("exception-model"))) {
+ // The module already records an exception model; -exception-model must
+ // not contradict it.
+ if (Existing->getString() != getExceptionModelName(EH)) {
+ reportFatalUsageError(
+ "-exception-model=" + getExceptionModelName(EH) +
+ " conflicts with the \"exception-model\" module flag \"" +
+ Existing->getString() + "\"");
+ }
+ } else {
+ M.addModuleFlag(Module::Error, "exception-model",
+ MDString::get(M.getContext(), getExceptionModelName(EH)));
+ }
+ }
+
for (Function &F : M)
setFunctionAttributes(F, CPU, Features, TuneCPU);
}
diff --git a/llvm/lib/IR/RuntimeLibcalls.cpp b/llvm/lib/IR/RuntimeLibcalls.cpp
index 9bc4bd18ee2d3..d55d1c4ac5883 100644
--- a/llvm/lib/IR/RuntimeLibcalls.cpp
+++ b/llvm/lib/IR/RuntimeLibcalls.cpp
@@ -101,12 +101,10 @@ RuntimeLibcallsInfo::RuntimeLibcallsInfo(const Triple &TT,
}
// TODO: Consider the remaining module flags.
-RuntimeLibcallsInfo::RuntimeLibcallsInfo(const Module &M,
- ExceptionHandling ExceptionModel,
- StringRef ABIName,
+RuntimeLibcallsInfo::RuntimeLibcallsInfo(const Module &M, StringRef ABIName,
VectorLibrary VecLib)
- : RuntimeLibcallsInfo(M.getTargetTriple(), ExceptionModel, M.getFloatABI(),
- ABIName, VecLib) {}
+ : RuntimeLibcallsInfo(M.getTargetTriple(), M.getExceptionModel(),
+ M.getFloatABI(), ABIName, VecLib) {}
bool RuntimeLibcallsInfo::isLibraryAvailable(StringRef LibraryName) const {
// TODO: Drive this from module-level state (e.g. the linked runtime). For now
diff --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp
index 11c9b2f61988b..3ab145ad1fe71 100644
--- a/llvm/lib/LTO/LTOBackend.cpp
+++ b/llvm/lib/LTO/LTOBackend.cpp
@@ -485,8 +485,7 @@ static void codegen(const Config &Conf, TargetMachine *TM,
TargetLibraryInfoImpl TLII(Mod.getTargetTriple(), TM->Options.VecLib);
CodeGenPasses.add(new TargetLibraryInfoWrapperPass(TLII));
CodeGenPasses.add(new RuntimeLibraryInfoWrapper(
- TM->Options.ExceptionModel, TM->Options.MCOptions.ABIName,
- TM->Options.VecLib));
+ TM->Options.MCOptions.ABIName, TM->Options.VecLib));
// No need to make index available if the module is empty.
// In theory these passes should not use the index for an empty
diff --git a/llvm/lib/Passes/RunCodeGen.cpp b/llvm/lib/Passes/RunCodeGen.cpp
index aae30c47389c2..0ba67d01c3a9b 100644
--- a/llvm/lib/Passes/RunCodeGen.cpp
+++ b/llvm/lib/Passes/RunCodeGen.cpp
@@ -46,8 +46,8 @@ runCodeGenPipelineLegacy(TargetMachine &TM, Module &M, raw_pwrite_stream &OS,
CodeGenPasses.add(new TargetLibraryInfoWrapperPass(TLII));
const TargetOptions &Options = TM.Options;
- CodeGenPasses.add(new RuntimeLibraryInfoWrapper(
- Options.ExceptionModel, Options.MCOptions.ABIName, Options.VecLib));
+ CodeGenPasses.add(
+ new RuntimeLibraryInfoWrapper(Options.MCOptions.ABIName, Options.VecLib));
if (TM.addPassesToEmitFile(CodeGenPasses, OS, DwoOS ? &DwoOS->os() : nullptr,
CGFT, DisableVerify))
diff --git a/llvm/tools/llc/lib/NewPMDriver.cpp b/llvm/tools/llc/lib/NewPMDriver.cpp
index 475608de5500a..3eac9bd15355e 100644
--- a/llvm/tools/llc/lib/NewPMDriver.cpp
+++ b/llvm/tools/llc/lib/NewPMDriver.cpp
@@ -137,8 +137,7 @@ int llvm::compileModuleWithNewPM(
MAM.registerPass([&] {
const TargetOptions &Options = Target->Options;
- return RuntimeLibraryAnalysis(Options.ExceptionModel,
- Options.MCOptions.ABIName, Options.VecLib);
+ return RuntimeLibraryAnalysis(Options.MCOptions.ABIName, Options.VecLib);
});
MAM.registerPass([&] { return MachineModuleAnalysis(MMI); });
diff --git a/llvm/tools/llc/lib/llcdriver.cpp b/llvm/tools/llc/lib/llcdriver.cpp
index 94d204ed1424a..54410c33a23a4 100644
--- a/llvm/tools/llc/lib/llcdriver.cpp
+++ b/llvm/tools/llc/lib/llcdriver.cpp
@@ -754,8 +754,7 @@ static int compileModule(char **argv, SmallVectorImpl<PassPlugin> &PluginList,
// Build up all of the passes that we want to do to the module.
legacy::PassManager PM;
PM.add(new TargetLibraryInfoWrapperPass(TLII));
- PM.add(new RuntimeLibraryInfoWrapper(Target->Options.ExceptionModel,
- Options.MCOptions.ABIName,
+ PM.add(new RuntimeLibraryInfoWrapper(Options.MCOptions.ABIName,
Target->Options.VecLib));
{
diff --git a/llvm/tools/opt/NewPMDriver.cpp b/llvm/tools/opt/NewPMDriver.cpp
index ebe6bd7c5f341..a920f154db21c 100644
--- a/llvm/tools/opt/NewPMDriver.cpp
+++ b/llvm/tools/opt/NewPMDriver.cpp
@@ -452,8 +452,7 @@ bool llvm::runPassPipeline(
MAM.registerPass([&] {
const TargetOptions &Options = TM->Options;
- return RuntimeLibraryAnalysis(Options.ExceptionModel,
- Options.MCOptions.ABIName, Options.VecLib);
+ return RuntimeLibraryAnalysis(Options.MCOptions.ABIName, Options.VecLib);
});
}
diff --git a/llvm/tools/opt/optdriver.cpp b/llvm/tools/opt/optdriver.cpp
index bcbf7190783ee..46c6833515e18 100644
--- a/llvm/tools/opt/optdriver.cpp
+++ b/llvm/tools/opt/optdriver.cpp
@@ -847,8 +847,8 @@ optMain(int argc, char **argv,
(VerifyDebugInfoPreserve && !VerifyEachDebugInfoPreserve);
Passes.add(new TargetLibraryInfoWrapperPass(TLII));
- Passes.add(new RuntimeLibraryInfoWrapper(
- Options->ExceptionModel, Options->MCOptions.ABIName, Options->VecLib));
+ Passes.add(new RuntimeLibraryInfoWrapper(Options->MCOptions.ABIName,
+ Options->VecLib));
// Add internal analysis passes from the target machine.
Passes.add(createTargetTransformInfoWrapperPass(TM ? TM->getTargetIRAnalysis()
More information about the flang-commits
mailing list