xref: /freebsd/contrib/llvm-project/clang/lib/Basic/CodeGenOptions.cpp (revision 770cf0a5f02dc8983a89c6568d741fbc25baa999)
1 //===--- CodeGenOptions.cpp -----------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "clang/Basic/CodeGenOptions.h"
10 
11 namespace clang {
12 
13 CodeGenOptions::CodeGenOptions() {
14 #define CODEGENOPT(Name, Bits, Default, Compatibility) Name = Default;
15 #define ENUM_CODEGENOPT(Name, Type, Bits, Default, Compatibility)              \
16   set##Name(Default);
17 #include "clang/Basic/CodeGenOptions.def"
18 
19   RelocationModel = llvm::Reloc::PIC_;
20 }
21 
22 void CodeGenOptions::resetNonModularOptions(StringRef ModuleFormat) {
23   // FIXME: Replace with C++20 `using enum CodeGenOptions::CompatibilityKind`.
24   using CK = CompatibilityKind;
25 
26   // First reset benign codegen and debug options.
27 #define CODEGENOPT(Name, Bits, Default, Compatibility)                         \
28   if constexpr (CK::Compatibility == CK::Benign)                               \
29     Name = Default;
30 #define ENUM_CODEGENOPT(Name, Type, Bits, Default, Compatibility)              \
31   if constexpr (CK::Compatibility == CK::Benign)                               \
32     set##Name(Default);
33 #include "clang/Basic/CodeGenOptions.def"
34 
35   // Conditionally reset debug options that only matter when the debug info is
36   // emitted into the PCM (-gmodules).
37   if (ModuleFormat == "raw" && !DebugTypeExtRefs) {
38 #define DEBUGOPT(Name, Bits, Default, Compatibility)                           \
39   if constexpr (CK::Compatibility == CK::Affecting)                            \
40     Name = Default;
41 #define VALUE_DEBUGOPT(Name, Bits, Default, Compatibility)                     \
42   if constexpr (CK::Compatibility == CK::Affecting)                            \
43     Name = Default;
44 #define ENUM_DEBUGOPT(Name, Type, Bits, Default, Compatibility)                \
45   if constexpr (CK::Compatibility == CK::Affecting)                            \
46     set##Name(Default);
47 #include "clang/Basic/DebugOptions.def"
48   }
49 
50   RelocationModel = llvm::Reloc::PIC_;
51 }
52 
53 }  // end namespace clang
54