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/Support/CodeGen.h"
23 void addPathIfExists(const Driver
&D
, const Twine
&Path
,
24 ToolChain::path_list
&Paths
);
26 void AddLinkerInputs(const ToolChain
&TC
, const InputInfoList
&Inputs
,
27 const llvm::opt::ArgList
&Args
,
28 llvm::opt::ArgStringList
&CmdArgs
, const JobAction
&JA
);
30 void addLinkerCompressDebugSectionsOption(const ToolChain
&TC
,
31 const llvm::opt::ArgList
&Args
,
32 llvm::opt::ArgStringList
&CmdArgs
);
34 void claimNoWarnArgs(const llvm::opt::ArgList
&Args
);
36 bool addSanitizerRuntimes(const ToolChain
&TC
, const llvm::opt::ArgList
&Args
,
37 llvm::opt::ArgStringList
&CmdArgs
);
39 void linkSanitizerRuntimeDeps(const ToolChain
&TC
,
40 llvm::opt::ArgStringList
&CmdArgs
);
42 bool addXRayRuntime(const ToolChain
&TC
, const llvm::opt::ArgList
&Args
,
43 llvm::opt::ArgStringList
&CmdArgs
);
45 void linkXRayRuntimeDeps(const ToolChain
&TC
,
46 llvm::opt::ArgStringList
&CmdArgs
);
48 void AddRunTimeLibs(const ToolChain
&TC
, const Driver
&D
,
49 llvm::opt::ArgStringList
&CmdArgs
,
50 const llvm::opt::ArgList
&Args
);
52 void AddStaticDeviceLibsLinking(Compilation
&C
, const Tool
&T
,
54 const InputInfoList
&Inputs
,
55 const llvm::opt::ArgList
&DriverArgs
,
56 llvm::opt::ArgStringList
&CmdArgs
,
57 StringRef Arch
, StringRef Target
,
58 bool isBitCodeSDL
, bool postClangLink
);
59 void AddStaticDeviceLibsPostLinking(const Driver
&D
,
60 const llvm::opt::ArgList
&DriverArgs
,
61 llvm::opt::ArgStringList
&CmdArgs
,
62 StringRef Arch
, StringRef Target
,
63 bool isBitCodeSDL
, bool postClangLink
);
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
,
71 bool SDLSearch(const Driver
&D
, const llvm::opt::ArgList
&DriverArgs
,
72 llvm::opt::ArgStringList
&CmdArgs
,
73 SmallVector
<std::string
, 8> LibraryPaths
, std::string Lib
,
74 StringRef Arch
, StringRef Target
, bool isBitCodeSDL
,
77 bool GetSDLFromOffloadArchive(Compilation
&C
, const Driver
&D
, const Tool
&T
,
78 const JobAction
&JA
, const InputInfoList
&Inputs
,
79 const llvm::opt::ArgList
&DriverArgs
,
80 llvm::opt::ArgStringList
&CC1Args
,
81 SmallVector
<std::string
, 8> LibraryPaths
,
82 StringRef Lib
, StringRef Arch
, StringRef Target
,
83 bool isBitCodeSDL
, bool postClangLink
);
85 const char *SplitDebugName(const JobAction
&JA
, const llvm::opt::ArgList
&Args
,
86 const InputInfo
&Input
, const InputInfo
&Output
);
88 void SplitDebugInfo(const ToolChain
&TC
, Compilation
&C
, const Tool
&T
,
89 const JobAction
&JA
, const llvm::opt::ArgList
&Args
,
90 const InputInfo
&Output
, const char *OutFile
);
92 void addLTOOptions(const ToolChain
&ToolChain
, const llvm::opt::ArgList
&Args
,
93 llvm::opt::ArgStringList
&CmdArgs
, const InputInfo
&Output
,
94 const InputInfo
&Input
, bool IsThinLTO
);
96 const char *RelocationModelName(llvm::Reloc::Model Model
);
98 std::tuple
<llvm::Reloc::Model
, unsigned, bool>
99 ParsePICArgs(const ToolChain
&ToolChain
, const llvm::opt::ArgList
&Args
);
101 unsigned ParseFunctionAlignment(const ToolChain
&TC
,
102 const llvm::opt::ArgList
&Args
);
104 unsigned ParseDebugDefaultVersion(const ToolChain
&TC
,
105 const llvm::opt::ArgList
&Args
);
107 void AddAssemblerKPIC(const ToolChain
&ToolChain
,
108 const llvm::opt::ArgList
&Args
,
109 llvm::opt::ArgStringList
&CmdArgs
);
111 void addOpenMPRuntimeSpecificRPath(const ToolChain
&TC
,
112 const llvm::opt::ArgList
&Args
,
113 llvm::opt::ArgStringList
&CmdArgs
);
114 void addArchSpecificRPath(const ToolChain
&TC
, const llvm::opt::ArgList
&Args
,
115 llvm::opt::ArgStringList
&CmdArgs
);
116 void addOpenMPRuntimeLibraryPath(const ToolChain
&TC
,
117 const llvm::opt::ArgList
&Args
,
118 llvm::opt::ArgStringList
&CmdArgs
);
119 /// Returns true, if an OpenMP runtime has been added.
120 bool addOpenMPRuntime(llvm::opt::ArgStringList
&CmdArgs
, const ToolChain
&TC
,
121 const llvm::opt::ArgList
&Args
,
122 bool ForceStaticHostRuntime
= false,
123 bool IsOffloadingHost
= false, bool GompNeedsRT
= false);
125 /// Adds Fortran runtime libraries to \p CmdArgs.
126 void addFortranRuntimeLibs(const ToolChain
&TC
,
127 llvm::opt::ArgStringList
&CmdArgs
);
129 /// Adds the path for the Fortran runtime libraries to \p CmdArgs.
130 void addFortranRuntimeLibraryPath(const ToolChain
&TC
,
131 const llvm::opt::ArgList
&Args
,
132 llvm::opt::ArgStringList
&CmdArgs
);
134 void addHIPRuntimeLibArgs(const ToolChain
&TC
, const llvm::opt::ArgList
&Args
,
135 llvm::opt::ArgStringList
&CmdArgs
);
137 const char *getAsNeededOption(const ToolChain
&TC
, bool as_needed
);
139 llvm::opt::Arg
*getLastProfileUseArg(const llvm::opt::ArgList
&Args
);
140 llvm::opt::Arg
*getLastProfileSampleUseArg(const llvm::opt::ArgList
&Args
);
142 bool isObjCAutoRefCount(const llvm::opt::ArgList
&Args
);
144 llvm::StringRef
getLTOParallelism(const llvm::opt::ArgList
&Args
,
147 bool areOptimizationsEnabled(const llvm::opt::ArgList
&Args
);
149 bool isUseSeparateSections(const llvm::Triple
&Triple
);
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
156 void addDirectoryList(const llvm::opt::ArgList
&Args
,
157 llvm::opt::ArgStringList
&CmdArgs
, const char *ArgName
,
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
);
165 std::string
getCPUName(const Driver
&D
, const llvm::opt::ArgList
&Args
,
166 const llvm::Triple
&T
, bool FromAs
= false);
168 /// Iterate \p Args and convert -mxxx to +xxx and -mno-xxx to -xxx and
169 /// append it to \p Features.
171 /// Note: Since \p Features may contain default values before calling
172 /// this function, or may be appended with entries to override arguments,
173 /// entries in \p Features are not unique.
174 void handleTargetFeaturesGroup(const llvm::opt::ArgList
&Args
,
175 std::vector
<StringRef
> &Features
,
176 llvm::opt::OptSpecifier Group
);
178 /// If there are multiple +xxx or -xxx features, keep the last one.
179 SmallVector
<StringRef
> unifyTargetFeatures(ArrayRef
<StringRef
> Features
);
181 /// Handles the -save-stats option and returns the filename to save statistics
183 SmallString
<128> getStatsFileName(const llvm::opt::ArgList
&Args
,
184 const InputInfo
&Output
,
185 const InputInfo
&Input
, const Driver
&D
);
187 /// \p Flag must be a flag accepted by the driver with its leading '-' removed,
188 // otherwise '-print-multi-lib' will not emit them correctly.
189 void addMultilibFlag(bool Enabled
, const char *const Flag
,
190 Multilib::flags_list
&Flags
);
192 void addX86AlignBranchArgs(const Driver
&D
, const llvm::opt::ArgList
&Args
,
193 llvm::opt::ArgStringList
&CmdArgs
, bool IsLTO
);
195 void checkAMDGPUCodeObjectVersion(const Driver
&D
,
196 const llvm::opt::ArgList
&Args
);
198 unsigned getAMDGPUCodeObjectVersion(const Driver
&D
,
199 const llvm::opt::ArgList
&Args
);
201 bool haveAMDGPUCodeObjectVersionArgument(const Driver
&D
,
202 const llvm::opt::ArgList
&Args
);
204 void addMachineOutlinerArgs(const Driver
&D
, const llvm::opt::ArgList
&Args
,
205 llvm::opt::ArgStringList
&CmdArgs
,
206 const llvm::Triple
&Triple
, bool IsLTO
);
208 void addOpenMPDeviceRTL(const Driver
&D
, const llvm::opt::ArgList
&DriverArgs
,
209 llvm::opt::ArgStringList
&CC1Args
,
210 StringRef BitcodeSuffix
, const llvm::Triple
&Triple
);
211 } // end namespace tools
212 } // end namespace driver
213 } // end namespace clang
215 #endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_COMMONARGS_H