clang  16.0.0git
CommonArgs.h
Go to the documentation of this file.
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 
9 #ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_COMMONARGS_H
10 #define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_COMMONARGS_H
11 
12 #include "clang/Driver/Driver.h"
13 #include "clang/Driver/InputInfo.h"
14 #include "clang/Driver/Multilib.h"
15 #include "clang/Driver/Tool.h"
16 #include "clang/Driver/ToolChain.h"
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/Option/Arg.h"
19 #include "llvm/Option/ArgList.h"
20 #include "llvm/Support/CodeGen.h"
21 
22 namespace clang {
23 namespace driver {
24 namespace tools {
25 
26 void addPathIfExists(const Driver &D, const Twine &Path,
27  ToolChain::path_list &Paths);
28 
29 void AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs,
30  const llvm::opt::ArgList &Args,
31  llvm::opt::ArgStringList &CmdArgs, const JobAction &JA);
32 
33 void addLinkerCompressDebugSectionsOption(const ToolChain &TC,
34  const llvm::opt::ArgList &Args,
35  llvm::opt::ArgStringList &CmdArgs);
36 
37 void claimNoWarnArgs(const llvm::opt::ArgList &Args);
38 
39 bool addSanitizerRuntimes(const ToolChain &TC, const llvm::opt::ArgList &Args,
40  llvm::opt::ArgStringList &CmdArgs);
41 
42 void linkSanitizerRuntimeDeps(const ToolChain &TC,
43  llvm::opt::ArgStringList &CmdArgs);
44 
45 bool addXRayRuntime(const ToolChain &TC, const llvm::opt::ArgList &Args,
46  llvm::opt::ArgStringList &CmdArgs);
47 
48 void linkXRayRuntimeDeps(const ToolChain &TC,
49  llvm::opt::ArgStringList &CmdArgs);
50 
51 void AddRunTimeLibs(const ToolChain &TC, const Driver &D,
52  llvm::opt::ArgStringList &CmdArgs,
53  const llvm::opt::ArgList &Args);
54 
55 void AddStaticDeviceLibsLinking(Compilation &C, const Tool &T,
56  const JobAction &JA,
57  const InputInfoList &Inputs,
58  const llvm::opt::ArgList &DriverArgs,
59  llvm::opt::ArgStringList &CmdArgs,
60  StringRef Arch, StringRef Target,
61  bool isBitCodeSDL, bool postClangLink);
62 void AddStaticDeviceLibsPostLinking(const Driver &D,
63  const llvm::opt::ArgList &DriverArgs,
64  llvm::opt::ArgStringList &CmdArgs,
65  StringRef Arch, StringRef Target,
66  bool isBitCodeSDL, bool postClangLink);
67 void AddStaticDeviceLibs(Compilation *C, const Tool *T, const JobAction *JA,
68  const InputInfoList *Inputs, const Driver &D,
69  const llvm::opt::ArgList &DriverArgs,
70  llvm::opt::ArgStringList &CmdArgs, StringRef Arch,
71  StringRef Target, bool isBitCodeSDL,
72  bool postClangLink);
73 
74 bool SDLSearch(const Driver &D, const llvm::opt::ArgList &DriverArgs,
75  llvm::opt::ArgStringList &CmdArgs,
76  SmallVector<std::string, 8> LibraryPaths, std::string Lib,
77  StringRef Arch, StringRef Target, bool isBitCodeSDL,
78  bool postClangLink);
79 
80 bool GetSDLFromOffloadArchive(Compilation &C, const Driver &D, const Tool &T,
81  const JobAction &JA, const InputInfoList &Inputs,
82  const llvm::opt::ArgList &DriverArgs,
83  llvm::opt::ArgStringList &CC1Args,
84  SmallVector<std::string, 8> LibraryPaths,
85  StringRef Lib, StringRef Arch, StringRef Target,
86  bool isBitCodeSDL, bool postClangLink);
87 
88 const char *SplitDebugName(const JobAction &JA, const llvm::opt::ArgList &Args,
89  const InputInfo &Input, const InputInfo &Output);
90 
91 void SplitDebugInfo(const ToolChain &TC, Compilation &C, const Tool &T,
92  const JobAction &JA, const llvm::opt::ArgList &Args,
93  const InputInfo &Output, const char *OutFile);
94 
95 void addLTOOptions(const ToolChain &ToolChain, const llvm::opt::ArgList &Args,
96  llvm::opt::ArgStringList &CmdArgs, const InputInfo &Output,
97  const InputInfo &Input, bool IsThinLTO);
98 
99 const char *RelocationModelName(llvm::Reloc::Model Model);
100 
101 std::tuple<llvm::Reloc::Model, unsigned, bool>
102 ParsePICArgs(const ToolChain &ToolChain, const llvm::opt::ArgList &Args);
103 
104 unsigned ParseFunctionAlignment(const ToolChain &TC,
105  const llvm::opt::ArgList &Args);
106 
107 // Extract the integer N from a string spelled "-dwarf-N", returning 0
108 // on mismatch. The StringRef input (rather than an Arg) allows
109 // for use by the "-Xassembler" option parser.
110 unsigned DwarfVersionNum(StringRef ArgValue);
111 // Find a DWARF format version option.
112 // This function is a complementary for DwarfVersionNum().
113 const llvm::opt::Arg *getDwarfNArg(const llvm::opt::ArgList &Args);
114 unsigned getDwarfVersion(const ToolChain &TC, const llvm::opt::ArgList &Args);
115 
116 void AddAssemblerKPIC(const ToolChain &ToolChain,
117  const llvm::opt::ArgList &Args,
118  llvm::opt::ArgStringList &CmdArgs);
119 
120 void addOpenMPRuntimeSpecificRPath(const ToolChain &TC,
121  const llvm::opt::ArgList &Args,
122  llvm::opt::ArgStringList &CmdArgs);
123 void addArchSpecificRPath(const ToolChain &TC, const llvm::opt::ArgList &Args,
124  llvm::opt::ArgStringList &CmdArgs);
125 void addOpenMPRuntimeLibraryPath(const ToolChain &TC,
126  const llvm::opt::ArgList &Args,
127  llvm::opt::ArgStringList &CmdArgs);
128 /// Returns true, if an OpenMP runtime has been added.
129 bool addOpenMPRuntime(llvm::opt::ArgStringList &CmdArgs, const ToolChain &TC,
130  const llvm::opt::ArgList &Args,
131  bool ForceStaticHostRuntime = false,
132  bool IsOffloadingHost = false, bool GompNeedsRT = false);
133 
134 /// Adds Fortran runtime libraries to \p CmdArgs.
135 void addFortranRuntimeLibs(const ToolChain &TC,
136  llvm::opt::ArgStringList &CmdArgs);
137 
138 /// Adds the path for the Fortran runtime libraries to \p CmdArgs.
139 void addFortranRuntimeLibraryPath(const ToolChain &TC,
140  const llvm::opt::ArgList &Args,
141  llvm::opt::ArgStringList &CmdArgs);
142 
143 void addHIPRuntimeLibArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
144  llvm::opt::ArgStringList &CmdArgs);
145 
146 const char *getAsNeededOption(const ToolChain &TC, bool as_needed);
147 
148 llvm::opt::Arg *getLastProfileUseArg(const llvm::opt::ArgList &Args);
149 llvm::opt::Arg *getLastProfileSampleUseArg(const llvm::opt::ArgList &Args);
150 
151 bool isObjCAutoRefCount(const llvm::opt::ArgList &Args);
152 
153 llvm::StringRef getLTOParallelism(const llvm::opt::ArgList &Args,
154  const Driver &D);
155 
156 bool areOptimizationsEnabled(const llvm::opt::ArgList &Args);
157 
158 bool isUseSeparateSections(const llvm::Triple &Triple);
159 
160 /// \p EnvVar is split by system delimiter for environment variables.
161 /// If \p ArgName is "-I", "-L", or an empty string, each entry from \p EnvVar
162 /// is prefixed by \p ArgName then added to \p Args. Otherwise, for each
163 /// entry of \p EnvVar, \p ArgName is added to \p Args first, then the entry
164 /// itself is added.
165 void addDirectoryList(const llvm::opt::ArgList &Args,
166  llvm::opt::ArgStringList &CmdArgs, const char *ArgName,
167  const char *EnvVar);
168 
169 void AddTargetFeature(const llvm::opt::ArgList &Args,
170  std::vector<StringRef> &Features,
171  llvm::opt::OptSpecifier OnOpt,
172  llvm::opt::OptSpecifier OffOpt, StringRef FeatureName);
173 
174 std::string getCPUName(const Driver &D, const llvm::opt::ArgList &Args,
175  const llvm::Triple &T, bool FromAs = false);
176 
177 /// Iterate \p Args and convert -mxxx to +xxx and -mno-xxx to -xxx and
178 /// append it to \p Features.
179 ///
180 /// Note: Since \p Features may contain default values before calling
181 /// this function, or may be appended with entries to override arguments,
182 /// entries in \p Features are not unique.
183 void handleTargetFeaturesGroup(const llvm::opt::ArgList &Args,
184  std::vector<StringRef> &Features,
185  llvm::opt::OptSpecifier Group);
186 
187 /// If there are multiple +xxx or -xxx features, keep the last one.
188 SmallVector<StringRef> unifyTargetFeatures(ArrayRef<StringRef> Features);
189 
190 /// Handles the -save-stats option and returns the filename to save statistics
191 /// to.
192 SmallString<128> getStatsFileName(const llvm::opt::ArgList &Args,
193  const InputInfo &Output,
194  const InputInfo &Input, const Driver &D);
195 
196 /// \p Flag must be a flag accepted by the driver with its leading '-' removed,
197 // otherwise '-print-multi-lib' will not emit them correctly.
198 void addMultilibFlag(bool Enabled, const char *const Flag,
199  Multilib::flags_list &Flags);
200 
201 void addX86AlignBranchArgs(const Driver &D, const llvm::opt::ArgList &Args,
202  llvm::opt::ArgStringList &CmdArgs, bool IsLTO,
203  const StringRef PluginOptPrefix = "");
204 
205 void checkAMDGPUCodeObjectVersion(const Driver &D,
206  const llvm::opt::ArgList &Args);
207 
208 unsigned getAMDGPUCodeObjectVersion(const Driver &D,
209  const llvm::opt::ArgList &Args);
210 
211 bool haveAMDGPUCodeObjectVersionArgument(const Driver &D,
212  const llvm::opt::ArgList &Args);
213 
214 void addMachineOutlinerArgs(const Driver &D, const llvm::opt::ArgList &Args,
215  llvm::opt::ArgStringList &CmdArgs,
216  const llvm::Triple &Triple, bool IsLTO,
217  const StringRef PluginOptPrefix = "");
218 
219 void addOpenMPDeviceRTL(const Driver &D, const llvm::opt::ArgList &DriverArgs,
220  llvm::opt::ArgStringList &CC1Args,
221  StringRef BitcodeSuffix, const llvm::Triple &Triple);
222 } // end namespace tools
223 } // end namespace driver
224 } // end namespace clang
225 
226 #endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_COMMONARGS_H
clang::driver::Multilib::flags_list
std::vector< std::string > flags_list
Definition: Multilib.h:30
clang::driver::tools::ParseFunctionAlignment
unsigned ParseFunctionAlignment(const ToolChain &TC, const llvm::opt::ArgList &Args)
clang::driver::tools::AddAssemblerKPIC
void AddAssemblerKPIC(const ToolChain &ToolChain, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
clang::driver::tools::GetSDLFromOffloadArchive
bool GetSDLFromOffloadArchive(Compilation &C, const Driver &D, const Tool &T, const JobAction &JA, const InputInfoList &Inputs, const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, SmallVector< std::string, 8 > LibraryPaths, StringRef Lib, StringRef Arch, StringRef Target, bool isBitCodeSDL, bool postClangLink)
Search if a user provided archive file lib<libname>.a exists in any of the library paths.
Definition: CommonArgs.cpp:1892
Driver.h
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::driver::tools::ParsePICArgs
std::tuple< llvm::Reloc::Model, unsigned, bool > ParsePICArgs(const ToolChain &ToolChain, const llvm::opt::ArgList &Args)
clang::driver::tools::getDwarfVersion
unsigned getDwarfVersion(const ToolChain &TC, const llvm::opt::ArgList &Args)
Definition: CommonArgs.cpp:1556
clang::driver::ToolChain::path_list
SmallVector< std::string, 16 > path_list
Definition: ToolChain.h:93
clang::driver::tools::getDwarfNArg
const llvm::opt::Arg * getDwarfNArg(const llvm::opt::ArgList &Args)
clang::driver::tools::getLastProfileSampleUseArg
llvm::opt::Arg * getLastProfileSampleUseArg(const llvm::opt::ArgList &Args)
clang::driver::tools::addOpenMPRuntimeLibraryPath
void addOpenMPRuntimeLibraryPath(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
clang::driver::tools::AddStaticDeviceLibs
void AddStaticDeviceLibs(Compilation *C, const Tool *T, const JobAction *JA, const InputInfoList *Inputs, const Driver &D, const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CmdArgs, StringRef Arch, StringRef Target, bool isBitCodeSDL, bool postClangLink)
Definition: CommonArgs.cpp:2051
clang::driver::InputInfoList
SmallVector< InputInfo, 4 > InputInfoList
Definition: Driver.h:48
clang::driver::tools::getCPUName
std::string getCPUName(const Driver &D, const llvm::opt::ArgList &Args, const llvm::Triple &T, bool FromAs=false)
clang::driver::tools::getLastProfileUseArg
llvm::opt::Arg * getLastProfileUseArg(const llvm::opt::ArgList &Args)
clang::diag::Group
Group
Definition: DiagnosticCategories.h:23
clang::driver::tools::SplitDebugInfo
void SplitDebugInfo(const ToolChain &TC, Compilation &C, const Tool &T, const JobAction &JA, const llvm::opt::ArgList &Args, const InputInfo &Output, const char *OutFile)
clang::driver::tools::SDLSearch
bool SDLSearch(const Driver &D, const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CmdArgs, SmallVector< std::string, 8 > LibraryPaths, std::string Lib, StringRef Arch, StringRef Target, bool isBitCodeSDL, bool postClangLink)
SDLSearch: Search for Static Device Library The search for SDL bitcode files is consistent with how s...
Definition: CommonArgs.cpp:1811
InputInfo.h
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::tools::areOptimizationsEnabled
bool areOptimizationsEnabled(const llvm::opt::ArgList &Args)
clang::driver::tools::AddStaticDeviceLibsLinking
void AddStaticDeviceLibsLinking(Compilation &C, const Tool &T, const JobAction &JA, const InputInfoList &Inputs, const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CmdArgs, StringRef Arch, StringRef Target, bool isBitCodeSDL, bool postClangLink)
Definition: CommonArgs.cpp:2004
clang::driver::tools::addFortranRuntimeLibs
void addFortranRuntimeLibs(const ToolChain &TC, llvm::opt::ArgStringList &CmdArgs)
Adds Fortran runtime libraries to CmdArgs.
Definition: CommonArgs.cpp:806
clang::driver::tools::getAsNeededOption
const char * getAsNeededOption(const ToolChain &TC, bool as_needed)
Definition: CommonArgs.cpp:873
clang::driver::tools::claimNoWarnArgs
void claimNoWarnArgs(const llvm::opt::ArgList &Args)
clang::driver::tools::getLTOParallelism
llvm::StringRef getLTOParallelism(const llvm::opt::ArgList &Args, const Driver &D)
clang::driver::tools::addPathIfExists
void addPathIfExists(const Driver &D, const Twine &Path, ToolChain::path_list &Paths)
Definition: CommonArgs.cpp:130
Tool.h
clang::driver::tools::unifyTargetFeatures
SmallVector< StringRef > unifyTargetFeatures(ArrayRef< StringRef > Features)
If there are multiple +xxx or -xxx features, keep the last one.
Definition: CommonArgs.cpp:155
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::tools::addXRayRuntime
bool addXRayRuntime(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
clang::driver::tools::getAMDGPUCodeObjectVersion
unsigned getAMDGPUCodeObjectVersion(const Driver &D, const llvm::opt::ArgList &Args)
Definition: CommonArgs.cpp:2158
clang::driver::tools::addOpenMPDeviceRTL
void addOpenMPDeviceRTL(const Driver &D, const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, StringRef BitcodeSuffix, const llvm::Triple &Triple)
Definition: CommonArgs.cpp:2215
clang::driver::tools::isUseSeparateSections
bool isUseSeparateSections(const llvm::Triple &Triple)
Definition: CommonArgs.cpp:484
clang::driver::tools::haveAMDGPUCodeObjectVersionArgument
bool haveAMDGPUCodeObjectVersionArgument(const Driver &D, const llvm::opt::ArgList &Args)
Definition: CommonArgs.cpp:2175
clang::driver::tools::addLTOOptions
void addLTOOptions(const ToolChain &ToolChain, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const InputInfo &Output, const InputInfo &Input, bool IsThinLTO)
ToolChain.h
clang::driver::tools::addHIPRuntimeLibArgs
void addHIPRuntimeLibArgs(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
Definition: CommonArgs.cpp:2280
clang::driver::tools::addMachineOutlinerArgs
void addMachineOutlinerArgs(const Driver &D, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const llvm::Triple &Triple, bool IsLTO, const StringRef PluginOptPrefix="")
Definition: CommonArgs.cpp:2180
clang::driver::tools::AddRunTimeLibs
void AddRunTimeLibs(const ToolChain &TC, const Driver &D, llvm::opt::ArgStringList &CmdArgs, const llvm::opt::ArgList &Args)
clang::driver::tools::AddTargetFeature
void AddTargetFeature(const llvm::opt::ArgList &Args, std::vector< StringRef > &Features, llvm::opt::OptSpecifier OnOpt, llvm::opt::OptSpecifier OffOpt, StringRef FeatureName)
clang::driver::tools::addOpenMPRuntime
bool addOpenMPRuntime(llvm::opt::ArgStringList &CmdArgs, const ToolChain &TC, const llvm::opt::ArgList &Args, bool ForceStaticHostRuntime=false, bool IsOffloadingHost=false, bool GompNeedsRT=false)
Returns true, if an OpenMP runtime has been added.
clang::driver::tools::addArchSpecificRPath
void addArchSpecificRPath(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
clang::driver::tools::RelocationModelName
const char * RelocationModelName(llvm::Reloc::Model Model)
Definition: CommonArgs.cpp:1263
clang::driver::tools::linkSanitizerRuntimeDeps
void linkSanitizerRuntimeDeps(const ToolChain &TC, llvm::opt::ArgStringList &CmdArgs)
clang
Definition: CalledOnceCheck.h:17
clang::driver::tools::addSanitizerRuntimes
bool addSanitizerRuntimes(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
clang::driver::tools::addMultilibFlag
void addMultilibFlag(bool Enabled, const char *const Flag, Multilib::flags_list &Flags)
Flag must be a flag accepted by the driver with its leading '-' removed,
Definition: CommonArgs.cpp:1734
clang::driver::tools::checkAMDGPUCodeObjectVersion
void checkAMDGPUCodeObjectVersion(const Driver &D, const llvm::opt::ArgList &Args)
Definition: CommonArgs.cpp:2131
Multilib.h
clang::driver::tools::linkXRayRuntimeDeps
void linkXRayRuntimeDeps(const ToolChain &TC, llvm::opt::ArgStringList &CmdArgs)
clang::driver::tools::addDirectoryList
void addDirectoryList(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const char *ArgName, const char *EnvVar)
EnvVar is split by system delimiter for environment variables.
clang::driver::tools::addLinkerCompressDebugSectionsOption
void addLinkerCompressDebugSectionsOption(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
Definition: CommonArgs.cpp:285
clang::driver::tools::AddStaticDeviceLibsPostLinking
void AddStaticDeviceLibsPostLinking(const Driver &D, const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CmdArgs, StringRef Arch, StringRef Target, bool isBitCodeSDL, bool postClangLink)
Definition: CommonArgs.cpp:2017
clang::driver::tools::addX86AlignBranchArgs
void addX86AlignBranchArgs(const Driver &D, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, bool IsLTO, const StringRef PluginOptPrefix="")
clang::driver::tools::DwarfVersionNum
unsigned DwarfVersionNum(StringRef ArgValue)
Definition: CommonArgs.cpp:1541
clang::driver::tools::addOpenMPRuntimeSpecificRPath
void addOpenMPRuntimeSpecificRPath(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
clang::driver::tools::getStatsFileName
SmallString< 128 > getStatsFileName(const llvm::opt::ArgList &Args, const InputInfo &Output, const InputInfo &Input, const Driver &D)
Handles the -save-stats option and returns the filename to save statistics to.
Definition: CommonArgs.cpp:1710
clang::driver::tools::addFortranRuntimeLibraryPath
void addFortranRuntimeLibraryPath(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
Adds the path for the Fortran runtime libraries to CmdArgs.
clang::driver::tools::SplitDebugName
const char * SplitDebugName(const JobAction &JA, const llvm::opt::ArgList &Args, const InputInfo &Input, const InputInfo &Output)
clang::driver::tools::isObjCAutoRefCount
bool isObjCAutoRefCount(const llvm::opt::ArgList &Args)