CommonArgs.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. //===--- CommonArgs.h - Args handling for multiple toolchains ---*- 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. #ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_COMMONARGS_H
  9. #define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_COMMONARGS_H
  10. #include "clang/Driver/Driver.h"
  11. #include "clang/Driver/InputInfo.h"
  12. #include "clang/Driver/Multilib.h"
  13. #include "clang/Driver/Tool.h"
  14. #include "clang/Driver/ToolChain.h"
  15. #include "llvm/Support/CodeGen.h"
  16. namespace clang {
  17. namespace driver {
  18. namespace tools {
  19. void addPathIfExists(const Driver &D, const Twine &Path,
  20. ToolChain::path_list &Paths);
  21. void AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs,
  22. const llvm::opt::ArgList &Args,
  23. llvm::opt::ArgStringList &CmdArgs, const JobAction &JA);
  24. void addLinkerCompressDebugSectionsOption(const ToolChain &TC,
  25. const llvm::opt::ArgList &Args,
  26. llvm::opt::ArgStringList &CmdArgs);
  27. void claimNoWarnArgs(const llvm::opt::ArgList &Args);
  28. bool addSanitizerRuntimes(const ToolChain &TC, const llvm::opt::ArgList &Args,
  29. llvm::opt::ArgStringList &CmdArgs);
  30. void linkSanitizerRuntimeDeps(const ToolChain &TC,
  31. llvm::opt::ArgStringList &CmdArgs);
  32. bool addXRayRuntime(const ToolChain &TC, const llvm::opt::ArgList &Args,
  33. llvm::opt::ArgStringList &CmdArgs);
  34. void linkXRayRuntimeDeps(const ToolChain &TC,
  35. llvm::opt::ArgStringList &CmdArgs);
  36. void AddRunTimeLibs(const ToolChain &TC, const Driver &D,
  37. llvm::opt::ArgStringList &CmdArgs,
  38. const llvm::opt::ArgList &Args);
  39. void AddStaticDeviceLibsLinking(Compilation &C, const Tool &T,
  40. const JobAction &JA,
  41. const InputInfoList &Inputs,
  42. const llvm::opt::ArgList &DriverArgs,
  43. llvm::opt::ArgStringList &CmdArgs,
  44. StringRef Arch, StringRef Target,
  45. bool isBitCodeSDL, bool postClangLink);
  46. void AddStaticDeviceLibsPostLinking(const Driver &D,
  47. const llvm::opt::ArgList &DriverArgs,
  48. llvm::opt::ArgStringList &CmdArgs,
  49. StringRef Arch, StringRef Target,
  50. bool isBitCodeSDL, bool postClangLink);
  51. void AddStaticDeviceLibs(Compilation *C, const Tool *T, const JobAction *JA,
  52. const InputInfoList *Inputs, const Driver &D,
  53. const llvm::opt::ArgList &DriverArgs,
  54. llvm::opt::ArgStringList &CmdArgs, StringRef Arch,
  55. StringRef Target, bool isBitCodeSDL,
  56. bool postClangLink);
  57. bool SDLSearch(const Driver &D, const llvm::opt::ArgList &DriverArgs,
  58. llvm::opt::ArgStringList &CmdArgs,
  59. SmallVector<std::string, 8> LibraryPaths, std::string Lib,
  60. StringRef Arch, StringRef Target, bool isBitCodeSDL,
  61. bool postClangLink);
  62. bool GetSDLFromOffloadArchive(Compilation &C, const Driver &D, const Tool &T,
  63. const JobAction &JA, const InputInfoList &Inputs,
  64. const llvm::opt::ArgList &DriverArgs,
  65. llvm::opt::ArgStringList &CC1Args,
  66. SmallVector<std::string, 8> LibraryPaths,
  67. StringRef Lib, StringRef Arch, StringRef Target,
  68. bool isBitCodeSDL, bool postClangLink);
  69. const char *SplitDebugName(const JobAction &JA, const llvm::opt::ArgList &Args,
  70. const InputInfo &Input, const InputInfo &Output);
  71. void SplitDebugInfo(const ToolChain &TC, Compilation &C, const Tool &T,
  72. const JobAction &JA, const llvm::opt::ArgList &Args,
  73. const InputInfo &Output, const char *OutFile);
  74. void addLTOOptions(const ToolChain &ToolChain, const llvm::opt::ArgList &Args,
  75. llvm::opt::ArgStringList &CmdArgs, const InputInfo &Output,
  76. const InputInfo &Input, bool IsThinLTO);
  77. std::tuple<llvm::Reloc::Model, unsigned, bool>
  78. ParsePICArgs(const ToolChain &ToolChain, const llvm::opt::ArgList &Args);
  79. unsigned ParseFunctionAlignment(const ToolChain &TC,
  80. const llvm::opt::ArgList &Args);
  81. unsigned ParseDebugDefaultVersion(const ToolChain &TC,
  82. const llvm::opt::ArgList &Args);
  83. void AddAssemblerKPIC(const ToolChain &ToolChain,
  84. const llvm::opt::ArgList &Args,
  85. llvm::opt::ArgStringList &CmdArgs);
  86. void addOpenMPRuntimeSpecificRPath(const ToolChain &TC,
  87. const llvm::opt::ArgList &Args,
  88. llvm::opt::ArgStringList &CmdArgs);
  89. void addArchSpecificRPath(const ToolChain &TC, const llvm::opt::ArgList &Args,
  90. llvm::opt::ArgStringList &CmdArgs);
  91. void addOpenMPRuntimeLibraryPath(const ToolChain &TC,
  92. const llvm::opt::ArgList &Args,
  93. llvm::opt::ArgStringList &CmdArgs);
  94. /// Returns true, if an OpenMP runtime has been added.
  95. bool addOpenMPRuntime(llvm::opt::ArgStringList &CmdArgs, const ToolChain &TC,
  96. const llvm::opt::ArgList &Args,
  97. bool ForceStaticHostRuntime = false,
  98. bool IsOffloadingHost = false, bool GompNeedsRT = false);
  99. const char *getAsNeededOption(const ToolChain &TC, bool as_needed);
  100. llvm::opt::Arg *getLastProfileUseArg(const llvm::opt::ArgList &Args);
  101. llvm::opt::Arg *getLastProfileSampleUseArg(const llvm::opt::ArgList &Args);
  102. bool isObjCAutoRefCount(const llvm::opt::ArgList &Args);
  103. llvm::StringRef getLTOParallelism(const llvm::opt::ArgList &Args,
  104. const Driver &D);
  105. bool areOptimizationsEnabled(const llvm::opt::ArgList &Args);
  106. bool isUseSeparateSections(const llvm::Triple &Triple);
  107. /// \p EnvVar is split by system delimiter for environment variables.
  108. /// If \p ArgName is "-I", "-L", or an empty string, each entry from \p EnvVar
  109. /// is prefixed by \p ArgName then added to \p Args. Otherwise, for each
  110. /// entry of \p EnvVar, \p ArgName is added to \p Args first, then the entry
  111. /// itself is added.
  112. void addDirectoryList(const llvm::opt::ArgList &Args,
  113. llvm::opt::ArgStringList &CmdArgs, const char *ArgName,
  114. const char *EnvVar);
  115. void AddTargetFeature(const llvm::opt::ArgList &Args,
  116. std::vector<StringRef> &Features,
  117. llvm::opt::OptSpecifier OnOpt,
  118. llvm::opt::OptSpecifier OffOpt, StringRef FeatureName);
  119. std::string getCPUName(const Driver &D, const llvm::opt::ArgList &Args,
  120. const llvm::Triple &T, bool FromAs = false);
  121. /// Iterate \p Args and convert -mxxx to +xxx and -mno-xxx to -xxx and
  122. /// append it to \p Features.
  123. ///
  124. /// Note: Since \p Features may contain default values before calling
  125. /// this function, or may be appended with entries to override arguments,
  126. /// entries in \p Features are not unique.
  127. void handleTargetFeaturesGroup(const llvm::opt::ArgList &Args,
  128. std::vector<StringRef> &Features,
  129. llvm::opt::OptSpecifier Group);
  130. /// If there are multiple +xxx or -xxx features, keep the last one.
  131. std::vector<StringRef>
  132. unifyTargetFeatures(const std::vector<StringRef> &Features);
  133. /// Handles the -save-stats option and returns the filename to save statistics
  134. /// to.
  135. SmallString<128> getStatsFileName(const llvm::opt::ArgList &Args,
  136. const InputInfo &Output,
  137. const InputInfo &Input, const Driver &D);
  138. /// \p Flag must be a flag accepted by the driver with its leading '-' removed,
  139. // otherwise '-print-multi-lib' will not emit them correctly.
  140. void addMultilibFlag(bool Enabled, const char *const Flag,
  141. Multilib::flags_list &Flags);
  142. void addX86AlignBranchArgs(const Driver &D, const llvm::opt::ArgList &Args,
  143. llvm::opt::ArgStringList &CmdArgs, bool IsLTO);
  144. void checkAMDGPUCodeObjectVersion(const Driver &D,
  145. const llvm::opt::ArgList &Args);
  146. unsigned getAMDGPUCodeObjectVersion(const Driver &D,
  147. const llvm::opt::ArgList &Args);
  148. bool haveAMDGPUCodeObjectVersionArgument(const Driver &D,
  149. const llvm::opt::ArgList &Args);
  150. void addMachineOutlinerArgs(const Driver &D, const llvm::opt::ArgList &Args,
  151. llvm::opt::ArgStringList &CmdArgs,
  152. const llvm::Triple &Triple, bool IsLTO);
  153. void addOpenMPDeviceRTL(const Driver &D, const llvm::opt::ArgList &DriverArgs,
  154. llvm::opt::ArgStringList &CC1Args,
  155. StringRef BitcodeSuffix, const llvm::Triple &Triple);
  156. } // end namespace tools
  157. } // end namespace driver
  158. } // end namespace clang
  159. #endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_COMMONARGS_H