clang 18.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"
15#include "clang/Driver/Tool.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
22namespace clang {
23namespace driver {
24namespace tools {
25
26void addPathIfExists(const Driver &D, const Twine &Path,
28
29void AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs,
30 const llvm::opt::ArgList &Args,
31 llvm::opt::ArgStringList &CmdArgs, const JobAction &JA);
32
34 const llvm::opt::ArgList &Args,
35 llvm::opt::ArgStringList &CmdArgs);
36
37void claimNoWarnArgs(const llvm::opt::ArgList &Args);
38
39bool addSanitizerRuntimes(const ToolChain &TC, const llvm::opt::ArgList &Args,
40 llvm::opt::ArgStringList &CmdArgs);
41
43 const llvm::opt::ArgList &Args,
44 llvm::opt::ArgStringList &CmdArgs);
45
46bool addXRayRuntime(const ToolChain &TC, const llvm::opt::ArgList &Args,
47 llvm::opt::ArgStringList &CmdArgs);
48
49void linkXRayRuntimeDeps(const ToolChain &TC, const llvm::opt::ArgList &Args,
50 llvm::opt::ArgStringList &CmdArgs);
51
52void AddRunTimeLibs(const ToolChain &TC, const Driver &D,
53 llvm::opt::ArgStringList &CmdArgs,
54 const llvm::opt::ArgList &Args);
55
57 const JobAction &JA,
58 const InputInfoList &Inputs,
59 const llvm::opt::ArgList &DriverArgs,
60 llvm::opt::ArgStringList &CmdArgs,
61 StringRef Arch, StringRef Target,
62 bool isBitCodeSDL, bool postClangLink);
63void AddStaticDeviceLibs(Compilation *C, const Tool *T, const JobAction *JA,
64 const InputInfoList *Inputs, const Driver &D,
65 const llvm::opt::ArgList &DriverArgs,
66 llvm::opt::ArgStringList &CmdArgs, StringRef Arch,
67 StringRef Target, bool isBitCodeSDL,
68 bool postClangLink);
69
70bool SDLSearch(const Driver &D, const llvm::opt::ArgList &DriverArgs,
71 llvm::opt::ArgStringList &CmdArgs,
72 SmallVector<std::string, 8> LibraryPaths, std::string Lib,
73 StringRef Arch, StringRef Target, bool isBitCodeSDL,
74 bool postClangLink);
75
76bool GetSDLFromOffloadArchive(Compilation &C, const Driver &D, const Tool &T,
77 const JobAction &JA, const InputInfoList &Inputs,
78 const llvm::opt::ArgList &DriverArgs,
79 llvm::opt::ArgStringList &CC1Args,
80 SmallVector<std::string, 8> LibraryPaths,
81 StringRef Lib, StringRef Arch, StringRef Target,
82 bool isBitCodeSDL, bool postClangLink);
83
84const char *SplitDebugName(const JobAction &JA, const llvm::opt::ArgList &Args,
85 const InputInfo &Input, const InputInfo &Output);
86
87void SplitDebugInfo(const ToolChain &TC, Compilation &C, const Tool &T,
88 const JobAction &JA, const llvm::opt::ArgList &Args,
89 const InputInfo &Output, const char *OutFile);
90
91void addLTOOptions(const ToolChain &ToolChain, const llvm::opt::ArgList &Args,
92 llvm::opt::ArgStringList &CmdArgs, const InputInfo &Output,
93 const InputInfo &Input, bool IsThinLTO);
94
95const char *RelocationModelName(llvm::Reloc::Model Model);
96
97std::tuple<llvm::Reloc::Model, unsigned, bool>
98ParsePICArgs(const ToolChain &ToolChain, const llvm::opt::ArgList &Args);
99
101 const llvm::opt::ArgList &Args);
102
103void addDebugInfoKind(llvm::opt::ArgStringList &CmdArgs,
104 llvm::codegenoptions::DebugInfoKind DebugInfoKind);
105
106llvm::codegenoptions::DebugInfoKind
107debugLevelToInfoKind(const llvm::opt::Arg &A);
108
109// Extract the integer N from a string spelled "-dwarf-N", returning 0
110// on mismatch. The StringRef input (rather than an Arg) allows
111// for use by the "-Xassembler" option parser.
112unsigned DwarfVersionNum(StringRef ArgValue);
113// Find a DWARF format version option.
114// This function is a complementary for DwarfVersionNum().
115const llvm::opt::Arg *getDwarfNArg(const llvm::opt::ArgList &Args);
116unsigned getDwarfVersion(const ToolChain &TC, const llvm::opt::ArgList &Args);
117
119 const llvm::opt::ArgList &Args,
120 llvm::opt::ArgStringList &CmdArgs);
121
122void addArchSpecificRPath(const ToolChain &TC, const llvm::opt::ArgList &Args,
123 llvm::opt::ArgStringList &CmdArgs);
125 const llvm::opt::ArgList &Args,
126 llvm::opt::ArgStringList &CmdArgs);
127/// Returns true, if an OpenMP runtime has been added.
128bool addOpenMPRuntime(llvm::opt::ArgStringList &CmdArgs, const ToolChain &TC,
129 const llvm::opt::ArgList &Args,
130 bool ForceStaticHostRuntime = false,
131 bool IsOffloadingHost = false, bool GompNeedsRT = false);
132
133/// Adds Fortran runtime libraries to \p CmdArgs.
134void addFortranRuntimeLibs(const ToolChain &TC,
135 llvm::opt::ArgStringList &CmdArgs);
136
137/// Adds the path for the Fortran runtime libraries to \p CmdArgs.
139 const llvm::opt::ArgList &Args,
140 llvm::opt::ArgStringList &CmdArgs);
141
143 const llvm::opt::ArgList &Args,
144 llvm::opt::ArgStringList &CmdArgs);
145
146void addAsNeededOption(const ToolChain &TC, const llvm::opt::ArgList &Args,
147 llvm::opt::ArgStringList &CmdArgs, bool as_needed);
148
149llvm::opt::Arg *getLastCSProfileGenerateArg(const llvm::opt::ArgList &Args);
150llvm::opt::Arg *getLastProfileUseArg(const llvm::opt::ArgList &Args);
151llvm::opt::Arg *getLastProfileSampleUseArg(const llvm::opt::ArgList &Args);
152
153bool isObjCAutoRefCount(const llvm::opt::ArgList &Args);
154
155llvm::StringRef getLTOParallelism(const llvm::opt::ArgList &Args,
156 const Driver &D);
157
158bool areOptimizationsEnabled(const llvm::opt::ArgList &Args);
159
160bool isUseSeparateSections(const llvm::Triple &Triple);
161
162/// \p EnvVar is split by system delimiter for environment variables.
163/// If \p ArgName is "-I", "-L", or an empty string, each entry from \p EnvVar
164/// is prefixed by \p ArgName then added to \p Args. Otherwise, for each
165/// entry of \p EnvVar, \p ArgName is added to \p Args first, then the entry
166/// itself is added.
167void addDirectoryList(const llvm::opt::ArgList &Args,
168 llvm::opt::ArgStringList &CmdArgs, const char *ArgName,
169 const char *EnvVar);
170
171void AddTargetFeature(const llvm::opt::ArgList &Args,
172 std::vector<StringRef> &Features,
173 llvm::opt::OptSpecifier OnOpt,
174 llvm::opt::OptSpecifier OffOpt, StringRef FeatureName);
175
176std::string getCPUName(const Driver &D, const llvm::opt::ArgList &Args,
177 const llvm::Triple &T, bool FromAs = false);
178
179void getTargetFeatures(const Driver &D, const llvm::Triple &Triple,
180 const llvm::opt::ArgList &Args,
181 llvm::opt::ArgStringList &CmdArgs, bool ForAS,
182 bool IsAux = false);
183
184/// Iterate \p Args and convert -mxxx to +xxx and -mno-xxx to -xxx and
185/// append it to \p Features.
186///
187/// Note: Since \p Features may contain default values before calling
188/// this function, or may be appended with entries to override arguments,
189/// entries in \p Features are not unique.
190void handleTargetFeaturesGroup(const Driver &D, const llvm::Triple &Triple,
191 const llvm::opt::ArgList &Args,
192 std::vector<StringRef> &Features,
193 llvm::opt::OptSpecifier Group);
194
195/// If there are multiple +xxx or -xxx features, keep the last one.
197
198/// Handles the -save-stats option and returns the filename to save statistics
199/// to.
200SmallString<128> getStatsFileName(const llvm::opt::ArgList &Args,
201 const InputInfo &Output,
202 const InputInfo &Input, const Driver &D);
203
204/// \p Flag must be a flag accepted by the driver.
205void addMultilibFlag(bool Enabled, const StringRef Flag,
206 Multilib::flags_list &Flags);
207
208void addX86AlignBranchArgs(const Driver &D, const llvm::opt::ArgList &Args,
209 llvm::opt::ArgStringList &CmdArgs, bool IsLTO,
210 const StringRef PluginOptPrefix = "");
211
213 const llvm::opt::ArgList &Args);
214
215unsigned getAMDGPUCodeObjectVersion(const Driver &D,
216 const llvm::opt::ArgList &Args);
217
219 const llvm::opt::ArgList &Args);
220
221void addMachineOutlinerArgs(const Driver &D, const llvm::opt::ArgList &Args,
222 llvm::opt::ArgStringList &CmdArgs,
223 const llvm::Triple &Triple, bool IsLTO,
224 const StringRef PluginOptPrefix = "");
225
226void addOpenMPDeviceRTL(const Driver &D, const llvm::opt::ArgList &DriverArgs,
227 llvm::opt::ArgStringList &CC1Args,
228 StringRef BitcodeSuffix, const llvm::Triple &Triple);
229} // end namespace tools
230} // end namespace driver
231} // end namespace clang
232
233#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_COMMONARGS_H
Compilation - A set of tasks to perform for a single driver invocation.
Definition: Compilation.h:45
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:77
InputInfo - Wrapper for information about an input source.
Definition: InputInfo.h:22
std::vector< std::string > flags_list
Definition: Multilib.h:34
ToolChain - Access to tools for a single platform.
Definition: ToolChain.h:92
SmallVector< std::string, 16 > path_list
Definition: ToolChain.h:94
Tool - Information on a specific compilation tool.
Definition: Tool.h:32
void addX86AlignBranchArgs(const Driver &D, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, bool IsLTO, const StringRef PluginOptPrefix="")
void addMachineOutlinerArgs(const Driver &D, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const llvm::Triple &Triple, bool IsLTO, const StringRef PluginOptPrefix="")
unsigned ParseFunctionAlignment(const ToolChain &TC, const llvm::opt::ArgList &Args)
void addOpenMPDeviceRTL(const Driver &D, const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, StringRef BitcodeSuffix, const llvm::Triple &Triple)
void handleTargetFeaturesGroup(const Driver &D, const llvm::Triple &Triple, 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.
SmallVector< StringRef > unifyTargetFeatures(ArrayRef< StringRef > Features)
If there are multiple +xxx or -xxx features, keep the last one.
Definition: CommonArgs.cpp:190
llvm::opt::Arg * getLastProfileSampleUseArg(const llvm::opt::ArgList &Args)
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.
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)
const char * SplitDebugName(const JobAction &JA, const llvm::opt::ArgList &Args, const InputInfo &Input, const InputInfo &Output)
void checkAMDGPUCodeObjectVersion(const Driver &D, const llvm::opt::ArgList &Args)
void getTargetFeatures(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, bool ForAS, bool IsAux=false)
void addAsNeededOption(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, bool as_needed)
std::string getCPUName(const Driver &D, const llvm::opt::ArgList &Args, const llvm::Triple &T, bool FromAs=false)
void addHIPRuntimeLibArgs(const ToolChain &TC, Compilation &C, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
void addMultilibFlag(bool Enabled, const StringRef Flag, Multilib::flags_list &Flags)
Flag must be a flag accepted by the driver.
bool isUseSeparateSections(const llvm::Triple &Triple)
Definition: CommonArgs.cpp:589
void linkXRayRuntimeDeps(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
void AddRunTimeLibs(const ToolChain &TC, const Driver &D, llvm::opt::ArgStringList &CmdArgs, const llvm::opt::ArgList &Args)
void SplitDebugInfo(const ToolChain &TC, Compilation &C, const Tool &T, const JobAction &JA, const llvm::opt::ArgList &Args, const InputInfo &Output, const char *OutFile)
void linkSanitizerRuntimeDeps(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
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.
bool addSanitizerRuntimes(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
bool areOptimizationsEnabled(const llvm::opt::ArgList &Args)
void addOpenMPRuntimeLibraryPath(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
bool addXRayRuntime(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
void AddAssemblerKPIC(const ToolChain &ToolChain, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
bool haveAMDGPUCodeObjectVersionArgument(const Driver &D, const llvm::opt::ArgList &Args)
void addFortranRuntimeLibs(const ToolChain &TC, llvm::opt::ArgStringList &CmdArgs)
Adds Fortran runtime libraries to CmdArgs.
Definition: CommonArgs.cpp:948
void addDebugInfoKind(llvm::opt::ArgStringList &CmdArgs, llvm::codegenoptions::DebugInfoKind DebugInfoKind)
void addPathIfExists(const Driver &D, const Twine &Path, ToolChain::path_list &Paths)
Definition: CommonArgs.cpp:150
llvm::codegenoptions::DebugInfoKind debugLevelToInfoKind(const llvm::opt::Arg &A)
llvm::opt::Arg * getLastCSProfileGenerateArg(const llvm::opt::ArgList &Args)
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)
llvm::opt::Arg * getLastProfileUseArg(const llvm::opt::ArgList &Args)
void addFortranRuntimeLibraryPath(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
Adds the path for the Fortran runtime libraries to CmdArgs.
llvm::StringRef getLTOParallelism(const llvm::opt::ArgList &Args, const Driver &D)
void addLinkerCompressDebugSectionsOption(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
Definition: CommonArgs.cpp:306
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.
void addLTOOptions(const ToolChain &ToolChain, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const InputInfo &Output, const InputInfo &Input, bool IsThinLTO)
std::tuple< llvm::Reloc::Model, unsigned, bool > ParsePICArgs(const ToolChain &ToolChain, const llvm::opt::ArgList &Args)
void claimNoWarnArgs(const llvm::opt::ArgList &Args)
unsigned DwarfVersionNum(StringRef ArgValue)
void AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const JobAction &JA)
unsigned getDwarfVersion(const ToolChain &TC, const llvm::opt::ArgList &Args)
unsigned getAMDGPUCodeObjectVersion(const Driver &D, const llvm::opt::ArgList &Args)
const llvm::opt::Arg * getDwarfNArg(const llvm::opt::ArgList &Args)
void AddTargetFeature(const llvm::opt::ArgList &Args, std::vector< StringRef > &Features, llvm::opt::OptSpecifier OnOpt, llvm::opt::OptSpecifier OffOpt, StringRef FeatureName)
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.
void addArchSpecificRPath(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
bool isObjCAutoRefCount(const llvm::opt::ArgList &Args)
const char * RelocationModelName(llvm::Reloc::Model Model)
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...
@ C
Languages that the frontend can parse and compile.