clang  19.0.0git
Clang.h
Go to the documentation of this file.
1 //===--- Clang.h - Clang Tool and ToolChain Implementations ====-*- 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_CLANG_H
10 #define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_CLANG_H
11 
12 #include "MSVC.h"
13 #include "clang/Driver/Driver.h"
14 #include "clang/Driver/Tool.h"
15 #include "clang/Driver/Types.h"
16 #include "llvm/Frontend/Debug/Options.h"
17 #include "llvm/Option/Option.h"
18 #include "llvm/Support/raw_ostream.h"
19 #include "llvm/TargetParser/Triple.h"
20 
21 namespace clang {
22 class ObjCRuntime;
23 namespace driver {
24 
25 namespace tools {
26 
27 /// Clang compiler tool.
28 class LLVM_LIBRARY_VISIBILITY Clang : public Tool {
29  // Indicates whether this instance has integrated backend using
30  // internal LLVM infrastructure.
31  bool HasBackend;
32 
33 public:
34  static const char *getBaseInputName(const llvm::opt::ArgList &Args,
35  const InputInfo &Input);
36  static const char *getBaseInputStem(const llvm::opt::ArgList &Args,
37  const InputInfoList &Inputs);
38  static const char *getDependencyFileName(const llvm::opt::ArgList &Args,
39  const InputInfoList &Inputs);
40 
41 private:
42  void AddPreprocessingOptions(Compilation &C, const JobAction &JA,
43  const Driver &D, const llvm::opt::ArgList &Args,
44  llvm::opt::ArgStringList &CmdArgs,
45  const InputInfo &Output,
46  const InputInfoList &Inputs) const;
47 
48  void RenderTargetOptions(const llvm::Triple &EffectiveTriple,
49  const llvm::opt::ArgList &Args, bool KernelOrKext,
50  llvm::opt::ArgStringList &CmdArgs) const;
51 
52  void AddAArch64TargetArgs(const llvm::opt::ArgList &Args,
53  llvm::opt::ArgStringList &CmdArgs) const;
54  void AddARMTargetArgs(const llvm::Triple &Triple,
55  const llvm::opt::ArgList &Args,
56  llvm::opt::ArgStringList &CmdArgs,
57  bool KernelOrKext) const;
58  void AddARM64TargetArgs(const llvm::opt::ArgList &Args,
59  llvm::opt::ArgStringList &CmdArgs) const;
60  void AddLoongArchTargetArgs(const llvm::opt::ArgList &Args,
61  llvm::opt::ArgStringList &CmdArgs) const;
62  void AddMIPSTargetArgs(const llvm::opt::ArgList &Args,
63  llvm::opt::ArgStringList &CmdArgs) const;
64  void AddPPCTargetArgs(const llvm::opt::ArgList &Args,
65  llvm::opt::ArgStringList &CmdArgs) const;
66  void AddR600TargetArgs(const llvm::opt::ArgList &Args,
67  llvm::opt::ArgStringList &CmdArgs) const;
68  void AddRISCVTargetArgs(const llvm::opt::ArgList &Args,
69  llvm::opt::ArgStringList &CmdArgs) const;
70  void AddSparcTargetArgs(const llvm::opt::ArgList &Args,
71  llvm::opt::ArgStringList &CmdArgs) const;
72  void AddSystemZTargetArgs(const llvm::opt::ArgList &Args,
73  llvm::opt::ArgStringList &CmdArgs) const;
74  void AddX86TargetArgs(const llvm::opt::ArgList &Args,
75  llvm::opt::ArgStringList &CmdArgs) const;
76  void AddHexagonTargetArgs(const llvm::opt::ArgList &Args,
77  llvm::opt::ArgStringList &CmdArgs) const;
78  void AddLanaiTargetArgs(const llvm::opt::ArgList &Args,
79  llvm::opt::ArgStringList &CmdArgs) const;
80  void AddWebAssemblyTargetArgs(const llvm::opt::ArgList &Args,
81  llvm::opt::ArgStringList &CmdArgs) const;
82  void AddVETargetArgs(const llvm::opt::ArgList &Args,
83  llvm::opt::ArgStringList &CmdArgs) const;
84 
85  enum RewriteKind { RK_None, RK_Fragile, RK_NonFragile };
86 
87  ObjCRuntime AddObjCRuntimeArgs(const llvm::opt::ArgList &args,
88  const InputInfoList &inputs,
89  llvm::opt::ArgStringList &cmdArgs,
90  RewriteKind rewrite) const;
91 
92  void AddClangCLArgs(const llvm::opt::ArgList &Args, types::ID InputType,
93  llvm::opt::ArgStringList &CmdArgs) const;
94 
95  void ConstructHostCompilerJob(Compilation &C, const JobAction &JA,
96  const InputInfo &Output,
97  const InputInfoList &Inputs,
98  const llvm::opt::ArgList &TCArgs) const;
99 
100  mutable std::unique_ptr<llvm::raw_fd_ostream> CompilationDatabase = nullptr;
101  void DumpCompilationDatabase(Compilation &C, StringRef Filename,
102  StringRef Target,
103  const InputInfo &Output, const InputInfo &Input,
104  const llvm::opt::ArgList &Args) const;
105 
106  void DumpCompilationDatabaseFragmentToDir(
107  StringRef Dir, Compilation &C, StringRef Target, const InputInfo &Output,
108  const InputInfo &Input, const llvm::opt::ArgList &Args) const;
109 
110 public:
111  Clang(const ToolChain &TC, bool HasIntegratedBackend = true);
112  ~Clang() override;
113 
114  bool hasGoodDiagnostics() const override { return true; }
115  bool hasIntegratedAssembler() const override { return true; }
116  bool hasIntegratedBackend() const override { return HasBackend; }
117  bool hasIntegratedCPP() const override { return true; }
118  bool canEmitIR() const override { return true; }
119 
120  void ConstructJob(Compilation &C, const JobAction &JA,
121  const InputInfo &Output, const InputInfoList &Inputs,
122  const llvm::opt::ArgList &TCArgs,
123  const char *LinkingOutput) const override;
124 };
125 
126 /// Clang integrated assembler tool.
127 class LLVM_LIBRARY_VISIBILITY ClangAs : public Tool {
128 public:
129  ClangAs(const ToolChain &TC)
130  : Tool("clang::as", "clang integrated assembler", TC) {}
131  void AddLoongArchTargetArgs(const llvm::opt::ArgList &Args,
132  llvm::opt::ArgStringList &CmdArgs) const;
133  void AddMIPSTargetArgs(const llvm::opt::ArgList &Args,
134  llvm::opt::ArgStringList &CmdArgs) const;
135  void AddX86TargetArgs(const llvm::opt::ArgList &Args,
136  llvm::opt::ArgStringList &CmdArgs) const;
137  void AddRISCVTargetArgs(const llvm::opt::ArgList &Args,
138  llvm::opt::ArgStringList &CmdArgs) const;
139  bool hasGoodDiagnostics() const override { return true; }
140  bool hasIntegratedAssembler() const override { return false; }
141  bool hasIntegratedCPP() const override { return false; }
142 
143  void ConstructJob(Compilation &C, const JobAction &JA,
144  const InputInfo &Output, const InputInfoList &Inputs,
145  const llvm::opt::ArgList &TCArgs,
146  const char *LinkingOutput) const override;
147 };
148 
149 /// Offload bundler tool.
150 class LLVM_LIBRARY_VISIBILITY OffloadBundler final : public Tool {
151 public:
153  : Tool("offload bundler", "clang-offload-bundler", TC) {}
154 
155  bool hasIntegratedCPP() const override { return false; }
156  void ConstructJob(Compilation &C, const JobAction &JA,
157  const InputInfo &Output, const InputInfoList &Inputs,
158  const llvm::opt::ArgList &TCArgs,
159  const char *LinkingOutput) const override;
160  void ConstructJobMultipleOutputs(Compilation &C, const JobAction &JA,
161  const InputInfoList &Outputs,
162  const InputInfoList &Inputs,
163  const llvm::opt::ArgList &TCArgs,
164  const char *LinkingOutput) const override;
165 };
166 
167 /// Offload wrapper tool.
168 class LLVM_LIBRARY_VISIBILITY OffloadWrapper final : public Tool {
169 public:
171  : Tool("offload wrapper", "clang-offload-wrapper", TC) {}
172 
173  bool hasIntegratedCPP() const override { return false; }
174  void ConstructJob(Compilation &C, const JobAction &JA,
175  const InputInfo &Output, const InputInfoList &Inputs,
176  const llvm::opt::ArgList &TCArgs,
177  const char *LinkingOutput) const override;
178 };
179 
180 /// Offload binary tool.
181 class LLVM_LIBRARY_VISIBILITY OffloadPackager final : public Tool {
182 public:
184  : Tool("Offload::Packager", "clang-offload-packager", TC) {}
185 
186  bool hasIntegratedCPP() const override { return false; }
187  void ConstructJob(Compilation &C, const JobAction &JA,
188  const InputInfo &Output, const InputInfoList &Inputs,
189  const llvm::opt::ArgList &TCArgs,
190  const char *LinkingOutput) const override;
191 };
192 
193 /// Offload deps tool.
194 class LLVM_LIBRARY_VISIBILITY OffloadDeps final : public Tool {
195  void constructJob(Compilation &C, const JobAction &JA,
197  const llvm::opt::ArgList &TCArgs,
198  const char *LinkingOutput) const;
199 
200 public:
202  : Tool("offload deps", "clang-offload-deps", TC) {}
203 
204  bool hasIntegratedCPP() const override { return false; }
205  void ConstructJob(Compilation &C, const JobAction &JA,
206  const InputInfo &Output, const InputInfoList &Inputs,
207  const llvm::opt::ArgList &TCArgs,
208  const char *LinkingOutput) const override;
209  void ConstructJobMultipleOutputs(Compilation &C, const JobAction &JA,
210  const InputInfoList &Outputs,
211  const InputInfoList &Inputs,
212  const llvm::opt::ArgList &TCArgs,
213  const char *LinkingOutput) const override;
214 };
215 
216 /// SPIR-V translator tool.
217 class LLVM_LIBRARY_VISIBILITY SPIRVTranslator final : public Tool {
218 public:
220  : Tool("SPIR-V translator", "llvm-spirv", TC) {}
221 
222  bool hasIntegratedCPP() const override { return false; }
223  void ConstructJob(Compilation &C, const JobAction &JA,
224  const InputInfo &Output, const InputInfoList &Inputs,
225  const llvm::opt::ArgList &TCArgs,
226  const char *LinkingOutput) const override;
227 };
228 
229 /// SYCL post-link device code processing tool.
230 class LLVM_LIBRARY_VISIBILITY SYCLPostLink final : public Tool {
231 public:
233  : Tool("SYCL post link", "sycl-post-link", TC) {}
234 
235  bool hasIntegratedCPP() const override { return false; }
236  bool hasGoodDiagnostics() const override { return true; }
237  void ConstructJob(Compilation &C, const JobAction &JA,
238  const InputInfo &Output, const InputInfoList &Inputs,
239  const llvm::opt::ArgList &TCArgs,
240  const char *LinkingOutput) const override;
241 };
242 
243 /// File table transformation tool.
244 class LLVM_LIBRARY_VISIBILITY FileTableTform final : public Tool {
245 public:
247  : Tool("File table transformation", "file-table-tform", TC) {}
248 
249  bool hasIntegratedCPP() const override { return false; }
250  bool hasGoodDiagnostics() const override { return true; }
251  void ConstructJob(Compilation &C, const JobAction &JA,
252  const InputInfo &Output, const InputInfoList &Inputs,
253  const llvm::opt::ArgList &TCArgs,
254  const char *LinkingOutput) const override;
255 };
256 
257 /// Append Footer tool
258 class LLVM_LIBRARY_VISIBILITY AppendFooter final : public Tool {
259 public:
261  : Tool("Append Footer to source", "append-file", TC) {}
262 
263  bool hasIntegratedCPP() const override { return false; }
264  bool hasGoodDiagnostics() const override { return true; }
265  void ConstructJob(Compilation &C, const JobAction &JA,
266  const InputInfo &Output, const InputInfoList &Inputs,
267  const llvm::opt::ArgList &TCArgs,
268  const char *LinkingOutput) const override;
269 };
270 
271 /// SPIR-V to LLVM-IR wrapper tool
272 class LLVM_LIBRARY_VISIBILITY SpirvToIrWrapper final : public Tool {
273 public:
275  : Tool("Convert SPIR-V to LLVM-IR if needed", "spirv-to-ir-wrapper", TC) {
276  }
277 
278  bool hasIntegratedCPP() const override { return false; }
279  bool hasGoodDiagnostics() const override { return true; }
280  void ConstructJob(Compilation &C, const JobAction &JA,
281  const InputInfo &Output, const InputInfoList &Inputs,
282  const llvm::opt::ArgList &TCArgs,
283  const char *LinkingOutput) const override;
284 };
285 
286 /// Linker wrapper tool.
287 class LLVM_LIBRARY_VISIBILITY LinkerWrapper final : public Tool {
288  const Tool *Linker;
289 
290 public:
291  LinkerWrapper(const ToolChain &TC, const Tool *Linker)
292  : Tool("Offload::Linker", "linker", TC), Linker(Linker) {}
293 
294  bool hasIntegratedCPP() const override { return false; }
295  void ConstructJob(Compilation &C, const JobAction &JA,
296  const InputInfo &Output, const InputInfoList &Inputs,
297  const llvm::opt::ArgList &TCArgs,
298  const char *LinkingOutput) const override;
299 };
300 
302 
304  const llvm::opt::ArgList &Args,
305  llvm::opt::Arg *&Arg);
306 
307 // Calculate the output path of the module file when compiling a module unit
308 // with the `-fmodule-output` option or `-fmodule-output=` option specified.
309 // The behavior is:
310 // - If `-fmodule-output=` is specfied, then the module file is
311 // writing to the value.
312 // - Otherwise if the output object file of the module unit is specified, the
313 // output path
314 // of the module file should be the same with the output object file except
315 // the corresponding suffix. This requires both `-o` and `-c` are specified.
316 // - Otherwise, the output path of the module file will be the same with the
317 // input with the corresponding suffix.
319 getCXX20NamedModuleOutputPath(const llvm::opt::ArgList &Args,
320  const char *BaseInput);
321 
322 } // end namespace tools
323 
324 } // end namespace driver
325 } // end namespace clang
326 
327 #endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_CLANG_H
StringRef Filename
Definition: Format.cpp:2976
llvm::MachO::Target Target
Definition: MachO.h:50
The basic abstraction for the target Objective-C runtime.
Definition: ObjCRuntime.h:28
Compilation - A set of tasks to perform for a single driver invocation.
Definition: Compilation.h:45
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:77
InputInfo - Wrapper for information about an input source.
Definition: InputInfo.h:22
ToolChain - Access to tools for a single platform.
Definition: ToolChain.h:92
Tool - Information on a specific compilation tool.
Definition: Tool.h:32
Append Footer tool.
Definition: Clang.h:258
bool hasGoodDiagnostics() const override
Does this tool have "good" standardized diagnostics, or should the driver add an additional "command ...
Definition: Clang.h:264
AppendFooter(const ToolChain &TC)
Definition: Clang.h:260
bool hasIntegratedCPP() const override
Definition: Clang.h:263
Clang integrated assembler tool.
Definition: Clang.h:127
bool hasGoodDiagnostics() const override
Does this tool have "good" standardized diagnostics, or should the driver add an additional "command ...
Definition: Clang.h:139
bool hasIntegratedCPP() const override
Definition: Clang.h:141
ClangAs(const ToolChain &TC)
Definition: Clang.h:129
bool hasIntegratedAssembler() const override
Definition: Clang.h:140
Clang compiler tool.
Definition: Clang.h:28
bool hasIntegratedBackend() const override
Definition: Clang.h:116
bool hasGoodDiagnostics() const override
Does this tool have "good" standardized diagnostics, or should the driver add an additional "command ...
Definition: Clang.h:114
bool canEmitIR() const override
Definition: Clang.h:118
bool hasIntegratedCPP() const override
Definition: Clang.h:117
bool hasIntegratedAssembler() const override
Definition: Clang.h:115
File table transformation tool.
Definition: Clang.h:244
bool hasIntegratedCPP() const override
Definition: Clang.h:249
FileTableTform(const ToolChain &TC)
Definition: Clang.h:246
bool hasGoodDiagnostics() const override
Does this tool have "good" standardized diagnostics, or should the driver add an additional "command ...
Definition: Clang.h:250
Linker wrapper tool.
Definition: Clang.h:287
bool hasIntegratedCPP() const override
Definition: Clang.h:294
LinkerWrapper(const ToolChain &TC, const Tool *Linker)
Definition: Clang.h:291
Offload bundler tool.
Definition: Clang.h:150
bool hasIntegratedCPP() const override
Definition: Clang.h:155
OffloadBundler(const ToolChain &TC)
Definition: Clang.h:152
Offload deps tool.
Definition: Clang.h:194
bool hasIntegratedCPP() const override
Definition: Clang.h:204
OffloadDeps(const ToolChain &TC)
Definition: Clang.h:201
Offload binary tool.
Definition: Clang.h:181
OffloadPackager(const ToolChain &TC)
Definition: Clang.h:183
bool hasIntegratedCPP() const override
Definition: Clang.h:186
Offload wrapper tool.
Definition: Clang.h:168
bool hasIntegratedCPP() const override
Definition: Clang.h:173
OffloadWrapper(const ToolChain &TC)
Definition: Clang.h:170
SPIR-V translator tool.
Definition: Clang.h:217
bool hasIntegratedCPP() const override
Definition: Clang.h:222
SPIRVTranslator(const ToolChain &TC)
Definition: Clang.h:219
SPIR-V to LLVM-IR wrapper tool.
Definition: Clang.h:272
bool hasGoodDiagnostics() const override
Does this tool have "good" standardized diagnostics, or should the driver add an additional "command ...
Definition: Clang.h:279
bool hasIntegratedCPP() const override
Definition: Clang.h:278
SpirvToIrWrapper(const ToolChain &TC)
Definition: Clang.h:274
DwarfFissionKind getDebugFissionKind(const Driver &D, const llvm::opt::ArgList &Args, llvm::opt::Arg *&Arg)
llvm::SmallString< 256 > getCXX20NamedModuleOutputPath(const llvm::opt::ArgList &Args, const char *BaseInput)
The JSON file list parser is used to communicate input to InstallAPI.