clang  12.0.0git
CommonArgs.h
Go to the documentation of this file.
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 const char *SplitDebugName(const llvm::opt::ArgList &Args,
49  const InputInfo &Input, const InputInfo &Output);
50 
51 void SplitDebugInfo(const ToolChain &TC, Compilation &C, const Tool &T,
52  const JobAction &JA, const llvm::opt::ArgList &Args,
53  const InputInfo &Output, const char *OutFile);
54 
55 void addLTOOptions(const ToolChain &ToolChain, const llvm::opt::ArgList &Args,
56  llvm::opt::ArgStringList &CmdArgs, const InputInfo &Output,
57  const InputInfo &Input, bool IsThinLTO);
58 
59 std::tuple<llvm::Reloc::Model, unsigned, bool>
60 ParsePICArgs(const ToolChain &ToolChain, const llvm::opt::ArgList &Args);
61 
62 unsigned ParseFunctionAlignment(const ToolChain &TC,
63  const llvm::opt::ArgList &Args);
64 
65 unsigned ParseDebugDefaultVersion(const ToolChain &TC,
66  const llvm::opt::ArgList &Args);
67 
68 void AddAssemblerKPIC(const ToolChain &ToolChain,
69  const llvm::opt::ArgList &Args,
70  llvm::opt::ArgStringList &CmdArgs);
71 
72 void addArchSpecificRPath(const ToolChain &TC, const llvm::opt::ArgList &Args,
73  llvm::opt::ArgStringList &CmdArgs);
74 /// Returns true, if an OpenMP runtime has been added.
75 bool addOpenMPRuntime(llvm::opt::ArgStringList &CmdArgs, const ToolChain &TC,
76  const llvm::opt::ArgList &Args,
77  bool ForceStaticHostRuntime = false,
78  bool IsOffloadingHost = false, bool GompNeedsRT = false);
79 
80 llvm::opt::Arg *getLastProfileUseArg(const llvm::opt::ArgList &Args);
81 llvm::opt::Arg *getLastProfileSampleUseArg(const llvm::opt::ArgList &Args);
82 
83 bool isObjCAutoRefCount(const llvm::opt::ArgList &Args);
84 
85 llvm::StringRef getLTOParallelism(const llvm::opt::ArgList &Args,
86  const Driver &D);
87 
88 bool areOptimizationsEnabled(const llvm::opt::ArgList &Args);
89 
90 bool isUseSeparateSections(const llvm::Triple &Triple);
91 
92 /// \p EnvVar is split by system delimiter for environment variables.
93 /// If \p ArgName is "-I", "-L", or an empty string, each entry from \p EnvVar
94 /// is prefixed by \p ArgName then added to \p Args. Otherwise, for each
95 /// entry of \p EnvVar, \p ArgName is added to \p Args first, then the entry
96 /// itself is added.
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 /// Iterate \p Args and convert -mxxx to +xxx and -mno-xxx to -xxx and
110 /// append it to \p Features.
111 ///
112 /// Note: Since \p Features may contain default values before calling
113 /// this function, or may be appended with entries to override arguments,
114 /// entries in \p Features are not unique.
115 void handleTargetFeaturesGroup(const llvm::opt::ArgList &Args,
116  std::vector<StringRef> &Features,
117  llvm::opt::OptSpecifier Group);
118 
119 /// If there are multiple +xxx or -xxx features, keep the last one.
120 std::vector<StringRef>
121 unifyTargetFeatures(const std::vector<StringRef> &Features);
122 
123 /// Handles the -save-stats option and returns the filename to save statistics
124 /// to.
125 SmallString<128> getStatsFileName(const llvm::opt::ArgList &Args,
126  const InputInfo &Output,
127  const InputInfo &Input, const Driver &D);
128 
129 /// \p Flag must be a flag accepted by the driver with its leading '-' removed,
130 // otherwise '-print-multi-lib' will not emit them correctly.
131 void addMultilibFlag(bool Enabled, const char *const Flag,
132  Multilib::flags_list &Flags);
133 
134 void addX86AlignBranchArgs(const Driver &D, const llvm::opt::ArgList &Args,
135  llvm::opt::ArgStringList &CmdArgs, bool IsLTO);
136 } // end namespace tools
137 } // end namespace driver
138 } // end namespace clang
139 
140 #endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_COMMONARGS_H
void handleTargetFeaturesGroup(const llvm::opt::ArgList &Args, std::vector< StringRef > &Features, llvm::opt::OptSpecifier Group)
Iterate Args and convert -mxxx to +xxx and -mno-xxx to -xxx and append it to Features.
SmallVector< std::string, 16 > path_list
Definition: ToolChain.h:92
std::vector< StringRef > unifyTargetFeatures(const std::vector< StringRef > &Features)
If there are multiple +xxx or -xxx features, keep the last one.
Definition: CommonArgs.cpp:88
bool addXRayRuntime(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
bool isUseSeparateSections(const llvm::Triple &Triple)
Definition: CommonArgs.cpp:381
void addLTOOptions(const ToolChain &ToolChain, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const InputInfo &Output, const InputInfo &Input, bool IsThinLTO)
void AddRunTimeLibs(const ToolChain &TC, const Driver &D, llvm::opt::ArgStringList &CmdArgs, const llvm::opt::ArgList &Args)
void AddTargetFeature(const llvm::opt::ArgList &Args, std::vector< StringRef > &Features, llvm::opt::OptSpecifier OnOpt, llvm::opt::OptSpecifier OffOpt, StringRef FeatureName)
bool addOpenMPRuntime(llvm::opt::ArgStringList &CmdArgs, const ToolChain &TC, const llvm::opt::ArgList &Args, bool ForceStaticHostRuntime=false, bool IsOffloadingHost=false, bool GompNeedsRT=false)
Returns true, if an OpenMP runtime has been added.
std::string getCPUName(const llvm::opt::ArgList &Args, const llvm::Triple &T, bool FromAs=false)
void linkSanitizerRuntimeDeps(const ToolChain &TC, llvm::opt::ArgStringList &CmdArgs)
bool addSanitizerRuntimes(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
void addMultilibFlag(bool Enabled, const char *const Flag, Multilib::flags_list &Flags)
Flag must be a flag accepted by the driver with its leading &#39;-&#39; removed,
void addArchSpecificRPath(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
const char * SplitDebugName(const llvm::opt::ArgList &Args, const InputInfo &Input, const InputInfo &Output)
void addDirectoryList(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const char *ArgName, const char *EnvVar)
EnvVar is split by system delimiter for environment variables.
void linkXRayRuntimeDeps(const ToolChain &TC, llvm::opt::ArgStringList &CmdArgs)
SmallString< 128 > getStatsFileName(const llvm::opt::ArgList &Args, const InputInfo &Output, const InputInfo &Input, const Driver &D)
Handles the -save-stats option and returns the filename to save statistics to.
std::vector< std::string > flags_list
Definition: Multilib.h:30
std::tuple< llvm::Reloc::Model, unsigned, bool > ParsePICArgs(const ToolChain &ToolChain, const llvm::opt::ArgList &Args)
bool isObjCAutoRefCount(const llvm::opt::ArgList &Args)
unsigned ParseFunctionAlignment(const ToolChain &TC, const llvm::opt::ArgList &Args)
void AddAssemblerKPIC(const ToolChain &ToolChain, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs)
void addX86AlignBranchArgs(const Driver &D, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, bool IsLTO)
llvm::opt::Arg * getLastProfileSampleUseArg(const llvm::opt::ArgList &Args)
llvm::opt::Arg * getLastProfileUseArg(const llvm::opt::ArgList &Args)
void SplitDebugInfo(const ToolChain &TC, Compilation &C, const Tool &T, const JobAction &JA, const llvm::opt::ArgList &Args, const InputInfo &Output, const char *OutFile)
SmallVector< InputInfo, 4 > InputInfoList
Definition: Tool.h:27
Dataflow Directional Tag Classes.
void AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const JobAction &JA)
bool areOptimizationsEnabled(const llvm::opt::ArgList &Args)
void claimNoWarnArgs(const llvm::opt::ArgList &Args)
unsigned ParseDebugDefaultVersion(const ToolChain &TC, const llvm::opt::ArgList &Args)
void addPathIfExists(const Driver &D, const Twine &Path, ToolChain::path_list &Paths)
Definition: CommonArgs.cpp:63
llvm::StringRef getLTOParallelism(const llvm::opt::ArgList &Args, const Driver &D)