clang 24.0.0git
ToolChain.h
Go to the documentation of this file.
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/LLVM.h"
16#include "clang/Driver/Action.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/SmallSet.h"
23#include "llvm/ADT/SmallVector.h"
24#include "llvm/ADT/StringRef.h"
25#include "llvm/Frontend/Debug/Options.h"
26#include "llvm/MC/MCTargetOptions.h"
27#include "llvm/Option/Option.h"
28#include "llvm/Support/VersionTuple.h"
29#include "llvm/Support/VirtualFileSystemFwd.h"
30#include "llvm/Target/TargetOptions.h"
31#include "llvm/TargetParser/Triple.h"
32#include <cassert>
33#include <climits>
34#include <memory>
35#include <optional>
36#include <string>
37#include <utility>
38
39namespace llvm {
40namespace opt {
41
42class Arg;
43class ArgList;
44class DerivedArgList;
45
46} // namespace opt
47} // namespace llvm
48
49namespace clang {
50
51class ObjCRuntime;
52
53namespace driver {
54
55class Driver;
56class InputInfo;
57class SanitizerArgs;
58class Tool;
59class XRayArgs;
60
61enum LTOKind : int;
62
63/// Helper structure used to pass information extracted from clang executable
64/// name such as `i686-linux-android-g++`.
66 /// Target part of the executable name, as `i686-linux-android`.
67 std::string TargetPrefix;
68
69 /// Driver mode part of the executable name, as `g++`.
70 std::string ModeSuffix;
71
72 /// Corresponding driver mode argument, as '--driver-mode=g++'
73 const char *DriverMode = nullptr;
74
75 /// True if TargetPrefix is recognized as a registered target name.
76 bool TargetIsValid = false;
77
78 ParsedClangName() = default;
79 ParsedClangName(std::string Suffix, const char *Mode)
80 : ModeSuffix(Suffix), DriverMode(Mode) {}
81 ParsedClangName(std::string Target, std::string Suffix, const char *Mode,
82 bool IsRegistered)
83 : TargetPrefix(Target), ModeSuffix(Suffix), DriverMode(Mode),
84 TargetIsValid(IsRegistered) {}
85
86 bool isEmpty() const {
87 return TargetPrefix.empty() && ModeSuffix.empty() && DriverMode == nullptr;
88 }
89};
90
91/// ToolChain - Access to tools for a single platform.
92class ToolChain {
93public:
95
100
105
111
118
124
129
134
141
143
144private:
146
147 const Driver &D;
148 llvm::Triple Triple;
149 const llvm::opt::ArgList &Args;
150
151 // We need to initialize CachedRTTIArg before CachedRTTIMode
152 const llvm::opt::Arg *const CachedRTTIArg;
153
154 const RTTIMode CachedRTTIMode;
155
156 const ExceptionsMode CachedExceptionsMode;
157
158 /// The list of toolchain specific path prefixes to search for libraries.
159 path_list LibraryPaths;
160
161 /// The list of toolchain specific path prefixes to search for files.
162 path_list FilePaths;
163
164 /// The list of toolchain specific path prefixes to search for programs.
165 path_list ProgramPaths;
166
167 mutable std::unique_ptr<Tool> Clang;
168 mutable std::unique_ptr<Tool> Flang;
169 mutable std::unique_ptr<Tool> Assemble;
170 mutable std::unique_ptr<Tool> Link;
171 mutable std::unique_ptr<Tool> StaticLibTool;
172 mutable std::unique_ptr<Tool> IfsMerge;
173 mutable std::unique_ptr<Tool> OffloadBundler;
174 mutable std::unique_ptr<Tool> OffloadPackager;
175 mutable std::unique_ptr<Tool> LinkerWrapper;
176
177 Tool *getClang() const;
178 Tool *getFlang() const;
179 Tool *getAssemble() const;
180 Tool *getLink() const;
181 Tool *getStaticLibTool() const;
182 Tool *getIfsMerge() const;
183 Tool *getClangAs() const;
184 Tool *getOffloadBundler() const;
185 Tool *getOffloadPackager() const;
186 Tool *getLinkerWrapper() const;
187
188 /// Track if diagnostics have been emitted for sanitizer arguments already to
189 /// avoid duplicate diagnostics.
190 mutable bool SanitizerArgsChecked = false;
191
192 /// Set of BoundArch values which have already had diagnostics emitted.
193 mutable llvm::SmallSet<StringRef, 4> BoundArchSanitizerArgsChecked;
194
195 /// The effective clang triple for the current Job.
196 mutable llvm::Triple EffectiveTriple;
197
198 /// Set the toolchain's effective clang triple.
199 void setEffectiveTriple(llvm::Triple ET) const {
200 EffectiveTriple = std::move(ET);
201 }
202
203 std::optional<std::string>
204 getFallbackAndroidTargetPath(StringRef BaseDir) const;
205
206 mutable std::optional<CXXStdlibType> cxxStdlibType;
207 mutable std::optional<RuntimeLibType> runtimeLibType;
208 mutable std::optional<UnwindLibType> unwindLibType;
209 mutable std::optional<CStdlibType> cStdlibType;
210
211protected:
215
217 llvm::iterator_range<llvm::SmallVector<Multilib>::const_reverse_iterator>;
218
219 /// Get selected multilibs in priority order with default fallback.
221
222 /// Discover and load a multilib.yaml configuration.
223 bool loadMultilibsFromYAML(const llvm::opt::ArgList &Args, const Driver &D,
224 StringRef Fallback = {});
225
226 /// Load multilib configuration from a YAML file at \p MultilibPath,
227 std::optional<std::string> findMultilibsYAML(const llvm::opt::ArgList &Args,
228 const Driver &D,
229 StringRef FallbackDir = {});
230
231 ToolChain(const Driver &D, const llvm::Triple &T,
232 const llvm::opt::ArgList &Args);
233
234 void setTripleEnvironment(llvm::Triple::EnvironmentType Env);
235
236 virtual Tool *buildAssembler() const;
237 virtual Tool *buildLinker() const;
238 virtual Tool *buildStaticLibTool() const;
239 virtual Tool *getTool(Action::ActionClass AC) const;
240
241 virtual std::string buildCompilerRTBasename(const llvm::opt::ArgList &Args,
242 StringRef Component,
243 FileType Type, bool AddArch,
244 bool IsFortran = false) const;
245
246 /// Find the target-specific subdirectory for the current target triple under
247 /// \p BaseDir, doing fallback triple searches as necessary.
248 /// \return The subdirectory path if it exists.
249 std::optional<std::string> getTargetSubDirPath(StringRef BaseDir) const;
250
251 /// \name Utilities for implementing subclasses.
252 ///@{
253 static void addSystemFrameworkInclude(const llvm::opt::ArgList &DriverArgs,
254 llvm::opt::ArgStringList &CC1Args,
255 const Twine &Path);
256 static void addExternCSystemInclude(const llvm::opt::ArgList &DriverArgs,
257 llvm::opt::ArgStringList &CC1Args,
258 const Twine &Path);
259 static void
260 addExternCSystemIncludeIfExists(const llvm::opt::ArgList &DriverArgs,
261 llvm::opt::ArgStringList &CC1Args,
262 const Twine &Path);
263 static void addSystemFrameworkIncludes(const llvm::opt::ArgList &DriverArgs,
264 llvm::opt::ArgStringList &CC1Args,
265 ArrayRef<StringRef> Paths);
266 static void addSystemIncludes(const llvm::opt::ArgList &DriverArgs,
267 llvm::opt::ArgStringList &CC1Args,
268 ArrayRef<StringRef> Paths);
269
270 static std::string concat(StringRef Path, const Twine &A, const Twine &B = "",
271 const Twine &C = "", const Twine &D = "");
272 ///@}
273
274public:
275 static void addSystemInclude(const llvm::opt::ArgList &DriverArgs,
276 llvm::opt::ArgStringList &CC1Args,
277 const Twine &Path);
278 virtual ~ToolChain();
279
280 // Accessors
281
282 const Driver &getDriver() const { return D; }
283 llvm::vfs::FileSystem &getVFS() const;
284 const llvm::Triple &getTriple() const { return Triple; }
285
286 /// Get the toolchain's aux triple, if it has one.
287 ///
288 /// Exactly what the aux triple represents depends on the toolchain, but for
289 /// example when compiling CUDA code for the GPU, the triple might be NVPTX,
290 /// while the aux triple is the host (CPU) toolchain, e.g. x86-linux-gnu.
291 virtual const llvm::Triple *getAuxTriple() const { return nullptr; }
292
293 /// Some toolchains need to modify the file name, for example to replace the
294 /// extension for object files with .cubin for OpenMP offloading to Nvidia
295 /// GPUs.
296 virtual std::string getInputFilename(const InputInfo &Input) const;
297
298 llvm::Triple::ArchType getArch() const { return Triple.getArch(); }
299 StringRef getArchName() const { return Triple.getArchName(); }
300 StringRef getPlatform() const { return Triple.getVendorName(); }
301 StringRef getOS() const { return Triple.getOSName(); }
302
303 /// Provide the default architecture name (as expected by -arch) for
304 /// this toolchain.
305 StringRef getDefaultUniversalArchName() const;
306
307 StringRef getTripleString() const { return Triple.getTriple(); }
308
309 /// Get the toolchain's effective clang triple.
310 const llvm::Triple &getEffectiveTriple() const {
311 assert(!EffectiveTriple.getTriple().empty() && "No effective triple");
312 return EffectiveTriple;
313 }
314
315 bool hasEffectiveTriple() const {
316 return !EffectiveTriple.getTriple().empty();
317 }
318
319 path_list &getLibraryPaths() { return LibraryPaths; }
320 const path_list &getLibraryPaths() const { return LibraryPaths; }
321
322 path_list &getFilePaths() { return FilePaths; }
323 const path_list &getFilePaths() const { return FilePaths; }
324
325 path_list &getProgramPaths() { return ProgramPaths; }
326 const path_list &getProgramPaths() const { return ProgramPaths; }
327
328 const MultilibSet &getMultilibs() const { return Multilibs; }
329
333
334 /// Get flags suitable for multilib selection, based on the provided clang
335 /// command line arguments. The command line arguments aren't suitable to be
336 /// used directly for multilib selection because they are not normalized and
337 /// normalization is a complex process. The result of this function is similar
338 /// to clang command line arguments except that the list of arguments is
339 /// incomplete. Only certain command line arguments are processed. If more
340 /// command line arguments are needed for multilib selection then this
341 /// function should be extended.
342 /// To allow users to find out what flags are returned, clang accepts a
343 /// -print-multi-flags-experimental argument.
344 Multilib::flags_list getMultilibFlags(const llvm::opt::ArgList &) const;
345
347 const llvm::opt::ArgList &JobArgs, BoundArch BA = {},
348 Action::OffloadKind DeviceOffloadKind = Action::OFK_None) const;
349
350 /// Returns the feature requirement for a sanitizer on a specific arch for
351 /// diagnostic purposes. Returns the required feature name (e.g., "xnack+") if
352 /// the sanitizer is generally supported but requires a specific feature for
353 /// the given BoundArch, or an empty StringRef otherwise.
354 virtual StringRef getSanitizerRequirement(SanitizerMask Kinds,
355 BoundArch BA) const {
356 return {};
357 }
358
359 const XRayArgs getXRayArgs(const llvm::opt::ArgList &) const;
360
361 // Returns the Arg * that explicitly turned on/off rtti, or nullptr.
362 const llvm::opt::Arg *getRTTIArg() const { return CachedRTTIArg; }
363
364 // Returns the RTTIMode for the toolchain with the current arguments.
365 RTTIMode getRTTIMode() const { return CachedRTTIMode; }
366
367 // Returns the ExceptionsMode for the toolchain with the current arguments.
368 ExceptionsMode getExceptionsMode() const { return CachedExceptionsMode; }
369
370 /// Return any implicit target and/or mode flag for an invocation of
371 /// the compiler driver as `ProgName`.
372 ///
373 /// For example, when called with i686-linux-android-g++, the first element
374 /// of the return value will be set to `"i686-linux-android"` and the second
375 /// will be set to "--driver-mode=g++"`.
376 /// It is OK if the target name is not registered. In this case the return
377 /// value contains false in the field TargetIsValid.
378 ///
379 /// \pre `llvm::InitializeAllTargets()` has been called.
380 /// \param ProgName The name the Clang driver was invoked with (from,
381 /// e.g., argv[0]).
382 /// \return A structure of type ParsedClangName that contains the executable
383 /// name parts.
384 static ParsedClangName getTargetAndModeFromProgramName(StringRef ProgName);
385
386 // Tool access.
387
388 /// TranslateArgs - Create a new derived argument list for any argument
389 /// translations this ToolChain may wish to perform, or 0 if no tool chain
390 /// specific translations are needed. If \p DeviceOffloadKind is specified
391 /// the translation specific for that offload kind is performed.
392 ///
393 /// \param BA - The bound architecture.
394 /// \param DeviceOffloadKind - The device offload kind used for the
395 /// translation.
396 virtual llvm::opt::DerivedArgList *
397 TranslateArgs(const llvm::opt::DerivedArgList &Args, BoundArch BA,
398 Action::OffloadKind DeviceOffloadKind) const {
399 return nullptr;
400 }
401
402 /// TranslateOpenMPTargetArgs - Create a new derived argument list for
403 /// that contains the OpenMP target specific flags passed via
404 /// -Xopenmp-target -opt=val OR -Xopenmp-target=<triple> -opt=val
405 virtual llvm::opt::DerivedArgList *TranslateOpenMPTargetArgs(
406 const llvm::opt::DerivedArgList &Args, bool SameTripleAsHost,
407 SmallVectorImpl<llvm::opt::Arg *> &AllocatedArgs) const;
408
409 /// Append the argument following \p A to \p DAL assuming \p A is an Xarch
410 /// argument. If \p AllocatedArgs is null pointer, synthesized arguments are
411 /// added to \p DAL, otherwise they are appended to \p AllocatedArgs.
412 virtual void TranslateXarchArgs(
413 const llvm::opt::DerivedArgList &Args, llvm::opt::Arg *&A,
414 llvm::opt::DerivedArgList *DAL,
415 SmallVectorImpl<llvm::opt::Arg *> *AllocatedArgs = nullptr) const;
416
417 /// Translate -Xarch_ arguments. If there are no such arguments, return
418 /// a null pointer, otherwise return a DerivedArgList containing the
419 /// translated arguments.
420 virtual llvm::opt::DerivedArgList *
421 TranslateXarchArgs(const llvm::opt::DerivedArgList &Args, BoundArch BA,
422 Action::OffloadKind DeviceOffloadKind,
423 SmallVectorImpl<llvm::opt::Arg *> *AllocatedArgs) const;
424
425 /// Choose a tool to use to handle the action \p JA.
426 ///
427 /// This can be overridden when a particular ToolChain needs to use
428 /// a compiler other than Clang.
429 virtual Tool *SelectTool(const JobAction &JA) const;
430
431 // Helper methods
432
433 std::string GetFilePath(const char *Name) const;
434 std::optional<std::string> GetFilePathIfExists(const char *Name) const;
435 std::string GetProgramPath(const char *Name) const;
436
437 /// Returns the linker path, respecting the -fuse-ld= argument to determine
438 /// the linker suffix or name.
439 /// If LinkerIsLLD is non-nullptr, it is set to true if the returned linker
440 /// is LLD. If it's set, it can be assumed that the linker is LLD built
441 /// at the same revision as clang, and clang can make assumptions about
442 /// LLD's supported flags, error output, etc.
443 std::string GetLinkerPath(bool *LinkerIsLLD = nullptr) const;
444
445 /// Returns the linker path for emitting a static library.
446 std::string GetStaticLibToolPath() const;
447
448 /// Dispatch to the specific toolchain for verbose printing.
449 ///
450 /// This is used when handling the verbose option to print detailed,
451 /// toolchain-specific information useful for understanding the behavior of
452 /// the driver on a specific platform.
453 virtual void printVerboseInfo(raw_ostream &OS) const {}
454
455 // Platform defaults information
456
457 /// Returns true if the toolchain is targeting a non-native
458 /// architecture.
459 virtual bool isCrossCompiling() const;
460
461 /// HasNativeLTOLinker - Check whether the linker and related tools have
462 /// native LLVM support.
463 virtual bool HasNativeLLVMSupport() const;
464
465 /// Returns the default LTO mode for this toolchain.
466 virtual LTOKind getDefaultLTOMode() const;
467
468 /// Resolve the requested LTO mode for this toolchain.
469 virtual LTOKind getLTOMode(const llvm::opt::ArgList &Args,
471
472 /// Returns true if LTO is active for this toolchain given the args.
473 bool isUsingLTO(const llvm::opt::ArgList &Args,
475
476 /// LookupTypeForExtension - Return the default language type to use for the
477 /// given extension.
478 virtual types::ID LookupTypeForExtension(StringRef Ext) const;
479
480 /// IsBlocksDefault - Does this tool chain enable -fblocks by default.
481 virtual bool IsBlocksDefault() const { return false; }
482
483 /// IsIntegratedAssemblerDefault - Does this tool chain enable -integrated-as
484 /// by default.
485 virtual bool IsIntegratedAssemblerDefault() const { return true; }
486
487 /// IsIntegratedBackendDefault - Does this tool chain enable
488 /// -fintegrated-objemitter by default.
489 virtual bool IsIntegratedBackendDefault() const { return true; }
490
491 /// IsIntegratedBackendSupported - Does this tool chain support
492 /// -fintegrated-objemitter.
493 virtual bool IsIntegratedBackendSupported() const { return true; }
494
495 /// IsNonIntegratedBackendSupported - Does this tool chain support
496 /// -fno-integrated-objemitter.
497 virtual bool IsNonIntegratedBackendSupported() const { return false; }
498
499 /// Check if the toolchain should use the integrated assembler.
500 virtual bool useIntegratedAs() const;
501
502 /// Check if the toolchain should use the integrated backend.
503 virtual bool useIntegratedBackend() const;
504
505 /// Check if the toolchain should use AsmParser to parse inlineAsm when
506 /// integrated assembler is not default.
507 virtual bool parseInlineAsmUsingAsmParser() const { return false; }
508
509 /// IsMathErrnoDefault - Does this tool chain use -fmath-errno by default.
510 virtual bool IsMathErrnoDefault() const { return true; }
511
512 /// IsEncodeExtendedBlockSignatureDefault - Does this tool chain enable
513 /// -fencode-extended-block-signature by default.
514 virtual bool IsEncodeExtendedBlockSignatureDefault() const { return false; }
515
516 /// IsObjCNonFragileABIDefault - Does this tool chain set
517 /// -fobjc-nonfragile-abi by default.
518 virtual bool IsObjCNonFragileABIDefault() const { return false; }
519
520 /// UseObjCMixedDispatchDefault - When using non-legacy dispatch, should the
521 /// mixed dispatch method be used?
522 virtual bool UseObjCMixedDispatch() const { return false; }
523
524 /// Check whether to enable x86 relax relocations by default.
525 virtual bool useRelaxRelocations() const;
526
527 /// Check whether use IEEE binary128 as long double format by default.
528 bool defaultToIEEELongDouble() const;
529
530 /// GetDefaultStackProtectorLevel - Get the default stack protector level for
531 /// this tool chain.
533 GetDefaultStackProtectorLevel(bool KernelOrKext) const {
534 return LangOptions::SSPOff;
535 }
536
537 /// Get the default trivial automatic variable initialization.
542
543 /// GetDefaultLinker - Get the default linker to use.
544 virtual const char *getDefaultLinker() const { return "ld"; }
545
546 /// GetDefaultRuntimeLibType - Get the default runtime library variant to use.
550
554
556 return ToolChain::UNW_None;
557 }
558
559 virtual std::string getCompilerRTPath() const;
560
561 virtual std::string getCompilerRT(const llvm::opt::ArgList &Args,
562 StringRef Component,
564 bool IsFortran = false) const;
565
566 /// Adds Fortran runtime libraries to \p CmdArgs.
567 virtual void addFortranRuntimeLibs(const llvm::opt::ArgList &Args,
568 llvm::opt::ArgStringList &CmdArgs) const;
569
570 /// Adds the path for the Fortran runtime libraries to \p CmdArgs.
571 virtual void
572 addFortranRuntimeLibraryPath(const llvm::opt::ArgList &Args,
573 llvm::opt::ArgStringList &CmdArgs) const;
574
575 /// Add the path for libflang_rt.runtime.a
576 void addFlangRTLibPath(const llvm::opt::ArgList &Args,
577 llvm::opt::ArgStringList &CmdArgs) const;
578
579 const char *getCompilerRTArgString(const llvm::opt::ArgList &Args,
580 StringRef Component,
582 bool IsFortran = false) const;
583
584 std::string getCompilerRTBasename(const llvm::opt::ArgList &Args,
585 StringRef Component,
587
588 // Returns Triple without the OSs version.
589 llvm::Triple getTripleWithoutOSVersion() const;
590
591 /// Returns the target-specific path for Flang's intrinsic modules in the
592 /// resource directory if it exists.
593 std::optional<std::string> getDefaultIntrinsicModuleDir() const;
594
595 // Returns the target specific runtime path if it exists.
596 std::optional<std::string> getRuntimePath() const;
597
598 // Returns target specific standard library path if it exists.
599 std::optional<std::string> getStdlibPath() const;
600
601 // Returns target specific standard library include path if it exists.
602 std::optional<std::string> getStdlibIncludePath() const;
603
604 // Returns <ResourceDir>/lib/<OSName>/<arch> or <ResourceDir>/lib/<triple>.
605 // This is used by runtimes (such as OpenMP) to find arch-specific libraries.
606 virtual path_list getArchSpecificLibPaths() const;
607
608 // Returns <OSname> part of above.
609 virtual StringRef getOSLibName() const;
610
611 /// needsProfileRT - returns true if instrumentation profile is on.
612 static bool needsProfileRT(const llvm::opt::ArgList &Args);
613
614 /// Returns true if gcov instrumentation (-fprofile-arcs or --coverage) is on.
615 static bool needsGCovInstrumentation(const llvm::opt::ArgList &Args);
616
617 /// How detailed should the unwind tables be by default.
618 virtual UnwindTableLevel
619 getDefaultUnwindTableLevel(const llvm::opt::ArgList &Args) const;
620
621 /// Test whether this toolchain supports outline atomics by default.
622 virtual bool
623 IsAArch64OutlineAtomicsDefault(const llvm::opt::ArgList &Args) const {
624 return false;
625 }
626
627 /// Test whether this toolchain defaults to PIC.
628 virtual bool isPICDefault() const = 0;
629
630 /// Test whether this toolchain defaults to PIE.
631 virtual bool isPIEDefault(const llvm::opt::ArgList &Args) const = 0;
632
633 /// Tests whether this toolchain forces its default for PIC, PIE or
634 /// non-PIC. If this returns true, any PIC related flags should be ignored
635 /// and instead the results of \c isPICDefault() and \c isPIEDefault(const
636 /// llvm::opt::ArgList &Args) are used exclusively.
637 virtual bool isPICDefaultForced() const = 0;
638
639 /// SupportsProfiling - Does this tool chain support -pg.
640 virtual bool SupportsProfiling() const { return true; }
641
642 /// Complain if this tool chain doesn't support Objective-C ARC.
643 virtual void CheckObjCARC() const {}
644
645 /// Get the default debug info format. Typically, this is DWARF.
646 virtual llvm::codegenoptions::DebugInfoFormat getDefaultDebugFormat() const {
647 return llvm::codegenoptions::DIF_DWARF;
648 }
649
650 /// UseDwarfDebugFlags - Embed the compile options to clang into the Dwarf
651 /// compile unit information.
652 virtual bool UseDwarfDebugFlags() const { return false; }
653
654 /// Add an additional -fdebug-prefix-map entry.
655 virtual std::string GetGlobalDebugPathRemapping() const { return {}; }
656
657 // Return the DWARF version to emit, in the absence of arguments
658 // to the contrary.
659 virtual unsigned GetDefaultDwarfVersion() const { return 5; }
660
661 // Some toolchains may have different restrictions on the DWARF version and
662 // may need to adjust it. E.g. NVPTX may need to enforce DWARF2 even when host
663 // compilation uses DWARF5.
664 virtual unsigned getMaxDwarfVersion() const { return UINT_MAX; }
665
666 // True if the driver should assume "-fstandalone-debug"
667 // in the absence of an option specifying otherwise,
668 // provided that debugging was requested in the first place.
669 // i.e. a value of 'true' does not imply that debugging is wanted.
670 virtual bool GetDefaultStandaloneDebug() const { return false; }
671
672 /// Returns true if this toolchain adds '-gsimple-template-names=simple'
673 /// by default when generating debug-info.
674 virtual bool getDefaultDebugSimpleTemplateNames() const { return false; }
675
676 // Return the default debugger "tuning."
677 virtual llvm::DebuggerKind getDefaultDebuggerTuning() const {
678 return llvm::DebuggerKind::GDB;
679 }
680
681 /// Does this toolchain supports given debug info option or not.
682 virtual bool supportsDebugInfoOption(const llvm::opt::Arg *) const {
683 return true;
684 }
685
686 /// Adjust debug information kind considering all passed options.
687 virtual void
688 adjustDebugInfoKind(llvm::codegenoptions::DebugInfoKind &DebugInfoKind,
689 const llvm::opt::ArgList &Args) const {}
690
691 /// GetExceptionModel - Return the tool chain exception model.
692 virtual llvm::ExceptionHandling
693 GetExceptionModel(const llvm::opt::ArgList &Args) const;
694
695 /// SupportsEmbeddedBitcode - Does this tool chain support embedded bitcode.
696 virtual bool SupportsEmbeddedBitcode() const { return false; }
697
698 /// getThreadModel() - Which thread model does this target use?
699 virtual std::string getThreadModel() const { return "posix"; }
700
701 /// isThreadModelSupported() - Does this target support a thread model?
702 virtual bool isThreadModelSupported(const StringRef Model) const;
703
704 /// isBareMetal - Is this a bare metal target.
705 virtual bool isBareMetal() const { return false; }
706
707 virtual std::string getMultiarchTriple(const Driver &D,
708 const llvm::Triple &TargetTriple,
709 StringRef SysRoot) const {
710 return TargetTriple.str();
711 }
712
713 /// ComputeLLVMTriple - Return the LLVM target triple to use, after taking
714 /// command line arguments into account.
715 virtual std::string
716 ComputeLLVMTriple(const llvm::opt::ArgList &Args, BoundArch BA = {},
717 types::ID InputType = types::TY_INVALID) const;
718
719 /// ComputeEffectiveClangTriple - Return the Clang triple to use for this
720 /// target, which may take into account the command line arguments. For
721 /// example, on Darwin the -mmacos-version-min= command line argument (which
722 /// sets the deployment target) determines the version in the triple passed to
723 /// Clang.
724 virtual std::string
725 ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args, BoundArch BA = {},
726 types::ID InputType = types::TY_INVALID) const;
727
728 /// getDefaultObjCRuntime - Return the default Objective-C runtime
729 /// for this platform.
730 ///
731 /// FIXME: this really belongs on some sort of DeploymentTarget abstraction
732 virtual ObjCRuntime getDefaultObjCRuntime(bool isNonFragile) const;
733
734 /// hasBlocksRuntime - Given that the user is compiling with
735 /// -fblocks, does this tool chain guarantee the existence of a
736 /// blocks runtime?
737 ///
738 /// FIXME: this really belongs on some sort of DeploymentTarget abstraction
739 virtual bool hasBlocksRuntime() const { return true; }
740
741 /// Return the sysroot, possibly searching for a default sysroot using
742 /// target-specific logic.
743 virtual std::string computeSysRoot() const;
744
745 /// Add the clang cc1 arguments for system include paths.
746 ///
747 /// This routine is responsible for adding the necessary cc1 arguments to
748 /// include headers from standard system header directories.
749 virtual void
750 AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs,
751 llvm::opt::ArgStringList &CC1Args) const;
752
753 /// Add options that need to be passed to cc1 for this target.
754 virtual void
755 addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
756 llvm::opt::ArgStringList &CC1Args, BoundArch BA,
757 Action::OffloadKind DeviceOffloadKind) const;
758
759 /// Add options that need to be passed to cc1as for this target.
760 virtual void
761 addClangCC1ASTargetOptions(const llvm::opt::ArgList &Args,
762 llvm::opt::ArgStringList &CC1ASArgs) const;
763
764 /// Add warning options that need to be passed to cc1 for this target.
765 virtual void addClangWarningOptions(llvm::opt::ArgStringList &CC1Args) const;
766
767 /// Get the list of extra macro defines requested by the multilib
768 /// configuration.
770 getMultilibMacroDefinesStr(llvm::opt::ArgList &Args) const {
772 }
773
774 // GetRuntimeLibType - Determine the runtime library type to use with the
775 // given compilation arguments.
776 virtual RuntimeLibType
777 GetRuntimeLibType(const llvm::opt::ArgList &Args) const;
778
779 // GetCXXStdlibType - Determine the C++ standard library type to use with the
780 // given compilation arguments.
781 virtual CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const;
782
783 // GetCXXStdlibName - Determine the name of the C++ standard library to use
784 // with the given compilation arguments.
785 virtual StringRef GetCXXStdlibName(const llvm::opt::ArgList &Args) const;
786
787 // GetUnwindLibType - Determine the unwind library type to use with the
788 // given compilation arguments.
789 virtual UnwindLibType GetUnwindLibType(const llvm::opt::ArgList &Args) const;
790
791 // Determine the C standard library to use with the given
792 // compilation arguments. Defaults to CST_System when no --cstdlib= flag
793 // is provided.
794 virtual CStdlibType GetCStdlibType(const llvm::opt::ArgList &Args) const;
795
796 // Detect the highest available version of libc++ in include path.
797 virtual std::string detectLibcxxVersion(StringRef IncludePath) const;
798
799 /// AddClangCXXStdlibIncludeArgs - Add the clang -cc1 level arguments to set
800 /// the include paths to use for the given C++ standard library type.
801 virtual void
802 AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs,
803 llvm::opt::ArgStringList &CC1Args) const;
804
805 /// AddClangCXXStdlibIsystemArgs - Add the clang -cc1 level arguments to set
806 /// the specified include paths for the C++ standard library.
807 void AddClangCXXStdlibIsystemArgs(const llvm::opt::ArgList &DriverArgs,
808 llvm::opt::ArgStringList &CC1Args) const;
809
810 /// Returns if the C++ standard library should be linked in.
811 /// Note that e.g. -lm should still be linked even if this returns false.
812 bool ShouldLinkCXXStdlib(const llvm::opt::ArgList &Args) const;
813
814 /// AddCXXStdlibLibArgs - Add the system specific linker arguments to use
815 /// for the given C++ standard library type.
816 virtual void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
817 llvm::opt::ArgStringList &CmdArgs) const;
818
819 /// AddFilePathLibArgs - Add each thing in getFilePaths() as a "-L" option.
820 virtual void AddFilePathLibArgs(const llvm::opt::ArgList &Args,
821 llvm::opt::ArgStringList &CmdArgs) const;
822
823 /// AddCCKextLibArgs - Add the system specific linker arguments to use
824 /// for kernel extensions (Darwin-specific).
825 virtual void AddCCKextLibArgs(const llvm::opt::ArgList &Args,
826 llvm::opt::ArgStringList &CmdArgs) const;
827
828 /// If a runtime library exists that sets global flags for unsafe floating
829 /// point math, return true.
830 ///
831 /// This checks for presence of the -Ofast, -ffast-math or -funsafe-math flags.
832 virtual bool isFastMathRuntimeAvailable(
833 const llvm::opt::ArgList &Args, std::string &Path) const;
834
835 /// AddFastMathRuntimeIfAvailable - If a runtime library exists that sets
836 /// global flags for unsafe floating point math, add it and return true.
837 ///
838 /// This checks for presence of the -Ofast, -ffast-math or -funsafe-math flags.
840 const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const;
841
842 /// getSystemGPUArchs - Use a tool to detect the user's availible GPUs.
844 getSystemGPUArchs(const llvm::opt::ArgList &Args) const;
845
846 /// addProfileRTLibs - When -fprofile-instr-profile is specified, try to pass
847 /// a suitable profile runtime library to the linker.
848 virtual void addProfileRTLibs(const llvm::opt::ArgList &Args,
849 llvm::opt::ArgStringList &CmdArgs) const;
850
851 /// Add arguments to use system-specific CUDA includes.
852 virtual void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs,
853 llvm::opt::ArgStringList &CC1Args) const;
854
855 /// Add arguments to use system-specific HIP includes.
856 virtual void AddHIPIncludeArgs(const llvm::opt::ArgList &DriverArgs,
857 llvm::opt::ArgStringList &CC1Args) const;
858
859 /// Add arguments to use system-specific SYCL includes.
860 virtual void addSYCLIncludeArgs(const llvm::opt::ArgList &DriverArgs,
861 llvm::opt::ArgStringList &CC1Args) const;
862
863 /// Add arguments to use MCU GCC toolchain includes.
864 virtual void AddIAMCUIncludeArgs(const llvm::opt::ArgList &DriverArgs,
865 llvm::opt::ArgStringList &CC1Args) const;
866
867 /// On Windows, returns the MSVC compatibility version.
868 virtual VersionTuple computeMSVCVersion(const Driver *D,
869 const llvm::opt::ArgList &Args) const;
870
871 /// Get paths for device libraries.
873 getDeviceLibs(const llvm::opt::ArgList &Args, BoundArch BA,
874 const Action::OffloadKind DeviceOffloadingKind) const;
875
876 /// Add the system specific libraries for the active offload kinds.
877 virtual void addOffloadRTLibs(unsigned ActiveKinds,
878 const llvm::opt::ArgList &Args,
879 llvm::opt::ArgStringList &CmdArgs) const {}
880
881 /// Return sanitizers which are available in this toolchain.
882 virtual SanitizerMask
884 Action::OffloadKind DeviceOffloadKind) const;
885
886 /// Return sanitizers which are enabled by default.
888 return SanitizerMask();
889 }
890
891 /// Returns true when it's possible to split LTO unit to use whole
892 /// program devirtualization and CFI santiizers.
893 virtual bool canSplitThinLTOUnit() const { return true; }
894
895 /// Returns the output denormal handling type in the default floating point
896 /// environment for the given \p FPType if given. Otherwise, the default
897 /// assumed mode for any floating point type.
898 virtual llvm::DenormalMode getDefaultDenormalModeForType(
899 const llvm::opt::ArgList &DriverArgs, const JobAction &JA,
900 const llvm::fltSemantics *FPType = nullptr) const {
901 return llvm::DenormalMode::getIEEE();
902 }
903
904 // We want to expand the shortened versions of the triples passed in to
905 // the values used for the bitcode libraries.
906 static void normalizeOffloadTriple(llvm::Triple &TT) {
907 if (TT.isNVPTX()) {
908 if (TT.getVendor() == llvm::Triple::UnknownVendor)
909 TT.setVendor(llvm::Triple::NVIDIA);
910 if (TT.getOS() == llvm::Triple::UnknownOS)
911 TT.setOS(llvm::Triple::CUDA);
912 return;
913 }
914
915 if (TT.isAMDGCN()) {
916 // Fixup legacy "amdgcn" triples to "amdgpu"
917 TT.setArch(llvm::Triple::amdgpu, TT.getSubArch());
918 if (TT.getVendor() == llvm::Triple::UnknownVendor)
919 TT.setVendor(llvm::Triple::AMD);
920 if (TT.getOS() == llvm::Triple::UnknownOS)
921 TT.setOS(llvm::Triple::AMDHSA);
922 return;
923 }
924 }
925
926 static llvm::Triple normalizeOffloadTriple(llvm::StringRef OrigTT) {
927 llvm::Triple TT(OrigTT);
929 return TT;
930 }
931};
932
933/// Set a ToolChain's effective triple. Reset it when the registration object
934/// is destroyed.
936 const ToolChain &TC;
937
938public:
939 RegisterEffectiveTriple(const ToolChain &TC, llvm::Triple T) : TC(TC) {
940 TC.setEffectiveTriple(std::move(T));
941 }
942
943 ~RegisterEffectiveTriple() { TC.setEffectiveTriple(llvm::Triple()); }
944};
945
946} // namespace driver
947
948} // namespace clang
949
950#endif // LLVM_CLANG_DRIVER_TOOLCHAIN_H
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Defines the clang::LangOptions interface.
llvm::MachO::FileType FileType
Definition MachO.h:46
Defines the clang::SanitizerKind enum.
The basic abstraction for the target Objective-C runtime.
Definition ObjCRuntime.h:28
The base class of the type hierarchy.
Definition TypeBase.h:1879
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition Driver.h:93
InputInfo - Wrapper for information about an input source.
Definition InputInfo.h:22
See also MultilibSetBuilder for combining multilibs into a set.
Definition Multilib.h:129
std::vector< std::string > flags_list
Definition Multilib.h:37
RegisterEffectiveTriple(const ToolChain &TC, llvm::Triple T)
Definition ToolChain.h:939
ToolChain - Access to tools for a single platform.
Definition ToolChain.h:92
static void normalizeOffloadTriple(llvm::Triple &TT)
Definition ToolChain.h:906
virtual bool isFastMathRuntimeAvailable(const llvm::opt::ArgList &Args, std::string &Path) const
If a runtime library exists that sets global flags for unsafe floating point math,...
virtual std::string GetGlobalDebugPathRemapping() const
Add an additional -fdebug-prefix-map entry.
Definition ToolChain.h:655
virtual void AddCCKextLibArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const
AddCCKextLibArgs - Add the system specific linker arguments to use for kernel extensions (Darwin-spec...
virtual void addClangWarningOptions(llvm::opt::ArgStringList &CC1Args) const
Add warning options that need to be passed to cc1 for this target.
static void addSystemInclude(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, const Twine &Path)
Utility function to add a system include directory to CC1 arguments.
bool isUsingLTO(const llvm::opt::ArgList &Args, Action::OffloadKind Kind=Action::OFK_None) const
Returns true if LTO is active for this toolchain given the args.
virtual unsigned getMaxDwarfVersion() const
Definition ToolChain.h:664
virtual CStdlibType GetCStdlibType(const llvm::opt::ArgList &Args) const
virtual void adjustDebugInfoKind(llvm::codegenoptions::DebugInfoKind &DebugInfoKind, const llvm::opt::ArgList &Args) const
Adjust debug information kind considering all passed options.
Definition ToolChain.h:688
virtual std::string computeSysRoot() const
Return the sysroot, possibly searching for a default sysroot using target-specific logic.
virtual bool useIntegratedAs() const
Check if the toolchain should use the integrated assembler.
virtual llvm::DenormalMode getDefaultDenormalModeForType(const llvm::opt::ArgList &DriverArgs, const JobAction &JA, const llvm::fltSemantics *FPType=nullptr) const
Returns the output denormal handling type in the default floating point environment for the given FPT...
Definition ToolChain.h:898
const MultilibSet & getMultilibs() const
Definition ToolChain.h:328
virtual llvm::opt::DerivedArgList * TranslateOpenMPTargetArgs(const llvm::opt::DerivedArgList &Args, bool SameTripleAsHost, SmallVectorImpl< llvm::opt::Arg * > &AllocatedArgs) const
TranslateOpenMPTargetArgs - Create a new derived argument list for that contains the OpenMP target sp...
std::optional< std::string > getStdlibPath() const
virtual unsigned GetDefaultDwarfVersion() const
Definition ToolChain.h:659
virtual RuntimeLibType GetRuntimeLibType(const llvm::opt::ArgList &Args) const
virtual UnwindTableLevel getDefaultUnwindTableLevel(const llvm::opt::ArgList &Args) const
How detailed should the unwind tables be by default.
static llvm::Triple normalizeOffloadTriple(llvm::StringRef OrigTT)
Definition ToolChain.h:926
virtual llvm::SmallVector< BitCodeLibraryInfo, 12 > getDeviceLibs(const llvm::opt::ArgList &Args, BoundArch BA, const Action::OffloadKind DeviceOffloadingKind) const
Get paths for device libraries.
virtual LTOKind getDefaultLTOMode() const
Returns the default LTO mode for this toolchain.
bool ShouldLinkCXXStdlib(const llvm::opt::ArgList &Args) const
Returns if the C++ standard library should be linked in.
static void addSystemFrameworkIncludes(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, ArrayRef< StringRef > Paths)
Utility function to add a list of system framework directories to CC1.
static void addExternCSystemInclude(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, const Twine &Path)
Utility function to add a system include directory with extern "C" semantics to CC1 arguments.
virtual std::string getInputFilename(const InputInfo &Input) const
Some toolchains need to modify the file name, for example to replace the extension for object files w...
virtual Tool * buildStaticLibTool() const
virtual bool IsIntegratedBackendSupported() const
IsIntegratedBackendSupported - Does this tool chain support -fintegrated-objemitter.
Definition ToolChain.h:493
virtual void addFortranRuntimeLibraryPath(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const
Adds the path for the Fortran runtime libraries to CmdArgs.
std::optional< std::string > findMultilibsYAML(const llvm::opt::ArgList &Args, const Driver &D, StringRef FallbackDir={})
Load multilib configuration from a YAML file at MultilibPath,.
std::string GetFilePath(const char *Name) const
virtual void addFortranRuntimeLibs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const
Adds Fortran runtime libraries to CmdArgs.
virtual llvm::codegenoptions::DebugInfoFormat getDefaultDebugFormat() const
Get the default debug info format. Typically, this is DWARF.
Definition ToolChain.h:646
path_list & getFilePaths()
Definition ToolChain.h:322
virtual Tool * SelectTool(const JobAction &JA) const
Choose a tool to use to handle the action JA.
virtual bool supportsDebugInfoOption(const llvm::opt::Arg *) const
Does this toolchain supports given debug info option or not.
Definition ToolChain.h:682
static bool needsProfileRT(const llvm::opt::ArgList &Args)
needsProfileRT - returns true if instrumentation profile is on.
StringRef getOS() const
Definition ToolChain.h:301
virtual bool IsObjCNonFragileABIDefault() const
IsObjCNonFragileABIDefault - Does this tool chain set -fobjc-nonfragile-abi by default.
Definition ToolChain.h:518
virtual std::string ComputeEffectiveClangTriple(const llvm::opt::ArgList &Args, BoundArch BA={}, types::ID InputType=types::TY_INVALID) const
ComputeEffectiveClangTriple - Return the Clang triple to use for this target, which may take into acc...
virtual bool isBareMetal() const
isBareMetal - Is this a bare metal target.
Definition ToolChain.h:705
virtual bool isThreadModelSupported(const StringRef Model) const
isThreadModelSupported() - Does this target support a thread model?
virtual SanitizerMask getSupportedSanitizers(BoundArch BA, Action::OffloadKind DeviceOffloadKind) const
Return sanitizers which are available in this toolchain.
llvm::Triple::ArchType getArch() const
Definition ToolChain.h:298
const Driver & getDriver() const
Definition ToolChain.h:282
virtual std::string detectLibcxxVersion(StringRef IncludePath) const
static std::string concat(StringRef Path, const Twine &A, const Twine &B="", const Twine &C="", const Twine &D="")
RTTIMode getRTTIMode() const
Definition ToolChain.h:365
ExceptionsMode getExceptionsMode() const
Definition ToolChain.h:368
llvm::vfs::FileSystem & getVFS() const
Multilib::flags_list getMultilibFlags(const llvm::opt::ArgList &) const
Get flags suitable for multilib selection, based on the provided clang command line arguments.
static bool needsGCovInstrumentation(const llvm::opt::ArgList &Args)
Returns true if gcov instrumentation (-fprofile-arcs or –coverage) is on.
virtual void printVerboseInfo(raw_ostream &OS) const
Dispatch to the specific toolchain for verbose printing.
Definition ToolChain.h:453
const path_list & getProgramPaths() const
Definition ToolChain.h:326
bool loadMultilibsFromYAML(const llvm::opt::ArgList &Args, const Driver &D, StringRef Fallback={})
Discover and load a multilib.yaml configuration.
virtual std::string getCompilerRT(const llvm::opt::ArgList &Args, StringRef Component, FileType Type=ToolChain::FT_Static, bool IsFortran=false) const
ToolChain(const Driver &D, const llvm::Triple &T, const llvm::opt::ArgList &Args)
Definition ToolChain.cpp:92
virtual llvm::DebuggerKind getDefaultDebuggerTuning() const
Definition ToolChain.h:677
virtual bool isPIEDefault(const llvm::opt::ArgList &Args) const =0
Test whether this toolchain defaults to PIE.
virtual bool SupportsEmbeddedBitcode() const
SupportsEmbeddedBitcode - Does this tool chain support embedded bitcode.
Definition ToolChain.h:696
SmallVector< std::string > getMultilibMacroDefinesStr(llvm::opt::ArgList &Args) const
Get the list of extra macro defines requested by the multilib configuration.
Definition ToolChain.h:770
static void addSystemFrameworkInclude(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, const Twine &Path)
Utility function to add a system framework directory to CC1 arguments.
virtual bool isPICDefaultForced() const =0
Tests whether this toolchain forces its default for PIC, PIE or non-PIC.
virtual llvm::opt::DerivedArgList * TranslateArgs(const llvm::opt::DerivedArgList &Args, BoundArch BA, Action::OffloadKind DeviceOffloadKind) const
TranslateArgs - Create a new derived argument list for any argument translations this ToolChain may w...
Definition ToolChain.h:397
SmallVector< std::string > MultilibMacroDefines
Definition ToolChain.h:214
void AddClangCXXStdlibIsystemArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const
AddClangCXXStdlibIsystemArgs - Add the clang -cc1 level arguments to set the specified include paths ...
bool addFastMathRuntimeIfAvailable(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const
AddFastMathRuntimeIfAvailable - If a runtime library exists that sets global flags for unsafe floatin...
path_list & getProgramPaths()
Definition ToolChain.h:325
static void addExternCSystemIncludeIfExists(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, const Twine &Path)
const path_list & getFilePaths() const
Definition ToolChain.h:323
virtual LTOKind getLTOMode(const llvm::opt::ArgList &Args, Action::OffloadKind Kind=Action::OFK_None) const
Resolve the requested LTO mode for this toolchain.
bool hasEffectiveTriple() const
Definition ToolChain.h:315
virtual void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, BoundArch BA, Action::OffloadKind DeviceOffloadKind) const
Add options that need to be passed to cc1 for this target.
virtual bool useIntegratedBackend() const
Check if the toolchain should use the integrated backend.
const llvm::Triple & getEffectiveTriple() const
Get the toolchain's effective clang triple.
Definition ToolChain.h:310
virtual LangOptions::TrivialAutoVarInitKind GetDefaultTrivialAutoVarInit() const
Get the default trivial automatic variable initialization.
Definition ToolChain.h:539
std::string GetStaticLibToolPath() const
Returns the linker path for emitting a static library.
virtual llvm::ExceptionHandling GetExceptionModel(const llvm::opt::ArgList &Args) const
GetExceptionModel - Return the tool chain exception model.
virtual void addOffloadRTLibs(unsigned ActiveKinds, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const
Add the system specific libraries for the active offload kinds.
Definition ToolChain.h:877
virtual bool IsMathErrnoDefault() const
IsMathErrnoDefault - Does this tool chain use -fmath-errno by default.
Definition ToolChain.h:510
virtual void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const
AddCXXStdlibLibArgs - Add the system specific linker arguments to use for the given C++ standard libr...
static ParsedClangName getTargetAndModeFromProgramName(StringRef ProgName)
Return any implicit target and/or mode flag for an invocation of the compiler driver as ProgName.
virtual bool IsIntegratedBackendDefault() const
IsIntegratedBackendDefault - Does this tool chain enable -fintegrated-objemitter by default.
Definition ToolChain.h:489
virtual std::string getThreadModel() const
getThreadModel() - Which thread model does this target use?
Definition ToolChain.h:699
virtual const char * getDefaultLinker() const
GetDefaultLinker - Get the default linker to use.
Definition ToolChain.h:544
virtual bool GetDefaultStandaloneDebug() const
Definition ToolChain.h:670
virtual Tool * buildLinker() const
const llvm::opt::Arg * getRTTIArg() const
Definition ToolChain.h:362
const path_list & getLibraryPaths() const
Definition ToolChain.h:320
const llvm::Triple & getTriple() const
Definition ToolChain.h:284
bool defaultToIEEELongDouble() const
Check whether use IEEE binary128 as long double format by default.
virtual types::ID LookupTypeForExtension(StringRef Ext) const
LookupTypeForExtension - Return the default language type to use for the given extension.
virtual bool HasNativeLLVMSupport() const
HasNativeLTOLinker - Check whether the linker and related tools have native LLVM support.
const llvm::SmallVector< Multilib > & getSelectedMultilibs() const
Definition ToolChain.h:330
virtual UnwindLibType GetUnwindLibType(const llvm::opt::ArgList &Args) const
void addFlangRTLibPath(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const
Add the path for libflang_rt.runtime.a.
std::optional< std::string > getTargetSubDirPath(StringRef BaseDir) const
Find the target-specific subdirectory for the current target triple under BaseDir,...
virtual void addProfileRTLibs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const
addProfileRTLibs - When -fprofile-instr-profile is specified, try to pass a suitable profile runtime ...
virtual bool getDefaultDebugSimpleTemplateNames() const
Returns true if this toolchain adds '-gsimple-template-names=simple' by default when generating debug...
Definition ToolChain.h:674
const XRayArgs getXRayArgs(const llvm::opt::ArgList &) const
virtual void AddCudaIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const
Add arguments to use system-specific CUDA includes.
OrderedMultilibs getOrderedMultilibs() const
Get selected multilibs in priority order with default fallback.
llvm::iterator_range< llvm::SmallVector< Multilib >::const_reverse_iterator > OrderedMultilibs
Definition ToolChain.h:216
StringRef getTripleString() const
Definition ToolChain.h:307
virtual std::string getCompilerRTPath() const
llvm::Triple getTripleWithoutOSVersion() const
std::string GetLinkerPath(bool *LinkerIsLLD=nullptr) const
Returns the linker path, respecting the -fuse-ld= argument to determine the linker suffix or name.
virtual std::string buildCompilerRTBasename(const llvm::opt::ArgList &Args, StringRef Component, FileType Type, bool AddArch, bool IsFortran=false) const
virtual Expected< SmallVector< std::string > > getSystemGPUArchs(const llvm::opt::ArgList &Args) const
getSystemGPUArchs - Use a tool to detect the user's availible GPUs.
virtual std::string ComputeLLVMTriple(const llvm::opt::ArgList &Args, BoundArch BA={}, types::ID InputType=types::TY_INVALID) const
ComputeLLVMTriple - Return the LLVM target triple to use, after taking command line arguments into ac...
std::string GetProgramPath(const char *Name) const
virtual LangOptions::StackProtectorMode GetDefaultStackProtectorLevel(bool KernelOrKext) const
GetDefaultStackProtectorLevel - Get the default stack protector level for this tool chain.
Definition ToolChain.h:533
virtual bool hasBlocksRuntime() const
hasBlocksRuntime - Given that the user is compiling with -fblocks, does this tool chain guarantee the...
Definition ToolChain.h:739
virtual bool UseDwarfDebugFlags() const
UseDwarfDebugFlags - Embed the compile options to clang into the Dwarf compile unit information.
Definition ToolChain.h:652
static void addSystemIncludes(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, ArrayRef< StringRef > Paths)
Utility function to add a list of system include directories to CC1.
virtual bool SupportsProfiling() const
SupportsProfiling - Does this tool chain support -pg.
Definition ToolChain.h:640
virtual void AddHIPIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const
Add arguments to use system-specific HIP includes.
virtual bool canSplitThinLTOUnit() const
Returns true when it's possible to split LTO unit to use whole program devirtualization and CFI santi...
Definition ToolChain.h:893
virtual void AddClangCXXStdlibIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const
AddClangCXXStdlibIncludeArgs - Add the clang -cc1 level arguments to set the include paths to use for...
virtual VersionTuple computeMSVCVersion(const Driver *D, const llvm::opt::ArgList &Args) const
On Windows, returns the MSVC compatibility version.
virtual void addSYCLIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const
Add arguments to use system-specific SYCL includes.
virtual StringRef getOSLibName() const
virtual bool UseObjCMixedDispatch() const
UseObjCMixedDispatchDefault - When using non-legacy dispatch, should the mixed dispatch method be use...
Definition ToolChain.h:522
virtual void AddIAMCUIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const
Add arguments to use MCU GCC toolchain includes.
virtual CXXStdlibType GetDefaultCXXStdlibType() const
Definition ToolChain.h:551
std::optional< std::string > getStdlibIncludePath() const
virtual void AddFilePathLibArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const
AddFilePathLibArgs - Add each thing in getFilePaths() as a "-L" option.
virtual RuntimeLibType GetDefaultRuntimeLibType() const
GetDefaultRuntimeLibType - Get the default runtime library variant to use.
Definition ToolChain.h:547
StringRef getDefaultUniversalArchName() const
Provide the default architecture name (as expected by -arch) for this toolchain.
virtual Tool * buildAssembler() const
virtual StringRef GetCXXStdlibName(const llvm::opt::ArgList &Args) const
void setTripleEnvironment(llvm::Triple::EnvironmentType Env)
virtual void addClangCC1ASTargetOptions(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CC1ASArgs) const
Add options that need to be passed to cc1as for this target.
virtual bool IsIntegratedAssemblerDefault() const
IsIntegratedAssemblerDefault - Does this tool chain enable -integrated-as by default.
Definition ToolChain.h:485
virtual CXXStdlibType GetCXXStdlibType(const llvm::opt::ArgList &Args) const
llvm::SmallVector< Multilib > SelectedMultilibs
Definition ToolChain.h:213
virtual void CheckObjCARC() const
Complain if this tool chain doesn't support Objective-C ARC.
Definition ToolChain.h:643
virtual bool IsAArch64OutlineAtomicsDefault(const llvm::opt::ArgList &Args) const
Test whether this toolchain supports outline atomics by default.
Definition ToolChain.h:623
SanitizerArgs getSanitizerArgs(const llvm::opt::ArgList &JobArgs, BoundArch BA={}, Action::OffloadKind DeviceOffloadKind=Action::OFK_None) const
path_list & getLibraryPaths()
Definition ToolChain.h:319
virtual void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const
Add the clang cc1 arguments for system include paths.
virtual UnwindLibType GetDefaultUnwindLibType() const
Definition ToolChain.h:555
std::optional< std::string > getRuntimePath() const
virtual Tool * getTool(Action::ActionClass AC) const
virtual bool IsEncodeExtendedBlockSignatureDefault() const
IsEncodeExtendedBlockSignatureDefault - Does this tool chain enable -fencode-extended-block-signature...
Definition ToolChain.h:514
StringRef getPlatform() const
Definition ToolChain.h:300
virtual StringRef getSanitizerRequirement(SanitizerMask Kinds, BoundArch BA) const
Returns the feature requirement for a sanitizer on a specific arch for diagnostic purposes.
Definition ToolChain.h:354
const char * getCompilerRTArgString(const llvm::opt::ArgList &Args, StringRef Component, FileType Type=ToolChain::FT_Static, bool IsFortran=false) const
virtual bool IsBlocksDefault() const
IsBlocksDefault - Does this tool chain enable -fblocks by default.
Definition ToolChain.h:481
friend class RegisterEffectiveTriple
Definition ToolChain.h:145
virtual path_list getArchSpecificLibPaths() const
virtual std::string getMultiarchTriple(const Driver &D, const llvm::Triple &TargetTriple, StringRef SysRoot) const
Definition ToolChain.h:707
std::optional< std::string > GetFilePathIfExists(const char *Name) const
virtual bool isCrossCompiling() const
Returns true if the toolchain is targeting a non-native architecture.
std::string getCompilerRTBasename(const llvm::opt::ArgList &Args, StringRef Component, FileType Type=ToolChain::FT_Static) const
virtual bool IsNonIntegratedBackendSupported() const
IsNonIntegratedBackendSupported - Does this tool chain support -fno-integrated-objemitter.
Definition ToolChain.h:497
std::optional< std::string > getDefaultIntrinsicModuleDir() const
Returns the target-specific path for Flang's intrinsic modules in the resource directory if it exists...
virtual const llvm::Triple * getAuxTriple() const
Get the toolchain's aux triple, if it has one.
Definition ToolChain.h:291
virtual SanitizerMask getDefaultSanitizers() const
Return sanitizers which are enabled by default.
Definition ToolChain.h:887
virtual void TranslateXarchArgs(const llvm::opt::DerivedArgList &Args, llvm::opt::Arg *&A, llvm::opt::DerivedArgList *DAL, SmallVectorImpl< llvm::opt::Arg * > *AllocatedArgs=nullptr) const
Append the argument following A to DAL assuming A is an Xarch argument.
virtual bool useRelaxRelocations() const
Check whether to enable x86 relax relocations by default.
virtual bool isPICDefault() const =0
Test whether this toolchain defaults to PIC.
StringRef getArchName() const
Definition ToolChain.h:299
virtual bool parseInlineAsmUsingAsmParser() const
Check if the toolchain should use AsmParser to parse inlineAsm when integrated assembler is not defau...
Definition ToolChain.h:507
SmallVector< std::string, 16 > path_list
Definition ToolChain.h:94
virtual ObjCRuntime getDefaultObjCRuntime(bool isNonFragile) const
getDefaultObjCRuntime - Return the default Objective-C runtime for this platform.
Tool - Information on a specific compilation tool.
Definition Tool.h:32
#define UINT_MAX
Definition limits.h:64
LTOKind
Describes the kind of LTO mode selected via -f(no-)?lto(=.*)? options.
Definition Driver.h:57
Top level wrappers for InstallAPI frontend operations.
const FunctionProtoType * T
Diagnostic wrappers for TextAPI types for error reporting.
Definition Dominators.h:30
Represents a bound architecture for offload / multiple architecture compilation.
Helper structure used to pass information extracted from clang executable name such as i686-linux-and...
Definition ToolChain.h:65
ParsedClangName(std::string Suffix, const char *Mode)
Definition ToolChain.h:79
const char * DriverMode
Corresponding driver mode argument, as '–driver-mode=g++'.
Definition ToolChain.h:73
std::string ModeSuffix
Driver mode part of the executable name, as g++.
Definition ToolChain.h:70
std::string TargetPrefix
Target part of the executable name, as i686-linux-android.
Definition ToolChain.h:67
bool TargetIsValid
True if TargetPrefix is recognized as a registered target name.
Definition ToolChain.h:76
ParsedClangName(std::string Target, std::string Suffix, const char *Mode, bool IsRegistered)
Definition ToolChain.h:81
BitCodeLibraryInfo(StringRef Path, bool ShouldInternalize=true)
Definition ToolChain.h:138