clang 24.0.0git
CodeGenOptions.cpp
Go to the documentation of this file.
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
10#include "llvm/Support/Path.h"
11
12namespace clang {
13
15#define CODEGENOPT(Name, Bits, Default, Compatibility) Name = Default;
16#define ENUM_CODEGENOPT(Name, Type, Bits, Default, Compatibility) \
17 set##Name(Default);
18#include "clang/Basic/CodeGenOptions.def"
19
20 RelocationModel = llvm::Reloc::PIC_;
21}
22
23void CodeGenOptions::resetNonModularOptions(StringRef ModuleFormat) {
24 // FIXME: Replace with C++20 `using enum CodeGenOptions::CompatibilityKind`.
25 using CK = CompatibilityKind;
26
27 // First reset benign codegen and debug options.
28#define CODEGENOPT(Name, Bits, Default, Compatibility) \
29 if constexpr (CK::Compatibility == CK::Benign) \
30 Name = Default;
31#define ENUM_CODEGENOPT(Name, Type, Bits, Default, Compatibility) \
32 if constexpr (CK::Compatibility == CK::Benign) \
33 set##Name(Default);
34#include "clang/Basic/CodeGenOptions.def"
35
36 // Conditionally reset debug options that only matter when the debug info is
37 // emitted into the PCM (-gmodules).
38 if (ModuleFormat == "raw" && !DebugTypeExtRefs) {
39#define DEBUGOPT(Name, Bits, Default, Compatibility) \
40 if constexpr (CK::Compatibility != CK::Benign) \
41 Name = Default;
42#define VALUE_DEBUGOPT(Name, Bits, Default, Compatibility) \
43 if constexpr (CK::Compatibility != CK::Benign) \
44 Name = Default;
45#define ENUM_DEBUGOPT(Name, Type, Bits, Default, Compatibility) \
46 if constexpr (CK::Compatibility != CK::Benign) \
47 set##Name(Default);
48#include "clang/Basic/DebugOptions.def"
49 }
50
51 RelocationModel = llvm::Reloc::PIC_;
52}
53
54std::string CodeGenOptions::remapDebugPathPrefix(StringRef Path) const {
55 SmallString<256> P = Path;
56
57 for (auto &[From, To] : llvm::reverse(DebugPrefixMap))
58 if (llvm::sys::path::replace_path_prefix(P, From, To))
59 break;
60 return P.str().str();
61}
62
63} // end namespace clang
CompatibilityKind
For ASTs produced with different option value, signifies their level of compatibility.
llvm::SmallVector< std::pair< std::string, std::string >, 0 > DebugPrefixMap
llvm::Reloc::Model RelocationModel
The name of the relocation model to use.
std::string remapDebugPathPrefix(StringRef Path) const
Remap specified path prefix using provided DebugPrefixMap map.
void resetNonModularOptions(StringRef ModuleFormat)
Reset all of the options that are not considered when building a module.
Top level wrappers for InstallAPI frontend operations.