Coverage Report

Created: 2022-01-18 06:27

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