clang  14.0.0git
Hexagon.cpp
Go to the documentation of this file.
1 //===--- Hexagon.cpp - Hexagon ToolChain Implementations --------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "Hexagon.h"
10 #include "CommonArgs.h"
12 #include "clang/Driver/Driver.h"
14 #include "clang/Driver/InputInfo.h"
15 #include "clang/Driver/Options.h"
16 #include "llvm/ADT/StringExtras.h"
17 #include "llvm/Option/ArgList.h"
18 #include "llvm/Support/FileSystem.h"
19 #include "llvm/Support/Path.h"
20 #include "llvm/Support/VirtualFileSystem.h"
21 
22 using namespace clang::driver;
23 using namespace clang::driver::tools;
24 using namespace clang::driver::toolchains;
25 using namespace clang;
26 using namespace llvm::opt;
27 
28 // Default hvx-length for various versions.
29 static StringRef getDefaultHvxLength(StringRef Cpu) {
30  return llvm::StringSwitch<StringRef>(Cpu)
31  .Case("v60", "64b")
32  .Case("v62", "64b")
33  .Case("v65", "64b")
34  .Default("128b");
35 }
36 
37 static void handleHVXWarnings(const Driver &D, const ArgList &Args) {
38  // Handle the unsupported values passed to mhvx-length.
39  if (Arg *A = Args.getLastArg(options::OPT_mhexagon_hvx_length_EQ)) {
40  StringRef Val = A->getValue();
41  if (!Val.equals_insensitive("64b") && !Val.equals_insensitive("128b"))
42  D.Diag(diag::err_drv_unsupported_option_argument)
43  << A->getOption().getName() << Val;
44  }
45 }
46 
47 // Handle hvx target features explicitly.
48 static void handleHVXTargetFeatures(const Driver &D, const ArgList &Args,
49  std::vector<StringRef> &Features,
50  StringRef Cpu, bool &HasHVX) {
51  // Handle HVX warnings.
52  handleHVXWarnings(D, Args);
53 
54  // Add the +hvx* features based on commandline flags.
55  StringRef HVXFeature, HVXLength;
56 
57  // Handle -mhvx, -mhvx=, -mno-hvx.
58  if (Arg *A = Args.getLastArg(options::OPT_mno_hexagon_hvx,
59  options::OPT_mhexagon_hvx,
60  options::OPT_mhexagon_hvx_EQ)) {
61  if (A->getOption().matches(options::OPT_mno_hexagon_hvx))
62  return;
63  if (A->getOption().matches(options::OPT_mhexagon_hvx_EQ)) {
64  HasHVX = true;
65  HVXFeature = Cpu = A->getValue();
66  HVXFeature = Args.MakeArgString(llvm::Twine("+hvx") + HVXFeature.lower());
67  } else if (A->getOption().matches(options::OPT_mhexagon_hvx)) {
68  HasHVX = true;
69  HVXFeature = Args.MakeArgString(llvm::Twine("+hvx") + Cpu);
70  }
71  Features.push_back(HVXFeature);
72  }
73 
74  // Handle -mhvx-length=.
75  if (Arg *A = Args.getLastArg(options::OPT_mhexagon_hvx_length_EQ)) {
76  // These flags are valid only if HVX in enabled.
77  if (!HasHVX)
78  D.Diag(diag::err_drv_invalid_hvx_length);
79  else if (A->getOption().matches(options::OPT_mhexagon_hvx_length_EQ))
80  HVXLength = A->getValue();
81  }
82  // Default hvx-length based on Cpu.
83  else if (HasHVX)
84  HVXLength = getDefaultHvxLength(Cpu);
85 
86  if (!HVXLength.empty()) {
87  HVXFeature =
88  Args.MakeArgString(llvm::Twine("+hvx-length") + HVXLength.lower());
89  Features.push_back(HVXFeature);
90  }
91 }
92 
93 // Hexagon target features.
94 void hexagon::getHexagonTargetFeatures(const Driver &D, const ArgList &Args,
95  std::vector<StringRef> &Features) {
96  handleTargetFeaturesGroup(Args, Features,
97  options::OPT_m_hexagon_Features_Group);
98 
99  bool UseLongCalls = false;
100  if (Arg *A = Args.getLastArg(options::OPT_mlong_calls,
101  options::OPT_mno_long_calls)) {
102  if (A->getOption().matches(options::OPT_mlong_calls))
103  UseLongCalls = true;
104  }
105 
106  Features.push_back(UseLongCalls ? "+long-calls" : "-long-calls");
107 
108  bool HasHVX = false;
110  // 't' in Cpu denotes tiny-core micro-architecture. For now, the co-processors
111  // have no dependency on micro-architecture.
112  const bool TinyCore = Cpu.contains('t');
113 
114  if (TinyCore)
115  Cpu = Cpu.take_front(Cpu.size() - 1);
116 
117  handleHVXTargetFeatures(D, Args, Features, Cpu, HasHVX);
118 
119  if (HexagonToolChain::isAutoHVXEnabled(Args) && !HasHVX)
120  D.Diag(diag::warn_drv_vectorize_needs_hvx);
121 }
122 
123 // Hexagon tools start.
125  ArgStringList &CmdArgs) const {
126 }
127 
129  const InputInfo &Output,
130  const InputInfoList &Inputs,
131  const ArgList &Args,
132  const char *LinkingOutput) const {
133  claimNoWarnArgs(Args);
134 
135  auto &HTC = static_cast<const toolchains::HexagonToolChain&>(getToolChain());
136  const Driver &D = HTC.getDriver();
137  ArgStringList CmdArgs;
138 
139  CmdArgs.push_back("--arch=hexagon");
140 
141  RenderExtraToolArgs(JA, CmdArgs);
142 
143  const char *AsName = "llvm-mc";
144  CmdArgs.push_back("-filetype=obj");
145  CmdArgs.push_back(Args.MakeArgString(
146  "-mcpu=hexagon" +
148 
149  addSanitizerRuntimes(HTC, Args, CmdArgs);
150 
151  if (Output.isFilename()) {
152  CmdArgs.push_back("-o");
153  CmdArgs.push_back(Output.getFilename());
154  } else {
155  assert(Output.isNothing() && "Unexpected output");
156  CmdArgs.push_back("-fsyntax-only");
157  }
158 
160  CmdArgs.push_back(Args.MakeArgString("-gpsize=" + Twine(G.getValue())));
161  }
162 
163  Args.AddAllArgValues(CmdArgs, options::OPT_Wa_COMMA, options::OPT_Xassembler);
164 
165  // Only pass -x if gcc will understand it; otherwise hope gcc
166  // understands the suffix correctly. The main use case this would go
167  // wrong in is for linker inputs if they happened to have an odd
168  // suffix; really the only way to get this to happen is a command
169  // like '-x foobar a.c' which will treat a.c like a linker input.
170  //
171  // FIXME: For the linker case specifically, can we safely convert
172  // inputs into '-Wl,' options?
173  for (const auto &II : Inputs) {
174  // Don't try to pass LLVM or AST inputs to a generic gcc.
175  if (types::isLLVMIR(II.getType()))
176  D.Diag(clang::diag::err_drv_no_linker_llvm_support)
177  << HTC.getTripleString();
178  else if (II.getType() == types::TY_AST)
179  D.Diag(clang::diag::err_drv_no_ast_support)
180  << HTC.getTripleString();
181  else if (II.getType() == types::TY_ModuleFile)
182  D.Diag(diag::err_drv_no_module_support)
183  << HTC.getTripleString();
184 
185  if (II.isFilename())
186  CmdArgs.push_back(II.getFilename());
187  else
188  // Don't render as input, we need gcc to do the translations.
189  // FIXME: What is this?
190  II.getInputArg().render(Args, CmdArgs);
191  }
192 
193  auto *Exec = Args.MakeArgString(HTC.GetProgramPath(AsName));
194  C.addCommand(std::make_unique<Command>(JA, *this,
196  Exec, CmdArgs, Inputs, Output));
197 }
198 
200  ArgStringList &CmdArgs) const {
201 }
202 
203 static void
205  const toolchains::HexagonToolChain &HTC,
206  const InputInfo &Output, const InputInfoList &Inputs,
207  const ArgList &Args, ArgStringList &CmdArgs,
208  const char *LinkingOutput) {
209 
210  const Driver &D = HTC.getDriver();
211 
212  //----------------------------------------------------------------------------
213  //
214  //----------------------------------------------------------------------------
215  bool IsStatic = Args.hasArg(options::OPT_static);
216  bool IsShared = Args.hasArg(options::OPT_shared);
217  bool IsPIE = Args.hasArg(options::OPT_pie);
218  bool IncStdLib = !Args.hasArg(options::OPT_nostdlib);
219  bool IncStartFiles = !Args.hasArg(options::OPT_nostartfiles);
220  bool IncDefLibs = !Args.hasArg(options::OPT_nodefaultlibs);
221  bool UseG0 = false;
222  const char *Exec = Args.MakeArgString(HTC.GetLinkerPath());
223  bool UseLLD = (llvm::sys::path::filename(Exec).equals_insensitive("ld.lld") ||
224  llvm::sys::path::stem(Exec).equals_insensitive("ld.lld"));
225  bool UseShared = IsShared && !IsStatic;
226  StringRef CpuVer = toolchains::HexagonToolChain::GetTargetCPUVersion(Args);
227 
228  bool NeedsSanitizerDeps = addSanitizerRuntimes(HTC, Args, CmdArgs);
229 
230  //----------------------------------------------------------------------------
231  // Silence warnings for various options
232  //----------------------------------------------------------------------------
233  Args.ClaimAllArgs(options::OPT_g_Group);
234  Args.ClaimAllArgs(options::OPT_emit_llvm);
235  Args.ClaimAllArgs(options::OPT_w); // Other warning options are already
236  // handled somewhere else.
237  Args.ClaimAllArgs(options::OPT_static_libgcc);
238 
239  //----------------------------------------------------------------------------
240  //
241  //----------------------------------------------------------------------------
242  if (Args.hasArg(options::OPT_s))
243  CmdArgs.push_back("-s");
244 
245  if (Args.hasArg(options::OPT_r))
246  CmdArgs.push_back("-r");
247 
248  for (const auto &Opt : HTC.ExtraOpts)
249  CmdArgs.push_back(Opt.c_str());
250 
251  if (!UseLLD) {
252  CmdArgs.push_back("-march=hexagon");
253  CmdArgs.push_back(Args.MakeArgString("-mcpu=hexagon" + CpuVer));
254  }
255 
256  if (IsShared) {
257  CmdArgs.push_back("-shared");
258  // The following should be the default, but doing as hexagon-gcc does.
259  CmdArgs.push_back("-call_shared");
260  }
261 
262  if (IsStatic)
263  CmdArgs.push_back("-static");
264 
265  if (IsPIE && !IsShared)
266  CmdArgs.push_back("-pie");
267 
269  CmdArgs.push_back(Args.MakeArgString("-G" + Twine(G.getValue())));
270  UseG0 = G.getValue() == 0;
271  }
272 
273  CmdArgs.push_back("-o");
274  CmdArgs.push_back(Output.getFilename());
275 
276  if (HTC.getTriple().isMusl()) {
277  if (!Args.hasArg(options::OPT_shared, options::OPT_static))
278  CmdArgs.push_back("-dynamic-linker=/lib/ld-musl-hexagon.so.1");
279 
280  if (!Args.hasArg(options::OPT_shared, options::OPT_nostartfiles,
281  options::OPT_nostdlib))
282  CmdArgs.push_back(Args.MakeArgString(D.SysRoot + "/usr/lib/crt1.o"));
283  else if (Args.hasArg(options::OPT_shared) &&
284  !Args.hasArg(options::OPT_nostartfiles, options::OPT_nostdlib))
285  CmdArgs.push_back(Args.MakeArgString(D.SysRoot + "/usr/lib/crti.o"));
286 
287  CmdArgs.push_back(
288  Args.MakeArgString(StringRef("-L") + D.SysRoot + "/usr/lib"));
289  Args.AddAllArgs(CmdArgs,
290  {options::OPT_T_Group, options::OPT_e, options::OPT_s,
291  options::OPT_t, options::OPT_u_Group});
292  AddLinkerInputs(HTC, Inputs, Args, CmdArgs, JA);
293 
294  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs)) {
295  if (NeedsSanitizerDeps) {
296  linkSanitizerRuntimeDeps(HTC, CmdArgs);
297 
298  CmdArgs.push_back("-lunwind");
299  }
300 
301  CmdArgs.push_back("-lclang_rt.builtins-hexagon");
302  CmdArgs.push_back("-lc");
303  }
304  if (D.CCCIsCXX()) {
305  if (HTC.ShouldLinkCXXStdlib(Args))
306  HTC.AddCXXStdlibLibArgs(Args, CmdArgs);
307  }
308  return;
309  }
310 
311  //----------------------------------------------------------------------------
312  // moslib
313  //----------------------------------------------------------------------------
314  std::vector<std::string> OsLibs;
315  bool HasStandalone = false;
316  for (const Arg *A : Args.filtered(options::OPT_moslib_EQ)) {
317  A->claim();
318  OsLibs.emplace_back(A->getValue());
319  HasStandalone = HasStandalone || (OsLibs.back() == "standalone");
320  }
321  if (OsLibs.empty()) {
322  OsLibs.push_back("standalone");
323  HasStandalone = true;
324  }
325 
326  //----------------------------------------------------------------------------
327  // Start Files
328  //----------------------------------------------------------------------------
329  const std::string MCpuSuffix = "/" + CpuVer.str();
330  const std::string MCpuG0Suffix = MCpuSuffix + "/G0";
331  const std::string RootDir =
333  const std::string StartSubDir =
334  "hexagon/lib" + (UseG0 ? MCpuG0Suffix : MCpuSuffix);
335 
336  auto Find = [&HTC] (const std::string &RootDir, const std::string &SubDir,
337  const char *Name) -> std::string {
338  std::string RelName = SubDir + Name;
339  std::string P = HTC.GetFilePath(RelName.c_str());
340  if (llvm::sys::fs::exists(P))
341  return P;
342  return RootDir + RelName;
343  };
344 
345  if (IncStdLib && IncStartFiles) {
346  if (!IsShared) {
347  if (HasStandalone) {
348  std::string Crt0SA = Find(RootDir, StartSubDir, "/crt0_standalone.o");
349  CmdArgs.push_back(Args.MakeArgString(Crt0SA));
350  }
351  std::string Crt0 = Find(RootDir, StartSubDir, "/crt0.o");
352  CmdArgs.push_back(Args.MakeArgString(Crt0));
353  }
354  std::string Init = UseShared
355  ? Find(RootDir, StartSubDir + "/pic", "/initS.o")
356  : Find(RootDir, StartSubDir, "/init.o");
357  CmdArgs.push_back(Args.MakeArgString(Init));
358  }
359 
360  //----------------------------------------------------------------------------
361  // Library Search Paths
362  //----------------------------------------------------------------------------
363  const ToolChain::path_list &LibPaths = HTC.getFilePaths();
364  for (const auto &LibPath : LibPaths)
365  CmdArgs.push_back(Args.MakeArgString(StringRef("-L") + LibPath));
366 
367  //----------------------------------------------------------------------------
368  //
369  //----------------------------------------------------------------------------
370  Args.AddAllArgs(CmdArgs,
371  {options::OPT_T_Group, options::OPT_e, options::OPT_s,
372  options::OPT_t, options::OPT_u_Group});
373 
374  AddLinkerInputs(HTC, Inputs, Args, CmdArgs, JA);
375 
376  //----------------------------------------------------------------------------
377  // Libraries
378  //----------------------------------------------------------------------------
379  if (IncStdLib && IncDefLibs) {
380  if (D.CCCIsCXX()) {
381  if (HTC.ShouldLinkCXXStdlib(Args))
382  HTC.AddCXXStdlibLibArgs(Args, CmdArgs);
383  CmdArgs.push_back("-lm");
384  }
385 
386  CmdArgs.push_back("--start-group");
387 
388  if (!IsShared) {
389  for (StringRef Lib : OsLibs)
390  CmdArgs.push_back(Args.MakeArgString("-l" + Lib));
391  CmdArgs.push_back("-lc");
392  }
393  CmdArgs.push_back("-lgcc");
394 
395  CmdArgs.push_back("--end-group");
396  }
397 
398  //----------------------------------------------------------------------------
399  // End files
400  //----------------------------------------------------------------------------
401  if (IncStdLib && IncStartFiles) {
402  std::string Fini = UseShared
403  ? Find(RootDir, StartSubDir + "/pic", "/finiS.o")
404  : Find(RootDir, StartSubDir, "/fini.o");
405  CmdArgs.push_back(Args.MakeArgString(Fini));
406  }
407 }
408 
410  const InputInfo &Output,
411  const InputInfoList &Inputs,
412  const ArgList &Args,
413  const char *LinkingOutput) const {
414  auto &HTC = static_cast<const toolchains::HexagonToolChain&>(getToolChain());
415 
416  ArgStringList CmdArgs;
417  constructHexagonLinkArgs(C, JA, HTC, Output, Inputs, Args, CmdArgs,
418  LinkingOutput);
419 
420  const char *Exec = Args.MakeArgString(HTC.GetLinkerPath());
421  C.addCommand(std::make_unique<Command>(JA, *this,
423  Exec, CmdArgs, Inputs, Output));
424 }
425 // Hexagon tools end.
426 
427 /// Hexagon Toolchain
428 
429 std::string HexagonToolChain::getHexagonTargetDir(
430  const std::string &InstalledDir,
431  const SmallVectorImpl<std::string> &PrefixDirs) const {
432  std::string InstallRelDir;
433  const Driver &D = getDriver();
434 
435  // Locate the rest of the toolchain ...
436  for (auto &I : PrefixDirs)
437  if (D.getVFS().exists(I))
438  return I;
439 
440  if (getVFS().exists(InstallRelDir = InstalledDir + "/../target"))
441  return InstallRelDir;
442 
443  return InstalledDir;
444 }
445 
446 Optional<unsigned> HexagonToolChain::getSmallDataThreshold(
447  const ArgList &Args) {
448  StringRef Gn = "";
449  if (Arg *A = Args.getLastArg(options::OPT_G)) {
450  Gn = A->getValue();
451  } else if (Args.getLastArg(options::OPT_shared, options::OPT_fpic,
452  options::OPT_fPIC)) {
453  Gn = "0";
454  }
455 
456  unsigned G;
457  if (!Gn.getAsInteger(10, G))
458  return G;
459 
460  return None;
461 }
462 
463 std::string HexagonToolChain::getCompilerRTPath() const {
464  SmallString<128> Dir(getDriver().SysRoot);
465  llvm::sys::path::append(Dir, "usr", "lib");
466  Dir += SelectedMultilib.gccSuffix();
467  return std::string(Dir.str());
468 }
469 
470 void HexagonToolChain::getHexagonLibraryPaths(const ArgList &Args,
471  ToolChain::path_list &LibPaths) const {
472  const Driver &D = getDriver();
473 
474  //----------------------------------------------------------------------------
475  // -L Args
476  //----------------------------------------------------------------------------
477  for (Arg *A : Args.filtered(options::OPT_L))
478  for (const char *Value : A->getValues())
479  LibPaths.push_back(Value);
480 
481  //----------------------------------------------------------------------------
482  // Other standard paths
483  //----------------------------------------------------------------------------
484  std::vector<std::string> RootDirs;
485  std::copy(D.PrefixDirs.begin(), D.PrefixDirs.end(),
486  std::back_inserter(RootDirs));
487 
488  std::string TargetDir = getHexagonTargetDir(D.getInstalledDir(),
489  D.PrefixDirs);
490  if (!llvm::is_contained(RootDirs, TargetDir))
491  RootDirs.push_back(TargetDir);
492 
493  bool HasPIC = Args.hasArg(options::OPT_fpic, options::OPT_fPIC);
494  // Assume G0 with -shared.
495  bool HasG0 = Args.hasArg(options::OPT_shared);
496  if (auto G = getSmallDataThreshold(Args))
497  HasG0 = G.getValue() == 0;
498 
499  const std::string CpuVer = GetTargetCPUVersion(Args).str();
500  for (auto &Dir : RootDirs) {
501  std::string LibDir = Dir + "/hexagon/lib";
502  std::string LibDirCpu = LibDir + '/' + CpuVer;
503  if (HasG0) {
504  if (HasPIC)
505  LibPaths.push_back(LibDirCpu + "/G0/pic");
506  LibPaths.push_back(LibDirCpu + "/G0");
507  }
508  LibPaths.push_back(LibDirCpu);
509  LibPaths.push_back(LibDir);
510  }
511 }
512 
513 HexagonToolChain::HexagonToolChain(const Driver &D, const llvm::Triple &Triple,
514  const llvm::opt::ArgList &Args)
515  : Linux(D, Triple, Args) {
516  const std::string TargetDir = getHexagonTargetDir(D.getInstalledDir(),
517  D.PrefixDirs);
518 
519  // Note: Generic_GCC::Generic_GCC adds InstalledDir and getDriver().Dir to
520  // program paths
521  const std::string BinDir(TargetDir + "/bin");
522  if (D.getVFS().exists(BinDir))
523  getProgramPaths().push_back(BinDir);
524 
525  ToolChain::path_list &LibPaths = getFilePaths();
526 
527  // Remove paths added by Linux toolchain. Currently Hexagon_TC really targets
528  // 'elf' OS type, so the Linux paths are not appropriate. When we actually
529  // support 'linux' we'll need to fix this up
530  LibPaths.clear();
531  getHexagonLibraryPaths(Args, LibPaths);
532 }
533 
535 
536 void HexagonToolChain::AddCXXStdlibLibArgs(const ArgList &Args,
537  ArgStringList &CmdArgs) const {
539  switch (Type) {
541  CmdArgs.push_back("-lc++");
542  CmdArgs.push_back("-lc++abi");
543  CmdArgs.push_back("-lunwind");
544  break;
545 
547  CmdArgs.push_back("-lstdc++");
548  break;
549  }
550 }
551 
553  return new tools::hexagon::Assembler(*this);
554 }
555 
557  return new tools::hexagon::Linker(*this);
558 }
559 
561  const llvm::opt::ArgList &DriverArgs) const {
562  // Copied in large part from lib/Frontend/CompilerInvocation.cpp.
563  Arg *A = DriverArgs.getLastArg(options::OPT_O_Group);
564  if (!A)
565  return 0;
566 
567  if (A->getOption().matches(options::OPT_O0))
568  return 0;
569  if (A->getOption().matches(options::OPT_Ofast) ||
570  A->getOption().matches(options::OPT_O4))
571  return 3;
572  assert(A->getNumValues() != 0);
573  StringRef S(A->getValue());
574  if (S == "s" || S == "z" || S.empty())
575  return 2;
576  if (S == "g")
577  return 1;
578 
579  unsigned OptLevel;
580  if (S.getAsInteger(10, OptLevel))
581  return 0;
582  return OptLevel;
583 }
584 
585 void HexagonToolChain::addClangTargetOptions(const ArgList &DriverArgs,
586  ArgStringList &CC1Args,
587  Action::OffloadKind) const {
588 
589  bool UseInitArrayDefault = getTriple().isMusl();
590 
591  if (!DriverArgs.hasFlag(options::OPT_fuse_init_array,
592  options::OPT_fno_use_init_array,
593  UseInitArrayDefault))
594  CC1Args.push_back("-fno-use-init-array");
595 
596  if (DriverArgs.hasArg(options::OPT_ffixed_r19)) {
597  CC1Args.push_back("-target-feature");
598  CC1Args.push_back("+reserved-r19");
599  }
600  if (isAutoHVXEnabled(DriverArgs)) {
601  CC1Args.push_back("-mllvm");
602  CC1Args.push_back("-hexagon-autohvx");
603  }
604 }
605 
606 void HexagonToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
607  ArgStringList &CC1Args) const {
608  if (DriverArgs.hasArg(options::OPT_nostdinc))
609  return;
610 
611  const bool IsELF = !getTriple().isMusl() && !getTriple().isOSLinux();
612  const bool IsLinuxMusl = getTriple().isMusl() && getTriple().isOSLinux();
613 
614  const Driver &D = getDriver();
615  SmallString<128> ResourceDirInclude(D.ResourceDir);
616  if (!IsELF) {
617  llvm::sys::path::append(ResourceDirInclude, "include");
618  if (!DriverArgs.hasArg(options::OPT_nobuiltininc) &&
619  (!IsLinuxMusl || DriverArgs.hasArg(options::OPT_nostdlibinc)))
620  addSystemInclude(DriverArgs, CC1Args, ResourceDirInclude);
621  }
622  if (DriverArgs.hasArg(options::OPT_nostdlibinc))
623  return;
624 
625  const bool HasSysRoot = !D.SysRoot.empty();
626  if (HasSysRoot) {
628  if (IsLinuxMusl)
629  llvm::sys::path::append(P, "usr/include");
630  else
631  llvm::sys::path::append(P, "include");
632 
633  addExternCSystemInclude(DriverArgs, CC1Args, P.str());
634  // LOCAL_INCLUDE_DIR
635  addSystemInclude(DriverArgs, CC1Args, P + "/usr/local/include");
636  // TOOL_INCLUDE_DIR
637  AddMultilibIncludeArgs(DriverArgs, CC1Args);
638  }
639 
640  if (!DriverArgs.hasArg(options::OPT_nobuiltininc) && IsLinuxMusl)
641  addSystemInclude(DriverArgs, CC1Args, ResourceDirInclude);
642 
643  if (HasSysRoot)
644  return;
646  D.PrefixDirs);
647  addExternCSystemInclude(DriverArgs, CC1Args, TargetDir + "/hexagon/include");
648 }
649 
651  const llvm::opt::ArgList &DriverArgs,
652  llvm::opt::ArgStringList &CC1Args) const {
653  const Driver &D = getDriver();
654  if (!D.SysRoot.empty() && getTriple().isMusl())
655  addLibStdCXXIncludePaths(D.SysRoot + "/usr/include/c++/v1", "", "",
656  DriverArgs, CC1Args);
657  else if (getTriple().isMusl())
658  addLibStdCXXIncludePaths("/usr/include/c++/v1", "", "", DriverArgs,
659  CC1Args);
660  else {
662  addLibStdCXXIncludePaths(TargetDir + "/hexagon/include/c++/v1", "", "",
663  DriverArgs, CC1Args);
664  }
665 }
667  const llvm::opt::ArgList &DriverArgs,
668  llvm::opt::ArgStringList &CC1Args) const {
669  const Driver &D = getDriver();
671  addLibStdCXXIncludePaths(TargetDir + "/hexagon/include/c++", "", "",
672  DriverArgs, CC1Args);
673 }
674 
676 HexagonToolChain::GetCXXStdlibType(const ArgList &Args) const {
677  Arg *A = Args.getLastArg(options::OPT_stdlib_EQ);
678  if (!A) {
679  if (getTriple().isMusl())
680  return ToolChain::CST_Libcxx;
681  else
683  }
684  StringRef Value = A->getValue();
685  if (Value != "libstdc++" && Value != "libc++")
686  getDriver().Diag(diag::err_drv_invalid_stdlib_name) << A->getAsString(Args);
687 
688  if (Value == "libstdc++")
690  else if (Value == "libc++")
691  return ToolChain::CST_Libcxx;
692  else
694 }
695 
696 bool HexagonToolChain::isAutoHVXEnabled(const llvm::opt::ArgList &Args) {
697  if (Arg *A = Args.getLastArg(options::OPT_fvectorize,
698  options::OPT_fno_vectorize))
699  return A->getOption().matches(options::OPT_fvectorize);
700  return false;
701 }
702 
703 //
704 // Returns the default CPU for Hexagon. This is the default compilation target
705 // if no Hexagon processor is selected at the command-line.
706 //
708  return "hexagonv60";
709 }
710 
711 StringRef HexagonToolChain::GetTargetCPUVersion(const ArgList &Args) {
712  Arg *CpuArg = nullptr;
713  if (Arg *A = Args.getLastArg(options::OPT_mcpu_EQ))
714  CpuArg = A;
715 
716  StringRef CPU = CpuArg ? CpuArg->getValue() : GetDefaultCPU();
717  if (CPU.startswith("hexagon"))
718  return CPU.substr(sizeof("hexagon") - 1);
719  return CPU;
720 }
clang::driver::toolchains
Definition: AIX.h:55
clang::driver::Driver::PrefixDirs
prefix_list PrefixDirs
Definition: Driver.h:148
clang::driver::toolchains::HexagonToolChain::getSmallDataThreshold
static Optional< unsigned > getSmallDataThreshold(const llvm::opt::ArgList &Args)
Definition: Hexagon.cpp:446
clang::driver::ToolChain::getProgramPaths
path_list & getProgramPaths()
Definition: ToolChain.h:262
clang::driver::tools::hexagon::Assembler::ConstructJob
void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override
ConstructJob - Construct jobs to perform the action JA, writing to Output and with Inputs,...
Definition: Hexagon.cpp:128
Driver.h
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
llvm::SmallVector
Definition: LLVM.h:38
clang::driver::toolchains::HexagonToolChain::GetTargetCPUVersion
static StringRef GetTargetCPUVersion(const llvm::opt::ArgList &Args)
Definition: Hexagon.cpp:711
clang::driver::tools
Definition: AIX.h:17
clang::driver::ToolChain::getDriver
const Driver & getDriver() const
Definition: ToolChain.h:221
llvm::Optional< unsigned >
handleHVXTargetFeatures
static void handleHVXTargetFeatures(const Driver &D, const ArgList &Args, std::vector< StringRef > &Features, StringRef Cpu, bool &HasHVX)
Definition: Hexagon.cpp:48
clang::driver::toolchains::HexagonToolChain
Definition: Hexagon.h:61
clang::driver::ToolChain::GetFilePath
std::string GetFilePath(const char *Name) const
Definition: ToolChain.cpp:536
clang::driver::toolchains::HexagonToolChain::addLibCxxIncludePaths
void addLibCxxIncludePaths(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
Definition: Hexagon.cpp:650
clang::driver::toolchains::HexagonToolChain::AddClangSystemIncludeArgs
void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
Add the clang cc1 arguments for system include paths.
Definition: Hexagon.cpp:606
clang::driver::ToolChain::GetLinkerPath
std::string GetLinkerPath(bool *LinkerIsLLD=nullptr, bool *LinkerIsLLDDarwinNew=nullptr) const
Returns the linker path, respecting the -fuse-ld= argument to determine the linker suffix or name.
Definition: ToolChain.cpp:544
clang::driver::InputInfo
InputInfo - Wrapper for information about an input source.
Definition: InputInfo.h:22
clang::driver::tools::hexagon::getHexagonTargetFeatures
void getHexagonTargetFeatures(const Driver &D, const llvm::opt::ArgList &Args, std::vector< StringRef > &Features)
clang::Type
The base class of the type hierarchy.
Definition: Type.h:1490
InputInfo.h
clang::driver::toolchains::HexagonToolChain::addClangTargetOptions
void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, Action::OffloadKind DeviceOffloadKind) const override
Add options that need to be passed to cc1 for this target.
Definition: Hexagon.cpp:585
clang::driver::toolchains::Generic_GCC::AddMultilibIncludeArgs
void AddMultilibIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const
Definition: Gnu.cpp:2853
clang::driver::Driver::InstalledDir
std::string InstalledDir
The path to the installed clang directory, if any.
Definition: Driver.h:132
clang::driver::tools::hexagon::Assembler::RenderExtraToolArgs
void RenderExtraToolArgs(const JobAction &JA, llvm::opt::ArgStringList &CmdArgs) const
Definition: Hexagon.cpp:124
clang::driver::tools::AddLinkerInputs
void AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const JobAction &JA)
clang::driver::ToolChain::getFilePaths
path_list & getFilePaths()
Definition: ToolChain.h:259
clang::driver::toolchains::HexagonToolChain::isAutoHVXEnabled
static bool isAutoHVXEnabled(const llvm::opt::ArgList &Args)
Definition: Hexagon.cpp:696
clang::driver::Driver::Diag
DiagnosticBuilder Diag(unsigned DiagID) const
Definition: Driver.h:112
clang::driver::Tool
Tool - Information on a specific compilation tool.
Definition: Tool.h:32
clang::driver::tools::claimNoWarnArgs
void claimNoWarnArgs(const llvm::opt::ArgList &Args)
Options.h
clang::driver::InputInfo::isFilename
bool isFilename() const
Definition: InputInfo.h:75
handleHVXWarnings
static void handleHVXWarnings(const Driver &D, const ArgList &Args)
Definition: Hexagon.cpp:37
clang::driver::toolchains::Linux::ExtraOpts
std::vector< std::string > ExtraOpts
Definition: Linux.h:57
clang::driver::toolchains::HexagonToolChain::getHexagonTargetDir
std::string getHexagonTargetDir(const std::string &InstalledDir, const SmallVectorImpl< std::string > &PrefixDirs) const
Hexagon Toolchain.
Definition: Hexagon.cpp:429
llvm::opt
Definition: DiagnosticOptions.h:19
DriverDiagnostic.h
clang::driver::ResponseFileSupport::AtFileCurCP
static constexpr ResponseFileSupport AtFileCurCP()
Definition: Job.h:92
clang::driver::InputInfo::isNothing
bool isNothing() const
Definition: InputInfo.h:74
clang::driver::tools::hexagon::Assembler
Definition: Hexagon.h:23
clang::driver::ToolChain::CXXStdlibType
CXXStdlibType
Definition: ToolChain.h:95
llvm::SmallString< 128 >
clang::driver::ToolChain::getTriple
const llvm::Triple & getTriple() const
Definition: ToolChain.h:223
clang::driver::Driver::SysRoot
std::string SysRoot
sysroot, if present
Definition: Driver.h:151
clang::driver::toolchains::Linux
Definition: Linux.h:19
clang::driver::ToolChain::CST_Libcxx
@ CST_Libcxx
Definition: ToolChain.h:96
clang::driver::Driver::CCCIsCXX
bool CCCIsCXX() const
Whether the driver should follow g++ like behavior.
Definition: Driver.h:179
clang::driver::toolchains::HexagonToolChain::buildAssembler
Tool * buildAssembler() const override
Definition: Hexagon.cpp:552
clang::driver::tools::handleTargetFeaturesGroup
void handleTargetFeaturesGroup(const llvm::opt::ArgList &Args, std::vector< StringRef > &Features, llvm::opt::OptSpecifier Group)
Iterate Args and convert -mxxx to +xxx and -mno-xxx to -xxx and append it to Features.
clang::driver::types::isLLVMIR
bool isLLVMIR(ID Id)
Is this LLVM IR.
Definition: Types.cpp:222
clang::driver::toolchains::HexagonToolChain::addLibStdCxxIncludePaths
void addLibStdCxxIncludePaths(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override
Definition: Hexagon.cpp:666
clang::driver::ToolChain::CST_Libstdcxx
@ CST_Libstdcxx
Definition: ToolChain.h:97
clang::driver::Driver::ResourceDir
std::string ResourceDir
The path to the compiler resource directory.
Definition: Driver.h:135
constructHexagonLinkArgs
static void constructHexagonLinkArgs(Compilation &C, const JobAction &JA, const toolchains::HexagonToolChain &HTC, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, ArgStringList &CmdArgs, const char *LinkingOutput)
Definition: Hexagon.cpp:204
clang::driver::ToolChain::ShouldLinkCXXStdlib
bool ShouldLinkCXXStdlib(const llvm::opt::ArgList &Args) const
Returns if the C++ standard library should be linked in.
Definition: ToolChain.cpp:930
clang::driver::toolchains::HexagonToolChain::GetCXXStdlibType
CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const override
Definition: Hexagon.cpp:676
P
StringRef P
Definition: ASTMatchersInternal.cpp:563
Compilation.h
getDefaultHvxLength
static StringRef getDefaultHvxLength(StringRef Cpu)
Definition: Hexagon.cpp:29
Value
Value
Definition: UninitializedValues.cpp:102
clang::driver::toolchains::HexagonToolChain::~HexagonToolChain
~HexagonToolChain() override
Definition: Hexagon.cpp:534
clang::driver::Compilation
Compilation - A set of tasks to perform for a single driver invocation.
Definition: Compilation.h:45
clang::driver::tools::hexagon::Linker::ConstructJob
void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override
ConstructJob - Construct jobs to perform the action JA, writing to Output and with Inputs,...
Definition: Hexagon.cpp:409
clang::driver::toolchains::Generic_GCC::addLibStdCXXIncludePaths
bool addLibStdCXXIncludePaths(Twine IncludeDir, StringRef Triple, Twine IncludeSuffix, const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, bool DetectDebian=false) const
Definition: Gnu.cpp:2925
IsStatic
bool IsStatic
Definition: Format.cpp:2391
clang::driver::InputInfo::getFilename
const char * getFilename() const
Definition: InputInfo.h:83
clang::driver::tools::linkSanitizerRuntimeDeps
void linkSanitizerRuntimeDeps(const ToolChain &TC, llvm::opt::ArgStringList &CmdArgs)
CommonArgs.h
clang
Definition: CalledOnceCheck.h:17
clang::driver::Driver
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:59
Hexagon.h
clang::driver::toolchains::HexagonToolChain::GetDefaultCPU
static StringRef GetDefaultCPU()
Definition: Hexagon.cpp:707
clang::driver::toolchains::HexagonToolChain::AddCXXStdlibLibArgs
void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const override
AddCXXStdlibLibArgs - Add the system specific linker arguments to use for the given C++ standard libr...
Definition: Hexagon.cpp:536
clang::driver::tools::addSanitizerRuntimes
bool addSanitizerRuntimes(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
clang::driver::Driver::getVFS
llvm::vfs::FileSystem & getVFS() const
Definition: Driver.h:329
clang::driver::ToolChain::addExternCSystemInclude
static void addExternCSystemInclude(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, const Twine &Path)
Utility function to add a system include directory with extern "C" semantics to CC1 arguments.
Definition: ToolChain.cpp:858
clang::driver::tools::hexagon::Linker
Definition: Hexagon.h:38
clang::driver::Action::OffloadKind
OffloadKind
Definition: Action.h:85
clang::driver
Definition: Action.h:31
llvm::SmallVectorImpl
Definition: LLVM.h:39
clang::driver::ToolChain::addSystemInclude
static void addSystemInclude(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, const Twine &Path)
Utility function to add a system include directory to CC1 arguments.
Definition: ToolChain.cpp:843
clang::driver::toolchains::HexagonToolChain::getOptimizationLevel
unsigned getOptimizationLevel(const llvm::opt::ArgList &DriverArgs) const
Definition: Hexagon.cpp:560
clang::driver::toolchains::HexagonToolChain::getHexagonLibraryPaths
void getHexagonLibraryPaths(const llvm::opt::ArgList &Args, ToolChain::path_list &LibPaths) const
Definition: Hexagon.cpp:470
clang::driver::JobAction
Definition: Action.h:380
clang::driver::tools::hexagon::Linker::RenderExtraToolArgs
virtual void RenderExtraToolArgs(const JobAction &JA, llvm::opt::ArgStringList &CmdArgs) const
Definition: Hexagon.cpp:199
clang::driver::toolchains::HexagonToolChain::buildLinker
Tool * buildLinker() const override
Definition: Hexagon.cpp:556
clang::driver::Driver::getInstalledDir
const char * getInstalledDir() const
Get the path to where the clang executable was installed.
Definition: Driver.h:348