clang 10.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"
17 #include "clang/Basic/TargetOptions.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 SPIRAddrSpaceMap[] = {
25 0, // Default
26 1, // opencl_global
27 3, // opencl_local
28 2, // opencl_constant
29 0, // opencl_private
30 4, // opencl_generic
31 0, // cuda_device
32 0, // cuda_constant
33 0, // cuda_shared
34 0, // ptr32_sptr
35 0, // ptr32_uptr
36 0 // ptr64
37 };
38
39 class LLVM_LIBRARY_VISIBILITY SPIRTargetInfo : public TargetInfo {
40 public:
41 SPIRTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
42 : TargetInfo(Triple) {
43 assert(getTriple().getOS() == llvm::Triple::UnknownOS &&
44 "SPIR target must use unknown OS");
45 assert(getTriple().getEnvironment() == llvm::Triple::UnknownEnvironment &&
46 "SPIR target must use unknown environment type");
47 TLSSupported = false;
48 VLASupported = false;
49 LongWidth = LongAlign = 64;
50 AddrSpaceMap = &SPIRAddrSpaceMap;
51 UseAddrSpaceMapMangling = true;
52 HasLegalHalfType = true;
53 HasFloat16 = true;
54 // Define available target features
55 // These must be defined in sorted order!
56 NoAsmVariants = true;
57 }
58
59 void getTargetDefines(const LangOptions &Opts,
60 MacroBuilder &Builder) const override;
61
62 bool hasFeature(StringRef Feature) const override {
63 return Feature == "spir";
64 }
65
66 // SPIR supports the half type and the only llvm intrinsic allowed in SPIR is
67 // memcpy as per section 3 of the SPIR spec.
68 bool useFP16ConversionIntrinsics() const override { return false; }
69
70 ArrayRef<Builtin::Info> getTargetBuiltins() const override { return None; }
71
72 const char *getClobbers() const override { return ""; }
73
74 ArrayRef<const char *> getGCCRegNames() const override { return None; }
75
76 bool validateAsmConstraint(const char *&Name,
77 TargetInfo::ConstraintInfo &info) const override {
78 return true;
79 }
80
81 ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override {
82 return None;
83 }
84
85 BuiltinVaListKind getBuiltinVaListKind() const override {
86 return TargetInfo::VoidPtrBuiltinVaList;
87 }
88
89 CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
90 return (CC == CC_SpirFunction || CC == CC_OpenCLKernel) ? CCCR_OK
91 : CCCR_Warning;
92 }
93
94 CallingConv getDefaultCallingConv() const override {
95 return CC_SpirFunction;
96 }
97
98 void setSupportedOpenCLOpts() override {
99 // Assume all OpenCL extensions and optional core features are supported
100 // for SPIR since it is a generic target.
101 getSupportedOpenCLOpts().supportAll();
102 }
103 };
104 class LLVM_LIBRARY_VISIBILITY SPIR32TargetInfo : public SPIRTargetInfo {
105 public:
106 SPIR32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
107 : SPIRTargetInfo(Triple, Opts) {
108 PointerWidth = PointerAlign = 32;
109 SizeType = TargetInfo::UnsignedInt;
110 PtrDiffType = IntPtrType = TargetInfo::SignedInt;
111 resetDataLayout("e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-"
112 "v96:128-v192:256-v256:256-v512:512-v1024:1024");
113 }
114
115 void getTargetDefines(const LangOptions &Opts,
116 MacroBuilder &Builder) const override;
117 };
118
119 class LLVM_LIBRARY_VISIBILITY SPIR64TargetInfo : public SPIRTargetInfo {
120 public:
121 SPIR64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
122 : SPIRTargetInfo(Triple, Opts) {
123 PointerWidth = PointerAlign = 64;
124 SizeType = TargetInfo::UnsignedLong;
125 PtrDiffType = IntPtrType = TargetInfo::SignedLong;
126 resetDataLayout("e-i64:64-v16:16-v24:32-v32:32-v48:64-"
127 "v96:128-v192:256-v256:256-v512:512-v1024:1024");
128 }
129
130 void getTargetDefines(const LangOptions &Opts,
131 MacroBuilder &Builder) const override;
132 };
133 } // namespace targets
134 } // namespace clang
135 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_SPIR_H
clang::CC_OpenCLKernel
Definition: Specifiers.h:279
clang::targets::SPIR64TargetInfo
Definition: SPIR.h:119
clang::targets::SPIRTargetInfo::getDefaultCallingConv
CallingConv getDefaultCallingConv() const override
Gets the default calling convention for the given target and declaration context. ...
Definition: SPIR.h:94
clang::CC_SpirFunction
Definition: Specifiers.h:278
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:68
clang::targets::SPIRTargetInfo::checkCallingConvention
CallingConvCheckResult checkCallingConvention(CallingConv CC) const override
Determines whether a given calling convention is valid for the target.
Definition: SPIR.h:89
clang::targets::SPIR32TargetInfo::SPIR32TargetInfo
SPIR32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: SPIR.h:106
clang::TargetOptions
Options for controlling the target.
Definition: TargetOptions.h:26
clang::TransferrableTargetInfo::SignedInt
Definition: TargetInfo.h:113
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:70
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:53
clang::targets::SPIRTargetInfo::SPIRTargetInfo
SPIRTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
Definition: SPIR.h:41
clang::targets::SPIRTargetInfo
Definition: SPIR.h:39
llvm::ArrayRef
Definition: LLVM.h:31
clang::targets::SPIRTargetInfo::getGCCRegNames
ArrayRef< const char * > getGCCRegNames() const override
Definition: SPIR.h:74
clang::TargetInfo::VoidPtrBuiltinVaList
typedef void* __builtin_va_list;
Definition: TargetInfo.h:231
clang::TargetInfo
Exposes information about the current target.
Definition: TargetInfo.h:164
clang::TransferrableTargetInfo::SignedLong
Definition: TargetInfo.h:115
clang::CallingConv
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition: Specifiers.h:265
clang::TargetInfo::ConstraintInfo
Definition: TargetInfo.h:830
clang::targets::SPIRTargetInfo::setSupportedOpenCLOpts
void setSupportedOpenCLOpts() override
Set supported OpenCL extensions and optional core features.
Definition: SPIR.h:98
clang::TransferrableTargetInfo::UnsignedLong
Definition: TargetInfo.h:116
TargetOptions.h
Defines the clang::TargetOptions class.
clang::TransferrableTargetInfo::UnsignedInt
Definition: TargetInfo.h:114
clang::targets::SPIRAddrSpaceMap
static const unsigned SPIRAddrSpaceMap[]
Definition: SPIR.h:24
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:21
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:85
clang::targets::SPIR32TargetInfo
Definition: SPIR.h:104
clang::MacroBuilder
Definition: MacroBuilder.h:23
clang::targets::SPIR64TargetInfo::SPIR64TargetInfo
SPIR64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: SPIR.h:121
clang::TargetInfo::BuiltinVaListKind
BuiltinVaListKind
The different kinds of __builtin_va_list types defined by the target implementation.
Definition: TargetInfo.h:226
clang::targets::SPIRTargetInfo::validateAsmConstraint
bool validateAsmConstraint(const char *&Name, TargetInfo::ConstraintInfo &info) const override
Definition: SPIR.h:76
clang::targets::SPIRTargetInfo::getGCCRegAliases
ArrayRef< TargetInfo::GCCRegAlias > getGCCRegAliases() const override
Definition: SPIR.h:81
TargetInfo.h
Defines the clang::TargetInfo interface.
clang::targets::SPIRTargetInfo::hasFeature
bool hasFeature(StringRef Feature) const override
Determine whether the given target has the given feature.
Definition: SPIR.h:62
clang::targets::SPIRTargetInfo::getClobbers
const char * getClobbers() const override
Returns a string of target-specific clobbers, in LLVM format.
Definition: SPIR.h:72
clang::TargetInfo::CallingConvCheckResult
CallingConvCheckResult
Definition: TargetInfo.h:1283