clang  14.0.0git
AMDGPU.h
Go to the documentation of this file.
1 //===--- AMDGPU.h - AMDGPU ToolChain Implementations ----------*- 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_LIB_DRIVER_TOOLCHAINS_AMDGPU_H
10 #define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_AMDGPU_H
11 
12 #include "Gnu.h"
13 #include "ROCm.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"
20 
21 #include <map>
22 
23 namespace clang {
24 namespace driver {
25 
26 namespace tools {
27 namespace amdgpu {
28 
29 class LLVM_LIBRARY_VISIBILITY Linker : public Tool {
30 public:
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;
38 };
39 
40 void getAMDGPUTargetFeatures(const Driver &D, const llvm::Triple &Triple,
41  const llvm::opt::ArgList &Args,
42  std::vector<StringRef> &Features);
43 
44 } // end namespace amdgpu
45 } // end namespace tools
46 
47 namespace toolchains {
48 
49 class LLVM_LIBRARY_VISIBILITY AMDGPUToolChain : public Generic_ELF {
50 protected:
51  const std::map<options::ID, const StringRef> OptionsDefault;
52 
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");
57  return opt->second;
58  }
59 
60 public:
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; }
66 
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 {
71  return false;
72  }
73  bool isPICDefaultForced() const override { return false; }
74  bool SupportsProfiling() const override { return false; }
75 
76  llvm::opt::DerivedArgList *
77  TranslateArgs(const llvm::opt::DerivedArgList &Args, StringRef BoundArch,
78  Action::OffloadKind DeviceOffloadKind) const override;
79 
80  void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
81  llvm::opt::ArgStringList &CC1Args,
82  Action::OffloadKind DeviceOffloadKind) const override;
83 
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);
87 
88  llvm::DenormalMode getDefaultDenormalModeForType(
89  const llvm::opt::ArgList &DriverArgs, const JobAction &JA,
90  const llvm::fltSemantics *FPType = nullptr) const override;
91 
92  static bool isWave64(const llvm::opt::ArgList &DriverArgs,
93  llvm::AMDGPU::GPUKind Kind);
94  /// Needed for using lto.
95  bool HasNativeLLVMSupport() const override {
96  return true;
97  }
98 
99  /// Needed for translating LTO options.
100  const char *getDefaultLinker() const override { return "ld.lld"; }
101 
102  /// Should skip argument.
103  bool shouldSkipArgument(const llvm::opt::Arg *Arg) const;
104 
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;
109 
110 protected:
111  /// Check and diagnose invalid target ID specified by -mcpu.
112  virtual void checkTargetID(const llvm::opt::ArgList &DriverArgs) const;
113 
114  /// The struct type returned by getParsedTargetID.
119  };
120 
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;
125 
126  /// Get GPU arch from -mcpu without checking.
127  StringRef getGPUArch(const llvm::opt::ArgList &DriverArgs) const;
128 
129  llvm::Error detectSystemGPUs(const llvm::opt::ArgList &Args,
130  SmallVector<std::string, 1> &GPUArchs) const;
131 };
132 
133 class LLVM_LIBRARY_VISIBILITY ROCMToolChain : public AMDGPUToolChain {
134 public:
135  ROCMToolChain(const Driver &D, const llvm::Triple &Triple,
136  const llvm::opt::ArgList &Args);
137  void
138  addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
139  llvm::opt::ArgStringList &CC1Args,
140  Action::OffloadKind DeviceOffloadKind) const override;
141 
142  // Returns a list of device library names shared by different languages
144  getCommonDeviceLibNames(const llvm::opt::ArgList &DriverArgs,
145  const std::string &GPUArch) const;
146 };
147 
148 } // end namespace toolchains
149 } // end namespace driver
150 } // end namespace clang
151 
152 #endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_AMDGPU_H
clang::driver::toolchains::AMDGPUToolChain::OptionsDefault
const std::map< options::ID, const StringRef > OptionsDefault
Definition: AMDGPU.h:51
clang::driver::toolchains::AMDGPUToolChain::IsIntegratedAssemblerDefault
bool IsIntegratedAssemblerDefault() const override
IsIntegratedAssemblerDefault - Does this tool chain enable -integrated-as by default.
Definition: AMDGPU.h:64
clang::driver::toolchains::AMDGPUToolChain::ParsedTargetIDType
The struct type returned by getParsedTargetID.
Definition: AMDGPU.h:115
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::driver::tools::amdgpu::Linker::isLinkJob
bool isLinkJob() const override
Definition: AMDGPU.h:32
llvm::SmallVector
Definition: LLVM.h:38
clang::driver::toolchains::AMDGPUToolChain::getDefaultLinker
const char * getDefaultLinker() const override
Needed for translating LTO options.
Definition: AMDGPU.h:100
clang::driver::toolchains::AMDGPUToolChain::SupportsProfiling
bool SupportsProfiling() const override
SupportsProfiling - Does this tool chain support -pg.
Definition: AMDGPU.h:74
llvm::Optional< std::string >
clang::driver::InputInfo
InputInfo - Wrapper for information about an input source.
Definition: InputInfo.h:22
clang::driver::Tool
Tool - Information on a specific compilation tool.
Definition: Tool.h:32
clang::driver::toolchains::Generic_ELF
Definition: Gnu.h:362
Options.h
clang::driver::options::ID
ID
Definition: Options.h:41
clang::driver::tools::amdgpu::Linker::Linker
Linker(const ToolChain &TC)
Definition: AMDGPU.h:31
clang::driver::toolchains::AMDGPUToolChain::useIntegratedAs
bool useIntegratedAs() const override
Check if the toolchain should use the integrated assembler.
Definition: AMDGPU.h:67
Tool.h
clang::driver::toolchains::AMDGPUToolChain::getOptionDefault
StringRef getOptionDefault(options::ID OptID) const
Definition: AMDGPU.h:54
TargetID.h
clang::driver::toolchains::AMDGPUToolChain::isPICDefaultForced
bool isPICDefaultForced() const override
Tests whether this toolchain forces its default for PIC, PIE or non-PIC.
Definition: AMDGPU.h:73
clang::driver::tools::amdgpu::Linker::hasIntegratedCPP
bool hasIntegratedCPP() const override
Definition: AMDGPU.h:33
clang::driver::toolchains::AMDGPUToolChain::isPIEDefault
bool isPIEDefault(const llvm::opt::ArgList &Args) const override
Test whether this toolchain defaults to PIE.
Definition: AMDGPU.h:70
clang::driver::toolchains::AMDGPUToolChain::HasNativeLLVMSupport
bool HasNativeLLVMSupport() const override
Needed for using lto.
Definition: AMDGPU.h:95
ToolChain.h
clang::driver::toolchains::AMDGPUToolChain::ParsedTargetIDType::OptionalGPUArch
Optional< std::string > OptionalGPUArch
Definition: AMDGPU.h:117
ROCm.h
Gnu.h
clang::driver::ToolChain
ToolChain - Access to tools for a single platform.
Definition: ToolChain.h:91
clang::driver::toolchains::AMDGPUToolChain::isPICDefault
bool isPICDefault() const override
Test whether this toolchain defaults to PIC.
Definition: AMDGPU.h:69
clang::driver::Compilation
Compilation - A set of tasks to perform for a single driver invocation.
Definition: Compilation.h:45
clang::ObjCPropertyAttribute::Kind
Kind
Definition: DeclObjCCommon.h:22
clang::driver::tools::amdgpu::getAMDGPUTargetFeatures
void getAMDGPUTargetFeatures(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args, std::vector< StringRef > &Features)
Definition: AMDGPU.cpp:536
clang
Definition: CalledOnceCheck.h:17
clang::driver::Driver
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:59
clang::driver::toolchains::AMDGPUToolChain::ParsedTargetIDType::OptionalTargetID
Optional< std::string > OptionalTargetID
Definition: AMDGPU.h:116
clang::driver::tools::amdgpu::Linker
Definition: AMDGPU.h:29
clang::driver::toolchains::ROCMToolChain
Definition: AMDGPU.h:133
clang::driver::toolchains::AMDGPUToolChain::isCrossCompiling
bool isCrossCompiling() const override
Returns true if the toolchain is targeting a non-native architecture.
Definition: AMDGPU.h:68
clang::driver::Action::OffloadKind
OffloadKind
Definition: Action.h:85
clang::driver::toolchains::AMDGPUToolChain::ParsedTargetIDType::OptionalFeatures
Optional< llvm::StringMap< bool > > OptionalFeatures
Definition: AMDGPU.h:118
clang::driver::JobAction
Definition: Action.h:380
clang::driver::toolchains::AMDGPUToolChain::GetDefaultDwarfVersion
unsigned GetDefaultDwarfVersion() const override
Definition: AMDGPU.h:63
clang::driver::toolchains::AMDGPUToolChain
Definition: AMDGPU.h:49
clang::driver::toolchains::AMDGPUToolChain::IsMathErrnoDefault
bool IsMathErrnoDefault() const override
IsMathErrnoDefault - Does this tool chain use -fmath-errno by default.
Definition: AMDGPU.h:65