llvm-project/clang/lib/Basic/CodeGenOptions.cpp
Jan Svoboda c592b61fc8
[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.
2025-07-15 12:45:09 -07:00

54 lines
2.1 KiB
C++

//===--- CodeGenOptions.cpp -----------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "clang/Basic/CodeGenOptions.h"
namespace clang {
CodeGenOptions::CodeGenOptions() {
#define CODEGENOPT(Name, Bits, Default, Compatibility) Name = Default;
#define ENUM_CODEGENOPT(Name, Type, Bits, Default, Compatibility) \
set##Name(Default);
#include "clang/Basic/CodeGenOptions.def"
RelocationModel = llvm::Reloc::PIC_;
}
void CodeGenOptions::resetNonModularOptions(StringRef ModuleFormat) {
// FIXME: Replace with C++20 `using enum CodeGenOptions::CompatibilityKind`.
using CK = CompatibilityKind;
// First reset benign codegen and debug options.
#define CODEGENOPT(Name, Bits, Default, Compatibility) \
if constexpr (CK::Compatibility == CK::Benign) \
Name = Default;
#define ENUM_CODEGENOPT(Name, Type, Bits, Default, Compatibility) \
if constexpr (CK::Compatibility == CK::Benign) \
set##Name(Default);
#include "clang/Basic/CodeGenOptions.def"
// Conditionally reset debug options that only matter when the debug info is
// emitted into the PCM (-gmodules).
if (ModuleFormat == "raw" && !DebugTypeExtRefs) {
#define DEBUGOPT(Name, Bits, Default, Compatibility) \
if constexpr (CK::Compatibility != CK::Benign) \
Name = Default;
#define VALUE_DEBUGOPT(Name, Bits, Default, Compatibility) \
if constexpr (CK::Compatibility != CK::Benign) \
Name = Default;
#define ENUM_DEBUGOPT(Name, Type, Bits, Default, Compatibility) \
if constexpr (CK::Compatibility != CK::Benign) \
set##Name(Default);
#include "clang/Basic/DebugOptions.def"
}
RelocationModel = llvm::Reloc::PIC_;
}
} // end namespace clang