Coverage Report

Created: 2020-02-25 14:32

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