xref: /freebsd/contrib/llvm-project/clang/lib/Basic/Targets/SPIR.h (revision 77013d11e6483b970af25e13c9b892075742f7e5)
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     5, // opencl_global_device
32     6, // opencl_global_host
33     0, // cuda_device
34     0, // cuda_constant
35     0, // cuda_shared
36     0, // ptr32_sptr
37     0, // ptr32_uptr
38     0  // ptr64
39 };
40 
41 class LLVM_LIBRARY_VISIBILITY SPIRTargetInfo : public TargetInfo {
42 public:
43   SPIRTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
44       : TargetInfo(Triple) {
45     assert(getTriple().getOS() == llvm::Triple::UnknownOS &&
46            "SPIR target must use unknown OS");
47     assert(getTriple().getEnvironment() == llvm::Triple::UnknownEnvironment &&
48            "SPIR target must use unknown environment type");
49     TLSSupported = false;
50     VLASupported = false;
51     LongWidth = LongAlign = 64;
52     AddrSpaceMap = &SPIRAddrSpaceMap;
53     UseAddrSpaceMapMangling = true;
54     HasLegalHalfType = true;
55     HasFloat16 = true;
56     // Define available target features
57     // These must be defined in sorted order!
58     NoAsmVariants = true;
59   }
60 
61   void getTargetDefines(const LangOptions &Opts,
62                         MacroBuilder &Builder) const override;
63 
64   bool hasFeature(StringRef Feature) const override {
65     return Feature == "spir";
66   }
67 
68   // SPIR supports the half type and the only llvm intrinsic allowed in SPIR is
69   // memcpy as per section 3 of the SPIR spec.
70   bool useFP16ConversionIntrinsics() const override { return false; }
71 
72   ArrayRef<Builtin::Info> getTargetBuiltins() const override { return None; }
73 
74   const char *getClobbers() const override { return ""; }
75 
76   ArrayRef<const char *> getGCCRegNames() const override { return None; }
77 
78   bool validateAsmConstraint(const char *&Name,
79                              TargetInfo::ConstraintInfo &info) const override {
80     return true;
81   }
82 
83   ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override {
84     return None;
85   }
86 
87   BuiltinVaListKind getBuiltinVaListKind() const override {
88     return TargetInfo::VoidPtrBuiltinVaList;
89   }
90 
91   CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
92     return (CC == CC_SpirFunction || CC == CC_OpenCLKernel) ? CCCR_OK
93                                                             : CCCR_Warning;
94   }
95 
96   CallingConv getDefaultCallingConv() const override {
97     return CC_SpirFunction;
98   }
99 
100   void setSupportedOpenCLOpts() override {
101     // Assume all OpenCL extensions and optional core features are supported
102     // for SPIR since it is a generic target.
103     supportAllOpenCLOpts();
104   }
105 
106   bool hasExtIntType() const override { return true; }
107 
108   bool hasInt128Type() const override { return false; }
109 };
110 class LLVM_LIBRARY_VISIBILITY SPIR32TargetInfo : public SPIRTargetInfo {
111 public:
112   SPIR32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
113       : SPIRTargetInfo(Triple, Opts) {
114     PointerWidth = PointerAlign = 32;
115     SizeType = TargetInfo::UnsignedInt;
116     PtrDiffType = IntPtrType = TargetInfo::SignedInt;
117     resetDataLayout("e-p:32:32-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 
125 class LLVM_LIBRARY_VISIBILITY SPIR64TargetInfo : public SPIRTargetInfo {
126 public:
127   SPIR64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
128       : SPIRTargetInfo(Triple, Opts) {
129     PointerWidth = PointerAlign = 64;
130     SizeType = TargetInfo::UnsignedLong;
131     PtrDiffType = IntPtrType = TargetInfo::SignedLong;
132     resetDataLayout("e-i64:64-v16:16-v24:32-v32:32-v48:64-"
133                     "v96:128-v192:256-v256:256-v512:512-v1024:1024");
134   }
135 
136   void getTargetDefines(const LangOptions &Opts,
137                         MacroBuilder &Builder) const override;
138 };
139 } // namespace targets
140 } // namespace clang
141 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_SPIR_H
142