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