clang 24.0.0git
Flang.cpp
Go to the documentation of this file.
1//===-- Flang.cpp - Flang+LLVM ToolChain 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 "Flang.h"
10#include "Arch/RISCV.h"
11#include "Cuda.h"
12
18#include "llvm/Frontend/Debug/Options.h"
19#include "llvm/Support/Path.h"
20#include "llvm/TargetParser/Host.h"
21#include "llvm/TargetParser/RISCVISAInfo.h"
22#include "llvm/TargetParser/RISCVTargetParser.h"
23
24#include <cassert>
25
26using namespace clang::driver;
27using namespace clang::driver::tools;
28using namespace clang;
29using namespace llvm::opt;
30
31/// Add -x lang to \p CmdArgs for \p Input.
32static void addDashXForInput(const ArgList &Args, const InputInfo &Input,
33 ArgStringList &CmdArgs) {
34 CmdArgs.push_back("-x");
35 // Map the driver type to the frontend type.
36 CmdArgs.push_back(types::getTypeName(Input.getType()));
37}
38
39// Translate the dependency-file options into the arguments understood by
40// `flang -fc1`. The options handled here:
41// -M Emit only the dependencies and skip code generation. They are
42// written to stdout unless -MF redirects them.
43// -MM Treated identically to -M. The -MM/-M split exists to omit system
44// headers, but Fortran has no notion of system vs user headers, so
45// there is nothing for -MM to exclude.
46// -MD Compile normally and produce the object file, while also writing the
47// dependency file. Its name defaults to the -o value, or the input
48// file name when -o is absent, with the extension replaced by .d.
49// -MMD Treated identically to -MD, for the same reason -MM equals -M.
50// -MF Set the path of the dependency file to write.
51// -MT Set the dependency target name (the part before the colon).
52// -MQ Like -MT, but additionally quotes characters special to Make.
54 const JobAction &JA,
55 const ArgList &Args,
56 const InputInfo &Output,
57 const InputInfoList &Inputs,
58 ArgStringList &CmdArgs) {
59 Arg *ArgM = Args.getLastArg(options::OPT_M, options::OPT_MM);
60 Arg *ArgMD = Args.getLastArg(options::OPT_MD, options::OPT_MMD);
61
62 if (!ArgM && !ArgMD)
63 return;
64
65 // Drop warnings for -M/-MM so they don't mix into the dependency output.
66 if (ArgM)
67 CmdArgs.push_back("-w");
68 else
69 ArgM = ArgMD;
70
71 // Emit "-MT <target>", quoting Make metacharacters when requested.
72 auto addTarget = [&](StringRef Target, bool Quote) {
73 CmdArgs.push_back("-MT");
74 if (Quote) {
75 SmallString<128> Quoted;
77 CmdArgs.push_back(Args.MakeArgString(Quoted));
78 } else {
79 CmdArgs.push_back(Args.MakeArgString(Target));
80 }
81 };
82
83 // Decide where to write the dependency file.
84 const char *DepFile;
85 if (Arg *MF = Args.getLastArg(options::OPT_MF)) {
86 // -MF gives the path explicitly.
87 DepFile = MF->getValue();
88 C.addFailureResultFile(DepFile, &JA);
89 } else if (Output.getType() == types::TY_Dependencies) {
90 // Plain -M/-MM: the dependency file is the output, so use its name
91 DepFile = Output.getFilename();
92 } else if (!ArgMD) {
93 // -M/-MM with no -o: write the dependencies to stdout.
94 DepFile = "-";
95 } else {
96 // -MD/-MMD: name it after -o, else the input, with a .d extension.
98 if (Arg *OutputOpt = Args.getLastArg(options::OPT_o))
99 P = OutputOpt->getValue();
100 else
101 P = llvm::sys::path::filename(Inputs[0].getBaseInput());
102 llvm::sys::path::replace_extension(P, "d");
103 DepFile = Args.MakeArgString(P);
104 C.addFailureResultFile(DepFile, &JA);
105 }
106 CmdArgs.push_back("-dependency-file");
107 CmdArgs.push_back(DepFile);
108
109 // Render the explicit target(s). -MT is verbatim, -MQ is Make-quoted.
110 bool HasTarget = false;
111 for (const Arg *A : Args.filtered(options::OPT_MT, options::OPT_MQ)) {
112 HasTarget = true;
113 A->claim();
114 addTarget(A->getValue(), A->getOption().matches(options::OPT_MQ));
115 }
116
117 // With no explicit target, default to the object file. In -M/-MM mode -o
118 // names the dependency file, not the target, so derive <base>.o instead.
119 if (!HasTarget) {
120 Arg *OutputOpt = Args.getLastArg(options::OPT_o);
121 if (OutputOpt && Output.getType() != types::TY_Dependencies) {
122 addTarget(OutputOpt->getValue(), /*Quote=*/true);
123 } else {
124 SmallString<128> P(llvm::sys::path::filename(Inputs[0].getBaseInput()));
125 llvm::sys::path::replace_extension(P, "o");
126 addTarget(P, /*Quote=*/true);
127 }
128 }
129}
130
131void Flang::addFortranDialectOptions(const ArgList &Args,
132 ArgStringList &CmdArgs) const {
133 Args.addAllArgs(CmdArgs,
134 {options::OPT_ffixed_form,
135 options::OPT_ffree_form,
136 options::OPT_ffixed_line_length_EQ,
137 options::OPT_fopenacc,
138 options::OPT_finput_charset_EQ,
139 options::OPT_fimplicit_none,
140 options::OPT_fimplicit_none_ext,
141 options::OPT_fno_implicit_none,
142 options::OPT_fbackslash,
143 options::OPT_fno_backslash,
144 options::OPT_flogical_abbreviations,
145 options::OPT_fno_logical_abbreviations,
146 options::OPT_fxor_operator,
147 options::OPT_fno_xor_operator,
148 options::OPT_falternative_parameter_statement,
149 options::OPT_fdefault_integer_4,
150 options::OPT_fdefault_real_4,
151 options::OPT_fdefault_real_8,
152 options::OPT_fdefault_integer_8,
153 options::OPT_fdefault_double_8,
154 options::OPT_flarge_sizes,
155 options::OPT_fno_automatic,
156 options::OPT_fhermetic_module_files,
157 options::OPT_frealloc_lhs,
158 options::OPT_fno_realloc_lhs,
159 options::OPT_fsave_main_program,
160 options::OPT_fd_lines_as_code,
161 options::OPT_fd_lines_as_comments,
162 options::OPT_fno_save_main_program,
163 options::OPT_fprefer_intrinsic_module_use_association,
164 options::OPT_fno_prefer_intrinsic_module_use_association});
165}
166
167void Flang::addPreprocessingOptions(const ArgList &Args,
168 ArgStringList &CmdArgs) const {
169 Args.addAllArgs(CmdArgs,
170 {options::OPT_P, options::OPT_D, options::OPT_U,
171 options::OPT_I, options::OPT_cpp, options::OPT_nocpp});
172}
173
174/// @C shouldLoopVersion
175///
176/// Check if Loop Versioning should be enabled.
177/// We look for the last of one of the following:
178/// -Ofast, -O4, -O<number> and -f[no-]version-loops-for-stride.
179/// Loop versioning is disabled if the last option is
180/// -fno-version-loops-for-stride.
181/// Loop versioning is enabled if the last option is one of:
182/// -floop-versioning
183/// -Ofast
184/// -O4
185/// -O3
186/// For all other cases, loop versioning is disabled.
187///
188/// The gfortran compiler automatically enables the option for -O3 or -Ofast.
189///
190/// @return true if loop-versioning should be enabled, otherwise false.
191static bool shouldLoopVersion(const ArgList &Args) {
192 const Arg *LoopVersioningArg = Args.getLastArg(
193 options::OPT_Ofast, options::OPT_O, options::OPT_O4,
194 options::OPT_floop_versioning, options::OPT_fno_loop_versioning);
195 if (!LoopVersioningArg)
196 return false;
197
198 if (LoopVersioningArg->getOption().matches(options::OPT_fno_loop_versioning))
199 return false;
200
201 if (LoopVersioningArg->getOption().matches(options::OPT_floop_versioning))
202 return true;
203
204 if (LoopVersioningArg->getOption().matches(options::OPT_Ofast) ||
205 LoopVersioningArg->getOption().matches(options::OPT_O4))
206 return true;
207
208 if (LoopVersioningArg->getOption().matches(options::OPT_O)) {
209 StringRef S(LoopVersioningArg->getValue());
210 unsigned OptLevel = 0;
211 // Note -Os or Oz woould "fail" here, so return false. Which is the
212 // desiered behavior.
213 if (S.getAsInteger(10, OptLevel))
214 return false;
215
216 return OptLevel > 2;
217 }
218
219 llvm_unreachable("We should not end up here");
220 return false;
221}
222
223void Flang::addDebugOptions(const llvm::opt::ArgList &Args, const JobAction &JA,
224 const InputInfo &Output, const InputInfo &Input,
225 llvm::opt::ArgStringList &CmdArgs) const {
226 const auto &TC = getToolChain();
227 const Driver &D = TC.getDriver();
228 Args.addAllArgs(CmdArgs,
229 {options::OPT_module_dir,
230 options::OPT_fdebug_module_writer,
231 options::OPT_fintrinsic_modules_path,
232 options::OPT_pedantic,
233 options::OPT_std_EQ,
234 options::OPT_W_Joined,
235 options::OPT_fconvert_EQ,
236 options::OPT_fpass_plugin_EQ,
237 options::OPT_funderscoring,
238 options::OPT_fno_underscoring,
239 options::OPT_funsigned,
240 options::OPT_fno_unsigned,
241 options::OPT_fenumeration_type,
242 options::OPT_fno_enumeration_type,
243 options::OPT_fout_of_bounds_subscripts,
244 options::OPT_fno_out_of_bounds_subscripts,
245 options::OPT_fopenacc_default_none_scalars_strict,
246 options::OPT_fno_openacc_default_none_scalars_strict,
247 options::OPT_fopenacc_multiple_names_in_routine,
248 options::OPT_fno_openacc_multiple_names_in_routine,
249 options::OPT_finstrument_functions});
250
251 llvm::codegenoptions::DebugInfoKind DebugInfoKind;
252 bool hasDwarfNArg = getDwarfNArg(Args) != nullptr;
253 if (Args.hasArg(options::OPT_gN_Group)) {
254 Arg *gNArg = Args.getLastArg(options::OPT_gN_Group);
255 DebugInfoKind = debugLevelToInfoKind(*gNArg);
256 } else if (Args.hasArg(options::OPT_g_Flag) || hasDwarfNArg) {
257 DebugInfoKind = llvm::codegenoptions::FullDebugInfo;
258 } else {
259 DebugInfoKind = llvm::codegenoptions::NoDebugInfo;
260 }
261 addDebugInfoKind(CmdArgs, DebugInfoKind);
262 // Pass on the DWARF version when debug information is being generated, or
263 // when -gdwarf-N names a version. Leaving it out means the version stays
264 // unset and the backend falls back to dwarf::DWARF_VERSION (4) instead of
265 // honouring toolchain default like clang does.
266 //
267 // Note that both conditions are needed to match clang for cases like
268 // "-gdwarf-5 -g0".
269 if (hasDwarfNArg || DebugInfoKind != llvm::codegenoptions::NoDebugInfo) {
270 const unsigned DwarfVersion = getDwarfVersion(getToolChain(), Args);
271 CmdArgs.push_back(
272 Args.MakeArgString("-dwarf-version=" + Twine(DwarfVersion)));
273 }
274 if (Args.hasArg(options::OPT_gsplit_dwarf) ||
275 Args.hasArg(options::OPT_gsplit_dwarf_EQ)) {
276 // FIXME: -gsplit-dwarf on AIX is currently unimplemented.
277 if (TC.getTriple().isOSAIX()) {
278 D.Diag(diag::err_drv_unsupported_opt_for_target)
279 << Args.getLastArg(options::OPT_gsplit_dwarf)->getSpelling()
280 << TC.getTriple().str();
281 return;
282 }
283 if (DebugInfoKind == llvm::codegenoptions::NoDebugInfo)
284 return;
285
286 Arg *SplitDWARFArg;
287 DwarfFissionKind DwarfFission = getDebugFissionKind(D, Args, SplitDWARFArg);
288
289 if (DwarfFission == DwarfFissionKind::None ||
290 !checkDebugInfoOption(SplitDWARFArg, Args, D, TC))
291 return;
292
293 if (!TC.getTriple().isOSBinFormatELF() &&
294 !TC.getTriple().isOSBinFormatWasm() &&
295 !TC.getTriple().isOSBinFormatCOFF()) {
296 D.Diag(diag::warn_drv_unsupported_debug_info_opt_for_target)
297 << SplitDWARFArg->getSpelling() << TC.getTriple().str();
298 return;
299 }
300
303 return;
304
305 const char *SplitDWARFOut = SplitDebugName(JA, Args, Input, Output);
306 CmdArgs.push_back("-split-dwarf-file");
307 CmdArgs.push_back(SplitDWARFOut);
308 if (DwarfFission == DwarfFissionKind::Split) {
309 CmdArgs.push_back("-split-dwarf-output");
310 CmdArgs.push_back(SplitDWARFOut);
311 }
312 }
313
314 // Handle compressed debug sections (-gz).
315 renderDebugInfoCompressionArgs(Args, CmdArgs, D, TC);
316
317 addDebugInfoForProfilingArgs(D, TC, Args, CmdArgs);
318}
319
320void Flang::addCodegenOptions(const ArgList &Args,
321 ArgStringList &CmdArgs) const {
322 Arg *stackArrays =
323 Args.getLastArg(options::OPT_Ofast, options::OPT_fstack_arrays,
324 options::OPT_fno_stack_arrays);
325 if (stackArrays &&
326 !stackArrays->getOption().matches(options::OPT_fno_stack_arrays))
327 CmdArgs.push_back("-fstack-arrays");
328
329 if (Args.hasFlag(options::OPT_fsafe_trampoline,
330 options::OPT_fno_safe_trampoline, false)) {
331 const llvm::Triple &T = getToolChain().getTriple();
332 if (T.getArch() == llvm::Triple::x86_64 ||
333 T.getArch() == llvm::Triple::aarch64 ||
334 T.getArch() == llvm::Triple::aarch64_be) {
335 CmdArgs.push_back("-fsafe-trampoline");
336 } else {
338 diag::warn_drv_unsupported_option_for_target)
339 << "-fsafe-trampoline" << T.str();
340 }
341 }
342
343 // -fno-protect-parens is the default for -Ofast.
344 if (!Args.hasFlag(options::OPT_fprotect_parens,
345 options::OPT_fno_protect_parens,
346 /*Default=*/!Args.hasArg(options::OPT_Ofast)))
347 CmdArgs.push_back("-fno-protect-parens");
348
349 if (Args.hasFlag(options::OPT_funsafe_cray_pointers,
350 options::OPT_fno_unsafe_cray_pointers, false)) {
351 // TODO: currently passed as MLIR option
352 CmdArgs.push_back("-mmlir");
353 CmdArgs.push_back("-unsafe-cray-pointers");
354 }
355
356 Args.addOptInFlag(CmdArgs, options::OPT_fexperimental_loop_fusion,
357 options::OPT_fno_experimental_loop_fusion);
358 Args.AddLastArg(CmdArgs, options::OPT_ffp_sum_reassociation,
359 options::OPT_fno_fp_sum_reassociation);
360
361 handleInterchangeLoopsArgs(Args, CmdArgs);
362 handleVectorizeLoopsArgs(Args, CmdArgs);
363 handleVectorizeSLPArgs(Args, CmdArgs);
364
365 if (shouldLoopVersion(Args))
366 CmdArgs.push_back("-fversion-loops-for-stride");
367
368 for (const auto &arg :
369 Args.getAllArgValues(options::OPT_frepack_arrays_contiguity_EQ))
370 if (arg != "whole" && arg != "innermost") {
371 getToolChain().getDriver().Diag(diag::err_drv_unsupported_option_argument)
372 << "-frepack-arrays-contiguity=" << arg;
373 }
374
375 Args.addAllArgs(
376 CmdArgs,
377 {options::OPT_fdo_concurrent_to_openmp_EQ,
378 options::OPT_fno_ppc_native_vec_elem_order,
379 options::OPT_fppc_native_vec_elem_order, options::OPT_finit_global_zero,
380 options::OPT_fno_init_global_zero, options::OPT_frepack_arrays,
381 options::OPT_fno_repack_arrays,
382 options::OPT_frepack_arrays_contiguity_EQ,
383 options::OPT_fstack_repack_arrays, options::OPT_fno_stack_repack_arrays,
384 options::OPT_ftime_report, options::OPT_ftime_report_EQ,
385 options::OPT_funroll_loops, options::OPT_fno_unroll_loops,
386 options::OPT_relaxed_c_loc});
387
388 const llvm::Triple &Triple = getToolChain().getEffectiveTriple();
389 addSeparateSectionFlags(Triple, Args, CmdArgs);
390
391 if (Args.hasArg(options::OPT_fcoarray))
392 CmdArgs.push_back("-fcoarray");
393}
394
395void Flang::addLTOOptions(const ArgList &Args, ArgStringList &CmdArgs) const {
396 const ToolChain &TC = getToolChain();
397 LTOKind LTOMode = TC.getLTOMode(Args);
398 // LTO mode is parsed by the Clang driver library.
399 assert(LTOMode != LTOK_Unknown && "Unknown LTO mode.");
400 if (LTOMode == LTOK_Full)
401 CmdArgs.push_back("-flto=full");
402 else if (LTOMode == LTOK_Thin)
403 CmdArgs.push_back("-flto=thin");
404
405 if (Args.hasFlag(options::OPT_fsplit_lto_unit,
406 options::OPT_fno_split_lto_unit, /*Default=*/false))
407 CmdArgs.push_back("-fsplit-lto-unit");
408
409 Args.addAllArgs(CmdArgs, {options::OPT_ffat_lto_objects,
410 options::OPT_fno_fat_lto_objects});
411}
412
413void Flang::addPicOptions(const ArgList &Args, ArgStringList &CmdArgs) const {
414 // ParsePICArgs parses -fPIC/-fPIE and their variants and returns a tuple of
415 // (RelocationModel, PICLevel, IsPIE).
416 llvm::Reloc::Model RelocationModel;
417 unsigned PICLevel;
418 bool IsPIE;
419 std::tie(RelocationModel, PICLevel, IsPIE) =
420 ParsePICArgs(getToolChain(), Args);
421
422 if (auto *RMName = RelocationModelName(RelocationModel)) {
423 CmdArgs.push_back("-mrelocation-model");
424 CmdArgs.push_back(RMName);
425 }
426 if (PICLevel > 0) {
427 CmdArgs.push_back("-pic-level");
428 CmdArgs.push_back(PICLevel == 1 ? "1" : "2");
429 if (IsPIE)
430 CmdArgs.push_back("-pic-is-pie");
431 }
432}
433
434void Flang::AddAArch64TargetArgs(const ArgList &Args,
435 ArgStringList &CmdArgs) const {
436 // Handle -msve_vector_bits=<bits>
437 if (Arg *A = Args.getLastArg(options::OPT_msve_vector_bits_EQ)) {
438 StringRef Val = A->getValue();
439 const Driver &D = getToolChain().getDriver();
440 if (Val == "128" || Val == "256" || Val == "512" || Val == "1024" ||
441 Val == "2048" || Val == "128+" || Val == "256+" || Val == "512+" ||
442 Val == "1024+" || Val == "2048+") {
443 unsigned Bits = 0;
444 if (!Val.consume_back("+")) {
445 [[maybe_unused]] bool Invalid = Val.getAsInteger(10, Bits);
446 assert(!Invalid && "Failed to parse value");
447 CmdArgs.push_back(
448 Args.MakeArgString("-mvscale-max=" + llvm::Twine(Bits / 128)));
449 }
450
451 [[maybe_unused]] bool Invalid = Val.getAsInteger(10, Bits);
452 assert(!Invalid && "Failed to parse value");
453 CmdArgs.push_back(
454 Args.MakeArgString("-mvscale-min=" + llvm::Twine(Bits / 128)));
455 // Silently drop requests for vector-length agnostic code as it's implied.
456 } else if (Val != "scalable")
457 // Handle the unsupported values passed to msve-vector-bits.
458 D.Diag(diag::err_drv_unsupported_option_argument)
459 << A->getSpelling() << Val;
460 }
461}
462
463void Flang::AddLoongArch64TargetArgs(const ArgList &Args,
464 ArgStringList &CmdArgs) const {
465 const Driver &D = getToolChain().getDriver();
466 // Currently, flang only support `-mabi=lp64d` in LoongArch64.
467 if (const Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) {
468 StringRef V = A->getValue();
469 if (V != "lp64d") {
470 D.Diag(diag::err_drv_argument_not_allowed_with) << "-mabi" << V;
471 }
472 }
473
474 if (const Arg *A = Args.getLastArg(options::OPT_mannotate_tablejump,
475 options::OPT_mno_annotate_tablejump)) {
476 if (A->getOption().matches(options::OPT_mannotate_tablejump)) {
477 CmdArgs.push_back("-mllvm");
478 CmdArgs.push_back("-loongarch-annotate-tablejump");
479 }
480 }
481}
482
483void Flang::AddPPCTargetArgs(const ArgList &Args,
484 ArgStringList &CmdArgs) const {
485 const Driver &D = getToolChain().getDriver();
486 bool VecExtabi = false;
487
488 if (const Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) {
489 StringRef V = A->getValue();
490 if (V == "vec-extabi")
491 VecExtabi = true;
492 else if (V == "vec-default")
493 VecExtabi = false;
494 else
495 D.Diag(diag::err_drv_unsupported_option_argument)
496 << A->getSpelling() << V;
497 }
498
499 const llvm::Triple &T = getToolChain().getTriple();
500 if (VecExtabi) {
501 if (!T.isOSAIX()) {
502 D.Diag(diag::err_drv_unsupported_opt_for_target)
503 << "-mabi=vec-extabi" << T.str();
504 }
505 CmdArgs.push_back("-mabi=vec-extabi");
506 }
507}
508
509void Flang::AddRISCVTargetArgs(const ArgList &Args,
510 ArgStringList &CmdArgs) const {
511 const Driver &D = getToolChain().getDriver();
512 const llvm::Triple &Triple = getToolChain().getTriple();
513
514 StringRef ABIName = riscv::getRISCVABI(Args, Triple);
515 if (ABIName == "lp64" || ABIName == "lp64f" || ABIName == "lp64d")
516 CmdArgs.push_back(Args.MakeArgString("-mabi=" + ABIName));
517 else
518 D.Diag(diag::err_drv_unsupported_option_argument) << "-mabi=" << ABIName;
519
520 // Handle -mrvv-vector-bits=<bits>
521 if (Arg *A = Args.getLastArg(options::OPT_mrvv_vector_bits_EQ)) {
522 StringRef Val = A->getValue();
523
524 // Get minimum VLen from march.
525 unsigned MinVLen = 0;
526 std::string Arch = riscv::getRISCVArch(Args, Triple);
527 auto ISAInfo = llvm::RISCVISAInfo::parseArchString(
528 Arch, /*EnableExperimentalExtensions*/ true);
529 // Ignore parsing error.
530 if (!errorToBool(ISAInfo.takeError()))
531 MinVLen = (*ISAInfo)->getMinVLen();
532
533 // If the value is "zvl", use MinVLen from march. Otherwise, try to parse
534 // as integer as long as we have a MinVLen.
535 unsigned Bits = 0;
536 if (Val == "zvl" && MinVLen >= llvm::RISCV::RVVBitsPerBlock) {
537 Bits = MinVLen;
538 } else if (!Val.getAsInteger(10, Bits)) {
539 // Only accept power of 2 values beteen RVVBitsPerBlock and 65536 that
540 // at least MinVLen.
541 if (Bits < MinVLen || Bits < llvm::RISCV::RVVBitsPerBlock ||
542 Bits > 65536 || !llvm::isPowerOf2_32(Bits))
543 Bits = 0;
544 }
545
546 // If we got a valid value try to use it.
547 if (Bits != 0) {
548 unsigned VScaleMin = Bits / llvm::RISCV::RVVBitsPerBlock;
549 CmdArgs.push_back(
550 Args.MakeArgString("-mvscale-max=" + llvm::Twine(VScaleMin)));
551 CmdArgs.push_back(
552 Args.MakeArgString("-mvscale-min=" + llvm::Twine(VScaleMin)));
553 } else if (Val != "scalable") {
554 // Handle the unsupported values passed to mrvv-vector-bits.
555 D.Diag(diag::err_drv_unsupported_option_argument)
556 << A->getSpelling() << Val;
557 }
558 }
559}
560
561void Flang::AddX86_64TargetArgs(const ArgList &Args,
562 ArgStringList &CmdArgs) const {
563 if (Arg *A = Args.getLastArg(options::OPT_masm_EQ)) {
564 StringRef Value = A->getValue();
565 if (Value == "intel" || Value == "att") {
566 CmdArgs.push_back(Args.MakeArgString("-mllvm"));
567 CmdArgs.push_back(Args.MakeArgString("-x86-asm-syntax=" + Value));
568 } else {
569 getToolChain().getDriver().Diag(diag::err_drv_unsupported_option_argument)
570 << A->getSpelling() << Value;
571 }
572 }
573}
574
575static void addVSDefines(const ToolChain &TC, const ArgList &Args,
576 ArgStringList &CmdArgs) {
577
578 unsigned ver = 0;
579 const VersionTuple vt = TC.computeMSVCVersion(nullptr, Args);
580 ver = vt.getMajor() * 10000000 + vt.getMinor().value_or(0) * 100000 +
581 vt.getSubminor().value_or(0);
582 CmdArgs.push_back(Args.MakeArgString("-D_MSC_VER=" + Twine(ver / 100000)));
583 CmdArgs.push_back(Args.MakeArgString("-D_MSC_FULL_VER=" + Twine(ver)));
584 CmdArgs.push_back(Args.MakeArgString("-D_WIN32"));
585
586 const llvm::Triple &triple = TC.getTriple();
587 if (triple.isAArch64()) {
588 CmdArgs.push_back("-D_M_ARM64=1");
589 } else if (triple.isX86() && triple.isArch32Bit()) {
590 CmdArgs.push_back("-D_M_IX86=600");
591 } else if (triple.isX86() && triple.isArch64Bit()) {
592 CmdArgs.push_back("-D_M_X64=100");
593 } else {
594 llvm_unreachable(
595 "Flang on Windows only supports X86_32, X86_64 and AArch64");
596 }
597}
598
599static void processVSRuntimeLibrary(const ToolChain &TC, const ArgList &Args,
600 ArgStringList &CmdArgs) {
601 assert(TC.getTriple().isKnownWindowsMSVCEnvironment() &&
602 "can only add VS runtime library on Windows!");
603
604 // Flang/Clang (including clang-cl) -compiled programs targeting the MSVC ABI
605 // should only depend on msv(u)crt. LLVM still emits libgcc/compiler-rt
606 // functions in some cases like 128-bit integer math (__udivti3, __modti3,
607 // __fixsfti, __floattidf, ...) that msvc does not support. We are injecting a
608 // dependency to Compiler-RT's builtin library where these are implemented.
609 CmdArgs.push_back(Args.MakeArgString(
610 "--dependent-lib=" + TC.getCompilerRTBasename(Args, "builtins")));
611
612 unsigned RTOptionID = options::OPT__SLASH_MT;
613 if (auto *rtl = Args.getLastArg(options::OPT_fms_runtime_lib_EQ)) {
614 RTOptionID = llvm::StringSwitch<unsigned>(rtl->getValue())
615 .Case("static", options::OPT__SLASH_MT)
616 .Case("static_dbg", options::OPT__SLASH_MTd)
617 .Case("dll", options::OPT__SLASH_MD)
618 .Case("dll_dbg", options::OPT__SLASH_MDd)
619 .Default(options::OPT__SLASH_MT);
620 }
621 switch (RTOptionID) {
622 case options::OPT__SLASH_MT:
623 CmdArgs.push_back("-D_MT");
624 CmdArgs.push_back("--dependent-lib=libcmt");
625 CmdArgs.push_back("--dependent-lib=flang_rt.runtime.static.lib");
626 break;
627 case options::OPT__SLASH_MTd:
628 CmdArgs.push_back("-D_MT");
629 CmdArgs.push_back("-D_DEBUG");
630 CmdArgs.push_back("--dependent-lib=libcmtd");
631 CmdArgs.push_back("--dependent-lib=flang_rt.runtime.static_dbg.lib");
632 break;
633 case options::OPT__SLASH_MD:
634 CmdArgs.push_back("-D_MT");
635 CmdArgs.push_back("-D_DLL");
636 CmdArgs.push_back("--dependent-lib=msvcrt");
637 CmdArgs.push_back("--dependent-lib=flang_rt.runtime.dynamic.lib");
638 break;
639 case options::OPT__SLASH_MDd:
640 CmdArgs.push_back("-D_MT");
641 CmdArgs.push_back("-D_DEBUG");
642 CmdArgs.push_back("-D_DLL");
643 CmdArgs.push_back("--dependent-lib=msvcrtd");
644 CmdArgs.push_back("--dependent-lib=flang_rt.runtime.dynamic_dbg.lib");
645 break;
646 }
647}
648
649void Flang::AddAMDGPUTargetArgs(const ArgList &Args, ArgStringList &CmdArgs,
650 BoundArch BA,
651 Action::OffloadKind DeviceOffloadKind) const {
652 if (Arg *A = Args.getLastArg(options::OPT_mcode_object_version_EQ)) {
653 StringRef Val = A->getValue();
654 CmdArgs.push_back(Args.MakeArgString("-mcode-object-version=" + Val));
655 CmdArgs.push_back(Args.MakeArgString("-mllvm"));
656 CmdArgs.push_back(
657 Args.MakeArgString("--amdhsa-code-object-version=" + Val));
658 }
659
660 const ToolChain &TC = getToolChain();
661 TC.addClangTargetOptions(Args, CmdArgs, BA, DeviceOffloadKind);
662}
663
664void Flang::AddNVPTXTargetArgs(const ArgList &Args, ArgStringList &CmdArgs,
665 BoundArch BA,
666 Action::OffloadKind DeviceOffloadKind) const {
667 // we cannot use addClangTargetOptions, as it appends unsupported args for
668 // flang: -fcuda-is-device, -fno-threadsafe-statics,
669 // -fcuda-allow-variadic-functions and -target-sdk-version Instead we manually
670 // detect the CUDA installation and link libdevice
671 const ToolChain &TC = getToolChain();
672 const Driver &D = TC.getDriver();
673 const llvm::Triple &Triple = TC.getEffectiveTriple();
674
675 if (!Args.hasFlag(options::OPT_offloadlib, options::OPT_no_offloadlib, true))
676 return;
677
678 // Detect CUDA installation and link libdevice
679 CudaInstallationDetector CudaInstallation(D, Triple, Args);
680 if (!CudaInstallation.isValid()) {
681 D.Diag(diag::err_drv_no_cuda_installation);
682 return;
683 }
684
685 StringRef GpuArch = Args.getLastArgValue(options::OPT_march_EQ);
686 if (GpuArch.empty()) {
687 D.Diag(diag::err_drv_offload_missing_gpu_arch) << "NVPTX" << "flang";
688 return;
689 }
690
691 std::string LibDeviceFile = CudaInstallation.getLibDeviceFile(GpuArch);
692 if (LibDeviceFile.empty()) {
693 D.Diag(diag::err_drv_no_cuda_libdevice) << GpuArch;
694 return;
695 }
696
697 CmdArgs.push_back("-mlink-builtin-bitcode");
698 CmdArgs.push_back(Args.MakeArgString(LibDeviceFile));
699}
700
701void Flang::addTargetOptions(const ArgList &Args, ArgStringList &CmdArgs,
702 BoundArch BA,
703 Action::OffloadKind DeviceOffloadKind) const {
704 const ToolChain &TC = getToolChain();
705 const llvm::Triple &Triple = TC.getEffectiveTriple();
706 const Driver &D = TC.getDriver();
707
708 std::string CPU = getCPUName(D, Args, Triple);
709 if (!CPU.empty()) {
710 CmdArgs.push_back("-target-cpu");
711 CmdArgs.push_back(Args.MakeArgString(CPU));
712 }
713
714 addOutlineAtomicsArgs(D, getToolChain(), Args, CmdArgs, Triple);
715
716 // Add the target features.
717 switch (TC.getArch()) {
718 default:
719 getTargetFeatures(D, Triple, Args, CmdArgs, /*ForAs*/ false);
720 break;
721 case llvm::Triple::aarch64:
722 getTargetFeatures(D, Triple, Args, CmdArgs, /*ForAs*/ false);
723 AddAArch64TargetArgs(Args, CmdArgs);
724 break;
725 case llvm::Triple::amdgpu:
726 case llvm::Triple::r600:
727 getTargetFeatures(D, Triple, Args, CmdArgs, /*ForAs*/ false);
728 AddAMDGPUTargetArgs(Args, CmdArgs, BA, DeviceOffloadKind);
729 break;
730 case llvm::Triple::nvptx:
731 case llvm::Triple::nvptx64:
732 AddNVPTXTargetArgs(Args, CmdArgs, BA, DeviceOffloadKind);
733 break;
734 case llvm::Triple::riscv64:
735 getTargetFeatures(D, Triple, Args, CmdArgs, /*ForAs*/ false);
736 AddRISCVTargetArgs(Args, CmdArgs);
737 break;
738 case llvm::Triple::x86_64:
739 getTargetFeatures(D, Triple, Args, CmdArgs, /*ForAs*/ false);
740 AddX86_64TargetArgs(Args, CmdArgs);
741 break;
742 case llvm::Triple::ppc:
743 case llvm::Triple::ppc64:
744 case llvm::Triple::ppc64le:
745 getTargetFeatures(D, Triple, Args, CmdArgs, /*ForAs*/ false);
746 AddPPCTargetArgs(Args, CmdArgs);
747 break;
748 case llvm::Triple::loongarch64:
749 getTargetFeatures(D, Triple, Args, CmdArgs, /*ForAs*/ false);
750 AddLoongArch64TargetArgs(Args, CmdArgs);
751 break;
752 }
753
754 if (Arg *A = Args.getLastArg(options::OPT_fveclib)) {
755 StringRef Name = A->getValue();
756 if (Name == "SVML") {
757 if (Triple.getArch() != llvm::Triple::x86 &&
758 Triple.getArch() != llvm::Triple::x86_64)
759 D.Diag(diag::err_drv_unsupported_opt_for_target)
760 << Name << Triple.getArchName();
761 } else if (Name == "AMDLIBM") {
762 if (Triple.getArch() != llvm::Triple::x86 &&
763 Triple.getArch() != llvm::Triple::x86_64)
764 D.Diag(diag::err_drv_unsupported_opt_for_target)
765 << Name << Triple.getArchName();
766 } else if (Name == "libmvec") {
767 if (Triple.getArch() != llvm::Triple::x86 &&
768 Triple.getArch() != llvm::Triple::x86_64 &&
769 Triple.getArch() != llvm::Triple::aarch64 &&
770 Triple.getArch() != llvm::Triple::aarch64_be)
771 D.Diag(diag::err_drv_unsupported_opt_for_target)
772 << Name << Triple.getArchName();
773 } else if (Name == "SLEEF" || Name == "ArmPL") {
774 if (Triple.getArch() != llvm::Triple::aarch64 &&
775 Triple.getArch() != llvm::Triple::aarch64_be)
776 D.Diag(diag::err_drv_unsupported_opt_for_target)
777 << Name << Triple.getArchName();
778 }
779
780 if (Triple.isOSDarwin()) {
781 // flang doesn't currently suport nostdlib, nodefaultlibs. Adding these
782 // here incase they are added someday
783 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
784 if (A->getValue() == StringRef{"Accelerate"}) {
785 CmdArgs.push_back("-framework");
786 CmdArgs.push_back("Accelerate");
787 }
788 }
789 }
790 A->render(Args, CmdArgs);
791 }
792
793 if (Triple.isKnownWindowsMSVCEnvironment()) {
794 processVSRuntimeLibrary(TC, Args, CmdArgs);
795 addVSDefines(TC, Args, CmdArgs);
796 }
797
798 // TODO: Add target specific flags, ABI, mtune option etc.
799 if (const Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) {
800 CmdArgs.push_back("-tune-cpu");
801 if (A->getValue() == StringRef{"native"})
802 CmdArgs.push_back(Args.MakeArgString(llvm::sys::getHostCPUName()));
803 else
804 CmdArgs.push_back(A->getValue());
805 }
806
807 Args.addAllArgs(CmdArgs,
808 {options::OPT_fverbose_asm, options::OPT_fno_verbose_asm,
809 options::OPT_fatomic_ignore_denormal_mode,
810 options::OPT_fno_atomic_ignore_denormal_mode,
811 options::OPT_fatomic_fine_grained_memory,
812 options::OPT_fno_atomic_fine_grained_memory,
813 options::OPT_fatomic_remote_memory,
814 options::OPT_fno_atomic_remote_memory,
815 options::OPT_munsafe_fp_atomics});
816}
817
818void Flang::addOffloadOptions(Compilation &C, const InputInfoList &Inputs,
819 const JobAction &JA, const ArgList &Args,
820 ArgStringList &CmdArgs) const {
821 bool IsOpenMPDevice = JA.isDeviceOffloading(Action::OFK_OpenMP);
822 bool IsHostOffloadingAction = JA.isHostOffloading(Action::OFK_OpenMP) ||
823 JA.isHostOffloading(C.getActiveOffloadKinds());
824
825 // Tell the frontend when it is compiling for an offloading device, regardless
826 // of offloading programming model.
828 CmdArgs.push_back("-foffload-device");
829
830 // Skips the primary input file, which is the input file that the compilation
831 // proccess will be executed upon (e.g. the host bitcode file) and
832 // adds other secondary input (e.g. device bitcode files for embedding to the
833 // -fembed-offload-object argument or the host IR file for proccessing
834 // during device compilation to the fopenmp-host-ir-file-path argument via
835 // OpenMPDeviceInput). This is condensed logic from the ConstructJob
836 // function inside of the Clang driver for pushing on further input arguments
837 // needed for offloading during various phases of compilation.
838 for (size_t i = 1; i < Inputs.size(); ++i) {
839 if (Inputs[i].getType() == types::TY_Nothing) {
840 // contains nothing, so it's skippable
841 } else if (IsHostOffloadingAction) {
842 CmdArgs.push_back(
843 Args.MakeArgString("-fembed-offload-object=" +
844 getToolChain().getInputFilename(Inputs[i])));
845 } else if (IsOpenMPDevice) {
846 if (Inputs[i].getFilename()) {
847 CmdArgs.push_back("-fopenmp-host-ir-file-path");
848 CmdArgs.push_back(Args.MakeArgString(Inputs[i].getFilename()));
849 } else {
850 llvm_unreachable("missing openmp host-ir file for device offloading");
851 }
852 } else {
853 llvm_unreachable(
854 "unexpectedly given multiple inputs or given unknown input");
855 }
856 }
857
858 // When in OpenMP offloading mode, forward assumptions information about
859 // thread and team counts in the target device. The host needs to know about
860 // this to prevent the SPMD to SPMD-no-loop promotion being done differently
861 // for host and device on the same target region.
862 if (Args.hasFlag(options::OPT_fopenmp_assume_teams_oversubscription,
863 options::OPT_fno_openmp_assume_teams_oversubscription,
864 /*Default=*/false))
865 CmdArgs.push_back("-fopenmp-assume-teams-oversubscription");
866 if (Args.hasFlag(options::OPT_fopenmp_assume_threads_oversubscription,
867 options::OPT_fno_openmp_assume_threads_oversubscription,
868 /*Default=*/false))
869 CmdArgs.push_back("-fopenmp-assume-threads-oversubscription");
870
871 if (IsOpenMPDevice) {
872 // -fopenmp-is-target-device is passed along to tell the frontend that it is
873 // generating code for a device, so that only the relevant code is emitted.
874 CmdArgs.push_back("-fopenmp-is-target-device");
875
876 // -fopenmp-target-fast implies -fopenmp-assume-no-thread-state and
877 // -fopenmp-assume-no-nested-parallelism, and forces -O3 unless an
878 // explicit optimization level was requested.
879 bool TargetFastUsed =
880 Args.hasFlag(options::OPT_fopenmp_target_fast,
881 options::OPT_fno_openmp_target_fast, false);
882
883 if (TargetFastUsed && !Args.hasArg(options::OPT_O_Group))
884 CmdArgs.push_back("-O3");
885
886 // When in OpenMP offloading mode, enable debugging on the device.
887 Args.AddAllArgs(CmdArgs, options::OPT_fopenmp_target_debug_EQ);
888 if (Args.hasFlag(options::OPT_fopenmp_target_debug,
889 options::OPT_fno_openmp_target_debug, /*Default=*/false))
890 CmdArgs.push_back("-fopenmp-target-debug");
891
892 // Handle -fopenmp-assume-no-thread-state (implied by target-fast)
893 if (Args.hasFlag(options::OPT_fopenmp_assume_no_thread_state,
894 options::OPT_fno_openmp_assume_no_thread_state,
895 /*Default=*/TargetFastUsed))
896 CmdArgs.push_back("-fopenmp-assume-no-thread-state");
897
898 // Handle -fopenmp-assume-no-nested-parallelism (implied by target-fast)
899 if (Args.hasFlag(options::OPT_fopenmp_assume_no_nested_parallelism,
900 options::OPT_fno_openmp_assume_no_nested_parallelism,
901 /*Default=*/TargetFastUsed))
902 CmdArgs.push_back("-fopenmp-assume-no-nested-parallelism");
903
904 if (!Args.hasFlag(options::OPT_offloadlib, options::OPT_no_offloadlib,
905 true))
906 CmdArgs.push_back("-nogpulib");
907 }
908
909 addOpenMPHostOffloadingArgs(C, JA, Args, CmdArgs);
910}
911
912static void addFloatingPointOptions(const Driver &D, const ArgList &Args,
913 ArgStringList &CmdArgs) {
914 StringRef FPContract;
915 StringRef LastSeenFfpContractOption;
916 StringRef LastFpContractOverrideOption;
917 bool HonorINFs = true;
918 bool HonorNaNs = true;
919 bool ApproxFunc = false;
920 bool SignedZeros = true;
921 bool AssociativeMath = false;
922 bool ReciprocalMath = false;
923
924 StringRef LastComplexRangeOption;
926
927 for (const Arg *A : Args) {
928 auto optId = A->getOption().getID();
929 switch (optId) {
930 // if this isn't an FP option, skip the claim below
931 default:
932 continue;
933
934 case options::OPT_fcomplex_arithmetic_EQ: {
936 StringRef Val = A->getValue();
937 if (Val == "full")
939 else if (Val == "improved")
941 else if (Val == "basic")
943 else {
944 D.Diag(diag::err_drv_unsupported_option_argument)
945 << A->getSpelling() << Val;
946 break;
947 }
948
949 setComplexRange(D, Args.MakeArgString(A->getSpelling() + Val), NewRange,
950 LastComplexRangeOption, Range);
951 break;
952 }
953 case options::OPT_fhonor_infinities:
954 HonorINFs = true;
955 break;
956 case options::OPT_fno_honor_infinities:
957 HonorINFs = false;
958 break;
959 case options::OPT_fhonor_nans:
960 HonorNaNs = true;
961 break;
962 case options::OPT_fno_honor_nans:
963 HonorNaNs = false;
964 break;
965 case options::OPT_fapprox_func:
966 ApproxFunc = true;
967 break;
968 case options::OPT_fno_approx_func:
969 ApproxFunc = false;
970 break;
971 case options::OPT_fsigned_zeros:
972 SignedZeros = true;
973 break;
974 case options::OPT_fno_signed_zeros:
975 SignedZeros = false;
976 break;
977 case options::OPT_fassociative_math:
978 AssociativeMath = true;
979 break;
980 case options::OPT_fno_associative_math:
981 AssociativeMath = false;
982 break;
983 case options::OPT_freciprocal_math:
984 ReciprocalMath = true;
985 break;
986 case options::OPT_fno_reciprocal_math:
987 ReciprocalMath = false;
988 break;
989 case options::OPT_ffp_contract: {
990 StringRef Val = A->getValue();
991 if (Val == "fast" || Val == "off") {
992 if (Val != FPContract && LastFpContractOverrideOption != "") {
993 D.Diag(clang::diag::warn_drv_overriding_option)
994 << LastFpContractOverrideOption
995 << Args.MakeArgString("-ffp-contract=" + Val);
996 }
997 FPContract = Val;
998 LastSeenFfpContractOption = Val;
999 } else if (Val == "on") {
1000 // Warn instead of error because users might have makefiles written for
1001 // gfortran (which accepts -ffp-contract=on)
1002 D.Diag(diag::warn_drv_unsupported_option_for_flang)
1003 << Val << A->getOption().getName() << "off";
1004 FPContract = "off";
1005 LastSeenFfpContractOption = "off";
1006 } else {
1007 // Clang's "fast-honor-pragmas" option is not supported because it is
1008 // non-standard
1009 D.Diag(diag::err_drv_unsupported_option_argument)
1010 << A->getSpelling() << Val;
1011 }
1012 LastFpContractOverrideOption = "";
1013 break;
1014 }
1015 case options::OPT_Ofast:
1016 [[fallthrough]];
1017 case options::OPT_ffast_math:
1018 HonorINFs = false;
1019 HonorNaNs = false;
1020 AssociativeMath = true;
1021 ReciprocalMath = true;
1022 ApproxFunc = true;
1023 SignedZeros = false;
1024 FPContract = "fast";
1025 if (A->getOption().getID() == options::OPT_Ofast)
1026 LastFpContractOverrideOption = "-Ofast";
1027 else
1028 LastFpContractOverrideOption = "-ffast-math";
1029 setComplexRange(D, A->getSpelling(),
1031 LastComplexRangeOption, Range);
1032 break;
1033 case options::OPT_fno_fast_math:
1034 HonorINFs = true;
1035 HonorNaNs = true;
1036 AssociativeMath = false;
1037 ReciprocalMath = false;
1038 ApproxFunc = false;
1039 SignedZeros = true;
1040 // -fno-fast-math should undo -ffast-math so I return FPContract to the
1041 // default. If -ffp-contract= was explicitly specified, restore the
1042 // user-requested value from LastSeenFfpContractOption so that
1043 // -ffp-contract=off -fno-fast-math --> -ffp-contract=off
1044 if (LastSeenFfpContractOption != "")
1045 FPContract = LastSeenFfpContractOption;
1046 else
1047 FPContract = "";
1048 setComplexRange(D, A->getSpelling(),
1050 LastComplexRangeOption, Range);
1051 LastFpContractOverrideOption = "";
1052 break;
1053 }
1054
1055 // If we handled this option claim it
1056 A->claim();
1057 }
1058
1059 StringRef Recip = parseMRecipOption(D.getDiags(), Args);
1060 if (!Recip.empty())
1061 CmdArgs.push_back(Args.MakeArgString("-mrecip=" + Recip));
1062
1064 std::string ComplexRangeStr = renderComplexRangeOption(Range);
1065 CmdArgs.push_back(Args.MakeArgString(ComplexRangeStr));
1066 CmdArgs.push_back(Args.MakeArgString("-fcomplex-arithmetic=" +
1067 complexRangeKindToStr(Range)));
1068 }
1069
1070 if (llvm::opt::Arg *A =
1071 Args.getLastArg(clang::options::OPT_ffast_real_mod,
1072 clang::options::OPT_fno_fast_real_mod)) {
1073 if (A->getOption().matches(clang::options::OPT_ffast_real_mod))
1074 CmdArgs.push_back("-ffast-real-mod");
1075 else if (A->getOption().matches(clang::options::OPT_fno_fast_real_mod))
1076 CmdArgs.push_back("-fno-fast-real-mod");
1077 }
1078
1079 if (!HonorINFs && !HonorNaNs && AssociativeMath && ReciprocalMath &&
1080 ApproxFunc && !SignedZeros &&
1081 (FPContract == "fast" || FPContract.empty())) {
1082 CmdArgs.push_back("-ffast-math");
1083 return;
1084 }
1085
1086 if (!FPContract.empty())
1087 CmdArgs.push_back(Args.MakeArgString("-ffp-contract=" + FPContract));
1088
1089 if (!HonorINFs)
1090 CmdArgs.push_back("-menable-no-infs");
1091
1092 if (!HonorNaNs)
1093 CmdArgs.push_back("-menable-no-nans");
1094
1095 if (ApproxFunc)
1096 CmdArgs.push_back("-fapprox-func");
1097
1098 if (!SignedZeros)
1099 CmdArgs.push_back("-fno-signed-zeros");
1100
1101 if (AssociativeMath && !SignedZeros)
1102 CmdArgs.push_back("-mreassociate");
1103
1104 if (ReciprocalMath)
1105 CmdArgs.push_back("-freciprocal-math");
1106}
1107
1108// Add options related to IEEE Floating point modes
1109//
1110// Initial halting mode:
1111// Validate -ffpe-trap= and forward it to -fc1. This is handled separately from
1112// addFloatingPointOptions() on purpose: -ffpe-trap= is not part of the
1113// fast-math option set, so it must not be skipped by that function's
1114// -ffast-math fast path. The value check and the target-support warnings depend
1115// only on the option value and the target triple (no frontend-only state), so
1116// they are done here in the driver rather than deferred to -fc1; -fc1 only
1117// translates the list into its LangOptions bitmask.
1118//
1119// TODO:
1120// Rounding modes
1121// Underflow mode
1122static void addIEEEFPModesOptions(const Driver &D, const ArgList &Args,
1123 ArgStringList &CmdArgs,
1124 const llvm::Triple &Triple) {
1125 const Arg *A = Args.getLastArg(options::OPT_ffpe_trap_EQ);
1126 if (!A)
1127 return;
1128
1129 // The value is a comma-separated list of exception mnemonics. "none" and an
1130 // empty list request no halting and reset any earlier request in the list;
1131 // any other unrecognized mnemonic is an error.
1133 StringRef(A->getValue())
1134 .split(Traps, ',', /*MaxSplit=*/-1, /*KeepEmpty=*/false);
1135
1136 bool RequestsTrap = false;
1137 bool RequestsDenormal = false;
1138 for (StringRef Trap : Traps) {
1139 if (Trap == "none") {
1140 RequestsTrap = false;
1141 RequestsDenormal = false;
1142 continue;
1143 }
1144 bool IsKnown = llvm::StringSwitch<bool>(Trap)
1145 .Cases({"invalid", "zero", "overflow", "underflow",
1146 "inexact", "denormal"},
1147 true)
1148 .Default(false);
1149 if (!IsKnown) {
1150 D.Diag(diag::err_drv_unsupported_option_argument)
1151 << A->getSpelling() << Trap;
1152 return;
1153 }
1154 RequestsTrap = true;
1155 RequestsDenormal |= (Trap == "denormal");
1156 }
1157
1158 // Run-time halting is implemented in flang-rt only where the target's
1159 // floating-point environment can trap: it relies on glibc's feenableexcept
1160 // (in practice Linux), and "denormal" additionally requires an x86 target.
1161 // Warn (conservatively) when the target cannot honor the request; the runtime
1162 // otherwise ignores it. The denormal-specific warning names just
1163 // "-ffpe-trap=denormal" to point at the unsupported mnemonic.
1164 if (RequestsTrap && !Triple.isX86() && !Triple.isOSLinux())
1165 D.Diag(diag::warn_drv_unsupported_option_for_target)
1166 << A->getAsString(Args) << Triple.str();
1167 else if (RequestsDenormal && !Triple.isX86())
1168 D.Diag(diag::warn_drv_unsupported_option_for_target)
1169 << "-ffpe-trap=denormal" << Triple.str();
1170
1171 A->render(Args, CmdArgs);
1172}
1173
1174static void renderRemarksOptions(const ArgList &Args, ArgStringList &CmdArgs,
1175 const InputInfo &Input) {
1176 StringRef Format = "yaml";
1177 if (const Arg *A = Args.getLastArg(options::OPT_fsave_optimization_record_EQ))
1178 Format = A->getValue();
1179
1180 CmdArgs.push_back("-opt-record-file");
1181
1182 const Arg *A = Args.getLastArg(options::OPT_foptimization_record_file_EQ);
1183 if (A) {
1184 CmdArgs.push_back(A->getValue());
1185 } else {
1187
1188 if (Args.hasArg(options::OPT_c) || Args.hasArg(options::OPT_S)) {
1189 if (Arg *FinalOutput = Args.getLastArg(options::OPT_o))
1190 F = FinalOutput->getValue();
1191 }
1192
1193 if (F.empty()) {
1194 // Use the input filename.
1195 F = llvm::sys::path::stem(Input.getBaseInput());
1196 }
1197
1198 SmallString<32> Extension;
1199 Extension += "opt.";
1200 Extension += Format;
1201
1202 llvm::sys::path::replace_extension(F, Extension);
1203 CmdArgs.push_back(Args.MakeArgString(F));
1204 }
1205
1206 if (const Arg *A =
1207 Args.getLastArg(options::OPT_foptimization_record_passes_EQ)) {
1208 CmdArgs.push_back("-opt-record-passes");
1209 CmdArgs.push_back(A->getValue());
1210 }
1211
1212 if (!Format.empty()) {
1213 CmdArgs.push_back("-opt-record-format");
1214 CmdArgs.push_back(Format.data());
1215 }
1216}
1217
1218static void addPGOAndCoverageFlags(const ToolChain &TC, const JobAction &JA,
1219 const ArgList &Args,
1220 ArgStringList &CmdArgs) {
1221 const Driver &D = TC.getDriver();
1222 const llvm::Triple &T = TC.getTriple();
1223
1224 bool IsCudaDevice = JA.isDeviceOffloading(Action::OFK_Cuda);
1225 bool IsHIPDevice = JA.isDeviceOffloading(Action::OFK_HIP);
1226
1227 if (T.isOSAIX()) {
1228 if (Arg *ProfileSampleUseArg = getLastProfileSampleUseArg(Args))
1229 D.Diag(diag::err_drv_unsupported_opt_for_target)
1230 << ProfileSampleUseArg->getSpelling() << TC.getTriple().str();
1231 }
1232
1233 if (!(IsCudaDevice || IsHIPDevice)) {
1234 // recognise options: -fprofile-sample-use= and -fno-profile-sample-use=
1235 if (Arg *A = getLastProfileSampleUseArg(Args)) {
1236 if (Arg *PGOArg = Args.getLastArg(options::OPT_fprofile_generate,
1237 options::OPT_fprofile_generate_EQ)) {
1238 D.Diag(diag::err_drv_argument_not_allowed_with)
1239 << PGOArg->getAsString(Args) << A->getAsString(Args);
1240 }
1241
1242 StringRef fname = A->getValue();
1243 if (!llvm::sys::fs::exists(fname))
1244 D.Diag(diag::err_drv_no_such_file) << fname;
1245 else
1246 A->render(Args, CmdArgs);
1247 }
1248 }
1249
1250 //-fpseudo-probe-for-profiling
1251 if (Args.hasFlag(options::OPT_fpseudo_probe_for_profiling,
1252 options::OPT_fno_pseudo_probe_for_profiling, false))
1253 CmdArgs.push_back("-fpseudo-probe-for-profiling");
1254
1255 // TODO: Consider reusing Clang's addPGOAndCoverageFlags() for
1256 // -fprofile-generate and other similar options handling instead of
1257 // duplicating driver logic here.
1258 if (Arg *PGOGenerateArg = Args.getLastArg(
1259 options::OPT_fprofile_generate, options::OPT_fprofile_generate_EQ,
1260 options::OPT_fno_profile_generate)) {
1261 if (!PGOGenerateArg->getOption().matches(options::OPT_fno_profile_generate))
1262 PGOGenerateArg->render(Args, CmdArgs);
1263 }
1264
1265 addSplitMachineFunctionsArgs(TC.getDriver(), Args, CmdArgs, TC.getTriple());
1266 Args.addAllArgs(CmdArgs, {options::OPT_fprofile_use_EQ});
1267}
1268
1270 const InputInfo &Output, const InputInfoList &Inputs,
1271 const ArgList &Args, const char *LinkingOutput) const {
1272 const auto &TC = getToolChain();
1273 const llvm::Triple &Triple = TC.getEffectiveTriple();
1274 const std::string &TripleStr = Triple.getTriple();
1275
1276 const Driver &D = TC.getDriver();
1277 ArgStringList CmdArgs;
1278
1279 // Invoke ourselves in -fc1 mode.
1280 CmdArgs.push_back("-fc1");
1281
1282 // Add the "effective" target triple.
1283 CmdArgs.push_back("-triple");
1284 CmdArgs.push_back(Args.MakeArgString(TripleStr));
1285
1286 if (isa<PreprocessJobAction>(JA)) {
1287 if (Output.getType() == types::TY_Dependencies) {
1288 CmdArgs.push_back("-fsyntax-only");
1289 } else {
1290 CmdArgs.push_back("-E");
1291 if (Args.getLastArg(options::OPT_dM))
1292 CmdArgs.push_back("-dM");
1293 }
1294 } else if (isa<CompileJobAction>(JA) || isa<BackendJobAction>(JA)) {
1295 if (JA.getType() == types::TY_Nothing) {
1296 CmdArgs.push_back("-fsyntax-only");
1297 } else if (JA.getType() == types::TY_AST) {
1298 CmdArgs.push_back("-emit-ast");
1299 } else if (JA.getType() == types::TY_LLVM_IR ||
1300 JA.getType() == types::TY_LTO_IR) {
1301 CmdArgs.push_back("-emit-llvm");
1302 } else if (JA.getType() == types::TY_LLVM_BC ||
1303 JA.getType() == types::TY_LTO_BC) {
1304 CmdArgs.push_back("-emit-llvm-bc");
1305 } else if (JA.getType() == types::TY_PP_Asm) {
1306 CmdArgs.push_back("-S");
1307 } else {
1308 assert(false && "Unexpected output type!");
1309 }
1310 } else if (isa<AssembleJobAction>(JA)) {
1311 CmdArgs.push_back("-emit-obj");
1312 } else if (isa<PrecompileJobAction>(JA)) {
1313 // The precompile job action is only needed for options such as -mcpu=help.
1314 // Those will already have been handled by the fc1 driver.
1315 } else {
1316 assert(false && "Unexpected action class for Flang tool.");
1317 }
1318
1319 // We support some options that are invalid for Fortran and have no effect.
1320 // These are solely for compatibility with other compilers. Emit a warning if
1321 // any such options are provided, then proceed normally.
1322 for (options::ID Opt : {options::OPT_fbuiltin, options::OPT_fno_builtin})
1323 if (const Arg *A = Args.getLastArg(Opt))
1324 D.Diag(diag::warn_drv_invalid_argument_for_flang) << A->getSpelling();
1325
1326 // Warn about options that are ignored by flang. These are options that are
1327 // accepted by gfortran, but have no equivalent in flang.
1328 for (const Arg *A :
1329 Args.filtered(options::OPT_clang_ignored_gcc_optimization_f_Group)) {
1330 D.Diag(diag::warn_ignored_gcc_optimization) << A->getAsString(Args);
1331 A->claim();
1332 }
1333
1334 // -fkeep-inline-functions/-fno-keep-inline-functions are real Clang options
1335 // but are not supported by Flang; warn and ignore them.
1336 for (options::ID Opt : {options::OPT_fkeep_inline_functions,
1337 options::OPT_fno_keep_inline_functions}) {
1338 if (const Arg *A = Args.getLastArg(Opt)) {
1339 D.Diag(diag::warn_ignored_gcc_optimization) << A->getAsString(Args);
1340 A->claim();
1341 }
1342 }
1343
1344 const InputInfo &Input = Inputs[0];
1345 types::ID InputType = Input.getType();
1346
1347 // Add preprocessing options like -I, -D, etc. if we are using the
1348 // preprocessor (i.e. skip when dealing with e.g. binary files).
1350 addPreprocessingOptions(Args, CmdArgs);
1351
1352 addFortranDialectOptions(Args, CmdArgs);
1353
1354 // 'flang -E' always produces output that is suitable for use as fixed form
1355 // Fortran. However it is only valid free form source if the original is also
1356 // free form. Ensure this logic does not incorrectly assume fixed-form for
1357 // cases where it shouldn't, such as `flang -x f95 foo.f90`.
1358 bool isAtemporaryPreprocessedFile =
1359 Input.isFilename() &&
1360 llvm::sys::path::extension(Input.getFilename())
1361 .ends_with(types::getTypeTempSuffix(InputType, /*CLStyle=*/false));
1362 if (InputType == types::TY_PP_Fortran && isAtemporaryPreprocessedFile &&
1363 !Args.getLastArg(options::OPT_ffixed_form, options::OPT_ffree_form))
1364 CmdArgs.push_back("-ffixed-form");
1365
1366 handleColorDiagnosticsArgs(D, Args, CmdArgs);
1367
1368 addLTOOptions(Args, CmdArgs);
1369
1370 // -fPIC and related options.
1371 addPicOptions(Args, CmdArgs);
1372
1373 // Floating point related options
1374 addFloatingPointOptions(D, Args, CmdArgs);
1375
1376 // Initial floating-point exception halting mode. Handled separately so it is
1377 // not skipped by the -ffast-math fast path in addFloatingPointOptions().
1378 addIEEEFPModesOptions(D, Args, CmdArgs, Triple);
1379
1380 // Integer MOD/MODULO zero-divisor check. Forwarded here with -ffpe-trap=
1381 // rather than in addFloatingPointOptions() so -ffast-math does not drop it.
1382 Args.AddLastArg(CmdArgs, options::OPT_fcheck_integer_mod_zero_divisor);
1383
1384 // Add target args, features, etc.
1385 addTargetOptions(Args, CmdArgs, JA.getOffloadingArch(),
1387
1388 if (!TC.useIntegratedAs())
1389 CmdArgs.push_back("-no-integrated-as");
1390
1391 llvm::Reloc::Model RelocationModel =
1392 std::get<0>(ParsePICArgs(getToolChain(), Args));
1393 // Add MCModel information
1394 addMCModel(D, Args, Triple, RelocationModel, CmdArgs);
1395
1396 // Add Codegen options
1397 addCodegenOptions(Args, CmdArgs);
1398
1399 // Add R Group options
1400 Args.AddAllArgs(CmdArgs, options::OPT_R_Group);
1401
1402 // Remarks can be enabled with any of the `-f.*optimization-record.*` flags.
1403 if (willEmitRemarks(Args))
1404 renderRemarksOptions(Args, CmdArgs, Input);
1405
1406 // Add debug compile options
1407 addDebugOptions(Args, JA, Output, Input, CmdArgs);
1408
1409 // Disable all warnings
1410 // TODO: Handle interactions between -w, -pedantic, -Wall, -WOption
1411 Args.AddLastArg(CmdArgs, options::OPT_w);
1412
1413 addPGOAndCoverageFlags(TC, JA, Args, CmdArgs);
1414
1415 // Forward flags for OpenMP. We don't do this if the current action is an
1416 // device offloading action other than OpenMP.
1417 if (Args.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ,
1418 options::OPT_fno_openmp, false) &&
1421 switch (D.getOpenMPRuntime(Args)) {
1422 case Driver::OMPRT_OMP:
1424 // Clang can generate useful OpenMP code for these two runtime libraries.
1425 CmdArgs.push_back("-fopenmp");
1426 Args.AddAllArgs(CmdArgs, options::OPT_fopenmp_version_EQ);
1427
1428 if (Args.hasArg(options::OPT_fopenmp_force_usm))
1429 CmdArgs.push_back("-fopenmp-force-usm");
1430 Args.AddLastArg(CmdArgs, options::OPT_fopenmp_simd,
1431 options::OPT_fno_openmp_simd);
1432
1433 // FIXME: Clang supports a whole bunch more flags here.
1434 break;
1435 default:
1436 // By default, if Clang doesn't know how to generate useful OpenMP code
1437 // for a specific runtime library, we just don't pass the '-fopenmp' flag
1438 // down to the actual compilation.
1439 // FIXME: It would be better to have a mode which *only* omits IR
1440 // generation based on the OpenMP support so that we get consistent
1441 // semantic analysis, etc.
1442 const Arg *A = Args.getLastArg(options::OPT_fopenmp_EQ);
1443 D.Diag(diag::warn_drv_unsupported_openmp_library)
1444 << A->getSpelling() << A->getValue();
1445 break;
1446 }
1447 } else {
1448 Args.AddLastArg(CmdArgs, options::OPT_fopenmp_simd,
1449 options::OPT_fno_openmp_simd);
1450 }
1451
1452 // Pass the path to compiler resource files.
1453 CmdArgs.push_back("-resource-dir");
1454 CmdArgs.push_back(D.ResourceDir.c_str());
1455
1456 // Default intrinsic module dirs must be added after any user-provided dirs in
1457 // -fintrinsic-modules-path since the default dirs have lower precedence than
1458 // user-provided dirs
1459 if (std::optional<std::string> IntrModPath =
1461 CmdArgs.push_back("-fintrinsic-modules-path");
1462 CmdArgs.push_back(Args.MakeArgString(*IntrModPath));
1463 }
1464
1465 // Ideally, every target triple has its own set of builtin modules since they
1466 // are compiled with platform-dependent conditionals such as `#if __x86_64__`.
1467 // However, getting the builtin modules for offload targets requires building
1468 // the flang-rt and openmp for those targets as well:
1469 // -DLLVM_RUNTIME_TARGETS=default;amdgcn-amd-amdhsa;nvptx64-nvidia-cuda.
1470 // To reduce friction when build systems have not yet been updated, we also
1471 // add the host's builtin module to the search path (with lower priority), in
1472 // case a module file has not been found for the offload targets itself.
1473 // FIXME: This workaround may mix module files targeting different triples and
1474 // should eventually be removed.
1475 auto &&HostTCs =
1476 C.getOffloadToolChains<clang::driver::OffloadAction ::OFK_Host>();
1477 for (auto [OKind, HostTC] : llvm::make_range(HostTCs.first, HostTCs.second)) {
1478 if (HostTC == &TC)
1479 continue;
1480
1481 if (std::optional<std::string> IntrModPath =
1482 HostTC->getDefaultIntrinsicModuleDir()) {
1483 CmdArgs.push_back("-fintrinsic-modules-path");
1484 CmdArgs.push_back(Args.MakeArgString(*IntrModPath));
1485 }
1486 }
1487
1488 // Offloading related options
1489 addOffloadOptions(C, Inputs, JA, Args, CmdArgs);
1490
1491 // Forward -Xflang arguments to -fc1
1492 Args.AddAllArgValues(CmdArgs, options::OPT_Xflang);
1493
1495 getFramePointerKind(Args, Triple);
1496
1497 const char *FPKeepKindStr = nullptr;
1498 switch (FPKeepKind) {
1500 FPKeepKindStr = "-mframe-pointer=none";
1501 break;
1503 FPKeepKindStr = "-mframe-pointer=reserved";
1504 break;
1506 FPKeepKindStr = "-mframe-pointer=non-leaf-no-reserve";
1507 break;
1509 FPKeepKindStr = "-mframe-pointer=non-leaf";
1510 break;
1512 FPKeepKindStr = "-mframe-pointer=all";
1513 break;
1514 }
1515 assert(FPKeepKindStr && "unknown FramePointerKind");
1516 CmdArgs.push_back(FPKeepKindStr);
1517
1518 // Forward -mllvm options to the LLVM option parser. In practice, this means
1519 // forwarding to `-fc1` as that's where the LLVM parser is run.
1520 for (const Arg *A : Args.filtered(options::OPT_mllvm)) {
1521 A->claim();
1522 A->render(Args, CmdArgs);
1523 }
1524
1525 for (const Arg *A : Args.filtered(options::OPT_mmlir)) {
1526 A->claim();
1527 A->render(Args, CmdArgs);
1528 }
1529
1530 // Remove any unsupported gfortran diagnostic options
1531 for (const Arg *A : Args.filtered(options::OPT_flang_ignored_w_Group)) {
1532 A->claim();
1533 D.Diag(diag::warn_drv_unsupported_diag_option_for_flang)
1534 << A->getOption().getName();
1535 }
1536
1537 // Optimization level for CodeGen.
1538 if (const Arg *A = Args.getLastArg(options::OPT_O_Group)) {
1539 if (A->getOption().matches(options::OPT_O4)) {
1540 CmdArgs.push_back("-O3");
1541 D.Diag(diag::warn_O4_is_O3);
1542 } else if (A->getOption().matches(options::OPT_Ofast)) {
1543 CmdArgs.push_back("-O3");
1544 D.Diag(diag::warn_drv_deprecated_arg_ofast_for_flang);
1545 } else {
1546 A->render(Args, CmdArgs);
1547 }
1548 }
1549
1550 renderGlobalISelOptions(D, Args, CmdArgs, Triple);
1551 renderCommonIntegerOverflowOptions(Args, CmdArgs, false);
1552
1553 assert((Output.isFilename() || Output.isNothing()) && "Invalid output.");
1554 if (Output.isFilename()) {
1555 CmdArgs.push_back("-o");
1556 CmdArgs.push_back(Output.getFilename());
1557 }
1558
1559 if (Args.getLastArg(options::OPT_save_temps_EQ))
1560 Args.AddLastArg(CmdArgs, options::OPT_save_temps_EQ);
1561
1562 renderDependencyGenerationOptions(C, JA, Args, Output, Inputs, CmdArgs);
1563
1564 addDashXForInput(Args, Input, CmdArgs);
1565
1566 bool FRecordCmdLine = false;
1567 bool GRecordCmdLine = false;
1568 bool DXRecordCmdLine = false;
1569 if (shouldRecordCommandLine(TC, Args, FRecordCmdLine, GRecordCmdLine,
1570 DXRecordCmdLine)) {
1571 const char *CmdLine = renderEscapedCommandLine(TC, Args);
1572 if (FRecordCmdLine) {
1573 CmdArgs.push_back("-record-command-line");
1574 CmdArgs.push_back(CmdLine);
1575 }
1576 if (TC.UseDwarfDebugFlags() || GRecordCmdLine) {
1577 CmdArgs.push_back("-dwarf-debug-flags");
1578 CmdArgs.push_back(CmdLine);
1579 }
1580 }
1581
1582 // The input could be Ty_Nothing when "querying" options such as -mcpu=help
1583 // are used.
1584 ArrayRef<InputInfo> FrontendInputs = Input;
1585 if (Input.isNothing())
1586 FrontendInputs = {};
1587
1588 for (const InputInfo &Input : FrontendInputs) {
1589 if (Input.isFilename())
1590 CmdArgs.push_back(Input.getFilename());
1591 else
1592 Input.getInputArg().renderAsInput(Args, CmdArgs);
1593 }
1594
1595 // Handle "clang --driver-mode=flang" case
1596 bool isClangDriverWithFlangMode = false;
1597 std::string DriverName = D.Name;
1598 if (const char *PA = D.getPrependArg())
1599 DriverName = PA;
1600 if (DriverName.find("clang") != std::string::npos && D.IsFlangMode())
1601 isClangDriverWithFlangMode = true;
1602
1603 const char *Exec = isClangDriverWithFlangMode
1604 ? Args.MakeArgString(D.GetProgramPath("flang", TC))
1606 C.addCommand(std::make_unique<Command>(JA, *this,
1608 Exec, CmdArgs, Inputs, Output));
1609}
1610
1611Flang::Flang(const ToolChain &TC) : Tool("flang", "flang frontend", TC) {}
1612
#define V(N, I)
static void addDashXForInput(const ArgList &Args, const InputInfo &Input, ArgStringList &CmdArgs)
Add -x lang to CmdArgs for Input.
Definition Clang.cpp:337
static void renderRemarksOptions(const ArgList &Args, ArgStringList &CmdArgs, const llvm::Triple &Triple, const InputInfo &Input, const InputInfo &Output, const JobAction &JA)
Definition Clang.cpp:1268
static void addPGOAndCoverageFlags(const ToolChain &TC, Compilation &C, const JobAction &JA, const InputInfo &Output, const ArgList &Args, SanitizerArgs &SanArgs, ArgStringList &CmdArgs)
Definition Clang.cpp:368
clang::CodeGenOptions::FramePointerKind getFramePointerKind(const llvm::opt::ArgList &Args, const llvm::Triple &Triple)
static void processVSRuntimeLibrary(const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs)
Definition Flang.cpp:599
static void addVSDefines(const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs)
Definition Flang.cpp:575
static bool shouldLoopVersion(const ArgList &Args)
@C shouldLoopVersion
Definition Flang.cpp:191
static void addDashXForInput(const ArgList &Args, const InputInfo &Input, ArgStringList &CmdArgs)
Add -x lang to CmdArgs for Input.
Definition Flang.cpp:32
static void addIEEEFPModesOptions(const Driver &D, const ArgList &Args, ArgStringList &CmdArgs, const llvm::Triple &Triple)
Definition Flang.cpp:1122
static void addFloatingPointOptions(const Driver &D, const ArgList &Args, ArgStringList &CmdArgs)
Definition Flang.cpp:912
static void renderDependencyGenerationOptions(Compilation &C, const JobAction &JA, const ArgList &Args, const InputInfo &Output, const InputInfoList &Inputs, ArgStringList &CmdArgs)
Definition Flang.cpp:53
TokenType getType() const
Returns the token's type, e.g.
llvm::MachO::Target Target
Definition MachO.h:51
ComplexRangeKind
Controls the various implementations for complex multiplication and.
@ CX_Full
Implementation of complex division and multiplication using a call to runtime library functions(gener...
@ CX_Basic
Implementation of complex division and multiplication using algebraic formulas at source precision.
@ CX_None
No range rule is enabled.
@ CX_Improved
Implementation of complex division offering an improved handling for overflow in intermediate calcula...
types::ID getType() const
Definition Action.h:153
BoundArch getOffloadingArch() const
Definition Action.h:216
OffloadKind getOffloadingDeviceKind() const
Definition Action.h:215
bool isHostOffloading(unsigned int OKind) const
Check if this action have any offload kinds.
Definition Action.h:223
bool isDeviceOffloading(OffloadKind OKind) const
Definition Action.h:226
Compilation - A set of tasks to perform for a single driver invocation.
Definition Compilation.h:46
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition Driver.h:96
DiagnosticsEngine & getDiags() const
Definition Driver.h:411
const char * getPrependArg() const
Definition Driver.h:422
OpenMPRuntimeKind getOpenMPRuntime(const llvm::opt::ArgList &Args) const
Compute the desired OpenMP runtime from the flags provided.
Definition Driver.cpp:922
DiagnosticBuilder Diag(unsigned DiagID) const
Definition Driver.h:160
std::string Name
The name the driver was invoked as.
Definition Driver.h:167
const char * getDriverProgramPath() const
Get the path to the main driver executable.
Definition Driver.h:433
std::string GetProgramPath(StringRef Name, const ToolChain &TC) const
GetProgramPath - Lookup Name in the list of program search paths.
Definition Driver.cpp:5953
std::string ResourceDir
The path to the compiler resource directory.
Definition Driver.h:180
@ OMPRT_IOMP5
The legacy name for the LLVM OpenMP runtime from when it was the Intel OpenMP runtime.
Definition Driver.h:156
@ OMPRT_OMP
The LLVM OpenMP runtime.
Definition Driver.h:146
bool IsFlangMode() const
Whether the driver should invoke flang for fortran inputs.
Definition Driver.h:236
InputInfo - Wrapper for information about an input source.
Definition InputInfo.h:22
const char * getBaseInput() const
Definition InputInfo.h:78
const llvm::opt::Arg & getInputArg() const
Definition InputInfo.h:87
const char * getFilename() const
Definition InputInfo.h:83
bool isNothing() const
Definition InputInfo.h:74
bool isFilename() const
Definition InputInfo.h:75
types::ID getType() const
Definition InputInfo.h:77
ToolChain - Access to tools for a single platform.
Definition ToolChain.h:96
virtual bool useIntegratedAs() const
Check if the toolchain should use the integrated assembler.
llvm::Triple::ArchType getArch() const
Definition ToolChain.h:302
const Driver & getDriver() const
Definition ToolChain.h:286
virtual LTOKind getLTOMode(const llvm::opt::ArgList &Args, Action::OffloadKind Kind=Action::OFK_None) const
Resolve the requested LTO mode for this toolchain.
virtual void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, BoundArch BA, Action::OffloadKind DeviceOffloadKind) const
Add options that need to be passed to cc1 for this target.
const llvm::Triple & getEffectiveTriple() const
Get the toolchain's effective clang triple.
Definition ToolChain.h:314
const llvm::Triple & getTriple() const
Definition ToolChain.h:288
virtual bool UseDwarfDebugFlags() const
UseDwarfDebugFlags - Embed the compile options to clang into the Dwarf compile unit information.
Definition ToolChain.h:656
virtual VersionTuple computeMSVCVersion(const Driver *D, const llvm::opt::ArgList &Args) const
On Windows, returns the MSVC compatibility version.
std::string getCompilerRTBasename(const llvm::opt::ArgList &Args, StringRef Component, FileType Type=ToolChain::FT_Static) const
std::optional< std::string > getDefaultIntrinsicModuleDir() const
Returns the target-specific path for Flang's intrinsic modules in the resource directory if it exists...
const ToolChain & getToolChain() const
Definition Tool.h:52
Tool(const char *Name, const char *ShortName, const ToolChain &TC)
Definition Tool.cpp:13
Flang(const ToolChain &TC)
Definition Flang.cpp:1611
void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override
ConstructJob - Construct jobs to perform the action JA, writing to Output and with Inputs,...
Definition Flang.cpp:1269
std::string getRISCVArch(const llvm::opt::ArgList &Args, const llvm::Triple &Triple)
Definition RISCV.cpp:305
StringRef getRISCVABI(const llvm::opt::ArgList &Args, const llvm::Triple &Triple)
void addMCModel(const Driver &D, const llvm::opt::ArgList &Args, const llvm::Triple &Triple, const llvm::Reloc::Model &RelocationModel, llvm::opt::ArgStringList &CmdArgs)
llvm::opt::Arg * getLastProfileSampleUseArg(const llvm::opt::ArgList &Args)
void handleVectorizeSLPArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
Enable -fslp-vectorize based on the optimization level selected.
const char * SplitDebugName(const JobAction &JA, const llvm::opt::ArgList &Args, const InputInfo &Input, const InputInfo &Output)
void addOutlineAtomicsArgs(const Driver &D, const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const llvm::Triple &Triple)
void getTargetFeatures(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, bool ForAS, bool IsAux=false)
void renderDebugInfoCompressionArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const Driver &D, const ToolChain &TC)
std::string complexRangeKindToStr(LangOptions::ComplexRangeKind Range)
void handleColorDiagnosticsArgs(const Driver &D, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
Handle the -f{no}-color-diagnostics and -f{no}-diagnostics-colors options.
std::string getCPUName(const Driver &D, const llvm::opt::ArgList &Args, const llvm::Triple &T, bool FromAs=false)
void setComplexRange(const Driver &D, StringRef NewOpt, LangOptions::ComplexRangeKind NewRange, StringRef &LastOpt, LangOptions::ComplexRangeKind &Range)
void addDebugInfoForProfilingArgs(const Driver &D, const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
void addDebugInfoKind(llvm::opt::ArgStringList &CmdArgs, llvm::codegenoptions::DebugInfoKind DebugInfoKind)
llvm::codegenoptions::DebugInfoKind debugLevelToInfoKind(const llvm::opt::Arg &A)
void renderGlobalISelOptions(const Driver &D, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const llvm::Triple &Triple)
std::string renderComplexRangeOption(LangOptions::ComplexRangeKind Range)
DwarfFissionKind getDebugFissionKind(const Driver &D, const llvm::opt::ArgList &Args, llvm::opt::Arg *&Arg)
void handleInterchangeLoopsArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
Enable -floop-interchange based on the optimization level selected.
const char * renderEscapedCommandLine(const ToolChain &TC, const llvm::opt::ArgList &Args)
Join the args in the given ArgList, escape spaces and backslashes and return the joined string.
void renderCommonIntegerOverflowOptions(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, bool IsMSVCCompat)
void addSplitMachineFunctionsArgs(const Driver &D, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const llvm::Triple &Triple)
bool checkDebugInfoOption(const llvm::opt::Arg *A, const llvm::opt::ArgList &Args, const Driver &D, const ToolChain &TC)
std::tuple< llvm::Reloc::Model, unsigned, bool > ParsePICArgs(const ToolChain &ToolChain, const llvm::opt::ArgList &Args)
unsigned getDwarfVersion(const ToolChain &TC, const llvm::opt::ArgList &Args)
bool shouldRecordCommandLine(const ToolChain &TC, const llvm::opt::ArgList &Args, bool &FRecordCommandLine, bool &GRecordCommandLine, bool &DXRecordCommandLine)
Check if the command line should be recorded in the object file.
const llvm::opt::Arg * getDwarfNArg(const llvm::opt::ArgList &Args)
void addSeparateSectionFlags(const llvm::Triple &Triple, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
Append -ffunction-sections / -fdata-sections to CmdArgs when the corresponding flags are enabled (exp...
void handleVectorizeLoopsArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
Enable -fvectorize based on the optimization level selected.
const char * RelocationModelName(llvm::Reloc::Model Model)
void addOpenMPHostOffloadingArgs(const Compilation &C, const JobAction &JA, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
Adds offloading options for OpenMP host compilation to CmdArgs.
ID getPreprocessedType(ID Id)
getPreprocessedType - Get the ID of the type for this input when it has been preprocessed,...
Definition Types.cpp:53
const char * getTypeName(ID Id)
getTypeName - Return the name of the type for Id.
Definition Types.cpp:49
const char * getTypeTempSuffix(ID Id, bool CLStyle=false)
getTypeTempSuffix - Return the suffix to use when creating a temp file of this type,...
Definition Types.cpp:81
LTOKind
Describes the kind of LTO mode selected via -f(no-)?lto(=.*)? options.
Definition Driver.h:60
SmallVector< InputInfo, 4 > InputInfoList
Definition Driver.h:52
bool willEmitRemarks(const llvm::opt::ArgList &Args)
Top level wrappers for InstallAPI frontend operations.
bool isa(CodeGen::Address addr)
Definition Address.h:330
void quoteMakeTarget(StringRef Target, SmallVectorImpl< char > &Res)
Quote target names for inclusion in GNU Make dependency files.
@ Default
Set to the current date and time.
const FunctionProtoType * T
StringRef parseMRecipOption(clang::DiagnosticsEngine &Diags, const llvm::opt::ArgList &Args)
bool(*)(llvm::ArrayRef< const char * >, llvm::raw_ostream &, llvm::raw_ostream &, bool, bool) Driver
Definition Wasm.cpp:36
__DEVICE__ _Tp arg(const std::complex< _Tp > &__c)
static constexpr ResponseFileSupport AtFileUTF8()
Definition Job.h:86