clang 20.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
13#include "clang/Driver/Driver.h"
16#include "clang/Driver/Tool.h"
18#include "llvm/ADT/StringRef.h"
19#include "llvm/Option/Arg.h"
20#include "llvm/Option/ArgList.h"
21#include "llvm/Support/CodeGen.h"
22
23namespace clang {
24namespace driver {
25namespace tools {
26
27void addPathIfExists(const Driver &D, const Twine &Path,
29
30void AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs,
31 const llvm::opt::ArgList &Args,
32 llvm::opt::ArgStringList &CmdArgs, const JobAction &JA);
33
35 const llvm::opt::ArgList &Args,
36 llvm::opt::ArgStringList &CmdArgs);
37
38void claimNoWarnArgs(const llvm::opt::ArgList &Args);
39
40bool addSanitizerRuntimes(const ToolChain &TC, const llvm::opt::ArgList &Args,
41 llvm::opt::ArgStringList &CmdArgs);
42
44 const llvm::opt::ArgList &Args,
45 llvm::opt::ArgStringList &CmdArgs);
46
47bool addXRayRuntime(const ToolChain &TC, const llvm::opt::ArgList &Args,
48 llvm::opt::ArgStringList &CmdArgs);
49
50void linkXRayRuntimeDeps(const ToolChain &TC, const llvm::opt::ArgList &Args,
51 llvm::opt::ArgStringList &CmdArgs);
52
53void AddRunTimeLibs(const ToolChain &TC, const Driver &D,
54 llvm::opt::ArgStringList &CmdArgs,
55 const llvm::opt::ArgList &Args);
56
58 const JobAction &JA,
59 const InputInfoList &Inputs,
60 const llvm::opt::ArgList &DriverArgs,
61 llvm::opt::ArgStringList &CmdArgs,
62 StringRef Arch, StringRef Target,
63 bool isBitCodeSDL);
64void 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
70const char *SplitDebugName(const JobAction &JA, const llvm::opt::ArgList &Args,
71 const InputInfo &Input, const InputInfo &Output);
72
73void SplitDebugInfo(const ToolChain &TC, Compilation &C, const Tool &T,
74 const JobAction &JA, const llvm::opt::ArgList &Args,
75 const InputInfo &Output, const char *OutFile);
76
77void addLTOOptions(const ToolChain &ToolChain, const llvm::opt::ArgList &Args,
78 llvm::opt::ArgStringList &CmdArgs, const InputInfo &Output,
79 const InputInfo &Input, bool IsThinLTO);
80
81const char *RelocationModelName(llvm::Reloc::Model Model);
82
83std::tuple<llvm::Reloc::Model, unsigned, bool>
84ParsePICArgs(const ToolChain &ToolChain, const llvm::opt::ArgList &Args);
85
87 const llvm::opt::ArgList &Args);
88
89void addDebugInfoKind(llvm::opt::ArgStringList &CmdArgs,
90 llvm::codegenoptions::DebugInfoKind DebugInfoKind);
91
92llvm::codegenoptions::DebugInfoKind
93debugLevelToInfoKind(const llvm::opt::Arg &A);
94
95// Extract the integer N from a string spelled "-dwarf-N", returning 0
96// on mismatch. The StringRef input (rather than an Arg) allows
97// for use by the "-Xassembler" option parser.
98unsigned DwarfVersionNum(StringRef ArgValue);
99// Find a DWARF format version option.
100// This function is a complementary for DwarfVersionNum().
101const llvm::opt::Arg *getDwarfNArg(const llvm::opt::ArgList &Args);
102unsigned getDwarfVersion(const ToolChain &TC, const llvm::opt::ArgList &Args);
103
105 const llvm::opt::ArgList &Args,
106 llvm::opt::ArgStringList &CmdArgs);
107
108void addArchSpecificRPath(const ToolChain &TC, const llvm::opt::ArgList &Args,
109 llvm::opt::ArgStringList &CmdArgs);
111 const llvm::opt::ArgList &Args,
112 llvm::opt::ArgStringList &CmdArgs);
113/// Returns true, if an OpenMP runtime has been added.
114bool addOpenMPRuntime(const Compilation &C, llvm::opt::ArgStringList &CmdArgs,
115 const ToolChain &TC, const llvm::opt::ArgList &Args,
116 bool ForceStaticHostRuntime = false,
117 bool IsOffloadingHost = false, bool GompNeedsRT = false);
118
119/// Adds offloading options for OpenMP host compilation to \p CmdArgs.
121 const llvm::opt::ArgList &Args,
122 llvm::opt::ArgStringList &CmdArgs);
123
124/// Adds Fortran runtime libraries to \p CmdArgs.
125void addFortranRuntimeLibs(const ToolChain &TC, const llvm::opt::ArgList &Args,
126 llvm::opt::ArgStringList &CmdArgs);
127
128/// Adds the path for the Fortran runtime libraries to \p CmdArgs.
130 const llvm::opt::ArgList &Args,
131 llvm::opt::ArgStringList &CmdArgs);
132
134 const llvm::opt::ArgList &Args,
135 llvm::opt::ArgStringList &CmdArgs);
136
137void addAsNeededOption(const ToolChain &TC, const llvm::opt::ArgList &Args,
138 llvm::opt::ArgStringList &CmdArgs, bool as_needed);
139
140llvm::opt::Arg *getLastCSProfileGenerateArg(const llvm::opt::ArgList &Args);
141llvm::opt::Arg *getLastProfileUseArg(const llvm::opt::ArgList &Args);
142llvm::opt::Arg *getLastProfileSampleUseArg(const llvm::opt::ArgList &Args);
143
144bool isObjCAutoRefCount(const llvm::opt::ArgList &Args);
145
146llvm::StringRef getLTOParallelism(const llvm::opt::ArgList &Args,
147 const Driver &D);
148
149bool areOptimizationsEnabled(const llvm::opt::ArgList &Args);
150
151bool isUseSeparateSections(const llvm::Triple &Triple);
152// Parse -mtls-dialect=. Return true if the target supports both general-dynamic
153// and TLSDESC, and TLSDESC is requested.
154bool isTLSDESCEnabled(const ToolChain &TC, const llvm::opt::ArgList &Args);
155
156/// \p EnvVar is split by system delimiter for environment variables.
157/// If \p ArgName is "-I", "-L", or an empty string, each entry from \p EnvVar
158/// is prefixed by \p ArgName then added to \p Args. Otherwise, for each
159/// entry of \p EnvVar, \p ArgName is added to \p Args first, then the entry
160/// itself is added.
161void addDirectoryList(const llvm::opt::ArgList &Args,
162 llvm::opt::ArgStringList &CmdArgs, const char *ArgName,
163 const char *EnvVar);
164
165void AddTargetFeature(const llvm::opt::ArgList &Args,
166 std::vector<StringRef> &Features,
167 llvm::opt::OptSpecifier OnOpt,
168 llvm::opt::OptSpecifier OffOpt, StringRef FeatureName);
169
170std::string getCPUName(const Driver &D, const llvm::opt::ArgList &Args,
171 const llvm::Triple &T, bool FromAs = false);
172
173void getTargetFeatures(const Driver &D, const llvm::Triple &Triple,
174 const llvm::opt::ArgList &Args,
175 llvm::opt::ArgStringList &CmdArgs, bool ForAS,
176 bool IsAux = false);
177
178/// Iterate \p Args and convert -mxxx to +xxx and -mno-xxx to -xxx and
179/// append it to \p Features.
180///
181/// Note: Since \p Features may contain default values before calling
182/// this function, or may be appended with entries to override arguments,
183/// entries in \p Features are not unique.
184void handleTargetFeaturesGroup(const Driver &D, const llvm::Triple &Triple,
185 const llvm::opt::ArgList &Args,
186 std::vector<StringRef> &Features,
187 llvm::opt::OptSpecifier Group);
188
189/// If there are multiple +xxx or -xxx features, keep the last one.
191
192/// Handles the -save-stats option and returns the filename to save statistics
193/// to.
194SmallString<128> getStatsFileName(const llvm::opt::ArgList &Args,
195 const InputInfo &Output,
196 const InputInfo &Input, const Driver &D);
197
198/// \p Flag must be a flag accepted by the driver.
199void addMultilibFlag(bool Enabled, const StringRef Flag,
200 Multilib::flags_list &Flags);
201
202void addX86AlignBranchArgs(const Driver &D, const llvm::opt::ArgList &Args,
203 llvm::opt::ArgStringList &CmdArgs, bool IsLTO,
204 const StringRef PluginOptPrefix = "");
205
207 const llvm::opt::ArgList &Args);
208
209unsigned getAMDGPUCodeObjectVersion(const Driver &D,
210 const llvm::opt::ArgList &Args);
211
213 const llvm::opt::ArgList &Args);
214
215void addMachineOutlinerArgs(const Driver &D, const llvm::opt::ArgList &Args,
216 llvm::opt::ArgStringList &CmdArgs,
217 const llvm::Triple &Triple, bool IsLTO,
218 const StringRef PluginOptPrefix = "");
219
220void addOpenMPDeviceRTL(const Driver &D, const llvm::opt::ArgList &DriverArgs,
221 llvm::opt::ArgStringList &CC1Args,
222 StringRef BitcodeSuffix, const llvm::Triple &Triple,
223 const ToolChain &HostTC);
224
225void addOutlineAtomicsArgs(const Driver &D, const ToolChain &TC,
226 const llvm::opt::ArgList &Args,
227 llvm::opt::ArgStringList &CmdArgs,
228 const llvm::Triple &Triple);
229void addOffloadCompressArgs(const llvm::opt::ArgList &TCArgs,
230 llvm::opt::ArgStringList &CmdArgs);
231void addMCModel(const Driver &D, const llvm::opt::ArgList &Args,
232 const llvm::Triple &Triple,
233 const llvm::Reloc::Model &RelocationModel,
234 llvm::opt::ArgStringList &CmdArgs);
235
236/// Handle the -f{no}-color-diagnostics and -f{no}-diagnostics-colors options.
237void handleColorDiagnosticsArgs(const Driver &D, const llvm::opt::ArgList &Args,
238 llvm::opt::ArgStringList &CmdArgs);
239
240/// Add backslashes to escape spaces and other backslashes.
241/// This is used for the space-separated argument list specified with
242/// the -dwarf-debug-flags option.
243void escapeSpacesAndBackslashes(const char *Arg,
245
246/// Join the args in the given ArgList, escape spaces and backslashes and
247/// return the joined string. This is used when saving the command line as a
248/// result of using either the -frecord-command-line or -grecord-command-line
249/// options. The lifetime of the returned c-string will match that of the Args
250/// argument.
251const char *renderEscapedCommandLine(const ToolChain &TC,
252 const llvm::opt::ArgList &Args);
253
254/// Check if the command line should be recorded in the object file. This is
255/// done if either -frecord-command-line or -grecord-command-line options have
256/// been passed. This also does some error checking since -frecord-command-line
257/// is currently only supported on ELF platforms. The last two boolean
258/// arguments are out parameters and will be set depending on the command
259/// line options that were passed.
261 const llvm::opt::ArgList &Args,
262 bool &FRecordCommandLine,
263 bool &GRecordCommandLine);
264
265void renderCommonIntegerOverflowOptions(const llvm::opt::ArgList &Args,
266 llvm::opt::ArgStringList &CmdArgs);
267
268} // end namespace tools
269} // end namespace driver
270} // end namespace clang
271
273getFramePointerKind(const llvm::opt::ArgList &Args, const llvm::Triple &Triple);
274
275#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_COMMONARGS_H
const Decl * D
IndirectLocalPath & Path
clang::CodeGenOptions::FramePointerKind getFramePointerKind(const llvm::opt::ArgList &Args, const llvm::Triple &Triple)
Definition: CommonArgs.cpp:216
llvm::MachO::Target Target
Definition: MachO.h:51
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:37
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 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)
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 addOffloadCompressArgs(const llvm::opt::ArgList &TCArgs, llvm::opt::ArgStringList &CmdArgs)
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.
void addMCModel(const Driver &D, const llvm::opt::ArgList &Args, const llvm::Triple &Triple, const llvm::Reloc::Model &RelocationModel, llvm::opt::ArgStringList &CmdArgs)
SmallVector< StringRef > unifyTargetFeatures(ArrayRef< StringRef > Features)
If there are multiple +xxx or -xxx features, keep the last one.
Definition: CommonArgs.cpp:383
llvm::opt::Arg * getLastProfileSampleUseArg(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, const ToolChain &HostTC)
const char * SplitDebugName(const JobAction &JA, const llvm::opt::ArgList &Args, const InputInfo &Input, const InputInfo &Output)
void addOutlineAtomicsArgs(const Driver &D, const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const llvm::Triple &Triple)
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 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)
void addAsNeededOption(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, bool as_needed)
void handleColorDiagnosticsArgs(const Driver &D, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
Handle the -f{no}-color-diagnostics and -f{no}-diagnostics-colors options.
std::string getCPUName(const Driver &D, const llvm::opt::ArgList &Args, const llvm::Triple &T, bool FromAs=false)
bool shouldRecordCommandLine(const ToolChain &TC, const llvm::opt::ArgList &Args, bool &FRecordCommandLine, bool &GRecordCommandLine)
Check if the command line should be recorded in the object file.
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:818
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)
bool isTLSDESCEnabled(const ToolChain &TC, const llvm::opt::ArgList &Args)
Definition: CommonArgs.cpp:822
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:345
llvm::codegenoptions::DebugInfoKind debugLevelToInfoKind(const llvm::opt::Arg &A)
llvm::opt::Arg * getLastCSProfileGenerateArg(const llvm::opt::ArgList &Args)
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:532
const char * renderEscapedCommandLine(const ToolChain &TC, const llvm::opt::ArgList &Args)
Join the args in the given ArgList, escape spaces and backslashes and return the joined string.
void addLTOOptions(const ToolChain &ToolChain, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const InputInfo &Output, const InputInfo &Input, bool IsThinLTO)
bool addOpenMPRuntime(const Compilation &C, 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 renderCommonIntegerOverflowOptions(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
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)
void escapeSpacesAndBackslashes(const char *Arg, llvm::SmallVectorImpl< char > &Res)
Add backslashes to escape spaces and other backslashes.
bool isObjCAutoRefCount(const llvm::opt::ArgList &Args)
void addFortranRuntimeLibs(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
Adds Fortran runtime libraries to CmdArgs.
const char * RelocationModelName(llvm::Reloc::Model Model)
void addOpenMPHostOffloadingArgs(const Compilation &C, const JobAction &JA, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
Adds offloading options for OpenMP host compilation to CmdArgs.
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * T