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 addGPULibraries(const ToolChain &TC, const llvm::opt::ArgList &Args,
39 llvm::opt::ArgStringList &CmdArgs);
40
41void claimNoWarnArgs(const llvm::opt::ArgList &Args);
42
43bool addSanitizerRuntimes(const ToolChain &TC, const llvm::opt::ArgList &Args,
44 llvm::opt::ArgStringList &CmdArgs);
45
47 const llvm::opt::ArgList &Args,
48 llvm::opt::ArgStringList &CmdArgs);
49
50bool addXRayRuntime(const ToolChain &TC, const llvm::opt::ArgList &Args,
51 llvm::opt::ArgStringList &CmdArgs);
52
53void linkXRayRuntimeDeps(const ToolChain &TC, const llvm::opt::ArgList &Args,
54 llvm::opt::ArgStringList &CmdArgs);
55
56void AddRunTimeLibs(const ToolChain &TC, const Driver &D,
57 llvm::opt::ArgStringList &CmdArgs,
58 const llvm::opt::ArgList &Args);
59
61 const JobAction &JA,
62 const InputInfoList &Inputs,
63 const llvm::opt::ArgList &DriverArgs,
64 llvm::opt::ArgStringList &CmdArgs,
65 StringRef Arch, StringRef Target,
66 bool isBitCodeSDL);
67void 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
73const char *SplitDebugName(const JobAction &JA, const llvm::opt::ArgList &Args,
74 const InputInfo &Input, const InputInfo &Output);
75
76void SplitDebugInfo(const ToolChain &TC, Compilation &C, const Tool &T,
77 const JobAction &JA, const llvm::opt::ArgList &Args,
78 const InputInfo &Output, const char *OutFile);
79
80void addLTOOptions(const ToolChain &ToolChain, const llvm::opt::ArgList &Args,
81 llvm::opt::ArgStringList &CmdArgs, const InputInfo &Output,
82 const InputInfo &Input, bool IsThinLTO);
83
84const char *RelocationModelName(llvm::Reloc::Model Model);
85
86std::tuple<llvm::Reloc::Model, unsigned, bool>
87ParsePICArgs(const ToolChain &ToolChain, const llvm::opt::ArgList &Args);
88
90 const llvm::opt::ArgList &Args);
91
92void addDebugInfoKind(llvm::opt::ArgStringList &CmdArgs,
93 llvm::codegenoptions::DebugInfoKind DebugInfoKind);
94
95llvm::codegenoptions::DebugInfoKind
96debugLevelToInfoKind(const llvm::opt::Arg &A);
97
98// Extract the integer N from a string spelled "-dwarf-N", returning 0
99// on mismatch. The StringRef input (rather than an Arg) allows
100// for use by the "-Xassembler" option parser.
101unsigned DwarfVersionNum(StringRef ArgValue);
102// Find a DWARF format version option.
103// This function is a complementary for DwarfVersionNum().
104const llvm::opt::Arg *getDwarfNArg(const llvm::opt::ArgList &Args);
105unsigned getDwarfVersion(const ToolChain &TC, const llvm::opt::ArgList &Args);
106
108 const llvm::opt::ArgList &Args,
109 llvm::opt::ArgStringList &CmdArgs);
110
111void addArchSpecificRPath(const ToolChain &TC, const llvm::opt::ArgList &Args,
112 llvm::opt::ArgStringList &CmdArgs);
114 const llvm::opt::ArgList &Args,
115 llvm::opt::ArgStringList &CmdArgs);
116/// Returns true, if an OpenMP runtime has been added.
117bool addOpenMPRuntime(const Compilation &C, llvm::opt::ArgStringList &CmdArgs,
118 const ToolChain &TC, const llvm::opt::ArgList &Args,
119 bool ForceStaticHostRuntime = false,
120 bool IsOffloadingHost = false, bool GompNeedsRT = false);
121
122/// Adds offloading options for OpenMP host compilation to \p CmdArgs.
124 const llvm::opt::ArgList &Args,
125 llvm::opt::ArgStringList &CmdArgs);
126
127/// Adds Fortran runtime libraries to \p CmdArgs.
128void addFortranRuntimeLibs(const ToolChain &TC, const llvm::opt::ArgList &Args,
129 llvm::opt::ArgStringList &CmdArgs);
130
131/// Adds the path for the Fortran runtime libraries to \p CmdArgs.
133 const llvm::opt::ArgList &Args,
134 llvm::opt::ArgStringList &CmdArgs);
135
137 const llvm::opt::ArgList &Args,
138 llvm::opt::ArgStringList &CmdArgs);
139
140void addAsNeededOption(const ToolChain &TC, const llvm::opt::ArgList &Args,
141 llvm::opt::ArgStringList &CmdArgs, bool as_needed);
142
143llvm::opt::Arg *getLastCSProfileGenerateArg(const llvm::opt::ArgList &Args);
144llvm::opt::Arg *getLastProfileUseArg(const llvm::opt::ArgList &Args);
145llvm::opt::Arg *getLastProfileSampleUseArg(const llvm::opt::ArgList &Args);
146
147bool isObjCAutoRefCount(const llvm::opt::ArgList &Args);
148
149llvm::StringRef getLTOParallelism(const llvm::opt::ArgList &Args,
150 const Driver &D);
151
152bool areOptimizationsEnabled(const llvm::opt::ArgList &Args);
153
154bool isUseSeparateSections(const llvm::Triple &Triple);
155// Parse -mtls-dialect=. Return true if the target supports both general-dynamic
156// and TLSDESC, and TLSDESC is requested.
157bool isTLSDESCEnabled(const ToolChain &TC, const llvm::opt::ArgList &Args);
158
159/// \p EnvVar is split by system delimiter for environment variables.
160/// If \p ArgName is "-I", "-L", or an empty string, each entry from \p EnvVar
161/// is prefixed by \p ArgName then added to \p Args. Otherwise, for each
162/// entry of \p EnvVar, \p ArgName is added to \p Args first, then the entry
163/// itself is added.
164void addDirectoryList(const llvm::opt::ArgList &Args,
165 llvm::opt::ArgStringList &CmdArgs, const char *ArgName,
166 const char *EnvVar);
167
168void AddTargetFeature(const llvm::opt::ArgList &Args,
169 std::vector<StringRef> &Features,
170 llvm::opt::OptSpecifier OnOpt,
171 llvm::opt::OptSpecifier OffOpt, StringRef FeatureName);
172
173std::string getCPUName(const Driver &D, const llvm::opt::ArgList &Args,
174 const llvm::Triple &T, bool FromAs = false);
175
176void getTargetFeatures(const Driver &D, const llvm::Triple &Triple,
177 const llvm::opt::ArgList &Args,
178 llvm::opt::ArgStringList &CmdArgs, bool ForAS,
179 bool IsAux = false);
180
181/// Iterate \p Args and convert -mxxx to +xxx and -mno-xxx to -xxx and
182/// append it to \p Features.
183///
184/// Note: Since \p Features may contain default values before calling
185/// this function, or may be appended with entries to override arguments,
186/// entries in \p Features are not unique.
187void handleTargetFeaturesGroup(const Driver &D, const llvm::Triple &Triple,
188 const llvm::opt::ArgList &Args,
189 std::vector<StringRef> &Features,
190 llvm::opt::OptSpecifier Group);
191
192/// If there are multiple +xxx or -xxx features, keep the last one.
194
195/// Handles the -save-stats option and returns the filename to save statistics
196/// to.
197SmallString<128> getStatsFileName(const llvm::opt::ArgList &Args,
198 const InputInfo &Output,
199 const InputInfo &Input, const Driver &D);
200
201/// \p Flag must be a flag accepted by the driver.
202void addMultilibFlag(bool Enabled, const StringRef Flag,
203 Multilib::flags_list &Flags);
204
205void addX86AlignBranchArgs(const Driver &D, const llvm::opt::ArgList &Args,
206 llvm::opt::ArgStringList &CmdArgs, bool IsLTO,
207 const StringRef PluginOptPrefix = "");
208
210 const llvm::opt::ArgList &Args);
211
212unsigned getAMDGPUCodeObjectVersion(const Driver &D,
213 const llvm::opt::ArgList &Args);
214
216 const llvm::opt::ArgList &Args);
217
218void addMachineOutlinerArgs(const Driver &D, const llvm::opt::ArgList &Args,
219 llvm::opt::ArgStringList &CmdArgs,
220 const llvm::Triple &Triple, bool IsLTO,
221 const StringRef PluginOptPrefix = "");
222
223void addOpenMPDeviceRTL(const Driver &D, const llvm::opt::ArgList &DriverArgs,
224 llvm::opt::ArgStringList &CC1Args,
225 StringRef BitcodeSuffix, const llvm::Triple &Triple,
226 const ToolChain &HostTC);
227
228void addOutlineAtomicsArgs(const Driver &D, const ToolChain &TC,
229 const llvm::opt::ArgList &Args,
230 llvm::opt::ArgStringList &CmdArgs,
231 const llvm::Triple &Triple);
232void addOffloadCompressArgs(const llvm::opt::ArgList &TCArgs,
233 llvm::opt::ArgStringList &CmdArgs);
234void addMCModel(const Driver &D, const llvm::opt::ArgList &Args,
235 const llvm::Triple &Triple,
236 const llvm::Reloc::Model &RelocationModel,
237 llvm::opt::ArgStringList &CmdArgs);
238
239} // end namespace tools
240} // end namespace driver
241} // end namespace clang
242
244getFramePointerKind(const llvm::opt::ArgList &Args, const llvm::Triple &Triple);
245
246#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:212
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: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.
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:379
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 addGPULibraries(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
Definition: CommonArgs.cpp:513
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:797
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:801
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:341
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:495
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)
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