clang 19.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 Fortran runtime libraries to \p CmdArgs.
120void addFortranRuntimeLibs(const ToolChain &TC, const llvm::opt::ArgList &Args,
121 llvm::opt::ArgStringList &CmdArgs);
122
123/// Adds the path for the Fortran runtime libraries to \p CmdArgs.
125 const llvm::opt::ArgList &Args,
126 llvm::opt::ArgStringList &CmdArgs);
127
129 const llvm::opt::ArgList &Args,
130 llvm::opt::ArgStringList &CmdArgs);
131
132void addAsNeededOption(const ToolChain &TC, const llvm::opt::ArgList &Args,
133 llvm::opt::ArgStringList &CmdArgs, bool as_needed);
134
135llvm::opt::Arg *getLastCSProfileGenerateArg(const llvm::opt::ArgList &Args);
136llvm::opt::Arg *getLastProfileUseArg(const llvm::opt::ArgList &Args);
137llvm::opt::Arg *getLastProfileSampleUseArg(const llvm::opt::ArgList &Args);
138
139bool isObjCAutoRefCount(const llvm::opt::ArgList &Args);
140
141llvm::StringRef getLTOParallelism(const llvm::opt::ArgList &Args,
142 const Driver &D);
143
144bool areOptimizationsEnabled(const llvm::opt::ArgList &Args);
145
146bool isUseSeparateSections(const llvm::Triple &Triple);
147// Parse -mtls-dialect=. Return true if the target supports both general-dynamic
148// and TLSDESC, and TLSDESC is requested.
149bool isTLSDESCEnabled(const ToolChain &TC, const llvm::opt::ArgList &Args);
150
151/// \p EnvVar is split by system delimiter for environment variables.
152/// If \p ArgName is "-I", "-L", or an empty string, each entry from \p EnvVar
153/// is prefixed by \p ArgName then added to \p Args. Otherwise, for each
154/// entry of \p EnvVar, \p ArgName is added to \p Args first, then the entry
155/// itself is added.
156void addDirectoryList(const llvm::opt::ArgList &Args,
157 llvm::opt::ArgStringList &CmdArgs, const char *ArgName,
158 const char *EnvVar);
159
160void AddTargetFeature(const llvm::opt::ArgList &Args,
161 std::vector<StringRef> &Features,
162 llvm::opt::OptSpecifier OnOpt,
163 llvm::opt::OptSpecifier OffOpt, StringRef FeatureName);
164
165std::string getCPUName(const Driver &D, const llvm::opt::ArgList &Args,
166 const llvm::Triple &T, bool FromAs = false);
167
168void getTargetFeatures(const Driver &D, const llvm::Triple &Triple,
169 const llvm::opt::ArgList &Args,
170 llvm::opt::ArgStringList &CmdArgs, bool ForAS,
171 bool IsAux = false);
172
173/// Iterate \p Args and convert -mxxx to +xxx and -mno-xxx to -xxx and
174/// append it to \p Features.
175///
176/// Note: Since \p Features may contain default values before calling
177/// this function, or may be appended with entries to override arguments,
178/// entries in \p Features are not unique.
179void handleTargetFeaturesGroup(const Driver &D, const llvm::Triple &Triple,
180 const llvm::opt::ArgList &Args,
181 std::vector<StringRef> &Features,
182 llvm::opt::OptSpecifier Group);
183
184/// If there are multiple +xxx or -xxx features, keep the last one.
186
187/// Handles the -save-stats option and returns the filename to save statistics
188/// to.
189SmallString<128> getStatsFileName(const llvm::opt::ArgList &Args,
190 const InputInfo &Output,
191 const InputInfo &Input, const Driver &D);
192
193/// \p Flag must be a flag accepted by the driver.
194void addMultilibFlag(bool Enabled, const StringRef Flag,
195 Multilib::flags_list &Flags);
196
197void addX86AlignBranchArgs(const Driver &D, const llvm::opt::ArgList &Args,
198 llvm::opt::ArgStringList &CmdArgs, bool IsLTO,
199 const StringRef PluginOptPrefix = "");
200
202 const llvm::opt::ArgList &Args);
203
204unsigned getAMDGPUCodeObjectVersion(const Driver &D,
205 const llvm::opt::ArgList &Args);
206
208 const llvm::opt::ArgList &Args);
209
210void addMachineOutlinerArgs(const Driver &D, const llvm::opt::ArgList &Args,
211 llvm::opt::ArgStringList &CmdArgs,
212 const llvm::Triple &Triple, bool IsLTO,
213 const StringRef PluginOptPrefix = "");
214
215void addOpenMPDeviceRTL(const Driver &D, const llvm::opt::ArgList &DriverArgs,
216 llvm::opt::ArgStringList &CC1Args,
217 StringRef BitcodeSuffix, const llvm::Triple &Triple,
218 const ToolChain &HostTC);
219
220void addOutlineAtomicsArgs(const Driver &D, const ToolChain &TC,
221 const llvm::opt::ArgList &Args,
222 llvm::opt::ArgStringList &CmdArgs,
223 const llvm::Triple &Triple);
224void addOffloadCompressArgs(const llvm::opt::ArgList &TCArgs,
225 llvm::opt::ArgStringList &CmdArgs);
226
227} // end namespace tools
228} // end namespace driver
229} // end namespace clang
230
232getFramePointerKind(const llvm::opt::ArgList &Args, const llvm::Triple &Triple);
233
234#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_COMMONARGS_H
clang::CodeGenOptions::FramePointerKind getFramePointerKind(const llvm::opt::ArgList &Args, const llvm::Triple &Triple)
Definition: CommonArgs.cpp:180
llvm::MachO::Target Target
Definition: MachO.h:48
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 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.
SmallVector< StringRef > unifyTargetFeatures(ArrayRef< StringRef > Features)
If there are multiple +xxx or -xxx features, keep the last one.
Definition: CommonArgs.cpp:328
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)
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:727
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:731
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:290
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:444
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.
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)
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)
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * T