15#include "llvm/Frontend/Debug/Options.h"
16#include "llvm/Support/FileSystem.h"
17#include "llvm/Support/Path.h"
18#include "llvm/TargetParser/Host.h"
19#include "llvm/TargetParser/RISCVISAInfo.h"
20#include "llvm/TargetParser/RISCVTargetParser.h"
31 ArgStringList &CmdArgs) {
32 CmdArgs.push_back(
"-x");
37void Flang::addFortranDialectOptions(
const ArgList &Args,
38 ArgStringList &CmdArgs)
const {
39 Args.addAllArgs(CmdArgs, {options::OPT_ffixed_form,
40 options::OPT_ffree_form,
41 options::OPT_ffixed_line_length_EQ,
42 options::OPT_fopenacc,
43 options::OPT_finput_charset_EQ,
44 options::OPT_fimplicit_none,
45 options::OPT_fno_implicit_none,
46 options::OPT_fbackslash,
47 options::OPT_fno_backslash,
48 options::OPT_flogical_abbreviations,
49 options::OPT_fno_logical_abbreviations,
50 options::OPT_fxor_operator,
51 options::OPT_fno_xor_operator,
52 options::OPT_falternative_parameter_statement,
53 options::OPT_fdefault_real_8,
54 options::OPT_fdefault_integer_8,
55 options::OPT_fdefault_double_8,
56 options::OPT_flarge_sizes,
57 options::OPT_fno_automatic,
58 options::OPT_fhermetic_module_files,
59 options::OPT_frealloc_lhs,
60 options::OPT_fno_realloc_lhs});
63void Flang::addPreprocessingOptions(
const ArgList &Args,
64 ArgStringList &CmdArgs)
const {
65 Args.addAllArgs(CmdArgs,
66 {options::OPT_P, options::OPT_D, options::OPT_U,
67 options::OPT_I, options::OPT_cpp, options::OPT_nocpp});
88 const Arg *LoopVersioningArg = Args.getLastArg(
89 options::OPT_Ofast, options::OPT_O, options::OPT_O4,
90 options::OPT_floop_versioning, options::OPT_fno_loop_versioning);
91 if (!LoopVersioningArg)
94 if (LoopVersioningArg->getOption().matches(options::OPT_fno_loop_versioning))
97 if (LoopVersioningArg->getOption().matches(options::OPT_floop_versioning))
100 if (LoopVersioningArg->getOption().matches(options::OPT_Ofast) ||
101 LoopVersioningArg->getOption().matches(options::OPT_O4))
104 if (LoopVersioningArg->getOption().matches(options::OPT_O)) {
105 StringRef S(LoopVersioningArg->getValue());
106 unsigned OptLevel = 0;
109 if (S.getAsInteger(10, OptLevel))
115 llvm_unreachable(
"We should not end up here");
119void Flang::addOtherOptions(
const ArgList &Args, ArgStringList &CmdArgs)
const {
120 Args.addAllArgs(CmdArgs,
121 {options::OPT_module_dir, options::OPT_fdebug_module_writer,
122 options::OPT_fintrinsic_modules_path, options::OPT_pedantic,
123 options::OPT_std_EQ, options::OPT_W_Joined,
124 options::OPT_fconvert_EQ, options::OPT_fpass_plugin_EQ,
125 options::OPT_funderscoring, options::OPT_fno_underscoring,
126 options::OPT_funsigned, options::OPT_fno_unsigned});
128 llvm::codegenoptions::DebugInfoKind DebugInfoKind;
129 if (Args.hasArg(options::OPT_gN_Group)) {
130 Arg *gNArg = Args.getLastArg(options::OPT_gN_Group);
132 }
else if (Args.hasArg(options::OPT_g_Flag)) {
133 DebugInfoKind = llvm::codegenoptions::FullDebugInfo;
135 DebugInfoKind = llvm::codegenoptions::NoDebugInfo;
140void Flang::addCodegenOptions(
const ArgList &Args,
141 ArgStringList &CmdArgs)
const {
143 Args.getLastArg(options::OPT_Ofast, options::OPT_fstack_arrays,
144 options::OPT_fno_stack_arrays);
146 !stackArrays->getOption().matches(options::OPT_fno_stack_arrays))
147 CmdArgs.push_back(
"-fstack-arrays");
150 CmdArgs.push_back(
"-fversion-loops-for-stride");
152 Args.addAllArgs(CmdArgs, {options::OPT_flang_experimental_hlfir,
153 options::OPT_flang_deprecated_no_hlfir,
154 options::OPT_fno_ppc_native_vec_elem_order,
155 options::OPT_fppc_native_vec_elem_order});
158void Flang::addPicOptions(
const ArgList &Args, ArgStringList &CmdArgs)
const {
161 llvm::Reloc::Model RelocationModel;
164 std::tie(RelocationModel, PICLevel, IsPIE) =
168 CmdArgs.push_back(
"-mrelocation-model");
169 CmdArgs.push_back(RMName);
172 CmdArgs.push_back(
"-pic-level");
173 CmdArgs.push_back(PICLevel == 1 ?
"1" :
"2");
175 CmdArgs.push_back(
"-pic-is-pie");
179void Flang::AddAArch64TargetArgs(
const ArgList &Args,
180 ArgStringList &CmdArgs)
const {
182 if (Arg *A = Args.getLastArg(options::OPT_msve_vector_bits_EQ)) {
183 StringRef Val = A->getValue();
185 if (Val ==
"128" || Val ==
"256" || Val ==
"512" || Val ==
"1024" ||
186 Val ==
"2048" || Val ==
"128+" || Val ==
"256+" || Val ==
"512+" ||
187 Val ==
"1024+" || Val ==
"2048+") {
189 if (!Val.consume_back(
"+")) {
190 [[maybe_unused]]
bool Invalid = Val.getAsInteger(10, Bits);
191 assert(!
Invalid &&
"Failed to parse value");
193 Args.MakeArgString(
"-mvscale-max=" + llvm::Twine(Bits / 128)));
196 [[maybe_unused]]
bool Invalid = Val.getAsInteger(10, Bits);
197 assert(!
Invalid &&
"Failed to parse value");
199 Args.MakeArgString(
"-mvscale-min=" + llvm::Twine(Bits / 128)));
201 }
else if (Val !=
"scalable")
203 D.Diag(diag::err_drv_unsupported_option_argument)
204 << A->getSpelling() << Val;
208void Flang::AddLoongArch64TargetArgs(
const ArgList &Args,
209 ArgStringList &CmdArgs)
const {
212 if (
const Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) {
213 StringRef
V = A->getValue();
215 D.Diag(diag::err_drv_argument_not_allowed_with) <<
"-mabi" <<
V;
219 if (
const Arg *A = Args.getLastArg(options::OPT_mannotate_tablejump,
220 options::OPT_mno_annotate_tablejump)) {
221 if (A->getOption().matches(options::OPT_mannotate_tablejump)) {
222 CmdArgs.push_back(
"-mllvm");
223 CmdArgs.push_back(
"-loongarch-annotate-tablejump");
228void Flang::AddPPCTargetArgs(
const ArgList &Args,
229 ArgStringList &CmdArgs)
const {
231 bool VecExtabi =
false;
233 if (
const Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) {
234 StringRef
V = A->getValue();
235 if (
V ==
"vec-extabi")
237 else if (
V ==
"vec-default")
240 D.Diag(diag::err_drv_unsupported_option_argument)
241 << A->getSpelling() <<
V;
247 D.Diag(diag::err_drv_unsupported_opt_for_target)
248 <<
"-mabi=vec-extabi" <<
T.str();
250 CmdArgs.push_back(
"-mabi=vec-extabi");
254void Flang::AddRISCVTargetArgs(
const ArgList &Args,
255 ArgStringList &CmdArgs)
const {
258 if (Arg *A = Args.getLastArg(options::OPT_mrvv_vector_bits_EQ)) {
259 StringRef Val = A->getValue();
263 unsigned MinVLen = 0;
265 auto ISAInfo = llvm::RISCVISAInfo::parseArchString(
268 if (!errorToBool(ISAInfo.takeError()))
269 MinVLen = (*ISAInfo)->getMinVLen();
274 if (Val ==
"zvl" && MinVLen >= llvm::RISCV::RVVBitsPerBlock) {
276 }
else if (!Val.getAsInteger(10, Bits)) {
279 if (Bits < MinVLen || Bits < llvm::RISCV::RVVBitsPerBlock ||
280 Bits > 65536 || !llvm::isPowerOf2_32(Bits))
286 unsigned VScaleMin = Bits / llvm::RISCV::RVVBitsPerBlock;
288 Args.MakeArgString(
"-mvscale-max=" + llvm::Twine(VScaleMin)));
290 Args.MakeArgString(
"-mvscale-min=" + llvm::Twine(VScaleMin)));
291 }
else if (Val !=
"scalable") {
293 D.Diag(diag::err_drv_unsupported_option_argument)
294 << A->getSpelling() << Val;
299void Flang::AddX86_64TargetArgs(
const ArgList &Args,
300 ArgStringList &CmdArgs)
const {
301 if (Arg *A = Args.getLastArg(options::OPT_masm_EQ)) {
302 StringRef
Value = A->getValue();
304 CmdArgs.push_back(Args.MakeArgString(
"-mllvm"));
305 CmdArgs.push_back(Args.MakeArgString(
"-x86-asm-syntax=" +
Value));
308 << A->getSpelling() <<
Value;
314 ArgStringList &CmdArgs) {
318 ver = vt.getMajor() * 10000000 + vt.getMinor().value_or(0) * 100000 +
319 vt.getSubminor().value_or(0);
320 CmdArgs.push_back(Args.MakeArgString(
"-D_MSC_VER=" + Twine(ver / 100000)));
321 CmdArgs.push_back(Args.MakeArgString(
"-D_MSC_FULL_VER=" + Twine(ver)));
322 CmdArgs.push_back(Args.MakeArgString(
"-D_WIN32"));
324 const llvm::Triple &triple = TC.
getTriple();
325 if (triple.isAArch64()) {
326 CmdArgs.push_back(
"-D_M_ARM64=1");
327 }
else if (triple.isX86() && triple.isArch32Bit()) {
328 CmdArgs.push_back(
"-D_M_IX86=600");
329 }
else if (triple.isX86() && triple.isArch64Bit()) {
330 CmdArgs.push_back(
"-D_M_X64=100");
333 "Flang on Windows only supports X86_32, X86_64 and AArch64");
338 ArgStringList &CmdArgs) {
339 assert(TC.
getTriple().isKnownWindowsMSVCEnvironment() &&
340 "can only add VS runtime library on Windows!");
342 if (TC.
getTriple().isKnownWindowsMSVCEnvironment()) {
343 CmdArgs.push_back(Args.MakeArgString(
346 unsigned RTOptionID = options::OPT__SLASH_MT;
347 if (
auto *rtl = Args.getLastArg(options::OPT_fms_runtime_lib_EQ)) {
348 RTOptionID = llvm::StringSwitch<unsigned>(rtl->getValue())
349 .Case(
"static", options::OPT__SLASH_MT)
350 .Case(
"static_dbg", options::OPT__SLASH_MTd)
351 .Case(
"dll", options::OPT__SLASH_MD)
352 .Case(
"dll_dbg", options::OPT__SLASH_MDd)
353 .Default(options::OPT__SLASH_MT);
355 switch (RTOptionID) {
356 case options::OPT__SLASH_MT:
357 CmdArgs.push_back(
"-D_MT");
358 CmdArgs.push_back(
"--dependent-lib=libcmt");
359 CmdArgs.push_back(
"--dependent-lib=FortranRuntime.static.lib");
360 CmdArgs.push_back(
"--dependent-lib=FortranDecimal.static.lib");
362 case options::OPT__SLASH_MTd:
363 CmdArgs.push_back(
"-D_MT");
364 CmdArgs.push_back(
"-D_DEBUG");
365 CmdArgs.push_back(
"--dependent-lib=libcmtd");
366 CmdArgs.push_back(
"--dependent-lib=FortranRuntime.static_dbg.lib");
367 CmdArgs.push_back(
"--dependent-lib=FortranDecimal.static_dbg.lib");
369 case options::OPT__SLASH_MD:
370 CmdArgs.push_back(
"-D_MT");
371 CmdArgs.push_back(
"-D_DLL");
372 CmdArgs.push_back(
"--dependent-lib=msvcrt");
373 CmdArgs.push_back(
"--dependent-lib=FortranRuntime.dynamic.lib");
374 CmdArgs.push_back(
"--dependent-lib=FortranDecimal.dynamic.lib");
376 case options::OPT__SLASH_MDd:
377 CmdArgs.push_back(
"-D_MT");
378 CmdArgs.push_back(
"-D_DEBUG");
379 CmdArgs.push_back(
"-D_DLL");
380 CmdArgs.push_back(
"--dependent-lib=msvcrtd");
381 CmdArgs.push_back(
"--dependent-lib=FortranRuntime.dynamic_dbg.lib");
382 CmdArgs.push_back(
"--dependent-lib=FortranDecimal.dynamic_dbg.lib");
387void Flang::AddAMDGPUTargetArgs(
const ArgList &Args,
388 ArgStringList &CmdArgs)
const {
389 if (Arg *A = Args.getLastArg(options::OPT_mcode_object_version_EQ)) {
390 StringRef Val = A->getValue();
391 CmdArgs.push_back(Args.MakeArgString(
"-mcode-object-version=" + Val));
398void Flang::addTargetOptions(
const ArgList &Args,
399 ArgStringList &CmdArgs)
const {
406 CmdArgs.push_back(
"-target-cpu");
407 CmdArgs.push_back(Args.MakeArgString(CPU));
416 case llvm::Triple::aarch64:
418 AddAArch64TargetArgs(Args, CmdArgs);
421 case llvm::Triple::r600:
422 case llvm::Triple::amdgcn:
424 AddAMDGPUTargetArgs(Args, CmdArgs);
426 case llvm::Triple::riscv64:
428 AddRISCVTargetArgs(Args, CmdArgs);
430 case llvm::Triple::x86_64:
432 AddX86_64TargetArgs(Args, CmdArgs);
434 case llvm::Triple::ppc:
435 case llvm::Triple::ppc64:
436 case llvm::Triple::ppc64le:
437 AddPPCTargetArgs(Args, CmdArgs);
439 case llvm::Triple::loongarch64:
441 AddLoongArch64TargetArgs(Args, CmdArgs);
445 if (Arg *A = Args.getLastArg(options::OPT_fveclib)) {
446 StringRef Name = A->getValue();
447 if (Name ==
"SVML") {
448 if (Triple.getArch() != llvm::Triple::x86 &&
449 Triple.getArch() != llvm::Triple::x86_64)
450 D.Diag(diag::err_drv_unsupported_opt_for_target)
451 << Name << Triple.getArchName();
452 }
else if (Name ==
"LIBMVEC-X86") {
453 if (Triple.getArch() != llvm::Triple::x86 &&
454 Triple.getArch() != llvm::Triple::x86_64)
455 D.Diag(diag::err_drv_unsupported_opt_for_target)
456 << Name << Triple.getArchName();
457 }
else if (Name ==
"SLEEF" || Name ==
"ArmPL") {
458 if (Triple.getArch() != llvm::Triple::aarch64 &&
459 Triple.getArch() != llvm::Triple::aarch64_be)
460 D.Diag(diag::err_drv_unsupported_opt_for_target)
461 << Name << Triple.getArchName();
464 if (Triple.isOSDarwin()) {
467 if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
468 if (A->getValue() == StringRef{
"Accelerate"}) {
469 CmdArgs.push_back(
"-framework");
470 CmdArgs.push_back(
"Accelerate");
474 A->render(Args, CmdArgs);
477 if (Triple.isKnownWindowsMSVCEnvironment()) {
483 if (
const Arg *A = Args.getLastArg(options::OPT_mtune_EQ)) {
484 CmdArgs.push_back(
"-tune-cpu");
485 if (A->getValue() == StringRef{
"native"})
486 CmdArgs.push_back(Args.MakeArgString(llvm::sys::getHostCPUName()));
488 CmdArgs.push_back(A->getValue());
493 const JobAction &JA,
const ArgList &Args,
494 ArgStringList &CmdArgs)
const {
507 for (
size_t i = 1; i < Inputs.size(); ++i) {
508 if (Inputs[i].getType() == types::TY_Nothing) {
510 }
else if (IsHostOffloadingAction) {
512 Args.MakeArgString(
"-fembed-offload-object=" +
514 }
else if (IsOpenMPDevice) {
515 if (Inputs[i].getFilename()) {
516 CmdArgs.push_back(
"-fopenmp-host-ir-file-path");
517 CmdArgs.push_back(Args.MakeArgString(Inputs[i].getFilename()));
519 llvm_unreachable(
"missing openmp host-ir file for device offloading");
523 "unexpectedly given multiple inputs or given unknown input");
527 if (IsOpenMPDevice) {
530 CmdArgs.push_back(
"-fopenmp-is-target-device");
533 Args.AddAllArgs(CmdArgs, options::OPT_fopenmp_target_debug_EQ);
534 if (Args.hasFlag(options::OPT_fopenmp_target_debug,
535 options::OPT_fno_openmp_target_debug,
false))
536 CmdArgs.push_back(
"-fopenmp-target-debug");
540 if (Args.hasFlag(options::OPT_fopenmp_assume_teams_oversubscription,
541 options::OPT_fno_openmp_assume_teams_oversubscription,
543 CmdArgs.push_back(
"-fopenmp-assume-teams-oversubscription");
544 if (Args.hasFlag(options::OPT_fopenmp_assume_threads_oversubscription,
545 options::OPT_fno_openmp_assume_threads_oversubscription,
547 CmdArgs.push_back(
"-fopenmp-assume-threads-oversubscription");
548 if (Args.hasArg(options::OPT_fopenmp_assume_no_thread_state))
549 CmdArgs.push_back(
"-fopenmp-assume-no-thread-state");
550 if (Args.hasArg(options::OPT_fopenmp_assume_no_nested_parallelism))
551 CmdArgs.push_back(
"-fopenmp-assume-no-nested-parallelism");
552 if (Args.hasArg(options::OPT_nogpulib))
553 CmdArgs.push_back(
"-nogpulib");
560 ArgStringList &CmdArgs) {
561 StringRef FPContract;
562 bool HonorINFs =
true;
563 bool HonorNaNs =
true;
564 bool ApproxFunc =
false;
565 bool SignedZeros =
true;
566 bool AssociativeMath =
false;
567 bool ReciprocalMath =
false;
569 if (
const Arg *A = Args.getLastArg(options::OPT_ffp_contract)) {
570 const StringRef Val = A->getValue();
571 if (Val ==
"fast" || Val ==
"off") {
573 }
else if (Val ==
"on") {
576 D.Diag(diag::warn_drv_unsupported_option_for_flang)
577 << Val << A->getOption().getName() <<
"off";
582 D.Diag(diag::err_drv_unsupported_option_argument)
583 << A->getSpelling() << Val;
586 for (
const Arg *A : Args) {
587 auto optId = A->getOption().
getID();
593 case options::OPT_fhonor_infinities:
596 case options::OPT_fno_honor_infinities:
599 case options::OPT_fhonor_nans:
602 case options::OPT_fno_honor_nans:
605 case options::OPT_fapprox_func:
608 case options::OPT_fno_approx_func:
611 case options::OPT_fsigned_zeros:
614 case options::OPT_fno_signed_zeros:
617 case options::OPT_fassociative_math:
618 AssociativeMath =
true;
620 case options::OPT_fno_associative_math:
621 AssociativeMath =
false;
623 case options::OPT_freciprocal_math:
624 ReciprocalMath =
true;
626 case options::OPT_fno_reciprocal_math:
627 ReciprocalMath =
false;
629 case options::OPT_Ofast:
631 case options::OPT_ffast_math:
634 AssociativeMath =
true;
635 ReciprocalMath =
true;
640 case options::OPT_fno_fast_math:
643 AssociativeMath =
false;
644 ReciprocalMath =
false;
650 if (FPContract ==
"fast")
659 if (!HonorINFs && !HonorNaNs && AssociativeMath && ReciprocalMath &&
660 ApproxFunc && !SignedZeros &&
661 (FPContract ==
"fast" || FPContract.empty())) {
662 CmdArgs.push_back(
"-ffast-math");
666 if (!FPContract.empty())
667 CmdArgs.push_back(Args.MakeArgString(
"-ffp-contract=" + FPContract));
670 CmdArgs.push_back(
"-menable-no-infs");
673 CmdArgs.push_back(
"-menable-no-nans");
676 CmdArgs.push_back(
"-fapprox-func");
679 CmdArgs.push_back(
"-fno-signed-zeros");
681 if (AssociativeMath && !SignedZeros)
682 CmdArgs.push_back(
"-mreassociate");
685 CmdArgs.push_back(
"-freciprocal-math");
690 StringRef Format =
"yaml";
691 if (
const Arg *A = Args.getLastArg(options::OPT_fsave_optimization_record_EQ))
692 Format = A->getValue();
694 CmdArgs.push_back(
"-opt-record-file");
696 const Arg *A = Args.getLastArg(options::OPT_foptimization_record_file_EQ);
698 CmdArgs.push_back(A->getValue());
702 if (Args.hasArg(options::OPT_c) || Args.hasArg(options::OPT_S)) {
703 if (Arg *FinalOutput = Args.getLastArg(options::OPT_o))
704 F = FinalOutput->getValue();
716 llvm::sys::path::replace_extension(F, Extension);
717 CmdArgs.push_back(Args.MakeArgString(F));
721 Args.getLastArg(options::OPT_foptimization_record_passes_EQ)) {
722 CmdArgs.push_back(
"-opt-record-passes");
723 CmdArgs.push_back(A->getValue());
726 if (!Format.empty()) {
727 CmdArgs.push_back(
"-opt-record-format");
728 CmdArgs.push_back(Format.data());
734 const ArgList &Args,
const char *LinkingOutput)
const {
737 const std::string &TripleStr = Triple.getTriple();
740 ArgStringList CmdArgs;
744 CmdArgs.push_back(
"-fc1");
747 CmdArgs.push_back(
"-triple");
748 CmdArgs.push_back(Args.MakeArgString(TripleStr));
750 if (isa<PreprocessJobAction>(JA)) {
751 CmdArgs.push_back(
"-E");
752 if (Args.getLastArg(options::OPT_dM)) {
753 CmdArgs.push_back(
"-dM");
755 }
else if (isa<CompileJobAction>(JA) || isa<BackendJobAction>(JA)) {
756 if (JA.
getType() == types::TY_Nothing) {
757 CmdArgs.push_back(
"-fsyntax-only");
758 }
else if (JA.
getType() == types::TY_AST) {
759 CmdArgs.push_back(
"-emit-ast");
760 }
else if (JA.
getType() == types::TY_LLVM_IR ||
761 JA.
getType() == types::TY_LTO_IR) {
762 CmdArgs.push_back(
"-emit-llvm");
763 }
else if (JA.
getType() == types::TY_LLVM_BC ||
764 JA.
getType() == types::TY_LTO_BC) {
765 CmdArgs.push_back(
"-emit-llvm-bc");
766 }
else if (JA.
getType() == types::TY_PP_Asm) {
767 CmdArgs.push_back(
"-S");
769 assert(
false &&
"Unexpected output type!");
771 }
else if (isa<AssembleJobAction>(JA)) {
772 CmdArgs.push_back(
"-emit-obj");
773 }
else if (isa<PrecompileJobAction>(JA)) {
777 assert(
false &&
"Unexpected action class for Flang tool.");
786 addPreprocessingOptions(Args, CmdArgs);
788 addFortranDialectOptions(Args, CmdArgs);
793 if (InputType == types::TY_PP_Fortran &&
794 !Args.getLastArg(options::OPT_ffixed_form, options::OPT_ffree_form))
795 CmdArgs.push_back(
"-ffixed-form");
803 CmdArgs.push_back(
"-flto=full");
807 "the option '-flto=thin' is a work in progress"));
808 CmdArgs.push_back(
"-flto=thin");
812 addPicOptions(Args, CmdArgs);
818 addTargetOptions(Args, CmdArgs);
820 llvm::Reloc::Model RelocationModel =
823 addMCModel(
D, Args, Triple, RelocationModel, CmdArgs);
826 addCodegenOptions(Args, CmdArgs);
829 Args.AddAllArgs(CmdArgs, options::OPT_R_Group);
836 addOtherOptions(Args, CmdArgs);
840 Args.AddLastArg(CmdArgs, options::OPT_w);
844 if (Args.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ,
845 options::OPT_fno_openmp,
false) &&
848 switch (
D.getOpenMPRuntime(Args)) {
852 CmdArgs.push_back(
"-fopenmp");
853 Args.AddAllArgs(CmdArgs, options::OPT_fopenmp_version_EQ);
855 if (Args.hasArg(options::OPT_fopenmp_force_usm))
856 CmdArgs.push_back(
"-fopenmp-force-usm");
859 D.Diag(diag::warn_openmp_experimental);
870 const Arg *A = Args.getLastArg(options::OPT_fopenmp_EQ);
871 D.Diag(diag::warn_drv_unsupported_openmp_library)
872 << A->getSpelling() << A->getValue();
878 CmdArgs.push_back(
"-resource-dir");
879 CmdArgs.push_back(
D.ResourceDir.c_str());
882 addOffloadOptions(
C, Inputs, JA, Args, CmdArgs);
885 Args.AddAllArgValues(CmdArgs, options::OPT_Xflang);
890 const char *FPKeepKindStr =
nullptr;
891 switch (FPKeepKind) {
893 FPKeepKindStr =
"-mframe-pointer=none";
896 FPKeepKindStr =
"-mframe-pointer=reserved";
899 FPKeepKindStr =
"-mframe-pointer=non-leaf";
902 FPKeepKindStr =
"-mframe-pointer=all";
905 assert(FPKeepKindStr &&
"unknown FramePointerKind");
906 CmdArgs.push_back(FPKeepKindStr);
910 for (
const Arg *A : Args.filtered(options::OPT_mllvm)) {
912 A->render(Args, CmdArgs);
915 for (
const Arg *A : Args.filtered(options::OPT_mmlir)) {
917 A->render(Args, CmdArgs);
921 for (
const Arg *A : Args.filtered(options::OPT_flang_ignored_w_Group)) {
923 D.Diag(diag::warn_drv_unsupported_diag_option_for_flang)
924 << A->getOption().getName();
928 if (
const Arg *A = Args.getLastArg(options::OPT_O_Group)) {
929 if (A->getOption().matches(options::OPT_O4)) {
930 CmdArgs.push_back(
"-O3");
931 D.Diag(diag::warn_O4_is_O3);
932 }
else if (A->getOption().matches(options::OPT_Ofast)) {
933 CmdArgs.push_back(
"-O3");
935 A->render(Args, CmdArgs);
943 CmdArgs.push_back(
"-o");
947 if (Args.getLastArg(options::OPT_save_temps_EQ))
948 Args.AddLastArg(CmdArgs, options::OPT_save_temps_EQ);
952 bool FRecordCmdLine =
false;
953 bool GRecordCmdLine =
false;
956 if (FRecordCmdLine) {
957 CmdArgs.push_back(
"-record-command-line");
958 CmdArgs.push_back(CmdLine);
961 CmdArgs.push_back(
"-dwarf-debug-flags");
962 CmdArgs.push_back(CmdLine);
972 for (
const InputInfo &Input : FrontendInputs) {
979 const char *Exec = Args.MakeArgString(
D.GetProgramPath(
"flang", TC));
980 C.addCommand(std::make_unique<Command>(JA, *
this,
982 Exec, CmdArgs, Inputs, Output));
static void addDashXForInput(const ArgList &Args, const InputInfo &Input, ArgStringList &CmdArgs)
Add -x lang to CmdArgs for Input.
static void renderRemarksOptions(const ArgList &Args, ArgStringList &CmdArgs, const llvm::Triple &Triple, const InputInfo &Input, const InputInfo &Output, const JobAction &JA)
clang::CodeGenOptions::FramePointerKind getFramePointerKind(const llvm::opt::ArgList &Args, const llvm::Triple &Triple)
static void processVSRuntimeLibrary(const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs)
static void addVSDefines(const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs)
static bool shouldLoopVersion(const ArgList &Args)
@C shouldLoopVersion
static void addDashXForInput(const ArgList &Args, const InputInfo &Input, ArgStringList &CmdArgs)
Add -x lang to CmdArgs for Input.
static void addFloatingPointOptions(const Driver &D, const ArgList &Args, ArgStringList &CmdArgs)
Concrete class used by the front-end to report problems and issues.
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
unsigned getCustomDiagID(Level L, const char(&FormatString)[N])
Return an ID for a diagnostic with the specified format string and level.
types::ID getType() const
bool isHostOffloading(unsigned int OKind) const
Check if this action have any offload kinds.
bool isDeviceOffloading(OffloadKind OKind) const
Compilation - A set of tasks to perform for a single driver invocation.
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
DiagnosticBuilder Diag(unsigned DiagID) const
@ OMPRT_IOMP5
The legacy name for the LLVM OpenMP runtime from when it was the Intel OpenMP runtime.
@ OMPRT_OMP
The LLVM OpenMP runtime.
ID getPreprocessedType(ID Id)
getPreprocessedType - Get the ID of the type for this input when it has been preprocessed,...
const char * getTypeName(ID Id)
getTypeName - Return the name of the type for Id.
LTOKind
Describes the kind of LTO mode selected via -f(no-)?lto(=.*)? options.
bool willEmitRemarks(const llvm::opt::ArgList &Args)
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * T
static constexpr ResponseFileSupport AtFileUTF8()