28#include "clang/Config/config.h"
40#include "llvm/ADT/STLExtras.h"
41#include "llvm/ADT/SmallSet.h"
42#include "llvm/ADT/SmallString.h"
43#include "llvm/ADT/StringExtras.h"
44#include "llvm/ADT/StringSwitch.h"
45#include "llvm/ADT/Twine.h"
46#include "llvm/BinaryFormat/Magic.h"
47#include "llvm/Config/llvm-config.h"
48#include "llvm/Option/Arg.h"
49#include "llvm/Option/ArgList.h"
50#include "llvm/Option/Option.h"
51#include "llvm/Support/CodeGen.h"
52#include "llvm/Support/Compression.h"
53#include "llvm/Support/ErrorHandling.h"
54#include "llvm/Support/FileSystem.h"
55#include "llvm/Support/Path.h"
56#include "llvm/Support/Process.h"
57#include "llvm/Support/Program.h"
58#include "llvm/Support/Threading.h"
59#include "llvm/Support/VirtualFileSystem.h"
60#include "llvm/Support/YAMLParser.h"
61#include "llvm/TargetParser/AMDGPUTargetParser.h"
62#include "llvm/TargetParser/Host.h"
63#include "llvm/TargetParser/PPCTargetParser.h"
72 Arg *A = Args.getLastArg(options::OPT_offload_jobs_EQ);
76 StringRef Val = A->getValue();
77 if (Val.equals_insensitive(
"jobserver"))
81 if (Val.getAsInteger(10, NumThreads) || NumThreads <= 0)
88 const llvm::Triple &Triple) {
89 if (Args.hasArg(options::OPT_pg) && !Args.hasArg(options::OPT_mfentry))
92 if (Triple.isAndroid())
95 switch (Triple.getArch()) {
96 case llvm::Triple::xcore:
97 case llvm::Triple::wasm32:
98 case llvm::Triple::wasm64:
99 case llvm::Triple::msp430:
103 case llvm::Triple::ppc:
104 case llvm::Triple::ppcle:
105 case llvm::Triple::ppc64:
106 case llvm::Triple::ppc64le:
107 case llvm::Triple::riscv32:
108 case llvm::Triple::riscv64:
109 case llvm::Triple::riscv32be:
110 case llvm::Triple::riscv64be:
111 case llvm::Triple::sparc:
112 case llvm::Triple::sparcel:
113 case llvm::Triple::sparcv9:
114 case llvm::Triple::amdgpu:
115 case llvm::Triple::r600:
116 case llvm::Triple::csky:
117 case llvm::Triple::loongarch32:
118 case llvm::Triple::loongarch64:
119 case llvm::Triple::m68k:
120 case llvm::Triple::mips64:
121 case llvm::Triple::mips64el:
122 case llvm::Triple::mips:
123 case llvm::Triple::mipsel:
129 if (Triple.isOSFuchsia() || Triple.isOSNetBSD()) {
133 if (Triple.isOSLinux() || Triple.isOSHurd()) {
134 switch (Triple.getArch()) {
136 case llvm::Triple::arm:
137 case llvm::Triple::armeb:
138 case llvm::Triple::thumb:
139 case llvm::Triple::thumbeb:
140 case llvm::Triple::systemz:
141 case llvm::Triple::x86:
142 case llvm::Triple::x86_64:
149 if (Triple.isOSWindows()) {
150 switch (Triple.getArch()) {
151 case llvm::Triple::x86:
153 case llvm::Triple::x86_64:
154 return Triple.isOSBinFormatMachO();
155 case llvm::Triple::arm:
156 case llvm::Triple::thumb:
173 if (Triple.isAArch64() || Triple.isPS() || Triple.isVE() ||
174 (Triple.isAndroid() && !Triple.isARM()))
177 if ((Triple.isARM() || Triple.isThumb()) && Triple.isOSBinFormatMachO())
184 switch (Triple.getArch()) {
187 case llvm::Triple::arm:
188 case llvm::Triple::thumb:
191 return Triple.isOSDarwin();
198 const llvm::Triple &Triple) {
199 switch (Triple.getArch()) {
202 case llvm::Triple::arm:
203 case llvm::Triple::armeb:
204 case llvm::Triple::thumb:
205 case llvm::Triple::thumbeb:
209 if (Arg *A = Args.getLastArg(options::OPT_mframe_chain)) {
210 StringRef
V = A->getValue();
215 case llvm::Triple::aarch64:
219 return Triple.isOSWindows();
226 const llvm::Triple &Triple) {
227 if (Triple.isARM() || Triple.isThumb()) {
231 if (Arg *A = Args.getLastArg(options::OPT_mframe_chain)) {
232 StringRef
V = A->getValue();
233 return V ==
"aapcs+leaf";
242 const llvm::Triple &Triple) {
284 Args.hasFlag(options::OPT_fno_omit_frame_pointer,
285 options::OPT_fomit_frame_pointer, DefaultFP);
291 Args.hasFlag(options::OPT_mno_omit_leaf_frame_pointer,
292 options::OPT_momit_leaf_frame_pointer, DefaultLeafFP);
294 bool FPRegReserved = Args.hasFlag(options::OPT_mreserve_frame_pointer_reg,
295 options::OPT_mno_reserve_frame_pointer_reg,
313 const StringRef PluginOptPrefix) {
314 if (
const Arg *A = Args.getLastArg(options::OPT_Rpass_EQ))
315 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) +
316 "-pass-remarks=" + A->getValue()));
318 if (
const Arg *A = Args.getLastArg(options::OPT_Rpass_missed_EQ))
319 CmdArgs.push_back(Args.MakeArgString(
320 Twine(PluginOptPrefix) +
"-pass-remarks-missed=" + A->getValue()));
322 if (
const Arg *A = Args.getLastArg(options::OPT_Rpass_analysis_EQ))
323 CmdArgs.push_back(Args.MakeArgString(
324 Twine(PluginOptPrefix) +
"-pass-remarks-analysis=" + A->getValue()));
328 const llvm::Triple &Triple,
331 const StringRef PluginOptPrefix) {
332 StringRef Format =
"yaml";
333 if (
const Arg *A = Args.getLastArg(options::OPT_fsave_optimization_record_EQ))
334 Format = A->getValue();
338 Args.getLastArg(options::OPT_foptimization_record_file_EQ)) {
341 }
else if (
const Arg *A = Args.getLastArg(options::OPT_dumpdir)) {
348 assert(!F.empty() &&
"Cannot determine remarks output name.");
350 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) +
351 "opt-remarks-filename=" + F +
"opt.ld." +
355 Args.getLastArg(options::OPT_foptimization_record_passes_EQ))
356 CmdArgs.push_back(Args.MakeArgString(
357 Twine(PluginOptPrefix) +
"opt-remarks-passes=" + A->getValue()));
359 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) +
360 "opt-remarks-format=" + Format.data()));
364 ArgStringList &CmdArgs,
365 const StringRef PluginOptPrefix) {
366 if (Args.hasFlag(options::OPT_fdiagnostics_show_hotness,
367 options::OPT_fno_diagnostics_show_hotness,
false))
368 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) +
369 "opt-remarks-with-hotness"));
372 Args.getLastArg(options::OPT_fdiagnostics_hotness_threshold_EQ))
374 Args.MakeArgString(Twine(PluginOptPrefix) +
375 "opt-remarks-hotness-threshold=" + A->getValue()));
380 StringRef Processor) {
384 llvm::AMDGPU::GPUKind GPUKind = llvm::AMDGPU::parseArchAMDGCN(Processor);
385 if (llvm::AMDGPU::getFeatureBitset(GPUKind).test(
386 llvm::AMDGPU::FEAT_SUPPORTS_WGP))
388 return TargetFeatureArg.getOption().matches(options::OPT_mno_cumode);
393 if (D.
getVFS().exists(Path))
394 Paths.push_back(Path.str());
398 const llvm::Triple &Triple,
400 std::vector<StringRef> &Features,
401 OptSpecifier Group) {
402 std::set<StringRef> Warned;
403 for (
const Arg *A : Args.filtered(Group)) {
404 StringRef Name = A->getOption().getName();
408 assert(Name.starts_with(
"m") &&
"Invalid feature name.");
409 Name = Name.substr(1);
413 if (Warned.count(Name) == 0) {
415 clang::diag::warn_drv_unsupported_option_for_processor)
416 << A->getAsString(Args) << Proc;
422 bool IsNegative = Name.consume_front(
"no-");
424 Features.push_back(Args.MakeArgString((IsNegative ?
"-" :
"+") + Name));
432 llvm::DenseSet<StringRef> UsedFeatures;
433 for (StringRef
Feature : llvm::reverse(Features)) {
434 if (UsedFeatures.insert(
Feature.drop_front()).second)
435 UnifiedFeatures.insert(UnifiedFeatures.begin(),
Feature);
438 return UnifiedFeatures;
442 const char *ArgName,
const char *EnvVar) {
443 const char *DirList = ::getenv(EnvVar);
444 bool CombinedArg =
false;
449 StringRef Name(ArgName);
450 if (Name ==
"-I" || Name ==
"-L" || Name.empty())
453 StringRef Dirs(DirList);
457 StringRef::size_type Delim;
458 while ((Delim = Dirs.find(llvm::sys::EnvPathSeparator)) != StringRef::npos) {
461 CmdArgs.push_back(Args.MakeArgString(std::string(ArgName) +
"."));
463 CmdArgs.push_back(ArgName);
464 CmdArgs.push_back(
".");
469 Args.MakeArgString(std::string(ArgName) + Dirs.substr(0, Delim)));
471 CmdArgs.push_back(ArgName);
472 CmdArgs.push_back(Args.MakeArgString(Dirs.substr(0, Delim)));
475 Dirs = Dirs.substr(Delim + 1);
480 CmdArgs.push_back(Args.MakeArgString(std::string(ArgName) +
"."));
482 CmdArgs.push_back(ArgName);
483 CmdArgs.push_back(
".");
487 CmdArgs.push_back(Args.MakeArgString(std::string(ArgName) + Dirs));
489 CmdArgs.push_back(ArgName);
490 CmdArgs.push_back(Args.MakeArgString(Dirs));
496 const ArgList &Args, ArgStringList &CmdArgs,
502 Args.AddAllArgValues(CmdArgs, options::OPT_Zlinker_input);
509 for (
const auto &II : Inputs) {
513 if (
auto *IA = II.getAction())
523 if (II.isFilename()) {
524 CmdArgs.push_back(II.getFilename());
533 const Arg &A = II.getInputArg();
536 if (A.getOption().matches(options::OPT_Z_reserved_lib_stdcxx))
538 else if (A.getOption().matches(options::OPT_Z_reserved_lib_cckext))
541 else if (A.getOption().matches(options::OPT_rpath) &&
545 A.renderAsInput(Args, CmdArgs);
547 if (
const Arg *A = Args.getLastArg(options::OPT_fveclib)) {
548 const llvm::Triple &Triple = TC.
getTriple();
549 StringRef
V = A->getValue();
550 if (
V ==
"ArmPL" && (Triple.isOSLinux() || Triple.isOSDarwin())) {
568 if (Triple.isOSLinux()) {
569 CmdArgs.push_back(Args.MakeArgString(
"--push-state"));
570 CmdArgs.push_back(Args.MakeArgString(
"--as-needed"));
572 if (!Args.hasArg(options::OPT_nostdlib))
573 CmdArgs.push_back(Args.MakeArgString(
"-lm"));
574 CmdArgs.push_back(Args.MakeArgString(
"-lamath"));
575 if (!Args.hasArg(options::OPT_nostdlib))
576 CmdArgs.push_back(Args.MakeArgString(
"-lm"));
577 if (Triple.isOSLinux())
578 CmdArgs.push_back(Args.MakeArgString(
"--pop-state"));
585 switch (
T.getArch()) {
586 case llvm::Triple::x86:
590 case llvm::Triple::aarch64:
591 if (
T.isOSManagarm())
592 return "aarch64managarm";
595 return "aarch64linux";
596 case llvm::Triple::aarch64_be:
598 return "aarch64elfb";
599 return "aarch64linuxb";
600 case llvm::Triple::arm:
601 case llvm::Triple::thumb:
602 case llvm::Triple::armeb:
603 case llvm::Triple::thumbeb: {
606 return IsBigEndian ?
"armelfb" :
"armelf";
607 return IsBigEndian ?
"armelfb_linux_eabi" :
"armelf_linux_eabi";
609 case llvm::Triple::m68k:
611 case llvm::Triple::ppc:
613 return "elf32ppclinux";
615 case llvm::Triple::ppcle:
617 return "elf32lppclinux";
619 case llvm::Triple::ppc64:
621 case llvm::Triple::ppc64le:
623 case llvm::Triple::riscv32:
624 return "elf32lriscv";
625 case llvm::Triple::riscv64:
626 return "elf64lriscv";
627 case llvm::Triple::riscv32be:
628 return "elf32briscv";
629 case llvm::Triple::riscv64be:
630 return "elf64briscv";
631 case llvm::Triple::sparc:
632 case llvm::Triple::sparcel:
633 return "elf32_sparc";
634 case llvm::Triple::sparcv9:
635 return "elf64_sparc";
636 case llvm::Triple::loongarch32:
637 return "elf32loongarch";
638 case llvm::Triple::loongarch64:
639 return "elf64loongarch";
640 case llvm::Triple::mips:
641 return "elf32btsmip";
642 case llvm::Triple::mipsel:
643 return "elf32ltsmip";
644 case llvm::Triple::mips64:
646 return "elf32btsmipn32";
647 return "elf64btsmip";
648 case llvm::Triple::mips64el:
650 return "elf32ltsmipn32";
651 return "elf64ltsmip";
652 case llvm::Triple::systemz:
654 case llvm::Triple::x86_64:
656 return "elf32_x86_64";
658 case llvm::Triple::ve:
660 case llvm::Triple::csky:
661 return "cskyelf_linux";
668 const ToolChain &TC,
const llvm::opt::ArgList &Args,
669 llvm::opt::ArgStringList &CmdArgs) {
675 if (
const Arg *A = Args.getLastArg(options::OPT_gz_EQ)) {
676 StringRef
V = A->getValue();
677 if (
V ==
"none" ||
V ==
"zlib" ||
V ==
"zstd")
678 CmdArgs.push_back(Args.MakeArgString(
"--compress-debug-sections=" +
V));
680 TC.
getDriver().
Diag(diag::err_drv_unsupported_option_argument)
681 << A->getSpelling() <<
V;
686 ArgStringList &CmdArgs,
689 const Arg *A = Args.getLastArg(options::OPT_gz_EQ);
693 StringRef
Value = A->getValue();
694 if (
Value ==
"none") {
695 CmdArgs.push_back(
"--compress-debug-sections=none");
696 }
else if (
Value ==
"zlib") {
697 if (llvm::compression::zlib::isAvailable()) {
699 Args.MakeArgString(
"--compress-debug-sections=" + Twine(
Value)));
701 D.
Diag(diag::warn_debug_compression_unavailable) <<
"zlib";
703 }
else if (
Value ==
"zstd") {
704 if (llvm::compression::zstd::isAvailable()) {
706 Args.MakeArgString(
"--compress-debug-sections=" + Twine(
Value)));
708 D.
Diag(diag::warn_debug_compression_unavailable) <<
"zstd";
711 D.
Diag(diag::err_drv_unsupported_option_argument)
712 << A->getSpelling() <<
Value;
718 std::vector<StringRef> &Features,
719 OptSpecifier OnOpt, OptSpecifier OffOpt,
720 StringRef FeatureName) {
721 if (Arg *A = Args.getLastArg(OnOpt, OffOpt)) {
722 if (A->getOption().matches(OnOpt))
723 Features.push_back(Args.MakeArgString(
"+" + FeatureName));
725 Features.push_back(Args.MakeArgString(
"-" + FeatureName));
731 const ArgList &Args) {
732 if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) {
739 if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) {
740 return A->getValue();
748 if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) {
749 StringRef CPU = A->getValue();
755 return llvm::sys::getHostCPUName();
765 const llvm::Triple &
T,
bool FromAs) {
768 switch (
T.getArch()) {
772 case llvm::Triple::aarch64:
773 case llvm::Triple::aarch64_32:
774 case llvm::Triple::aarch64_be:
777 case llvm::Triple::arm:
778 case llvm::Triple::armeb:
779 case llvm::Triple::thumb:
780 case llvm::Triple::thumbeb: {
781 StringRef MArch, MCPU;
786 case llvm::Triple::avr:
787 if (
const Arg *A = Args.getLastArg(options::OPT_mmcu_EQ))
788 return A->getValue();
791 case llvm::Triple::m68k:
794 case llvm::Triple::mips:
795 case llvm::Triple::mipsel:
796 case llvm::Triple::mips64:
797 case llvm::Triple::mips64el: {
801 return std::string(CPUName);
804 case llvm::Triple::nvptx:
805 case llvm::Triple::nvptx64:
806 if (
const Arg *A = Args.getLastArg(options::OPT_march_EQ))
807 return A->getValue();
810 case llvm::Triple::ppc:
811 case llvm::Triple::ppcle:
812 case llvm::Triple::ppc64:
813 case llvm::Triple::ppc64le:
814 if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
816 llvm::PPC::getNormalizedPPCTargetCPU(
T, A->getValue()));
817 return std::string(llvm::PPC::getNormalizedPPCTargetCPU(
T));
819 case llvm::Triple::csky:
820 if (
const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
821 return A->getValue();
822 else if (
const Arg *A = Args.getLastArg(options::OPT_march_EQ))
823 return A->getValue();
826 case llvm::Triple::riscv32:
827 case llvm::Triple::riscv64:
828 case llvm::Triple::riscv32be:
829 case llvm::Triple::riscv64be:
832 case llvm::Triple::bpfel:
833 case llvm::Triple::bpfeb:
834 if (
const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
835 return A->getValue();
838 case llvm::Triple::sparc:
839 case llvm::Triple::sparcel:
840 case llvm::Triple::sparcv9:
843 case llvm::Triple::x86:
844 case llvm::Triple::x86_64:
847 case llvm::Triple::hexagon:
851 case llvm::Triple::lanai:
854 case llvm::Triple::systemz:
857 case llvm::Triple::amdgpu:
858 case llvm::Triple::r600:
861 case llvm::Triple::wasm32:
862 case llvm::Triple::wasm64:
865 case llvm::Triple::loongarch32:
866 case llvm::Triple::loongarch64:
869 case llvm::Triple::xtensa:
870 if (
const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
871 return A->getValue();
877 const llvm::Triple &Triple,
879 std::vector<StringRef> &Features) {
881 options::OPT_m_wasm_Features_Group);
885 const ArgList &Args, ArgStringList &CmdArgs,
886 bool ForAS,
bool IsAux) {
887 std::vector<StringRef> Features;
888 switch (Triple.getArch()) {
891 case llvm::Triple::mips:
892 case llvm::Triple::mipsel:
893 case llvm::Triple::mips64:
894 case llvm::Triple::mips64el:
897 case llvm::Triple::arm:
898 case llvm::Triple::armeb:
899 case llvm::Triple::thumb:
900 case llvm::Triple::thumbeb:
903 case llvm::Triple::ppc:
904 case llvm::Triple::ppcle:
905 case llvm::Triple::ppc64:
906 case llvm::Triple::ppc64le:
909 case llvm::Triple::riscv32:
910 case llvm::Triple::riscv64:
911 case llvm::Triple::riscv32be:
912 case llvm::Triple::riscv64be:
915 case llvm::Triple::systemz:
918 case llvm::Triple::aarch64:
919 case llvm::Triple::aarch64_32:
920 case llvm::Triple::aarch64_be:
923 case llvm::Triple::x86:
924 case llvm::Triple::x86_64:
927 case llvm::Triple::hexagon:
930 case llvm::Triple::wasm32:
931 case llvm::Triple::wasm64:
934 case llvm::Triple::sparc:
935 case llvm::Triple::sparcel:
936 case llvm::Triple::sparcv9:
939 case llvm::Triple::amdgpu:
940 case llvm::Triple::r600:
943 case llvm::Triple::nvptx:
944 case llvm::Triple::nvptx64:
947 case llvm::Triple::m68k:
950 case llvm::Triple::msp430:
953 case llvm::Triple::ve:
956 case llvm::Triple::csky:
959 case llvm::Triple::loongarch32:
960 case llvm::Triple::loongarch64:
966 CmdArgs.push_back(IsAux ?
"-aux-target-feature" :
"-target-feature");
967 CmdArgs.push_back(
Feature.data());
972 Arg *LtoJobsArg = Args.getLastArg(options::OPT_flto_jobs_EQ);
975 if (!llvm::get_threadpool_strategy(LtoJobsArg->getValue()))
976 D.
Diag(diag::err_drv_invalid_int_value)
977 << LtoJobsArg->getAsString(Args) << LtoJobsArg->getValue();
978 return LtoJobsArg->getValue();
983 return Triple.isPS();
988 ArgStringList &CmdArgs) {
990 if (Args.hasFlag(options::OPT_ffunction_sections,
991 options::OPT_fno_function_sections, UseSeparateSections))
992 CmdArgs.push_back(
"-ffunction-sections");
994 bool HasDefaultDataSections = Triple.isOSBinFormatXCOFF();
995 if (Args.hasFlag(options::OPT_fdata_sections, options::OPT_fno_data_sections,
996 UseSeparateSections || HasDefaultDataSections))
997 CmdArgs.push_back(
"-fdata-sections");
1001 const llvm::opt::ArgList &Args) {
1003 Arg *A = Args.getLastArg(options::OPT_mtls_dialect_EQ);
1005 return Triple.hasDefaultTLSDESC();
1006 StringRef
V = A->getValue();
1007 bool SupportedArgument =
false, EnableTLSDESC =
false;
1008 bool Unsupported = !Triple.isOSBinFormatELF();
1009 if (Triple.isLoongArch() || Triple.isRISCV()) {
1010 SupportedArgument =
V ==
"desc" ||
V ==
"trad";
1011 EnableTLSDESC =
V ==
"desc";
1012 }
else if (Triple.isX86()) {
1013 SupportedArgument =
V ==
"gnu" ||
V ==
"gnu2";
1014 EnableTLSDESC =
V ==
"gnu2";
1019 TC.
getDriver().
Diag(diag::err_drv_unsupported_opt_for_target)
1020 << A->getSpelling() << Triple.getTriple();
1021 }
else if (!SupportedArgument) {
1022 TC.
getDriver().
Diag(diag::err_drv_unsupported_option_argument_for_target)
1023 << A->getSpelling() <<
V << Triple.getTriple();
1025 return EnableTLSDESC;
1029 llvm::opt::ArgStringList &CmdArgs) {
1030 if (Arg *A = Args.getLastArg(options::OPT_fthinlto_distributor_EQ)) {
1032 Args.MakeArgString(
"--thinlto-distributor=" + Twine(A->getValue())));
1034 CmdArgs.push_back(Args.MakeArgString(
"--thinlto-remote-compiler=" +
1037 CmdArgs.push_back(Args.MakeArgString(
1038 "--thinlto-remote-compiler-prepend-arg=" + Twine(PA)));
1040 for (
const auto &A :
1041 Args.getAllArgValues(options::OPT_Xthinlto_distributor_EQ))
1042 CmdArgs.push_back(Args.MakeArgString(
"--thinlto-distributor-arg=" + A));
1047 ArgStringList &CmdArgs,
const InputInfo &Output,
1050 const bool IsOSAIX = Triple.isOSAIX();
1051 const bool IsAMDGCN = Triple.isAMDGCN();
1052 StringRef Linker = Args.getLastArgValue(options::OPT_fuse_ld_EQ);
1055 const bool IsFatLTO = Args.hasFlag(options::OPT_ffat_lto_objects,
1056 options::OPT_fno_fat_lto_objects,
false);
1057 const bool IsUnifiedLTO = Args.hasArg(options::OPT_funified_lto);
1059 assert(!Inputs.empty() &&
"Must have at least one input.");
1061 auto Input = llvm::find_if(
1063 if (Input == Inputs.end()) {
1066 Input = Inputs.begin();
1069 if (Linker !=
"lld" && Linker !=
"lld-link" &&
1070 llvm::sys::path::filename(LinkerPath) !=
"ld.lld" &&
1071 llvm::sys::path::stem(LinkerPath) !=
"ld.lld" && !Triple.isOSOpenBSD()) {
1075 const char *PluginPrefix = IsOSAIX ?
"-bplugin:" :
"";
1076 const char *PluginName = IsOSAIX ?
"/libLTO" :
"/LLVMgold";
1079 CmdArgs.push_back(
"-plugin");
1082 const char *Suffix =
".dll";
1083#elif defined(__APPLE__)
1084 const char *Suffix =
".dylib";
1086 const char *Suffix =
".so";
1090 llvm::sys::path::native(Twine(D.
Dir) +
1091 "/../" CLANG_INSTALL_LIBDIR_BASENAME +
1092 PluginName + Suffix,
1094 CmdArgs.push_back(Args.MakeArgString(Twine(PluginPrefix) + Plugin));
1099 CmdArgs.push_back(
"--fat-lto-objects");
1101 if (Args.hasArg(options::OPT_flto_partitions_EQ)) {
1103 StringRef A = Args.getLastArgValue(options::OPT_flto_partitions_EQ,
"8");
1104 if (A.getAsInteger(10,
Value) || (
Value < 1)) {
1105 Arg *Arg = Args.getLastArg(options::OPT_flto_partitions_EQ);
1106 D.
Diag(diag::err_drv_invalid_int_value)
1107 << Arg->getAsString(Args) << Arg->getValue();
1109 CmdArgs.push_back(Args.MakeArgString(
"--lto-partitions=" + A));
1113 const char *PluginOptPrefix = IsOSAIX ?
"-bplugin_opt:" :
"-plugin-opt=";
1114 const char *ExtraDash = IsOSAIX ?
"-" :
"";
1115 const char *ParallelismOpt = IsOSAIX ?
"-threads=" :
"jobs=";
1120 if (Args.hasArg(options::OPT_gdwarf_aranges)) {
1121 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) +
1122 "-generate-arange-section"));
1126 Arg *ArgVecLib = Args.getLastArg(options::OPT_fveclib);
1127 if (ArgVecLib && ArgVecLib->getNumValues() == 1) {
1130 std::optional<StringRef> OptVal =
1131 llvm::StringSwitch<std::optional<StringRef>>(ArgVecLib->getValue())
1132 .Case(
"Accelerate",
"Accelerate")
1133 .Case(
"libmvec",
"LIBMVEC")
1134 .Case(
"AMDLIBM",
"AMDLIBM")
1135 .Case(
"MASSV",
"MASSV")
1136 .Case(
"SVML",
"SVML")
1137 .Case(
"SLEEF",
"sleefgnuabi")
1138 .Case(
"Darwin_libsystem_m",
"Darwin_libsystem_m")
1139 .Case(
"ArmPL",
"ArmPL")
1140 .Case(
"none",
"none")
1141 .Default(std::nullopt);
1144 CmdArgs.push_back(Args.MakeArgString(
1145 Twine(PluginOptPrefix) +
"-vector-library=" + OptVal.value()));
1155 Args.MakeArgString(Twine(PluginOptPrefix) + ExtraDash +
"mcpu=" + CPU));
1157 if (Args.getLastArg(options::OPT_O_Group)) {
1158 unsigned OptimizationLevel =
1160 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) + ExtraDash +
1161 "O" + Twine(OptimizationLevel)));
1164 Args.MakeArgString(Twine(
"--lto-CGO") + Twine(OptimizationLevel)));
1167 if (Args.hasArg(options::OPT_gsplit_dwarf)) {
1169 if (
const Arg *A = Args.getLastArg(options::OPT_dumpdir)) {
1176 Args.MakeArgString(Twine(PluginOptPrefix) +
"dwo_dir=" + F +
"dwo"));
1179 if (IsThinLTO && !IsOSAIX)
1180 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) +
"thinlto"));
1181 else if (IsThinLTO && IsOSAIX)
1182 CmdArgs.push_back(Args.MakeArgString(Twine(
"-bdbg:thinlto")));
1187 if ((IsThinLTO || IsFatLTO || IsUnifiedLTO) &&
1188 Args.hasArg(options::OPT_fenable_matrix))
1190 Args.MakeArgString(Twine(PluginOptPrefix) +
"-enable-matrix"));
1193 if (!Parallelism.empty())
1194 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) +
1195 ParallelismOpt + Parallelism));
1200 if (Arg *A = Args.getLastArg(options::OPT_fslp_vectorize,
1201 options::OPT_fno_slp_vectorize))
1202 CmdArgs.push_back(Args.MakeArgString(
1203 Twine(PluginOptPrefix) +
"-vectorize-slp=" +
1204 (A->getOption().matches(options::OPT_fslp_vectorize) ?
"1" :
"0")));
1207 if (Arg *A = Args.getLastArg(options::OPT_fglobal_isel,
1208 options::OPT_fno_global_isel)) {
1211 CmdArgs.push_back(Args.MakeArgString(
1212 Twine(PluginOptPrefix) +
"-global-isel=" +
1213 (A->getOption().matches(options::OPT_fglobal_isel) ?
"1" :
"0")));
1218 Args.getLastArg(options::OPT_gTune_Group, options::OPT_ggdbN_Group)) {
1219 if (A->getOption().matches(options::OPT_glldb))
1221 Args.MakeArgString(Twine(PluginOptPrefix) +
"-debugger-tune=lldb"));
1222 else if (A->getOption().matches(options::OPT_gsce))
1224 Args.MakeArgString(Twine(PluginOptPrefix) +
"-debugger-tune=sce"));
1225 else if (A->getOption().matches(options::OPT_gdbx))
1227 Args.MakeArgString(Twine(PluginOptPrefix) +
"-debugger-tune=dbx"));
1230 Args.MakeArgString(Twine(PluginOptPrefix) +
"-debugger-tune=gdb"));
1236 Args.MakeArgString(Twine(PluginOptPrefix) +
"-no-integrated-as=1"));
1240 Arg *A = Args.getLastArg(options::OPT_g_Group);
1241 bool EnableDebugInfo = A && !A->getOption().matches(options::OPT_g0) &&
1242 !A->getOption().matches(options::OPT_ggdb0);
1243 if (EnableDebugInfo && Args.hasFlag(options::OPT_gstrict_dwarf,
1244 options::OPT_gno_strict_dwarf,
true))
1246 Args.MakeArgString(Twine(PluginOptPrefix) +
"-strict-dwarf=true"));
1248 for (
const Arg *A : Args.filtered_reverse(options::OPT_mabi_EQ)) {
1249 StringRef
V = A->getValue();
1250 if (
V ==
"vec-default")
1252 if (
V ==
"vec-extabi") {
1254 Args.MakeArgString(Twine(PluginOptPrefix) +
"-vec-extabi"));
1260 bool UseSeparateSections =
1263 if (Args.hasFlag(options::OPT_ffunction_sections,
1264 options::OPT_fno_function_sections, UseSeparateSections))
1266 Args.MakeArgString(Twine(PluginOptPrefix) +
"-function-sections=1"));
1267 else if (Args.hasArg(options::OPT_fno_function_sections))
1269 Args.MakeArgString(Twine(PluginOptPrefix) +
"-function-sections=0"));
1271 bool DataSectionsTurnedOff =
false;
1272 if (Args.hasFlag(options::OPT_fdata_sections, options::OPT_fno_data_sections,
1273 UseSeparateSections)) {
1275 Args.MakeArgString(Twine(PluginOptPrefix) +
"-data-sections=1"));
1276 }
else if (Args.hasArg(options::OPT_fno_data_sections)) {
1277 DataSectionsTurnedOff =
true;
1279 Args.MakeArgString(Twine(PluginOptPrefix) +
"-data-sections=0"));
1282 if (Args.hasArg(options::OPT_mxcoff_roptr) ||
1283 Args.hasArg(options::OPT_mno_xcoff_roptr)) {
1284 bool HasRoptr = Args.hasFlag(options::OPT_mxcoff_roptr,
1285 options::OPT_mno_xcoff_roptr,
false);
1286 StringRef OptStr = HasRoptr ?
"-mxcoff-roptr" :
"-mno-xcoff-roptr";
1288 D.
Diag(diag::err_drv_unsupported_opt_for_target)
1289 << OptStr << Triple.str();
1295 if (DataSectionsTurnedOff)
1296 D.
Diag(diag::err_roptr_requires_data_sections);
1299 Args.MakeArgString(Twine(PluginOptPrefix) +
"-mxcoff-roptr"));
1304 if (
auto *A = Args.getLastArg(options::OPT_fsplit_machine_functions,
1305 options::OPT_fno_split_machine_functions)) {
1306 if (A->getOption().matches(options::OPT_fsplit_machine_functions))
1307 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) +
1308 "-split-machine-functions"));
1312 Args.getLastArg(options::OPT_fpartition_static_data_sections,
1313 options::OPT_fno_partition_static_data_sections)) {
1314 if (A->getOption().matches(options::OPT_fpartition_static_data_sections)) {
1315 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) +
1316 "-partition-static-data-sections"));
1321 StringRef FName = A->getValue();
1322 if (!llvm::sys::fs::exists(FName))
1323 D.
Diag(diag::err_drv_no_such_file) << FName;
1325 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) +
1326 "sample-profile=" + FName));
1330 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) + ExtraDash +
1331 "cs-profile-generate"));
1332 if (CSPGOGenerateArg->getOption().matches(
1333 options::OPT_fcs_profile_generate_EQ)) {
1335 llvm::sys::path::append(Path,
"default_%m.profraw");
1336 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) + ExtraDash +
1337 "cs-profile-path=" + Path));
1340 Args.MakeArgString(Twine(PluginOptPrefix) + ExtraDash +
1341 "cs-profile-path=default_%m.profraw"));
1344 ProfileUseArg->getNumValues() == 0 ?
"" : ProfileUseArg->getValue());
1345 if (Path.empty() || llvm::sys::fs::is_directory(Path))
1346 llvm::sys::path::append(Path,
"default.profdata");
1347 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) + ExtraDash +
1348 "cs-profile-path=" + Path));
1352 if (Args.hasFlag(options::OPT_fjmc, options::OPT_fno_jmc,
false)) {
1354 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) +
1355 "-enable-jmc-instrument"));
1357 D.
Diag(clang::diag::warn_drv_fjmc_for_elf_only);
1360 if (Args.hasFlag(options::OPT_femulated_tls, options::OPT_fno_emulated_tls,
1361 Triple.hasDefaultEmulatedTLS())) {
1363 Args.MakeArgString(Twine(PluginOptPrefix) +
"-emulated-tls"));
1367 Args.MakeArgString(Twine(PluginOptPrefix) +
"-enable-tlsdesc"));
1369 if (Args.hasFlag(options::OPT_fstack_size_section,
1370 options::OPT_fno_stack_size_section,
false))
1372 Args.MakeArgString(Twine(PluginOptPrefix) +
"-stack-size-section"));
1374 if (Args.hasFlag(options::OPT_fexperimental_call_graph_section,
1375 options::OPT_fno_experimental_call_graph_section,
false))
1377 Args.MakeArgString(Twine(PluginOptPrefix) +
"-call-graph-section"));
1381 if (!StatsFile.empty())
1383 Args.MakeArgString(Twine(PluginOptPrefix) +
"stats-file=" + StatsFile));
1386 if (Arg *A = Args.getLastArg(options::OPT_fcrash_diagnostics_dir))
1387 CmdArgs.push_back(Args.MakeArgString(
1388 Twine(PluginOptPrefix) +
"-crash-diagnostics-dir=" + A->getValue()));
1399 Output, PluginOptPrefix);
1405 true, PluginOptPrefix);
1407 bool IsELF = Triple.isOSBinFormatELF();
1409 bool ImplicitMapSyms =
false;
1410 for (
const Arg *A : Args.filtered(options::OPT_Wa_COMMA)) {
1411 for (StringRef
V : A->getValues()) {
1412 auto Equal =
V.split(
'=');
1413 auto checkArg = [&](
bool ValidTarget,
1414 std::initializer_list<const char *>
Set) {
1416 D.
Diag(diag::err_drv_unsupported_opt_for_target)
1417 << (Twine(
"-Wa,") +
Equal.first +
"=").str()
1418 << Triple.getTriple();
1419 }
else if (!llvm::is_contained(
Set,
Equal.second)) {
1420 D.
Diag(diag::err_drv_unsupported_option_argument)
1421 << (Twine(
"-Wa,") +
Equal.first +
"=").str() <<
Equal.second;
1424 if (
Equal.first ==
"-mmapsyms") {
1425 ImplicitMapSyms =
Equal.second ==
"implicit";
1426 checkArg(IsELF && Triple.isAArch64(), {
"default",
"implicit"});
1427 }
else if (
V ==
"--crel")
1429 else if (
V ==
"--no-crel")
1437 if (IsELF && !Triple.isMIPS()) {
1438 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) +
"-crel"));
1440 D.
Diag(diag::err_drv_unsupported_opt_for_target)
1444 if (ImplicitMapSyms)
1446 Args.MakeArgString(Twine(PluginOptPrefix) +
"-implicit-mapsyms"));
1448 if (Args.hasArg(options::OPT_ftime_report))
1450 Args.MakeArgString(Twine(PluginOptPrefix) +
"-time-passes"));
1456 const ArgList &Args,
1457 ArgStringList &CmdArgs) {
1462 llvm::sys::path::append(DefaultLibPath, CLANG_INSTALL_LIBDIR_BASENAME);
1463 CmdArgs.push_back(Args.MakeArgString(
"-L" + DefaultLibPath));
1467 ArgStringList &CmdArgs) {
1468 if (!Args.hasFlag(options::OPT_frtlib_add_rpath,
1469 options::OPT_fno_rtlib_add_rpath,
false))
1481 llvm::sys::path::append(P, M.gccSuffix());
1482 CandidateRPaths.emplace_back(std::string(P));
1484 CandidateRPaths.emplace_back(*StdlibPath);
1486 for (
const auto &CandidateRPath : CandidateRPaths) {
1487 if (TC.
getVFS().exists(CandidateRPath)) {
1488 CmdArgs.push_back(
"-rpath");
1489 CmdArgs.push_back(Args.MakeArgString(CandidateRPath));
1495 ArgStringList &CmdArgs,
1496 const ToolChain &TC,
const ArgList &Args) {
1498 if (!Args.hasFlag(options::OPT_foffload_via_llvm,
1499 options::OPT_fno_offload_via_llvm,
false))
1502 CmdArgs.push_back(
"-lLLVMOffloadKernel");
1507 const ToolChain &TC,
const ArgList &Args,
1508 bool ForceStaticHostRuntime,
bool IsOffloadingHost,
1510 if (!Args.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ,
1511 options::OPT_fno_openmp,
false))
1520 if (ForceStaticHostRuntime)
1521 CmdArgs.push_back(
"-Bstatic");
1525 CmdArgs.push_back(
"-lomp");
1528 CmdArgs.push_back(
"-lgomp");
1531 CmdArgs.push_back(
"-liomp5");
1537 if (ForceStaticHostRuntime)
1538 CmdArgs.push_back(
"-Bdynamic");
1541 CmdArgs.push_back(
"-lrt");
1543 if (IsOffloadingHost)
1544 CmdArgs.push_back(
"-lomptarget");
1555 const llvm::opt::ArgList &Args,
1556 llvm::opt::ArgStringList &CmdArgs) {
1562 constexpr llvm::StringLiteral Targets(
"--offload-targets=");
1566 std::transform(TCRange.first, TCRange.second, std::back_inserter(Triples),
1567 [](
auto TC) { return TC.second->getTripleString(); });
1569 Args.MakeArgString(Twine(Targets) + llvm::join(Triples,
",")));
1573 ArgStringList &CmdArgs, StringRef Sanitizer,
1574 bool IsShared,
bool IsWhole) {
1577 if (IsWhole) CmdArgs.push_back(
"--whole-archive");
1580 if (IsWhole) CmdArgs.push_back(
"--no-whole-archive");
1590 ArgStringList &CmdArgs,
1591 StringRef Sanitizer) {
1596 if (TC.
getTriple().isOSSolaris() && !LinkerIsGnuLd)
1599 if (llvm::sys::fs::exists(SanRT +
".syms")) {
1600 CmdArgs.push_back(Args.MakeArgString(
"--dynamic-list=" + SanRT +
".syms"));
1607 const llvm::opt::ArgList &Args,
1608 llvm::opt::ArgStringList &CmdArgs,
1611 "AIX linker does not support any form of --as-needed option yet.");
1619 if (TC.
getTriple().isOSSolaris() && !LinkerIsGnuLd) {
1620 CmdArgs.push_back(
"-z");
1621 CmdArgs.push_back(as_needed ?
"ignore" :
"record");
1623 CmdArgs.push_back(as_needed ?
"--as-needed" :
"--no-as-needed");
1628 const llvm::opt::ArgList &Args,
1629 ArgStringList &CmdArgs) {
1634 if (TC.
getTriple().getOS() != llvm::Triple::RTEMS &&
1636 CmdArgs.push_back(
"-lpthread");
1638 CmdArgs.push_back(
"-lrt");
1640 CmdArgs.push_back(
"-lm");
1645 TC.
getTriple().getOS() != llvm::Triple::RTEMS)
1646 CmdArgs.push_back(
"-ldl");
1650 CmdArgs.push_back(
"-lexecinfo");
1652 CmdArgs.push_back(
"-lbsd");
1658 CmdArgs.push_back(
"-lresolv");
1668 assert(!TC.
getTriple().isOSDarwin() &&
"it's not used by Darwin");
1673 SharedRuntimes.push_back(
"asan");
1674 if (!Args.hasArg(options::OPT_shared) && !TC.
getTriple().isAndroid())
1675 HelperStaticRuntimes.push_back(
"asan-preinit");
1678 SharedRuntimes.push_back(
"memprof");
1679 if (!Args.hasArg(options::OPT_shared) && !TC.
getTriple().isAndroid())
1680 HelperStaticRuntimes.push_back(
"memprof-preinit");
1683 SharedRuntimes.push_back(
"nsan");
1686 SharedRuntimes.push_back(
"ubsan_minimal");
1688 SharedRuntimes.push_back(
"ubsan_standalone");
1691 SharedRuntimes.push_back(
"scudo_standalone");
1694 SharedRuntimes.push_back(
"tsan");
1696 SharedRuntimes.push_back(
"tysan");
1699 SharedRuntimes.push_back(
"hwasan_aliases");
1701 SharedRuntimes.push_back(
"hwasan");
1702 if (!Args.hasArg(options::OPT_shared))
1703 HelperStaticRuntimes.push_back(
"hwasan-preinit");
1706 SharedRuntimes.push_back(
"rtsan");
1711 StaticRuntimes.push_back(
"stats_client");
1715 HelperStaticRuntimes.push_back(
"asan_static");
1718 if (Args.hasArg(options::OPT_shared)) {
1727 StaticRuntimes.push_back(
"asan");
1729 StaticRuntimes.push_back(
"asan_cxx");
1734 StaticRuntimes.push_back(
"rtsan");
1737 StaticRuntimes.push_back(
"memprof");
1739 StaticRuntimes.push_back(
"memprof_cxx");
1744 StaticRuntimes.push_back(
"hwasan_aliases");
1746 StaticRuntimes.push_back(
"hwasan_aliases_cxx");
1748 StaticRuntimes.push_back(
"hwasan");
1750 StaticRuntimes.push_back(
"hwasan_cxx");
1754 StaticRuntimes.push_back(
"dfsan");
1756 StaticRuntimes.push_back(
"lsan");
1758 StaticRuntimes.push_back(
"msan");
1760 StaticRuntimes.push_back(
"msan_cxx");
1763 StaticRuntimes.push_back(
"nsan");
1765 StaticRuntimes.push_back(
"tsan");
1767 StaticRuntimes.push_back(
"tsan_cxx");
1770 StaticRuntimes.push_back(
"tysan");
1773 StaticRuntimes.push_back(
"ubsan_minimal");
1775 StaticRuntimes.push_back(
"ubsan_standalone");
1779 NonWholeStaticRuntimes.push_back(
"safestack");
1780 RequiredSymbols.push_back(
"__safestack_init");
1784 StaticRuntimes.push_back(
"cfi");
1786 StaticRuntimes.push_back(
"cfi_diag");
1791 StaticRuntimes.push_back(
"ubsan_standalone_cxx");
1794 NonWholeStaticRuntimes.push_back(
"stats");
1795 RequiredSymbols.push_back(
"__sanitizer_stats_register");
1798 StaticRuntimes.push_back(
"scudo_standalone");
1800 StaticRuntimes.push_back(
"scudo_standalone_cxx");
1803 NonWholeStaticRuntimes.push_back(
"ubsan_loop_detect");
1809 ArgStringList &CmdArgs) {
1812 NonWholeStaticRuntimes, HelperStaticRuntimes, RequiredSymbols;
1815 NonWholeStaticRuntimes, HelperStaticRuntimes,
1820 for (
auto S : RequiredSymbols) {
1821 CmdArgs.push_back(
"-u");
1822 CmdArgs.push_back(Args.MakeArgString(S));
1826 for (
auto RT : SharedRuntimes)
1830 bool FuzzerNeedsSanitizerDeps =
false;
1832 !Args.hasArg(options::OPT_shared)) {
1835 FuzzerNeedsSanitizerDeps =
true;
1839 if (!Args.hasArg(options::OPT_nostdlibxx)) {
1840 bool OnlyLibstdcxxStatic = Args.hasArg(options::OPT_static_libstdcxx) &&
1841 !Args.hasArg(options::OPT_static);
1842 if (OnlyLibstdcxxStatic)
1843 CmdArgs.push_back(
"-Bstatic");
1845 if (OnlyLibstdcxxStatic)
1846 CmdArgs.push_back(
"-Bdynamic");
1850 for (
auto RT : HelperStaticRuntimes)
1852 bool AddExportDynamic =
false;
1853 for (
auto RT : StaticRuntimes) {
1857 for (
auto RT : NonWholeStaticRuntimes) {
1863 if (AddExportDynamic && !TC.
getTriple().isNVPTX())
1864 CmdArgs.push_back(
"--export-dynamic");
1867 CmdArgs.push_back(
"--export-dynamic-symbol=__cfi_check");
1870 CmdArgs.push_back(
"-z");
1872 Args.MakeArgString(
"memtag-mode=" + SanArgs.
getMemtagMode()));
1875 CmdArgs.push_back(
"-z");
1876 CmdArgs.push_back(
"memtag-heap");
1880 CmdArgs.push_back(
"-z");
1881 CmdArgs.push_back(
"memtag-stack");
1885 CmdArgs.push_back(
"--android-memtag-note");
1888 return !StaticRuntimes.empty() || !NonWholeStaticRuntimes.empty() ||
1889 FuzzerNeedsSanitizerDeps;
1894 if (Args.hasArg(options::OPT_shared)) {
1896 CmdArgs.push_back(
"--whole-archive");
1898 CmdArgs.push_back(
"--no-whole-archive");
1902 CmdArgs.push_back(
"--whole-archive");
1904 for (
const auto &Mode : XRay.
modeList())
1906 CmdArgs.push_back(
"--no-whole-archive");
1914 const llvm::opt::ArgList &Args,
1915 ArgStringList &CmdArgs) {
1917 CmdArgs.push_back(
"-lpthread");
1919 CmdArgs.push_back(
"-lrt");
1920 CmdArgs.push_back(
"-lm");
1925 CmdArgs.push_back(
"-ldl");
1930 if (Arg *A = Args.getLastArg(options::OPT_O_Group))
1931 return !A->getOption().matches(options::OPT_O0);
1939 auto AddPostfix = [JA](
auto &F) {
1944 if (Arg *A = Args.getLastArg(options::OPT_gsplit_dwarf_EQ))
1945 if (StringRef(A->getValue()) ==
"single" && Output.
isFilename())
1949 if (
const Arg *A = Args.getLastArg(options::OPT_dumpdir)) {
1952 if (Args.hasArg(options::OPT_o, options::OPT__SLASH_o,
1953 options::OPT__SLASH_Fo) &&
1954 Args.hasArg(options::OPT_c) && Output.
isFilename()) {
1958 llvm::sys::path::remove_filename(
T);
1959 llvm::sys::path::append(
T, llvm::sys::path::stem(Obj));
1961 return Args.MakeArgString(
T);
1967 return Args.MakeArgString(
T);
1971 const JobAction &JA,
const ArgList &Args,
1972 const InputInfo &Output,
const char *OutFile) {
1973 ArgStringList ExtractArgs;
1974 ExtractArgs.push_back(
"--extract-dwo");
1976 ArgStringList StripArgs;
1977 StripArgs.push_back(
"--strip-dwo");
1982 ExtractArgs.push_back(OutFile);
1989 C.addCommand(std::make_unique<Command>(JA,
T,
1991 Exec, ExtractArgs, II, Output));
1994 C.addCommand(std::make_unique<Command>(
2004 Args.ClaimAllArgs(options::OPT_flto_EQ);
2005 Args.ClaimAllArgs(options::OPT_flto);
2006 Args.ClaimAllArgs(options::OPT_fno_lto);
2010 auto *CSPGOGenerateArg = Args.getLastArg(options::OPT_fcs_profile_generate,
2011 options::OPT_fcs_profile_generate_EQ,
2012 options::OPT_fno_profile_generate);
2013 if (CSPGOGenerateArg &&
2014 CSPGOGenerateArg->getOption().matches(options::OPT_fno_profile_generate))
2015 CSPGOGenerateArg =
nullptr;
2017 return CSPGOGenerateArg;
2021 auto *ProfileUseArg = Args.getLastArg(
2022 options::OPT_fprofile_instr_use, options::OPT_fprofile_instr_use_EQ,
2023 options::OPT_fprofile_use, options::OPT_fprofile_use_EQ,
2024 options::OPT_fno_profile_instr_use);
2026 if (ProfileUseArg &&
2027 ProfileUseArg->getOption().matches(options::OPT_fno_profile_instr_use))
2028 ProfileUseArg =
nullptr;
2030 return ProfileUseArg;
2034 auto *ProfileSampleUseArg = Args.getLastArg(
2035 options::OPT_fprofile_sample_use_EQ, options::OPT_fno_profile_sample_use);
2037 if (ProfileSampleUseArg && (ProfileSampleUseArg->getOption().matches(
2038 options::OPT_fno_profile_sample_use)))
2041 return Args.getLastArg(options::OPT_fprofile_sample_use_EQ);
2046 case llvm::Reloc::Static:
2048 case llvm::Reloc::PIC_:
2050 case llvm::Reloc::DynamicNoPIC:
2051 return "dynamic-no-pic";
2052 case llvm::Reloc::ROPI:
2054 case llvm::Reloc::RWPI:
2056 case llvm::Reloc::ROPI_RWPI:
2059 llvm_unreachable(
"Unknown Reloc::Model kind");
2066std::tuple<llvm::Reloc::Model, unsigned, bool>
2074 if (Triple.isOSBinFormatMachO() && Args.hasArg(options::OPT_static))
2076 bool IsPICLevelTwo = PIC;
2079 Args.hasArg(options::OPT_mkernel, options::OPT_fapple_kext);
2082 if (Triple.isAndroid()) {
2083 switch (Triple.getArch()) {
2084 case llvm::Triple::x86:
2085 case llvm::Triple::x86_64:
2087 IsPICLevelTwo =
true;
2097 if (Triple.isOHOSFamily() && Triple.getArch() == llvm::Triple::aarch64)
2101 if (Triple.isOSOpenBSD()) {
2103 case llvm::Triple::arm:
2104 case llvm::Triple::aarch64:
2105 case llvm::Triple::mips64:
2106 case llvm::Triple::mips64el:
2107 case llvm::Triple::x86:
2108 case llvm::Triple::x86_64:
2109 IsPICLevelTwo =
false;
2112 case llvm::Triple::ppc:
2113 case llvm::Triple::sparcv9:
2114 IsPICLevelTwo =
true;
2126 Arg *LastPICArg = Args.getLastArg(options::OPT_fPIC, options::OPT_fno_PIC,
2127 options::OPT_fpic, options::OPT_fno_pic,
2128 options::OPT_fPIE, options::OPT_fno_PIE,
2129 options::OPT_fpie, options::OPT_fno_pie);
2130 if (Triple.isOSWindows() && !Triple.isOSCygMing() && LastPICArg &&
2131 LastPICArg == Args.getLastArg(options::OPT_fPIC, options::OPT_fpic,
2132 options::OPT_fPIE, options::OPT_fpie)) {
2134 << LastPICArg->getSpelling() << Triple.str();
2135 if (Triple.getArch() == llvm::Triple::x86_64)
2136 return std::make_tuple(llvm::Reloc::PIC_, 2U,
false);
2137 return std::make_tuple(llvm::Reloc::Static, 0
U,
false);
2144 Option O = LastPICArg->getOption();
2145 if (O.matches(options::OPT_fPIC) || O.matches(options::OPT_fpic) ||
2146 O.matches(options::OPT_fPIE) || O.matches(options::OPT_fpie)) {
2147 PIE = O.matches(options::OPT_fPIE) || O.matches(options::OPT_fpie);
2149 PIE || O.matches(options::OPT_fPIC) || O.matches(options::OPT_fpic);
2151 O.matches(options::OPT_fPIE) || O.matches(options::OPT_fPIC);
2154 if (EffectiveTriple.isPS()) {
2155 Arg *ModelArg = Args.getLastArg(options::OPT_mcmodel_EQ);
2156 StringRef Model = ModelArg ? ModelArg->getValue() :
"";
2157 if (Model !=
"kernel") {
2160 << LastPICArg->getSpelling()
2161 << (EffectiveTriple.isPS4() ?
"PS4" :
"PS5");
2171 if (PIC && (Triple.isOSDarwin() || EffectiveTriple.isPS()))
2177 ((!EffectiveTriple.isiOS() || EffectiveTriple.isOSVersionLT(6)) &&
2178 !EffectiveTriple.isWatchOS() && !EffectiveTriple.isDriverKit()))
2181 if (Arg *A = Args.getLastArg(options::OPT_mdynamic_no_pic)) {
2184 if (!Triple.isOSDarwin())
2186 << A->getSpelling() << Triple.str();
2195 return std::make_tuple(llvm::Reloc::DynamicNoPIC, PIC ? 2U : 0
U,
false);
2198 bool EmbeddedPISupported;
2199 switch (Triple.getArch()) {
2200 case llvm::Triple::arm:
2201 case llvm::Triple::armeb:
2202 case llvm::Triple::thumb:
2203 case llvm::Triple::thumbeb:
2204 EmbeddedPISupported =
true;
2207 EmbeddedPISupported =
false;
2211 bool ROPI =
false, RWPI =
false;
2212 Arg* LastROPIArg = Args.getLastArg(options::OPT_fropi, options::OPT_fno_ropi);
2213 if (LastROPIArg && LastROPIArg->getOption().matches(options::OPT_fropi)) {
2214 if (!EmbeddedPISupported)
2216 << LastROPIArg->getSpelling() << Triple.str();
2219 Arg *LastRWPIArg = Args.getLastArg(options::OPT_frwpi, options::OPT_fno_rwpi);
2220 if (LastRWPIArg && LastRWPIArg->getOption().matches(options::OPT_frwpi)) {
2221 if (!EmbeddedPISupported)
2223 << LastRWPIArg->getSpelling() << Triple.str();
2228 if ((ROPI || RWPI) && (PIC || PIE))
2231 if (Triple.isMIPS()) {
2238 if (ABIName ==
"n64")
2241 if(Args.hasArg(options::OPT_mno_abicalls))
2242 return std::make_tuple(llvm::Reloc::Static, 0
U,
false);
2245 IsPICLevelTwo =
false;
2249 return std::make_tuple(llvm::Reloc::PIC_, IsPICLevelTwo ? 2U : 1U, PIE);
2251 llvm::Reloc::Model RelocM = llvm::Reloc::Static;
2253 RelocM = llvm::Reloc::ROPI_RWPI;
2255 RelocM = llvm::Reloc::ROPI;
2257 RelocM = llvm::Reloc::RWPI;
2259 return std::make_tuple(RelocM, 0
U,
false);
2263 bool HasStaticPIE = Args.hasArg(options::OPT_static_pie);
2264 if (HasStaticPIE && Args.hasArg(options::OPT_no_pie)) {
2266 const llvm::opt::OptTable &Opts = D.
getOpts();
2267 StringRef StaticPIEName = Opts.getOptionName(options::OPT_static_pie);
2268 StringRef NoPIEName = Opts.getOptionName(options::OPT_nopie);
2269 D.
Diag(diag::err_drv_cannot_mix_options) << StaticPIEName << NoPIEName;
2271 return HasStaticPIE;
2291 const ArgList &Args) {
2292 const Arg *A = Args.getLastArg(options::OPT_falign_functions,
2293 options::OPT_falign_functions_EQ,
2294 options::OPT_fno_align_functions);
2295 if (!A || A->getOption().matches(options::OPT_fno_align_functions))
2298 if (A->getOption().matches(options::OPT_falign_functions))
2302 if (StringRef(A->getValue()).getAsInteger(10,
Value) ||
Value > 65536)
2304 << A->getAsString(Args) << A->getValue();
2309 ArgStringList &CmdArgs, llvm::codegenoptions::DebugInfoKind DebugInfoKind) {
2310 switch (DebugInfoKind) {
2311 case llvm::codegenoptions::DebugDirectivesOnly:
2312 CmdArgs.push_back(
"-debug-info-kind=line-directives-only");
2314 case llvm::codegenoptions::DebugLineTablesOnly:
2315 CmdArgs.push_back(
"-debug-info-kind=line-tables-only");
2317 case llvm::codegenoptions::DebugInfoConstructor:
2318 CmdArgs.push_back(
"-debug-info-kind=constructor");
2320 case llvm::codegenoptions::LimitedDebugInfo:
2321 CmdArgs.push_back(
"-debug-info-kind=limited");
2323 case llvm::codegenoptions::FullDebugInfo:
2324 CmdArgs.push_back(
"-debug-info-kind=standalone");
2326 case llvm::codegenoptions::UnusedTypeInfo:
2327 CmdArgs.push_back(
"-debug-info-kind=unused-types");
2337 assert(A.getOption().matches(options::OPT_gN_Group) &&
2338 "Not a -g option that specifies a debug-info level");
2339 if (A.getOption().matches(options::OPT_g0) ||
2340 A.getOption().matches(options::OPT_ggdb0))
2341 return llvm::codegenoptions::NoDebugInfo;
2342 if (A.getOption().matches(options::OPT_gline_tables_only) ||
2343 A.getOption().matches(options::OPT_ggdb1))
2344 return llvm::codegenoptions::DebugLineTablesOnly;
2345 if (A.getOption().matches(options::OPT_gline_directives_only))
2346 return llvm::codegenoptions::DebugDirectivesOnly;
2347 return llvm::codegenoptions::DebugInfoConstructor;
2351 const ArgList &Args) {
2352 const Arg *A = Args.getLastArg(options::OPT_fdebug_default_version);
2358 if (StringRef(A->getValue()).getAsInteger(10,
Value) ||
Value > 6 ||
2361 << A->getAsString(Args) << A->getValue();
2366 return llvm::StringSwitch<unsigned>(ArgValue)
2367 .Case(
"-gdwarf-2", 2)
2368 .Case(
"-gdwarf-3", 3)
2369 .Case(
"-gdwarf-4", 4)
2370 .Case(
"-gdwarf-5", 5)
2371 .Case(
"-gdwarf-6", 6)
2376 return Args.getLastArg(options::OPT_gdwarf_2, options::OPT_gdwarf_3,
2377 options::OPT_gdwarf_4, options::OPT_gdwarf_5,
2378 options::OPT_gdwarf_6, options::OPT_gdwarf);
2382 const llvm::opt::ArgList &Args) {
2387 if (DwarfVersion == 5 && TC.
getTriple().isOSAIX())
2388 TC.
getDriver().
Diag(diag::err_drv_unsupported_opt_for_target)
2389 << GDwarfN->getSpelling() << TC.
getTriple().str();
2391 if (DwarfVersion == 0) {
2393 assert(DwarfVersion &&
"toolchain default DWARF version must be nonzero");
2395 return DwarfVersion;
2399 const ArgList &Args, Arg *&Arg) {
2400 Arg = Args.getLastArg(options::OPT_gsplit_dwarf, options::OPT_gsplit_dwarf_EQ,
2401 options::OPT_gno_split_dwarf);
2402 if (!Arg || Arg->getOption().matches(options::OPT_gno_split_dwarf))
2405 if (Arg->getOption().matches(options::OPT_gsplit_dwarf))
2408 StringRef
Value = Arg->getValue();
2409 if (
Value ==
"split")
2411 if (
Value ==
"single")
2414 D.
Diag(diag::err_drv_unsupported_option_argument)
2415 << Arg->getSpelling() << Arg->getValue();
2421 assert(A &&
"Expected non-nullptr argument.");
2424 D.
Diag(diag::warn_drv_unsupported_debug_info_opt_for_target)
2430 const ArgList &Args,
2431 ArgStringList &CmdArgs) {
2432 if (Args.hasFlag(options::OPT_fdebug_info_for_profiling,
2433 options::OPT_fno_debug_info_for_profiling,
false) &&
2435 Args.getLastArg(options::OPT_fdebug_info_for_profiling), Args, D, TC))
2436 CmdArgs.push_back(
"-fdebug-info-for-profiling");
2440 ArgStringList &CmdArgs) {
2441 llvm::Reloc::Model RelocationModel;
2446 if (RelocationModel != llvm::Reloc::Static)
2447 CmdArgs.push_back(
"-KPIC");
2453 return Args.hasFlag(options::OPT_fobjc_arc, options::OPT_fno_objc_arc,
false);
2459 const ArgList &Args) {
2460 if (Args.hasArg(options::OPT_static_libgcc) ||
2461 Args.hasArg(options::OPT_static) || Args.hasArg(options::OPT_static_pie) ||
2465 if (Args.hasArg(options::OPT_shared_libgcc))
2484 ArgStringList &CmdArgs,
const ArgList &Args) {
2488 CmdArgs.push_back(
"-l:libunwind.a");
2511 CmdArgs.push_back(
"-lgcc_eh");
2513 CmdArgs.push_back(
"-lgcc_s");
2521 CmdArgs.push_back(
"-lunwind");
2523 CmdArgs.push_back(
"-l:libunwind.a");
2526 CmdArgs.push_back(
"-l:libunwind.dll.a");
2528 CmdArgs.push_back(
"-l:libunwind.so");
2532 CmdArgs.push_back(
"-lunwind");
2542 ArgStringList &CmdArgs,
const ArgList &Args) {
2546 CmdArgs.push_back(
"-lgcc");
2550 CmdArgs.push_back(
"-lgcc");
2554 CmdArgs.push_back(
"--as-needed");
2556 CmdArgs.push_back(
"--no-as-needed");
2561 ArgStringList &CmdArgs,
const ArgList &Args) {
2572 if (TC.
getTriple().isKnownWindowsMSVCEnvironment()) {
2575 Arg *A = Args.getLastArg(options::OPT_rtlib_EQ);
2576 if (A && A->getValue() != StringRef(
"platform")) {
2577 TC.
getDriver().
Diag(diag::err_drv_unsupported_rtlib_for_platform)
2578 << A->getValue() <<
"MSVC";
2588 if (TC.
getTriple().isAndroid() && !Args.hasArg(options::OPT_static) &&
2589 !Args.hasArg(options::OPT_static_pie))
2590 CmdArgs.push_back(
"-ldl");
2597 const Arg *A = Args.getLastArg(options::OPT_save_stats_EQ);
2603 StringRef SaveStats = A->getValue();
2604 if (SaveStats ==
"obj" && Output.
isFilename()) {
2606 llvm::sys::path::remove_filename(StatsFile);
2607 }
else if (SaveStats !=
"cwd") {
2608 D.
Diag(diag::err_drv_invalid_value) << A->getAsString(Args) << SaveStats;
2612 StringRef BaseName = llvm::sys::path::filename(Input.
getBaseInput());
2613 llvm::sys::path::append(StatsFile, BaseName);
2614 llvm::sys::path::replace_extension(StatsFile,
"stats");
2626 assert(Flag.front() ==
'-');
2628 Flags.push_back(Flag.str());
2630 Flags.push_back((
"!" + Flag.substr(1)).str());
2635 ArgStringList &CmdArgs,
bool IsLTO,
2636 const StringRef PluginOptPrefix) {
2637 auto addArg = [&, IsLTO](
const Twine &Arg) {
2639 assert(!PluginOptPrefix.empty() &&
"Cannot have empty PluginOptPrefix!");
2640 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) + Arg));
2642 CmdArgs.push_back(
"-mllvm");
2643 CmdArgs.push_back(Args.MakeArgString(Arg));
2647 if (Args.hasArg(options::OPT_mbranches_within_32B_boundaries)) {
2648 addArg(Twine(
"-x86-branches-within-32B-boundaries"));
2650 if (
const Arg *A = Args.getLastArg(options::OPT_malign_branch_boundary_EQ)) {
2651 StringRef
Value = A->getValue();
2653 if (
Value.getAsInteger(10, Boundary) || Boundary < 16 ||
2654 !llvm::isPowerOf2_64(Boundary)) {
2655 D.
Diag(diag::err_drv_invalid_argument_to_option)
2656 <<
Value << A->getOption().getName();
2658 addArg(
"-x86-align-branch-boundary=" + Twine(Boundary));
2661 if (
const Arg *A = Args.getLastArg(options::OPT_malign_branch_EQ)) {
2662 std::string AlignBranch;
2663 for (StringRef
T : A->getValues()) {
2664 if (
T !=
"fused" &&
T !=
"jcc" &&
T !=
"jmp" &&
T !=
"call" &&
2665 T !=
"ret" &&
T !=
"indirect")
2666 D.
Diag(diag::err_drv_invalid_malign_branch_EQ)
2667 <<
T <<
"fused, jcc, jmp, call, ret, indirect";
2668 if (!AlignBranch.empty())
2672 addArg(
"-x86-align-branch=" + Twine(AlignBranch));
2674 if (
const Arg *A = Args.getLastArg(options::OPT_mpad_max_prefix_size_EQ)) {
2675 StringRef
Value = A->getValue();
2676 unsigned PrefixSize;
2677 if (
Value.getAsInteger(10, PrefixSize)) {
2678 D.
Diag(diag::err_drv_invalid_argument_to_option)
2679 <<
Value << A->getOption().getName();
2681 addArg(
"-x86-pad-max-prefix-size=" + Twine(PrefixSize));
2707 llvm::opt::ArgStringList &CC1Args,
2709 StringRef Lib, StringRef
Arch, StringRef
Target,
2710 bool isBitCodeSDL) {
2713 std::string LibDeviceLoc =
"/libdevice";
2714 std::string LibBcPrefix =
"/libbc-";
2715 std::string LibPrefix =
"/lib";
2732 for (StringRef
Base : {LibBcPrefix, LibPrefix}) {
2733 const auto *Ext =
Base.contains(LibBcPrefix) ?
".a" :
".bc";
2735 for (
auto Suffix : {Twine(Lib +
"-" +
Arch +
"-" +
Target).str(),
2736 Twine(Lib +
"-" +
Arch).str(), Twine(Lib).str()}) {
2737 SDLs.push_back(Twine(LibDeviceLoc +
Base + Suffix + Ext).str());
2738 SDLs.push_back(Twine(
Base + Suffix + Ext).str());
2748 const auto *Ext =
".a";
2750 for (
auto Suffix : {Twine(Lib +
"-" +
Arch +
"-" +
Target).str(),
2751 Twine(Lib +
"-" +
Arch).str()}) {
2752 SDLs.push_back(Twine(LibDeviceLoc + LibPrefix + Suffix + Ext).str());
2753 SDLs.push_back(Twine(LibPrefix + Suffix + Ext).str());
2764 bool FoundSDL =
false;
2765 for (
auto LPath : LibraryPaths) {
2766 for (
auto SDL : SDLs) {
2767 auto FullName = Twine(LPath + SDL).str();
2768 if (llvm::sys::fs::exists(FullName)) {
2769 CC1Args.push_back(DriverArgs.MakeArgString(FullName));
2786 const InputInfoList &Inputs,
const llvm::opt::ArgList &DriverArgs,
2787 llvm::opt::ArgStringList &CC1Args,
2789 StringRef
Arch, StringRef
Target,
bool isBitCodeSDL) {
2792 if (isBitCodeSDL &&
Arch.contains(
"nvptx"))
2795 bool FoundAOB =
false;
2796 std::string ArchiveOfBundles;
2799 bool IsMSVC = Triple.isWindowsMSVCEnvironment();
2800 auto Ext = IsMSVC ?
".lib" :
".a";
2801 if (!Lib.starts_with(
":") && !Lib.starts_with(
"-l")) {
2802 if (llvm::sys::fs::exists(Lib)) {
2803 ArchiveOfBundles = Lib;
2807 Lib.consume_front(
"-l");
2808 for (
auto LPath : LibraryPaths) {
2809 ArchiveOfBundles.clear();
2810 auto LibFile = (Lib.starts_with(
":") ? Lib.drop_front()
2811 : IsMSVC ? Lib + Ext
2812 :
"lib" + Lib + Ext)
2814 for (
auto Prefix : {
"/libdevice/",
"/"}) {
2815 auto AOB = Twine(LPath + Prefix + LibFile).str();
2816 if (llvm::sys::fs::exists(AOB)) {
2817 ArchiveOfBundles = AOB;
2830 llvm::file_magic Magic;
2831 auto EC = llvm::identify_magic(ArchiveOfBundles, Magic);
2832 if (EC || Magic != llvm::file_magic::archive)
2835 StringRef Prefix = isBitCodeSDL ?
"libbc-" :
"lib";
2836 std::string OutputLib =
2842 C.addTempFile(
C.getArgs().MakeArgString(OutputLib));
2846 DeviceTriple +=
'-';
2847 std::string NormalizedTriple =
2848 T.getToolChain().getEffectiveTriple().normalize(
2849 llvm::Triple::CanonicalForm::FOUR_IDENT);
2850 DeviceTriple += NormalizedTriple;
2852 DeviceTriple +=
'-';
2856 std::string UnbundleArg(
"-unbundle");
2857 std::string TypeArg(
"-type=a");
2858 std::string InputArg(
"-input=" + ArchiveOfBundles);
2859 std::string OffloadArg(
"-targets=" + std::string(DeviceTriple));
2860 std::string OutputArg(
"-output=" + OutputLib);
2862 const char *UBProgram = DriverArgs.MakeArgString(
2863 T.getToolChain().GetProgramPath(
"clang-offload-bundler"));
2865 ArgStringList UBArgs;
2866 UBArgs.push_back(
C.getArgs().MakeArgString(UnbundleArg));
2867 UBArgs.push_back(
C.getArgs().MakeArgString(TypeArg));
2868 UBArgs.push_back(
C.getArgs().MakeArgString(InputArg));
2869 UBArgs.push_back(
C.getArgs().MakeArgString(OffloadArg));
2870 UBArgs.push_back(
C.getArgs().MakeArgString(OutputArg));
2874 std::string AdditionalArgs(
"-allow-missing-bundles");
2875 UBArgs.push_back(
C.getArgs().MakeArgString(AdditionalArgs));
2880 std::string HipCompatibleArgs(
"-hip-openmp-compatible");
2881 UBArgs.push_back(
C.getArgs().MakeArgString(HipCompatibleArgs));
2883 C.addCommand(std::make_unique<Command>(
2885 InputInfo(&JA,
C.getArgs().MakeArgString(OutputLib))));
2887 CC1Args.push_back(DriverArgs.MakeArgString(OutputLib));
2894 const llvm::opt::ArgList &DriverArgs,
2895 llvm::opt::ArgStringList &CC1Args,
2897 bool isBitCodeSDL) {
2928 const llvm::opt::ArgList &DriverArgs,
2929 llvm::opt::ArgStringList &CC1Args,
2931 bool isBitCodeSDL) {
2935 std::optional<std::string> LibPath =
2936 llvm::sys::Process::GetEnv(
"LIBRARY_PATH");
2939 const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator,
'\0'};
2940 llvm::SplitString(*LibPath, Frags, EnvPathSeparatorStr);
2941 for (StringRef Path : Frags)
2942 LibraryPaths.emplace_back(Path.trim());
2946 for (std::string Search_Dir : DriverArgs.getAllArgValues(options::OPT_L))
2947 LibraryPaths.emplace_back(Search_Dir);
2951 llvm::sys::path::append(DefaultLibPath, CLANG_INSTALL_LIBDIR_BASENAME);
2952 LibraryPaths.emplace_back(DefaultLibPath.c_str());
2955 llvm::SmallSet<std::string, 16> SDLNames;
2956 static const StringRef HostOnlyArchives[] = {
2957 "omp",
"cudart",
"m",
"gcc",
"gcc_s",
"pthread",
"hip_hcc"};
2958 for (
auto SDLName : DriverArgs.getAllArgValues(options::OPT_l)) {
2959 if (!llvm::is_contained(HostOnlyArchives, SDLName)) {
2960 SDLNames.insert(std::string(
"-l") + SDLName);
2964 for (
auto Input : DriverArgs.getAllArgValues(options::OPT_INPUT)) {
2971 const StringRef LibFileExt =
".lib";
2972 if (!llvm::sys::path::has_extension(
FileName) ||
2974 llvm::sys::path::extension(
FileName).drop_front()) ==
2976 llvm::sys::path::extension(
FileName) == LibFileExt)
2977 SDLNames.insert(Input);
2984 for (
auto SDLName : SDLNames) {
2995static llvm::opt::Arg *
2997 return Args.getLastArg(options::OPT_mcode_object_version_EQ);
3001 const llvm::opt::ArgList &Args) {
3002 const unsigned MinCodeObjVer = 4;
3003 const unsigned MaxCodeObjVer = 6;
3006 if (CodeObjArg->getOption().getID() ==
3007 options::OPT_mcode_object_version_EQ) {
3008 unsigned CodeObjVer = MaxCodeObjVer;
3010 StringRef(CodeObjArg->getValue()).getAsInteger(0, CodeObjVer);
3011 if (Remnant || CodeObjVer < MinCodeObjVer || CodeObjVer > MaxCodeObjVer)
3012 D.
Diag(diag::err_drv_invalid_int_value)
3013 << CodeObjArg->getAsString(Args) << CodeObjArg->getValue();
3019 const llvm::opt::ArgList &Args) {
3020 unsigned CodeObjVer = 6;
3022 StringRef(CodeObjArg->getValue()).getAsInteger(0, CodeObjVer);
3027 const Driver &D,
const llvm::opt::ArgList &Args) {
3032 const llvm::opt::ArgList &Args,
3033 llvm::opt::ArgStringList &CmdArgs,
3034 const llvm::Triple &Triple,
bool IsLTO,
3035 const StringRef PluginOptPrefix) {
3036 auto addArg = [&, IsLTO](
const Twine &Arg) {
3038 assert(!PluginOptPrefix.empty() &&
"Cannot have empty PluginOptPrefix!");
3039 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) + Arg));
3041 CmdArgs.push_back(
"-mllvm");
3042 CmdArgs.push_back(Args.MakeArgString(Arg));
3046 if (Arg *A = Args.getLastArg(options::OPT_moutline,
3047 options::OPT_mno_outline)) {
3048 if (A->getOption().matches(options::OPT_moutline)) {
3052 if (Triple.isARM() || Triple.isThumb() || Triple.isAArch64() ||
3053 Triple.isRISCV() || Triple.isX86()) {
3054 addArg(Twine(
"-enable-machine-outliner"));
3056 D.
Diag(diag::warn_drv_moutline_unsupported_opt) << Triple.getArchName();
3062 CmdArgs.push_back(
"-mno-outline");
3065 addArg(Twine(
"-enable-machine-outliner=never"));
3069 auto *CodeGenDataGenArg =
3070 Args.getLastArg(options::OPT_fcodegen_data_generate_EQ);
3071 auto *CodeGenDataUseArg = Args.getLastArg(options::OPT_fcodegen_data_use_EQ);
3074 if (CodeGenDataGenArg && CodeGenDataUseArg)
3075 D.
Diag(diag::err_drv_argument_not_allowed_with)
3076 << CodeGenDataGenArg->getAsString(Args)
3077 << CodeGenDataUseArg->getAsString(Args);
3081 if (CodeGenDataGenArg)
3082 addArg(Twine(
"-codegen-data-generate"));
3085 if (CodeGenDataUseArg)
3086 addArg(Twine(
"-codegen-data-use-path=") + CodeGenDataUseArg->getValue());
3090 const llvm::opt::ArgList &DriverArgs,
3091 llvm::opt::ArgStringList &CC1Args,
3092 StringRef BitcodeSuffix,
3093 const llvm::Triple &Triple,
3098 std::optional<std::string> LibPath =
3099 llvm::sys::Process::GetEnv(
"LIBRARY_PATH");
3102 const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator,
'\0'};
3103 llvm::SplitString(*LibPath, Frags, EnvPathSeparatorStr);
3104 for (StringRef Path : Frags)
3105 LibraryPaths.emplace_back(Path.trim());
3110 LibraryPaths.emplace_back(LibPath);
3114 llvm::sys::path::append(P,
"..",
"lib", Triple.getTriple());
3115 LibraryPaths.emplace_back(P);
3117 OptSpecifier LibomptargetBCPathOpt =
3118 Triple.isAMDGCN() ? options::OPT_libomptarget_amdgpu_bc_path_EQ
3119 : Triple.isNVPTX() ? options::OPT_libomptarget_nvptx_bc_path_EQ
3120 : options::OPT_libomptarget_spirv_bc_path_EQ;
3122 StringRef ArchPrefix = Triple.isAMDGCN() ?
"amdgpu"
3123 : Triple.isNVPTX() ?
"nvptx"
3125 std::string LibOmpTargetName = (
"libomptarget-" + ArchPrefix +
".bc").str();
3128 if (
const Arg *A = DriverArgs.getLastArg(LibomptargetBCPathOpt)) {
3130 if (llvm::sys::fs::exists(LibOmpTargetFile) &&
3131 llvm::sys::fs::is_directory(LibOmpTargetFile)) {
3132 llvm::sys::path::append(LibOmpTargetFile, LibOmpTargetName);
3135 if (llvm::sys::fs::exists(LibOmpTargetFile)) {
3136 CC1Args.push_back(
"-mlink-builtin-bitcode");
3137 CC1Args.push_back(DriverArgs.MakeArgString(LibOmpTargetFile));
3139 D.
Diag(diag::err_drv_omp_offload_target_bcruntime_not_found)
3140 << LibOmpTargetFile;
3143 bool FoundBCLibrary =
false;
3145 for (StringRef LibraryPath : LibraryPaths) {
3147 llvm::sys::path::append(LibOmpTargetFile, LibOmpTargetName);
3148 if (llvm::sys::fs::exists(LibOmpTargetFile)) {
3149 CC1Args.push_back(
"-mlink-builtin-bitcode");
3150 CC1Args.push_back(DriverArgs.MakeArgString(LibOmpTargetFile));
3151 FoundBCLibrary =
true;
3156 if (!FoundBCLibrary)
3157 D.
Diag(diag::err_drv_omp_offload_target_missingbcruntime)
3158 << LibOmpTargetName << ArchPrefix;
3163 const llvm::opt::ArgList &DriverArgs,
3164 llvm::opt::ArgStringList &CC1Args) {
3166 StringRef LibclcNamespec;
3167 const Arg *A = DriverArgs.getLastArg(options::OPT_libclc_lib_EQ);
3170 LibclcNamespec = A->getValue();
3172 if (!TT.isAMDGPU() || TT.getEnvironment() != llvm::Triple::LLVM)
3176 if (DriverArgs.hasArg(options::OPT_no_offloadlib,
3177 options::OPT_nodefaultlibs, options::OPT_nostdlib))
3181 bool FilenameSearch = LibclcNamespec.consume_front(
":");
3182 if (FilenameSearch) {
3184 if (D.
getVFS().exists(LibclcFile)) {
3185 CC1Args.push_back(
"-mlink-builtin-bitcode");
3186 CC1Args.push_back(DriverArgs.MakeArgString(LibclcFile));
3189 D.
Diag(diag::err_drv_libclc_not_found) << LibclcFile;
3195 llvm::sys::path::append(BasePath,
"lib");
3200 if (
const Arg *CPUArg = DriverArgs.getLastArg(options::OPT_mcpu_EQ)) {
3201 StringRef CPU = CPUArg->getValue();
3204 llvm::sys::path::append(CPUPath, CPU,
"libclc.bc");
3205 if (D.
getVFS().exists(CPUPath)) {
3206 CC1Args.push_back(
"-mlink-builtin-bitcode");
3207 CC1Args.push_back(DriverArgs.MakeArgString(CPUPath));
3215 llvm::sys::path::append(GenericPath,
"libclc.bc");
3216 if (D.
getVFS().exists(GenericPath)) {
3217 CC1Args.push_back(
"-mlink-builtin-bitcode");
3218 CC1Args.push_back(DriverArgs.MakeArgString(GenericPath));
3222 D.
Diag(diag::err_drv_libclc_not_found) <<
"libclc.bc";
3227 const llvm::opt::ArgList &Args,
3228 llvm::opt::ArgStringList &CmdArgs,
3229 const llvm::Triple &Triple) {
3230 if (Arg *A = Args.getLastArg(options::OPT_moutline_atomics,
3231 options::OPT_mno_outline_atomics)) {
3233 if (!Triple.isAArch64()) {
3234 D.
Diag(diag::warn_drv_moutline_atomics_unsupported_opt)
3235 << Triple.getArchName() << A->getOption().getName();
3237 if (A->getOption().matches(options::OPT_moutline_atomics)) {
3238 CmdArgs.push_back(
"-target-feature");
3239 CmdArgs.push_back(
"+outline-atomics");
3241 CmdArgs.push_back(
"-target-feature");
3242 CmdArgs.push_back(
"-outline-atomics");
3246 CmdArgs.push_back(
"-target-feature");
3247 CmdArgs.push_back(
"+outline-atomics");
3252 llvm::opt::ArgStringList &CmdArgs) {
3253 if (TCArgs.hasFlag(options::OPT_offload_compress,
3254 options::OPT_no_offload_compress,
false))
3255 CmdArgs.push_back(
"--compress");
3256 if (TCArgs.hasArg(options::OPT_v))
3257 CmdArgs.push_back(
"--verbose");
3258 if (
auto *Arg = TCArgs.getLastArg(options::OPT_offload_compression_level_EQ))
3260 TCArgs.MakeArgString(Twine(
"--compression-level=") + Arg->getValue()));
3264 const llvm::Triple &Triple,
3265 const llvm::Reloc::Model &RelocationModel,
3266 llvm::opt::ArgStringList &CmdArgs) {
3267 if (Arg *A = Args.getLastArg(options::OPT_mcmodel_EQ)) {
3268 StringRef CM = A->getValue();
3270 if (Triple.isOSAIX() && CM ==
"medium")
3272 if (Triple.isAArch64(64)) {
3273 Ok = CM ==
"tiny" || CM ==
"small" || CM ==
"large";
3274 if (CM ==
"large" && !Triple.isOSBinFormatMachO() &&
3275 RelocationModel != llvm::Reloc::Static)
3276 D.
Diag(diag::err_drv_argument_only_allowed_with)
3277 << A->getAsString(Args) <<
"-fno-pic";
3278 }
else if (Triple.isLoongArch()) {
3279 if (CM ==
"extreme" &&
3280 Args.hasFlagNoClaim(options::OPT_fplt, options::OPT_fno_plt,
false))
3281 D.
Diag(diag::err_drv_argument_not_allowed_with)
3282 << A->getAsString(Args) <<
"-fplt";
3283 Ok = CM ==
"normal" || CM ==
"medium" || CM ==
"extreme";
3286 CM = llvm::StringSwitch<StringRef>(CM)
3287 .Case(
"normal",
"small")
3288 .Case(
"extreme",
"large")
3290 }
else if (Triple.isPPC64() || Triple.isOSAIX()) {
3291 Ok = CM ==
"small" || CM ==
"medium" || CM ==
"large";
3292 }
else if (Triple.isRISCV()) {
3294 if (CM ==
"large" && RelocationModel != llvm::Reloc::Static)
3295 D.
Diag(diag::err_drv_argument_not_allowed_with)
3296 << A->getAsString(Args) <<
"-fpic";
3299 else if (CM ==
"medany")
3301 Ok = CM ==
"small" || CM ==
"medium" ||
3302 (CM ==
"large" && Triple.isRISCV64());
3303 }
else if (Triple.getArch() == llvm::Triple::x86_64) {
3304 Ok = llvm::is_contained({
"small",
"kernel",
"medium",
"large"}, CM);
3305 }
else if (Triple.isNVPTX() || Triple.isAMDGPU() || Triple.isSPIRV()) {
3309 }
else if (Triple.isSPARC64()) {
3312 else if (CM ==
"medmid")
3314 else if (CM ==
"medany")
3316 Ok = CM ==
"small" || CM ==
"medium" || CM ==
"large";
3317 }
else if (Triple.getArch() == llvm::Triple::lanai) {
3318 Ok = llvm::is_contained({
"small",
"medium",
"large"}, CM);
3321 CmdArgs.push_back(Args.MakeArgString(
"-mcmodel=" + CM));
3323 D.
Diag(diag::err_drv_unsupported_option_argument_for_target)
3324 << A->getSpelling() << CM << Triple.getTriple();
3328 if (Triple.getArch() == llvm::Triple::x86_64) {
3329 bool IsMediumCM =
false;
3330 bool IsLargeCM =
false;
3331 if (Arg *A = Args.getLastArg(options::OPT_mcmodel_EQ)) {
3332 IsMediumCM = StringRef(A->getValue()) ==
"medium";
3333 IsLargeCM = StringRef(A->getValue()) ==
"large";
3335 if (Arg *A = Args.getLastArg(options::OPT_mlarge_data_threshold_EQ)) {
3336 if (!IsMediumCM && !IsLargeCM) {
3337 D.
Diag(diag::warn_drv_large_data_threshold_invalid_code_model)
3338 << A->getOption().getRenderName();
3340 A->render(Args, CmdArgs);
3342 }
else if (IsMediumCM) {
3343 CmdArgs.push_back(
"-mlarge-data-threshold=65536");
3344 }
else if (IsLargeCM) {
3345 CmdArgs.push_back(
"-mlarge-data-threshold=0");
3351 ArgStringList &CmdArgs) {
3356 Args.getLastArg(options::OPT_fcolor_diagnostics,
3357 options::OPT_fno_color_diagnostics);
3358 if (
const Arg *A = Args.getLastArg(options::OPT_fdiagnostics_color_EQ)) {
3359 StringRef
Value(A->getValue());
3361 D.
Diag(diag::err_drv_invalid_argument_to_option)
3362 <<
Value << A->getOption().getName();
3367 CmdArgs.push_back(
"-fcolor-diagnostics");
3370 CmdArgs.push_back(
"-fno-color-diagnostics");
3379 for (; *Arg; ++Arg) {
3385 Res.push_back(
'\\');
3388 Res.push_back(*Arg);
3393 const llvm::opt::ArgList &Args) {
3397 llvm::opt::ArgStringList OriginalArgs;
3398 for (
const auto &Arg : Args)
3399 Arg->render(Args, OriginalArgs);
3403 for (
const char *OriginalArg : OriginalArgs) {
3407 Flags += EscapedArg;
3410 return Args.MakeArgString(Flags);
3414 const llvm::opt::ArgList &Args,
3415 bool &FRecordCommandLine,
3416 bool &GRecordCommandLine,
3417 bool &DXRecordCommandLine) {
3420 const std::string &TripleStr = Triple.getTriple();
3422 FRecordCommandLine =
3423 Args.hasFlag(options::OPT_frecord_command_line,
3424 options::OPT_fno_record_command_line,
false);
3425 GRecordCommandLine =
3426 Args.hasFlag(options::OPT_grecord_command_line,
3427 options::OPT_gno_record_command_line,
false);
3428 DXRecordCommandLine = Triple.isDXIL() && Args.hasArg(options::OPT_g_Flag);
3429 if (FRecordCommandLine && !Triple.isOSBinFormatELF() &&
3430 !Triple.isOSBinFormatXCOFF() && !Triple.isOSBinFormatMachO())
3431 D.
Diag(diag::err_drv_unsupported_opt_for_target)
3432 << Args.getLastArg(options::OPT_frecord_command_line)->getAsString(Args)
3436 DXRecordCommandLine;
3440 ArgStringList &CmdArgs,
3441 const llvm::Triple &Triple) {
3442 if (Arg *A = Args.getLastArg(options::OPT_fglobal_isel,
3443 options::OPT_fno_global_isel)) {
3444 CmdArgs.push_back(
"-mllvm");
3445 if (A->getOption().matches(options::OPT_fglobal_isel)) {
3446 CmdArgs.push_back(
"-global-isel=1");
3451 bool IsArchSupported = Triple.getArch() == llvm::Triple::aarch64;
3452 bool IsOptLevelSupported =
false;
3454 Arg *A = Args.getLastArg(options::OPT_O_Group);
3455 if (IsArchSupported) {
3456 if (!A || A->getOption().matches(options::OPT_O0))
3457 IsOptLevelSupported =
true;
3459 if (!IsArchSupported || !IsOptLevelSupported) {
3460 CmdArgs.push_back(
"-mllvm");
3461 CmdArgs.push_back(
"-global-isel-abort=2");
3463 if (!IsArchSupported)
3464 D.
Diag(diag::warn_drv_global_isel_incomplete) << Triple.getArchName();
3466 D.
Diag(diag::warn_drv_global_isel_incomplete_opt);
3469 CmdArgs.push_back(
"-global-isel=0");
3475 ArgStringList &CmdArgs,
3476 bool IsMSVCCompat) {
3477 bool use_fwrapv = IsMSVCCompat;
3478 bool use_fwrapv_pointer =
false;
3479 for (
const Arg *A : Args.filtered(
3480 options::OPT_fstrict_overflow, options::OPT_fno_strict_overflow,
3481 options::OPT_fwrapv, options::OPT_fno_wrapv,
3482 options::OPT_fwrapv_pointer, options::OPT_fno_wrapv_pointer)) {
3484 switch (A->getOption().getID()) {
3485 case options::OPT_fstrict_overflow:
3487 use_fwrapv_pointer =
false;
3489 case options::OPT_fno_strict_overflow:
3491 use_fwrapv_pointer =
true;
3493 case options::OPT_fwrapv:
3496 case options::OPT_fno_wrapv:
3499 case options::OPT_fwrapv_pointer:
3500 use_fwrapv_pointer =
true;
3502 case options::OPT_fno_wrapv_pointer:
3503 use_fwrapv_pointer =
false;
3509 CmdArgs.push_back(
"-fwrapv");
3510 if (!use_fwrapv && IsMSVCCompat)
3511 CmdArgs.push_back(
"-fno-wrapv");
3512 if (use_fwrapv_pointer)
3513 CmdArgs.push_back(
"-fwrapv-pointer");
3520 if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
3521 if (A->getOption().matches(options::OPT_O4) ||
3522 A->getOption().matches(options::OPT_Ofast))
3525 if (A->getOption().matches(options::OPT_O0))
3528 assert(A->getOption().matches(options::OPT_O) &&
"Must have a -O flag");
3531 StringRef S(A->getValue());
3539 unsigned OptLevel = 0;
3540 if (S.getAsInteger(10, OptLevel))
3543 return OptLevel > 1;
3550 ArgStringList &CmdArgs) {
3552 if (Args.hasFlag(options::OPT_fvectorize, options::OPT_fno_vectorize,
3554 CmdArgs.push_back(
"-vectorize-loops");
3558 ArgStringList &CmdArgs) {
3560 if (Args.hasFlag(options::OPT_fslp_vectorize, options::OPT_fno_slp_vectorize,
3562 CmdArgs.push_back(
"-vectorize-slp");
3566 ArgStringList &CmdArgs) {
3567 if (Args.hasFlag(options::OPT_floop_interchange,
3568 options::OPT_fno_loop_interchange,
false))
3569 CmdArgs.push_back(
"-floop-interchange");
3590 llvm_unreachable(
"Fully covered switch above");
3596 if (!ComplexRangeStr.empty())
3597 return "-complex-range=" + ComplexRangeStr;
3598 return ComplexRangeStr;
3618 if (LastOpt == NewOpt || NewOpt.empty() || LastOpt.empty() ||
3619 (LastOpt ==
"-fcx-limited-range" && NewOpt ==
"-fno-cx-limited-range") ||
3620 (LastOpt ==
"-fno-cx-limited-range" && NewOpt ==
"-fcx-limited-range") ||
3621 (LastOpt ==
"-fcx-fortran-rules" && NewOpt ==
"-fno-cx-fortran-rules") ||
3622 (LastOpt ==
"-fno-cx-fortran-rules" && NewOpt ==
"-fcx-fortran-rules") ||
3623 (LastOpt ==
"-ffast-math" && NewOpt ==
"-fno-fast-math") ||
3624 (LastOpt.starts_with(
"-ffp-model=") && NewOpt ==
"-ffast-math") ||
3625 (LastOpt.starts_with(
"-ffp-model=") && NewOpt ==
"-fno-fast-math") ||
3626 (LastOpt.starts_with(
"-ffp-model=") &&
3627 NewOpt.starts_with(
"-ffp-model=")) ||
3628 (LastOpt.starts_with(
"-fcomplex-arithmetic=") &&
3629 NewOpt.starts_with(
"-fcomplex-arithmetic=")))
3632 D.
Diag(clang::diag::warn_drv_overriding_complex_range)
3652 const ArgStringList &LinkerInputs,
3654 const llvm::opt::ArgList &Args,
3655 const char *OutputFilename) {
3659 assert(!LinkerInputs.empty() && !JobInputs.empty() &&
3660 "Must have at least one input.");
3662 ArgStringList LlvmLinkArgs(
3663 {
"-o", OutputFilename ? OutputFilename : Output.
getFilename()});
3665 LlvmLinkArgs.append(LinkerInputs);
3668 const char *LlvmLink = Args.MakeArgString(TC.
GetProgramPath(
"llvm-link"));
3670 LlvmLink, LlvmLinkArgs, JobInputs,
static bool useLeafFramePointerForTargetByDefault(const llvm::Triple &Triple)
static unsigned ParseDebugDefaultVersion(const ToolChain &TC, const ArgList &Args)
static void getWebAssemblyTargetFeatures(const Driver &D, const llvm::Triple &Triple, const ArgList &Args, std::vector< StringRef > &Features)
static void emitComplexRangeDiag(const Driver &D, StringRef LastOpt, LangOptions::ComplexRangeKind Range, StringRef NewOpt, LangOptions::ComplexRangeKind NewRange)
static bool addSanitizerDynamicList(const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs, StringRef Sanitizer)
static bool mustMaintainValidFrameChain(const llvm::opt::ArgList &Args, const llvm::Triple &Triple)
static llvm::opt::Arg * getAMDGPUCodeObjectArgument(const Driver &D, const llvm::opt::ArgList &Args)
static void collectSanitizerRuntimes(const ToolChain &TC, const ArgList &Args, SmallVectorImpl< StringRef > &SharedRuntimes, SmallVectorImpl< StringRef > &StaticRuntimes, SmallVectorImpl< StringRef > &NonWholeStaticRuntimes, SmallVectorImpl< StringRef > &HelperStaticRuntimes, SmallVectorImpl< StringRef > &RequiredSymbols)
static void addSanitizerRuntime(const ToolChain &TC, const ArgList &Args, ArgStringList &CmdArgs, StringRef Sanitizer, bool IsShared, bool IsWhole)
static void AddUnwindLibrary(const ToolChain &TC, const Driver &D, ArgStringList &CmdArgs, const ArgList &Args)
static bool SDLSearch(const Driver &D, const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, const SmallVectorImpl< std::string > &LibraryPaths, StringRef Lib, StringRef Arch, StringRef Target, bool isBitCodeSDL)
SDLSearch: Search for Static Device Library The search for SDL bitcode files is consistent with how s...
static StringRef getAMDGPUTargetGPU(const llvm::Triple &T, const ArgList &Args)
Get the (LLVM) name of the AMDGPU gpu we are targeting.
static void renderRpassOptions(const ArgList &Args, ArgStringList &CmdArgs, const StringRef PluginOptPrefix)
static StringRef getWebAssemblyTargetCPU(const ArgList &Args)
Get the (LLVM) name of the WebAssembly cpu we are targeting.
static bool framePointerImpliesLeafFramePointer(const llvm::opt::ArgList &Args, const llvm::Triple &Triple)
static void renderRemarksHotnessOptions(const ArgList &Args, ArgStringList &CmdArgs, const StringRef PluginOptPrefix)
static void GetSDLFromOffloadArchive(Compilation &C, const Driver &D, const Tool &T, const JobAction &JA, const InputInfoList &Inputs, const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, const SmallVectorImpl< std::string > &LibraryPaths, StringRef Lib, StringRef Arch, StringRef Target, bool isBitCodeSDL)
Search if a user provided archive file lib<libname>.a exists in any of the library paths.
static std::string getLanaiTargetCPU(const ArgList &Args)
static void renderRemarksOptions(const ArgList &Args, ArgStringList &CmdArgs, const llvm::Triple &Triple, const InputInfo &Input, const InputInfo &Output, const StringRef PluginOptPrefix)
static bool useFramePointerForTargetByDefault(const llvm::opt::ArgList &Args, const llvm::Triple &Triple)
static void AddLibgcc(const ToolChain &TC, const Driver &D, ArgStringList &CmdArgs, const ArgList &Args)
static LibGccType getLibGccType(const ToolChain &TC, const Driver &D, const ArgList &Args)
clang::CodeGenOptions::FramePointerKind getFramePointerKind(const llvm::opt::ArgList &Args, const llvm::Triple &Triple)
static bool mustUseNonLeafFramePointerForTarget(const llvm::Triple &Triple)
static bool shouldIgnoreUnsupportedTargetFeature(const Arg &TargetFeatureArg, llvm::Triple T, StringRef Processor)
llvm::MachO::Target Target
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
DiagnosticOptions & getDiagnosticOptions() const
Retrieve the diagnostic options.
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_Promoted
Implementation of complex division using algebraic formulas at higher precision.
@ CX_None
No range rule is enabled.
@ CX_Improved
Implementation of complex division offering an improved handling for overflow in intermediate calcula...
BoundArch getOffloadingArch() const
static StringRef GetOffloadKindName(OffloadKind Kind)
Return a string containing a offload kind name.
OffloadKind getOffloadingDeviceKind() const
bool isHostOffloading(unsigned int OKind) const
Check if this action have any offload kinds.
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...
std::string CCPrintInternalStatReportFilename
The file to log CC_PRINT_INTERNAL_STAT_FILE output to, if enabled.
DiagnosticsEngine & getDiags() const
const char * getPrependArg() const
OpenMPRuntimeKind getOpenMPRuntime(const llvm::opt::ArgList &Args) const
Compute the desired OpenMP runtime from the flags provided.
DiagnosticBuilder Diag(unsigned DiagID) const
unsigned CCPrintInternalStats
Set CC_PRINT_INTERNAL_STAT mode, which causes the driver to dump internal performance report to CC_PR...
const llvm::opt::OptTable & getOpts() const
const char * getDriverProgramPath() const
Get the path to the main driver executable.
std::string ResourceDir
The path to the compiler resource directory.
llvm::vfs::FileSystem & getVFS() const
std::string GetTemporaryPath(StringRef Prefix, StringRef Suffix) const
GetTemporaryPath - Return the pathname of a temporary file to use as part of compilation; the file wi...
std::string Dir
The path the driver executable was in, as invoked from the command line.
@ OMPRT_IOMP5
The legacy name for the LLVM OpenMP runtime from when it was the Intel OpenMP runtime.
@ OMPRT_OMP
The LLVM OpenMP runtime.
@ OMPRT_Unknown
An unknown OpenMP runtime.
@ OMPRT_GOMP
The GNU OpenMP runtime.
std::string getTargetTriple() const
bool IsFlangMode() const
Whether the driver should invoke flang for fortran inputs.
bool CCCIsCXX() const
Whether the driver should follow g++ like behavior.
This corresponds to a single GCC Multilib, or a segment of one controlled by a command line flag.
std::vector< std::string > flags_list
bool needsFuzzerInterceptors() const
bool needsHwasanAliasesRt() const
bool needsStatsRt() const
bool needsMemProfRt() const
bool linkRuntimes() const
bool needsUbsanLoopDetectRt() const
bool needsUbsanRt() const
bool needsHwasanRt() const
bool hasCrossDsoCfi() const
bool needsCfiCrossDsoDiagRt() const
bool hasMemtagHeap() const
bool needsSafeStackRt() const
bool needsRtsanRt() const
bool requiresMinimalRuntime() const
bool hasMemtagStack() const
bool needsDfsanRt() const
bool needsScudoRt() const
bool needsUbsanCXXRt() const
bool needsCfiCrossDsoRt() const
const std::string & getMemtagMode() const
bool needsSharedRt() const
bool needsTysanRt() const
bool linkCXXRuntimes() const
bool needsXRayDSORt() const
llvm::ArrayRef< std::string > modeList() const
bool isLLVMIR(ID Id)
Is this LLVM IR.
ID lookupTypeForExtension(llvm::StringRef Ext)
lookupTypeForExtension - Lookup the type to use for the file extension Ext.
SmallVector< InputInfo, 4 > InputInfoList
bool willEmitRemarks(const llvm::opt::ArgList &Args)
Top level wrappers for InstallAPI frontend operations.
llvm::StringRef getProcessorFromTargetID(const llvm::Triple &T, llvm::StringRef OffloadArch)
Get processor name from target ID.
unsigned getOptimizationLevel(const llvm::opt::ArgList &Args, InputKind IK, DiagnosticsEngine &Diags)
const FunctionProtoType * T
@ Auto
Emit colors only if the output stream is detected to support them.
@ On
Always emit colors regardless of the output stream.
@ Off
Never emit colors regardless of the output stream.
static constexpr ResponseFileSupport None()
Returns a ResponseFileSupport indicating that response files are not supported.
static constexpr ResponseFileSupport AtFileCurCP()