[Flang] remove whole-archive option for AIX linker (#76039)
[llvm-project.git] / clang / lib / Driver / ToolChains / CommonArgs.h
blob25d68345a9f9ebf382c4df5a99bc21b66d0da83a
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 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_COMMONARGS_H
10 #define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_COMMONARGS_H
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"
23 namespace clang {
24 namespace driver {
25 namespace tools {
27 void addPathIfExists(const Driver &D, const Twine &Path,
28 ToolChain::path_list &Paths);
30 void AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs,
31 const llvm::opt::ArgList &Args,
32 llvm::opt::ArgStringList &CmdArgs, const JobAction &JA);
34 void addLinkerCompressDebugSectionsOption(const ToolChain &TC,
35 const llvm::opt::ArgList &Args,
36 llvm::opt::ArgStringList &CmdArgs);
38 void claimNoWarnArgs(const llvm::opt::ArgList &Args);
40 bool addSanitizerRuntimes(const ToolChain &TC, const llvm::opt::ArgList &Args,
41 llvm::opt::ArgStringList &CmdArgs);
43 void linkSanitizerRuntimeDeps(const ToolChain &TC,
44 const llvm::opt::ArgList &Args,
45 llvm::opt::ArgStringList &CmdArgs);
47 bool addXRayRuntime(const ToolChain &TC, const llvm::opt::ArgList &Args,
48 llvm::opt::ArgStringList &CmdArgs);
50 void linkXRayRuntimeDeps(const ToolChain &TC, const llvm::opt::ArgList &Args,
51 llvm::opt::ArgStringList &CmdArgs);
53 void AddRunTimeLibs(const ToolChain &TC, const Driver &D,
54 llvm::opt::ArgStringList &CmdArgs,
55 const llvm::opt::ArgList &Args);
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);
70 const char *SplitDebugName(const JobAction &JA, const llvm::opt::ArgList &Args,
71 const InputInfo &Input, const InputInfo &Output);
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);
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);
81 const char *RelocationModelName(llvm::Reloc::Model Model);
83 std::tuple<llvm::Reloc::Model, unsigned, bool>
84 ParsePICArgs(const ToolChain &ToolChain, const llvm::opt::ArgList &Args);
86 unsigned ParseFunctionAlignment(const ToolChain &TC,
87 const llvm::opt::ArgList &Args);
89 void addDebugInfoKind(llvm::opt::ArgStringList &CmdArgs,
90 llvm::codegenoptions::DebugInfoKind DebugInfoKind);
92 llvm::codegenoptions::DebugInfoKind
93 debugLevelToInfoKind(const llvm::opt::Arg &A);
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);
104 void AddAssemblerKPIC(const ToolChain &ToolChain,
105 const llvm::opt::ArgList &Args,
106 llvm::opt::ArgStringList &CmdArgs);
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(llvm::opt::ArgStringList &CmdArgs, const ToolChain &TC,
115 const llvm::opt::ArgList &Args,
116 bool ForceStaticHostRuntime = false,
117 bool IsOffloadingHost = false, bool GompNeedsRT = false);
119 /// Adds Fortran runtime libraries to \p CmdArgs.
120 void addFortranRuntimeLibs(const ToolChain &TC, const llvm::opt::ArgList &Args,
121 llvm::opt::ArgStringList &CmdArgs);
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);
128 void addHIPRuntimeLibArgs(const ToolChain &TC, Compilation &C,
129 const llvm::opt::ArgList &Args,
130 llvm::opt::ArgStringList &CmdArgs);
132 void addAsNeededOption(const ToolChain &TC, const llvm::opt::ArgList &Args,
133 llvm::opt::ArgStringList &CmdArgs, bool as_needed);
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);
139 bool isObjCAutoRefCount(const llvm::opt::ArgList &Args);
141 llvm::StringRef getLTOParallelism(const llvm::opt::ArgList &Args,
142 const Driver &D);
144 bool areOptimizationsEnabled(const llvm::opt::ArgList &Args);
146 bool isUseSeparateSections(const llvm::Triple &Triple);
148 /// \p EnvVar is split by system delimiter for environment variables.
149 /// If \p ArgName is "-I", "-L", or an empty string, each entry from \p EnvVar
150 /// is prefixed by \p ArgName then added to \p Args. Otherwise, for each
151 /// entry of \p EnvVar, \p ArgName is added to \p Args first, then the entry
152 /// itself is added.
153 void addDirectoryList(const llvm::opt::ArgList &Args,
154 llvm::opt::ArgStringList &CmdArgs, const char *ArgName,
155 const char *EnvVar);
157 void AddTargetFeature(const llvm::opt::ArgList &Args,
158 std::vector<StringRef> &Features,
159 llvm::opt::OptSpecifier OnOpt,
160 llvm::opt::OptSpecifier OffOpt, StringRef FeatureName);
162 std::string getCPUName(const Driver &D, const llvm::opt::ArgList &Args,
163 const llvm::Triple &T, bool FromAs = false);
165 void getTargetFeatures(const Driver &D, const llvm::Triple &Triple,
166 const llvm::opt::ArgList &Args,
167 llvm::opt::ArgStringList &CmdArgs, bool ForAS,
168 bool IsAux = false);
170 /// Iterate \p Args and convert -mxxx to +xxx and -mno-xxx to -xxx and
171 /// append it to \p Features.
173 /// Note: Since \p Features may contain default values before calling
174 /// this function, or may be appended with entries to override arguments,
175 /// entries in \p Features are not unique.
176 void handleTargetFeaturesGroup(const Driver &D, const llvm::Triple &Triple,
177 const llvm::opt::ArgList &Args,
178 std::vector<StringRef> &Features,
179 llvm::opt::OptSpecifier Group);
181 /// If there are multiple +xxx or -xxx features, keep the last one.
182 SmallVector<StringRef> unifyTargetFeatures(ArrayRef<StringRef> Features);
184 /// Handles the -save-stats option and returns the filename to save statistics
185 /// to.
186 SmallString<128> getStatsFileName(const llvm::opt::ArgList &Args,
187 const InputInfo &Output,
188 const InputInfo &Input, const Driver &D);
190 /// \p Flag must be a flag accepted by the driver.
191 void addMultilibFlag(bool Enabled, const StringRef Flag,
192 Multilib::flags_list &Flags);
194 void addX86AlignBranchArgs(const Driver &D, const llvm::opt::ArgList &Args,
195 llvm::opt::ArgStringList &CmdArgs, bool IsLTO,
196 const StringRef PluginOptPrefix = "");
198 void checkAMDGPUCodeObjectVersion(const Driver &D,
199 const llvm::opt::ArgList &Args);
201 unsigned getAMDGPUCodeObjectVersion(const Driver &D,
202 const llvm::opt::ArgList &Args);
204 bool haveAMDGPUCodeObjectVersionArgument(const Driver &D,
205 const llvm::opt::ArgList &Args);
207 void addMachineOutlinerArgs(const Driver &D, const llvm::opt::ArgList &Args,
208 llvm::opt::ArgStringList &CmdArgs,
209 const llvm::Triple &Triple, bool IsLTO,
210 const StringRef PluginOptPrefix = "");
212 void addOpenMPDeviceRTL(const Driver &D, const llvm::opt::ArgList &DriverArgs,
213 llvm::opt::ArgStringList &CC1Args,
214 StringRef BitcodeSuffix, const llvm::Triple &Triple);
215 } // end namespace tools
216 } // end namespace driver
217 } // end namespace clang
219 clang::CodeGenOptions::FramePointerKind
220 getFramePointerKind(const llvm::opt::ArgList &Args, const llvm::Triple &Triple);
222 #endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_COMMONARGS_H