-
-
Notifications
You must be signed in to change notification settings - Fork 267
/
Copy pathcl_options-llvm.cpp
104 lines (83 loc) · 2.96 KB
/
cl_options-llvm.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//===-- cl_options-llvm.cpp -----------------------------------------------===//
//
// LDC – the LLVM D compiler
//
// This file is distributed under the BSD-style LDC license. See the LICENSE
// file for details.
//
//===----------------------------------------------------------------------===//
#include "driver/cl_options-llvm.h"
#if LDC_WITH_LLD
#if LDC_LLVM_VER < 1700
#include "llvm/ADT/Triple.h"
#else
#include "llvm/TargetParser/Triple.h"
#endif
#endif
// Pull in command-line options and helper functions from special LLVM header
// shared by multiple LLVM tools.
#include "llvm/CodeGen/CommandFlags.h"
static llvm::codegen::RegisterCodeGenFlags CGF;
using namespace llvm;
static cl::opt<bool>
DisableRedZone("disable-red-zone", cl::ZeroOrMore,
cl::desc("Do not emit code that uses the red zone."));
// Now expose the helper functions (with static linkage) via external wrappers
// in the opts namespace, including some additional helper functions.
namespace opts {
std::string getArchStr() {
return codegen::getMArch();
}
Optional<Reloc::Model> getRelocModel() {
return codegen::getExplicitRelocModel();
}
Optional<CodeModel::Model> getCodeModel() {
return codegen::getExplicitCodeModel();
}
using FPK = llvm::FramePointerKind;
llvm::Optional<FPK> framePointerUsage() {
// Defaults to `FP::None`; no way to check if set explicitly by user except
// indirectly via setFunctionAttributes()...
return codegen::getFramePointerUsage();
}
bool disableRedZone() { return ::DisableRedZone; }
bool printTargetFeaturesHelp() {
const auto MCPU = codegen::getMCPU();
const auto MAttrs = codegen::getMAttrs();
if (MCPU == "help")
return true;
return std::any_of(MAttrs.begin(), MAttrs.end(),
[](const std::string &a) { return a == "help"; });
}
TargetOptions InitTargetOptionsFromCodeGenFlags(const llvm::Triple &triple) {
return codegen::InitTargetOptionsFromCodeGenFlags(triple);
}
std::string getCPUStr() {
return codegen::getCPUStr();
}
std::string getFeaturesStr() {
return codegen::getFeaturesStr();
}
void setFunctionAttributes(StringRef cpu, StringRef features,
Function &function) {
return codegen::setFunctionAttributes(cpu, features, function);
}
} // namespace opts
#if LDC_WITH_LLD
// LLD uses the shared header too (for LTO) and exposes some wrappers in
// the lld namespace. Define them here to prevent the LLD object from being
// linked in with its conflicting command-line options.
namespace lld {
TargetOptions initTargetOptionsFromCodeGenFlags() {
return ::opts::InitTargetOptionsFromCodeGenFlags(llvm::Triple());
}
Optional<Reloc::Model> getRelocModelFromCMModel() {
return ::opts::getRelocModel();
}
Optional<CodeModel::Model> getCodeModelFromCMModel() {
return ::opts::getCodeModel();
}
std::string getCPUStr() { return ::opts::getCPUStr(); }
std::vector<std::string> getMAttrs() { return codegen::getMAttrs(); }
} // namespace lld
#endif // LDC_WITH_LLD