clang 20.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"
16#include "clang/Driver/Tool.h"
18#include "llvm/ADT/SmallString.h"
19#include "llvm/TargetParser/TargetParser.h"
20
21#include <map>
22
23namespace clang {
24namespace driver {
25
26namespace tools {
27namespace amdgpu {
28
29class LLVM_LIBRARY_VISIBILITY Linker final : public Tool {
30public:
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
40void 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
47namespace toolchains {
48
49class LLVM_LIBRARY_VISIBILITY AMDGPUToolChain : public Generic_ELF {
50protected:
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
60public:
61 AMDGPUToolChain(const Driver &D, const llvm::Triple &Triple,
62 const llvm::opt::ArgList &Args);
63 unsigned GetDefaultDwarfVersion() const override { return 5; }
64
65 bool IsMathErrnoDefault() const override { return false; }
66 bool isCrossCompiling() const override { return true; }
67 bool isPICDefault() const override { return true; }
68 bool isPIEDefault(const llvm::opt::ArgList &Args) const override {
69 return false;
70 }
71 bool isPICDefaultForced() const override { return true; }
72 bool SupportsProfiling() const override { return false; }
73
74 llvm::opt::DerivedArgList *
75 TranslateArgs(const llvm::opt::DerivedArgList &Args, StringRef BoundArch,
76 Action::OffloadKind DeviceOffloadKind) const override;
77
78 void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
79 llvm::opt::ArgStringList &CC1Args,
80 Action::OffloadKind DeviceOffloadKind) const override;
81
82 /// Return whether denormals should be flushed, and treated as 0 by default
83 /// for the subtarget.
84 static bool getDefaultDenormsAreZeroForTarget(llvm::AMDGPU::GPUKind GPUKind);
85
86 llvm::DenormalMode getDefaultDenormalModeForType(
87 const llvm::opt::ArgList &DriverArgs, const JobAction &JA,
88 const llvm::fltSemantics *FPType = nullptr) const override;
89
90 static bool isWave64(const llvm::opt::ArgList &DriverArgs,
91 llvm::AMDGPU::GPUKind Kind);
92 /// Needed for using lto.
93 bool HasNativeLLVMSupport() const override {
94 return true;
95 }
96
97 /// Needed for translating LTO options.
98 const char *getDefaultLinker() const override { return "ld.lld"; }
99
100 /// Should skip sanitize options.
101 bool shouldSkipSanitizeOption(const ToolChain &TC,
102 const llvm::opt::ArgList &DriverArgs,
103 StringRef TargetID,
104 const llvm::opt::Arg *A) const;
105
106 /// Uses amdgpu-arch tool to get arch of the system GPU. Will return error
107 /// if unable to find one.
109 getSystemGPUArchs(const llvm::opt::ArgList &Args) const override;
110
111protected:
112 /// Check and diagnose invalid target ID specified by -mcpu.
113 virtual void checkTargetID(const llvm::opt::ArgList &DriverArgs) const;
114
115 /// The struct type returned by getParsedTargetID.
117 std::optional<std::string> OptionalTargetID;
118 std::optional<std::string> OptionalGPUArch;
119 std::optional<llvm::StringMap<bool>> OptionalFeatures;
120 };
121
122 /// Get target ID, GPU arch, and target ID features if the target ID is
123 /// specified and valid.
125 getParsedTargetID(const llvm::opt::ArgList &DriverArgs) const;
126
127 /// Get GPU arch from -mcpu without checking.
128 StringRef getGPUArch(const llvm::opt::ArgList &DriverArgs) const;
129
130 /// Common warning options shared by AMDGPU HIP, OpenCL and OpenMP toolchains.
131 /// Language specific warning options should go to derived classes.
132 void addClangWarningOptions(llvm::opt::ArgStringList &CC1Args) const override;
133};
134
135class LLVM_LIBRARY_VISIBILITY ROCMToolChain : public AMDGPUToolChain {
136public:
137 ROCMToolChain(const Driver &D, const llvm::Triple &Triple,
138 const llvm::opt::ArgList &Args);
139 void
140 addClangTargetOptions(const llvm::opt::ArgList &DriverArgs,
141 llvm::opt::ArgStringList &CC1Args,
142 Action::OffloadKind DeviceOffloadKind) const override;
143
144 // Returns a list of device library names shared by different languages
146 getCommonDeviceLibNames(const llvm::opt::ArgList &DriverArgs,
147 const std::string &GPUArch,
148 bool isOpenMP = false) const;
150 return SanitizerKind::Address;
151 }
152};
153
154} // end namespace toolchains
155} // end namespace driver
156} // end namespace clang
157
158#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_AMDGPU_H
const Decl * D
enum clang::sema::@1712::IndirectLocalPathEntry::EntryKind Kind
Compilation - A set of tasks to perform for a single driver invocation.
Definition: Compilation.h:45
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:77
InputInfo - Wrapper for information about an input source.
Definition: InputInfo.h:22
ToolChain - Access to tools for a single platform.
Definition: ToolChain.h:92
Tool - Information on a specific compilation tool.
Definition: Tool.h:32
bool isPIEDefault(const llvm::opt::ArgList &Args) const override
Test whether this toolchain defaults to PIE.
Definition: AMDGPU.h:68
bool isPICDefault() const override
Test whether this toolchain defaults to PIC.
Definition: AMDGPU.h:67
bool SupportsProfiling() const override
SupportsProfiling - Does this tool chain support -pg.
Definition: AMDGPU.h:72
bool HasNativeLLVMSupport() const override
Needed for using lto.
Definition: AMDGPU.h:93
bool IsMathErrnoDefault() const override
IsMathErrnoDefault - Does this tool chain use -fmath-errno by default.
Definition: AMDGPU.h:65
unsigned GetDefaultDwarfVersion() const override
Definition: AMDGPU.h:63
const std::map< options::ID, const StringRef > OptionsDefault
Definition: AMDGPU.h:51
bool isPICDefaultForced() const override
Tests whether this toolchain forces its default for PIC, PIE or non-PIC.
Definition: AMDGPU.h:71
const char * getDefaultLinker() const override
Needed for translating LTO options.
Definition: AMDGPU.h:98
StringRef getOptionDefault(options::ID OptID) const
Definition: AMDGPU.h:54
bool isCrossCompiling() const override
Returns true if the toolchain is targeting a non-native architecture.
Definition: AMDGPU.h:66
SanitizerMask getSupportedSanitizers() const override
Return sanitizers which are available in this toolchain.
Definition: AMDGPU.h:149
Linker(const ToolChain &TC)
Definition: AMDGPU.h:31
bool hasIntegratedCPP() const override
Definition: AMDGPU.h:33
bool isLinkJob() const override
Definition: AMDGPU.h:32
void getAMDGPUTargetFeatures(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args, std::vector< StringRef > &Features)
Definition: AMDGPU.cpp:669
The JSON file list parser is used to communicate input to InstallAPI.
The struct type returned by getParsedTargetID.
Definition: AMDGPU.h:116
std::optional< llvm::StringMap< bool > > OptionalFeatures
Definition: AMDGPU.h:119