xref: /freebsd/contrib/llvm-project/clang/lib/Basic/Targets/SPIR.h (revision 480093f4440d54b30b3025afeac24b48f2ba7a2e)
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
310b57cec5SDimitry Andric     0, // cuda_device
320b57cec5SDimitry Andric     0, // cuda_constant
33*480093f4SDimitry Andric     0, // cuda_shared
34*480093f4SDimitry Andric     0, // ptr32_sptr
35*480093f4SDimitry Andric     0, // ptr32_uptr
36*480093f4SDimitry Andric     0  // ptr64
370b57cec5SDimitry Andric };
380b57cec5SDimitry Andric 
390b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY SPIRTargetInfo : public TargetInfo {
400b57cec5SDimitry Andric public:
410b57cec5SDimitry Andric   SPIRTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
420b57cec5SDimitry Andric       : TargetInfo(Triple) {
430b57cec5SDimitry Andric     assert(getTriple().getOS() == llvm::Triple::UnknownOS &&
440b57cec5SDimitry Andric            "SPIR target must use unknown OS");
450b57cec5SDimitry Andric     assert(getTriple().getEnvironment() == llvm::Triple::UnknownEnvironment &&
460b57cec5SDimitry Andric            "SPIR target must use unknown environment type");
470b57cec5SDimitry Andric     TLSSupported = false;
480b57cec5SDimitry Andric     VLASupported = false;
490b57cec5SDimitry Andric     LongWidth = LongAlign = 64;
500b57cec5SDimitry Andric     AddrSpaceMap = &SPIRAddrSpaceMap;
510b57cec5SDimitry Andric     UseAddrSpaceMapMangling = true;
520b57cec5SDimitry Andric     HasLegalHalfType = true;
530b57cec5SDimitry Andric     HasFloat16 = true;
540b57cec5SDimitry Andric     // Define available target features
550b57cec5SDimitry Andric     // These must be defined in sorted order!
560b57cec5SDimitry Andric     NoAsmVariants = true;
570b57cec5SDimitry Andric   }
580b57cec5SDimitry Andric 
590b57cec5SDimitry Andric   void getTargetDefines(const LangOptions &Opts,
600b57cec5SDimitry Andric                         MacroBuilder &Builder) const override;
610b57cec5SDimitry Andric 
620b57cec5SDimitry Andric   bool hasFeature(StringRef Feature) const override {
630b57cec5SDimitry Andric     return Feature == "spir";
640b57cec5SDimitry Andric   }
650b57cec5SDimitry Andric 
660b57cec5SDimitry Andric   // SPIR supports the half type and the only llvm intrinsic allowed in SPIR is
670b57cec5SDimitry Andric   // memcpy as per section 3 of the SPIR spec.
680b57cec5SDimitry Andric   bool useFP16ConversionIntrinsics() const override { return false; }
690b57cec5SDimitry Andric 
700b57cec5SDimitry Andric   ArrayRef<Builtin::Info> getTargetBuiltins() const override { return None; }
710b57cec5SDimitry Andric 
720b57cec5SDimitry Andric   const char *getClobbers() const override { return ""; }
730b57cec5SDimitry Andric 
740b57cec5SDimitry Andric   ArrayRef<const char *> getGCCRegNames() const override { return None; }
750b57cec5SDimitry Andric 
760b57cec5SDimitry Andric   bool validateAsmConstraint(const char *&Name,
770b57cec5SDimitry Andric                              TargetInfo::ConstraintInfo &info) const override {
780b57cec5SDimitry Andric     return true;
790b57cec5SDimitry Andric   }
800b57cec5SDimitry Andric 
810b57cec5SDimitry Andric   ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override {
820b57cec5SDimitry Andric     return None;
830b57cec5SDimitry Andric   }
840b57cec5SDimitry Andric 
850b57cec5SDimitry Andric   BuiltinVaListKind getBuiltinVaListKind() const override {
860b57cec5SDimitry Andric     return TargetInfo::VoidPtrBuiltinVaList;
870b57cec5SDimitry Andric   }
880b57cec5SDimitry Andric 
890b57cec5SDimitry Andric   CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
900b57cec5SDimitry Andric     return (CC == CC_SpirFunction || CC == CC_OpenCLKernel) ? CCCR_OK
910b57cec5SDimitry Andric                                                             : CCCR_Warning;
920b57cec5SDimitry Andric   }
930b57cec5SDimitry Andric 
940b57cec5SDimitry Andric   CallingConv getDefaultCallingConv() const override {
950b57cec5SDimitry Andric     return CC_SpirFunction;
960b57cec5SDimitry Andric   }
970b57cec5SDimitry Andric 
980b57cec5SDimitry Andric   void setSupportedOpenCLOpts() override {
990b57cec5SDimitry Andric     // Assume all OpenCL extensions and optional core features are supported
1000b57cec5SDimitry Andric     // for SPIR since it is a generic target.
1010b57cec5SDimitry Andric     getSupportedOpenCLOpts().supportAll();
1020b57cec5SDimitry Andric   }
1030b57cec5SDimitry Andric };
1040b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY SPIR32TargetInfo : public SPIRTargetInfo {
1050b57cec5SDimitry Andric public:
1060b57cec5SDimitry Andric   SPIR32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
1070b57cec5SDimitry Andric       : SPIRTargetInfo(Triple, Opts) {
1080b57cec5SDimitry Andric     PointerWidth = PointerAlign = 32;
1090b57cec5SDimitry Andric     SizeType = TargetInfo::UnsignedInt;
1100b57cec5SDimitry Andric     PtrDiffType = IntPtrType = TargetInfo::SignedInt;
1110b57cec5SDimitry Andric     resetDataLayout("e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-"
1120b57cec5SDimitry Andric                     "v96:128-v192:256-v256:256-v512:512-v1024:1024");
1130b57cec5SDimitry Andric   }
1140b57cec5SDimitry Andric 
1150b57cec5SDimitry Andric   void getTargetDefines(const LangOptions &Opts,
1160b57cec5SDimitry Andric                         MacroBuilder &Builder) const override;
1170b57cec5SDimitry Andric };
1180b57cec5SDimitry Andric 
1190b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY SPIR64TargetInfo : public SPIRTargetInfo {
1200b57cec5SDimitry Andric public:
1210b57cec5SDimitry Andric   SPIR64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
1220b57cec5SDimitry Andric       : SPIRTargetInfo(Triple, Opts) {
1230b57cec5SDimitry Andric     PointerWidth = PointerAlign = 64;
1240b57cec5SDimitry Andric     SizeType = TargetInfo::UnsignedLong;
1250b57cec5SDimitry Andric     PtrDiffType = IntPtrType = TargetInfo::SignedLong;
1260b57cec5SDimitry Andric     resetDataLayout("e-i64:64-v16:16-v24:32-v32:32-v48:64-"
1270b57cec5SDimitry Andric                     "v96:128-v192:256-v256:256-v512:512-v1024:1024");
1280b57cec5SDimitry Andric   }
1290b57cec5SDimitry Andric 
1300b57cec5SDimitry Andric   void getTargetDefines(const LangOptions &Opts,
1310b57cec5SDimitry Andric                         MacroBuilder &Builder) const override;
1320b57cec5SDimitry Andric };
1330b57cec5SDimitry Andric } // namespace targets
1340b57cec5SDimitry Andric } // namespace clang
1350b57cec5SDimitry Andric #endif // LLVM_CLANG_LIB_BASIC_TARGETS_SPIR_H
136