blob: 30f2f0f291fe7e8c031f45358df5073757cba5c8 [file] [log] [blame]
Erich Keaneebba5922017-07-21 22:37:03 +00001//===--- SPIR.h - Declare SPIR target feature support -----------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Erich Keaneebba5922017-07-21 22:37:03 +00006//
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
21namespace clang {
22namespace targets {
23
24static const unsigned SPIRAddrSpaceMap[] = {
25 0, // Default
26 1, // opencl_global
27 3, // opencl_local
28 2, // opencl_constant
Yaxun Liub7318e02017-10-13 03:37:48 +000029 0, // opencl_private
Erich Keaneebba5922017-07-21 22:37:03 +000030 4, // opencl_generic
31 0, // cuda_device
32 0, // cuda_constant
33 0 // cuda_shared
34};
35
36class LLVM_LIBRARY_VISIBILITY SPIRTargetInfo : public TargetInfo {
37public:
38 SPIRTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
39 : TargetInfo(Triple) {
40 assert(getTriple().getOS() == llvm::Triple::UnknownOS &&
41 "SPIR target must use unknown OS");
42 assert(getTriple().getEnvironment() == llvm::Triple::UnknownEnvironment &&
43 "SPIR target must use unknown environment type");
44 TLSSupported = false;
Jonas Hahnfeld87d44262017-11-18 21:00:46 +000045 VLASupported = false;
Erich Keaneebba5922017-07-21 22:37:03 +000046 LongWidth = LongAlign = 64;
47 AddrSpaceMap = &SPIRAddrSpaceMap;
48 UseAddrSpaceMapMangling = true;
Sjoerd Meijer5c4c9982018-06-20 09:49:40 +000049 HasLegalHalfType = true;
Erich Keaneebba5922017-07-21 22:37:03 +000050 // Define available target features
51 // These must be defined in sorted order!
52 NoAsmVariants = true;
53 }
54
55 void getTargetDefines(const LangOptions &Opts,
56 MacroBuilder &Builder) const override;
57
58 bool hasFeature(StringRef Feature) const override {
59 return Feature == "spir";
60 }
61
Sjoerd Meijer5c4c9982018-06-20 09:49:40 +000062 // SPIR supports the half type and the only llvm intrinsic allowed in SPIR is
63 // memcpy as per section 3 of the SPIR spec.
64 bool useFP16ConversionIntrinsics() const override { return false; }
65
Erich Keaneebba5922017-07-21 22:37:03 +000066 ArrayRef<Builtin::Info> getTargetBuiltins() const override { return None; }
67
68 const char *getClobbers() const override { return ""; }
69
70 ArrayRef<const char *> getGCCRegNames() const override { return None; }
71
72 bool validateAsmConstraint(const char *&Name,
73 TargetInfo::ConstraintInfo &info) const override {
74 return true;
75 }
76
77 ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override {
78 return None;
79 }
80
81 BuiltinVaListKind getBuiltinVaListKind() const override {
82 return TargetInfo::VoidPtrBuiltinVaList;
83 }
84
85 CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
86 return (CC == CC_SpirFunction || CC == CC_OpenCLKernel) ? CCCR_OK
87 : CCCR_Warning;
88 }
89
90 CallingConv getDefaultCallingConv(CallingConvMethodType MT) const override {
91 return CC_SpirFunction;
92 }
93
94 void setSupportedOpenCLOpts() override {
95 // Assume all OpenCL extensions and optional core features are supported
96 // for SPIR since it is a generic target.
97 getSupportedOpenCLOpts().supportAll();
98 }
99};
100class LLVM_LIBRARY_VISIBILITY SPIR32TargetInfo : public SPIRTargetInfo {
101public:
102 SPIR32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
103 : SPIRTargetInfo(Triple, Opts) {
104 PointerWidth = PointerAlign = 32;
105 SizeType = TargetInfo::UnsignedInt;
106 PtrDiffType = IntPtrType = TargetInfo::SignedInt;
107 resetDataLayout("e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-"
108 "v96:128-v192:256-v256:256-v512:512-v1024:1024");
109 }
110
111 void getTargetDefines(const LangOptions &Opts,
112 MacroBuilder &Builder) const override;
113};
114
115class LLVM_LIBRARY_VISIBILITY SPIR64TargetInfo : public SPIRTargetInfo {
116public:
117 SPIR64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
118 : SPIRTargetInfo(Triple, Opts) {
119 PointerWidth = PointerAlign = 64;
120 SizeType = TargetInfo::UnsignedLong;
121 PtrDiffType = IntPtrType = TargetInfo::SignedLong;
122 resetDataLayout("e-i64:64-v16:16-v24:32-v32:32-v48:64-"
123 "v96:128-v192:256-v256:256-v512:512-v1024:1024");
124 }
125
126 void getTargetDefines(const LangOptions &Opts,
127 MacroBuilder &Builder) const override;
128};
129} // namespace targets
130} // namespace clang
131#endif // LLVM_CLANG_LIB_BASIC_TARGETS_SPIR_H