xref: /freebsd/contrib/llvm-project/clang/lib/Driver/ToolChains/CommonArgs.h (revision 7ef62cebc2f965b0f640263e179276928885e33d)
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/Driver/Driver.h"
13 #include "clang/Driver/InputInfo.h"
14 #include "clang/Driver/Multilib.h"
15 #include "clang/Driver/Tool.h"
16 #include "clang/Driver/ToolChain.h"
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/Option/Arg.h"
19 #include "llvm/Option/ArgList.h"
20 #include "llvm/Support/CodeGen.h"
21 
22 namespace clang {
23 namespace driver {
24 namespace tools {
25 
26 void addPathIfExists(const Driver &D, const Twine &Path,
27                      ToolChain::path_list &Paths);
28 
29 void AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs,
30                      const llvm::opt::ArgList &Args,
31                      llvm::opt::ArgStringList &CmdArgs, const JobAction &JA);
32 
33 void addLinkerCompressDebugSectionsOption(const ToolChain &TC,
34                                           const llvm::opt::ArgList &Args,
35                                           llvm::opt::ArgStringList &CmdArgs);
36 
37 void claimNoWarnArgs(const llvm::opt::ArgList &Args);
38 
39 bool addSanitizerRuntimes(const ToolChain &TC, const llvm::opt::ArgList &Args,
40                           llvm::opt::ArgStringList &CmdArgs);
41 
42 void linkSanitizerRuntimeDeps(const ToolChain &TC,
43                               llvm::opt::ArgStringList &CmdArgs);
44 
45 bool addXRayRuntime(const ToolChain &TC, const llvm::opt::ArgList &Args,
46                     llvm::opt::ArgStringList &CmdArgs);
47 
48 void linkXRayRuntimeDeps(const ToolChain &TC,
49                          llvm::opt::ArgStringList &CmdArgs);
50 
51 void AddRunTimeLibs(const ToolChain &TC, const Driver &D,
52                     llvm::opt::ArgStringList &CmdArgs,
53                     const llvm::opt::ArgList &Args);
54 
55 void AddStaticDeviceLibsLinking(Compilation &C, const Tool &T,
56                                 const JobAction &JA,
57                                 const InputInfoList &Inputs,
58                                 const llvm::opt::ArgList &DriverArgs,
59                                 llvm::opt::ArgStringList &CmdArgs,
60                                 StringRef Arch, StringRef Target,
61                                 bool isBitCodeSDL, bool postClangLink);
62 void AddStaticDeviceLibsPostLinking(const Driver &D,
63                                     const llvm::opt::ArgList &DriverArgs,
64                                     llvm::opt::ArgStringList &CmdArgs,
65                                     StringRef Arch, StringRef Target,
66                                     bool isBitCodeSDL, bool postClangLink);
67 void 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                          bool postClangLink);
73 
74 bool SDLSearch(const Driver &D, const llvm::opt::ArgList &DriverArgs,
75                llvm::opt::ArgStringList &CmdArgs,
76                SmallVector<std::string, 8> LibraryPaths, std::string Lib,
77                StringRef Arch, StringRef Target, bool isBitCodeSDL,
78                bool postClangLink);
79 
80 bool GetSDLFromOffloadArchive(Compilation &C, const Driver &D, const Tool &T,
81                               const JobAction &JA, const InputInfoList &Inputs,
82                               const llvm::opt::ArgList &DriverArgs,
83                               llvm::opt::ArgStringList &CC1Args,
84                               SmallVector<std::string, 8> LibraryPaths,
85                               StringRef Lib, StringRef Arch, StringRef Target,
86                               bool isBitCodeSDL, bool postClangLink);
87 
88 const char *SplitDebugName(const JobAction &JA, const llvm::opt::ArgList &Args,
89                            const InputInfo &Input, const InputInfo &Output);
90 
91 void SplitDebugInfo(const ToolChain &TC, Compilation &C, const Tool &T,
92                     const JobAction &JA, const llvm::opt::ArgList &Args,
93                     const InputInfo &Output, const char *OutFile);
94 
95 void addLTOOptions(const ToolChain &ToolChain, const llvm::opt::ArgList &Args,
96                    llvm::opt::ArgStringList &CmdArgs, const InputInfo &Output,
97                    const InputInfo &Input, bool IsThinLTO);
98 
99 const char *RelocationModelName(llvm::Reloc::Model Model);
100 
101 std::tuple<llvm::Reloc::Model, unsigned, bool>
102 ParsePICArgs(const ToolChain &ToolChain, const llvm::opt::ArgList &Args);
103 
104 unsigned ParseFunctionAlignment(const ToolChain &TC,
105                                 const llvm::opt::ArgList &Args);
106 
107 // Extract the integer N from a string spelled "-dwarf-N", returning 0
108 // on mismatch. The StringRef input (rather than an Arg) allows
109 // for use by the "-Xassembler" option parser.
110 unsigned DwarfVersionNum(StringRef ArgValue);
111 // Find a DWARF format version option.
112 // This function is a complementary for DwarfVersionNum().
113 const llvm::opt::Arg *getDwarfNArg(const llvm::opt::ArgList &Args);
114 unsigned getDwarfVersion(const ToolChain &TC, const llvm::opt::ArgList &Args);
115 
116 void AddAssemblerKPIC(const ToolChain &ToolChain,
117                       const llvm::opt::ArgList &Args,
118                       llvm::opt::ArgStringList &CmdArgs);
119 
120 void addOpenMPRuntimeSpecificRPath(const ToolChain &TC,
121                                    const llvm::opt::ArgList &Args,
122                                    llvm::opt::ArgStringList &CmdArgs);
123 void addArchSpecificRPath(const ToolChain &TC, const llvm::opt::ArgList &Args,
124                           llvm::opt::ArgStringList &CmdArgs);
125 void addOpenMPRuntimeLibraryPath(const ToolChain &TC,
126                                  const llvm::opt::ArgList &Args,
127                                  llvm::opt::ArgStringList &CmdArgs);
128 /// Returns true, if an OpenMP runtime has been added.
129 bool addOpenMPRuntime(llvm::opt::ArgStringList &CmdArgs, const ToolChain &TC,
130                       const llvm::opt::ArgList &Args,
131                       bool ForceStaticHostRuntime = false,
132                       bool IsOffloadingHost = false, bool GompNeedsRT = false);
133 
134 /// Adds Fortran runtime libraries to \p CmdArgs.
135 void addFortranRuntimeLibs(const ToolChain &TC,
136                            llvm::opt::ArgStringList &CmdArgs);
137 
138 /// Adds the path for the Fortran runtime libraries to \p CmdArgs.
139 void addFortranRuntimeLibraryPath(const ToolChain &TC,
140                                   const llvm::opt::ArgList &Args,
141                                   llvm::opt::ArgStringList &CmdArgs);
142 
143 void addHIPRuntimeLibArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
144                           llvm::opt::ArgStringList &CmdArgs);
145 
146 const char *getAsNeededOption(const ToolChain &TC, bool as_needed);
147 
148 llvm::opt::Arg *getLastProfileUseArg(const llvm::opt::ArgList &Args);
149 llvm::opt::Arg *getLastProfileSampleUseArg(const llvm::opt::ArgList &Args);
150 
151 bool isObjCAutoRefCount(const llvm::opt::ArgList &Args);
152 
153 llvm::StringRef getLTOParallelism(const llvm::opt::ArgList &Args,
154                                   const Driver &D);
155 
156 bool areOptimizationsEnabled(const llvm::opt::ArgList &Args);
157 
158 bool isUseSeparateSections(const llvm::Triple &Triple);
159 
160 /// \p EnvVar is split by system delimiter for environment variables.
161 /// If \p ArgName is "-I", "-L", or an empty string, each entry from \p EnvVar
162 /// is prefixed by \p ArgName then added to \p Args. Otherwise, for each
163 /// entry of \p EnvVar, \p ArgName is added to \p Args first, then the entry
164 /// itself is added.
165 void addDirectoryList(const llvm::opt::ArgList &Args,
166                       llvm::opt::ArgStringList &CmdArgs, const char *ArgName,
167                       const char *EnvVar);
168 
169 void AddTargetFeature(const llvm::opt::ArgList &Args,
170                       std::vector<StringRef> &Features,
171                       llvm::opt::OptSpecifier OnOpt,
172                       llvm::opt::OptSpecifier OffOpt, StringRef FeatureName);
173 
174 std::string getCPUName(const Driver &D, const llvm::opt::ArgList &Args,
175                        const llvm::Triple &T, bool FromAs = false);
176 
177 void getTargetFeatures(const Driver &D, const llvm::Triple &Triple,
178                        const llvm::opt::ArgList &Args,
179                        llvm::opt::ArgStringList &CmdArgs, bool ForAS,
180                        bool IsAux = false);
181 
182 /// Iterate \p Args and convert -mxxx to +xxx and -mno-xxx to -xxx and
183 /// append it to \p Features.
184 ///
185 /// Note: Since \p Features may contain default values before calling
186 /// this function, or may be appended with entries to override arguments,
187 /// entries in \p Features are not unique.
188 void handleTargetFeaturesGroup(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.
193 SmallVector<StringRef> unifyTargetFeatures(ArrayRef<StringRef> Features);
194 
195 /// Handles the -save-stats option and returns the filename to save statistics
196 /// to.
197 SmallString<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 with its leading '-' removed,
202 //     otherwise '-print-multi-lib' will not emit them correctly.
203 void addMultilibFlag(bool Enabled, const char *const Flag,
204                      Multilib::flags_list &Flags);
205 
206 void addX86AlignBranchArgs(const Driver &D, const llvm::opt::ArgList &Args,
207                            llvm::opt::ArgStringList &CmdArgs, bool IsLTO,
208                            const StringRef PluginOptPrefix = "");
209 
210 void checkAMDGPUCodeObjectVersion(const Driver &D,
211                                   const llvm::opt::ArgList &Args);
212 
213 unsigned getAMDGPUCodeObjectVersion(const Driver &D,
214                                     const llvm::opt::ArgList &Args);
215 
216 bool haveAMDGPUCodeObjectVersionArgument(const Driver &D,
217                                          const llvm::opt::ArgList &Args);
218 
219 void addMachineOutlinerArgs(const Driver &D, const llvm::opt::ArgList &Args,
220                             llvm::opt::ArgStringList &CmdArgs,
221                             const llvm::Triple &Triple, bool IsLTO,
222                             const StringRef PluginOptPrefix = "");
223 
224 void addOpenMPDeviceRTL(const Driver &D, const llvm::opt::ArgList &DriverArgs,
225                         llvm::opt::ArgStringList &CC1Args,
226                         StringRef BitcodeSuffix, const llvm::Triple &Triple);
227 } // end namespace tools
228 } // end namespace driver
229 } // end namespace clang
230 
231 #endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_COMMONARGS_H
232