blob: e64ad5482908939bdcffc60934e9e47b70410b81 [file] [log] [blame]
Erich Keaneebba5922017-07-21 22:37:03 +00001//===--- SPIR.h - Declare SPIR target feature support -----------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file declares SPIR TargetInfo objects.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_LIB_BASIC_TARGETS_SPIR_H
15#define LLVM_CLANG_LIB_BASIC_TARGETS_SPIR_H
16
17#include "clang/Basic/TargetInfo.h"
18#include "clang/Basic/TargetOptions.h"
19#include "llvm/ADT/Triple.h"
20#include "llvm/Support/Compiler.h"
21
22namespace clang {
23namespace targets {
24
25static const unsigned SPIRAddrSpaceMap[] = {
26 0, // Default
27 1, // opencl_global
28 3, // opencl_local
29 2, // opencl_constant
Yaxun Liub7318e02017-10-13 03:37:48 +000030 0, // opencl_private
Erich Keaneebba5922017-07-21 22:37:03 +000031 4, // opencl_generic
32 0, // cuda_device
33 0, // cuda_constant
34 0 // cuda_shared
35};
36
37class LLVM_LIBRARY_VISIBILITY SPIRTargetInfo : public TargetInfo {
38public:
39 SPIRTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
40 : TargetInfo(Triple) {
41 assert(getTriple().getOS() == llvm::Triple::UnknownOS &&
42 "SPIR target must use unknown OS");
43 assert(getTriple().getEnvironment() == llvm::Triple::UnknownEnvironment &&
44 "SPIR target must use unknown environment type");
45 TLSSupported = false;
46 LongWidth = LongAlign = 64;
47 AddrSpaceMap = &SPIRAddrSpaceMap;
48 UseAddrSpaceMapMangling = true;
49 // Define available target features
50 // These must be defined in sorted order!
51 NoAsmVariants = true;
52 }
53
54 void getTargetDefines(const LangOptions &Opts,
55 MacroBuilder &Builder) const override;
56
57 bool hasFeature(StringRef Feature) const override {
58 return Feature == "spir";
59 }
60
61 ArrayRef<Builtin::Info> getTargetBuiltins() const override { return None; }
62
63 const char *getClobbers() const override { return ""; }
64
65 ArrayRef<const char *> getGCCRegNames() const override { return None; }
66
67 bool validateAsmConstraint(const char *&Name,
68 TargetInfo::ConstraintInfo &info) const override {
69 return true;
70 }
71
72 ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override {
73 return None;
74 }
75
76 BuiltinVaListKind getBuiltinVaListKind() const override {
77 return TargetInfo::VoidPtrBuiltinVaList;
78 }
79
80 CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
81 return (CC == CC_SpirFunction || CC == CC_OpenCLKernel) ? CCCR_OK
82 : CCCR_Warning;
83 }
84
85 CallingConv getDefaultCallingConv(CallingConvMethodType MT) const override {
86 return CC_SpirFunction;
87 }
88
89 void setSupportedOpenCLOpts() override {
90 // Assume all OpenCL extensions and optional core features are supported
91 // for SPIR since it is a generic target.
92 getSupportedOpenCLOpts().supportAll();
93 }
94};
95class LLVM_LIBRARY_VISIBILITY SPIR32TargetInfo : public SPIRTargetInfo {
96public:
97 SPIR32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
98 : SPIRTargetInfo(Triple, Opts) {
99 PointerWidth = PointerAlign = 32;
100 SizeType = TargetInfo::UnsignedInt;
101 PtrDiffType = IntPtrType = TargetInfo::SignedInt;
102 resetDataLayout("e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-"
103 "v96:128-v192:256-v256:256-v512:512-v1024:1024");
104 }
105
106 void getTargetDefines(const LangOptions &Opts,
107 MacroBuilder &Builder) const override;
108};
109
110class LLVM_LIBRARY_VISIBILITY SPIR64TargetInfo : public SPIRTargetInfo {
111public:
112 SPIR64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
113 : SPIRTargetInfo(Triple, Opts) {
114 PointerWidth = PointerAlign = 64;
115 SizeType = TargetInfo::UnsignedLong;
116 PtrDiffType = IntPtrType = TargetInfo::SignedLong;
117 resetDataLayout("e-i64:64-v16:16-v24:32-v32:32-v48:64-"
118 "v96:128-v192:256-v256:256-v512:512-v1024:1024");
119 }
120
121 void getTargetDefines(const LangOptions &Opts,
122 MacroBuilder &Builder) const override;
123};
124} // namespace targets
125} // namespace clang
126#endif // LLVM_CLANG_LIB_BASIC_TARGETS_SPIR_H