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 "InputInfo.h"
13#include "clang/Driver/Driver.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"
18
19namespace clang {
20namespace driver {
21namespace tools {
22
23void addPathIfExists(const Driver &D, const Twine &Path,
24                     ToolChain::path_list &Paths);
25
26void AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs,
27                     const llvm::opt::ArgList &Args,
28                     llvm::opt::ArgStringList &CmdArgs, const JobAction &JA);
29
30void addLinkerCompressDebugSectionsOption(const ToolChain &TC,
31                                          const llvm::opt::ArgList &Args,
32                                          llvm::opt::ArgStringList &CmdArgs);
33
34void claimNoWarnArgs(const llvm::opt::ArgList &Args);
35
36bool addSanitizerRuntimes(const ToolChain &TC, const llvm::opt::ArgList &Args,
37                          llvm::opt::ArgStringList &CmdArgs);
38
39void linkSanitizerRuntimeDeps(const ToolChain &TC,
40                              llvm::opt::ArgStringList &CmdArgs);
41
42bool addXRayRuntime(const ToolChain &TC, const llvm::opt::ArgList &Args,
43                    llvm::opt::ArgStringList &CmdArgs);
44
45void linkXRayRuntimeDeps(const ToolChain &TC,
46                         llvm::opt::ArgStringList &CmdArgs);
47
48void AddRunTimeLibs(const ToolChain &TC, const Driver &D,
49                    llvm::opt::ArgStringList &CmdArgs,
50                    const llvm::opt::ArgList &Args);
51
52const char *SplitDebugName(const JobAction &JA, const llvm::opt::ArgList &Args,
53                           const InputInfo &Input, const InputInfo &Output);
54
55void SplitDebugInfo(const ToolChain &TC, Compilation &C, const Tool &T,
56                    const JobAction &JA, const llvm::opt::ArgList &Args,
57                    const InputInfo &Output, const char *OutFile);
58
59void addLTOOptions(const ToolChain &ToolChain, const llvm::opt::ArgList &Args,
60                   llvm::opt::ArgStringList &CmdArgs, const InputInfo &Output,
61                   const InputInfo &Input, bool IsThinLTO);
62
63std::tuple<llvm::Reloc::Model, unsigned, bool>
64ParsePICArgs(const ToolChain &ToolChain, const llvm::opt::ArgList &Args);
65
66unsigned ParseFunctionAlignment(const ToolChain &TC,
67                                const llvm::opt::ArgList &Args);
68
69unsigned ParseDebugDefaultVersion(const ToolChain &TC,
70                                  const llvm::opt::ArgList &Args);
71
72void AddAssemblerKPIC(const ToolChain &ToolChain,
73                      const llvm::opt::ArgList &Args,
74                      llvm::opt::ArgStringList &CmdArgs);
75
76void addArchSpecificRPath(const ToolChain &TC, const llvm::opt::ArgList &Args,
77                          llvm::opt::ArgStringList &CmdArgs);
78/// Returns true, if an OpenMP runtime has been added.
79bool addOpenMPRuntime(llvm::opt::ArgStringList &CmdArgs, const ToolChain &TC,
80                      const llvm::opt::ArgList &Args,
81                      bool ForceStaticHostRuntime = false,
82                      bool IsOffloadingHost = false, bool GompNeedsRT = false);
83
84llvm::opt::Arg *getLastProfileUseArg(const llvm::opt::ArgList &Args);
85llvm::opt::Arg *getLastProfileSampleUseArg(const llvm::opt::ArgList &Args);
86
87bool isObjCAutoRefCount(const llvm::opt::ArgList &Args);
88
89llvm::StringRef getLTOParallelism(const llvm::opt::ArgList &Args,
90                                  const Driver &D);
91
92bool areOptimizationsEnabled(const llvm::opt::ArgList &Args);
93
94bool isUseSeparateSections(const llvm::Triple &Triple);
95
96/// \p EnvVar is split by system delimiter for environment variables.
97/// If \p ArgName is "-I", "-L", or an empty string, each entry from \p EnvVar
98/// is prefixed by \p ArgName then added to \p Args. Otherwise, for each
99/// entry of \p EnvVar, \p ArgName is added to \p Args first, then the entry
100/// itself is added.
101void addDirectoryList(const llvm::opt::ArgList &Args,
102                      llvm::opt::ArgStringList &CmdArgs, const char *ArgName,
103                      const char *EnvVar);
104
105void AddTargetFeature(const llvm::opt::ArgList &Args,
106                      std::vector<StringRef> &Features,
107                      llvm::opt::OptSpecifier OnOpt,
108                      llvm::opt::OptSpecifier OffOpt, StringRef FeatureName);
109
110std::string getCPUName(const llvm::opt::ArgList &Args, const llvm::Triple &T,
111                       bool FromAs = false);
112
113/// Iterate \p Args and convert -mxxx to +xxx and -mno-xxx to -xxx and
114/// append it to \p Features.
115///
116/// Note: Since \p Features may contain default values before calling
117/// this function, or may be appended with entries to override arguments,
118/// entries in \p Features are not unique.
119void handleTargetFeaturesGroup(const llvm::opt::ArgList &Args,
120                               std::vector<StringRef> &Features,
121                               llvm::opt::OptSpecifier Group);
122
123/// If there are multiple +xxx or -xxx features, keep the last one.
124std::vector<StringRef>
125unifyTargetFeatures(const std::vector<StringRef> &Features);
126
127/// Handles the -save-stats option and returns the filename to save statistics
128/// to.
129SmallString<128> getStatsFileName(const llvm::opt::ArgList &Args,
130                                  const InputInfo &Output,
131                                  const InputInfo &Input, const Driver &D);
132
133/// \p Flag must be a flag accepted by the driver with its leading '-' removed,
134//     otherwise '-print-multi-lib' will not emit them correctly.
135void addMultilibFlag(bool Enabled, const char *const Flag,
136                     Multilib::flags_list &Flags);
137
138void addX86AlignBranchArgs(const Driver &D, const llvm::opt::ArgList &Args,
139                           llvm::opt::ArgStringList &CmdArgs, bool IsLTO);
140
141void checkAMDGPUCodeObjectVersion(const Driver &D,
142                                  const llvm::opt::ArgList &Args);
143
144unsigned getAMDGPUCodeObjectVersion(const Driver &D,
145                                    const llvm::opt::ArgList &Args);
146
147bool haveAMDGPUCodeObjectVersionArgument(const Driver &D,
148                                         const llvm::opt::ArgList &Args);
149
150void addMachineOutlinerArgs(const Driver &D, const llvm::opt::ArgList &Args,
151                            llvm::opt::ArgStringList &CmdArgs,
152                            const llvm::Triple &Triple, bool IsLTO);
153
154void addOpenMPDeviceRTL(const Driver &D, const llvm::opt::ArgList &DriverArgs,
155                        llvm::opt::ArgStringList &CC1Args,
156                        StringRef BitcodeSuffix, const llvm::Triple &Triple);
157} // end namespace tools
158} // end namespace driver
159} // end namespace clang
160
161#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_COMMONARGS_H
162