]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/Basic/Targets/SPIR.h
Vendor import of clang trunk r338150:
[FreeBSD/FreeBSD.git] / lib / Basic / Targets / SPIR.h
1 //===--- 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
22 namespace clang {
23 namespace targets {
24
25 static const unsigned SPIRAddrSpaceMap[] = {
26     0, // Default
27     1, // opencl_global
28     3, // opencl_local
29     2, // opencl_constant
30     0, // opencl_private
31     4, // opencl_generic
32     0, // cuda_device
33     0, // cuda_constant
34     0  // cuda_shared
35 };
36
37 class LLVM_LIBRARY_VISIBILITY SPIRTargetInfo : public TargetInfo {
38 public:
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     VLASupported = false;
47     LongWidth = LongAlign = 64;
48     AddrSpaceMap = &SPIRAddrSpaceMap;
49     UseAddrSpaceMapMangling = true;
50     HasLegalHalfType = true;
51     // Define available target features
52     // These must be defined in sorted order!
53     NoAsmVariants = true;
54   }
55
56   void getTargetDefines(const LangOptions &Opts,
57                         MacroBuilder &Builder) const override;
58
59   bool hasFeature(StringRef Feature) const override {
60     return Feature == "spir";
61   }
62
63   // SPIR supports the half type and the only llvm intrinsic allowed in SPIR is
64   // memcpy as per section 3 of the SPIR spec.
65   bool useFP16ConversionIntrinsics() const override { return false; }
66
67   ArrayRef<Builtin::Info> getTargetBuiltins() const override { return None; }
68
69   const char *getClobbers() const override { return ""; }
70
71   ArrayRef<const char *> getGCCRegNames() const override { return None; }
72
73   bool validateAsmConstraint(const char *&Name,
74                              TargetInfo::ConstraintInfo &info) const override {
75     return true;
76   }
77
78   ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override {
79     return None;
80   }
81
82   BuiltinVaListKind getBuiltinVaListKind() const override {
83     return TargetInfo::VoidPtrBuiltinVaList;
84   }
85
86   CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
87     return (CC == CC_SpirFunction || CC == CC_OpenCLKernel) ? CCCR_OK
88                                                             : CCCR_Warning;
89   }
90
91   CallingConv getDefaultCallingConv(CallingConvMethodType MT) const override {
92     return CC_SpirFunction;
93   }
94
95   void setSupportedOpenCLOpts() override {
96     // Assume all OpenCL extensions and optional core features are supported
97     // for SPIR since it is a generic target.
98     getSupportedOpenCLOpts().supportAll();
99   }
100 };
101 class LLVM_LIBRARY_VISIBILITY SPIR32TargetInfo : public SPIRTargetInfo {
102 public:
103   SPIR32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
104       : SPIRTargetInfo(Triple, Opts) {
105     PointerWidth = PointerAlign = 32;
106     SizeType = TargetInfo::UnsignedInt;
107     PtrDiffType = IntPtrType = TargetInfo::SignedInt;
108     resetDataLayout("e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-"
109                     "v96:128-v192:256-v256:256-v512:512-v1024:1024");
110   }
111
112   void getTargetDefines(const LangOptions &Opts,
113                         MacroBuilder &Builder) const override;
114 };
115
116 class LLVM_LIBRARY_VISIBILITY SPIR64TargetInfo : public SPIRTargetInfo {
117 public:
118   SPIR64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
119       : SPIRTargetInfo(Triple, Opts) {
120     PointerWidth = PointerAlign = 64;
121     SizeType = TargetInfo::UnsignedLong;
122     PtrDiffType = IntPtrType = TargetInfo::SignedLong;
123     resetDataLayout("e-i64:64-v16:16-v24:32-v32:32-v48:64-"
124                     "v96:128-v192:256-v256:256-v512:512-v1024:1024");
125   }
126
127   void getTargetDefines(const LangOptions &Opts,
128                         MacroBuilder &Builder) const override;
129 };
130 } // namespace targets
131 } // namespace clang
132 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_SPIR_H