xref: /freebsd/contrib/llvm-project/clang/lib/Basic/Targets/SPIR.h (revision e8d8bef961a50d4dc22501cde4fb9fb0be1b2532)
10b57cec5SDimitry Andric //===--- SPIR.h - Declare SPIR target feature support -----------*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This file declares SPIR TargetInfo objects.
100b57cec5SDimitry Andric //
110b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric 
130b57cec5SDimitry Andric #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_SPIR_H
140b57cec5SDimitry Andric #define LLVM_CLANG_LIB_BASIC_TARGETS_SPIR_H
150b57cec5SDimitry Andric 
160b57cec5SDimitry Andric #include "clang/Basic/TargetInfo.h"
170b57cec5SDimitry Andric #include "clang/Basic/TargetOptions.h"
180b57cec5SDimitry Andric #include "llvm/ADT/Triple.h"
190b57cec5SDimitry Andric #include "llvm/Support/Compiler.h"
200b57cec5SDimitry Andric 
210b57cec5SDimitry Andric namespace clang {
220b57cec5SDimitry Andric namespace targets {
230b57cec5SDimitry Andric 
240b57cec5SDimitry Andric static const unsigned SPIRAddrSpaceMap[] = {
250b57cec5SDimitry Andric     0, // Default
260b57cec5SDimitry Andric     1, // opencl_global
270b57cec5SDimitry Andric     3, // opencl_local
280b57cec5SDimitry Andric     2, // opencl_constant
290b57cec5SDimitry Andric     0, // opencl_private
300b57cec5SDimitry Andric     4, // opencl_generic
31*e8d8bef9SDimitry Andric     5, // opencl_global_device
32*e8d8bef9SDimitry Andric     6, // opencl_global_host
330b57cec5SDimitry Andric     0, // cuda_device
340b57cec5SDimitry Andric     0, // cuda_constant
35480093f4SDimitry Andric     0, // cuda_shared
36480093f4SDimitry Andric     0, // ptr32_sptr
37480093f4SDimitry Andric     0, // ptr32_uptr
38480093f4SDimitry Andric     0  // ptr64
390b57cec5SDimitry Andric };
400b57cec5SDimitry Andric 
410b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY SPIRTargetInfo : public TargetInfo {
420b57cec5SDimitry Andric public:
430b57cec5SDimitry Andric   SPIRTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
440b57cec5SDimitry Andric       : TargetInfo(Triple) {
450b57cec5SDimitry Andric     assert(getTriple().getOS() == llvm::Triple::UnknownOS &&
460b57cec5SDimitry Andric            "SPIR target must use unknown OS");
470b57cec5SDimitry Andric     assert(getTriple().getEnvironment() == llvm::Triple::UnknownEnvironment &&
480b57cec5SDimitry Andric            "SPIR target must use unknown environment type");
490b57cec5SDimitry Andric     TLSSupported = false;
500b57cec5SDimitry Andric     VLASupported = false;
510b57cec5SDimitry Andric     LongWidth = LongAlign = 64;
520b57cec5SDimitry Andric     AddrSpaceMap = &SPIRAddrSpaceMap;
530b57cec5SDimitry Andric     UseAddrSpaceMapMangling = true;
540b57cec5SDimitry Andric     HasLegalHalfType = true;
550b57cec5SDimitry Andric     HasFloat16 = true;
560b57cec5SDimitry Andric     // Define available target features
570b57cec5SDimitry Andric     // These must be defined in sorted order!
580b57cec5SDimitry Andric     NoAsmVariants = true;
590b57cec5SDimitry Andric   }
600b57cec5SDimitry Andric 
610b57cec5SDimitry Andric   void getTargetDefines(const LangOptions &Opts,
620b57cec5SDimitry Andric                         MacroBuilder &Builder) const override;
630b57cec5SDimitry Andric 
640b57cec5SDimitry Andric   bool hasFeature(StringRef Feature) const override {
650b57cec5SDimitry Andric     return Feature == "spir";
660b57cec5SDimitry Andric   }
670b57cec5SDimitry Andric 
680b57cec5SDimitry Andric   // SPIR supports the half type and the only llvm intrinsic allowed in SPIR is
690b57cec5SDimitry Andric   // memcpy as per section 3 of the SPIR spec.
700b57cec5SDimitry Andric   bool useFP16ConversionIntrinsics() const override { return false; }
710b57cec5SDimitry Andric 
720b57cec5SDimitry Andric   ArrayRef<Builtin::Info> getTargetBuiltins() const override { return None; }
730b57cec5SDimitry Andric 
740b57cec5SDimitry Andric   const char *getClobbers() const override { return ""; }
750b57cec5SDimitry Andric 
760b57cec5SDimitry Andric   ArrayRef<const char *> getGCCRegNames() const override { return None; }
770b57cec5SDimitry Andric 
780b57cec5SDimitry Andric   bool validateAsmConstraint(const char *&Name,
790b57cec5SDimitry Andric                              TargetInfo::ConstraintInfo &info) const override {
800b57cec5SDimitry Andric     return true;
810b57cec5SDimitry Andric   }
820b57cec5SDimitry Andric 
830b57cec5SDimitry Andric   ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override {
840b57cec5SDimitry Andric     return None;
850b57cec5SDimitry Andric   }
860b57cec5SDimitry Andric 
870b57cec5SDimitry Andric   BuiltinVaListKind getBuiltinVaListKind() const override {
880b57cec5SDimitry Andric     return TargetInfo::VoidPtrBuiltinVaList;
890b57cec5SDimitry Andric   }
900b57cec5SDimitry Andric 
910b57cec5SDimitry Andric   CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
920b57cec5SDimitry Andric     return (CC == CC_SpirFunction || CC == CC_OpenCLKernel) ? CCCR_OK
930b57cec5SDimitry Andric                                                             : CCCR_Warning;
940b57cec5SDimitry Andric   }
950b57cec5SDimitry Andric 
960b57cec5SDimitry Andric   CallingConv getDefaultCallingConv() const override {
970b57cec5SDimitry Andric     return CC_SpirFunction;
980b57cec5SDimitry Andric   }
990b57cec5SDimitry Andric 
1000b57cec5SDimitry Andric   void setSupportedOpenCLOpts() override {
1010b57cec5SDimitry Andric     // Assume all OpenCL extensions and optional core features are supported
1020b57cec5SDimitry Andric     // for SPIR since it is a generic target.
103*e8d8bef9SDimitry Andric     supportAllOpenCLOpts();
1040b57cec5SDimitry Andric   }
1055ffd83dbSDimitry Andric 
1065ffd83dbSDimitry Andric   bool hasExtIntType() const override { return true; }
107*e8d8bef9SDimitry Andric 
108*e8d8bef9SDimitry Andric   bool hasInt128Type() const override { return false; }
1090b57cec5SDimitry Andric };
1100b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY SPIR32TargetInfo : public SPIRTargetInfo {
1110b57cec5SDimitry Andric public:
1120b57cec5SDimitry Andric   SPIR32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
1130b57cec5SDimitry Andric       : SPIRTargetInfo(Triple, Opts) {
1140b57cec5SDimitry Andric     PointerWidth = PointerAlign = 32;
1150b57cec5SDimitry Andric     SizeType = TargetInfo::UnsignedInt;
1160b57cec5SDimitry Andric     PtrDiffType = IntPtrType = TargetInfo::SignedInt;
1170b57cec5SDimitry Andric     resetDataLayout("e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-"
1180b57cec5SDimitry Andric                     "v96:128-v192:256-v256:256-v512:512-v1024:1024");
1190b57cec5SDimitry Andric   }
1200b57cec5SDimitry Andric 
1210b57cec5SDimitry Andric   void getTargetDefines(const LangOptions &Opts,
1220b57cec5SDimitry Andric                         MacroBuilder &Builder) const override;
1230b57cec5SDimitry Andric };
1240b57cec5SDimitry Andric 
1250b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY SPIR64TargetInfo : public SPIRTargetInfo {
1260b57cec5SDimitry Andric public:
1270b57cec5SDimitry Andric   SPIR64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
1280b57cec5SDimitry Andric       : SPIRTargetInfo(Triple, Opts) {
1290b57cec5SDimitry Andric     PointerWidth = PointerAlign = 64;
1300b57cec5SDimitry Andric     SizeType = TargetInfo::UnsignedLong;
1310b57cec5SDimitry Andric     PtrDiffType = IntPtrType = TargetInfo::SignedLong;
1320b57cec5SDimitry Andric     resetDataLayout("e-i64:64-v16:16-v24:32-v32:32-v48:64-"
1330b57cec5SDimitry Andric                     "v96:128-v192:256-v256:256-v512:512-v1024:1024");
1340b57cec5SDimitry Andric   }
1350b57cec5SDimitry Andric 
1360b57cec5SDimitry Andric   void getTargetDefines(const LangOptions &Opts,
1370b57cec5SDimitry Andric                         MacroBuilder &Builder) const override;
1380b57cec5SDimitry Andric };
1390b57cec5SDimitry Andric } // namespace targets
1400b57cec5SDimitry Andric } // namespace clang
1410b57cec5SDimitry Andric #endif // LLVM_CLANG_LIB_BASIC_TARGETS_SPIR_H
142