@@ -127,6 +127,11 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
127
127
const llvm::Triple &Triple,
128
128
const ArgList &Args,
129
129
std::vector<StringRef> &Features) {
130
+ // Enable the `lsx` feature on 64-bit LoongArch by default.
131
+ if (Triple.isLoongArch64 () &&
132
+ (!Args.hasArgNoClaim (clang::driver::options::OPT_march_EQ)))
133
+ Features.push_back (" +lsx" );
134
+
130
135
std::string ArchName;
131
136
if (const Arg *A = Args.getLastArg (options::OPT_march_EQ))
132
137
ArchName = A->getValue ();
@@ -145,9 +150,11 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
145
150
} else if (A->getOption ().matches (options::OPT_msingle_float)) {
146
151
Features.push_back (" +f" );
147
152
Features.push_back (" -d" );
153
+ Features.push_back (" -lsx" );
148
154
} else /* Soft-float*/ {
149
155
Features.push_back (" -f" );
150
156
Features.push_back (" -d" );
157
+ Features.push_back (" -lsx" );
151
158
}
152
159
} else if (const Arg *A = Args.getLastArg (options::OPT_mfpu_EQ)) {
153
160
StringRef FPU = A->getValue ();
@@ -157,9 +164,11 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
157
164
} else if (FPU == " 32" ) {
158
165
Features.push_back (" +f" );
159
166
Features.push_back (" -d" );
167
+ Features.push_back (" -lsx" );
160
168
} else if (FPU == " 0" || FPU == " none" ) {
161
169
Features.push_back (" -f" );
162
170
Features.push_back (" -d" );
171
+ Features.push_back (" -lsx" );
163
172
} else {
164
173
D.Diag (diag::err_drv_loongarch_invalid_mfpu_EQ) << FPU;
165
174
}
@@ -174,6 +183,42 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
174
183
A->ignoreTargetSpecific ();
175
184
if (Arg *A = Args.getLastArgNoClaim (options::OPT_mfpu_EQ))
176
185
A->ignoreTargetSpecific ();
186
+ if (Arg *A = Args.getLastArgNoClaim (options::OPT_msimd_EQ))
187
+ A->ignoreTargetSpecific ();
188
+
189
+ // Select lsx/lasx feature determined by -msimd=.
190
+ // Option -msimd= precedes -m[no-]lsx and -m[no-]lasx.
191
+ if (const Arg *A = Args.getLastArg (options::OPT_msimd_EQ)) {
192
+ StringRef MSIMD = A->getValue ();
193
+ if (MSIMD == " lsx" ) {
194
+ // Option -msimd=lsx depends on 64-bit FPU.
195
+ // -m*-float and -mfpu=none/0/32 conflict with -msimd=lsx.
196
+ if (llvm::find (Features, " -d" ) != Features.end ())
197
+ D.Diag (diag::err_drv_loongarch_wrong_fpu_width) << /* LSX*/ 0 ;
198
+ else
199
+ Features.push_back (" +lsx" );
200
+ } else if (MSIMD == " lasx" ) {
201
+ // Option -msimd=lasx depends on 64-bit FPU and LSX.
202
+ // -m*-float, -mfpu=none/0/32 and -mno-lsx conflict with -msimd=lasx.
203
+ if (llvm::find (Features, " -d" ) != Features.end ())
204
+ D.Diag (diag::err_drv_loongarch_wrong_fpu_width) << /* LASX*/ 1 ;
205
+ else if (llvm::find (Features, " -lsx" ) != Features.end ())
206
+ D.Diag (diag::err_drv_loongarch_invalid_simd_option_combination);
207
+
208
+ // The command options do not contain -mno-lasx.
209
+ if (!Args.getLastArg (options::OPT_mno_lasx)) {
210
+ Features.push_back (" +lsx" );
211
+ Features.push_back (" +lasx" );
212
+ }
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" );
218
+ } else {
219
+ D.Diag (diag::err_drv_loongarch_invalid_msimd_EQ) << MSIMD;
220
+ }
221
+ }
177
222
178
223
// Select lsx feature determined by -m[no-]lsx.
179
224
if (const Arg *A = Args.getLastArg (options::OPT_mlsx, options::OPT_mno_lsx)) {
@@ -197,44 +242,13 @@ void loongarch::getLoongArchTargetFeatures(const Driver &D,
197
242
if (A->getOption ().matches (options::OPT_mlasx)) {
198
243
if (llvm::find (Features, " -d" ) != Features.end ())
199
244
D.Diag (diag::err_drv_loongarch_wrong_fpu_width) << /* LASX*/ 1 ;
200
- else if (llvm::find (Features, " -lsx" ) != Features.end ())
201
- D.Diag (diag::err_drv_loongarch_invalid_simd_option_combination);
202
245
else { /* -mlasx*/
203
246
Features.push_back (" +lsx" );
204
247
Features.push_back (" +lasx" );
205
248
}
206
249
} else /* -mno-lasx*/
207
250
Features.push_back (" -lasx" );
208
251
}
209
-
210
- // Select lsx/lasx feature determined by -msimd=.
211
- // Option -msimd= has lower priority than -m[no-]lsx and -m[no-]lasx.
212
- if (const Arg *A = Args.getLastArg (options::OPT_msimd_EQ)) {
213
- StringRef MSIMD = A->getValue ();
214
- if (MSIMD == " lsx" ) {
215
- // Option -msimd=lsx depends on 64-bit FPU.
216
- // -m*-float and -mfpu=none/0/32 conflict with -mlsx.
217
- if (llvm::find (Features, " -d" ) != Features.end ())
218
- D.Diag (diag::err_drv_loongarch_wrong_fpu_width) << /* LSX*/ 0 ;
219
- // The previous option does not contain feature -lsx.
220
- else if (llvm::find (Features, " -lsx" ) == Features.end ())
221
- Features.push_back (" +lsx" );
222
- } else if (MSIMD == " lasx" ) {
223
- // Option -msimd=lasx depends on 64-bit FPU and LSX.
224
- // -m*-float and -mfpu=none/0/32 conflict with -mlsx.
225
- if (llvm::find (Features, " -d" ) != Features.end ())
226
- D.Diag (diag::err_drv_loongarch_wrong_fpu_width) << /* LASX*/ 1 ;
227
- else if (llvm::find (Features, " -lsx" ) != Features.end ())
228
- D.Diag (diag::err_drv_loongarch_invalid_simd_option_combination);
229
- // The previous option does not contain feature -lasx.
230
- else if (llvm::find (Features, " -lasx" ) == Features.end ()) {
231
- Features.push_back (" +lsx" );
232
- Features.push_back (" +lasx" );
233
- }
234
- } else if (MSIMD != " none" ) {
235
- D.Diag (diag::err_drv_loongarch_invalid_msimd_EQ) << MSIMD;
236
- }
237
- }
238
252
}
239
253
240
254
std::string loongarch::postProcessTargetCPUString (const std::string &CPU,
0 commit comments