clang 24.0.0git
Sparc.cpp
Go to the documentation of this file.
1//===--- Sparc.cpp - Tools Implementations ----------------------*- C++ -*-===//
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 "Sparc.h"
10#include "clang/Driver/Driver.h"
12#include "llvm/ADT/StringSwitch.h"
13#include "llvm/Option/ArgList.h"
14#include "llvm/TargetParser/Host.h"
15
16using namespace clang::driver;
17using namespace clang::driver::tools;
18using namespace clang;
19using namespace llvm::opt;
20
21const char *sparc::getSparcAsmModeForCPU(StringRef Name,
22 const llvm::Triple &Triple) {
23 if (Triple.getArch() == llvm::Triple::sparcv9) {
24 const char *DefV9CPU;
25
26 if (Triple.isOSSolaris())
27 DefV9CPU = "-Av9b";
28 else if (Triple.isOSLinux() || Triple.isOSFreeBSD() || Triple.isOSOpenBSD())
29 DefV9CPU = "-Av9a";
30 else
31 DefV9CPU = "-Av9";
32
33 return llvm::StringSwitch<const char *>(Name)
34 .Case("niagara", "-Av9b")
35 .Case("niagara2", "-Av9b")
36 .Case("niagara3", "-Av9d")
37 .Case("niagara4", "-Av9d")
38 .Default(DefV9CPU);
39 } else {
40 const char *DefV8CPU;
41
42 if (Triple.isOSSolaris())
43 DefV8CPU = "-Av8plus";
44 else
45 DefV8CPU = "-Av8";
46
47 return llvm::StringSwitch<const char *>(Name)
48 .Case("v8", "-Av8")
49 .Case("supersparc", "-Av8")
50 .Case("sparclite", "-Asparclite")
51 .Case("f934", "-Asparclite")
52 .Case("hypersparc", "-Av8")
53 .Case("sparclite86x", "-Asparclite")
54 .Case("sparclet", "-Asparclet")
55 .Case("tsc701", "-Asparclet")
56 .Case("v9", "-Av8plus")
57 .Case("ultrasparc", "-Av8plus")
58 .Case("ultrasparc3", "-Av8plus")
59 .Case("niagara", "-Av8plusb")
60 .Case("niagara2", "-Av8plusb")
61 .Case("niagara3", "-Av8plusd")
62 .Case("niagara4", "-Av8plusd")
63 .Case("ma2100", "-Aleon")
64 .Case("ma2150", "-Aleon")
65 .Case("ma2155", "-Aleon")
66 .Case("ma2450", "-Aleon")
67 .Case("ma2455", "-Aleon")
68 .Case("ma2x5x", "-Aleon")
69 .Case("ma2080", "-Aleon")
70 .Case("ma2085", "-Aleon")
71 .Case("ma2480", "-Aleon")
72 .Case("ma2485", "-Aleon")
73 .Case("ma2x8x", "-Aleon")
74 .Case("leon2", "-Av8")
75 .Case("at697e", "-Av8")
76 .Case("at697f", "-Av8")
77 .Case("leon3", "-Aleon")
78 .Case("ut699", "-Av8")
79 .Case("gr712rc", "-Aleon")
80 .Case("leon4", "-Aleon")
81 .Case("gr740", "-Aleon")
82 .Case("leon5", "-Aleon")
83 .Default(DefV8CPU);
84 }
85}
86
88 const ArgList &Args) {
90 if (Arg *A = Args.getLastArg(options::OPT_msoft_float, options::OPT_mno_fpu,
91 options::OPT_mhard_float, options::OPT_mfpu,
92 options::OPT_mfloat_abi_EQ)) {
93 if (A->getOption().matches(options::OPT_msoft_float) ||
94 A->getOption().matches(options::OPT_mno_fpu))
96 else if (A->getOption().matches(options::OPT_mhard_float) ||
97 A->getOption().matches(options::OPT_mfpu))
99 else {
100 ABI = llvm::StringSwitch<sparc::FloatABI>(A->getValue())
101 .Case("soft", sparc::FloatABI::Soft)
102 .Case("hard", sparc::FloatABI::Hard)
103 .Default(sparc::FloatABI::Invalid);
104 if (ABI == sparc::FloatABI::Invalid &&
105 !StringRef(A->getValue()).empty()) {
106 D.Diag(clang::diag::err_drv_invalid_mfloat_abi) << A->getAsString(Args);
108 }
109 }
110 }
111
112 // If unspecified, choose the default based on the platform.
113 // Only the hard-float ABI on Sparc is standardized, and it is the
114 // default. GCC also supports a nonstandard soft-float ABI mode, also
115 // implemented in LLVM. However as this is not standard we set the default
116 // to be hard-float.
117 if (ABI == sparc::FloatABI::Invalid) {
119 }
120
121 return ABI;
122}
123
124std::string sparc::getSparcTargetCPU(const Driver &D, const ArgList &Args,
125 const llvm::Triple &Triple) {
126 if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) {
127 StringRef CPUName = A->getValue();
128 if (CPUName == "native") {
129 std::string CPU = std::string(llvm::sys::getHostCPUName());
130 if (!CPU.empty() && CPU != "generic")
131 return CPU;
132 return "";
133 }
134 return std::string(CPUName);
135 }
136
137 if (Triple.getArch() == llvm::Triple::sparc &&
138 (Triple.isOSSolaris() || Triple.isOSLinux()))
139 return "v9";
140 return "";
141}
142
143void sparc::getSparcTargetFeatures(const Driver &D, const llvm::Triple &Triple,
144 const ArgList &Args,
145 std::vector<StringRef> &Features) {
147 if (FloatABI == sparc::FloatABI::Soft)
148 Features.push_back("+soft-float");
149
150 if (Arg *A = Args.getLastArg(options::OPT_mfsmuld, options::OPT_mno_fsmuld)) {
151 if (A->getOption().matches(options::OPT_mfsmuld))
152 Features.push_back("+fsmuld");
153 else
154 Features.push_back("-fsmuld");
155 }
156
157 if (Arg *A = Args.getLastArg(options::OPT_mpopc, options::OPT_mno_popc)) {
158 if (A->getOption().matches(options::OPT_mpopc))
159 Features.push_back("+popc");
160 else
161 Features.push_back("-popc");
162 }
163
164 // Those OSes default to enabling VIS on 64-bit SPARC.
165 // See also the corresponding code for external assemblers in
166 // sparc::getSparcAsmModeForCPU().
167 bool IsSparcV9ATarget =
168 (Triple.getArch() == llvm::Triple::sparcv9) &&
169 (Triple.isOSLinux() || Triple.isOSFreeBSD() || Triple.isOSOpenBSD());
170 bool IsSparcV9BTarget = Triple.isOSSolaris();
171 bool IsSparcV8PlusTarget =
172 Triple.getArch() == llvm::Triple::sparc && Triple.isOSSolaris();
173 if (Arg *A = Args.getLastArg(options::OPT_mvis, options::OPT_mno_vis)) {
174 if (A->getOption().matches(options::OPT_mvis))
175 Features.push_back("+vis");
176 else
177 Features.push_back("-vis");
178 } else if (IsSparcV9ATarget) {
179 Features.push_back("+vis");
180 }
181
182 if (Arg *A = Args.getLastArg(options::OPT_mvis2, options::OPT_mno_vis2)) {
183 if (A->getOption().matches(options::OPT_mvis2))
184 Features.push_back("+vis2");
185 else
186 Features.push_back("-vis2");
187 } else if (IsSparcV9BTarget) {
188 Features.push_back("+vis2");
189 }
190
191 if (Arg *A = Args.getLastArg(options::OPT_mvis3, options::OPT_mno_vis3)) {
192 if (A->getOption().matches(options::OPT_mvis3))
193 Features.push_back("+vis3");
194 else
195 Features.push_back("-vis3");
196 }
197
198 if (Arg *A = Args.getLastArg(options::OPT_mhard_quad_float,
199 options::OPT_msoft_quad_float)) {
200 if (A->getOption().matches(options::OPT_mhard_quad_float))
201 Features.push_back("+hard-quad-float");
202 else
203 Features.push_back("-hard-quad-float");
204 }
205
206 if (Arg *A = Args.getLastArg(options::OPT_mv8plus, options::OPT_mno_v8plus)) {
207 if (A->getOption().matches(options::OPT_mv8plus))
208 Features.push_back("+v8plus");
209 } else if (IsSparcV8PlusTarget) {
210 Features.push_back("+v8plus");
211 }
212
213 if (Args.hasArg(options::OPT_ffixed_g1))
214 Features.push_back("+reserve-g1");
215
216 if (Args.hasArg(options::OPT_ffixed_g2))
217 Features.push_back("+reserve-g2");
218
219 if (Args.hasArg(options::OPT_ffixed_g3))
220 Features.push_back("+reserve-g3");
221
222 if (Args.hasArg(options::OPT_ffixed_g4))
223 Features.push_back("+reserve-g4");
224
225 if (Args.hasArg(options::OPT_ffixed_g5))
226 Features.push_back("+reserve-g5");
227
228 if (Args.hasArg(options::OPT_ffixed_g6))
229 Features.push_back("+reserve-g6");
230
231 if (Args.hasArg(options::OPT_ffixed_g7))
232 Features.push_back("+reserve-g7");
233
234 if (Args.hasArg(options::OPT_ffixed_o0))
235 Features.push_back("+reserve-o0");
236
237 if (Args.hasArg(options::OPT_ffixed_o1))
238 Features.push_back("+reserve-o1");
239
240 if (Args.hasArg(options::OPT_ffixed_o2))
241 Features.push_back("+reserve-o2");
242
243 if (Args.hasArg(options::OPT_ffixed_o3))
244 Features.push_back("+reserve-o3");
245
246 if (Args.hasArg(options::OPT_ffixed_o4))
247 Features.push_back("+reserve-o4");
248
249 if (Args.hasArg(options::OPT_ffixed_o5))
250 Features.push_back("+reserve-o5");
251
252 if (Args.hasArg(options::OPT_ffixed_l0))
253 Features.push_back("+reserve-l0");
254
255 if (Args.hasArg(options::OPT_ffixed_l1))
256 Features.push_back("+reserve-l1");
257
258 if (Args.hasArg(options::OPT_ffixed_l2))
259 Features.push_back("+reserve-l2");
260
261 if (Args.hasArg(options::OPT_ffixed_l3))
262 Features.push_back("+reserve-l3");
263
264 if (Args.hasArg(options::OPT_ffixed_l4))
265 Features.push_back("+reserve-l4");
266
267 if (Args.hasArg(options::OPT_ffixed_l5))
268 Features.push_back("+reserve-l5");
269
270 if (Args.hasArg(options::OPT_ffixed_l6))
271 Features.push_back("+reserve-l6");
272
273 if (Args.hasArg(options::OPT_ffixed_l7))
274 Features.push_back("+reserve-l7");
275
276 if (Args.hasArg(options::OPT_ffixed_i0))
277 Features.push_back("+reserve-i0");
278
279 if (Args.hasArg(options::OPT_ffixed_i1))
280 Features.push_back("+reserve-i1");
281
282 if (Args.hasArg(options::OPT_ffixed_i2))
283 Features.push_back("+reserve-i2");
284
285 if (Args.hasArg(options::OPT_ffixed_i3))
286 Features.push_back("+reserve-i3");
287
288 if (Args.hasArg(options::OPT_ffixed_i4))
289 Features.push_back("+reserve-i4");
290
291 if (Args.hasArg(options::OPT_ffixed_i5))
292 Features.push_back("+reserve-i5");
293
294 if (Args.hasArg(options::OPT_mfix_gr712rc)) {
295 Features.push_back("+fix-tn0009");
296 Features.push_back("+fix-tn0011");
297 Features.push_back("+fix-tn0012");
298 Features.push_back("+fix-tn0013");
299 }
300
301 if (Args.hasArg(options::OPT_mfix_ut700)) {
302 Features.push_back("+fix-tn0009");
303 Features.push_back("+fix-tn0010");
304 Features.push_back("+fix-tn0013");
305 }
306}
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition Driver.h:93
DiagnosticBuilder Diag(unsigned DiagID) const
Definition Driver.h:157
FloatABI getSparcFloatABI(const Driver &D, const llvm::opt::ArgList &Args)
void getSparcTargetFeatures(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args, std::vector< llvm::StringRef > &Features)
std::string getSparcTargetCPU(const Driver &D, const llvm::opt::ArgList &Args, const llvm::Triple &Triple)
const char * getSparcAsmModeForCPU(llvm::StringRef Name, const llvm::Triple &Triple)
Top level wrappers for InstallAPI frontend operations.