CommonArgs.h 11 KB

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