1 //===--- CommonArgs.h - Args handling for multiple toolchains ---*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_COMMONARGS_H
10 #define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_COMMONARGS_H
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"
26 void addPathIfExists(const Driver
&D
, const Twine
&Path
,
27 ToolChain::path_list
&Paths
);
29 void AddLinkerInputs(const ToolChain
&TC
, const InputInfoList
&Inputs
,
30 const llvm::opt::ArgList
&Args
,
31 llvm::opt::ArgStringList
&CmdArgs
, const JobAction
&JA
);
33 void addLinkerCompressDebugSectionsOption(const ToolChain
&TC
,
34 const llvm::opt::ArgList
&Args
,
35 llvm::opt::ArgStringList
&CmdArgs
);
37 void claimNoWarnArgs(const llvm::opt::ArgList
&Args
);
39 bool addSanitizerRuntimes(const ToolChain
&TC
, const llvm::opt::ArgList
&Args
,
40 llvm::opt::ArgStringList
&CmdArgs
);
42 void linkSanitizerRuntimeDeps(const ToolChain
&TC
,
43 const llvm::opt::ArgList
&Args
,
44 llvm::opt::ArgStringList
&CmdArgs
);
46 bool addXRayRuntime(const ToolChain
&TC
, const llvm::opt::ArgList
&Args
,
47 llvm::opt::ArgStringList
&CmdArgs
);
49 void linkXRayRuntimeDeps(const ToolChain
&TC
, const llvm::opt::ArgList
&Args
,
50 llvm::opt::ArgStringList
&CmdArgs
);
52 void AddRunTimeLibs(const ToolChain
&TC
, const Driver
&D
,
53 llvm::opt::ArgStringList
&CmdArgs
,
54 const llvm::opt::ArgList
&Args
);
56 void AddStaticDeviceLibsLinking(Compilation
&C
, const Tool
&T
,
58 const InputInfoList
&Inputs
,
59 const llvm::opt::ArgList
&DriverArgs
,
60 llvm::opt::ArgStringList
&CmdArgs
,
61 StringRef Arch
, StringRef Target
,
63 void AddStaticDeviceLibs(Compilation
*C
, const Tool
*T
, const JobAction
*JA
,
64 const InputInfoList
*Inputs
, const Driver
&D
,
65 const llvm::opt::ArgList
&DriverArgs
,
66 llvm::opt::ArgStringList
&CmdArgs
, StringRef Arch
,
67 StringRef Target
, bool isBitCodeSDL
);
69 const char *SplitDebugName(const JobAction
&JA
, const llvm::opt::ArgList
&Args
,
70 const InputInfo
&Input
, const InputInfo
&Output
);
72 void SplitDebugInfo(const ToolChain
&TC
, Compilation
&C
, const Tool
&T
,
73 const JobAction
&JA
, const llvm::opt::ArgList
&Args
,
74 const InputInfo
&Output
, const char *OutFile
);
76 void addLTOOptions(const ToolChain
&ToolChain
, const llvm::opt::ArgList
&Args
,
77 llvm::opt::ArgStringList
&CmdArgs
, const InputInfo
&Output
,
78 const InputInfo
&Input
, bool IsThinLTO
);
80 const char *RelocationModelName(llvm::Reloc::Model Model
);
82 std::tuple
<llvm::Reloc::Model
, unsigned, bool>
83 ParsePICArgs(const ToolChain
&ToolChain
, const llvm::opt::ArgList
&Args
);
85 unsigned ParseFunctionAlignment(const ToolChain
&TC
,
86 const llvm::opt::ArgList
&Args
);
88 void addDebugInfoKind(llvm::opt::ArgStringList
&CmdArgs
,
89 llvm::codegenoptions::DebugInfoKind DebugInfoKind
);
91 llvm::codegenoptions::DebugInfoKind
92 debugLevelToInfoKind(const llvm::opt::Arg
&A
);
94 // Extract the integer N from a string spelled "-dwarf-N", returning 0
95 // on mismatch. The StringRef input (rather than an Arg) allows
96 // for use by the "-Xassembler" option parser.
97 unsigned DwarfVersionNum(StringRef ArgValue
);
98 // Find a DWARF format version option.
99 // This function is a complementary for DwarfVersionNum().
100 const llvm::opt::Arg
*getDwarfNArg(const llvm::opt::ArgList
&Args
);
101 unsigned getDwarfVersion(const ToolChain
&TC
, const llvm::opt::ArgList
&Args
);
103 void AddAssemblerKPIC(const ToolChain
&ToolChain
,
104 const llvm::opt::ArgList
&Args
,
105 llvm::opt::ArgStringList
&CmdArgs
);
107 void addArchSpecificRPath(const ToolChain
&TC
, const llvm::opt::ArgList
&Args
,
108 llvm::opt::ArgStringList
&CmdArgs
);
109 void addOpenMPRuntimeLibraryPath(const ToolChain
&TC
,
110 const llvm::opt::ArgList
&Args
,
111 llvm::opt::ArgStringList
&CmdArgs
);
112 /// Returns true, if an OpenMP runtime has been added.
113 bool addOpenMPRuntime(llvm::opt::ArgStringList
&CmdArgs
, const ToolChain
&TC
,
114 const llvm::opt::ArgList
&Args
,
115 bool ForceStaticHostRuntime
= false,
116 bool IsOffloadingHost
= false, bool GompNeedsRT
= false);
118 /// Adds Fortran runtime libraries to \p CmdArgs.
119 void addFortranRuntimeLibs(const ToolChain
&TC
,
120 llvm::opt::ArgStringList
&CmdArgs
);
122 /// Adds the path for the Fortran runtime libraries to \p CmdArgs.
123 void addFortranRuntimeLibraryPath(const ToolChain
&TC
,
124 const llvm::opt::ArgList
&Args
,
125 llvm::opt::ArgStringList
&CmdArgs
);
127 void addHIPRuntimeLibArgs(const ToolChain
&TC
, Compilation
&C
,
128 const llvm::opt::ArgList
&Args
,
129 llvm::opt::ArgStringList
&CmdArgs
);
131 void addAsNeededOption(const ToolChain
&TC
, const llvm::opt::ArgList
&Args
,
132 llvm::opt::ArgStringList
&CmdArgs
, bool as_needed
);
134 llvm::opt::Arg
*getLastCSProfileGenerateArg(const llvm::opt::ArgList
&Args
);
135 llvm::opt::Arg
*getLastProfileUseArg(const llvm::opt::ArgList
&Args
);
136 llvm::opt::Arg
*getLastProfileSampleUseArg(const llvm::opt::ArgList
&Args
);
138 bool isObjCAutoRefCount(const llvm::opt::ArgList
&Args
);
140 llvm::StringRef
getLTOParallelism(const llvm::opt::ArgList
&Args
,
143 bool areOptimizationsEnabled(const llvm::opt::ArgList
&Args
);
145 bool isUseSeparateSections(const llvm::Triple
&Triple
);
147 /// \p EnvVar is split by system delimiter for environment variables.
148 /// If \p ArgName is "-I", "-L", or an empty string, each entry from \p EnvVar
149 /// is prefixed by \p ArgName then added to \p Args. Otherwise, for each
150 /// entry of \p EnvVar, \p ArgName is added to \p Args first, then the entry
152 void addDirectoryList(const llvm::opt::ArgList
&Args
,
153 llvm::opt::ArgStringList
&CmdArgs
, const char *ArgName
,
156 void AddTargetFeature(const llvm::opt::ArgList
&Args
,
157 std::vector
<StringRef
> &Features
,
158 llvm::opt::OptSpecifier OnOpt
,
159 llvm::opt::OptSpecifier OffOpt
, StringRef FeatureName
);
161 std::string
getCPUName(const Driver
&D
, const llvm::opt::ArgList
&Args
,
162 const llvm::Triple
&T
, bool FromAs
= false);
164 void getTargetFeatures(const Driver
&D
, const llvm::Triple
&Triple
,
165 const llvm::opt::ArgList
&Args
,
166 llvm::opt::ArgStringList
&CmdArgs
, bool ForAS
,
169 /// Iterate \p Args and convert -mxxx to +xxx and -mno-xxx to -xxx and
170 /// append it to \p Features.
172 /// Note: Since \p Features may contain default values before calling
173 /// this function, or may be appended with entries to override arguments,
174 /// entries in \p Features are not unique.
175 void handleTargetFeaturesGroup(const Driver
&D
, const llvm::Triple
&Triple
,
176 const llvm::opt::ArgList
&Args
,
177 std::vector
<StringRef
> &Features
,
178 llvm::opt::OptSpecifier Group
);
180 /// If there are multiple +xxx or -xxx features, keep the last one.
181 SmallVector
<StringRef
> unifyTargetFeatures(ArrayRef
<StringRef
> Features
);
183 /// Handles the -save-stats option and returns the filename to save statistics
185 SmallString
<128> getStatsFileName(const llvm::opt::ArgList
&Args
,
186 const InputInfo
&Output
,
187 const InputInfo
&Input
, const Driver
&D
);
189 /// \p Flag must be a flag accepted by the driver.
190 void addMultilibFlag(bool Enabled
, const StringRef Flag
,
191 Multilib::flags_list
&Flags
);
193 void addX86AlignBranchArgs(const Driver
&D
, const llvm::opt::ArgList
&Args
,
194 llvm::opt::ArgStringList
&CmdArgs
, bool IsLTO
,
195 const StringRef PluginOptPrefix
= "");
197 void checkAMDGPUCodeObjectVersion(const Driver
&D
,
198 const llvm::opt::ArgList
&Args
);
200 unsigned getAMDGPUCodeObjectVersion(const Driver
&D
,
201 const llvm::opt::ArgList
&Args
);
203 bool haveAMDGPUCodeObjectVersionArgument(const Driver
&D
,
204 const llvm::opt::ArgList
&Args
);
206 void addMachineOutlinerArgs(const Driver
&D
, const llvm::opt::ArgList
&Args
,
207 llvm::opt::ArgStringList
&CmdArgs
,
208 const llvm::Triple
&Triple
, bool IsLTO
,
209 const StringRef PluginOptPrefix
= "");
211 void addOpenMPDeviceRTL(const Driver
&D
, const llvm::opt::ArgList
&DriverArgs
,
212 llvm::opt::ArgStringList
&CC1Args
,
213 StringRef BitcodeSuffix
, const llvm::Triple
&Triple
);
214 } // end namespace tools
215 } // end namespace driver
216 } // end namespace clang
218 #endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_COMMONARGS_H