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