clang 20.0.0git
SPIR.cpp
Go to the documentation of this file.
1//===--- SPIR.cpp - Implement SPIR and SPIR-V target feature support ------===//
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// This file implements SPIR and SPIR-V TargetInfo objects.
10//
11//===----------------------------------------------------------------------===//
12
13#include "SPIR.h"
14#include "AMDGPU.h"
15#include "Targets.h"
18#include "llvm/TargetParser/TargetParser.h"
19
20using namespace clang;
21using namespace clang::targets;
22
23static constexpr Builtin::Info BuiltinInfo[] = {
24#define BUILTIN(ID, TYPE, ATTRS) \
25 {#ID, TYPE, ATTRS, nullptr, HeaderDesc::NO_HEADER, ALL_LANGUAGES},
26#include "clang/Basic/BuiltinsSPIRV.inc"
27};
28
32}
33
35 MacroBuilder &Builder) const {
36 DefineStd(Builder, "SPIR", Opts);
37}
38
40 MacroBuilder &Builder) const {
42 DefineStd(Builder, "SPIR32", Opts);
43}
44
46 MacroBuilder &Builder) const {
48 DefineStd(Builder, "SPIR64", Opts);
49}
50
52 MacroBuilder &Builder) const {
53 DefineStd(Builder, "SPIRV", Opts);
54}
55
57 MacroBuilder &Builder) const {
59}
60
62 MacroBuilder &Builder) const {
64 DefineStd(Builder, "SPIRV32", Opts);
65}
66
68 MacroBuilder &Builder) const {
70 DefineStd(Builder, "SPIRV64", Opts);
71}
72
73static const AMDGPUTargetInfo AMDGPUTI(llvm::Triple("amdgcn-amd-amdhsa"), {});
74
76 return AMDGPUTI.getGCCRegNames();
77}
78
80 llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags, StringRef,
81 const std::vector<std::string> &FeatureVec) const {
82 llvm::AMDGPU::fillAMDGPUFeatureMap({}, getTriple(), Features);
83
84 return TargetInfo::initFeatureMap(Features, Diags, {}, FeatureVec);
85}
86
88 const char *&Name, TargetInfo::ConstraintInfo &Info) const {
89 return AMDGPUTI.validateAsmConstraint(Name, Info);
90}
91
92std::string
93SPIRV64AMDGCNTargetInfo::convertConstraint(const char *&Constraint) const {
94 return AMDGPUTI.convertConstraint(Constraint);
95}
96
99}
100
102 MacroBuilder &Builder) const {
104 DefineStd(Builder, "SPIRV64", Opts);
105
106 Builder.defineMacro("__AMD__");
107 Builder.defineMacro("__AMDGPU__");
108 Builder.defineMacro("__AMDGCN__");
109}
110
112 assert(Aux && "Cannot invoke setAuxTarget without a valid auxiliary target!");
113
114 // This is a 1:1 copy of AMDGPUTargetInfo::setAuxTarget()
115 assert(HalfFormat == Aux->HalfFormat);
116 assert(FloatFormat == Aux->FloatFormat);
117 assert(DoubleFormat == Aux->DoubleFormat);
118
119 // On x86_64 long double is 80-bit extended precision format, which is
120 // not supported by AMDGPU. 128-bit floating point format is also not
121 // supported by AMDGPU. Therefore keep its own format for these two types.
122 auto SaveLongDoubleFormat = LongDoubleFormat;
123 auto SaveFloat128Format = Float128Format;
124 auto SaveLongDoubleWidth = LongDoubleWidth;
125 auto SaveLongDoubleAlign = LongDoubleAlign;
126 copyAuxTarget(Aux);
127 LongDoubleFormat = SaveLongDoubleFormat;
128 Float128Format = SaveFloat128Format;
129 LongDoubleWidth = SaveLongDoubleWidth;
130 LongDoubleAlign = SaveLongDoubleAlign;
131 // For certain builtin types support on the host target, claim they are
132 // supported to pass the compilation of the host code during the device-side
133 // compilation.
134 // FIXME: As the side effect, we also accept `__float128` uses in the device
135 // code. To reject these builtin types supported in the host target but not in
136 // the device target, one approach would support `device_builtin` attribute
137 // so that we could tell the device builtin types from the host ones. This
138 // also solves the different representations of the same builtin type, such
139 // as `size_t` in the MSVC environment.
140 if (Aux->hasFloat128Type()) {
141 HasFloat128 = true;
143 }
144}
static const AMDGPUTargetInfo AMDGPUTI(llvm::Triple("amdgcn-amd-amdhsa"), {})
static constexpr Builtin::Info BuiltinInfo[]
Definition: SPIR.cpp:23
static constexpr Builtin::Info BuiltinInfo[]
Definition: Builtins.cpp:32
Defines the clang::MacroBuilder utility class.
Enumerates target-specific builtins in their own namespaces within namespace clang.
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:231
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:499
Exposes information about the current target.
Definition: TargetInfo.h:220
void copyAuxTarget(const TargetInfo *Aux)
Copy type and layout related info.
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
Definition: TargetInfo.h:1262
virtual bool hasFloat128Type() const
Determine whether the __float128 type is supported on this target.
Definition: TargetInfo.h:703
virtual bool initFeatureMap(llvm::StringMap< bool > &Features, DiagnosticsEngine &Diags, StringRef CPU, const std::vector< std::string > &FeatureVec) const
Initialize the map with the default set of target features for the CPU this should include all legal ...
Definition: TargetInfo.cpp:549
ArrayRef< const char * > getGCCRegNames() const override
Definition: AMDGPU.cpp:176
bool validateAsmConstraint(const char *&Name, TargetInfo::ConstraintInfo &Info) const override
Accepted register names: (n, m is unsigned integer, n < m) v s a {vn}, {v[n]} {sn},...
Definition: AMDGPU.h:152
std::string convertConstraint(const char *&Constraint) const override
Definition: AMDGPU.h:239
ArrayRef< Builtin::Info > getTargetBuiltins() const override
Return information about target-specific builtins for the current primary target, and info about whic...
Definition: AMDGPU.cpp:269
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods -----------------------—===//
Definition: SPIR.cpp:51
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods -----------------------—===//
Definition: SPIR.cpp:39
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods -----------------------—===//
Definition: SPIR.cpp:45
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods -----------------------—===//
Definition: SPIR.cpp:34
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods -----------------------—===//
Definition: SPIR.cpp:61
ArrayRef< const char * > getGCCRegNames() const override
Definition: SPIR.cpp:75
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods -----------------------—===//
Definition: SPIR.cpp:101
void setAuxTarget(const TargetInfo *Aux) override
Definition: SPIR.cpp:111
bool validateAsmConstraint(const char *&Name, TargetInfo::ConstraintInfo &Info) const override
Definition: SPIR.cpp:87
ArrayRef< Builtin::Info > getTargetBuiltins() const override
Return information about target-specific builtins for the current primary target, and info about whic...
Definition: SPIR.cpp:97
bool initFeatureMap(llvm::StringMap< bool > &Features, DiagnosticsEngine &Diags, StringRef, const std::vector< std::string > &) const override
Initialize the map with the default set of target features for the CPU this should include all legal ...
Definition: SPIR.cpp:79
std::string convertConstraint(const char *&Constraint) const override
Definition: SPIR.cpp:93
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods -----------------------—===//
Definition: SPIR.cpp:67
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods -----------------------—===//
Definition: SPIR.cpp:56
ArrayRef< Builtin::Info > getTargetBuiltins() const override
Return information about target-specific builtins for the current primary target, and info about whic...
Definition: SPIR.cpp:29
LLVM_LIBRARY_VISIBILITY void DefineStd(clang::MacroBuilder &Builder, llvm::StringRef MacroName, const clang::LangOptions &Opts)
Define a macro name and standard variants.
The JSON file list parser is used to communicate input to InstallAPI.
const llvm::fltSemantics * DoubleFormat
Definition: TargetInfo.h:141
const llvm::fltSemantics * LongDoubleFormat
Definition: TargetInfo.h:141
const llvm::fltSemantics * Float128Format
Definition: TargetInfo.h:141
const llvm::fltSemantics * FloatFormat
Definition: TargetInfo.h:140
const llvm::fltSemantics * HalfFormat
Definition: TargetInfo.h:140