clang 8.0.0

PPC.cpp
Go to the documentation of this file.
1 //===--- PPC.cpp - PPC Helpers for Tools ------------------------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #include "PPC.h"
11 #include "ToolChains/CommonArgs.h"
12 #include "clang/Driver/Driver.h"
13 #include "clang/Driver/DriverDiagnostic.h"
14 #include "clang/Driver/Options.h"
15 #include "llvm/ADT/StringSwitch.h"
16 #include "llvm/Option/ArgList.h"
17
18 using namespace clang::driver;
19 using namespace clang::driver::tools;
20 using namespace clang;
21 using namespace llvm::opt;
22
23 /// getPPCTargetCPU - Get the (LLVM) name of the PowerPC cpu we are targeting.
24 std::string ppc::getPPCTargetCPU(const ArgList &Args) {
25 if (Arg *A = Args.getLastArg(clang::driver::options::OPT_mcpu_EQ)) {
26 StringRef CPUName = A->getValue();
27
28 if (CPUName == "native") {
29 std::string CPU = llvm::sys::getHostCPUName();
30 if (!CPU.empty() && CPU != "generic")
31 return CPU;
32 else
33 return "";
34 }
35
36 return llvm::StringSwitch<const char *>(CPUName)
37 .Case("common", "generic")
38 .Case("440", "440")
39 .Case("440fp", "440")
40 .Case("450", "450")
41 .Case("601", "601")
42 .Case("602", "602")
43 .Case("603", "603")
44 .Case("603e", "603e")
45 .Case("603ev", "603ev")
46 .Case("604", "604")
47 .Case("604e", "604e")
48 .Case("620", "620")
49 .Case("630", "pwr3")
50 .Case("G3", "g3")
51 .Case("7400", "7400")
52 .Case("G4", "g4")
53 .Case("7450", "7450")
54 .Case("G4+", "g4+")
55 .Case("750", "750")
56 .Case("970", "970")
57 .Case("G5", "g5")
58 .Case("a2", "a2")
59 .Case("a2q", "a2q")
60 .Case("e500mc", "e500mc")
61 .Case("e5500", "e5500")
62 .Case("power3", "pwr3")
63 .Case("power4", "pwr4")
64 .Case("power5", "pwr5")
65 .Case("power5x", "pwr5x")
66 .Case("power6", "pwr6")
67 .Case("power6x", "pwr6x")
68 .Case("power7", "pwr7")
69 .Case("power8", "pwr8")
70 .Case("power9", "pwr9")
71 .Case("pwr3", "pwr3")
72 .Case("pwr4", "pwr4")
73 .Case("pwr5", "pwr5")
74 .Case("pwr5x", "pwr5x")
75 .Case("pwr6", "pwr6")
76 .Case("pwr6x", "pwr6x")
77 .Case("pwr7", "pwr7")
78 .Case("pwr8", "pwr8")
79 .Case("pwr9", "pwr9")
80 .Case("powerpc", "ppc")
81 .Case("powerpc64", "ppc64")
82 .Case("powerpc64le", "ppc64le")
83 .Default("");
84 }
85
86 return "";
87 }
88
89 const char *ppc::getPPCAsmModeForCPU(StringRef Name) {
90 return llvm::StringSwitch<const char *>(Name)
91 .Case("pwr7", "-mpower7")
92 .Case("power7", "-mpower7")
93 .Case("pwr8", "-mpower8")
94 .Case("power8", "-mpower8")
95 .Case("ppc64le", "-mpower8")
96 .Case("pwr9", "-mpower9")
97 .Case("power9", "-mpower9")
98 .Default("-many");
99 }
100
101 void ppc::getPPCTargetFeatures(const Driver &D, const llvm::Triple &Triple,
102 const ArgList &Args,
103 std::vector<StringRef> &Features) {
104 handleTargetFeaturesGroup(Args, Features, options::OPT_m_ppc_Features_Group);
105
106 ppc::FloatABI FloatABI = ppc::getPPCFloatABI(D, Args);
107 if (FloatABI == ppc::FloatABI::Soft)
108 Features.push_back("-hard-float");
109
110 ppc::ReadGOTPtrMode ReadGOT = ppc::getPPCReadGOTPtrMode(D, Triple, Args);
111 if (ReadGOT == ppc::ReadGOTPtrMode::SecurePlt)
112 Features.push_back("+secure-plt");
113 }
114
115 ppc::ReadGOTPtrMode ppc::getPPCReadGOTPtrMode(const Driver &D, const llvm::Triple &Triple,
116 const ArgList &Args) {
117 if (Args.getLastArg(options::OPT_msecure_plt))
118 return ppc::ReadGOTPtrMode::SecurePlt;
119 if (Triple.isOSOpenBSD())
120 return ppc::ReadGOTPtrMode::SecurePlt;
121 else
122 return ppc::ReadGOTPtrMode::Bss;
123 }
124
125 ppc::FloatABI ppc::getPPCFloatABI(const Driver &D, const ArgList &Args) {
126 ppc::FloatABI ABI = ppc::FloatABI::Invalid;
127 if (Arg *A =
128 Args.getLastArg(options::OPT_msoft_float, options::OPT_mhard_float,
129 options::OPT_mfloat_abi_EQ)) {
130 if (A->getOption().matches(options::OPT_msoft_float))
131 ABI = ppc::FloatABI::Soft;
132 else if (A->getOption().matches(options::OPT_mhard_float))
133 ABI = ppc::FloatABI::Hard;
134 else {
135 ABI = llvm::StringSwitch<ppc::FloatABI>(A->getValue())
136 .Case("soft", ppc::FloatABI::Soft)
137 .Case("hard", ppc::FloatABI::Hard)
138 .Default(ppc::FloatABI::Invalid);
139 if (ABI == ppc::FloatABI::Invalid && !StringRef(A->getValue()).empty()) {
140 D.Diag(clang::diag::err_drv_invalid_mfloat_abi) << A->getAsString(Args);
141 ABI = ppc::FloatABI::Hard;
142 }
143 }
144 }
145
146 // If unspecified, choose the default based on the platform.
147 if (ABI == ppc::FloatABI::Invalid) {
148 ABI = ppc::FloatABI::Hard;
149 }
150
151 return ABI;
152 }
153
154 bool ppc::hasPPCAbiArg(const ArgList &Args, const char *Value) {
155 Arg *A = Args.getLastArg(options::OPT_mabi_EQ);
156 return A && (A->getValue() == StringRef(Value));
157 }
clang::driver::tools::ppc::getPPCAsmModeForCPU
const char * getPPCAsmModeForCPU(StringRef Name)
Definition: PPC.cpp:89
clang::driver::tools::handleTargetFeaturesGroup
void handleTargetFeaturesGroup(const llvm::opt::ArgList &Args, std::vector< StringRef > &Features, llvm::opt::OptSpecifier Group)
clang::driver::tools::ppc::ReadGOTPtrMode
ReadGOTPtrMode
Definition: PPC.h:32
clang::driver::Driver::Diag
DiagnosticBuilder Diag(unsigned DiagID) const
Definition: Driver.h:109
Value
Value
Definition: UninitializedValues.cpp:102
clang::driver::tools::ppc::FloatABI::Hard
CommonArgs.h
PPC.h
clang::driver::tools
Definition: AMDGPU.h:21
clang::driver::tools::ppc::getPPCFloatABI
FloatABI getPPCFloatABI(const Driver &D, const llvm::opt::ArgList &Args)
clang::driver::Driver
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:58
clang::driver::tools::ppc::FloatABI
FloatABI
Definition: PPC.h:26
Driver.h
llvm::opt
Definition: Action.h:24
clang::driver::tools::ppc::FloatABI::Soft
clang::driver::tools::ppc::hasPPCAbiArg
bool hasPPCAbiArg(const llvm::opt::ArgList &Args, const char *Value)
clang::driver::tools::ppc::getPPCTargetCPU
std::string getPPCTargetCPU(const llvm::opt::ArgList &Args)
clang::driver::tools::ppc::ReadGOTPtrMode::Bss
Options.h
clang::driver::tools::ppc::ReadGOTPtrMode::SecurePlt
clang::driver::tools::ppc::getPPCReadGOTPtrMode
ReadGOTPtrMode getPPCReadGOTPtrMode(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args)
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:22
clang::driver::tools::ppc::FloatABI::Invalid
clang::driver::tools::ppc::getPPCTargetFeatures
void getPPCTargetFeatures(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args, std::vector< llvm::StringRef > &Features)
clang::driver
Definition: Action.h:32
DriverDiagnostic.h