Coverage Report

Created: 2021-08-24 07:12

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/include/clang/Driver/ToolChain.h
Line
Count
Source (jump to first uncovered line)
1
//===- ToolChain.h - Collections of tools for one platform ------*- 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_DRIVER_TOOLCHAIN_H
10
#define LLVM_CLANG_DRIVER_TOOLCHAIN_H
11
12
#include "clang/Basic/DebugInfoOptions.h"
13
#include "clang/Basic/LLVM.h"
14
#include "clang/Basic/LangOptions.h"
15
#include "clang/Basic/Sanitizers.h"
16
#include "clang/Driver/Action.h"
17
#include "clang/Driver/Multilib.h"
18
#include "clang/Driver/Types.h"
19
#include "llvm/ADT/APFloat.h"
20
#include "llvm/ADT/ArrayRef.h"
21
#include "llvm/ADT/FloatingPointMode.h"
22
#include "llvm/ADT/SmallVector.h"
23
#include "llvm/ADT/StringRef.h"
24
#include "llvm/ADT/Triple.h"
25
#include "llvm/MC/MCTargetOptions.h"
26
#include "llvm/Option/Option.h"
27
#include "llvm/Support/VersionTuple.h"
28
#include "llvm/Target/TargetOptions.h"
29
#include <cassert>
30
#include <climits>
31
#include <memory>
32
#include <string>
33
#include <utility>
34
35
namespace llvm {
36
namespace opt {
37
38
class Arg;
39
class ArgList;
40
class DerivedArgList;
41
42
} // namespace opt
43
namespace vfs {
44
45
class FileSystem;
46
47
} // namespace vfs
48
} // namespace llvm
49
50
namespace clang {
51
52
class ObjCRuntime;
53
54
namespace driver {
55
56
class Driver;
57
class InputInfo;
58
class SanitizerArgs;
59
class Tool;
60
class XRayArgs;
61
62
/// Helper structure used to pass information extracted from clang executable
63
/// name such as `i686-linux-android-g++`.
64
struct ParsedClangName {
65
  /// Target part of the executable name, as `i686-linux-android`.
66
  std::string TargetPrefix;
67
68
  /// Driver mode part of the executable name, as `g++`.
69
  std::string ModeSuffix;
70
71
  /// Corresponding driver mode argument, as '--driver-mode=g++'
72
  const char *DriverMode = nullptr;
73
74
  /// True if TargetPrefix is recognized as a registered target name.
75
  bool TargetIsValid = false;
76
77
49.3k
  ParsedClangName() = default;
78
  ParsedClangName(std::string Suffix, const char *Mode)
79
105k
      : ModeSuffix(Suffix), DriverMode(Mode) {}
80
  ParsedClangName(std::string Target, std::string Suffix, const char *Mode,
81
                  bool IsRegistered)
82
      : TargetPrefix(Target), ModeSuffix(Suffix), DriverMode(Mode),
83
53
        TargetIsValid(IsRegistered) {}
84
85
0
  bool isEmpty() const {
86
0
    return TargetPrefix.empty() && ModeSuffix.empty() && DriverMode == nullptr;
87
0
  }
88
};
89
90
/// ToolChain - Access to tools for a single platform.
91
class ToolChain {
92
public:
93
  using path_list = SmallVector<std::string, 16>;
94
95
  enum CXXStdlibType {
96
    CST_Libcxx,
97
    CST_Libstdcxx
98
  };
99
100
  enum RuntimeLibType {
101
    RLT_CompilerRT,
102
    RLT_Libgcc
103
  };
104
105
  enum UnwindLibType {
106
    UNW_None,
107
    UNW_CompilerRT,
108
    UNW_Libgcc
109
  };
110
111
  enum RTTIMode {
112
    RM_Enabled,
113
    RM_Disabled,
114
  };
115
116
  enum FileType { FT_Object, FT_Static, FT_Shared };
117
118
private:
119
  friend class RegisterEffectiveTriple;
120
121
  const Driver &D;
122
  llvm::Triple Triple;
123
  const llvm::opt::ArgList &Args;
124
125
  // We need to initialize CachedRTTIArg before CachedRTTIMode
126
  const llvm::opt::Arg *const CachedRTTIArg;
127
128
  const RTTIMode CachedRTTIMode;
129
130
  /// The list of toolchain specific path prefixes to search for libraries.
131
  path_list LibraryPaths;
132
133
  /// The list of toolchain specific path prefixes to search for files.
134
  path_list FilePaths;
135
136
  /// The list of toolchain specific path prefixes to search for programs.
137
  path_list ProgramPaths;
138
139
  mutable std::unique_ptr<Tool> Clang;
140
  mutable std::unique_ptr<Tool> Flang;
141
  mutable std::unique_ptr<Tool> Assemble;
142
  mutable std::unique_ptr<Tool> Link;
143
  mutable std::unique_ptr<Tool> StaticLibTool;
144
  mutable std::unique_ptr<Tool> IfsMerge;
145
  mutable std::unique_ptr<Tool> OffloadBundler;
146
  mutable std::unique_ptr<Tool> OffloadWrapper;
147
148
  Tool *getClang() const;
149
  Tool *getFlang() const;
150
  Tool *getAssemble() const;
151
  Tool *getLink() const;
152
  Tool *getStaticLibTool() const;
153
  Tool *getIfsMerge() const;
154
  Tool *getClangAs() const;
155
  Tool *getOffloadBundler() const;
156
  Tool *getOffloadWrapper() const;
157
158
  mutable std::unique_ptr<SanitizerArgs> SanitizerArguments;
159
  mutable std::unique_ptr<XRayArgs> XRayArguments;
160
161
  /// The effective clang triple for the current Job.
162
  mutable llvm::Triple EffectiveTriple;
163
164
  /// Set the toolchain's effective clang triple.
165
105k
  void setEffectiveTriple(llvm::Triple ET) const {
166
105k
    EffectiveTriple = std::move(ET);
167
105k
  }
168
169
  mutable llvm::Optional<CXXStdlibType> cxxStdlibType;
170
  mutable llvm::Optional<RuntimeLibType> runtimeLibType;
171
  mutable llvm::Optional<UnwindLibType> unwindLibType;
172
173
protected:
174
  MultilibSet Multilibs;
175
  Multilib SelectedMultilib;
176
177
  ToolChain(const Driver &D, const llvm::Triple &T,
178
            const llvm::opt::ArgList &Args);
179
180
  void setTripleEnvironment(llvm::Triple::EnvironmentType Env);
181
182
  virtual Tool *buildAssembler() const;
183
  virtual Tool *buildLinker() const;
184
  virtual Tool *buildStaticLibTool() const;
185
  virtual Tool *getTool(Action::ActionClass AC) const;
186
187
  virtual std::string buildCompilerRTBasename(const llvm::opt::ArgList &Args,
188
                                              StringRef Component,
189
                                              FileType Type,
190
                                              bool AddArch) const;
191
192
  /// \name Utilities for implementing subclasses.
193
  ///@{
194
  static void addSystemInclude(const llvm::opt::ArgList &DriverArgs,
195
                               llvm::opt::ArgStringList &CC1Args,
196
                               const Twine &Path);
197
  static void addExternCSystemInclude(const llvm::opt::ArgList &DriverArgs,
198
                                      llvm::opt::ArgStringList &CC1Args,
199
                                      const Twine &Path);
200
  static void
201
      addExternCSystemIncludeIfExists(const llvm::opt::ArgList &DriverArgs,
202
                                      llvm::opt::ArgStringList &CC1Args,
203
                                      const Twine &Path);
204
  static void addSystemIncludes(const llvm::opt::ArgList &DriverArgs,
205
                                llvm::opt::ArgStringList &CC1Args,
206
                                ArrayRef<StringRef> Paths);
207
  ///@}
208
209
public:
210
  virtual ~ToolChain();
211
212
  // Accessors
213
214
1.03M
  const Driver &getDriver() const { return D; }
215
  llvm::vfs::FileSystem &getVFS() const;
216
2.24M
  const llvm::Triple &getTriple() const { return Triple; }
217
218
  /// Get the toolchain's aux triple, if it has one.
219
  ///
220
  /// Exactly what the aux triple represents depends on the toolchain, but for
221
  /// example when compiling CUDA code for the GPU, the triple might be NVPTX,
222
  /// while the aux triple is the host (CPU) toolchain, e.g. x86-linux-gnu.
223
388
  virtual const llvm::Triple *getAuxTriple() const { return nullptr; }
224
225
  /// Some toolchains need to modify the file name, for example to replace the
226
  /// extension for object files with .cubin for OpenMP offloading to Nvidia
227
  /// GPUs.
228
  virtual std::string getInputFilename(const InputInfo &Input) const;
229
230
491k
  llvm::Triple::ArchType getArch() const { return Triple.getArch(); }
231
1
  StringRef getArchName() const { return Triple.getArchName(); }
232
0
  StringRef getPlatform() const { return Triple.getVendorName(); }
233
36.2k
  StringRef getOS() const { return Triple.getOSName(); }
234
235
  /// Provide the default architecture name (as expected by -arch) for
236
  /// this toolchain.
237
  StringRef getDefaultUniversalArchName() const;
238
239
135k
  std::string getTripleString() const {
240
135k
    return Triple.getTriple();
241
135k
  }
242
243
  /// Get the toolchain's effective clang triple.
244
184k
  const llvm::Triple &getEffectiveTriple() const {
245
184k
    assert(!EffectiveTriple.getTriple().empty() && "No effective triple");
246
0
    return EffectiveTriple;
247
184k
  }
248
249
179
  path_list &getLibraryPaths() { return LibraryPaths; }
250
11.8k
  const path_list &getLibraryPaths() const { return LibraryPaths; }
251
252
7.41k
  path_list &getFilePaths() { return FilePaths; }
253
12.3k
  const path_list &getFilePaths() const { return FilePaths; }
254
255
53.1k
  path_list &getProgramPaths() { return ProgramPaths; }
256
9.20k
  const path_list &getProgramPaths() const { return ProgramPaths; }
257
258
1
  const MultilibSet &getMultilibs() const { return Multilibs; }
259
260
3
  const Multilib &getMultilib() const { return SelectedMultilib; }
261
262
  const SanitizerArgs& getSanitizerArgs() const;
263
264
  const XRayArgs& getXRayArgs() const;
265
266
  // Returns the Arg * that explicitly turned on/off rtti, or nullptr.
267
4
  const llvm::opt::Arg *getRTTIArg() const { return CachedRTTIArg; }
268
269
  // Returns the RTTIMode for the toolchain with the current arguments.
270
88.9k
  RTTIMode getRTTIMode() const { return CachedRTTIMode; }
271
272
  /// Return any implicit target and/or mode flag for an invocation of
273
  /// the compiler driver as `ProgName`.
274
  ///
275
  /// For example, when called with i686-linux-android-g++, the first element
276
  /// of the return value will be set to `"i686-linux-android"` and the second
277
  /// will be set to "--driver-mode=g++"`.
278
  /// It is OK if the target name is not registered. In this case the return
279
  /// value contains false in the field TargetIsValid.
280
  ///
281
  /// \pre `llvm::InitializeAllTargets()` has been called.
282
  /// \param ProgName The name the Clang driver was invoked with (from,
283
  /// e.g., argv[0]).
284
  /// \return A structure of type ParsedClangName that contains the executable
285
  /// name parts.
286
  static ParsedClangName getTargetAndModeFromProgramName(StringRef ProgName);
287
288
  // Tool access.
289
290
  /// TranslateArgs - Create a new derived argument list for any argument
291
  /// translations this ToolChain may wish to perform, or 0 if no tool chain
292
  /// specific translations are needed. If \p DeviceOffloadKind is specified
293
  /// the translation specific for that offload kind is performed.
294
  ///
295
  /// \param BoundArch - The bound architecture name, or 0.
296
  /// \param DeviceOffloadKind - The device offload kind used for the
297
  /// translation.
298
  virtual llvm::opt::DerivedArgList *
299
  TranslateArgs(const llvm::opt::DerivedArgList &Args, StringRef BoundArch,
300
1.06k
                Action::OffloadKind DeviceOffloadKind) const {
301
1.06k
    return nullptr;
302
1.06k
  }
303
304
  /// TranslateOpenMPTargetArgs - Create a new derived argument list for
305
  /// that contains the OpenMP target specific flags passed via
306
  /// -Xopenmp-target -opt=val OR -Xopenmp-target=<triple> -opt=val
307
  virtual llvm::opt::DerivedArgList *TranslateOpenMPTargetArgs(
308
      const llvm::opt::DerivedArgList &Args, bool SameTripleAsHost,
309
      SmallVectorImpl<llvm::opt::Arg *> &AllocatedArgs) const;
310
311
  /// Append the argument following \p A to \p DAL assuming \p A is an Xarch
312
  /// argument. If \p AllocatedArgs is null pointer, synthesized arguments are
313
  /// added to \p DAL, otherwise they are appended to \p AllocatedArgs.
314
  virtual void TranslateXarchArgs(
315
      const llvm::opt::DerivedArgList &Args, llvm::opt::Arg *&A,
316
      llvm::opt::DerivedArgList *DAL,
317
      SmallVectorImpl<llvm::opt::Arg *> *AllocatedArgs = nullptr) const;
318
319
  /// Translate -Xarch_ arguments. If there are no such arguments, return
320
  /// a null pointer, otherwise return a DerivedArgList containing the
321
  /// translated arguments.
322
  virtual llvm::opt::DerivedArgList *
323
  TranslateXarchArgs(const llvm::opt::DerivedArgList &Args, StringRef BoundArch,
324
                     Action::OffloadKind DeviceOffloadKind,
325
                     SmallVectorImpl<llvm::opt::Arg *> *AllocatedArgs) const;
326
327
  /// Choose a tool to use to handle the action \p JA.
328
  ///
329
  /// This can be overridden when a particular ToolChain needs to use
330
  /// a compiler other than Clang.
331
  virtual Tool *SelectTool(const JobAction &JA) const;
332
333
  // Helper methods
334
335
  std::string GetFilePath(const char *Name) const;
336
  std::string GetProgramPath(const char *Name) const;
337
338
  /// Returns the linker path, respecting the -fuse-ld= argument to determine
339
  /// the linker suffix or name.
340
  /// If LinkerIsLLD is non-nullptr, it is set to true if the returned linker
341
  /// is LLD. If it's set, it can be assumed that the linker is LLD built
342
  /// at the same revision as clang, and clang can make assumptions about
343
  /// LLD's supported flags, error output, etc.
344
  /// If LinkerIsLLDDarwinNew is non-nullptr, it's set if the linker is
345
  /// the new version in lld/MachO.
346
  std::string GetLinkerPath(bool *LinkerIsLLD = nullptr,
347
                            bool *LinkerIsLLDDarwinNew = nullptr) const;
348
349
  /// Returns the linker path for emitting a static library.
350
  std::string GetStaticLibToolPath() const;
351
352
  /// Dispatch to the specific toolchain for verbose printing.
353
  ///
354
  /// This is used when handling the verbose option to print detailed,
355
  /// toolchain-specific information useful for understanding the behavior of
356
  /// the driver on a specific platform.
357
9
  virtual void printVerboseInfo(raw_ostream &OS) const {}
358
359
  // Platform defaults information
360
361
  /// Returns true if the toolchain is targeting a non-native
362
  /// architecture.
363
  virtual bool isCrossCompiling() const;
364
365
  /// HasNativeLTOLinker - Check whether the linker and related tools have
366
  /// native LLVM support.
367
  virtual bool HasNativeLLVMSupport() const;
368
369
  /// LookupTypeForExtension - Return the default language type to use for the
370
  /// given extension.
371
  virtual types::ID LookupTypeForExtension(StringRef Ext) const;
372
373
  /// IsBlocksDefault - Does this tool chain enable -fblocks by default.
374
26.8k
  virtual bool IsBlocksDefault() const { return false; }
375
376
  /// IsIntegratedAssemblerDefault - Does this tool chain enable -integrated-as
377
  /// by default.
378
2.07k
  virtual bool IsIntegratedAssemblerDefault() const { return false; }
379
380
  /// Check if the toolchain should use the integrated assembler.
381
  virtual bool useIntegratedAs() const;
382
383
  /// Check if the toolchain should use AsmParser to parse inlineAsm when
384
  /// integrated assembler is not default.
385
873
  virtual bool parseInlineAsmUsingAsmParser() const { return false; }
386
387
  /// IsMathErrnoDefault - Does this tool chain use -fmath-errno by default.
388
25.2k
  virtual bool IsMathErrnoDefault() const { return true; }
389
390
  /// IsEncodeExtendedBlockSignatureDefault - Does this tool chain enable
391
  /// -fencode-extended-block-signature by default.
392
26.8k
  virtual bool IsEncodeExtendedBlockSignatureDefault() const { return false; }
393
394
  /// IsObjCNonFragileABIDefault - Does this tool chain set
395
  /// -fobjc-nonfragile-abi by default.
396
26.2k
  virtual bool IsObjCNonFragileABIDefault() const { return false; }
397
398
  /// UseObjCMixedDispatchDefault - When using non-legacy dispatch, should the
399
  /// mixed dispatch method be used?
400
2
  virtual bool UseObjCMixedDispatch() const { return false; }
401
402
  /// Check whether to enable x86 relax relocations by default.
403
  virtual bool useRelaxRelocations() const;
404
405
  /// GetDefaultStackProtectorLevel - Get the default stack protector level for
406
  /// this tool chain.
407
  virtual LangOptions::StackProtectorMode
408
26.2k
  GetDefaultStackProtectorLevel(bool KernelOrKext) const {
409
26.2k
    return LangOptions::SSPOff;
410
26.2k
  }
411
412
  /// Get the default trivial automatic variable initialization.
413
  virtual LangOptions::TrivialAutoVarInitKind
414
43.1k
  GetDefaultTrivialAutoVarInit() const {
415
43.1k
    return LangOptions::TrivialAutoVarInitKind::Uninitialized;
416
43.1k
  }
417
418
  /// GetDefaultLinker - Get the default linker to use.
419
5.78k
  virtual const char *getDefaultLinker() const { return "ld"; }
420
421
  /// GetDefaultRuntimeLibType - Get the default runtime library variant to use.
422
2.19k
  virtual RuntimeLibType GetDefaultRuntimeLibType() const {
423
2.19k
    return ToolChain::RLT_Libgcc;
424
2.19k
  }
425
426
8.17k
  virtual CXXStdlibType GetDefaultCXXStdlibType() const {
427
8.17k
    return ToolChain::CST_Libstdcxx;
428
8.17k
  }
429
430
1
  virtual UnwindLibType GetDefaultUnwindLibType() const {
431
1
    return ToolChain::UNW_None;
432
1
  }
433
434
  virtual std::string getCompilerRTPath() const;
435
436
  virtual std::string getCompilerRT(const llvm::opt::ArgList &Args,
437
                                    StringRef Component,
438
                                    FileType Type = ToolChain::FT_Static) const;
439
440
  const char *
441
  getCompilerRTArgString(const llvm::opt::ArgList &Args, StringRef Component,
442
                         FileType Type = ToolChain::FT_Static) const;
443
444
  std::string getCompilerRTBasename(const llvm::opt::ArgList &Args,
445
                                    StringRef Component,
446
                                    FileType Type = ToolChain::FT_Static) const;
447
448
  // Returns target specific runtime path if it exists.
449
  virtual std::string getRuntimePath() const;
450
451
  // Returns target specific standard library path if it exists.
452
  virtual std::string getStdlibPath() const;
453
454
  // Returns <ResourceDir>/lib/<OSName>/<arch>.  This is used by runtimes (such
455
  // as OpenMP) to find arch-specific libraries.
456
  std::string getArchSpecificLibPath() const;
457
458
  // Returns <OSname> part of above.
459
  virtual StringRef getOSLibName() const;
460
461
  /// needsProfileRT - returns true if instrumentation profile is on.
462
  static bool needsProfileRT(const llvm::opt::ArgList &Args);
463
464
  /// Returns true if gcov instrumentation (-fprofile-arcs or --coverage) is on.
465
  static bool needsGCovInstrumentation(const llvm::opt::ArgList &Args);
466
467
  /// IsUnwindTablesDefault - Does this tool chain use -funwind-tables
468
  /// by default.
469
  virtual bool IsUnwindTablesDefault(const llvm::opt::ArgList &Args) const;
470
471
  /// Test whether this toolchain supports outline atomics by default.
472
  virtual bool
473
950
  IsAArch64OutlineAtomicsDefault(const llvm::opt::ArgList &Args) const {
474
950
    return false;
475
950
  }
476
477
  /// Test whether this toolchain defaults to PIC.
478
  virtual bool isPICDefault() const = 0;
479
480
  /// Test whether this toolchain defaults to PIE.
481
  virtual bool isPIEDefault() const = 0;
482
483
  /// Test whether this toolchaind defaults to non-executable stacks.
484
  virtual bool isNoExecStackDefault() const;
485
486
  /// Tests whether this toolchain forces its default for PIC, PIE or
487
  /// non-PIC.  If this returns true, any PIC related flags should be ignored
488
  /// and instead the results of \c isPICDefault() and \c isPIEDefault() are
489
  /// used exclusively.
490
  virtual bool isPICDefaultForced() const = 0;
491
492
  /// SupportsProfiling - Does this tool chain support -pg.
493
25.3k
  virtual bool SupportsProfiling() const { return true; }
494
495
  /// Complain if this tool chain doesn't support Objective-C ARC.
496
41
  virtual void CheckObjCARC() const {}
497
498
  /// Get the default debug info format. Typically, this is DWARF.
499
3.73k
  virtual codegenoptions::DebugInfoFormat getDefaultDebugFormat() const {
500
3.73k
    return codegenoptions::DIF_DWARF;
501
3.73k
  }
502
503
  /// UseDwarfDebugFlags - Embed the compile options to clang into the Dwarf
504
  /// compile unit information.
505
27.2k
  virtual bool UseDwarfDebugFlags() const { return false; }
506
507
  // Return the DWARF version to emit, in the absence of arguments
508
  // to the contrary.
509
497
  virtual unsigned GetDefaultDwarfVersion() const { return 4; }
510
511
  // Some toolchains may have different restrictions on the DWARF version and
512
  // may need to adjust it. E.g. NVPTX may need to enforce DWARF2 even when host
513
  // compilation uses DWARF5.
514
3.75k
  virtual unsigned getMaxDwarfVersion() const { return UINT_MAX; }
515
516
  // True if the driver should assume "-fstandalone-debug"
517
  // in the absence of an option specifying otherwise,
518
  // provided that debugging was requested in the first place.
519
  // i.e. a value of 'true' does not imply that debugging is wanted.
520
26.7k
  virtual bool GetDefaultStandaloneDebug() const { return false; }
521
522
  // Return the default debugger "tuning."
523
18.7k
  virtual llvm::DebuggerKind getDefaultDebuggerTuning() const {
524
18.7k
    return llvm::DebuggerKind::GDB;
525
18.7k
  }
526
527
  /// Does this toolchain supports given debug info option or not.
528
8.12k
  virtual bool supportsDebugInfoOption(const llvm::opt::Arg *) const {
529
8.12k
    return true;
530
8.12k
  }
531
532
  /// Adjust debug information kind considering all passed options.
533
  virtual void adjustDebugInfoKind(codegenoptions::DebugInfoKind &DebugInfoKind,
534
42.8k
                                   const llvm::opt::ArgList &Args) const {}
535
536
  /// GetExceptionModel - Return the tool chain exception model.
537
  virtual llvm::ExceptionHandling
538
  GetExceptionModel(const llvm::opt::ArgList &Args) const;
539
540
  /// SupportsEmbeddedBitcode - Does this tool chain support embedded bitcode.
541
0
  virtual bool SupportsEmbeddedBitcode() const { return false; }
542
543
  /// getThreadModel() - Which thread model does this target use?
544
52.1k
  virtual std::string getThreadModel() const { return "posix"; }
545
546
  /// isThreadModelSupported() - Does this target support a thread model?
547
  virtual bool isThreadModelSupported(const StringRef Model) const;
548
549
  virtual std::string getMultiarchTriple(const Driver &D,
550
                                         const llvm::Triple &TargetTriple,
551
0
                                         StringRef SysRoot) const {
552
0
    return TargetTriple.str();
553
0
  }
554
555
  /// ComputeLLVMTriple - Return the LLVM target triple to use, after taking
556
  /// command line arguments into account.
557
  virtual std::string
558
  ComputeLLVMTriple(const llvm::opt::ArgList &Args,
559
                    types::ID InputType = types::TY_INVALID) const;
560
561
  /// ComputeEffectiveClangTriple - Return the Clang triple to use for this
562
  /// target, which may take into account the command line arguments. For
563
  /// example, on Darwin the -mmacosx-version-min= command line argument (which
564
  /// sets the deployment target) determines the version in the triple passed to
565
  /// Clang.
566
  virtual std::string ComputeEffectiveClangTriple(
567
      const llvm::opt::ArgList &Args,
568
      types::ID InputType = types::TY_INVALID) const;
569
570
  /// getDefaultObjCRuntime - Return the default Objective-C runtime
571
  /// for this platform.
572
  ///
573
  /// FIXME: this really belongs on some sort of DeploymentTarget abstraction
574
  virtual ObjCRuntime getDefaultObjCRuntime(bool isNonFragile) const;
575
576
  /// hasBlocksRuntime - Given that the user is compiling with
577
  /// -fblocks, does this tool chain guarantee the existence of a
578
  /// blocks runtime?
579
  ///
580
  /// FIXME: this really belongs on some sort of DeploymentTarget abstraction
581
833
  virtual bool hasBlocksRuntime() const { return true; }
582
583
  /// Return the sysroot, possibly searching for a default sysroot using
584
  /// target-specific logic.
585
  virtual std::string computeSysRoot() const;
586
587
  /// Add the clang cc1 arguments for system include paths.
588
  ///
589
  /// This routine is responsible for adding the necessary cc1 arguments to
590
  /// include headers from standard system header directories.
591
  virtual void
592
  AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
593
                            llvm::opt::ArgStringList &CC1Args) const;
594
595
  /// Add options that need to be passed to cc1 for this target.
596
  virtual void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
597
                                     llvm::opt::ArgStringList &CC1Args,
598
                                     Action::OffloadKind DeviceOffloadKind) const;
599
600
  /// Add warning options that need to be passed to cc1 for this target.
601
  virtual void addClangWarningOptions(llvm::opt::ArgStringList &CC1Args) const;
602
603
  // GetRuntimeLibType - Determine the runtime library type to use with the
604
  // given compilation arguments.
605
  virtual RuntimeLibType
606
  GetRuntimeLibType(const llvm::opt::ArgList &Args) const;
607
608
  // GetCXXStdlibType - Determine the C++ standard library type to use with the
609
  // given compilation arguments.
610
  virtual CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const;
611
612
  // GetUnwindLibType - Determine the unwind library type to use with the
613
  // given compilation arguments.
614
  virtual UnwindLibType GetUnwindLibType(const llvm::opt::ArgList &Args) const;
615
616
  // Detect the highest available version of libc++ in include path.
617
  virtual std::string detectLibcxxVersion(StringRef IncludePath) const;
618
619
  /// AddClangCXXStdlibIncludeArgs - Add the clang -cc1 level arguments to set
620
  /// the include paths to use for the given C++ standard library type.
621
  virtual void
622
  AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
623
                               llvm::opt::ArgStringList &CC1Args) const;
624
625
  /// AddClangCXXStdlibIsystemArgs - Add the clang -cc1 level arguments to set
626
  /// the specified include paths for the C++ standard library.
627
  void AddClangCXXStdlibIsystemArgs(const llvm::opt::ArgList &DriverArgs,
628
                                    llvm::opt::ArgStringList &CC1Args) const;
629
630
  /// Returns if the C++ standard library should be linked in.
631
  /// Note that e.g. -lm should still be linked even if this returns false.
632
  bool ShouldLinkCXXStdlib(const llvm::opt::ArgList &Args) const;
633
634
  /// AddCXXStdlibLibArgs - Add the system specific linker arguments to use
635
  /// for the given C++ standard library type.
636
  virtual void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
637
                                   llvm::opt::ArgStringList &CmdArgs) const;
638
639
  /// AddFilePathLibArgs - Add each thing in getFilePaths() as a "-L" option.
640
  void AddFilePathLibArgs(const llvm::opt::ArgList &Args,
641
                          llvm::opt::ArgStringList &CmdArgs) const;
642
643
  /// AddCCKextLibArgs - Add the system specific linker arguments to use
644
  /// for kernel extensions (Darwin-specific).
645
  virtual void AddCCKextLibArgs(const llvm::opt::ArgList &Args,
646
                                llvm::opt::ArgStringList &CmdArgs) const;
647
648
  /// If a runtime library exists that sets global flags for unsafe floating
649
  /// point math, return true.
650
  ///
651
  /// This checks for presence of the -Ofast, -ffast-math or -funsafe-math flags.
652
  virtual bool isFastMathRuntimeAvailable(
653
    const llvm::opt::ArgList &Args, std::string &Path) const;
654
655
  /// AddFastMathRuntimeIfAvailable - If a runtime library exists that sets
656
  /// global flags for unsafe floating point math, add it and return true.
657
  ///
658
  /// This checks for presence of the -Ofast, -ffast-math or -funsafe-math flags.
659
  bool addFastMathRuntimeIfAvailable(
660
    const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const;
661
662
  /// addProfileRTLibs - When -fprofile-instr-profile is specified, try to pass
663
  /// a suitable profile runtime library to the linker.
664
  virtual void addProfileRTLibs(const llvm::opt::ArgList &Args,
665
                                llvm::opt::ArgStringList &CmdArgs) const;
666
667
  /// Add arguments to use system-specific CUDA includes.
668
  virtual void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs,
669
                                  llvm::opt::ArgStringList &CC1Args) const;
670
671
  /// Add arguments to use system-specific HIP includes.
672
  virtual void AddHIPIncludeArgs(const llvm::opt::ArgList &DriverArgs,
673
                                 llvm::opt::ArgStringList &CC1Args) const;
674
675
  /// Add arguments to use MCU GCC toolchain includes.
676
  virtual void AddIAMCUIncludeArgs(const llvm::opt::ArgList &DriverArgs,
677
                                   llvm::opt::ArgStringList &CC1Args) const;
678
679
  /// On Windows, returns the MSVC compatibility version.
680
  virtual VersionTuple computeMSVCVersion(const Driver *D,
681
                                          const llvm::opt::ArgList &Args) const;
682
683
  /// Get paths of HIP device libraries.
684
  virtual llvm::SmallVector<std::string, 12>
685
  getHIPDeviceLibs(const llvm::opt::ArgList &Args) const;
686
687
  /// Return sanitizers which are available in this toolchain.
688
  virtual SanitizerMask getSupportedSanitizers() const;
689
690
  /// Return sanitizers which are enabled by default.
691
45.6k
  virtual SanitizerMask getDefaultSanitizers() const {
692
45.6k
    return SanitizerMask();
693
45.6k
  }
694
695
  /// Returns true when it's possible to split LTO unit to use whole
696
  /// program devirtualization and CFI santiizers.
697
26
  virtual bool canSplitThinLTOUnit() const { return true; }
698
699
  /// Returns the output denormal handling type in the default floating point
700
  /// environment for the given \p FPType if given. Otherwise, the default
701
  /// assumed mode for any floating point type.
702
  virtual llvm::DenormalMode getDefaultDenormalModeForType(
703
      const llvm::opt::ArgList &DriverArgs, const JobAction &JA,
704
75.0k
      const llvm::fltSemantics *FPType = nullptr) const {
705
75.0k
    return llvm::DenormalMode::getIEEE();
706
75.0k
  }
707
};
708
709
/// Set a ToolChain's effective triple. Reset it when the registration object
710
/// is destroyed.
711
class RegisterEffectiveTriple {
712
  const ToolChain &TC;
713
714
public:
715
52.5k
  RegisterEffectiveTriple(const ToolChain &TC, llvm::Triple T) : TC(TC) {
716
52.5k
    TC.setEffectiveTriple(std::move(T));
717
52.5k
  }
718
719
52.5k
  ~RegisterEffectiveTriple() { TC.setEffectiveTriple(llvm::Triple()); }
720
};
721
722
} // namespace driver
723
724
} // namespace clang
725
726
#endif // LLVM_CLANG_DRIVER_TOOLCHAIN_H