Debian Codegraph @

clang/lib/Driver/ToolChains/CommonArgs.h

raw
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
23 namespace clang {
24 namespace driver {
25 namespace tools {
26
27 void addPathIfExists(const Driver &D, const Twine &Path,
28 ToolChain::path_list &Paths);
29
30 void AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs,
31 const llvm::opt::ArgList &Args,
32 llvm::opt::ArgStringList &CmdArgs, const JobAction &JA);
33
34 void addLinkerCompressDebugSectionsOption(const ToolChain &TC,
35 const llvm::opt::ArgList &Args,
36 llvm::opt::ArgStringList &CmdArgs);
37
38 void claimNoWarnArgs(const llvm::opt::ArgList &Args);
39
40 bool addSanitizerRuntimes(const ToolChain &TC, const llvm::opt::ArgList &Args,
41 llvm::opt::ArgStringList &CmdArgs);
42
43 void linkSanitizerRuntimeDeps(const ToolChain &TC,
44 const llvm::opt::ArgList &Args,
45 llvm::opt::ArgStringList &CmdArgs);
46
47 bool addXRayRuntime(const ToolChain &TC, const llvm::opt::ArgList &Args,
48 llvm::opt::ArgStringList &CmdArgs);
49
50 void linkXRayRuntimeDeps(const ToolChain &TC, const llvm::opt::ArgList &Args,
51 llvm::opt::ArgStringList &CmdArgs);
52
53 void AddRunTimeLibs(const ToolChain &TC, const Driver &D,
54 llvm::opt::ArgStringList &CmdArgs,
55 const llvm::opt::ArgList &Args);
56
57 void 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);
64 void 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
70 const char *SplitDebugName(const JobAction &JA, const llvm::opt::ArgList &Args,
71 const InputInfo &Input, const InputInfo &Output);
72
73 void 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
77 void addLTOOptions(const ToolChain &ToolChain, const llvm::opt::ArgList &Args,
78 llvm::opt::ArgStringList &CmdArgs, const InputInfo &Output,
79 const InputInfo &Input, bool IsThinLTO);
80
81 const char *RelocationModelName(llvm::Reloc::Model Model);
82
83 std::tuple<llvm::Reloc::Model, unsigned, bool>
84 ParsePICArgs(const ToolChain &ToolChain, const llvm::opt::ArgList &Args);
85
86 unsigned ParseFunctionAlignment(const ToolChain &TC,
87 const llvm::opt::ArgList &Args);
88
89 void addDebugInfoKind(llvm::opt::ArgStringList &CmdArgs,
90 llvm::codegenoptions::DebugInfoKind DebugInfoKind);
91
92 llvm::codegenoptions::DebugInfoKind
93 debugLevelToInfoKind(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.
98 unsigned DwarfVersionNum(StringRef ArgValue);
99 // Find a DWARF format version option.
100 // This function is a complementary for DwarfVersionNum().
101 const llvm::opt::Arg *getDwarfNArg(const llvm::opt::ArgList &Args);
102 unsigned getDwarfVersion(const ToolChain &TC, const llvm::opt::ArgList &Args);
103
104 void AddAssemblerKPIC(const ToolChain &ToolChain,
105 const llvm::opt::ArgList &Args,
106 llvm::opt::ArgStringList &CmdArgs);
107
108 void addArchSpecificRPath(const ToolChain &TC, const llvm::opt::ArgList &Args,
109 llvm::opt::ArgStringList &CmdArgs);
110 void 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.
114 bool 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.
120 void 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.
124 void addFortranRuntimeLibraryPath(const ToolChain &TC,
125 const llvm::opt::ArgList &Args,
126 llvm::opt::ArgStringList &CmdArgs);
127
128 void addHIPRuntimeLibArgs(const ToolChain &TC, Compilation &C,
129 const llvm::opt::ArgList &Args,
130 llvm::opt::ArgStringList &CmdArgs);
131
132 void addAsNeededOption(const ToolChain &TC, const llvm::opt::ArgList &Args,
133 llvm::opt::ArgStringList &CmdArgs, bool as_needed);
134
135 llvm::opt::Arg *getLastCSProfileGenerateArg(const llvm::opt::ArgList &Args);
136 llvm::opt::Arg *getLastProfileUseArg(const llvm::opt::ArgList &Args);
137 llvm::opt::Arg *getLastProfileSampleUseArg(const llvm::opt::ArgList &Args);
138
139 bool isObjCAutoRefCount(const llvm::opt::ArgList &Args);
140
141 llvm::StringRef getLTOParallelism(const llvm::opt::ArgList &Args,
142 const Driver &D);
143
144 bool areOptimizationsEnabled(const llvm::opt::ArgList &Args);
145
146 bool 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.
149 bool 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.
156 void addDirectoryList(const llvm::opt::ArgList &Args,
157 llvm::opt::ArgStringList &CmdArgs, const char *ArgName,
158 const char *EnvVar);
159
160 void AddTargetFeature(const llvm::opt::ArgList &Args,
161 std::vector<StringRef> &Features,
162 llvm::opt::OptSpecifier OnOpt,
163 llvm::opt::OptSpecifier OffOpt, StringRef FeatureName);
164
165 std::string getCPUName(const Driver &D, const llvm::opt::ArgList &Args,
166 const llvm::Triple &T, bool FromAs = false);
167
168 void 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.
179 void 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.
185 SmallVector<StringRef> unifyTargetFeatures(ArrayRef<StringRef> Features);
186
187 /// Handles the -save-stats option and returns the filename to save statistics
188 /// to.
189 SmallString<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.
194 void addMultilibFlag(bool Enabled, const StringRef Flag,
195 Multilib::flags_list &Flags);
196
197 void addX86AlignBranchArgs(const Driver &D, const llvm::opt::ArgList &Args,
198 llvm::opt::ArgStringList &CmdArgs, bool IsLTO,
199 const StringRef PluginOptPrefix = "");
200
201 void checkAMDGPUCodeObjectVersion(const Driver &D,
202 const llvm::opt::ArgList &Args);
203
204 unsigned getAMDGPUCodeObjectVersion(const Driver &D,
205 const llvm::opt::ArgList &Args);
206
207 bool haveAMDGPUCodeObjectVersionArgument(const Driver &D,
208 const llvm::opt::ArgList &Args);
209
210 void 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
215 void 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
220 void addOutlineAtomicsArgs(const Driver &D, const ToolChain &TC,
221 const llvm::opt::ArgList &Args,
222 llvm::opt::ArgStringList &CmdArgs,
223 const llvm::Triple &Triple);
224 void addOffloadCompressArgs(const llvm::opt::ArgList &TCArgs,
225 llvm::opt::ArgStringList &CmdArgs);
226 void addMCModel(const Driver &D, const llvm::opt::ArgList &Args,
227 const llvm::Triple &Triple,
228 const llvm::Reloc::Model &RelocationModel,
229 llvm::opt::ArgStringList &CmdArgs);
230
231 } // end namespace tools
232 } // end namespace driver
233 } // end namespace clang
234
235 clang::CodeGenOptions::FramePointerKind
236 getFramePointerKind(const llvm::opt::ArgList &Args, const llvm::Triple &Triple);
237
238 #endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_COMMONARGS_H