31#include "clang/Config/config.h"
43#include "llvm/ADT/STLExtras.h"
44#include "llvm/ADT/SmallSet.h"
45#include "llvm/ADT/SmallString.h"
46#include "llvm/ADT/StringExtras.h"
47#include "llvm/ADT/StringSwitch.h"
48#include "llvm/ADT/Twine.h"
49#include "llvm/BinaryFormat/Magic.h"
50#include "llvm/Config/llvm-config.h"
51#include "llvm/Option/Arg.h"
52#include "llvm/Option/ArgList.h"
53#include "llvm/Option/Option.h"
54#include "llvm/Support/CodeGen.h"
55#include "llvm/Support/Compression.h"
56#include "llvm/Support/Debug.h"
57#include "llvm/Support/ErrorHandling.h"
58#include "llvm/Support/FileSystem.h"
59#include "llvm/Support/Path.h"
60#include "llvm/Support/Process.h"
61#include "llvm/Support/Program.h"
62#include "llvm/Support/ScopedPrinter.h"
63#include "llvm/Support/Threading.h"
64#include "llvm/Support/VirtualFileSystem.h"
65#include "llvm/Support/YAMLParser.h"
66#include "llvm/TargetParser/Host.h"
67#include "llvm/TargetParser/PPCTargetParser.h"
68#include "llvm/TargetParser/TargetParser.h"
77 const llvm::Triple &Triple) {
78 if (Args.hasArg(clang::driver::options::OPT_pg) &&
79 !Args.hasArg(clang::driver::options::OPT_mfentry))
82 if (Triple.isAndroid())
85 switch (Triple.getArch()) {
86 case llvm::Triple::xcore:
87 case llvm::Triple::wasm32:
88 case llvm::Triple::wasm64:
89 case llvm::Triple::msp430:
93 case llvm::Triple::ppc:
94 case llvm::Triple::ppcle:
95 case llvm::Triple::ppc64:
96 case llvm::Triple::ppc64le:
97 case llvm::Triple::riscv32:
98 case llvm::Triple::riscv64:
99 case llvm::Triple::sparc:
100 case llvm::Triple::sparcel:
101 case llvm::Triple::sparcv9:
102 case llvm::Triple::amdgcn:
103 case llvm::Triple::r600:
104 case llvm::Triple::csky:
105 case llvm::Triple::loongarch32:
106 case llvm::Triple::loongarch64:
107 case llvm::Triple::m68k:
113 if (Triple.isOSFuchsia() || Triple.isOSNetBSD()) {
117 if (Triple.isOSLinux() || Triple.isOSHurd()) {
118 switch (Triple.getArch()) {
120 case llvm::Triple::arm:
121 case llvm::Triple::armeb:
122 case llvm::Triple::thumb:
123 case llvm::Triple::thumbeb:
124 case llvm::Triple::mips64:
125 case llvm::Triple::mips64el:
126 case llvm::Triple::mips:
127 case llvm::Triple::mipsel:
128 case llvm::Triple::systemz:
129 case llvm::Triple::x86:
130 case llvm::Triple::x86_64:
137 if (Triple.isOSWindows()) {
138 switch (Triple.getArch()) {
139 case llvm::Triple::x86:
141 case llvm::Triple::x86_64:
142 return Triple.isOSBinFormatMachO();
143 case llvm::Triple::arm:
144 case llvm::Triple::thumb:
158 if (Triple.isAArch64() || Triple.isPS() || Triple.isVE() ||
159 (Triple.isAndroid() && !Triple.isARM()))
166 switch (Triple.getArch()) {
169 case llvm::Triple::arm:
170 case llvm::Triple::thumb:
173 return Triple.isOSDarwin();
180 const llvm::Triple &Triple) {
181 if (Triple.isARM() || Triple.isThumb()) {
185 if (Arg *A = Args.getLastArg(options::OPT_mframe_chain)) {
186 StringRef
V = A->getValue();
197 const llvm::Triple &Triple) {
198 if (Triple.isARM() || Triple.isThumb()) {
202 if (Arg *A = Args.getLastArg(options::OPT_mframe_chain)) {
203 StringRef
V = A->getValue();
204 return V ==
"aapcs+leaf";
213 const llvm::Triple &Triple) {
243 Args.hasFlag(clang::driver::options::OPT_fno_omit_frame_pointer,
244 clang::driver::options::OPT_fomit_frame_pointer, DefaultFP);
249 bool EnableLeafFP = Args.hasFlag(
250 clang::driver::options::OPT_mno_omit_leaf_frame_pointer,
251 clang::driver::options::OPT_momit_leaf_frame_pointer, DefaultLeafFP);
266 const StringRef PluginOptPrefix) {
267 if (
const Arg *A = Args.getLastArg(options::OPT_Rpass_EQ))
268 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) +
269 "-pass-remarks=" + A->getValue()));
271 if (
const Arg *A = Args.getLastArg(options::OPT_Rpass_missed_EQ))
272 CmdArgs.push_back(Args.MakeArgString(
273 Twine(PluginOptPrefix) +
"-pass-remarks-missed=" + A->getValue()));
275 if (
const Arg *A = Args.getLastArg(options::OPT_Rpass_analysis_EQ))
276 CmdArgs.push_back(Args.MakeArgString(
277 Twine(PluginOptPrefix) +
"-pass-remarks-analysis=" + A->getValue()));
281 const llvm::Triple &Triple,
284 const StringRef PluginOptPrefix) {
285 StringRef Format =
"yaml";
286 if (
const Arg *A = Args.getLastArg(options::OPT_fsave_optimization_record_EQ))
287 Format = A->getValue();
290 const Arg *A = Args.getLastArg(options::OPT_foptimization_record_file_EQ);
296 assert(!F.empty() &&
"Cannot determine remarks output name.");
298 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) +
299 "opt-remarks-filename=" + F +
300 ".opt.ld." + Format));
303 Args.getLastArg(options::OPT_foptimization_record_passes_EQ))
304 CmdArgs.push_back(Args.MakeArgString(
305 Twine(PluginOptPrefix) +
"opt-remarks-passes=" + A->getValue()));
307 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) +
308 "opt-remarks-format=" + Format.data()));
312 ArgStringList &CmdArgs,
313 const StringRef PluginOptPrefix) {
314 if (Args.hasFlag(options::OPT_fdiagnostics_show_hotness,
315 options::OPT_fno_diagnostics_show_hotness,
false))
316 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) +
317 "opt-remarks-with-hotness"));
320 Args.getLastArg(options::OPT_fdiagnostics_hotness_threshold_EQ))
322 Args.MakeArgString(Twine(PluginOptPrefix) +
323 "opt-remarks-hotness-threshold=" + A->getValue()));
328 StringRef Processor) {
332 auto GPUKind =
T.isAMDGCN() ? llvm::AMDGPU::parseArchAMDGCN(Processor)
333 : llvm::AMDGPU::parseArchR600(Processor);
334 auto GPUFeatures =
T.isAMDGCN() ? llvm::AMDGPU::getArchAttrAMDGCN(GPUKind)
335 : llvm::AMDGPU::getArchAttrR600(GPUKind);
336 if (GPUFeatures & llvm::AMDGPU::FEATURE_WGP)
338 return TargetFeatureArg.getOption().matches(options::OPT_mno_cumode);
343 if (
D.getVFS().exists(
Path))
344 Paths.push_back(
Path.str());
348 const llvm::Triple &Triple,
350 std::vector<StringRef> &Features,
351 OptSpecifier Group) {
352 std::set<StringRef> Warned;
353 for (
const Arg *A : Args.filtered(Group)) {
354 StringRef Name = A->getOption().getName();
358 assert(Name.starts_with(
"m") &&
"Invalid feature name.");
359 Name = Name.substr(1);
363 if (Warned.count(Name) == 0) {
365 clang::diag::warn_drv_unsupported_option_for_processor)
366 << A->getAsString(Args) << Proc;
372 bool IsNegative = Name.consume_front(
"no-");
374 Features.push_back(Args.MakeArgString((IsNegative ?
"-" :
"+") + Name));
382 llvm::DenseSet<StringRef> UsedFeatures;
383 for (StringRef Feature : llvm::reverse(Features)) {
384 if (UsedFeatures.insert(Feature.drop_front()).second)
385 UnifiedFeatures.insert(UnifiedFeatures.begin(), Feature);
388 return UnifiedFeatures;
392 const char *ArgName,
const char *EnvVar) {
393 const char *DirList = ::getenv(EnvVar);
394 bool CombinedArg =
false;
399 StringRef Name(ArgName);
400 if (Name ==
"-I" || Name ==
"-L" || Name.empty())
403 StringRef Dirs(DirList);
407 StringRef::size_type Delim;
408 while ((Delim = Dirs.find(llvm::sys::EnvPathSeparator)) != StringRef::npos) {
411 CmdArgs.push_back(Args.MakeArgString(std::string(ArgName) +
"."));
413 CmdArgs.push_back(ArgName);
414 CmdArgs.push_back(
".");
419 Args.MakeArgString(std::string(ArgName) + Dirs.substr(0, Delim)));
421 CmdArgs.push_back(ArgName);
422 CmdArgs.push_back(Args.MakeArgString(Dirs.substr(0, Delim)));
425 Dirs = Dirs.substr(Delim + 1);
430 CmdArgs.push_back(Args.MakeArgString(std::string(ArgName) +
"."));
432 CmdArgs.push_back(ArgName);
433 CmdArgs.push_back(
".");
437 CmdArgs.push_back(Args.MakeArgString(std::string(ArgName) + Dirs));
439 CmdArgs.push_back(ArgName);
440 CmdArgs.push_back(Args.MakeArgString(Dirs));
446 const ArgList &Args, ArgStringList &CmdArgs,
452 Args.AddAllArgValues(CmdArgs, options::OPT_Zlinker_input);
459 for (
const auto &II : Inputs) {
463 if (
auto *IA = II.getAction())
473 if (II.isFilename()) {
474 CmdArgs.push_back(II.getFilename());
483 const Arg &A = II.getInputArg();
486 if (A.getOption().matches(options::OPT_Z_reserved_lib_stdcxx))
488 else if (A.getOption().matches(options::OPT_Z_reserved_lib_cckext))
491 A.renderAsInput(Args, CmdArgs);
496 const ToolChain &TC,
const llvm::opt::ArgList &Args,
497 llvm::opt::ArgStringList &CmdArgs) {
503 if (
const Arg *A = Args.getLastArg(options::OPT_gz_EQ)) {
504 StringRef
V = A->getValue();
505 if (
V ==
"none" ||
V ==
"zlib" ||
V ==
"zstd")
506 CmdArgs.push_back(Args.MakeArgString(
"--compress-debug-sections=" +
V));
508 TC.
getDriver().
Diag(diag::err_drv_unsupported_option_argument)
509 << A->getSpelling() <<
V;
514 llvm::opt::ArgStringList &CmdArgs) {
515 if (Args.hasArg(options::OPT_nostdlib, options::OPT_r,
516 options::OPT_nodefaultlibs, options::OPT_nolibc,
517 options::OPT_nogpulibc))
524 CmdArgs.push_back(
"-lc");
525 CmdArgs.push_back(
"-lm");
530 std::vector<StringRef> &Features,
531 OptSpecifier OnOpt, OptSpecifier OffOpt,
532 StringRef FeatureName) {
533 if (Arg *A = Args.getLastArg(OnOpt, OffOpt)) {
534 if (A->getOption().matches(OnOpt))
535 Features.push_back(Args.MakeArgString(
"+" + FeatureName));
537 Features.push_back(Args.MakeArgString(
"-" + FeatureName));
543 const ArgList &Args) {
544 Arg *MArch = Args.getLastArg(options::OPT_march_EQ);
545 if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) {
547 return llvm::StringSwitch<std::string>(GPUName)
548 .Cases(
"rv630",
"rv635",
"r600")
549 .Cases(
"rv610",
"rv620",
"rs780",
"rs880")
550 .Case(
"rv740",
"rv770")
551 .Case(
"palm",
"cedar")
552 .Cases(
"sumo",
"sumo2",
"sumo")
553 .Case(
"hemlock",
"cypress")
554 .Case(
"aruba",
"cayman")
555 .Default(GPUName.str());
563 if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) {
564 return A->getValue();
572 if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) {
573 StringRef CPU = A->getValue();
579 return llvm::sys::getHostCPUName();
589 const llvm::Triple &
T,
bool FromAs) {
592 switch (
T.getArch()) {
596 case llvm::Triple::aarch64:
597 case llvm::Triple::aarch64_32:
598 case llvm::Triple::aarch64_be:
601 case llvm::Triple::arm:
602 case llvm::Triple::armeb:
603 case llvm::Triple::thumb:
604 case llvm::Triple::thumbeb: {
605 StringRef MArch, MCPU;
610 case llvm::Triple::avr:
611 if (
const Arg *A = Args.getLastArg(options::OPT_mmcu_EQ))
612 return A->getValue();
615 case llvm::Triple::m68k:
618 case llvm::Triple::mips:
619 case llvm::Triple::mipsel:
620 case llvm::Triple::mips64:
621 case llvm::Triple::mips64el: {
625 return std::string(CPUName);
628 case llvm::Triple::nvptx:
629 case llvm::Triple::nvptx64:
630 if (
const Arg *A = Args.getLastArg(options::OPT_march_EQ))
631 return A->getValue();
634 case llvm::Triple::ppc:
635 case llvm::Triple::ppcle:
636 case llvm::Triple::ppc64:
637 case llvm::Triple::ppc64le:
638 if (Arg *A = Args.getLastArg(clang::driver::options::OPT_mcpu_EQ))
640 llvm::PPC::getNormalizedPPCTargetCPU(
T, A->getValue()));
641 return std::string(llvm::PPC::getNormalizedPPCTargetCPU(
T));
643 case llvm::Triple::csky:
644 if (
const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
645 return A->getValue();
646 else if (
const Arg *A = Args.getLastArg(options::OPT_march_EQ))
647 return A->getValue();
650 case llvm::Triple::riscv32:
651 case llvm::Triple::riscv64:
654 case llvm::Triple::bpfel:
655 case llvm::Triple::bpfeb:
656 if (
const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
657 return A->getValue();
660 case llvm::Triple::sparc:
661 case llvm::Triple::sparcel:
662 case llvm::Triple::sparcv9:
665 case llvm::Triple::x86:
666 case llvm::Triple::x86_64:
669 case llvm::Triple::hexagon:
673 case llvm::Triple::lanai:
676 case llvm::Triple::systemz:
679 case llvm::Triple::r600:
680 case llvm::Triple::amdgcn:
683 case llvm::Triple::wasm32:
684 case llvm::Triple::wasm64:
687 case llvm::Triple::loongarch32:
688 case llvm::Triple::loongarch64:
694 const llvm::Triple &Triple,
696 std::vector<StringRef> &Features) {
698 options::OPT_m_wasm_Features_Group);
702 const ArgList &Args, ArgStringList &CmdArgs,
703 bool ForAS,
bool IsAux) {
704 std::vector<StringRef> Features;
705 switch (Triple.getArch()) {
708 case llvm::Triple::mips:
709 case llvm::Triple::mipsel:
710 case llvm::Triple::mips64:
711 case llvm::Triple::mips64el:
714 case llvm::Triple::arm:
715 case llvm::Triple::armeb:
716 case llvm::Triple::thumb:
717 case llvm::Triple::thumbeb:
720 case llvm::Triple::ppc:
721 case llvm::Triple::ppcle:
722 case llvm::Triple::ppc64:
723 case llvm::Triple::ppc64le:
726 case llvm::Triple::riscv32:
727 case llvm::Triple::riscv64:
730 case llvm::Triple::systemz:
733 case llvm::Triple::aarch64:
734 case llvm::Triple::aarch64_32:
735 case llvm::Triple::aarch64_be:
738 case llvm::Triple::x86:
739 case llvm::Triple::x86_64:
742 case llvm::Triple::hexagon:
745 case llvm::Triple::wasm32:
746 case llvm::Triple::wasm64:
749 case llvm::Triple::sparc:
750 case llvm::Triple::sparcel:
751 case llvm::Triple::sparcv9:
754 case llvm::Triple::r600:
755 case llvm::Triple::amdgcn:
758 case llvm::Triple::nvptx:
759 case llvm::Triple::nvptx64:
762 case llvm::Triple::m68k:
765 case llvm::Triple::msp430:
768 case llvm::Triple::ve:
771 case llvm::Triple::csky:
774 case llvm::Triple::loongarch32:
775 case llvm::Triple::loongarch64:
781 CmdArgs.push_back(IsAux ?
"-aux-target-feature" :
"-target-feature");
782 CmdArgs.push_back(Feature.data());
787 Arg *LtoJobsArg = Args.getLastArg(options::OPT_flto_jobs_EQ);
790 if (!llvm::get_threadpool_strategy(LtoJobsArg->getValue()))
791 D.Diag(diag::err_drv_invalid_int_value)
792 << LtoJobsArg->getAsString(Args) << LtoJobsArg->getValue();
793 return LtoJobsArg->getValue();
798 return Triple.isPS();
802 const llvm::opt::ArgList &Args) {
804 Arg *A = Args.getLastArg(options::OPT_mtls_dialect_EQ);
806 return Triple.hasDefaultTLSDESC();
807 StringRef
V = A->getValue();
808 bool SupportedArgument =
false, EnableTLSDESC =
false;
809 bool Unsupported = !Triple.isOSBinFormatELF();
810 if (Triple.isLoongArch() || Triple.isRISCV()) {
811 SupportedArgument =
V ==
"desc" ||
V ==
"trad";
812 EnableTLSDESC =
V ==
"desc";
813 }
else if (Triple.isX86()) {
814 SupportedArgument =
V ==
"gnu" ||
V ==
"gnu2";
815 EnableTLSDESC =
V ==
"gnu2";
820 TC.
getDriver().
Diag(diag::err_drv_unsupported_opt_for_target)
821 << A->getSpelling() << Triple.getTriple();
822 }
else if (!SupportedArgument) {
823 TC.
getDriver().
Diag(diag::err_drv_unsupported_option_argument_for_target)
824 << A->getSpelling() <<
V << Triple.getTriple();
826 return EnableTLSDESC;
830 ArgStringList &CmdArgs,
const InputInfo &Output,
831 const InputInfo &Input,
bool IsThinLTO) {
833 const bool IsOSAIX = Triple.isOSAIX();
834 const bool IsAMDGCN = Triple.isAMDGCN();
837 const bool IsFatLTO = Args.hasArg(options::OPT_ffat_lto_objects);
838 const bool IsUnifiedLTO = Args.hasArg(options::OPT_funified_lto);
839 if (llvm::sys::path::filename(Linker) !=
"ld.lld" &&
840 llvm::sys::path::stem(Linker) !=
"ld.lld" && !Triple.isOSOpenBSD()) {
844 const char *PluginPrefix = IsOSAIX ?
"-bplugin:" :
"";
845 const char *PluginName = IsOSAIX ?
"/libLTO" :
"/LLVMgold";
848 CmdArgs.push_back(
"-plugin");
851 const char *Suffix =
".dll";
852#elif defined(__APPLE__)
853 const char *Suffix =
".dylib";
855 const char *Suffix =
".so";
859 llvm::sys::path::native(Twine(
D.Dir) +
860 "/../" CLANG_INSTALL_LIBDIR_BASENAME +
863 CmdArgs.push_back(Args.MakeArgString(Twine(PluginPrefix) + Plugin));
868 CmdArgs.push_back(
"--fat-lto-objects");
871 const char *PluginOptPrefix = IsOSAIX ?
"-bplugin_opt:" :
"-plugin-opt=";
872 const char *ExtraDash = IsOSAIX ?
"-" :
"";
873 const char *ParallelismOpt = IsOSAIX ?
"-threads=" :
"jobs=";
878 if (Args.hasArg(options::OPT_gdwarf_aranges)) {
879 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) +
880 "-generate-arange-section"));
884 Arg *ArgVecLib = Args.getLastArg(options::OPT_fveclib);
885 if (ArgVecLib && ArgVecLib->getNumValues() == 1) {
888 std::optional<StringRef> OptVal =
889 llvm::StringSwitch<std::optional<StringRef>>(ArgVecLib->getValue())
890 .Case(
"Accelerate",
"Accelerate")
891 .Case(
"LIBMVEC",
"LIBMVEC-X86")
892 .Case(
"MASSV",
"MASSV")
893 .Case(
"SVML",
"SVML")
894 .Case(
"SLEEF",
"sleefgnuabi")
895 .Case(
"Darwin_libsystem_m",
"Darwin_libsystem_m")
896 .Case(
"ArmPL",
"ArmPL")
897 .Case(
"none",
"none")
898 .Default(std::nullopt);
901 CmdArgs.push_back(Args.MakeArgString(
902 Twine(PluginOptPrefix) +
"-vector-library=" + OptVal.value()));
912 Args.MakeArgString(Twine(PluginOptPrefix) + ExtraDash +
"mcpu=" + CPU));
914 if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
918 if (A->getOption().matches(options::OPT_O4) ||
919 A->getOption().matches(options::OPT_Ofast))
921 else if (A->getOption().matches(options::OPT_O)) {
922 OOpt = A->getValue();
925 else if (OOpt ==
"s" || OOpt ==
"z")
927 }
else if (A->getOption().matches(options::OPT_O0))
931 Args.MakeArgString(Twine(PluginOptPrefix) + ExtraDash +
"O" + OOpt));
933 CmdArgs.push_back(Args.MakeArgString(Twine(
"--lto-CGO") + OOpt));
937 if (Args.hasArg(options::OPT_gsplit_dwarf))
938 CmdArgs.push_back(Args.MakeArgString(
939 Twine(PluginOptPrefix) +
"dwo_dir=" + Output.
getFilename() +
"_dwo"));
941 if (IsThinLTO && !IsOSAIX)
942 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) +
"thinlto"));
943 else if (IsThinLTO && IsOSAIX)
944 CmdArgs.push_back(Args.MakeArgString(Twine(
"-bdbg:thinlto")));
949 if ((IsThinLTO || IsFatLTO || IsUnifiedLTO) &&
950 Args.hasArg(options::OPT_fenable_matrix))
952 Args.MakeArgString(Twine(PluginOptPrefix) +
"-enable-matrix"));
955 if (!Parallelism.empty())
956 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) +
957 ParallelismOpt + Parallelism));
960 if (Arg *A = Args.getLastArg(options::OPT_fglobal_isel,
961 options::OPT_fno_global_isel)) {
964 CmdArgs.push_back(Args.MakeArgString(
965 Twine(PluginOptPrefix) +
"-global-isel=" +
966 (A->getOption().matches(options::OPT_fglobal_isel) ?
"1" :
"0")));
971 Args.getLastArg(options::OPT_gTune_Group, options::OPT_ggdbN_Group)) {
972 if (A->getOption().matches(options::OPT_glldb))
974 Args.MakeArgString(Twine(PluginOptPrefix) +
"-debugger-tune=lldb"));
975 else if (A->getOption().matches(options::OPT_gsce))
977 Args.MakeArgString(Twine(PluginOptPrefix) +
"-debugger-tune=sce"));
978 else if (A->getOption().matches(options::OPT_gdbx))
980 Args.MakeArgString(Twine(PluginOptPrefix) +
"-debugger-tune=dbx"));
983 Args.MakeArgString(Twine(PluginOptPrefix) +
"-debugger-tune=gdb"));
989 Args.MakeArgString(Twine(PluginOptPrefix) +
"-no-integrated-as=1"));
993 Arg *A = Args.getLastArg(options::OPT_g_Group);
994 bool EnableDebugInfo = A && !A->getOption().matches(options::OPT_g0) &&
995 !A->getOption().matches(options::OPT_ggdb0);
996 if (EnableDebugInfo && Args.hasFlag(options::OPT_gstrict_dwarf,
997 options::OPT_gno_strict_dwarf,
true))
999 Args.MakeArgString(Twine(PluginOptPrefix) +
"-strict-dwarf=true"));
1001 for (
const Arg *A : Args.filtered_reverse(options::OPT_mabi_EQ)) {
1002 StringRef
V = A->getValue();
1003 if (
V ==
"vec-default")
1005 if (
V ==
"vec-extabi") {
1007 Args.MakeArgString(Twine(PluginOptPrefix) +
"-vec-extabi"));
1013 bool UseSeparateSections =
1016 if (Args.hasFlag(options::OPT_ffunction_sections,
1017 options::OPT_fno_function_sections, UseSeparateSections))
1019 Args.MakeArgString(Twine(PluginOptPrefix) +
"-function-sections=1"));
1020 else if (Args.hasArg(options::OPT_fno_function_sections))
1022 Args.MakeArgString(Twine(PluginOptPrefix) +
"-function-sections=0"));
1024 bool DataSectionsTurnedOff =
false;
1025 if (Args.hasFlag(options::OPT_fdata_sections, options::OPT_fno_data_sections,
1026 UseSeparateSections)) {
1028 Args.MakeArgString(Twine(PluginOptPrefix) +
"-data-sections=1"));
1029 }
else if (Args.hasArg(options::OPT_fno_data_sections)) {
1030 DataSectionsTurnedOff =
true;
1032 Args.MakeArgString(Twine(PluginOptPrefix) +
"-data-sections=0"));
1035 if (Args.hasArg(options::OPT_mxcoff_roptr) ||
1036 Args.hasArg(options::OPT_mno_xcoff_roptr)) {
1037 bool HasRoptr = Args.hasFlag(options::OPT_mxcoff_roptr,
1038 options::OPT_mno_xcoff_roptr,
false);
1039 StringRef OptStr = HasRoptr ?
"-mxcoff-roptr" :
"-mno-xcoff-roptr";
1041 D.Diag(diag::err_drv_unsupported_opt_for_target)
1042 << OptStr << Triple.str();
1048 if (DataSectionsTurnedOff)
1049 D.Diag(diag::err_roptr_requires_data_sections);
1052 Args.MakeArgString(Twine(PluginOptPrefix) +
"-mxcoff-roptr"));
1057 if (
auto *A = Args.getLastArg(options::OPT_fsplit_machine_functions,
1058 options::OPT_fno_split_machine_functions)) {
1059 if (A->getOption().matches(options::OPT_fsplit_machine_functions))
1060 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) +
1061 "-split-machine-functions"));
1065 StringRef FName = A->getValue();
1066 if (!llvm::sys::fs::exists(FName))
1067 D.Diag(diag::err_drv_no_such_file) << FName;
1069 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) +
1070 "sample-profile=" + FName));
1074 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) + ExtraDash +
1075 "cs-profile-generate"));
1076 if (CSPGOGenerateArg->getOption().matches(
1077 options::OPT_fcs_profile_generate_EQ)) {
1079 llvm::sys::path::append(
Path,
"default_%m.profraw");
1080 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) + ExtraDash +
1081 "cs-profile-path=" +
Path));
1084 Args.MakeArgString(Twine(PluginOptPrefix) + ExtraDash +
1085 "cs-profile-path=default_%m.profraw"));
1088 ProfileUseArg->getNumValues() == 0 ?
"" : ProfileUseArg->getValue());
1089 if (
Path.empty() || llvm::sys::fs::is_directory(
Path))
1090 llvm::sys::path::append(
Path,
"default.profdata");
1091 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) + ExtraDash +
1092 "cs-profile-path=" +
Path));
1096 if (Args.hasFlag(options::OPT_fjmc, options::OPT_fno_jmc,
false)) {
1098 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) +
1099 "-enable-jmc-instrument"));
1101 D.Diag(clang::diag::warn_drv_fjmc_for_elf_only);
1104 if (Args.hasFlag(options::OPT_femulated_tls, options::OPT_fno_emulated_tls,
1105 Triple.hasDefaultEmulatedTLS())) {
1107 Args.MakeArgString(Twine(PluginOptPrefix) +
"-emulated-tls"));
1111 Args.MakeArgString(Twine(PluginOptPrefix) +
"-enable-tlsdesc"));
1113 if (Args.hasFlag(options::OPT_fstack_size_section,
1114 options::OPT_fno_stack_size_section,
false))
1116 Args.MakeArgString(Twine(PluginOptPrefix) +
"-stack-size-section"));
1120 if (!StatsFile.empty())
1122 Args.MakeArgString(Twine(PluginOptPrefix) +
"stats-file=" + StatsFile));
1125 if (Arg *A = Args.getLastArg(options::OPT_fcrash_diagnostics_dir))
1126 CmdArgs.push_back(Args.MakeArgString(
1127 Twine(PluginOptPrefix) +
"-crash-diagnostics-dir=" + A->getValue()));
1138 Output, PluginOptPrefix);
1144 true, PluginOptPrefix);
1146 bool IsELF = Triple.isOSBinFormatELF();
1148 bool ImplicitMapSyms =
false;
1149 for (
const Arg *A : Args.filtered(options::OPT_Wa_COMMA)) {
1150 for (StringRef
V : A->getValues()) {
1151 auto Equal =
V.split(
'=');
1152 auto checkArg = [&](
bool ValidTarget,
1153 std::initializer_list<const char *>
Set) {
1155 D.Diag(diag::err_drv_unsupported_opt_for_target)
1156 << (Twine(
"-Wa,") +
Equal.first +
"=").str()
1157 << Triple.getTriple();
1158 }
else if (!llvm::is_contained(
Set,
Equal.second)) {
1159 D.Diag(diag::err_drv_unsupported_option_argument)
1160 << (Twine(
"-Wa,") +
Equal.first +
"=").str() <<
Equal.second;
1163 if (
Equal.first ==
"-mmapsyms") {
1164 ImplicitMapSyms =
Equal.second ==
"implicit";
1165 checkArg(IsELF && Triple.isAArch64(), {
"default",
"implicit"});
1166 }
else if (
V ==
"--crel")
1168 else if (
V ==
"--no-crel")
1176 if (IsELF && !Triple.isMIPS()) {
1177 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) +
"-crel"));
1179 D.Diag(diag::err_drv_unsupported_opt_for_target)
1180 <<
"-Wa,--crel" <<
D.getTargetTriple();
1183 if (ImplicitMapSyms)
1185 Args.MakeArgString(Twine(PluginOptPrefix) +
"-implicit-mapsyms"));
1189 const ArgList &Args,
1190 ArgStringList &CmdArgs) {
1195 llvm::sys::path::append(DefaultLibPath, CLANG_INSTALL_LIBDIR_BASENAME);
1196 CmdArgs.push_back(Args.MakeArgString(
"-L" + DefaultLibPath));
1200 ArgStringList &CmdArgs) {
1201 if (!Args.hasFlag(options::OPT_frtlib_add_rpath,
1202 options::OPT_fno_rtlib_add_rpath,
false))
1207 CandidateRPaths.emplace_back(*CandidateRPath);
1209 for (
const auto &CandidateRPath : CandidateRPaths) {
1210 if (TC.
getVFS().exists(CandidateRPath)) {
1211 CmdArgs.push_back(
"-rpath");
1212 CmdArgs.push_back(Args.MakeArgString(CandidateRPath));
1218 const ToolChain &TC,
const ArgList &Args,
1219 bool ForceStaticHostRuntime,
bool IsOffloadingHost,
1221 if (!Args.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ,
1222 options::OPT_fno_openmp,
false)) {
1224 if (Args.hasFlag(options::OPT_foffload_via_llvm,
1225 options::OPT_fno_offload_via_llvm,
false))
1226 CmdArgs.push_back(
"-lomptarget");
1236 if (ForceStaticHostRuntime)
1237 CmdArgs.push_back(
"-Bstatic");
1241 CmdArgs.push_back(
"-lomp");
1244 CmdArgs.push_back(
"-lgomp");
1247 CmdArgs.push_back(
"-liomp5");
1253 if (ForceStaticHostRuntime)
1254 CmdArgs.push_back(
"-Bdynamic");
1257 CmdArgs.push_back(
"-lrt");
1259 if (IsOffloadingHost)
1260 CmdArgs.push_back(
"-lomptarget");
1262 if (IsOffloadingHost && !Args.hasArg(options::OPT_nogpulib))
1263 CmdArgs.push_back(
"-lomptarget.devicertl");
1274 const llvm::opt::ArgList &Args,
1275 llvm::opt::ArgStringList &CmdArgs) {
1281 constexpr llvm::StringLiteral Targets(
"-fopenmp-targets=");
1285 std::transform(TCRange.first, TCRange.second, std::back_inserter(Triples),
1286 [](
auto TC) { return TC.second->getTripleString(); });
1288 Args.MakeArgString(Twine(Targets) + llvm::join(Triples,
",")));
1293 llvm::opt::ArgStringList &CmdArgs) {
1298 if (!TC.
getTriple().isKnownWindowsMSVCEnvironment()) {
1300 F128LibName.consume_front_insensitive(
"lib");
1301 if (!F128LibName.empty()) {
1302 bool AsNeeded = !TC.
getTriple().isOSAIX();
1303 CmdArgs.push_back(
"-lFortranFloat128Math");
1306 CmdArgs.push_back(Args.MakeArgString(
"-l" + F128LibName));
1310 CmdArgs.push_back(
"-lFortranRuntime");
1311 CmdArgs.push_back(
"-lFortranDecimal");
1316 const llvm::opt::ArgList &Args,
1317 ArgStringList &CmdArgs) {
1324 llvm::sys::path::append(DefaultLibPath,
"lib");
1325 if (TC.
getTriple().isKnownWindowsMSVCEnvironment())
1326 CmdArgs.push_back(Args.MakeArgString(
"-libpath:" + DefaultLibPath));
1328 CmdArgs.push_back(Args.MakeArgString(
"-L" + DefaultLibPath));
1332 ArgStringList &CmdArgs, StringRef Sanitizer,
1333 bool IsShared,
bool IsWhole) {
1336 if (IsWhole) CmdArgs.push_back(
"--whole-archive");
1339 if (IsWhole) CmdArgs.push_back(
"--no-whole-archive");
1349 ArgStringList &CmdArgs,
1350 StringRef Sanitizer) {
1355 if (TC.
getTriple().isOSSolaris() && !LinkerIsGnuLd)
1358 if (llvm::sys::fs::exists(SanRT +
".syms")) {
1359 CmdArgs.push_back(Args.MakeArgString(
"--dynamic-list=" + SanRT +
".syms"));
1366 const llvm::opt::ArgList &Args,
1367 llvm::opt::ArgStringList &CmdArgs,
1370 "AIX linker does not support any form of --as-needed option yet.");
1378 if (TC.
getTriple().isOSSolaris() && !LinkerIsGnuLd) {
1379 CmdArgs.push_back(
"-z");
1380 CmdArgs.push_back(as_needed ?
"ignore" :
"record");
1382 CmdArgs.push_back(as_needed ?
"--as-needed" :
"--no-as-needed");
1387 const llvm::opt::ArgList &Args,
1388 ArgStringList &CmdArgs) {
1393 if (TC.
getTriple().getOS() != llvm::Triple::RTEMS &&
1395 CmdArgs.push_back(
"-lpthread");
1397 CmdArgs.push_back(
"-lrt");
1399 CmdArgs.push_back(
"-lm");
1403 TC.
getTriple().getOS() != llvm::Triple::RTEMS)
1404 CmdArgs.push_back(
"-ldl");
1409 CmdArgs.push_back(
"-lexecinfo");
1415 CmdArgs.push_back(
"-lresolv");
1429 SharedRuntimes.push_back(
"asan");
1430 if (!Args.hasArg(options::OPT_shared) && !TC.
getTriple().isAndroid())
1431 HelperStaticRuntimes.push_back(
"asan-preinit");
1434 SharedRuntimes.push_back(
"memprof");
1435 if (!Args.hasArg(options::OPT_shared) && !TC.
getTriple().isAndroid())
1436 HelperStaticRuntimes.push_back(
"memprof-preinit");
1439 SharedRuntimes.push_back(
"nsan");
1442 SharedRuntimes.push_back(
"ubsan_minimal");
1444 SharedRuntimes.push_back(
"ubsan_standalone");
1447 SharedRuntimes.push_back(
"scudo_standalone");
1450 SharedRuntimes.push_back(
"tsan");
1453 SharedRuntimes.push_back(
"hwasan_aliases");
1455 SharedRuntimes.push_back(
"hwasan");
1456 if (!Args.hasArg(options::OPT_shared))
1457 HelperStaticRuntimes.push_back(
"hwasan-preinit");
1463 StaticRuntimes.push_back(
"stats_client");
1467 HelperStaticRuntimes.push_back(
"asan_static");
1470 if (Args.hasArg(options::OPT_shared)) {
1479 StaticRuntimes.push_back(
"asan");
1481 StaticRuntimes.push_back(
"asan_cxx");
1485 StaticRuntimes.push_back(
"memprof");
1487 StaticRuntimes.push_back(
"memprof_cxx");
1492 StaticRuntimes.push_back(
"hwasan_aliases");
1494 StaticRuntimes.push_back(
"hwasan_aliases_cxx");
1496 StaticRuntimes.push_back(
"hwasan");
1498 StaticRuntimes.push_back(
"hwasan_cxx");
1502 StaticRuntimes.push_back(
"dfsan");
1504 StaticRuntimes.push_back(
"lsan");
1506 StaticRuntimes.push_back(
"msan");
1508 StaticRuntimes.push_back(
"msan_cxx");
1511 StaticRuntimes.push_back(
"nsan");
1513 StaticRuntimes.push_back(
"tsan");
1515 StaticRuntimes.push_back(
"tsan_cxx");
1519 StaticRuntimes.push_back(
"ubsan_minimal");
1521 StaticRuntimes.push_back(
"ubsan_standalone");
1523 StaticRuntimes.push_back(
"ubsan_standalone_cxx");
1527 NonWholeStaticRuntimes.push_back(
"safestack");
1528 RequiredSymbols.push_back(
"__safestack_init");
1532 StaticRuntimes.push_back(
"cfi");
1534 StaticRuntimes.push_back(
"cfi_diag");
1536 StaticRuntimes.push_back(
"ubsan_standalone_cxx");
1540 NonWholeStaticRuntimes.push_back(
"stats");
1541 RequiredSymbols.push_back(
"__sanitizer_stats_register");
1544 StaticRuntimes.push_back(
"scudo_standalone");
1546 StaticRuntimes.push_back(
"scudo_standalone_cxx");
1553 ArgStringList &CmdArgs) {
1556 NonWholeStaticRuntimes, HelperStaticRuntimes, RequiredSymbols;
1559 NonWholeStaticRuntimes, HelperStaticRuntimes,
1564 for (
auto S : RequiredSymbols) {
1565 CmdArgs.push_back(
"-u");
1566 CmdArgs.push_back(Args.MakeArgString(S));
1571 !Args.hasArg(options::OPT_shared)) {
1577 if (!Args.hasArg(clang::driver::options::OPT_nostdlibxx)) {
1578 bool OnlyLibstdcxxStatic = Args.hasArg(options::OPT_static_libstdcxx) &&
1579 !Args.hasArg(options::OPT_static);
1580 if (OnlyLibstdcxxStatic)
1581 CmdArgs.push_back(
"-Bstatic");
1583 if (OnlyLibstdcxxStatic)
1584 CmdArgs.push_back(
"-Bdynamic");
1588 for (
auto RT : SharedRuntimes)
1590 for (
auto RT : HelperStaticRuntimes)
1592 bool AddExportDynamic =
false;
1593 for (
auto RT : StaticRuntimes) {
1597 for (
auto RT : NonWholeStaticRuntimes) {
1603 if (AddExportDynamic)
1604 CmdArgs.push_back(
"--export-dynamic");
1607 CmdArgs.push_back(
"--export-dynamic-symbol=__cfi_check");
1611 TC.
getDriver().
Diag(diag::err_drv_unsupported_opt_for_target)
1612 <<
"-fsanitize=memtag*" << TC.
getTriple().str();
1615 Args.MakeArgString(
"--android-memtag-mode=" + SanArgs.
getMemtagMode()));
1617 CmdArgs.push_back(
"--android-memtag-heap");
1619 CmdArgs.push_back(
"--android-memtag-stack");
1622 return !StaticRuntimes.empty() || !NonWholeStaticRuntimes.empty();
1626 if (Args.hasArg(options::OPT_shared))
1630 CmdArgs.push_back(
"--whole-archive");
1634 CmdArgs.push_back(
"--no-whole-archive");
1642 const llvm::opt::ArgList &Args,
1643 ArgStringList &CmdArgs) {
1645 CmdArgs.push_back(
"-lpthread");
1647 CmdArgs.push_back(
"-lrt");
1648 CmdArgs.push_back(
"-lm");
1653 CmdArgs.push_back(
"-ldl");
1658 if (Arg *A = Args.getLastArg(options::OPT_O_Group))
1659 return !A->getOption().matches(options::OPT_O0);
1667 auto AddPostfix = [JA](
auto &F) {
1672 if (Arg *A = Args.getLastArg(options::OPT_gsplit_dwarf_EQ))
1673 if (StringRef(A->getValue()) ==
"single" && Output.
isFilename())
1677 if (
const Arg *A = Args.getLastArg(options::OPT_dumpdir)) {
1680 Arg *FinalOutput = Args.getLastArg(options::OPT_o, options::OPT__SLASH_o);
1681 if (FinalOutput && Args.hasArg(options::OPT_c)) {
1682 T = FinalOutput->getValue();
1683 llvm::sys::path::remove_filename(
T);
1684 llvm::sys::path::append(
T,
1685 llvm::sys::path::stem(FinalOutput->getValue()));
1687 return Args.MakeArgString(
T);
1693 return Args.MakeArgString(
T);
1697 const JobAction &JA,
const ArgList &Args,
1698 const InputInfo &Output,
const char *OutFile) {
1699 ArgStringList ExtractArgs;
1700 ExtractArgs.push_back(
"--extract-dwo");
1702 ArgStringList StripArgs;
1703 StripArgs.push_back(
"--strip-dwo");
1708 ExtractArgs.push_back(OutFile);
1715 C.addCommand(std::make_unique<Command>(JA,
T,
1717 Exec, ExtractArgs, II, Output));
1720 C.addCommand(std::make_unique<Command>(
1730 Args.ClaimAllArgs(options::OPT_flto_EQ);
1731 Args.ClaimAllArgs(options::OPT_flto);
1732 Args.ClaimAllArgs(options::OPT_fno_lto);
1736 auto *CSPGOGenerateArg = Args.getLastArg(options::OPT_fcs_profile_generate,
1737 options::OPT_fcs_profile_generate_EQ,
1738 options::OPT_fno_profile_generate);
1739 if (CSPGOGenerateArg &&
1740 CSPGOGenerateArg->getOption().matches(options::OPT_fno_profile_generate))
1741 CSPGOGenerateArg =
nullptr;
1743 return CSPGOGenerateArg;
1747 auto *ProfileUseArg = Args.getLastArg(
1748 options::OPT_fprofile_instr_use, options::OPT_fprofile_instr_use_EQ,
1749 options::OPT_fprofile_use, options::OPT_fprofile_use_EQ,
1750 options::OPT_fno_profile_instr_use);
1752 if (ProfileUseArg &&
1753 ProfileUseArg->getOption().matches(options::OPT_fno_profile_instr_use))
1754 ProfileUseArg =
nullptr;
1756 return ProfileUseArg;
1760 auto *ProfileSampleUseArg = Args.getLastArg(
1761 options::OPT_fprofile_sample_use, options::OPT_fprofile_sample_use_EQ,
1762 options::OPT_fauto_profile, options::OPT_fauto_profile_EQ,
1763 options::OPT_fno_profile_sample_use, options::OPT_fno_auto_profile);
1765 if (ProfileSampleUseArg &&
1766 (ProfileSampleUseArg->getOption().matches(
1767 options::OPT_fno_profile_sample_use) ||
1768 ProfileSampleUseArg->getOption().matches(options::OPT_fno_auto_profile)))
1771 return Args.getLastArg(options::OPT_fprofile_sample_use_EQ,
1772 options::OPT_fauto_profile_EQ);
1777 case llvm::Reloc::Static:
1779 case llvm::Reloc::PIC_:
1781 case llvm::Reloc::DynamicNoPIC:
1782 return "dynamic-no-pic";
1783 case llvm::Reloc::ROPI:
1785 case llvm::Reloc::RWPI:
1787 case llvm::Reloc::ROPI_RWPI:
1790 llvm_unreachable(
"Unknown Reloc::Model kind");
1797std::tuple<llvm::Reloc::Model, unsigned, bool>
1805 if (Triple.isOSBinFormatMachO() && Args.hasArg(options::OPT_static))
1807 bool IsPICLevelTwo = PIC;
1810 Args.hasArg(options::OPT_mkernel, options::OPT_fapple_kext);
1813 if (Triple.isAndroid()) {
1814 switch (Triple.getArch()) {
1815 case llvm::Triple::arm:
1816 case llvm::Triple::armeb:
1817 case llvm::Triple::thumb:
1818 case llvm::Triple::thumbeb:
1819 case llvm::Triple::aarch64:
1820 case llvm::Triple::mips:
1821 case llvm::Triple::mipsel:
1822 case llvm::Triple::mips64:
1823 case llvm::Triple::mips64el:
1827 case llvm::Triple::x86:
1828 case llvm::Triple::x86_64:
1830 IsPICLevelTwo =
true;
1839 if (Triple.isOHOSFamily() && Triple.getArch() == llvm::Triple::aarch64)
1843 if (Triple.isOSOpenBSD()) {
1845 case llvm::Triple::arm:
1846 case llvm::Triple::aarch64:
1847 case llvm::Triple::mips64:
1848 case llvm::Triple::mips64el:
1849 case llvm::Triple::x86:
1850 case llvm::Triple::x86_64:
1851 IsPICLevelTwo =
false;
1854 case llvm::Triple::ppc:
1855 case llvm::Triple::sparcv9:
1856 IsPICLevelTwo =
true;
1868 Arg *LastPICArg = Args.getLastArg(options::OPT_fPIC, options::OPT_fno_PIC,
1869 options::OPT_fpic, options::OPT_fno_pic,
1870 options::OPT_fPIE, options::OPT_fno_PIE,
1871 options::OPT_fpie, options::OPT_fno_pie);
1872 if (Triple.isOSWindows() && !Triple.isOSCygMing() && LastPICArg &&
1873 LastPICArg == Args.getLastArg(options::OPT_fPIC, options::OPT_fpic,
1874 options::OPT_fPIE, options::OPT_fpie)) {
1876 << LastPICArg->getSpelling() << Triple.str();
1877 if (Triple.getArch() == llvm::Triple::x86_64)
1878 return std::make_tuple(llvm::Reloc::PIC_, 2U,
false);
1879 return std::make_tuple(llvm::Reloc::Static, 0
U,
false);
1886 Option O = LastPICArg->getOption();
1887 if (O.matches(options::OPT_fPIC) || O.matches(options::OPT_fpic) ||
1888 O.matches(options::OPT_fPIE) || O.matches(options::OPT_fpie)) {
1889 PIE = O.matches(options::OPT_fPIE) || O.matches(options::OPT_fpie);
1891 PIE || O.matches(options::OPT_fPIC) || O.matches(options::OPT_fpic);
1893 O.matches(options::OPT_fPIE) || O.matches(options::OPT_fPIC);
1896 if (EffectiveTriple.isPS()) {
1897 Arg *ModelArg = Args.getLastArg(options::OPT_mcmodel_EQ);
1898 StringRef Model = ModelArg ? ModelArg->getValue() :
"";
1899 if (Model !=
"kernel") {
1902 << LastPICArg->getSpelling()
1903 << (EffectiveTriple.isPS4() ?
"PS4" :
"PS5");
1913 if (PIC && (Triple.isOSDarwin() || EffectiveTriple.isPS()))
1919 ((!EffectiveTriple.isiOS() || EffectiveTriple.isOSVersionLT(6)) &&
1920 !EffectiveTriple.isWatchOS() && !EffectiveTriple.isDriverKit()))
1923 if (Arg *A = Args.getLastArg(options::OPT_mdynamic_no_pic)) {
1926 if (!Triple.isOSDarwin())
1928 << A->getSpelling() << Triple.str();
1937 return std::make_tuple(llvm::Reloc::DynamicNoPIC, PIC ? 2U : 0
U,
false);
1940 bool EmbeddedPISupported;
1941 switch (Triple.getArch()) {
1942 case llvm::Triple::arm:
1943 case llvm::Triple::armeb:
1944 case llvm::Triple::thumb:
1945 case llvm::Triple::thumbeb:
1946 EmbeddedPISupported =
true;
1949 EmbeddedPISupported =
false;
1953 bool ROPI =
false, RWPI =
false;
1954 Arg* LastROPIArg = Args.getLastArg(options::OPT_fropi, options::OPT_fno_ropi);
1955 if (LastROPIArg && LastROPIArg->getOption().matches(options::OPT_fropi)) {
1956 if (!EmbeddedPISupported)
1958 << LastROPIArg->getSpelling() << Triple.str();
1961 Arg *LastRWPIArg = Args.getLastArg(options::OPT_frwpi, options::OPT_fno_rwpi);
1962 if (LastRWPIArg && LastRWPIArg->getOption().matches(options::OPT_frwpi)) {
1963 if (!EmbeddedPISupported)
1965 << LastRWPIArg->getSpelling() << Triple.str();
1970 if ((ROPI || RWPI) && (PIC || PIE))
1973 if (Triple.isMIPS()) {
1980 if (ABIName ==
"n64")
1983 if(Args.hasArg(options::OPT_mno_abicalls))
1984 return std::make_tuple(llvm::Reloc::Static, 0
U,
false);
1987 IsPICLevelTwo =
false;
1991 return std::make_tuple(llvm::Reloc::PIC_, IsPICLevelTwo ? 2U : 1U, PIE);
1993 llvm::Reloc::Model RelocM = llvm::Reloc::Static;
1995 RelocM = llvm::Reloc::ROPI_RWPI;
1997 RelocM = llvm::Reloc::ROPI;
1999 RelocM = llvm::Reloc::RWPI;
2001 return std::make_tuple(RelocM, 0
U,
false);
2021 const ArgList &Args) {
2022 const Arg *A = Args.getLastArg(options::OPT_falign_functions,
2023 options::OPT_falign_functions_EQ,
2024 options::OPT_fno_align_functions);
2025 if (!A || A->getOption().matches(options::OPT_fno_align_functions))
2028 if (A->getOption().matches(options::OPT_falign_functions))
2032 if (StringRef(A->getValue()).getAsInteger(10,
Value) ||
Value > 65536)
2034 << A->getAsString(Args) << A->getValue();
2039 ArgStringList &CmdArgs, llvm::codegenoptions::DebugInfoKind DebugInfoKind) {
2040 switch (DebugInfoKind) {
2041 case llvm::codegenoptions::DebugDirectivesOnly:
2042 CmdArgs.push_back(
"-debug-info-kind=line-directives-only");
2044 case llvm::codegenoptions::DebugLineTablesOnly:
2045 CmdArgs.push_back(
"-debug-info-kind=line-tables-only");
2047 case llvm::codegenoptions::DebugInfoConstructor:
2048 CmdArgs.push_back(
"-debug-info-kind=constructor");
2050 case llvm::codegenoptions::LimitedDebugInfo:
2051 CmdArgs.push_back(
"-debug-info-kind=limited");
2053 case llvm::codegenoptions::FullDebugInfo:
2054 CmdArgs.push_back(
"-debug-info-kind=standalone");
2056 case llvm::codegenoptions::UnusedTypeInfo:
2057 CmdArgs.push_back(
"-debug-info-kind=unused-types");
2067 assert(A.getOption().matches(options::OPT_gN_Group) &&
2068 "Not a -g option that specifies a debug-info level");
2069 if (A.getOption().matches(options::OPT_g0) ||
2070 A.getOption().matches(options::OPT_ggdb0))
2071 return llvm::codegenoptions::NoDebugInfo;
2072 if (A.getOption().matches(options::OPT_gline_tables_only) ||
2073 A.getOption().matches(options::OPT_ggdb1))
2074 return llvm::codegenoptions::DebugLineTablesOnly;
2075 if (A.getOption().matches(options::OPT_gline_directives_only))
2076 return llvm::codegenoptions::DebugDirectivesOnly;
2077 return llvm::codegenoptions::DebugInfoConstructor;
2081 const ArgList &Args) {
2082 const Arg *A = Args.getLastArg(options::OPT_fdebug_default_version);
2088 if (StringRef(A->getValue()).getAsInteger(10,
Value) ||
Value > 5 ||
2091 << A->getAsString(Args) << A->getValue();
2096 return llvm::StringSwitch<unsigned>(ArgValue)
2097 .Case(
"-gdwarf-2", 2)
2098 .Case(
"-gdwarf-3", 3)
2099 .Case(
"-gdwarf-4", 4)
2100 .Case(
"-gdwarf-5", 5)
2105 return Args.getLastArg(options::OPT_gdwarf_2, options::OPT_gdwarf_3,
2106 options::OPT_gdwarf_4, options::OPT_gdwarf_5,
2107 options::OPT_gdwarf);
2111 const llvm::opt::ArgList &Args) {
2116 if (DwarfVersion == 5 && TC.
getTriple().isOSAIX())
2117 TC.
getDriver().
Diag(diag::err_drv_unsupported_opt_for_target)
2118 << GDwarfN->getSpelling() << TC.
getTriple().str();
2120 if (DwarfVersion == 0) {
2122 assert(DwarfVersion &&
"toolchain default DWARF version must be nonzero");
2124 return DwarfVersion;
2128 ArgStringList &CmdArgs) {
2129 llvm::Reloc::Model RelocationModel;
2134 if (RelocationModel != llvm::Reloc::Static)
2135 CmdArgs.push_back(
"-KPIC");
2141 return Args.hasFlag(options::OPT_fobjc_arc, options::OPT_fno_objc_arc,
false);
2147 const ArgList &Args) {
2148 if (Args.hasArg(options::OPT_static_libgcc) ||
2149 Args.hasArg(options::OPT_static) || Args.hasArg(options::OPT_static_pie) ||
2153 if (Args.hasArg(options::OPT_shared_libgcc))
2172 ArgStringList &CmdArgs,
const ArgList &Args) {
2176 CmdArgs.push_back(
"-l:libunwind.a");
2199 CmdArgs.push_back(
"-lgcc_eh");
2201 CmdArgs.push_back(
"-lgcc_s");
2209 CmdArgs.push_back(
"-lunwind");
2211 CmdArgs.push_back(
"-l:libunwind.a");
2214 CmdArgs.push_back(
"-l:libunwind.dll.a");
2216 CmdArgs.push_back(
"-l:libunwind.so");
2220 CmdArgs.push_back(
"-lunwind");
2230 ArgStringList &CmdArgs,
const ArgList &Args) {
2234 CmdArgs.push_back(
"-lgcc");
2238 CmdArgs.push_back(
"-lgcc");
2242 ArgStringList &CmdArgs,
const ArgList &Args) {
2253 if (TC.
getTriple().isKnownWindowsMSVCEnvironment()) {
2256 Arg *A = Args.getLastArg(options::OPT_rtlib_EQ);
2257 if (A && A->getValue() != StringRef(
"platform")) {
2258 TC.
getDriver().
Diag(diag::err_drv_unsupported_rtlib_for_platform)
2259 << A->getValue() <<
"MSVC";
2269 if (TC.
getTriple().isAndroid() && !Args.hasArg(options::OPT_static) &&
2270 !Args.hasArg(options::OPT_static_pie))
2271 CmdArgs.push_back(
"-ldl");
2278 const Arg *A = Args.getLastArg(options::OPT_save_stats_EQ);
2279 if (!A && !
D.CCPrintInternalStats)
2284 StringRef SaveStats = A->getValue();
2285 if (SaveStats ==
"obj" && Output.
isFilename()) {
2287 llvm::sys::path::remove_filename(StatsFile);
2288 }
else if (SaveStats !=
"cwd") {
2289 D.Diag(diag::err_drv_invalid_value) << A->getAsString(Args) << SaveStats;
2293 StringRef BaseName = llvm::sys::path::filename(Input.
getBaseInput());
2294 llvm::sys::path::append(StatsFile, BaseName);
2295 llvm::sys::path::replace_extension(StatsFile,
"stats");
2297 assert(
D.CCPrintInternalStats);
2298 StatsFile.assign(
D.CCPrintInternalStatReportFilename.empty()
2300 :
D.CCPrintInternalStatReportFilename);
2307 assert(Flag.front() ==
'-');
2309 Flags.push_back(Flag.str());
2311 Flags.push_back((
"!" + Flag.substr(1)).str());
2316 ArgStringList &CmdArgs,
bool IsLTO,
2317 const StringRef PluginOptPrefix) {
2318 auto addArg = [&, IsLTO](
const Twine &Arg) {
2320 assert(!PluginOptPrefix.empty() &&
"Cannot have empty PluginOptPrefix!");
2321 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) + Arg));
2323 CmdArgs.push_back(
"-mllvm");
2324 CmdArgs.push_back(Args.MakeArgString(Arg));
2328 if (Args.hasArg(options::OPT_mbranches_within_32B_boundaries)) {
2329 addArg(Twine(
"-x86-branches-within-32B-boundaries"));
2331 if (
const Arg *A = Args.getLastArg(options::OPT_malign_branch_boundary_EQ)) {
2332 StringRef
Value = A->getValue();
2334 if (
Value.getAsInteger(10, Boundary) || Boundary < 16 ||
2335 !llvm::isPowerOf2_64(Boundary)) {
2336 D.Diag(diag::err_drv_invalid_argument_to_option)
2337 <<
Value << A->getOption().getName();
2339 addArg(
"-x86-align-branch-boundary=" + Twine(Boundary));
2342 if (
const Arg *A = Args.getLastArg(options::OPT_malign_branch_EQ)) {
2343 std::string AlignBranch;
2344 for (StringRef
T : A->getValues()) {
2345 if (
T !=
"fused" &&
T !=
"jcc" &&
T !=
"jmp" &&
T !=
"call" &&
2346 T !=
"ret" &&
T !=
"indirect")
2347 D.Diag(diag::err_drv_invalid_malign_branch_EQ)
2348 <<
T <<
"fused, jcc, jmp, call, ret, indirect";
2349 if (!AlignBranch.empty())
2353 addArg(
"-x86-align-branch=" + Twine(AlignBranch));
2355 if (
const Arg *A = Args.getLastArg(options::OPT_mpad_max_prefix_size_EQ)) {
2356 StringRef
Value = A->getValue();
2357 unsigned PrefixSize;
2358 if (
Value.getAsInteger(10, PrefixSize)) {
2359 D.Diag(diag::err_drv_invalid_argument_to_option)
2360 <<
Value << A->getOption().getName();
2362 addArg(
"-x86-pad-max-prefix-size=" + Twine(PrefixSize));
2388 llvm::opt::ArgStringList &CC1Args,
2390 StringRef Lib, StringRef Arch, StringRef
Target,
2391 bool isBitCodeSDL) {
2394 std::string LibDeviceLoc =
"/libdevice";
2395 std::string LibBcPrefix =
"/libbc-";
2396 std::string LibPrefix =
"/lib";
2413 for (StringRef
Base : {LibBcPrefix, LibPrefix}) {
2414 const auto *Ext =
Base.contains(LibBcPrefix) ?
".a" :
".bc";
2416 for (
auto Suffix : {Twine(Lib +
"-" + Arch +
"-" +
Target).str(),
2417 Twine(Lib +
"-" + Arch).str(), Twine(Lib).str()}) {
2418 SDLs.push_back(Twine(LibDeviceLoc +
Base + Suffix + Ext).str());
2419 SDLs.push_back(Twine(
Base + Suffix + Ext).str());
2429 const auto *Ext =
".a";
2431 for (
auto Suffix : {Twine(Lib +
"-" + Arch +
"-" +
Target).str(),
2432 Twine(Lib +
"-" + Arch).str()}) {
2433 SDLs.push_back(Twine(LibDeviceLoc + LibPrefix + Suffix + Ext).str());
2434 SDLs.push_back(Twine(LibPrefix + Suffix + Ext).str());
2445 bool FoundSDL =
false;
2446 for (
auto LPath : LibraryPaths) {
2447 for (
auto SDL : SDLs) {
2448 auto FullName = Twine(LPath + SDL).str();
2449 if (llvm::sys::fs::exists(
FullName)) {
2450 CC1Args.push_back(DriverArgs.MakeArgString(
FullName));
2467 const InputInfoList &Inputs,
const llvm::opt::ArgList &DriverArgs,
2468 llvm::opt::ArgStringList &CC1Args,
2470 StringRef Arch, StringRef
Target,
bool isBitCodeSDL) {
2473 if (isBitCodeSDL && Arch.contains(
"nvptx"))
2476 bool FoundAOB =
false;
2477 std::string ArchiveOfBundles;
2479 llvm::Triple Triple(
D.getTargetTriple());
2480 bool IsMSVC = Triple.isWindowsMSVCEnvironment();
2481 auto Ext = IsMSVC ?
".lib" :
".a";
2482 if (!Lib.starts_with(
":") && !Lib.starts_with(
"-l")) {
2483 if (llvm::sys::fs::exists(Lib)) {
2484 ArchiveOfBundles = Lib;
2488 Lib.consume_front(
"-l");
2489 for (
auto LPath : LibraryPaths) {
2490 ArchiveOfBundles.clear();
2491 auto LibFile = (Lib.starts_with(
":") ? Lib.drop_front()
2492 : IsMSVC ? Lib + Ext
2493 :
"lib" + Lib + Ext)
2495 for (
auto Prefix : {
"/libdevice/",
"/"}) {
2496 auto AOB = Twine(LPath + Prefix + LibFile).str();
2497 if (llvm::sys::fs::exists(AOB)) {
2498 ArchiveOfBundles = AOB;
2511 llvm::file_magic Magic;
2512 auto EC = llvm::identify_magic(ArchiveOfBundles, Magic);
2513 if (EC || Magic != llvm::file_magic::archive)
2516 StringRef Prefix = isBitCodeSDL ?
"libbc-" :
"lib";
2517 std::string OutputLib =
2518 D.GetTemporaryPath(Twine(Prefix + llvm::sys::path::filename(Lib) +
"-" +
2523 C.addTempFile(
C.getArgs().MakeArgString(OutputLib));
2525 ArgStringList CmdArgs;
2528 DeviceTriple +=
'-';
2529 std::string NormalizedTriple =
T.getToolChain().getTriple().normalize();
2530 DeviceTriple += NormalizedTriple;
2532 DeviceTriple +=
'-';
2536 std::string UnbundleArg(
"-unbundle");
2537 std::string TypeArg(
"-type=a");
2538 std::string InputArg(
"-input=" + ArchiveOfBundles);
2539 std::string OffloadArg(
"-targets=" + std::string(DeviceTriple));
2540 std::string OutputArg(
"-output=" + OutputLib);
2542 const char *UBProgram = DriverArgs.MakeArgString(
2543 T.getToolChain().GetProgramPath(
"clang-offload-bundler"));
2545 ArgStringList UBArgs;
2546 UBArgs.push_back(
C.getArgs().MakeArgString(UnbundleArg));
2547 UBArgs.push_back(
C.getArgs().MakeArgString(TypeArg));
2548 UBArgs.push_back(
C.getArgs().MakeArgString(InputArg));
2549 UBArgs.push_back(
C.getArgs().MakeArgString(OffloadArg));
2550 UBArgs.push_back(
C.getArgs().MakeArgString(OutputArg));
2554 std::string AdditionalArgs(
"-allow-missing-bundles");
2555 UBArgs.push_back(
C.getArgs().MakeArgString(AdditionalArgs));
2560 std::string HipCompatibleArgs(
"-hip-openmp-compatible");
2561 UBArgs.push_back(
C.getArgs().MakeArgString(HipCompatibleArgs));
2563 C.addCommand(std::make_unique<Command>(
2565 InputInfo(&JA,
C.getArgs().MakeArgString(OutputLib))));
2567 CC1Args.push_back(DriverArgs.MakeArgString(OutputLib));
2576 const llvm::opt::ArgList &DriverArgs,
2577 llvm::opt::ArgStringList &CC1Args,
2578 StringRef Arch, StringRef
Target,
2579 bool isBitCodeSDL) {
2581 Arch,
Target, isBitCodeSDL);
2610 const llvm::opt::ArgList &DriverArgs,
2611 llvm::opt::ArgStringList &CC1Args,
2612 StringRef Arch, StringRef
Target,
2613 bool isBitCodeSDL) {
2617 std::optional<std::string> LibPath =
2618 llvm::sys::Process::GetEnv(
"LIBRARY_PATH");
2621 const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator,
'\0'};
2622 llvm::SplitString(*LibPath, Frags, EnvPathSeparatorStr);
2623 for (StringRef
Path : Frags)
2624 LibraryPaths.emplace_back(
Path.trim());
2628 for (std::string Search_Dir : DriverArgs.getAllArgValues(options::OPT_L))
2629 LibraryPaths.emplace_back(Search_Dir);
2633 llvm::sys::path::append(DefaultLibPath, CLANG_INSTALL_LIBDIR_BASENAME);
2634 LibraryPaths.emplace_back(DefaultLibPath.c_str());
2637 llvm::SmallSet<std::string, 16> SDLNames;
2638 static const StringRef HostOnlyArchives[] = {
2639 "omp",
"cudart",
"m",
"gcc",
"gcc_s",
"pthread",
"hip_hcc"};
2640 for (
auto SDLName : DriverArgs.getAllArgValues(options::OPT_l)) {
2641 if (!llvm::is_contained(HostOnlyArchives, SDLName)) {
2642 SDLNames.insert(std::string(
"-l") + SDLName);
2646 for (
auto Input : DriverArgs.getAllArgValues(options::OPT_INPUT)) {
2653 const StringRef LibFileExt =
".lib";
2654 if (!llvm::sys::path::has_extension(
FileName) ||
2656 llvm::sys::path::extension(
FileName).drop_front()) ==
2658 llvm::sys::path::extension(
FileName) == LibFileExt)
2659 SDLNames.insert(Input);
2666 for (
auto SDLName : SDLNames) {
2668 if (!
SDLSearch(
D, DriverArgs, CC1Args, LibraryPaths, SDLName, Arch,
Target,
2671 LibraryPaths, SDLName, Arch,
Target,
2677static llvm::opt::Arg *
2679 return Args.getLastArg(options::OPT_mcode_object_version_EQ);
2683 const llvm::opt::ArgList &Args) {
2684 const unsigned MinCodeObjVer = 4;
2685 const unsigned MaxCodeObjVer = 6;
2688 if (CodeObjArg->getOption().getID() ==
2689 options::OPT_mcode_object_version_EQ) {
2690 unsigned CodeObjVer = MaxCodeObjVer;
2692 StringRef(CodeObjArg->getValue()).getAsInteger(0, CodeObjVer);
2693 if (Remnant || CodeObjVer < MinCodeObjVer || CodeObjVer > MaxCodeObjVer)
2694 D.Diag(diag::err_drv_invalid_int_value)
2695 << CodeObjArg->getAsString(Args) << CodeObjArg->getValue();
2700 if (CodeObjVer == 6)
2701 D.Diag(diag::warn_drv_amdgpu_cov6);
2707 const llvm::opt::ArgList &Args) {
2708 unsigned CodeObjVer = 4;
2710 StringRef(CodeObjArg->getValue()).getAsInteger(0, CodeObjVer);
2715 const Driver &
D,
const llvm::opt::ArgList &Args) {
2720 const llvm::opt::ArgList &Args,
2721 llvm::opt::ArgStringList &CmdArgs,
2722 const llvm::Triple &Triple,
bool IsLTO,
2723 const StringRef PluginOptPrefix) {
2724 auto addArg = [&, IsLTO](
const Twine &Arg) {
2726 assert(!PluginOptPrefix.empty() &&
"Cannot have empty PluginOptPrefix!");
2727 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) + Arg));
2729 CmdArgs.push_back(
"-mllvm");
2730 CmdArgs.push_back(Args.MakeArgString(Arg));
2734 if (Arg *A = Args.getLastArg(options::OPT_moutline,
2735 options::OPT_mno_outline)) {
2736 if (A->getOption().matches(options::OPT_moutline)) {
2740 if (!(Triple.isARM() || Triple.isThumb() || Triple.isAArch64())) {
2741 D.Diag(diag::warn_drv_moutline_unsupported_opt) << Triple.getArchName();
2743 addArg(Twine(
"-enable-machine-outliner"));
2747 addArg(Twine(
"-enable-machine-outliner=never"));
2753 const llvm::opt::ArgList &DriverArgs,
2754 llvm::opt::ArgStringList &CC1Args,
2755 StringRef BitcodeSuffix,
2756 const llvm::Triple &Triple,
2761 std::optional<std::string> LibPath =
2762 llvm::sys::Process::GetEnv(
"LIBRARY_PATH");
2765 const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator,
'\0'};
2766 llvm::SplitString(*LibPath, Frags, EnvPathSeparatorStr);
2767 for (StringRef
Path : Frags)
2768 LibraryPaths.emplace_back(
Path.trim());
2773 LibraryPaths.emplace_back(LibPath);
2775 OptSpecifier LibomptargetBCPathOpt =
2776 Triple.isAMDGCN() ? options::OPT_libomptarget_amdgpu_bc_path_EQ
2777 : options::OPT_libomptarget_nvptx_bc_path_EQ;
2779 StringRef ArchPrefix = Triple.isAMDGCN() ?
"amdgpu" :
"nvptx";
2780 std::string LibOmpTargetName =
2781 (
"libomptarget-" + ArchPrefix +
"-" + BitcodeSuffix +
".bc").str();
2784 if (
const Arg *A = DriverArgs.getLastArg(LibomptargetBCPathOpt)) {
2786 if (llvm::sys::fs::exists(LibOmpTargetFile) &&
2787 llvm::sys::fs::is_directory(LibOmpTargetFile)) {
2788 llvm::sys::path::append(LibOmpTargetFile, LibOmpTargetName);
2791 if (llvm::sys::fs::exists(LibOmpTargetFile)) {
2792 CC1Args.push_back(
"-mlink-builtin-bitcode");
2793 CC1Args.push_back(DriverArgs.MakeArgString(LibOmpTargetFile));
2795 D.Diag(diag::err_drv_omp_offload_target_bcruntime_not_found)
2796 << LibOmpTargetFile;
2799 bool FoundBCLibrary =
false;
2801 for (StringRef LibraryPath : LibraryPaths) {
2803 llvm::sys::path::append(LibOmpTargetFile, LibOmpTargetName);
2804 if (llvm::sys::fs::exists(LibOmpTargetFile)) {
2805 CC1Args.push_back(
"-mlink-builtin-bitcode");
2806 CC1Args.push_back(DriverArgs.MakeArgString(LibOmpTargetFile));
2807 FoundBCLibrary =
true;
2812 if (!FoundBCLibrary)
2813 D.Diag(diag::err_drv_omp_offload_target_missingbcruntime)
2814 << LibOmpTargetName << ArchPrefix;
2818 const llvm::opt::ArgList &Args,
2819 llvm::opt::ArgStringList &CmdArgs) {
2821 !Args.hasArg(options::OPT_nostdlib) &&
2822 !Args.hasArg(options::OPT_no_hip_rt) && !Args.hasArg(options::OPT_r)) {
2826 for (
auto *Arg : Args.filtered(options::OPT_no_hip_rt)) {
2833 const llvm::opt::ArgList &Args,
2834 llvm::opt::ArgStringList &CmdArgs,
2835 const llvm::Triple &Triple) {
2836 if (Arg *A = Args.getLastArg(options::OPT_moutline_atomics,
2837 options::OPT_mno_outline_atomics)) {
2839 if (!Triple.isAArch64()) {
2840 D.Diag(diag::warn_drv_moutline_atomics_unsupported_opt)
2841 << Triple.getArchName() << A->getOption().getName();
2843 if (A->getOption().matches(options::OPT_moutline_atomics)) {
2844 CmdArgs.push_back(
"-target-feature");
2845 CmdArgs.push_back(
"+outline-atomics");
2847 CmdArgs.push_back(
"-target-feature");
2848 CmdArgs.push_back(
"-outline-atomics");
2852 CmdArgs.push_back(
"-target-feature");
2853 CmdArgs.push_back(
"+outline-atomics");
2858 llvm::opt::ArgStringList &CmdArgs) {
2859 if (TCArgs.hasFlag(options::OPT_offload_compress,
2860 options::OPT_no_offload_compress,
false))
2861 CmdArgs.push_back(
"-compress");
2862 if (TCArgs.hasArg(options::OPT_v))
2863 CmdArgs.push_back(
"-verbose");
2864 if (
auto *Arg = TCArgs.getLastArg(options::OPT_offload_compression_level_EQ))
2866 TCArgs.MakeArgString(Twine(
"-compression-level=") + Arg->getValue()));
2870 const llvm::Triple &Triple,
2871 const llvm::Reloc::Model &RelocationModel,
2872 llvm::opt::ArgStringList &CmdArgs) {
2873 if (Arg *A = Args.getLastArg(options::OPT_mcmodel_EQ)) {
2874 StringRef CM = A->getValue();
2876 if (Triple.isOSAIX() && CM ==
"medium")
2878 if (Triple.isAArch64(64)) {
2879 Ok = CM ==
"tiny" || CM ==
"small" || CM ==
"large";
2880 if (CM ==
"large" && !Triple.isOSBinFormatMachO() &&
2881 RelocationModel != llvm::Reloc::Static)
2882 D.Diag(diag::err_drv_argument_only_allowed_with)
2883 << A->getAsString(Args) <<
"-fno-pic";
2884 }
else if (Triple.isLoongArch()) {
2885 if (CM ==
"extreme" &&
2886 Args.hasFlagNoClaim(options::OPT_fplt, options::OPT_fno_plt,
false))
2887 D.Diag(diag::err_drv_argument_not_allowed_with)
2888 << A->getAsString(Args) <<
"-fplt";
2889 Ok = CM ==
"normal" || CM ==
"medium" || CM ==
"extreme";
2892 CM = llvm::StringSwitch<StringRef>(CM)
2893 .Case(
"normal",
"small")
2894 .Case(
"extreme",
"large")
2896 }
else if (Triple.isPPC64() || Triple.isOSAIX()) {
2897 Ok = CM ==
"small" || CM ==
"medium" || CM ==
"large";
2898 }
else if (Triple.isRISCV()) {
2901 else if (CM ==
"medany")
2903 Ok = CM ==
"small" || CM ==
"medium";
2904 }
else if (Triple.getArch() == llvm::Triple::x86_64) {
2905 Ok = llvm::is_contained({
"small",
"kernel",
"medium",
"large",
"tiny"},
2907 }
else if (Triple.isNVPTX() || Triple.isAMDGPU() || Triple.isSPIRV()) {
2911 }
else if (Triple.isSPARC64()) {
2914 else if (CM ==
"medmid")
2916 else if (CM ==
"medany")
2918 Ok = CM ==
"small" || CM ==
"medium" || CM ==
"large";
2921 CmdArgs.push_back(Args.MakeArgString(
"-mcmodel=" + CM));
2923 D.Diag(diag::err_drv_unsupported_option_argument_for_target)
2924 << A->getSpelling() << CM << Triple.getTriple();
2928 if (Triple.getArch() == llvm::Triple::x86_64) {
2929 bool IsMediumCM =
false;
2930 bool IsLargeCM =
false;
2931 if (Arg *A = Args.getLastArg(options::OPT_mcmodel_EQ)) {
2932 IsMediumCM = StringRef(A->getValue()) ==
"medium";
2933 IsLargeCM = StringRef(A->getValue()) ==
"large";
2935 if (Arg *A = Args.getLastArg(options::OPT_mlarge_data_threshold_EQ)) {
2936 if (!IsMediumCM && !IsLargeCM) {
2937 D.Diag(diag::warn_drv_large_data_threshold_invalid_code_model)
2938 << A->getOption().getRenderName();
2940 A->render(Args, CmdArgs);
2942 }
else if (IsMediumCM) {
2943 CmdArgs.push_back(
"-mlarge-data-threshold=65536");
2944 }
else if (IsLargeCM) {
2945 CmdArgs.push_back(
"-mlarge-data-threshold=0");
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 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 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 std::string getAMDGPUTargetGPU(const llvm::Triple &T, const ArgList &Args)
Get the (LLVM) name of the AMDGPU gpu we are targeting.
static bool mustUseNonLeafFramePointerForTarget(const llvm::Triple &Triple)
static bool shouldIgnoreUnsupportedTargetFeature(const Arg &TargetFeatureArg, llvm::Triple T, StringRef Processor)
Defines the clang::LangOptions interface.
llvm::MachO::Target Target
Defines types useful for describing an Objective-C runtime.
Defines version macros and version-related utility functions for Clang.
const char * 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...
OpenMPRuntimeKind getOpenMPRuntime(const llvm::opt::ArgList &Args) const
Compute the desired OpenMP runtime from the flags provided.
DiagnosticBuilder Diag(unsigned DiagID) const
StringRef getFlangF128MathLibrary() const
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::vector< std::string > flags_list
bool needsFuzzerInterceptors() const
bool needsHwasanAliasesRt() const
bool needsStatsRt() const
bool needsMemProfRt() const
bool needsCfiDiagRt() const
bool linkRuntimes() const
bool needsUbsanRt() const
bool needsHwasanRt() const
bool hasCrossDsoCfi() const
bool hasMemtagHeap() const
bool needsSafeStackRt() const
bool requiresMinimalRuntime() const
bool hasMemtagStack() const
bool needsDfsanRt() const
bool needsScudoRt() const
const std::string & getMemtagMode() const
bool needsSharedRt() const
bool linkCXXRuntimes() 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.
bool willEmitRemarks(const llvm::opt::ArgList &Args)
The JSON file list parser is used to communicate input to InstallAPI.
llvm::StringRef getProcessorFromTargetID(const llvm::Triple &T, llvm::StringRef OffloadArch)
Get processor name from target ID.
const FunctionProtoType * T
static constexpr ResponseFileSupport AtFileCurCP()