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 return IsLA32 ?
"ilp32s" :
"lp64s";
107 case llvm::Triple::GNUF32:
108 return IsLA32 ?
"ilp32f" :
"lp64f";
109 case llvm::Triple::GNUF64:
120 case llvm::Triple::GNU:
122 return IsLA32 ?
"ilp32d" :
"lp64d";
127 const llvm::Triple &Triple,
129 std::vector<StringRef> &Features) {
131 if (Triple.isLoongArch64() &&
132 (!Args.hasArgNoClaim(clang::driver::options::OPT_march_EQ)))
133 Features.push_back(
"+lsx");
135 std::string ArchName;
136 if (
const Arg *A = Args.getLastArg(options::OPT_march_EQ))
137 ArchName = A->getValue();
139 llvm::LoongArch::getArchFeatures(ArchName, Features);
144 if (
const Arg *A = Args.getLastArg(options::OPT_mdouble_float,
145 options::OPT_msingle_float,
146 options::OPT_msoft_float)) {
147 if (A->getOption().matches(options::OPT_mdouble_float)) {
148 Features.push_back(
"+f");
149 Features.push_back(
"+d");
150 }
else if (A->getOption().matches(options::OPT_msingle_float)) {
151 Features.push_back(
"+f");
152 Features.push_back(
"-d");
153 Features.push_back(
"-lsx");
155 Features.push_back(
"-f");
156 Features.push_back(
"-d");
157 Features.push_back(
"-lsx");
159 }
else if (
const Arg *A = Args.getLastArg(options::OPT_mfpu_EQ)) {
160 StringRef FPU = A->getValue();
162 Features.push_back(
"+f");
163 Features.push_back(
"+d");
164 }
else if (FPU ==
"32") {
165 Features.push_back(
"+f");
166 Features.push_back(
"-d");
167 Features.push_back(
"-lsx");
168 }
else if (FPU ==
"0" || FPU ==
"none") {
169 Features.push_back(
"-f");
170 Features.push_back(
"-d");
171 Features.push_back(
"-lsx");
173 D.Diag(diag::err_drv_loongarch_invalid_mfpu_EQ) << FPU;
179 options::OPT_mstrict_align,
"ual");
182 if (Arg *A = Args.getLastArgNoClaim(options::OPT_mabi_EQ))
183 A->ignoreTargetSpecific();
184 if (Arg *A = Args.getLastArgNoClaim(options::OPT_mfpu_EQ))
185 A->ignoreTargetSpecific();
186 if (Arg *A = Args.getLastArgNoClaim(options::OPT_msimd_EQ))
187 A->ignoreTargetSpecific();
191 if (
const Arg *A = Args.getLastArg(options::OPT_msimd_EQ)) {
192 StringRef MSIMD = A->getValue();
193 if (MSIMD ==
"lsx") {
196 if (llvm::find(Features,
"-d") != Features.end())
197 D.Diag(diag::err_drv_loongarch_wrong_fpu_width) << 0;
199 Features.push_back(
"+lsx");
200 }
else if (MSIMD ==
"lasx") {
203 if (llvm::find(Features,
"-d") != Features.end())
204 D.Diag(diag::err_drv_loongarch_wrong_fpu_width) << 1;
205 else if (llvm::find(Features,
"-lsx") != Features.end())
206 D.Diag(diag::err_drv_loongarch_invalid_simd_option_combination);
209 if (!Args.getLastArg(options::OPT_mno_lasx)) {
210 Features.push_back(
"+lsx");
211 Features.push_back(
"+lasx");
213 }
else if (MSIMD ==
"none") {
214 if (llvm::find(Features,
"+lsx") != Features.end())
215 Features.push_back(
"-lsx");
216 if (llvm::find(Features,
"+lasx") != Features.end())
217 Features.push_back(
"-lasx");
219 D.Diag(diag::err_drv_loongarch_invalid_msimd_EQ) << MSIMD;
224 if (
const Arg *A = Args.getLastArg(options::OPT_mlsx, options::OPT_mno_lsx)) {
227 if (A->getOption().matches(options::OPT_mlsx)) {
228 if (llvm::find(Features,
"-d") != Features.end())
229 D.Diag(diag::err_drv_loongarch_wrong_fpu_width) << 0;
231 Features.push_back(
"+lsx");
233 Features.push_back(
"-lsx");
239 Args.getLastArg(options::OPT_mlasx, options::OPT_mno_lasx)) {
242 if (A->getOption().matches(options::OPT_mlasx)) {
243 if (llvm::find(Features,
"-d") != Features.end())
244 D.Diag(diag::err_drv_loongarch_wrong_fpu_width) << 1;
246 Features.push_back(
"+lsx");
247 Features.push_back(
"+lasx");
250 Features.push_back(
"-lasx");
255 const llvm::Triple &Triple) {
256 std::string CPUString = CPU;
257 if (CPUString ==
"native") {
258 CPUString = llvm::sys::getHostCPUName();
259 if (CPUString ==
"generic")
260 CPUString = llvm::LoongArch::getDefaultArch(Triple.isLoongArch64());
262 if (CPUString.empty())
263 CPUString = llvm::LoongArch::getDefaultArch(Triple.isLoongArch64());
268 const llvm::Triple &Triple) {
272 if (
const Arg *A = Args.getLastArg(options::OPT_march_EQ)) {
273 Arch = A->getValue();
274 if (Arch ==
"la64v1.0" || Arch ==
"la64v1.1")
275 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.