clang  14.0.0git
SPIR.h
Go to the documentation of this file.
1 //===--- SPIR.h - Declare SPIR target feature support -----------*- 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 // This file declares SPIR TargetInfo objects.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_SPIR_H
14 #define LLVM_CLANG_LIB_BASIC_TARGETS_SPIR_H
15 
16 #include "clang/Basic/TargetInfo.h"
18 #include "llvm/ADT/Triple.h"
19 #include "llvm/Support/Compiler.h"
20 
21 namespace clang {
22 namespace targets {
23 
24 static const unsigned SPIRDefIsPrivMap[] = {
25  0, // Default
26  1, // opencl_global
27  3, // opencl_local
28  2, // opencl_constant
29  0, // opencl_private
30  4, // opencl_generic
31  5, // opencl_global_device
32  6, // opencl_global_host
33  0, // cuda_device
34  0, // cuda_constant
35  0, // cuda_shared
36  // SYCL address space values for this map are dummy
37  0, // sycl_global
38  0, // sycl_global_device
39  0, // sycl_global_host
40  0, // sycl_local
41  0, // sycl_private
42  0, // ptr32_sptr
43  0, // ptr32_uptr
44  0 // ptr64
45 };
46 
47 static const unsigned SPIRDefIsGenMap[] = {
48  4, // Default
49  // OpenCL address space values for this map are dummy and they can't be used
50  0, // opencl_global
51  0, // opencl_local
52  0, // opencl_constant
53  0, // opencl_private
54  0, // opencl_generic
55  0, // opencl_global_device
56  0, // opencl_global_host
57  0, // cuda_device
58  0, // cuda_constant
59  0, // cuda_shared
60  1, // sycl_global
61  5, // sycl_global_device
62  6, // sycl_global_host
63  3, // sycl_local
64  0, // sycl_private
65  0, // ptr32_sptr
66  0, // ptr32_uptr
67  0 // ptr64
68 };
69 
70 class LLVM_LIBRARY_VISIBILITY SPIRTargetInfo : public TargetInfo {
71 public:
72  SPIRTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
73  : TargetInfo(Triple) {
74  assert(getTriple().getOS() == llvm::Triple::UnknownOS &&
75  "SPIR target must use unknown OS");
76  assert(getTriple().getEnvironment() == llvm::Triple::UnknownEnvironment &&
77  "SPIR target must use unknown environment type");
78  TLSSupported = false;
79  VLASupported = false;
80  LongWidth = LongAlign = 64;
81  AddrSpaceMap = &SPIRDefIsPrivMap;
82  UseAddrSpaceMapMangling = true;
83  HasLegalHalfType = true;
84  HasFloat16 = true;
85  // Define available target features
86  // These must be defined in sorted order!
87  NoAsmVariants = true;
88  }
89 
90  void getTargetDefines(const LangOptions &Opts,
91  MacroBuilder &Builder) const override;
92 
93  bool hasFeature(StringRef Feature) const override {
94  return Feature == "spir";
95  }
96 
97  // SPIR supports the half type and the only llvm intrinsic allowed in SPIR is
98  // memcpy as per section 3 of the SPIR spec.
99  bool useFP16ConversionIntrinsics() const override { return false; }
100 
101  ArrayRef<Builtin::Info> getTargetBuiltins() const override { return None; }
102 
103  const char *getClobbers() const override { return ""; }
104 
105  ArrayRef<const char *> getGCCRegNames() const override { return None; }
106 
107  bool validateAsmConstraint(const char *&Name,
108  TargetInfo::ConstraintInfo &info) const override {
109  return true;
110  }
111 
113  return None;
114  }
115 
118  }
119 
121  getDWARFAddressSpace(unsigned AddressSpace) const override {
122  return AddressSpace;
123  }
124 
126  return (CC == CC_SpirFunction || CC == CC_OpenCLKernel) ? CCCR_OK
127  : CCCR_Warning;
128  }
129 
131  return CC_SpirFunction;
132  }
133 
134  void setAddressSpaceMap(bool DefaultIsGeneric) {
135  AddrSpaceMap = DefaultIsGeneric ? &SPIRDefIsGenMap : &SPIRDefIsPrivMap;
136  }
137 
138  void adjust(DiagnosticsEngine &Diags, LangOptions &Opts) override {
139  TargetInfo::adjust(Diags, Opts);
140  // FIXME: SYCL specification considers unannotated pointers and references
141  // to be pointing to the generic address space. See section 5.9.3 of
142  // SYCL 2020 specification.
143  // Currently, there is no way of representing SYCL's default address space
144  // language semantic along with the semantics of embedded C's default
145  // address space in the same address space map. Hence the map needs to be
146  // reset to allow mapping to the desired value of 'Default' entry for SYCL.
147  setAddressSpaceMap(/*DefaultIsGeneric=*/Opts.SYCLIsDevice);
148  }
149 
150  void setSupportedOpenCLOpts() override {
151  // Assume all OpenCL extensions and optional core features are supported
152  // for SPIR since it is a generic target.
153  supportAllOpenCLOpts();
154  }
155 
156  bool hasExtIntType() const override { return true; }
157 
158  bool hasInt128Type() const override { return false; }
159 };
160 
161 class LLVM_LIBRARY_VISIBILITY SPIR32TargetInfo : public SPIRTargetInfo {
162 public:
163  SPIR32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
164  : SPIRTargetInfo(Triple, Opts) {
165  PointerWidth = PointerAlign = 32;
166  SizeType = TargetInfo::UnsignedInt;
167  PtrDiffType = IntPtrType = TargetInfo::SignedInt;
168  resetDataLayout("e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-"
169  "v96:128-v192:256-v256:256-v512:512-v1024:1024");
170  }
171 
172  void getTargetDefines(const LangOptions &Opts,
173  MacroBuilder &Builder) const override;
174 };
175 
176 class LLVM_LIBRARY_VISIBILITY SPIR64TargetInfo : public SPIRTargetInfo {
177 public:
178  SPIR64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
179  : SPIRTargetInfo(Triple, Opts) {
180  PointerWidth = PointerAlign = 64;
181  SizeType = TargetInfo::UnsignedLong;
182  PtrDiffType = IntPtrType = TargetInfo::SignedLong;
183  resetDataLayout("e-i64:64-v16:16-v24:32-v32:32-v48:64-"
184  "v96:128-v192:256-v256:256-v512:512-v1024:1024");
185  }
186 
187  void getTargetDefines(const LangOptions &Opts,
188  MacroBuilder &Builder) const override;
189 };
190 } // namespace targets
191 } // namespace clang
192 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_SPIR_H
clang::targets::SPIR32TargetInfo::SPIR32TargetInfo
SPIR32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: SPIR.h:163
clang::targets::SPIR64TargetInfo
Definition: SPIR.h:176
clang::targets::SPIRTargetInfo::checkCallingConvention
CallingConvCheckResult checkCallingConvention(CallingConv CC) const override
Determines whether a given calling convention is valid for the target.
Definition: SPIR.h:125
clang::targets::SPIR32TargetInfo
Definition: SPIR.h:161
clang::targets::SPIRTargetInfo::getDWARFAddressSpace
Optional< unsigned > getDWARFAddressSpace(unsigned AddressSpace) const override
Definition: SPIR.h:121
clang::targets::SPIRTargetInfo::hasExtIntType
bool hasExtIntType() const override
Determine whether the _ExtInt type is supported on this target.
Definition: SPIR.h:156
clang::targets::SPIRTargetInfo::adjust
void adjust(DiagnosticsEngine &Diags, LangOptions &Opts) override
Set forced language options.
Definition: SPIR.h:138
TargetInfo.h
clang::DiagnosticsEngine
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:191
clang::TargetInfo
Exposes information about the current target.
Definition: TargetInfo.h:189
clang::TargetInfo::VoidPtrBuiltinVaList
@ VoidPtrBuiltinVaList
typedef void* __builtin_va_list;
Definition: TargetInfo.h:270
clang::TargetInfo::adjust
virtual void adjust(DiagnosticsEngine &Diags, LangOptions &Opts)
Set forced language options.
Definition: TargetInfo.cpp:353
llvm::Optional< unsigned >
clang::targets::SPIRTargetInfo::setAddressSpaceMap
void setAddressSpaceMap(bool DefaultIsGeneric)
Definition: SPIR.h:134
clang::TargetInfo::BuiltinVaListKind
BuiltinVaListKind
The different kinds of __builtin_va_list types defined by the target implementation.
Definition: TargetInfo.h:265
clang::targets::SPIRTargetInfo::getGCCRegNames
ArrayRef< const char * > getGCCRegNames() const override
Definition: SPIR.h:105
clang::targets::SPIRTargetInfo::getTargetBuiltins
ArrayRef< Builtin::Info > getTargetBuiltins() const override
Return information about target-specific builtins for the current primary target, and info about whic...
Definition: SPIR.h:101
clang::CC_OpenCLKernel
@ CC_OpenCLKernel
Definition: Specifiers.h:277
clang::targets::SPIRTargetInfo
Definition: SPIR.h:70
clang::targets::SPIRTargetInfo::getDefaultCallingConv
CallingConv getDefaultCallingConv() const override
Gets the default calling convention for the given target and declaration context.
Definition: SPIR.h:130
clang::targets::SPIRDefIsGenMap
static const unsigned SPIRDefIsGenMap[]
Definition: SPIR.h:47
clang::CallingConv
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition: Specifiers.h:263
clang::targets::SPIRTargetInfo::SPIRTargetInfo
SPIRTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
Definition: SPIR.h:72
clang::targets::SPIRTargetInfo::setSupportedOpenCLOpts
void setSupportedOpenCLOpts() override
Set supported OpenCL extensions and optional core features.
Definition: SPIR.h:150
clang::targets::SPIR64TargetInfo::SPIR64TargetInfo
SPIR64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: SPIR.h:178
clang::CC_SpirFunction
@ CC_SpirFunction
Definition: Specifiers.h:276
clang::targets::SPIRTargetInfo::hasInt128Type
bool hasInt128Type() const override
Determine whether the __int128 type is supported on this target.
Definition: SPIR.h:158
TargetOptions.h
llvm::ArrayRef
Definition: LLVM.h:34
clang::targets::SPIRTargetInfo::getClobbers
const char * getClobbers() const override
Returns a string of target-specific clobbers, in LLVM format.
Definition: SPIR.h:103
clang::TargetInfo::ConstraintInfo
Definition: TargetInfo.h:960
clang::LangOptions
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:58
clang::targets::SPIRTargetInfo::hasFeature
bool hasFeature(StringRef Feature) const override
Determine whether the given target has the given feature.
Definition: SPIR.h:93
clang
Definition: CalledOnceCheck.h:17
clang::targets::SPIRTargetInfo::getBuiltinVaListKind
BuiltinVaListKind getBuiltinVaListKind() const override
Returns the kind of __builtin_va_list type that should be used with this target.
Definition: SPIR.h:116
clang::TransferrableTargetInfo::SignedInt
@ SignedInt
Definition: TargetInfo.h:125
clang::TransferrableTargetInfo::UnsignedLong
@ UnsignedLong
Definition: TargetInfo.h:128
clang::targets::SPIRDefIsPrivMap
static const unsigned SPIRDefIsPrivMap[]
Definition: SPIR.h:24
clang::targets::SPIRTargetInfo::validateAsmConstraint
bool validateAsmConstraint(const char *&Name, TargetInfo::ConstraintInfo &info) const override
Definition: SPIR.h:107
clang::targets::SPIRTargetInfo::useFP16ConversionIntrinsics
bool useFP16ConversionIntrinsics() const override
Check whether llvm intrinsics such as llvm.convert.to.fp16 should be used to convert to and from __fp...
Definition: SPIR.h:99
clang::targets::SPIRTargetInfo::getGCCRegAliases
ArrayRef< TargetInfo::GCCRegAlias > getGCCRegAliases() const override
Definition: SPIR.h:112
clang::TargetOptions
Options for controlling the target.
Definition: TargetOptions.h:26
clang::TargetInfo::CallingConvCheckResult
CallingConvCheckResult
Definition: TargetInfo.h:1459
clang::MacroBuilder
Definition: MacroBuilder.h:23
clang::TransferrableTargetInfo::UnsignedInt
@ UnsignedInt
Definition: TargetInfo.h:126
clang::TransferrableTargetInfo::SignedLong
@ SignedLong
Definition: TargetInfo.h:127