Coverage Report

Created: 2021-01-19 06:58

/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
50.4k
  ParsedClangName() = default;
78
  ParsedClangName(std::string Suffix, const char *Mode)
79
77.9k
      : 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
30
        TargetIsValid(IsRegistered) {}
84
85
48.1k
  bool isEmpty() const {
86
48.1k
    return TargetPrefix.empty() && 
ModeSuffix.empty()48.0k
&&
DriverMode == nullptr27.4k
;
87
48.1k
  }
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
106k
  void setEffectiveTriple(llvm::Triple ET) const {
166
106k
    EffectiveTriple = std::move(ET);
167
106k
  }
168
169
protected:
170
  MultilibSet Multilibs;
171
  Multilib SelectedMultilib;
172
173
  ToolChain(const Driver &D, const llvm::Triple &T,
174
            const llvm::opt::ArgList &Args);
175
176
  void setTripleEnvironment(llvm::Triple::EnvironmentType Env);
177
178
  virtual Tool *buildAssembler() const;
179
  virtual Tool *buildLinker() const;
180
  virtual Tool *buildStaticLibTool() const;
181
  virtual Tool *getTool(Action::ActionClass AC) const;
182
183
  /// \name Utilities for implementing subclasses.
184
  ///@{
185
  static void addSystemInclude(const llvm::opt::ArgList &DriverArgs,
186
                               llvm::opt::ArgStringList &CC1Args,
187
                               const Twine &Path);
188
  static void addExternCSystemInclude(const llvm::opt::ArgList &DriverArgs,
189
                                      llvm::opt::ArgStringList &CC1Args,
190
                                      const Twine &Path);
191
  static void
192
      addExternCSystemIncludeIfExists(const llvm::opt::ArgList &DriverArgs,
193
                                      llvm::opt::ArgStringList &CC1Args,
194
                                      const Twine &Path);
195
  static void addSystemIncludes(const llvm::opt::ArgList &DriverArgs,
196
                                llvm::opt::ArgStringList &CC1Args,
197
                                ArrayRef<StringRef> Paths);
198
  ///@}
199
200
public:
201
  virtual ~ToolChain();
202
203
  // Accessors
204
205
1.04M
  const Driver &getDriver() const { return D; }
206
  llvm::vfs::FileSystem &getVFS() const;
207
2.25M
  const llvm::Triple &getTriple() const { return Triple; }
208
209
  /// Get the toolchain's aux triple, if it has one.
210
  ///
211
  /// Exactly what the aux triple represents depends on the toolchain, but for
212
  /// example when compiling CUDA code for the GPU, the triple might be NVPTX,
213
  /// while the aux triple is the host (CPU) toolchain, e.g. x86-linux-gnu.
214
368
  virtual const llvm::Triple *getAuxTriple() const { return nullptr; }
215
216
  /// Some toolchains need to modify the file name, for example to replace the
217
  /// extension for object files with .cubin for OpenMP offloading to Nvidia
218
  /// GPUs.
219
  virtual std::string getInputFilename(const InputInfo &Input) const;
220
221
513k
  llvm::Triple::ArchType getArch() const { return Triple.getArch(); }
222
2
  StringRef getArchName() const { return Triple.getArchName(); }
223
0
  StringRef getPlatform() const { return Triple.getVendorName(); }
224
56.9k
  StringRef getOS() const { return Triple.getOSName(); }
225
226
  /// Provide the default architecture name (as expected by -arch) for
227
  /// this toolchain.
228
  StringRef getDefaultUniversalArchName() const;
229
230
37.6k
  std::string getTripleString() const {
231
37.6k
    return Triple.getTriple();
232
37.6k
  }
233
234
  /// Get the toolchain's effective clang triple.
235
188k
  const llvm::Triple &getEffectiveTriple() const {
236
188k
    assert(!EffectiveTriple.getTriple().empty() && "No effective triple");
237
188k
    return EffectiveTriple;
238
188k
  }
239
240
35
  path_list &getLibraryPaths() { return LibraryPaths; }
241
10.8k
  const path_list &getLibraryPaths() const { return LibraryPaths; }
242
243
6.99k
  path_list &getFilePaths() { return FilePaths; }
244
11.6k
  const path_list &getFilePaths() const { return FilePaths; }
245
246
53.8k
  path_list &getProgramPaths() { return ProgramPaths; }
247
8.65k
  const path_list &getProgramPaths() const { return ProgramPaths; }
248
249
1
  const MultilibSet &getMultilibs() const { return Multilibs; }
250
251
3
  const Multilib &getMultilib() const { return SelectedMultilib; }
252
253
  const SanitizerArgs& getSanitizerArgs() const;
254
255
  const XRayArgs& getXRayArgs() const;
256
257
  // Returns the Arg * that explicitly turned on/off rtti, or nullptr.
258
4
  const llvm::opt::Arg *getRTTIArg() const { return CachedRTTIArg; }
259
260
  // Returns the RTTIMode for the toolchain with the current arguments.
261
91.4k
  RTTIMode getRTTIMode() const { return CachedRTTIMode; }
262
263
  /// Return any implicit target and/or mode flag for an invocation of
264
  /// the compiler driver as `ProgName`.
265
  ///
266
  /// For example, when called with i686-linux-android-g++, the first element
267
  /// of the return value will be set to `"i686-linux-android"` and the second
268
  /// will be set to "--driver-mode=g++"`.
269
  /// It is OK if the target name is not registered. In this case the return
270
  /// value contains false in the field TargetIsValid.
271
  ///
272
  /// \pre `llvm::InitializeAllTargets()` has been called.
273
  /// \param ProgName The name the Clang driver was invoked with (from,
274
  /// e.g., argv[0]).
275
  /// \return A structure of type ParsedClangName that contains the executable
276
  /// name parts.
277
  static ParsedClangName getTargetAndModeFromProgramName(StringRef ProgName);
278
279
  // Tool access.
280
281
  /// TranslateArgs - Create a new derived argument list for any argument
282
  /// translations this ToolChain may wish to perform, or 0 if no tool chain
283
  /// specific translations are needed. If \p DeviceOffloadKind is specified
284
  /// the translation specific for that offload kind is performed.
285
  ///
286
  /// \param BoundArch - The bound architecture name, or 0.
287
  /// \param DeviceOffloadKind - The device offload kind used for the
288
  /// translation.
289
  virtual llvm::opt::DerivedArgList *
290
  TranslateArgs(const llvm::opt::DerivedArgList &Args, StringRef BoundArch,
291
964
                Action::OffloadKind DeviceOffloadKind) const {
292
964
    return nullptr;
293
964
  }
294
295
  /// TranslateOpenMPTargetArgs - Create a new derived argument list for
296
  /// that contains the OpenMP target specific flags passed via
297
  /// -Xopenmp-target -opt=val OR -Xopenmp-target=<triple> -opt=val
298
  virtual llvm::opt::DerivedArgList *TranslateOpenMPTargetArgs(
299
      const llvm::opt::DerivedArgList &Args, bool SameTripleAsHost,
300
      SmallVectorImpl<llvm::opt::Arg *> &AllocatedArgs) const;
301
302
  /// Append the argument following \p A to \p DAL assuming \p A is an Xarch
303
  /// argument. If \p AllocatedArgs is null pointer, synthesized arguments are
304
  /// added to \p DAL, otherwise they are appended to \p AllocatedArgs.
305
  virtual void TranslateXarchArgs(
306
      const llvm::opt::DerivedArgList &Args, llvm::opt::Arg *&A,
307
      llvm::opt::DerivedArgList *DAL,
308
      SmallVectorImpl<llvm::opt::Arg *> *AllocatedArgs = nullptr) const;
309
310
  /// Translate -Xarch_ arguments. If there are no such arguments, return
311
  /// a null pointer, otherwise return a DerivedArgList containing the
312
  /// translated arguments.
313
  virtual llvm::opt::DerivedArgList *
314
  TranslateXarchArgs(const llvm::opt::DerivedArgList &Args, StringRef BoundArch,
315
                     Action::OffloadKind DeviceOffloadKind,
316
                     SmallVectorImpl<llvm::opt::Arg *> *AllocatedArgs) const;
317
318
  /// Choose a tool to use to handle the action \p JA.
319
  ///
320
  /// This can be overridden when a particular ToolChain needs to use
321
  /// a compiler other than Clang.
322
  virtual Tool *SelectTool(const JobAction &JA) const;
323
324
  // Helper methods
325
326
  std::string GetFilePath(const char *Name) const;
327
  std::string GetProgramPath(const char *Name) const;
328
329
  /// Returns the linker path, respecting the -fuse-ld= argument to determine
330
  /// the linker suffix or name.
331
  /// If LinkerIsLLD is non-nullptr, it is set to true if the returned linker
332
  /// is LLD. If it's set, it can be assumed that the linker is LLD built
333
  /// at the same revision as clang, and clang can make assumptions about
334
  /// LLD's supported flags, error output, etc.
335
  /// If LinkerIsLLDDarwinNew is non-nullptr, it's set if the linker is
336
  /// the new version in lld/MachO.
337
  std::string GetLinkerPath(bool *LinkerIsLLD = nullptr,
338
                            bool *LinkerIsLLDDarwinNew = nullptr) const;
339
340
  /// Returns the linker path for emitting a static library.
341
  std::string GetStaticLibToolPath() const;
342
343
  /// Dispatch to the specific toolchain for verbose printing.
344
  ///
345
  /// This is used when handling the verbose option to print detailed,
346
  /// toolchain-specific information useful for understanding the behavior of
347
  /// the driver on a specific platform.
348
9
  virtual void printVerboseInfo(raw_ostream &OS) const {}
349
350
  // Platform defaults information
351
352
  /// Returns true if the toolchain is targeting a non-native
353
  /// architecture.
354
  virtual bool isCrossCompiling() const;
355
356
  /// HasNativeLTOLinker - Check whether the linker and related tools have
357
  /// native LLVM support.
358
  virtual bool HasNativeLLVMSupport() const;
359
360
  /// LookupTypeForExtension - Return the default language type to use for the
361
  /// given extension.
362
  virtual types::ID LookupTypeForExtension(StringRef Ext) const;
363
364
  /// IsBlocksDefault - Does this tool chain enable -fblocks by default.
365
25.9k
  virtual bool IsBlocksDefault() const { return false; }
366
367
  /// IsIntegratedAssemblerDefault - Does this tool chain enable -integrated-as
368
  /// by default.
369
1.79k
  virtual bool IsIntegratedAssemblerDefault() const { return false; }
370
371
  /// Check if the toolchain should use the integrated assembler.
372
  virtual bool useIntegratedAs() const;
373
374
  /// IsMathErrnoDefault - Does this tool chain use -fmath-errno by default.
375
24.3k
  virtual bool IsMathErrnoDefault() const { return true; }
376
377
  /// IsEncodeExtendedBlockSignatureDefault - Does this tool chain enable
378
  /// -fencode-extended-block-signature by default.
379
25.9k
  virtual bool IsEncodeExtendedBlockSignatureDefault() const { return false; }
380
381
  /// IsObjCNonFragileABIDefault - Does this tool chain set
382
  /// -fobjc-nonfragile-abi by default.
383
25.2k
  virtual bool IsObjCNonFragileABIDefault() const { return false; }
384
385
  /// UseObjCMixedDispatchDefault - When using non-legacy dispatch, should the
386
  /// mixed dispatch method be used?
387
0
  virtual bool UseObjCMixedDispatch() const { return false; }
388
389
  /// Check whether to enable x86 relax relocations by default.
390
  virtual bool useRelaxRelocations() const;
391
392
  /// GetDefaultStackProtectorLevel - Get the default stack protector level for
393
  /// this tool chain.
394
  virtual LangOptions::StackProtectorMode
395
25.3k
  GetDefaultStackProtectorLevel(bool KernelOrKext) const {
396
25.3k
    return LangOptions::SSPOff;
397
25.3k
  }
398
399
  /// Get the default trivial automatic variable initialization.
400
  virtual LangOptions::TrivialAutoVarInitKind
401
44.5k
  GetDefaultTrivialAutoVarInit() const {
402
44.5k
    return LangOptions::TrivialAutoVarInitKind::Uninitialized;
403
44.5k
  }
404
405
  /// GetDefaultLinker - Get the default linker to use.
406
5.50k
  virtual const char *getDefaultLinker() const { return "ld"; }
407
408
  /// GetDefaultRuntimeLibType - Get the default runtime library variant to use.
409
9.64k
  virtual RuntimeLibType GetDefaultRuntimeLibType() const {
410
9.64k
    return ToolChain::RLT_Libgcc;
411
9.64k
  }
412
413
7.96k
  virtual CXXStdlibType GetDefaultCXXStdlibType() const {
414
7.96k
    return ToolChain::CST_Libstdcxx;
415
7.96k
  }
416
417
0
  virtual UnwindLibType GetDefaultUnwindLibType() const {
418
0
    return ToolChain::UNW_None;
419
0
  }
420
421
  virtual std::string getCompilerRTPath() const;
422
423
  virtual std::string getCompilerRT(const llvm::opt::ArgList &Args,
424
                                    StringRef Component,
425
                                    FileType Type = ToolChain::FT_Static) const;
426
427
  const char *
428
  getCompilerRTArgString(const llvm::opt::ArgList &Args, StringRef Component,
429
                         FileType Type = ToolChain::FT_Static) const;
430
431
  virtual std::string
432
  getCompilerRTBasename(const llvm::opt::ArgList &Args, StringRef Component,
433
                        FileType Type = ToolChain::FT_Static,
434
                        bool AddArch = true) const;
435
436
  // Returns target specific runtime path if it exists.
437
  virtual Optional<std::string> getRuntimePath() const;
438
439
  // Returns target specific C++ library path if it exists.
440
  virtual Optional<std::string> getCXXStdlibPath() const;
441
442
  // Returns <ResourceDir>/lib/<OSName>/<arch>.  This is used by runtimes (such
443
  // as OpenMP) to find arch-specific libraries.
444
  std::string getArchSpecificLibPath() const;
445
446
  // Returns <OSname> part of above.
447
  virtual StringRef getOSLibName() const;
448
449
  /// needsProfileRT - returns true if instrumentation profile is on.
450
  static bool needsProfileRT(const llvm::opt::ArgList &Args);
451
452
  /// Returns true if gcov instrumentation (-fprofile-arcs or --coverage) is on.
453
  static bool needsGCovInstrumentation(const llvm::opt::ArgList &Args);
454
455
  /// IsUnwindTablesDefault - Does this tool chain use -funwind-tables
456
  /// by default.
457
  virtual bool IsUnwindTablesDefault(const llvm::opt::ArgList &Args) const;
458
459
  /// Test whether this toolchain defaults to PIC.
460
  virtual bool isPICDefault() const = 0;
461
462
  /// Test whether this toolchain defaults to PIE.
463
  virtual bool isPIEDefault() const = 0;
464
465
  /// Test whether this toolchaind defaults to non-executable stacks.
466
  virtual bool isNoExecStackDefault() const;
467
468
  /// Tests whether this toolchain forces its default for PIC, PIE or
469
  /// non-PIC.  If this returns true, any PIC related flags should be ignored
470
  /// and instead the results of \c isPICDefault() and \c isPIEDefault() are
471
  /// used exclusively.
472
  virtual bool isPICDefaultForced() const = 0;
473
474
  /// SupportsProfiling - Does this tool chain support -pg.
475
24.6k
  virtual bool SupportsProfiling() const { return true; }
476
477
  /// Complain if this tool chain doesn't support Objective-C ARC.
478
7
  virtual void CheckObjCARC() const {}
479
480
  /// Get the default debug info format. Typically, this is DWARF.
481
6.48k
  virtual codegenoptions::DebugInfoFormat getDefaultDebugFormat() const {
482
6.48k
    return codegenoptions::DIF_DWARF;
483
6.48k
  }
484
485
  /// UseDwarfDebugFlags - Embed the compile options to clang into the Dwarf
486
  /// compile unit information.
487
26.2k
  virtual bool UseDwarfDebugFlags() const { return false; }
488
489
  // Return the DWARF version to emit, in the absence of arguments
490
  // to the contrary.
491
423
  virtual unsigned GetDefaultDwarfVersion() const { return 4; }
492
493
  // Some toolchains may have different restrictions on the DWARF version and
494
  // may need to adjust it. E.g. NVPTX may need to enforce DWARF2 even when host
495
  // compilation uses DWARF5.
496
6.49k
  virtual unsigned getMaxDwarfVersion() const { return UINT_MAX; }
497
498
  // True if the driver should assume "-fstandalone-debug"
499
  // in the absence of an option specifying otherwise,
500
  // provided that debugging was requested in the first place.
501
  // i.e. a value of 'true' does not imply that debugging is wanted.
502
25.8k
  virtual bool GetDefaultStandaloneDebug() const { return false; }
503
504
  // Return the default debugger "tuning."
505
18.0k
  virtual llvm::DebuggerKind getDefaultDebuggerTuning() const {
506
18.0k
    return llvm::DebuggerKind::GDB;
507
18.0k
  }
508
509
  /// Does this toolchain supports given debug info option or not.
510
14.4k
  virtual bool supportsDebugInfoOption(const llvm::opt::Arg *) const {
511
14.4k
    return true;
512
14.4k
  }
513
514
  /// Adjust debug information kind considering all passed options.
515
  virtual void adjustDebugInfoKind(codegenoptions::DebugInfoKind &DebugInfoKind,
516
44.1k
                                   const llvm::opt::ArgList &Args) const {}
517
518
  /// GetExceptionModel - Return the tool chain exception model.
519
  virtual llvm::ExceptionHandling
520
  GetExceptionModel(const llvm::opt::ArgList &Args) const;
521
522
  /// SupportsEmbeddedBitcode - Does this tool chain support embedded bitcode.
523
0
  virtual bool SupportsEmbeddedBitcode() const { return false; }
524
525
  /// getThreadModel() - Which thread model does this target use?
526
53.0k
  virtual std::string getThreadModel() const { return "posix"; }
527
528
  /// isThreadModelSupported() - Does this target support a thread model?
529
  virtual bool isThreadModelSupported(const StringRef Model) const;
530
531
  /// ComputeLLVMTriple - Return the LLVM target triple to use, after taking
532
  /// command line arguments into account.
533
  virtual std::string
534
  ComputeLLVMTriple(const llvm::opt::ArgList &Args,
535
                    types::ID InputType = types::TY_INVALID) const;
536
537
  /// ComputeEffectiveClangTriple - Return the Clang triple to use for this
538
  /// target, which may take into account the command line arguments. For
539
  /// example, on Darwin the -mmacosx-version-min= command line argument (which
540
  /// sets the deployment target) determines the version in the triple passed to
541
  /// Clang.
542
  virtual std::string ComputeEffectiveClangTriple(
543
      const llvm::opt::ArgList &Args,
544
      types::ID InputType = types::TY_INVALID) const;
545
546
  /// getDefaultObjCRuntime - Return the default Objective-C runtime
547
  /// for this platform.
548
  ///
549
  /// FIXME: this really belongs on some sort of DeploymentTarget abstraction
550
  virtual ObjCRuntime getDefaultObjCRuntime(bool isNonFragile) const;
551
552
  /// hasBlocksRuntime - Given that the user is compiling with
553
  /// -fblocks, does this tool chain guarantee the existence of a
554
  /// blocks runtime?
555
  ///
556
  /// FIXME: this really belongs on some sort of DeploymentTarget abstraction
557
791
  virtual bool hasBlocksRuntime() const { return true; }
558
559
  /// Return the sysroot, possibly searching for a default sysroot using
560
  /// target-specific logic.
561
  virtual std::string computeSysRoot() const;
562
563
  /// Add the clang cc1 arguments for system include paths.
564
  ///
565
  /// This routine is responsible for adding the necessary cc1 arguments to
566
  /// include headers from standard system header directories.
567
  virtual void
568
  AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
569
                            llvm::opt::ArgStringList &CC1Args) const;
570
571
  /// Add options that need to be passed to cc1 for this target.
572
  virtual void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
573
                                     llvm::opt::ArgStringList &CC1Args,
574
                                     Action::OffloadKind DeviceOffloadKind) const;
575
576
  /// Add warning options that need to be passed to cc1 for this target.
577
  virtual void addClangWarningOptions(llvm::opt::ArgStringList &CC1Args) const;
578
579
  // GetRuntimeLibType - Determine the runtime library type to use with the
580
  // given compilation arguments.
581
  virtual RuntimeLibType
582
  GetRuntimeLibType(const llvm::opt::ArgList &Args) const;
583
584
  // GetCXXStdlibType - Determine the C++ standard library type to use with the
585
  // given compilation arguments.
586
  virtual CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const;
587
588
  // GetUnwindLibType - Determine the unwind library type to use with the
589
  // given compilation arguments.
590
  virtual UnwindLibType GetUnwindLibType(const llvm::opt::ArgList &Args) const;
591
592
  /// AddClangCXXStdlibIncludeArgs - Add the clang -cc1 level arguments to set
593
  /// the include paths to use for the given C++ standard library type.
594
  virtual void
595
  AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
596
                               llvm::opt::ArgStringList &CC1Args) const;
597
598
  /// AddClangCXXStdlibIsystemArgs - Add the clang -cc1 level arguments to set
599
  /// the specified include paths for the C++ standard library.
600
  void AddClangCXXStdlibIsystemArgs(const llvm::opt::ArgList &DriverArgs,
601
                                    llvm::opt::ArgStringList &CC1Args) const;
602
603
  /// Returns if the C++ standard library should be linked in.
604
  /// Note that e.g. -lm should still be linked even if this returns false.
605
  bool ShouldLinkCXXStdlib(const llvm::opt::ArgList &Args) const;
606
607
  /// AddCXXStdlibLibArgs - Add the system specific linker arguments to use
608
  /// for the given C++ standard library type.
609
  virtual void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
610
                                   llvm::opt::ArgStringList &CmdArgs) const;
611
612
  /// AddFilePathLibArgs - Add each thing in getFilePaths() as a "-L" option.
613
  void AddFilePathLibArgs(const llvm::opt::ArgList &Args,
614
                          llvm::opt::ArgStringList &CmdArgs) const;
615
616
  /// AddCCKextLibArgs - Add the system specific linker arguments to use
617
  /// for kernel extensions (Darwin-specific).
618
  virtual void AddCCKextLibArgs(const llvm::opt::ArgList &Args,
619
                                llvm::opt::ArgStringList &CmdArgs) const;
620
621
  /// If a runtime library exists that sets global flags for unsafe floating
622
  /// point math, return true.
623
  ///
624
  /// This checks for presence of the -Ofast, -ffast-math or -funsafe-math flags.
625
  virtual bool isFastMathRuntimeAvailable(
626
    const llvm::opt::ArgList &Args, std::string &Path) const;
627
628
  /// AddFastMathRuntimeIfAvailable - If a runtime library exists that sets
629
  /// global flags for unsafe floating point math, add it and return true.
630
  ///
631
  /// This checks for presence of the -Ofast, -ffast-math or -funsafe-math flags.
632
  bool addFastMathRuntimeIfAvailable(
633
    const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const;
634
635
  /// addProfileRTLibs - When -fprofile-instr-profile is specified, try to pass
636
  /// a suitable profile runtime library to the linker.
637
  virtual void addProfileRTLibs(const llvm::opt::ArgList &Args,
638
                                llvm::opt::ArgStringList &CmdArgs) const;
639
640
  /// Add arguments to use system-specific CUDA includes.
641
  virtual void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs,
642
                                  llvm::opt::ArgStringList &CC1Args) const;
643
644
  /// Add arguments to use system-specific HIP includes.
645
  virtual void AddHIPIncludeArgs(const llvm::opt::ArgList &DriverArgs,
646
                                 llvm::opt::ArgStringList &CC1Args) const;
647
648
  /// Add arguments to use MCU GCC toolchain includes.
649
  virtual void AddIAMCUIncludeArgs(const llvm::opt::ArgList &DriverArgs,
650
                                   llvm::opt::ArgStringList &CC1Args) const;
651
652
  /// On Windows, returns the MSVC compatibility version.
653
  virtual VersionTuple computeMSVCVersion(const Driver *D,
654
                                          const llvm::opt::ArgList &Args) const;
655
656
  /// Return sanitizers which are available in this toolchain.
657
  virtual SanitizerMask getSupportedSanitizers() const;
658
659
  /// Return sanitizers which are enabled by default.
660
46.8k
  virtual SanitizerMask getDefaultSanitizers() const {
661
46.8k
    return SanitizerMask();
662
46.8k
  }
663
664
  /// Returns true when it's possible to split LTO unit to use whole
665
  /// program devirtualization and CFI santiizers.
666
18
  virtual bool canSplitThinLTOUnit() const { return true; }
667
668
  /// Returns the output denormal handling type in the default floating point
669
  /// environment for the given \p FPType if given. Otherwise, the default
670
  /// assumed mode for any floating point type.
671
  virtual llvm::DenormalMode getDefaultDenormalModeForType(
672
      const llvm::opt::ArgList &DriverArgs, const JobAction &JA,
673
78.5k
      const llvm::fltSemantics *FPType = nullptr) const {
674
78.5k
    return llvm::DenormalMode::getIEEE();
675
78.5k
  }
676
};
677
678
/// Set a ToolChain's effective triple. Reset it when the registration object
679
/// is destroyed.
680
class RegisterEffectiveTriple {
681
  const ToolChain &TC;
682
683
public:
684
53.3k
  RegisterEffectiveTriple(const ToolChain &TC, llvm::Triple T) : TC(TC) {
685
53.3k
    TC.setEffectiveTriple(std::move(T));
686
53.3k
  }
687
688
53.3k
  ~RegisterEffectiveTriple() { TC.setEffectiveTriple(llvm::Triple()); }
689
};
690
691
} // namespace driver
692
693
} // namespace clang
694
695
#endif // LLVM_CLANG_DRIVER_TOOLCHAIN_H