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"
16#include "llvm/TargetParser/TargetParser.h"
17
18using namespace clang;
19using namespace clang::targets;
20
22 MacroBuilder &Builder) const {
23 DefineStd(Builder, "SPIR", Opts);
24}
25
27 MacroBuilder &Builder) const {
29 DefineStd(Builder, "SPIR32", Opts);
30}
31
33 MacroBuilder &Builder) const {
35 DefineStd(Builder, "SPIR64", Opts);
36}
37
39 MacroBuilder &Builder) const {
40 DefineStd(Builder, "SPIRV", Opts);
41}
42
44 MacroBuilder &Builder) const {
46}
47
49 MacroBuilder &Builder) const {
51 DefineStd(Builder, "SPIRV32", Opts);
52}
53
55 MacroBuilder &Builder) const {
57 DefineStd(Builder, "SPIRV64", Opts);
58}
59
60static const AMDGPUTargetInfo AMDGPUTI(llvm::Triple("amdgcn-amd-amdhsa"), {});
61
63 return AMDGPUTI.getGCCRegNames();
64}
65
67 llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags, StringRef,
68 const std::vector<std::string> &FeatureVec) const {
69 llvm::AMDGPU::fillAMDGPUFeatureMap({}, getTriple(), Features);
70
71 return TargetInfo::initFeatureMap(Features, Diags, {}, FeatureVec);
72}
73
75 const char *&Name, TargetInfo::ConstraintInfo &Info) const {
76 return AMDGPUTI.validateAsmConstraint(Name, Info);
77}
78
79std::string
80SPIRV64AMDGCNTargetInfo::convertConstraint(const char *&Constraint) const {
81 return AMDGPUTI.convertConstraint(Constraint);
82}
83
86}
87
89 MacroBuilder &Builder) const {
91 DefineStd(Builder, "SPIRV64", Opts);
92
93 Builder.defineMacro("__AMD__");
94 Builder.defineMacro("__AMDGPU__");
95 Builder.defineMacro("__AMDGCN__");
96}
97
99 assert(Aux && "Cannot invoke setAuxTarget without a valid auxiliary target!");
100
101 // This is a 1:1 copy of AMDGPUTargetInfo::setAuxTarget()
102 assert(HalfFormat == Aux->HalfFormat);
103 assert(FloatFormat == Aux->FloatFormat);
104 assert(DoubleFormat == Aux->DoubleFormat);
105
106 // On x86_64 long double is 80-bit extended precision format, which is
107 // not supported by AMDGPU. 128-bit floating point format is also not
108 // supported by AMDGPU. Therefore keep its own format for these two types.
109 auto SaveLongDoubleFormat = LongDoubleFormat;
110 auto SaveFloat128Format = Float128Format;
111 auto SaveLongDoubleWidth = LongDoubleWidth;
112 auto SaveLongDoubleAlign = LongDoubleAlign;
113 copyAuxTarget(Aux);
114 LongDoubleFormat = SaveLongDoubleFormat;
115 Float128Format = SaveFloat128Format;
116 LongDoubleWidth = SaveLongDoubleWidth;
117 LongDoubleAlign = SaveLongDoubleAlign;
118 // For certain builtin types support on the host target, claim they are
119 // supported to pass the compilation of the host code during the device-side
120 // compilation.
121 // FIXME: As the side effect, we also accept `__float128` uses in the device
122 // code. To reject these builtin types supported in the host target but not in
123 // the device target, one approach would support `device_builtin` attribute
124 // so that we could tell the device builtin types from the host ones. This
125 // also solves the different representations of the same builtin type, such
126 // as `size_t` in the MSVC environment.
127 if (Aux->hasFloat128Type()) {
128 HasFloat128 = true;
130 }
131}
static const AMDGPUTargetInfo AMDGPUTI(llvm::Triple("amdgcn-amd-amdhsa"), {})
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:192
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:476
Exposes information about the current target.
Definition: TargetInfo.h:218
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:1256
virtual bool hasFloat128Type() const
Determine whether the __float128 type is supported on this target.
Definition: TargetInfo.h:693
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:532
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:139
std::string convertConstraint(const char *&Constraint) const override
Definition: AMDGPU.h:226
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:38
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods -----------------------—===//
Definition: SPIR.cpp:26
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods -----------------------—===//
Definition: SPIR.cpp:32
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods -----------------------—===//
Definition: SPIR.cpp:21
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods -----------------------—===//
Definition: SPIR.cpp:48
ArrayRef< const char * > getGCCRegNames() const override
Definition: SPIR.cpp:62
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods -----------------------—===//
Definition: SPIR.cpp:88
void setAuxTarget(const TargetInfo *Aux) override
Definition: SPIR.cpp:98
bool validateAsmConstraint(const char *&Name, TargetInfo::ConstraintInfo &Info) const override
Definition: SPIR.cpp:74
ArrayRef< Builtin::Info > getTargetBuiltins() const override
Return information about target-specific builtins for the current primary target, and info about whic...
Definition: SPIR.cpp:84
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:66
std::string convertConstraint(const char *&Constraint) const override
Definition: SPIR.cpp:80
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods -----------------------—===//
Definition: SPIR.cpp:54
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods -----------------------—===//
Definition: SPIR.cpp:43
void DefineStd(MacroBuilder &Builder, StringRef MacroName, const LangOptions &Opts)
DefineStd - Define a macro name and standard variants.
Definition: Targets.cpp:59
The JSON file list parser is used to communicate input to InstallAPI.
const llvm::fltSemantics * DoubleFormat
Definition: TargetInfo.h:139
const llvm::fltSemantics * LongDoubleFormat
Definition: TargetInfo.h:139
const llvm::fltSemantics * Float128Format
Definition: TargetInfo.h:139
const llvm::fltSemantics * FloatFormat
Definition: TargetInfo.h:138
const llvm::fltSemantics * HalfFormat
Definition: TargetInfo.h:138