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 
19 namespace clang {
20 namespace driver {
21 namespace tools {
22 
23 void addPathIfExists(const Driver &D, const Twine &Path,
24                      ToolChain::path_list &Paths);
25 
26 void AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs,
27                      const llvm::opt::ArgList &Args,
28                      llvm::opt::ArgStringList &CmdArgs, const JobAction &JA);
29 
30 void claimNoWarnArgs(const llvm::opt::ArgList &Args);
31 
32 bool addSanitizerRuntimes(const ToolChain &TC, const llvm::opt::ArgList &Args,
33                           llvm::opt::ArgStringList &CmdArgs);
34 
35 void linkSanitizerRuntimeDeps(const ToolChain &TC,
36                               llvm::opt::ArgStringList &CmdArgs);
37 
38 bool addXRayRuntime(const ToolChain &TC, const llvm::opt::ArgList &Args,
39                     llvm::opt::ArgStringList &CmdArgs);
40 
41 void linkXRayRuntimeDeps(const ToolChain &TC,
42                          llvm::opt::ArgStringList &CmdArgs);
43 
44 void AddRunTimeLibs(const ToolChain &TC, const Driver &D,
45                     llvm::opt::ArgStringList &CmdArgs,
46                     const llvm::opt::ArgList &Args);
47 
48 void AddHIPLinkerScript(const ToolChain &TC, Compilation &C,
49                         const InputInfo &Output, const InputInfoList &Inputs,
50                         const llvm::opt::ArgList &Args,
51                         llvm::opt::ArgStringList &CmdArgs, const JobAction &JA,
52                         const Tool &T);
53 
54 const char *SplitDebugName(const llvm::opt::ArgList &Args,
55                            const InputInfo &Input, const InputInfo &Output);
56 
57 void SplitDebugInfo(const ToolChain &TC, Compilation &C, const Tool &T,
58                     const JobAction &JA, const llvm::opt::ArgList &Args,
59                     const InputInfo &Output, const char *OutFile);
60 
61 void AddGoldPlugin(const ToolChain &ToolChain, const llvm::opt::ArgList &Args,
62                    llvm::opt::ArgStringList &CmdArgs, const InputInfo &Output,
63                    const InputInfo &Input, bool IsThinLTO);
64 
65 std::tuple<llvm::Reloc::Model, unsigned, bool>
66 ParsePICArgs(const ToolChain &ToolChain, const llvm::opt::ArgList &Args);
67 
68 unsigned ParseFunctionAlignment(const ToolChain &TC,
69                                 const llvm::opt::ArgList &Args);
70 
71 unsigned ParseDebugDefaultVersion(const ToolChain &TC,
72                                   const llvm::opt::ArgList &Args);
73 
74 void AddAssemblerKPIC(const ToolChain &ToolChain,
75                       const llvm::opt::ArgList &Args,
76                       llvm::opt::ArgStringList &CmdArgs);
77 
78 void addArchSpecificRPath(const ToolChain &TC, const llvm::opt::ArgList &Args,
79                           llvm::opt::ArgStringList &CmdArgs);
80 /// Returns true, if an OpenMP runtime has been added.
81 bool addOpenMPRuntime(llvm::opt::ArgStringList &CmdArgs, const ToolChain &TC,
82                       const llvm::opt::ArgList &Args,
83                       bool ForceStaticHostRuntime = false,
84                       bool IsOffloadingHost = false, bool GompNeedsRT = false);
85 
86 llvm::opt::Arg *getLastProfileUseArg(const llvm::opt::ArgList &Args);
87 llvm::opt::Arg *getLastProfileSampleUseArg(const llvm::opt::ArgList &Args);
88 
89 bool isObjCAutoRefCount(const llvm::opt::ArgList &Args);
90 
91 unsigned getLTOParallelism(const llvm::opt::ArgList &Args, const Driver &D);
92 
93 bool areOptimizationsEnabled(const llvm::opt::ArgList &Args);
94 
95 bool isUseSeparateSections(const llvm::Triple &Triple);
96 
97 void addDirectoryList(const llvm::opt::ArgList &Args,
98                       llvm::opt::ArgStringList &CmdArgs, const char *ArgName,
99                       const char *EnvVar);
100 
101 void AddTargetFeature(const llvm::opt::ArgList &Args,
102                       std::vector<StringRef> &Features,
103                       llvm::opt::OptSpecifier OnOpt,
104                       llvm::opt::OptSpecifier OffOpt, StringRef FeatureName);
105 
106 std::string getCPUName(const llvm::opt::ArgList &Args, const llvm::Triple &T,
107                        bool FromAs = false);
108 
109 void handleTargetFeaturesGroup(const llvm::opt::ArgList &Args,
110                                std::vector<StringRef> &Features,
111                                llvm::opt::OptSpecifier Group);
112 
113 /// Handles the -save-stats option and returns the filename to save statistics
114 /// to.
115 SmallString<128> getStatsFileName(const llvm::opt::ArgList &Args,
116                                   const InputInfo &Output,
117                                   const InputInfo &Input, const Driver &D);
118 
119 /// \p Flag must be a flag accepted by the driver with its leading '-' removed,
120 //     otherwise '-print-multi-lib' will not emit them correctly.
121 void addMultilibFlag(bool Enabled, const char *const Flag,
122                      Multilib::flags_list &Flags);
123 
124 } // end namespace tools
125 } // end namespace driver
126 } // end namespace clang
127 
128 #endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_COMMONARGS_H
129