15#include "llvm/TargetParser/Host.h"
16#include "llvm/TargetParser/LoongArchTargetParser.h"
24 const llvm::Triple &Triple) {
25 assert((Triple.getArch() == llvm::Triple::loongarch32 ||
26 Triple.getArch() == llvm::Triple::loongarch64) &&
28 bool IsLA32 = Triple.getArch() == llvm::Triple::loongarch32;
31 const Arg *MABIArg = Args.getLastArg(options::OPT_mabi_EQ);
34 MABIValue = MABIArg->getValue();
38 const Arg *MFPUArg = Args.getLastArg(options::OPT_mfpu_EQ);
41 StringRef
V = MFPUArg->getValue();
46 else if (
V ==
"0" ||
V ==
"none")
49 D.Diag(diag::err_drv_loongarch_invalid_mfpu_EQ) <<
V;
53 if (
const Arg *A = Args.getLastArg(options::OPT_mdouble_float,
54 options::OPT_msingle_float,
55 options::OPT_msoft_float)) {
58 if (A->getOption().matches(options::OPT_mdouble_float)) {
59 ImpliedABI = IsLA32 ?
"ilp32d" :
"lp64d";
62 if (A->getOption().matches(options::OPT_msingle_float)) {
63 ImpliedABI = IsLA32 ?
"ilp32f" :
"lp64f";
66 if (A->getOption().matches(options::OPT_msoft_float)) {
67 ImpliedABI = IsLA32 ?
"ilp32s" :
"lp64s";
76 if (!MABIValue.empty() && ImpliedABI != MABIValue)
77 D.Diag(diag::warn_drv_loongarch_conflicting_implied_val)
78 << MABIArg->getAsString(Args) << A->getAsString(Args) << ImpliedABI;
80 if (FPU != -1 && ImpliedFPU != FPU)
81 D.Diag(diag::warn_drv_loongarch_conflicting_implied_val)
82 << MFPUArg->getAsString(Args) << A->getAsString(Args) << ImpliedFPU;
88 if (!MABIValue.empty())
94 return IsLA32 ?
"ilp32d" :
"lp64d";
96 return IsLA32 ?
"ilp32f" :
"lp64f";
98 return IsLA32 ?
"ilp32s" :
"lp64s";
104 switch (Triple.getEnvironment()) {
105 case llvm::Triple::GNUSF:
106 case llvm::Triple::MuslSF:
107 return IsLA32 ?
"ilp32s" :
"lp64s";
108 case llvm::Triple::GNUF32:
109 case llvm::Triple::MuslF32:
110 return IsLA32 ?
"ilp32f" :
"lp64f";
111 case llvm::Triple::GNUF64:
122 case llvm::Triple::GNU:
124 return IsLA32 ?
"ilp32d" :
"lp64d";
129 const llvm::Triple &Triple,
131 std::vector<StringRef> &Features) {
133 if (Triple.isLoongArch64() &&
134 (!Args.hasArgNoClaim(clang::driver::options::OPT_march_EQ)))
135 Features.push_back(
"+lsx");
137 std::string ArchName;
138 const Arg *MArch = Args.getLastArg(options::OPT_march_EQ);
140 ArchName = MArch->getValue();
142 llvm::LoongArch::getArchFeatures(ArchName, Features);
143 if (MArch && StringRef(MArch->getValue()) ==
"native")
144 for (
auto &F : llvm::sys::getHostCPUFeatures())
146 Args.MakeArgString((F.second ?
"+" :
"-") + F.first()));
151 if (
const Arg *A = Args.getLastArg(options::OPT_mdouble_float,
152 options::OPT_msingle_float,
153 options::OPT_msoft_float)) {
154 if (A->getOption().matches(options::OPT_mdouble_float)) {
155 Features.push_back(
"+f");
156 Features.push_back(
"+d");
157 }
else if (A->getOption().matches(options::OPT_msingle_float)) {
158 Features.push_back(
"+f");
159 Features.push_back(
"-d");
160 Features.push_back(
"-lsx");
162 Features.push_back(
"-f");
163 Features.push_back(
"-d");
164 Features.push_back(
"-lsx");
166 }
else if (
const Arg *A = Args.getLastArg(options::OPT_mfpu_EQ)) {
167 StringRef FPU = A->getValue();
169 Features.push_back(
"+f");
170 Features.push_back(
"+d");
171 }
else if (FPU ==
"32") {
172 Features.push_back(
"+f");
173 Features.push_back(
"-d");
174 Features.push_back(
"-lsx");
175 }
else if (FPU ==
"0" || FPU ==
"none") {
176 Features.push_back(
"-f");
177 Features.push_back(
"-d");
178 Features.push_back(
"-lsx");
180 D.Diag(diag::err_drv_loongarch_invalid_mfpu_EQ) << FPU;
186 options::OPT_mstrict_align,
"ual");
189 if (Arg *A = Args.getLastArgNoClaim(options::OPT_mabi_EQ))
190 A->ignoreTargetSpecific();
191 if (Arg *A = Args.getLastArgNoClaim(options::OPT_mfpu_EQ))
192 A->ignoreTargetSpecific();
193 if (Arg *A = Args.getLastArgNoClaim(options::OPT_msimd_EQ))
194 A->ignoreTargetSpecific();
198 if (
const Arg *A = Args.getLastArg(options::OPT_msimd_EQ)) {
199 StringRef MSIMD = A->getValue();
200 if (MSIMD ==
"lsx") {
203 if (llvm::find(Features,
"-d") != Features.end())
204 D.Diag(diag::err_drv_loongarch_wrong_fpu_width) << 0;
206 Features.push_back(
"+lsx");
207 }
else if (MSIMD ==
"lasx") {
210 if (llvm::find(Features,
"-d") != Features.end())
211 D.Diag(diag::err_drv_loongarch_wrong_fpu_width) << 1;
212 else if (llvm::find(Features,
"-lsx") != Features.end())
213 D.Diag(diag::err_drv_loongarch_invalid_simd_option_combination);
216 if (!Args.getLastArg(options::OPT_mno_lasx)) {
217 Features.push_back(
"+lsx");
218 Features.push_back(
"+lasx");
220 }
else if (MSIMD ==
"none") {
221 if (llvm::find(Features,
"+lsx") != Features.end())
222 Features.push_back(
"-lsx");
223 if (llvm::find(Features,
"+lasx") != Features.end())
224 Features.push_back(
"-lasx");
226 D.Diag(diag::err_drv_loongarch_invalid_msimd_EQ) << MSIMD;
231 if (
const Arg *A = Args.getLastArg(options::OPT_mlsx, options::OPT_mno_lsx)) {
234 if (A->getOption().matches(options::OPT_mlsx)) {
235 if (llvm::find(Features,
"-d") != Features.end())
236 D.Diag(diag::err_drv_loongarch_wrong_fpu_width) << 0;
238 Features.push_back(
"+lsx");
240 Features.push_back(
"-lsx");
246 Args.getLastArg(options::OPT_mlasx, options::OPT_mno_lasx)) {
249 if (A->getOption().matches(options::OPT_mlasx)) {
250 if (llvm::find(Features,
"-d") != Features.end())
251 D.Diag(diag::err_drv_loongarch_wrong_fpu_width) << 1;
253 Features.push_back(
"+lsx");
254 Features.push_back(
"+lasx");
257 Features.push_back(
"-lasx");
262 Args.getLastArg(options::OPT_mfrecipe, options::OPT_mno_frecipe)) {
263 if (A->getOption().matches(options::OPT_mfrecipe))
264 Features.push_back(
"+frecipe");
266 Features.push_back(
"-frecipe");
271 Args.getLastArg(options::OPT_mlam_bh, options::OPT_mno_lam_bh)) {
272 if (A->getOption().matches(options::OPT_mlam_bh))
273 Features.push_back(
"+lam-bh");
275 Features.push_back(
"-lam-bh");
280 Args.getLastArg(options::OPT_mlamcas, options::OPT_mno_lamcas)) {
281 if (A->getOption().matches(options::OPT_mlamcas))
282 Features.push_back(
"+lamcas");
284 Features.push_back(
"-lamcas");
288 if (
const Arg *A = Args.getLastArg(options::OPT_mld_seq_sa,
289 options::OPT_mno_ld_seq_sa)) {
290 if (A->getOption().matches(options::OPT_mld_seq_sa))
291 Features.push_back(
"+ld-seq-sa");
293 Features.push_back(
"-ld-seq-sa");
298 Args.getLastArg(options::OPT_mdiv32, options::OPT_mno_div32)) {
299 if (A->getOption().matches(options::OPT_mdiv32))
300 Features.push_back(
"+div32");
302 Features.push_back(
"-div32");
307 const llvm::Triple &Triple) {
308 std::string CPUString = CPU;
309 if (CPUString ==
"native") {
310 CPUString = llvm::sys::getHostCPUName();
311 if (CPUString ==
"generic")
312 CPUString = llvm::LoongArch::getDefaultArch(Triple.isLoongArch64());
314 if (CPUString.empty())
315 CPUString = llvm::LoongArch::getDefaultArch(Triple.isLoongArch64());
320 const llvm::Triple &Triple) {
324 if (
const Arg *A = Args.getLastArg(options::OPT_march_EQ)) {
325 Arch = A->getValue();
326 if (Arch ==
"la64v1.0" || Arch ==
"la64v1.1")
327 CPU = llvm::LoongArch::getDefaultArch(Triple.isLoongArch64());
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
The JSON file list parser is used to communicate input to InstallAPI.