Coverage Report

Created: 2020-09-19 12:23

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