aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Frontend/CompilerInvocation.cpp
diff options
context:
space:
mode:
authorJan Svoboda <jan_svoboda@apple.com>2025-07-15 12:45:09 -0700
committerGitHub <noreply@github.com>2025-07-15 12:45:09 -0700
commitc592b61fc82c79366216ae12b25b0130359b0a26 (patch)
tree66b671ae5fdaaf321a94a9378b1af3b957586060 /clang/lib/Frontend/CompilerInvocation.cpp
parentfccae859bc949ba390184614e07234267a734b86 (diff)
downloadllvm-c592b61fc82c79366216ae12b25b0130359b0a26.zip
llvm-c592b61fc82c79366216ae12b25b0130359b0a26.tar.gz
llvm-c592b61fc82c79366216ae12b25b0130359b0a26.tar.bz2
[clang][modules] Serialize `CodeGenOptions` (#146422)
Some `LangOptions` duplicate their `CodeGenOptions` counterparts. My understanding is that this was done solely because some infrastructure (like preprocessor initialization, serialization, module compatibility checks, etc.) were only possible/convenient for `LangOptions`. This PR implements the missing support for `CodeGenOptions`, which makes it possible to remove some duplicate `LangOptions` fields and simplify the logic. Motivated by https://github.com/llvm/llvm-project/pull/146342.
Diffstat (limited to 'clang/lib/Frontend/CompilerInvocation.cpp')
-rw-r--r--clang/lib/Frontend/CompilerInvocation.cpp37
1 files changed, 18 insertions, 19 deletions
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index 08cf0ae..56d10ce 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -4470,22 +4470,6 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
Opts.OpenACCMacroOverride = A->getValue();
}
- // FIXME: Eliminate this dependency.
- unsigned Opt = getOptimizationLevel(Args, IK, Diags),
- OptSize = getOptimizationLevelSize(Args);
- Opts.Optimize = Opt != 0;
- Opts.OptimizeSize = OptSize != 0;
-
- // This is the __NO_INLINE__ define, which just depends on things like the
- // optimization level and -fno-inline, not actually whether the backend has
- // inlining enabled.
- Opts.NoInlineDefine = !Opts.Optimize;
- if (Arg *InlineArg = Args.getLastArg(
- options::OPT_finline_functions, options::OPT_finline_hint_functions,
- options::OPT_fno_inline_functions, options::OPT_fno_inline))
- if (InlineArg->getOption().matches(options::OPT_fno_inline))
- Opts.NoInlineDefine = true;
-
if (Arg *A = Args.getLastArg(OPT_ffp_contract)) {
StringRef Val = A->getValue();
if (Val == "fast")
@@ -5335,6 +5319,21 @@ std::string CompilerInvocation::getModuleHash() const {
HBuilder.add(*Build);
}
+ // Extend the signature with affecting codegen options.
+ {
+ using CK = CodeGenOptions::CompatibilityKind;
+#define CODEGENOPT(Name, Bits, Default, Compatibility) \
+ if constexpr (CK::Compatibility != CK::Benign) \
+ HBuilder.add(CodeGenOpts->Name);
+#define ENUM_CODEGENOPT(Name, Type, Bits, Default, Compatibility) \
+ if constexpr (CK::Compatibility != CK::Benign) \
+ HBuilder.add(static_cast<unsigned>(CodeGenOpts->get##Name()));
+#define DEBUGOPT(Name, Bits, Default, Compatibility)
+#define VALUE_DEBUGOPT(Name, Bits, Default, Compatibility)
+#define ENUM_DEBUGOPT(Name, Type, Bits, Default, Compatibility)
+#include "clang/Basic/CodeGenOptions.def"
+ }
+
// When compiling with -gmodules, also hash -fdebug-prefix-map as it
// affects the debug info in the PCM.
if (getCodeGenOpts().DebugTypeExtRefs)
@@ -5345,13 +5344,13 @@ std::string CompilerInvocation::getModuleHash() const {
// FIXME: Replace with C++20 `using enum CodeGenOptions::CompatibilityKind`.
using CK = CodeGenOptions::CompatibilityKind;
#define DEBUGOPT(Name, Bits, Default, Compatibility) \
- if constexpr (CK::Compatibility == CK::Affecting) \
+ if constexpr (CK::Compatibility != CK::Benign) \
HBuilder.add(CodeGenOpts->Name);
#define VALUE_DEBUGOPT(Name, Bits, Default, Compatibility) \
- if constexpr (CK::Compatibility == CK::Affecting) \
+ if constexpr (CK::Compatibility != CK::Benign) \
HBuilder.add(CodeGenOpts->Name);
#define ENUM_DEBUGOPT(Name, Type, Bits, Default, Compatibility) \
- if constexpr (CK::Compatibility == CK::Affecting) \
+ if constexpr (CK::Compatibility != CK::Benign) \
HBuilder.add(static_cast<unsigned>(CodeGenOpts->get##Name()));
#include "clang/Basic/DebugOptions.def"
}