1 //===--- AMDGPU.h - AMDGPU ToolChain Implementations ----------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_AMDGPU_H
10 #define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_AMDGPU_H
14 #include "clang/Basic/TargetID.h"
15 #include "clang/Driver/Options.h"
16 #include "clang/Driver/Tool.h"
17 #include "clang/Driver/ToolChain.h"
18 #include "llvm/ADT/SmallString.h"
19 #include "llvm/Support/TargetParser.h"
29 class LLVM_LIBRARY_VISIBILITY Linker
: public Tool
{
31 Linker(const ToolChain
&TC
) : Tool("amdgpu::Linker", "ld.lld", TC
) {}
32 bool isLinkJob() const override
{ return true; }
33 bool hasIntegratedCPP() const override
{ return false; }
34 void ConstructJob(Compilation
&C
, const JobAction
&JA
,
35 const InputInfo
&Output
, const InputInfoList
&Inputs
,
36 const llvm::opt::ArgList
&TCArgs
,
37 const char *LinkingOutput
) const override
;
40 void getAMDGPUTargetFeatures(const Driver
&D
, const llvm::Triple
&Triple
,
41 const llvm::opt::ArgList
&Args
,
42 std::vector
<StringRef
> &Features
);
44 } // end namespace amdgpu
45 } // end namespace tools
47 namespace toolchains
{
49 class LLVM_LIBRARY_VISIBILITY AMDGPUToolChain
: public Generic_ELF
{
51 const std::map
<options::ID
, const StringRef
> OptionsDefault
;
53 Tool
*buildLinker() const override
;
54 StringRef
getOptionDefault(options::ID OptID
) const {
55 auto opt
= OptionsDefault
.find(OptID
);
56 assert(opt
!= OptionsDefault
.end() && "No Default for Option");
61 AMDGPUToolChain(const Driver
&D
, const llvm::Triple
&Triple
,
62 const llvm::opt::ArgList
&Args
);
63 unsigned GetDefaultDwarfVersion() const override
{ return 5; }
64 bool IsIntegratedAssemblerDefault() const override
{ return true; }
65 bool IsMathErrnoDefault() const override
{ return false; }
67 bool useIntegratedAs() const override
{ return true; }
68 bool isCrossCompiling() const override
{ return true; }
69 bool isPICDefault() const override
{ return false; }
70 bool isPIEDefault(const llvm::opt::ArgList
&Args
) const override
{
73 bool isPICDefaultForced() const override
{ return false; }
74 bool SupportsProfiling() const override
{ return false; }
76 llvm::opt::DerivedArgList
*
77 TranslateArgs(const llvm::opt::DerivedArgList
&Args
, StringRef BoundArch
,
78 Action::OffloadKind DeviceOffloadKind
) const override
;
80 void addClangTargetOptions(const llvm::opt::ArgList
&DriverArgs
,
81 llvm::opt::ArgStringList
&CC1Args
,
82 Action::OffloadKind DeviceOffloadKind
) const override
;
84 /// Return whether denormals should be flushed, and treated as 0 by default
85 /// for the subtarget.
86 static bool getDefaultDenormsAreZeroForTarget(llvm::AMDGPU::GPUKind GPUKind
);
88 llvm::DenormalMode
getDefaultDenormalModeForType(
89 const llvm::opt::ArgList
&DriverArgs
, const JobAction
&JA
,
90 const llvm::fltSemantics
*FPType
= nullptr) const override
;
92 static bool isWave64(const llvm::opt::ArgList
&DriverArgs
,
93 llvm::AMDGPU::GPUKind Kind
);
94 /// Needed for using lto.
95 bool HasNativeLLVMSupport() const override
{
99 /// Needed for translating LTO options.
100 const char *getDefaultLinker() const override
{ return "ld.lld"; }
102 /// Should skip argument.
103 bool shouldSkipArgument(const llvm::opt::Arg
*Arg
) const;
105 /// Uses amdgpu_arch tool to get arch of the system GPU. Will return error
106 /// if unable to find one.
107 llvm::Error
getSystemGPUArch(const llvm::opt::ArgList
&Args
,
108 std::string
&GPUArch
) const;
111 /// Check and diagnose invalid target ID specified by -mcpu.
112 virtual void checkTargetID(const llvm::opt::ArgList
&DriverArgs
) const;
114 /// The struct type returned by getParsedTargetID.
115 struct ParsedTargetIDType
{
116 Optional
<std::string
> OptionalTargetID
;
117 Optional
<std::string
> OptionalGPUArch
;
118 Optional
<llvm::StringMap
<bool>> OptionalFeatures
;
121 /// Get target ID, GPU arch, and target ID features if the target ID is
122 /// specified and valid.
124 getParsedTargetID(const llvm::opt::ArgList
&DriverArgs
) const;
126 /// Get GPU arch from -mcpu without checking.
127 StringRef
getGPUArch(const llvm::opt::ArgList
&DriverArgs
) const;
129 llvm::Error
detectSystemGPUs(const llvm::opt::ArgList
&Args
,
130 SmallVector
<std::string
, 1> &GPUArchs
) const;
133 class LLVM_LIBRARY_VISIBILITY ROCMToolChain
: public AMDGPUToolChain
{
135 ROCMToolChain(const Driver
&D
, const llvm::Triple
&Triple
,
136 const llvm::opt::ArgList
&Args
);
138 addClangTargetOptions(const llvm::opt::ArgList
&DriverArgs
,
139 llvm::opt::ArgStringList
&CC1Args
,
140 Action::OffloadKind DeviceOffloadKind
) const override
;
142 // Returns a list of device library names shared by different languages
143 llvm::SmallVector
<std::string
, 12>
144 getCommonDeviceLibNames(const llvm::opt::ArgList
&DriverArgs
,
145 const std::string
&GPUArch
,
146 bool isOpenMP
= false) const;
149 } // end namespace toolchains
150 } // end namespace driver
151 } // end namespace clang
153 #endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_AMDGPU_H