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/Basic/CodeGenOptions.h"
13#include "clang/Driver/Driver.h"
14#include "clang/Driver/InputInfo.h"
15#include "clang/Driver/Multilib.h"
16#include "clang/Driver/Tool.h"
17#include "clang/Driver/ToolChain.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,
28 ToolChain::path_list &Paths);
29
30void AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs,
31 const llvm::opt::ArgList &Args,
32 llvm::opt::ArgStringList &CmdArgs, const JobAction &JA);
33
34void addLinkerCompressDebugSectionsOption(const ToolChain &TC,
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
43void linkSanitizerRuntimeDeps(const ToolChain &TC,
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
57void AddStaticDeviceLibsLinking(Compilation &C, const Tool &T,
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
86unsigned ParseFunctionAlignment(const ToolChain &TC,
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
104void AddAssemblerKPIC(const ToolChain &ToolChain,
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);
110void addOpenMPRuntimeLibraryPath(const ToolChain &TC,
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.
124void addFortranRuntimeLibraryPath(const ToolChain &TC,
125 const llvm::opt::ArgList &Args,
126 llvm::opt::ArgStringList &CmdArgs);
127
128void addHIPRuntimeLibArgs(const ToolChain &TC, Compilation &C,
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.
185SmallVector<StringRef> unifyTargetFeatures(ArrayRef<StringRef> Features);
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
201void checkAMDGPUCodeObjectVersion(const Driver &D,
202 const llvm::opt::ArgList &Args);
203
204unsigned getAMDGPUCodeObjectVersion(const Driver &D,
205 const llvm::opt::ArgList &Args);
206
207bool haveAMDGPUCodeObjectVersionArgument(const Driver &D,
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
231clang::CodeGenOptions::FramePointerKind
232getFramePointerKind(const llvm::opt::ArgList &Args, const llvm::Triple &Triple);
233
234#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_COMMONARGS_H
235

source code of clang/lib/Driver/ToolChains/CommonArgs.h