blob: 706449d3d15fa956ee41b374862885919a88136f [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
30 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;
45 LongWidth = LongAlign = 64;
46 AddrSpaceMap = &SPIRAddrSpaceMap;
47 UseAddrSpaceMapMangling = true;
48 // Define available target features
49 // These must be defined in sorted order!
50 NoAsmVariants = true;
51 }
52
53 void getTargetDefines(const LangOptions &Opts,
54 MacroBuilder &Builder) const override;
55
56 bool hasFeature(StringRef Feature) const override {
57 return Feature == "spir";
58 }
59
60 ArrayRef<Builtin::Info> getTargetBuiltins() const override { return None; }
61
62 const char *getClobbers() const override { return ""; }
63
64 ArrayRef<const char *> getGCCRegNames() const override { return None; }
65
66 bool validateAsmConstraint(const char *&Name,
67 TargetInfo::ConstraintInfo &info) const override {
68 return true;
69 }
70
71 ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override {
72 return None;
73 }
74
75 BuiltinVaListKind getBuiltinVaListKind() const override {
76 return TargetInfo::VoidPtrBuiltinVaList;
77 }
78
79 CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
80 return (CC == CC_SpirFunction || CC == CC_OpenCLKernel) ? CCCR_OK
81 : CCCR_Warning;
82 }
83
84 CallingConv getDefaultCallingConv(CallingConvMethodType MT) const override {
85 return CC_SpirFunction;
86 }
87
88 void setSupportedOpenCLOpts() override {
89 // Assume all OpenCL extensions and optional core features are supported
90 // for SPIR since it is a generic target.
91 getSupportedOpenCLOpts().supportAll();
92 }
93};
94class LLVM_LIBRARY_VISIBILITY SPIR32TargetInfo : public SPIRTargetInfo {
95public:
96 SPIR32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
97 : SPIRTargetInfo(Triple, Opts) {
98 PointerWidth = PointerAlign = 32;
99 SizeType = TargetInfo::UnsignedInt;
100 PtrDiffType = IntPtrType = TargetInfo::SignedInt;
101 resetDataLayout("e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-"
102 "v96:128-v192:256-v256:256-v512:512-v1024:1024");
103 }
104
105 void getTargetDefines(const LangOptions &Opts,
106 MacroBuilder &Builder) const override;
107};
108
109class LLVM_LIBRARY_VISIBILITY SPIR64TargetInfo : public SPIRTargetInfo {
110public:
111 SPIR64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
112 : SPIRTargetInfo(Triple, Opts) {
113 PointerWidth = PointerAlign = 64;
114 SizeType = TargetInfo::UnsignedLong;
115 PtrDiffType = IntPtrType = TargetInfo::SignedLong;
116 resetDataLayout("e-i64:64-v16:16-v24:32-v32:32-v48:64-"
117 "v96:128-v192:256-v256:256-v512:512-v1024:1024");
118 }
119
120 void getTargetDefines(const LangOptions &Opts,
121 MacroBuilder &Builder) const override;
122};
123} // namespace targets
124} // namespace clang
125#endif // LLVM_CLANG_LIB_BASIC_TARGETS_SPIR_H