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