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);
1147 for (
const Arg *A : Args.filtered(options::OPT_Wa_COMMA)) {
1148 for (StringRef
V : A->getValues()) {
1151 else if (
V ==
"--no-crel")
1159 if (Triple.isOSBinFormatELF() && !Triple.isMIPS()) {
1160 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) +
"-crel"));
1162 D.Diag(diag::err_drv_unsupported_opt_for_target)
1163 <<
"-Wa,--crel" <<
D.getTargetTriple();
1169 const ArgList &Args,
1170 ArgStringList &CmdArgs) {
1175 llvm::sys::path::append(DefaultLibPath, CLANG_INSTALL_LIBDIR_BASENAME);
1176 CmdArgs.push_back(Args.MakeArgString(
"-L" + DefaultLibPath));
1180 ArgStringList &CmdArgs) {
1181 if (!Args.hasFlag(options::OPT_frtlib_add_rpath,
1182 options::OPT_fno_rtlib_add_rpath,
false))
1187 CandidateRPaths.emplace_back(*CandidateRPath);
1189 for (
const auto &CandidateRPath : CandidateRPaths) {
1190 if (TC.
getVFS().exists(CandidateRPath)) {
1191 CmdArgs.push_back(
"-rpath");
1192 CmdArgs.push_back(Args.MakeArgString(CandidateRPath));
1198 const ToolChain &TC,
const ArgList &Args,
1199 bool ForceStaticHostRuntime,
bool IsOffloadingHost,
1201 if (!Args.hasFlag(options::OPT_fopenmp, options::OPT_fopenmp_EQ,
1202 options::OPT_fno_openmp,
false)) {
1204 if (Args.hasFlag(options::OPT_foffload_via_llvm,
1205 options::OPT_fno_offload_via_llvm,
false))
1206 CmdArgs.push_back(
"-lomptarget");
1216 if (ForceStaticHostRuntime)
1217 CmdArgs.push_back(
"-Bstatic");
1221 CmdArgs.push_back(
"-lomp");
1224 CmdArgs.push_back(
"-lgomp");
1227 CmdArgs.push_back(
"-liomp5");
1233 if (ForceStaticHostRuntime)
1234 CmdArgs.push_back(
"-Bdynamic");
1237 CmdArgs.push_back(
"-lrt");
1239 if (IsOffloadingHost)
1240 CmdArgs.push_back(
"-lomptarget");
1242 if (IsOffloadingHost && !Args.hasArg(options::OPT_nogpulib))
1243 CmdArgs.push_back(
"-lomptarget.devicertl");
1254 const llvm::opt::ArgList &Args,
1255 llvm::opt::ArgStringList &CmdArgs) {
1261 constexpr llvm::StringLiteral Targets(
"-fopenmp-targets=");
1265 std::transform(TCRange.first, TCRange.second, std::back_inserter(Triples),
1266 [](
auto TC) { return TC.second->getTripleString(); });
1268 Args.MakeArgString(Twine(Targets) + llvm::join(Triples,
",")));
1273 llvm::opt::ArgStringList &CmdArgs) {
1278 if (!TC.
getTriple().isKnownWindowsMSVCEnvironment()) {
1280 F128LibName.consume_front_insensitive(
"lib");
1281 if (!F128LibName.empty()) {
1282 bool AsNeeded = !TC.
getTriple().isOSAIX();
1283 CmdArgs.push_back(
"-lFortranFloat128Math");
1286 CmdArgs.push_back(Args.MakeArgString(
"-l" + F128LibName));
1290 CmdArgs.push_back(
"-lFortranRuntime");
1291 CmdArgs.push_back(
"-lFortranDecimal");
1296 const llvm::opt::ArgList &Args,
1297 ArgStringList &CmdArgs) {
1304 llvm::sys::path::append(DefaultLibPath,
"lib");
1305 if (TC.
getTriple().isKnownWindowsMSVCEnvironment())
1306 CmdArgs.push_back(Args.MakeArgString(
"-libpath:" + DefaultLibPath));
1308 CmdArgs.push_back(Args.MakeArgString(
"-L" + DefaultLibPath));
1312 ArgStringList &CmdArgs, StringRef Sanitizer,
1313 bool IsShared,
bool IsWhole) {
1316 if (IsWhole) CmdArgs.push_back(
"--whole-archive");
1319 if (IsWhole) CmdArgs.push_back(
"--no-whole-archive");
1329 ArgStringList &CmdArgs,
1330 StringRef Sanitizer) {
1335 if (TC.
getTriple().isOSSolaris() && !LinkerIsGnuLd)
1338 if (llvm::sys::fs::exists(SanRT +
".syms")) {
1339 CmdArgs.push_back(Args.MakeArgString(
"--dynamic-list=" + SanRT +
".syms"));
1346 const llvm::opt::ArgList &Args,
1347 llvm::opt::ArgStringList &CmdArgs,
1350 "AIX linker does not support any form of --as-needed option yet.");
1358 if (TC.
getTriple().isOSSolaris() && !LinkerIsGnuLd) {
1359 CmdArgs.push_back(
"-z");
1360 CmdArgs.push_back(as_needed ?
"ignore" :
"record");
1362 CmdArgs.push_back(as_needed ?
"--as-needed" :
"--no-as-needed");
1367 const llvm::opt::ArgList &Args,
1368 ArgStringList &CmdArgs) {
1373 if (TC.
getTriple().getOS() != llvm::Triple::RTEMS &&
1375 CmdArgs.push_back(
"-lpthread");
1377 CmdArgs.push_back(
"-lrt");
1379 CmdArgs.push_back(
"-lm");
1383 TC.
getTriple().getOS() != llvm::Triple::RTEMS)
1384 CmdArgs.push_back(
"-ldl");
1389 CmdArgs.push_back(
"-lexecinfo");
1395 CmdArgs.push_back(
"-lresolv");
1409 SharedRuntimes.push_back(
"asan");
1410 if (!Args.hasArg(options::OPT_shared) && !TC.
getTriple().isAndroid())
1411 HelperStaticRuntimes.push_back(
"asan-preinit");
1414 SharedRuntimes.push_back(
"memprof");
1415 if (!Args.hasArg(options::OPT_shared) && !TC.
getTriple().isAndroid())
1416 HelperStaticRuntimes.push_back(
"memprof-preinit");
1419 SharedRuntimes.push_back(
"nsan");
1422 SharedRuntimes.push_back(
"ubsan_minimal");
1424 SharedRuntimes.push_back(
"ubsan_standalone");
1427 SharedRuntimes.push_back(
"scudo_standalone");
1430 SharedRuntimes.push_back(
"tsan");
1433 SharedRuntimes.push_back(
"hwasan_aliases");
1435 SharedRuntimes.push_back(
"hwasan");
1436 if (!Args.hasArg(options::OPT_shared))
1437 HelperStaticRuntimes.push_back(
"hwasan-preinit");
1443 StaticRuntimes.push_back(
"stats_client");
1447 HelperStaticRuntimes.push_back(
"asan_static");
1450 if (Args.hasArg(options::OPT_shared)) {
1459 StaticRuntimes.push_back(
"asan");
1461 StaticRuntimes.push_back(
"asan_cxx");
1465 StaticRuntimes.push_back(
"memprof");
1467 StaticRuntimes.push_back(
"memprof_cxx");
1472 StaticRuntimes.push_back(
"hwasan_aliases");
1474 StaticRuntimes.push_back(
"hwasan_aliases_cxx");
1476 StaticRuntimes.push_back(
"hwasan");
1478 StaticRuntimes.push_back(
"hwasan_cxx");
1482 StaticRuntimes.push_back(
"dfsan");
1484 StaticRuntimes.push_back(
"lsan");
1486 StaticRuntimes.push_back(
"msan");
1488 StaticRuntimes.push_back(
"msan_cxx");
1491 StaticRuntimes.push_back(
"nsan");
1493 StaticRuntimes.push_back(
"tsan");
1495 StaticRuntimes.push_back(
"tsan_cxx");
1499 StaticRuntimes.push_back(
"ubsan_minimal");
1501 StaticRuntimes.push_back(
"ubsan_standalone");
1503 StaticRuntimes.push_back(
"ubsan_standalone_cxx");
1507 NonWholeStaticRuntimes.push_back(
"safestack");
1508 RequiredSymbols.push_back(
"__safestack_init");
1512 StaticRuntimes.push_back(
"cfi");
1514 StaticRuntimes.push_back(
"cfi_diag");
1516 StaticRuntimes.push_back(
"ubsan_standalone_cxx");
1520 NonWholeStaticRuntimes.push_back(
"stats");
1521 RequiredSymbols.push_back(
"__sanitizer_stats_register");
1524 StaticRuntimes.push_back(
"scudo_standalone");
1526 StaticRuntimes.push_back(
"scudo_standalone_cxx");
1533 ArgStringList &CmdArgs) {
1536 NonWholeStaticRuntimes, HelperStaticRuntimes, RequiredSymbols;
1539 NonWholeStaticRuntimes, HelperStaticRuntimes,
1544 for (
auto S : RequiredSymbols) {
1545 CmdArgs.push_back(
"-u");
1546 CmdArgs.push_back(Args.MakeArgString(S));
1551 !Args.hasArg(options::OPT_shared)) {
1557 if (!Args.hasArg(clang::driver::options::OPT_nostdlibxx)) {
1558 bool OnlyLibstdcxxStatic = Args.hasArg(options::OPT_static_libstdcxx) &&
1559 !Args.hasArg(options::OPT_static);
1560 if (OnlyLibstdcxxStatic)
1561 CmdArgs.push_back(
"-Bstatic");
1563 if (OnlyLibstdcxxStatic)
1564 CmdArgs.push_back(
"-Bdynamic");
1568 for (
auto RT : SharedRuntimes)
1570 for (
auto RT : HelperStaticRuntimes)
1572 bool AddExportDynamic =
false;
1573 for (
auto RT : StaticRuntimes) {
1577 for (
auto RT : NonWholeStaticRuntimes) {
1583 if (AddExportDynamic)
1584 CmdArgs.push_back(
"--export-dynamic");
1587 CmdArgs.push_back(
"--export-dynamic-symbol=__cfi_check");
1591 TC.
getDriver().
Diag(diag::err_drv_unsupported_opt_for_target)
1592 <<
"-fsanitize=memtag*" << TC.
getTriple().str();
1595 Args.MakeArgString(
"--android-memtag-mode=" + SanArgs.
getMemtagMode()));
1597 CmdArgs.push_back(
"--android-memtag-heap");
1599 CmdArgs.push_back(
"--android-memtag-stack");
1602 return !StaticRuntimes.empty() || !NonWholeStaticRuntimes.empty();
1606 if (Args.hasArg(options::OPT_shared))
1610 CmdArgs.push_back(
"--whole-archive");
1614 CmdArgs.push_back(
"--no-whole-archive");
1622 const llvm::opt::ArgList &Args,
1623 ArgStringList &CmdArgs) {
1625 CmdArgs.push_back(
"-lpthread");
1627 CmdArgs.push_back(
"-lrt");
1628 CmdArgs.push_back(
"-lm");
1633 CmdArgs.push_back(
"-ldl");
1638 if (Arg *A = Args.getLastArg(options::OPT_O_Group))
1639 return !A->getOption().matches(options::OPT_O0);
1647 auto AddPostfix = [JA](
auto &F) {
1652 if (Arg *A = Args.getLastArg(options::OPT_gsplit_dwarf_EQ))
1653 if (StringRef(A->getValue()) ==
"single" && Output.
isFilename())
1657 if (
const Arg *A = Args.getLastArg(options::OPT_dumpdir)) {
1660 Arg *FinalOutput = Args.getLastArg(options::OPT_o, options::OPT__SLASH_o);
1661 if (FinalOutput && Args.hasArg(options::OPT_c)) {
1662 T = FinalOutput->getValue();
1663 llvm::sys::path::remove_filename(
T);
1664 llvm::sys::path::append(
T,
1665 llvm::sys::path::stem(FinalOutput->getValue()));
1667 return Args.MakeArgString(
T);
1673 return Args.MakeArgString(
T);
1677 const JobAction &JA,
const ArgList &Args,
1678 const InputInfo &Output,
const char *OutFile) {
1679 ArgStringList ExtractArgs;
1680 ExtractArgs.push_back(
"--extract-dwo");
1682 ArgStringList StripArgs;
1683 StripArgs.push_back(
"--strip-dwo");
1688 ExtractArgs.push_back(OutFile);
1695 C.addCommand(std::make_unique<Command>(JA,
T,
1697 Exec, ExtractArgs, II, Output));
1700 C.addCommand(std::make_unique<Command>(
1710 Args.ClaimAllArgs(options::OPT_flto_EQ);
1711 Args.ClaimAllArgs(options::OPT_flto);
1712 Args.ClaimAllArgs(options::OPT_fno_lto);
1716 auto *CSPGOGenerateArg = Args.getLastArg(options::OPT_fcs_profile_generate,
1717 options::OPT_fcs_profile_generate_EQ,
1718 options::OPT_fno_profile_generate);
1719 if (CSPGOGenerateArg &&
1720 CSPGOGenerateArg->getOption().matches(options::OPT_fno_profile_generate))
1721 CSPGOGenerateArg =
nullptr;
1723 return CSPGOGenerateArg;
1727 auto *ProfileUseArg = Args.getLastArg(
1728 options::OPT_fprofile_instr_use, options::OPT_fprofile_instr_use_EQ,
1729 options::OPT_fprofile_use, options::OPT_fprofile_use_EQ,
1730 options::OPT_fno_profile_instr_use);
1732 if (ProfileUseArg &&
1733 ProfileUseArg->getOption().matches(options::OPT_fno_profile_instr_use))
1734 ProfileUseArg =
nullptr;
1736 return ProfileUseArg;
1740 auto *ProfileSampleUseArg = Args.getLastArg(
1741 options::OPT_fprofile_sample_use, options::OPT_fprofile_sample_use_EQ,
1742 options::OPT_fauto_profile, options::OPT_fauto_profile_EQ,
1743 options::OPT_fno_profile_sample_use, options::OPT_fno_auto_profile);
1745 if (ProfileSampleUseArg &&
1746 (ProfileSampleUseArg->getOption().matches(
1747 options::OPT_fno_profile_sample_use) ||
1748 ProfileSampleUseArg->getOption().matches(options::OPT_fno_auto_profile)))
1751 return Args.getLastArg(options::OPT_fprofile_sample_use_EQ,
1752 options::OPT_fauto_profile_EQ);
1757 case llvm::Reloc::Static:
1759 case llvm::Reloc::PIC_:
1761 case llvm::Reloc::DynamicNoPIC:
1762 return "dynamic-no-pic";
1763 case llvm::Reloc::ROPI:
1765 case llvm::Reloc::RWPI:
1767 case llvm::Reloc::ROPI_RWPI:
1770 llvm_unreachable(
"Unknown Reloc::Model kind");
1777std::tuple<llvm::Reloc::Model, unsigned, bool>
1785 if (Triple.isOSBinFormatMachO() && Args.hasArg(options::OPT_static))
1787 bool IsPICLevelTwo = PIC;
1790 Args.hasArg(options::OPT_mkernel, options::OPT_fapple_kext);
1793 if (Triple.isAndroid()) {
1794 switch (Triple.getArch()) {
1795 case llvm::Triple::arm:
1796 case llvm::Triple::armeb:
1797 case llvm::Triple::thumb:
1798 case llvm::Triple::thumbeb:
1799 case llvm::Triple::aarch64:
1800 case llvm::Triple::mips:
1801 case llvm::Triple::mipsel:
1802 case llvm::Triple::mips64:
1803 case llvm::Triple::mips64el:
1807 case llvm::Triple::x86:
1808 case llvm::Triple::x86_64:
1810 IsPICLevelTwo =
true;
1819 if (Triple.isOHOSFamily() && Triple.getArch() == llvm::Triple::aarch64)
1823 if (Triple.isOSOpenBSD()) {
1825 case llvm::Triple::arm:
1826 case llvm::Triple::aarch64:
1827 case llvm::Triple::mips64:
1828 case llvm::Triple::mips64el:
1829 case llvm::Triple::x86:
1830 case llvm::Triple::x86_64:
1831 IsPICLevelTwo =
false;
1834 case llvm::Triple::ppc:
1835 case llvm::Triple::sparcv9:
1836 IsPICLevelTwo =
true;
1848 Arg *LastPICArg = Args.getLastArg(options::OPT_fPIC, options::OPT_fno_PIC,
1849 options::OPT_fpic, options::OPT_fno_pic,
1850 options::OPT_fPIE, options::OPT_fno_PIE,
1851 options::OPT_fpie, options::OPT_fno_pie);
1852 if (Triple.isOSWindows() && !Triple.isOSCygMing() && LastPICArg &&
1853 LastPICArg == Args.getLastArg(options::OPT_fPIC, options::OPT_fpic,
1854 options::OPT_fPIE, options::OPT_fpie)) {
1856 << LastPICArg->getSpelling() << Triple.str();
1857 if (Triple.getArch() == llvm::Triple::x86_64)
1858 return std::make_tuple(llvm::Reloc::PIC_, 2U,
false);
1859 return std::make_tuple(llvm::Reloc::Static, 0
U,
false);
1866 Option O = LastPICArg->getOption();
1867 if (O.matches(options::OPT_fPIC) || O.matches(options::OPT_fpic) ||
1868 O.matches(options::OPT_fPIE) || O.matches(options::OPT_fpie)) {
1869 PIE = O.matches(options::OPT_fPIE) || O.matches(options::OPT_fpie);
1871 PIE || O.matches(options::OPT_fPIC) || O.matches(options::OPT_fpic);
1873 O.matches(options::OPT_fPIE) || O.matches(options::OPT_fPIC);
1876 if (EffectiveTriple.isPS()) {
1877 Arg *ModelArg = Args.getLastArg(options::OPT_mcmodel_EQ);
1878 StringRef Model = ModelArg ? ModelArg->getValue() :
"";
1879 if (Model !=
"kernel") {
1882 << LastPICArg->getSpelling()
1883 << (EffectiveTriple.isPS4() ?
"PS4" :
"PS5");
1893 if (PIC && (Triple.isOSDarwin() || EffectiveTriple.isPS()))
1899 ((!EffectiveTriple.isiOS() || EffectiveTriple.isOSVersionLT(6)) &&
1900 !EffectiveTriple.isWatchOS() && !EffectiveTriple.isDriverKit()))
1903 if (Arg *A = Args.getLastArg(options::OPT_mdynamic_no_pic)) {
1906 if (!Triple.isOSDarwin())
1908 << A->getSpelling() << Triple.str();
1917 return std::make_tuple(llvm::Reloc::DynamicNoPIC, PIC ? 2U : 0
U,
false);
1920 bool EmbeddedPISupported;
1921 switch (Triple.getArch()) {
1922 case llvm::Triple::arm:
1923 case llvm::Triple::armeb:
1924 case llvm::Triple::thumb:
1925 case llvm::Triple::thumbeb:
1926 EmbeddedPISupported =
true;
1929 EmbeddedPISupported =
false;
1933 bool ROPI =
false, RWPI =
false;
1934 Arg* LastROPIArg = Args.getLastArg(options::OPT_fropi, options::OPT_fno_ropi);
1935 if (LastROPIArg && LastROPIArg->getOption().matches(options::OPT_fropi)) {
1936 if (!EmbeddedPISupported)
1938 << LastROPIArg->getSpelling() << Triple.str();
1941 Arg *LastRWPIArg = Args.getLastArg(options::OPT_frwpi, options::OPT_fno_rwpi);
1942 if (LastRWPIArg && LastRWPIArg->getOption().matches(options::OPT_frwpi)) {
1943 if (!EmbeddedPISupported)
1945 << LastRWPIArg->getSpelling() << Triple.str();
1950 if ((ROPI || RWPI) && (PIC || PIE))
1953 if (Triple.isMIPS()) {
1960 if (ABIName ==
"n64")
1963 if(Args.hasArg(options::OPT_mno_abicalls))
1964 return std::make_tuple(llvm::Reloc::Static, 0
U,
false);
1967 IsPICLevelTwo =
false;
1971 return std::make_tuple(llvm::Reloc::PIC_, IsPICLevelTwo ? 2U : 1U, PIE);
1973 llvm::Reloc::Model RelocM = llvm::Reloc::Static;
1975 RelocM = llvm::Reloc::ROPI_RWPI;
1977 RelocM = llvm::Reloc::ROPI;
1979 RelocM = llvm::Reloc::RWPI;
1981 return std::make_tuple(RelocM, 0
U,
false);
2001 const ArgList &Args) {
2002 const Arg *A = Args.getLastArg(options::OPT_falign_functions,
2003 options::OPT_falign_functions_EQ,
2004 options::OPT_fno_align_functions);
2005 if (!A || A->getOption().matches(options::OPT_fno_align_functions))
2008 if (A->getOption().matches(options::OPT_falign_functions))
2012 if (StringRef(A->getValue()).getAsInteger(10,
Value) ||
Value > 65536)
2014 << A->getAsString(Args) << A->getValue();
2019 ArgStringList &CmdArgs, llvm::codegenoptions::DebugInfoKind DebugInfoKind) {
2020 switch (DebugInfoKind) {
2021 case llvm::codegenoptions::DebugDirectivesOnly:
2022 CmdArgs.push_back(
"-debug-info-kind=line-directives-only");
2024 case llvm::codegenoptions::DebugLineTablesOnly:
2025 CmdArgs.push_back(
"-debug-info-kind=line-tables-only");
2027 case llvm::codegenoptions::DebugInfoConstructor:
2028 CmdArgs.push_back(
"-debug-info-kind=constructor");
2030 case llvm::codegenoptions::LimitedDebugInfo:
2031 CmdArgs.push_back(
"-debug-info-kind=limited");
2033 case llvm::codegenoptions::FullDebugInfo:
2034 CmdArgs.push_back(
"-debug-info-kind=standalone");
2036 case llvm::codegenoptions::UnusedTypeInfo:
2037 CmdArgs.push_back(
"-debug-info-kind=unused-types");
2047 assert(A.getOption().matches(options::OPT_gN_Group) &&
2048 "Not a -g option that specifies a debug-info level");
2049 if (A.getOption().matches(options::OPT_g0) ||
2050 A.getOption().matches(options::OPT_ggdb0))
2051 return llvm::codegenoptions::NoDebugInfo;
2052 if (A.getOption().matches(options::OPT_gline_tables_only) ||
2053 A.getOption().matches(options::OPT_ggdb1))
2054 return llvm::codegenoptions::DebugLineTablesOnly;
2055 if (A.getOption().matches(options::OPT_gline_directives_only))
2056 return llvm::codegenoptions::DebugDirectivesOnly;
2057 return llvm::codegenoptions::DebugInfoConstructor;
2061 const ArgList &Args) {
2062 const Arg *A = Args.getLastArg(options::OPT_fdebug_default_version);
2068 if (StringRef(A->getValue()).getAsInteger(10,
Value) ||
Value > 5 ||
2071 << A->getAsString(Args) << A->getValue();
2076 return llvm::StringSwitch<unsigned>(ArgValue)
2077 .Case(
"-gdwarf-2", 2)
2078 .Case(
"-gdwarf-3", 3)
2079 .Case(
"-gdwarf-4", 4)
2080 .Case(
"-gdwarf-5", 5)
2085 return Args.getLastArg(options::OPT_gdwarf_2, options::OPT_gdwarf_3,
2086 options::OPT_gdwarf_4, options::OPT_gdwarf_5,
2087 options::OPT_gdwarf);
2091 const llvm::opt::ArgList &Args) {
2096 if (DwarfVersion == 5 && TC.
getTriple().isOSAIX())
2097 TC.
getDriver().
Diag(diag::err_drv_unsupported_opt_for_target)
2098 << GDwarfN->getSpelling() << TC.
getTriple().str();
2100 if (DwarfVersion == 0) {
2102 assert(DwarfVersion &&
"toolchain default DWARF version must be nonzero");
2104 return DwarfVersion;
2108 ArgStringList &CmdArgs) {
2109 llvm::Reloc::Model RelocationModel;
2114 if (RelocationModel != llvm::Reloc::Static)
2115 CmdArgs.push_back(
"-KPIC");
2121 return Args.hasFlag(options::OPT_fobjc_arc, options::OPT_fno_objc_arc,
false);
2127 const ArgList &Args) {
2128 if (Args.hasArg(options::OPT_static_libgcc) ||
2129 Args.hasArg(options::OPT_static) || Args.hasArg(options::OPT_static_pie) ||
2133 if (Args.hasArg(options::OPT_shared_libgcc))
2152 ArgStringList &CmdArgs,
const ArgList &Args) {
2156 CmdArgs.push_back(
"-l:libunwind.a");
2179 CmdArgs.push_back(
"-lgcc_eh");
2181 CmdArgs.push_back(
"-lgcc_s");
2189 CmdArgs.push_back(
"-lunwind");
2191 CmdArgs.push_back(
"-l:libunwind.a");
2194 CmdArgs.push_back(
"-l:libunwind.dll.a");
2196 CmdArgs.push_back(
"-l:libunwind.so");
2200 CmdArgs.push_back(
"-lunwind");
2210 ArgStringList &CmdArgs,
const ArgList &Args) {
2214 CmdArgs.push_back(
"-lgcc");
2218 CmdArgs.push_back(
"-lgcc");
2222 ArgStringList &CmdArgs,
const ArgList &Args) {
2233 if (TC.
getTriple().isKnownWindowsMSVCEnvironment()) {
2236 Arg *A = Args.getLastArg(options::OPT_rtlib_EQ);
2237 if (A && A->getValue() != StringRef(
"platform")) {
2238 TC.
getDriver().
Diag(diag::err_drv_unsupported_rtlib_for_platform)
2239 << A->getValue() <<
"MSVC";
2249 if (TC.
getTriple().isAndroid() && !Args.hasArg(options::OPT_static) &&
2250 !Args.hasArg(options::OPT_static_pie))
2251 CmdArgs.push_back(
"-ldl");
2258 const Arg *A = Args.getLastArg(options::OPT_save_stats_EQ);
2259 if (!A && !
D.CCPrintInternalStats)
2264 StringRef SaveStats = A->getValue();
2265 if (SaveStats ==
"obj" && Output.
isFilename()) {
2267 llvm::sys::path::remove_filename(StatsFile);
2268 }
else if (SaveStats !=
"cwd") {
2269 D.Diag(diag::err_drv_invalid_value) << A->getAsString(Args) << SaveStats;
2273 StringRef BaseName = llvm::sys::path::filename(Input.
getBaseInput());
2274 llvm::sys::path::append(StatsFile, BaseName);
2275 llvm::sys::path::replace_extension(StatsFile,
"stats");
2277 assert(
D.CCPrintInternalStats);
2278 StatsFile.assign(
D.CCPrintInternalStatReportFilename.empty()
2280 :
D.CCPrintInternalStatReportFilename);
2287 assert(Flag.front() ==
'-');
2289 Flags.push_back(Flag.str());
2291 Flags.push_back((
"!" + Flag.substr(1)).str());
2296 ArgStringList &CmdArgs,
bool IsLTO,
2297 const StringRef PluginOptPrefix) {
2298 auto addArg = [&, IsLTO](
const Twine &Arg) {
2300 assert(!PluginOptPrefix.empty() &&
"Cannot have empty PluginOptPrefix!");
2301 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) + Arg));
2303 CmdArgs.push_back(
"-mllvm");
2304 CmdArgs.push_back(Args.MakeArgString(Arg));
2308 if (Args.hasArg(options::OPT_mbranches_within_32B_boundaries)) {
2309 addArg(Twine(
"-x86-branches-within-32B-boundaries"));
2311 if (
const Arg *A = Args.getLastArg(options::OPT_malign_branch_boundary_EQ)) {
2312 StringRef
Value = A->getValue();
2314 if (
Value.getAsInteger(10, Boundary) || Boundary < 16 ||
2315 !llvm::isPowerOf2_64(Boundary)) {
2316 D.Diag(diag::err_drv_invalid_argument_to_option)
2317 <<
Value << A->getOption().getName();
2319 addArg(
"-x86-align-branch-boundary=" + Twine(Boundary));
2322 if (
const Arg *A = Args.getLastArg(options::OPT_malign_branch_EQ)) {
2323 std::string AlignBranch;
2324 for (StringRef
T : A->getValues()) {
2325 if (
T !=
"fused" &&
T !=
"jcc" &&
T !=
"jmp" &&
T !=
"call" &&
2326 T !=
"ret" &&
T !=
"indirect")
2327 D.Diag(diag::err_drv_invalid_malign_branch_EQ)
2328 <<
T <<
"fused, jcc, jmp, call, ret, indirect";
2329 if (!AlignBranch.empty())
2333 addArg(
"-x86-align-branch=" + Twine(AlignBranch));
2335 if (
const Arg *A = Args.getLastArg(options::OPT_mpad_max_prefix_size_EQ)) {
2336 StringRef
Value = A->getValue();
2337 unsigned PrefixSize;
2338 if (
Value.getAsInteger(10, PrefixSize)) {
2339 D.Diag(diag::err_drv_invalid_argument_to_option)
2340 <<
Value << A->getOption().getName();
2342 addArg(
"-x86-pad-max-prefix-size=" + Twine(PrefixSize));
2368 llvm::opt::ArgStringList &CC1Args,
2370 StringRef Lib, StringRef Arch, StringRef
Target,
2371 bool isBitCodeSDL) {
2374 std::string LibDeviceLoc =
"/libdevice";
2375 std::string LibBcPrefix =
"/libbc-";
2376 std::string LibPrefix =
"/lib";
2393 for (StringRef
Base : {LibBcPrefix, LibPrefix}) {
2394 const auto *Ext =
Base.contains(LibBcPrefix) ?
".a" :
".bc";
2396 for (
auto Suffix : {Twine(Lib +
"-" + Arch +
"-" +
Target).str(),
2397 Twine(Lib +
"-" + Arch).str(), Twine(Lib).str()}) {
2398 SDLs.push_back(Twine(LibDeviceLoc +
Base + Suffix + Ext).str());
2399 SDLs.push_back(Twine(
Base + Suffix + Ext).str());
2409 const auto *Ext =
".a";
2411 for (
auto Suffix : {Twine(Lib +
"-" + Arch +
"-" +
Target).str(),
2412 Twine(Lib +
"-" + Arch).str()}) {
2413 SDLs.push_back(Twine(LibDeviceLoc + LibPrefix + Suffix + Ext).str());
2414 SDLs.push_back(Twine(LibPrefix + Suffix + Ext).str());
2425 bool FoundSDL =
false;
2426 for (
auto LPath : LibraryPaths) {
2427 for (
auto SDL : SDLs) {
2428 auto FullName = Twine(LPath + SDL).str();
2429 if (llvm::sys::fs::exists(
FullName)) {
2430 CC1Args.push_back(DriverArgs.MakeArgString(
FullName));
2447 const InputInfoList &Inputs,
const llvm::opt::ArgList &DriverArgs,
2448 llvm::opt::ArgStringList &CC1Args,
2450 StringRef Arch, StringRef
Target,
bool isBitCodeSDL) {
2453 if (isBitCodeSDL && Arch.contains(
"nvptx"))
2456 bool FoundAOB =
false;
2457 std::string ArchiveOfBundles;
2459 llvm::Triple Triple(
D.getTargetTriple());
2460 bool IsMSVC = Triple.isWindowsMSVCEnvironment();
2461 auto Ext = IsMSVC ?
".lib" :
".a";
2462 if (!Lib.starts_with(
":") && !Lib.starts_with(
"-l")) {
2463 if (llvm::sys::fs::exists(Lib)) {
2464 ArchiveOfBundles = Lib;
2468 Lib.consume_front(
"-l");
2469 for (
auto LPath : LibraryPaths) {
2470 ArchiveOfBundles.clear();
2471 auto LibFile = (Lib.starts_with(
":") ? Lib.drop_front()
2472 : IsMSVC ? Lib + Ext
2473 :
"lib" + Lib + Ext)
2475 for (
auto Prefix : {
"/libdevice/",
"/"}) {
2476 auto AOB = Twine(LPath + Prefix + LibFile).str();
2477 if (llvm::sys::fs::exists(AOB)) {
2478 ArchiveOfBundles = AOB;
2491 llvm::file_magic Magic;
2492 auto EC = llvm::identify_magic(ArchiveOfBundles, Magic);
2493 if (EC || Magic != llvm::file_magic::archive)
2496 StringRef Prefix = isBitCodeSDL ?
"libbc-" :
"lib";
2497 std::string OutputLib =
2498 D.GetTemporaryPath(Twine(Prefix + llvm::sys::path::filename(Lib) +
"-" +
2503 C.addTempFile(
C.getArgs().MakeArgString(OutputLib));
2505 ArgStringList CmdArgs;
2508 DeviceTriple +=
'-';
2509 std::string NormalizedTriple =
T.getToolChain().getTriple().normalize();
2510 DeviceTriple += NormalizedTriple;
2512 DeviceTriple +=
'-';
2516 std::string UnbundleArg(
"-unbundle");
2517 std::string TypeArg(
"-type=a");
2518 std::string InputArg(
"-input=" + ArchiveOfBundles);
2519 std::string OffloadArg(
"-targets=" + std::string(DeviceTriple));
2520 std::string OutputArg(
"-output=" + OutputLib);
2522 const char *UBProgram = DriverArgs.MakeArgString(
2523 T.getToolChain().GetProgramPath(
"clang-offload-bundler"));
2525 ArgStringList UBArgs;
2526 UBArgs.push_back(
C.getArgs().MakeArgString(UnbundleArg));
2527 UBArgs.push_back(
C.getArgs().MakeArgString(TypeArg));
2528 UBArgs.push_back(
C.getArgs().MakeArgString(InputArg));
2529 UBArgs.push_back(
C.getArgs().MakeArgString(OffloadArg));
2530 UBArgs.push_back(
C.getArgs().MakeArgString(OutputArg));
2534 std::string AdditionalArgs(
"-allow-missing-bundles");
2535 UBArgs.push_back(
C.getArgs().MakeArgString(AdditionalArgs));
2540 std::string HipCompatibleArgs(
"-hip-openmp-compatible");
2541 UBArgs.push_back(
C.getArgs().MakeArgString(HipCompatibleArgs));
2543 C.addCommand(std::make_unique<Command>(
2545 InputInfo(&JA,
C.getArgs().MakeArgString(OutputLib))));
2547 CC1Args.push_back(DriverArgs.MakeArgString(OutputLib));
2556 const llvm::opt::ArgList &DriverArgs,
2557 llvm::opt::ArgStringList &CC1Args,
2558 StringRef Arch, StringRef
Target,
2559 bool isBitCodeSDL) {
2561 Arch,
Target, isBitCodeSDL);
2590 const llvm::opt::ArgList &DriverArgs,
2591 llvm::opt::ArgStringList &CC1Args,
2592 StringRef Arch, StringRef
Target,
2593 bool isBitCodeSDL) {
2597 std::optional<std::string> LibPath =
2598 llvm::sys::Process::GetEnv(
"LIBRARY_PATH");
2601 const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator,
'\0'};
2602 llvm::SplitString(*LibPath, Frags, EnvPathSeparatorStr);
2603 for (StringRef
Path : Frags)
2604 LibraryPaths.emplace_back(
Path.trim());
2608 for (std::string Search_Dir : DriverArgs.getAllArgValues(options::OPT_L))
2609 LibraryPaths.emplace_back(Search_Dir);
2613 llvm::sys::path::append(DefaultLibPath, CLANG_INSTALL_LIBDIR_BASENAME);
2614 LibraryPaths.emplace_back(DefaultLibPath.c_str());
2617 llvm::SmallSet<std::string, 16> SDLNames;
2618 static const StringRef HostOnlyArchives[] = {
2619 "omp",
"cudart",
"m",
"gcc",
"gcc_s",
"pthread",
"hip_hcc"};
2620 for (
auto SDLName : DriverArgs.getAllArgValues(options::OPT_l)) {
2621 if (!llvm::is_contained(HostOnlyArchives, SDLName)) {
2622 SDLNames.insert(std::string(
"-l") + SDLName);
2626 for (
auto Input : DriverArgs.getAllArgValues(options::OPT_INPUT)) {
2633 const StringRef LibFileExt =
".lib";
2634 if (!llvm::sys::path::has_extension(
FileName) ||
2636 llvm::sys::path::extension(
FileName).drop_front()) ==
2638 llvm::sys::path::extension(
FileName) == LibFileExt)
2639 SDLNames.insert(Input);
2646 for (
auto SDLName : SDLNames) {
2648 if (!
SDLSearch(
D, DriverArgs, CC1Args, LibraryPaths, SDLName, Arch,
Target,
2651 LibraryPaths, SDLName, Arch,
Target,
2657static llvm::opt::Arg *
2659 return Args.getLastArg(options::OPT_mcode_object_version_EQ);
2663 const llvm::opt::ArgList &Args) {
2664 const unsigned MinCodeObjVer = 4;
2665 const unsigned MaxCodeObjVer = 6;
2668 if (CodeObjArg->getOption().getID() ==
2669 options::OPT_mcode_object_version_EQ) {
2670 unsigned CodeObjVer = MaxCodeObjVer;
2672 StringRef(CodeObjArg->getValue()).getAsInteger(0, CodeObjVer);
2673 if (Remnant || CodeObjVer < MinCodeObjVer || CodeObjVer > MaxCodeObjVer)
2674 D.Diag(diag::err_drv_invalid_int_value)
2675 << CodeObjArg->getAsString(Args) << CodeObjArg->getValue();
2680 if (CodeObjVer == 6)
2681 D.Diag(diag::warn_drv_amdgpu_cov6);
2687 const llvm::opt::ArgList &Args) {
2688 unsigned CodeObjVer = 4;
2690 StringRef(CodeObjArg->getValue()).getAsInteger(0, CodeObjVer);
2695 const Driver &
D,
const llvm::opt::ArgList &Args) {
2700 const llvm::opt::ArgList &Args,
2701 llvm::opt::ArgStringList &CmdArgs,
2702 const llvm::Triple &Triple,
bool IsLTO,
2703 const StringRef PluginOptPrefix) {
2704 auto addArg = [&, IsLTO](
const Twine &Arg) {
2706 assert(!PluginOptPrefix.empty() &&
"Cannot have empty PluginOptPrefix!");
2707 CmdArgs.push_back(Args.MakeArgString(Twine(PluginOptPrefix) + Arg));
2709 CmdArgs.push_back(
"-mllvm");
2710 CmdArgs.push_back(Args.MakeArgString(Arg));
2714 if (Arg *A = Args.getLastArg(options::OPT_moutline,
2715 options::OPT_mno_outline)) {
2716 if (A->getOption().matches(options::OPT_moutline)) {
2720 if (!(Triple.isARM() || Triple.isThumb() || Triple.isAArch64())) {
2721 D.Diag(diag::warn_drv_moutline_unsupported_opt) << Triple.getArchName();
2723 addArg(Twine(
"-enable-machine-outliner"));
2727 addArg(Twine(
"-enable-machine-outliner=never"));
2733 const llvm::opt::ArgList &DriverArgs,
2734 llvm::opt::ArgStringList &CC1Args,
2735 StringRef BitcodeSuffix,
2736 const llvm::Triple &Triple,
2741 std::optional<std::string> LibPath =
2742 llvm::sys::Process::GetEnv(
"LIBRARY_PATH");
2745 const char EnvPathSeparatorStr[] = {llvm::sys::EnvPathSeparator,
'\0'};
2746 llvm::SplitString(*LibPath, Frags, EnvPathSeparatorStr);
2747 for (StringRef
Path : Frags)
2748 LibraryPaths.emplace_back(
Path.trim());
2753 LibraryPaths.emplace_back(LibPath);
2755 OptSpecifier LibomptargetBCPathOpt =
2756 Triple.isAMDGCN() ? options::OPT_libomptarget_amdgpu_bc_path_EQ
2757 : options::OPT_libomptarget_nvptx_bc_path_EQ;
2759 StringRef ArchPrefix = Triple.isAMDGCN() ?
"amdgpu" :
"nvptx";
2760 std::string LibOmpTargetName =
2761 (
"libomptarget-" + ArchPrefix +
"-" + BitcodeSuffix +
".bc").str();
2764 if (
const Arg *A = DriverArgs.getLastArg(LibomptargetBCPathOpt)) {
2766 if (llvm::sys::fs::exists(LibOmpTargetFile) &&
2767 llvm::sys::fs::is_directory(LibOmpTargetFile)) {
2768 llvm::sys::path::append(LibOmpTargetFile, LibOmpTargetName);
2771 if (llvm::sys::fs::exists(LibOmpTargetFile)) {
2772 CC1Args.push_back(
"-mlink-builtin-bitcode");
2773 CC1Args.push_back(DriverArgs.MakeArgString(LibOmpTargetFile));
2775 D.Diag(diag::err_drv_omp_offload_target_bcruntime_not_found)
2776 << LibOmpTargetFile;
2779 bool FoundBCLibrary =
false;
2781 for (StringRef LibraryPath : LibraryPaths) {
2783 llvm::sys::path::append(LibOmpTargetFile, LibOmpTargetName);
2784 if (llvm::sys::fs::exists(LibOmpTargetFile)) {
2785 CC1Args.push_back(
"-mlink-builtin-bitcode");
2786 CC1Args.push_back(DriverArgs.MakeArgString(LibOmpTargetFile));
2787 FoundBCLibrary =
true;
2792 if (!FoundBCLibrary)
2793 D.Diag(diag::err_drv_omp_offload_target_missingbcruntime)
2794 << LibOmpTargetName << ArchPrefix;
2798 const llvm::opt::ArgList &Args,
2799 llvm::opt::ArgStringList &CmdArgs) {
2801 !Args.hasArg(options::OPT_nostdlib) &&
2802 !Args.hasArg(options::OPT_no_hip_rt) && !Args.hasArg(options::OPT_r)) {
2806 for (
auto *Arg : Args.filtered(options::OPT_no_hip_rt)) {
2813 const llvm::opt::ArgList &Args,
2814 llvm::opt::ArgStringList &CmdArgs,
2815 const llvm::Triple &Triple) {
2816 if (Arg *A = Args.getLastArg(options::OPT_moutline_atomics,
2817 options::OPT_mno_outline_atomics)) {
2819 if (!Triple.isAArch64()) {
2820 D.Diag(diag::warn_drv_moutline_atomics_unsupported_opt)
2821 << Triple.getArchName() << A->getOption().getName();
2823 if (A->getOption().matches(options::OPT_moutline_atomics)) {
2824 CmdArgs.push_back(
"-target-feature");
2825 CmdArgs.push_back(
"+outline-atomics");
2827 CmdArgs.push_back(
"-target-feature");
2828 CmdArgs.push_back(
"-outline-atomics");
2832 CmdArgs.push_back(
"-target-feature");
2833 CmdArgs.push_back(
"+outline-atomics");
2838 llvm::opt::ArgStringList &CmdArgs) {
2839 if (TCArgs.hasFlag(options::OPT_offload_compress,
2840 options::OPT_no_offload_compress,
false))
2841 CmdArgs.push_back(
"-compress");
2842 if (TCArgs.hasArg(options::OPT_v))
2843 CmdArgs.push_back(
"-verbose");
2844 if (
auto *Arg = TCArgs.getLastArg(options::OPT_offload_compression_level_EQ))
2846 TCArgs.MakeArgString(Twine(
"-compression-level=") + Arg->getValue()));
2850 const llvm::Triple &Triple,
2851 const llvm::Reloc::Model &RelocationModel,
2852 llvm::opt::ArgStringList &CmdArgs) {
2853 if (Arg *A = Args.getLastArg(options::OPT_mcmodel_EQ)) {
2854 StringRef CM = A->getValue();
2856 if (Triple.isOSAIX() && CM ==
"medium")
2858 if (Triple.isAArch64(64)) {
2859 Ok = CM ==
"tiny" || CM ==
"small" || CM ==
"large";
2860 if (CM ==
"large" && !Triple.isOSBinFormatMachO() &&
2861 RelocationModel != llvm::Reloc::Static)
2862 D.Diag(diag::err_drv_argument_only_allowed_with)
2863 << A->getAsString(Args) <<
"-fno-pic";
2864 }
else if (Triple.isLoongArch()) {
2865 if (CM ==
"extreme" &&
2866 Args.hasFlagNoClaim(options::OPT_fplt, options::OPT_fno_plt,
false))
2867 D.Diag(diag::err_drv_argument_not_allowed_with)
2868 << A->getAsString(Args) <<
"-fplt";
2869 Ok = CM ==
"normal" || CM ==
"medium" || CM ==
"extreme";
2872 CM = llvm::StringSwitch<StringRef>(CM)
2873 .Case(
"normal",
"small")
2874 .Case(
"extreme",
"large")
2876 }
else if (Triple.isPPC64() || Triple.isOSAIX()) {
2877 Ok = CM ==
"small" || CM ==
"medium" || CM ==
"large";
2878 }
else if (Triple.isRISCV()) {
2881 else if (CM ==
"medany")
2883 Ok = CM ==
"small" || CM ==
"medium";
2884 }
else if (Triple.getArch() == llvm::Triple::x86_64) {
2885 Ok = llvm::is_contained({
"small",
"kernel",
"medium",
"large",
"tiny"},
2887 }
else if (Triple.isNVPTX() || Triple.isAMDGPU() || Triple.isSPIRV()) {
2891 }
else if (Triple.isSPARC64()) {
2894 else if (CM ==
"medmid")
2896 else if (CM ==
"medany")
2898 Ok = CM ==
"small" || CM ==
"medium" || CM ==
"large";
2901 CmdArgs.push_back(Args.MakeArgString(
"-mcmodel=" + CM));
2903 D.Diag(diag::err_drv_unsupported_option_argument_for_target)
2904 << A->getSpelling() << CM << Triple.getTriple();
2908 if (Triple.getArch() == llvm::Triple::x86_64) {
2909 bool IsMediumCM =
false;
2910 bool IsLargeCM =
false;
2911 if (Arg *A = Args.getLastArg(options::OPT_mcmodel_EQ)) {
2912 IsMediumCM = StringRef(A->getValue()) ==
"medium";
2913 IsLargeCM = StringRef(A->getValue()) ==
"large";
2915 if (Arg *A = Args.getLastArg(options::OPT_mlarge_data_threshold_EQ)) {
2916 if (!IsMediumCM && !IsLargeCM) {
2917 D.Diag(diag::warn_drv_large_data_threshold_invalid_code_model)
2918 << A->getOption().getRenderName();
2920 A->render(Args, CmdArgs);
2922 }
else if (IsMediumCM) {
2923 CmdArgs.push_back(
"-mlarge-data-threshold=65536");
2924 }
else if (IsLargeCM) {
2925 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()