1*0b57cec5SDimitry Andric //===--- SPIR.h - Declare SPIR target feature support -----------*- C++ -*-===// 2*0b57cec5SDimitry Andric // 3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*0b57cec5SDimitry Andric // 7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 8*0b57cec5SDimitry Andric // 9*0b57cec5SDimitry Andric // This file declares SPIR TargetInfo objects. 10*0b57cec5SDimitry Andric // 11*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 12*0b57cec5SDimitry Andric 13*0b57cec5SDimitry Andric #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_SPIR_H 14*0b57cec5SDimitry Andric #define LLVM_CLANG_LIB_BASIC_TARGETS_SPIR_H 15*0b57cec5SDimitry Andric 16*0b57cec5SDimitry Andric #include "clang/Basic/TargetInfo.h" 17*0b57cec5SDimitry Andric #include "clang/Basic/TargetOptions.h" 18*0b57cec5SDimitry Andric #include "llvm/ADT/Triple.h" 19*0b57cec5SDimitry Andric #include "llvm/Support/Compiler.h" 20*0b57cec5SDimitry Andric 21*0b57cec5SDimitry Andric namespace clang { 22*0b57cec5SDimitry Andric namespace targets { 23*0b57cec5SDimitry Andric 24*0b57cec5SDimitry Andric static const unsigned SPIRAddrSpaceMap[] = { 25*0b57cec5SDimitry Andric 0, // Default 26*0b57cec5SDimitry Andric 1, // opencl_global 27*0b57cec5SDimitry Andric 3, // opencl_local 28*0b57cec5SDimitry Andric 2, // opencl_constant 29*0b57cec5SDimitry Andric 0, // opencl_private 30*0b57cec5SDimitry Andric 4, // opencl_generic 31*0b57cec5SDimitry Andric 0, // cuda_device 32*0b57cec5SDimitry Andric 0, // cuda_constant 33*0b57cec5SDimitry Andric 0 // cuda_shared 34*0b57cec5SDimitry Andric }; 35*0b57cec5SDimitry Andric 36*0b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY SPIRTargetInfo : public TargetInfo { 37*0b57cec5SDimitry Andric public: 38*0b57cec5SDimitry Andric SPIRTargetInfo(const llvm::Triple &Triple, const TargetOptions &) 39*0b57cec5SDimitry Andric : TargetInfo(Triple) { 40*0b57cec5SDimitry Andric assert(getTriple().getOS() == llvm::Triple::UnknownOS && 41*0b57cec5SDimitry Andric "SPIR target must use unknown OS"); 42*0b57cec5SDimitry Andric assert(getTriple().getEnvironment() == llvm::Triple::UnknownEnvironment && 43*0b57cec5SDimitry Andric "SPIR target must use unknown environment type"); 44*0b57cec5SDimitry Andric TLSSupported = false; 45*0b57cec5SDimitry Andric VLASupported = false; 46*0b57cec5SDimitry Andric LongWidth = LongAlign = 64; 47*0b57cec5SDimitry Andric AddrSpaceMap = &SPIRAddrSpaceMap; 48*0b57cec5SDimitry Andric UseAddrSpaceMapMangling = true; 49*0b57cec5SDimitry Andric HasLegalHalfType = true; 50*0b57cec5SDimitry Andric HasFloat16 = true; 51*0b57cec5SDimitry Andric // Define available target features 52*0b57cec5SDimitry Andric // These must be defined in sorted order! 53*0b57cec5SDimitry Andric NoAsmVariants = true; 54*0b57cec5SDimitry Andric } 55*0b57cec5SDimitry Andric 56*0b57cec5SDimitry Andric void getTargetDefines(const LangOptions &Opts, 57*0b57cec5SDimitry Andric MacroBuilder &Builder) const override; 58*0b57cec5SDimitry Andric 59*0b57cec5SDimitry Andric bool hasFeature(StringRef Feature) const override { 60*0b57cec5SDimitry Andric return Feature == "spir"; 61*0b57cec5SDimitry Andric } 62*0b57cec5SDimitry Andric 63*0b57cec5SDimitry Andric // SPIR supports the half type and the only llvm intrinsic allowed in SPIR is 64*0b57cec5SDimitry Andric // memcpy as per section 3 of the SPIR spec. 65*0b57cec5SDimitry Andric bool useFP16ConversionIntrinsics() const override { return false; } 66*0b57cec5SDimitry Andric 67*0b57cec5SDimitry Andric ArrayRef<Builtin::Info> getTargetBuiltins() const override { return None; } 68*0b57cec5SDimitry Andric 69*0b57cec5SDimitry Andric const char *getClobbers() const override { return ""; } 70*0b57cec5SDimitry Andric 71*0b57cec5SDimitry Andric ArrayRef<const char *> getGCCRegNames() const override { return None; } 72*0b57cec5SDimitry Andric 73*0b57cec5SDimitry Andric bool validateAsmConstraint(const char *&Name, 74*0b57cec5SDimitry Andric TargetInfo::ConstraintInfo &info) const override { 75*0b57cec5SDimitry Andric return true; 76*0b57cec5SDimitry Andric } 77*0b57cec5SDimitry Andric 78*0b57cec5SDimitry Andric ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override { 79*0b57cec5SDimitry Andric return None; 80*0b57cec5SDimitry Andric } 81*0b57cec5SDimitry Andric 82*0b57cec5SDimitry Andric BuiltinVaListKind getBuiltinVaListKind() const override { 83*0b57cec5SDimitry Andric return TargetInfo::VoidPtrBuiltinVaList; 84*0b57cec5SDimitry Andric } 85*0b57cec5SDimitry Andric 86*0b57cec5SDimitry Andric CallingConvCheckResult checkCallingConvention(CallingConv CC) const override { 87*0b57cec5SDimitry Andric return (CC == CC_SpirFunction || CC == CC_OpenCLKernel) ? CCCR_OK 88*0b57cec5SDimitry Andric : CCCR_Warning; 89*0b57cec5SDimitry Andric } 90*0b57cec5SDimitry Andric 91*0b57cec5SDimitry Andric CallingConv getDefaultCallingConv() const override { 92*0b57cec5SDimitry Andric return CC_SpirFunction; 93*0b57cec5SDimitry Andric } 94*0b57cec5SDimitry Andric 95*0b57cec5SDimitry Andric void setSupportedOpenCLOpts() override { 96*0b57cec5SDimitry Andric // Assume all OpenCL extensions and optional core features are supported 97*0b57cec5SDimitry Andric // for SPIR since it is a generic target. 98*0b57cec5SDimitry Andric getSupportedOpenCLOpts().supportAll(); 99*0b57cec5SDimitry Andric } 100*0b57cec5SDimitry Andric }; 101*0b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY SPIR32TargetInfo : public SPIRTargetInfo { 102*0b57cec5SDimitry Andric public: 103*0b57cec5SDimitry Andric SPIR32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) 104*0b57cec5SDimitry Andric : SPIRTargetInfo(Triple, Opts) { 105*0b57cec5SDimitry Andric PointerWidth = PointerAlign = 32; 106*0b57cec5SDimitry Andric SizeType = TargetInfo::UnsignedInt; 107*0b57cec5SDimitry Andric PtrDiffType = IntPtrType = TargetInfo::SignedInt; 108*0b57cec5SDimitry Andric resetDataLayout("e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-" 109*0b57cec5SDimitry Andric "v96:128-v192:256-v256:256-v512:512-v1024:1024"); 110*0b57cec5SDimitry Andric } 111*0b57cec5SDimitry Andric 112*0b57cec5SDimitry Andric void getTargetDefines(const LangOptions &Opts, 113*0b57cec5SDimitry Andric MacroBuilder &Builder) const override; 114*0b57cec5SDimitry Andric }; 115*0b57cec5SDimitry Andric 116*0b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY SPIR64TargetInfo : public SPIRTargetInfo { 117*0b57cec5SDimitry Andric public: 118*0b57cec5SDimitry Andric SPIR64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) 119*0b57cec5SDimitry Andric : SPIRTargetInfo(Triple, Opts) { 120*0b57cec5SDimitry Andric PointerWidth = PointerAlign = 64; 121*0b57cec5SDimitry Andric SizeType = TargetInfo::UnsignedLong; 122*0b57cec5SDimitry Andric PtrDiffType = IntPtrType = TargetInfo::SignedLong; 123*0b57cec5SDimitry Andric resetDataLayout("e-i64:64-v16:16-v24:32-v32:32-v48:64-" 124*0b57cec5SDimitry Andric "v96:128-v192:256-v256:256-v512:512-v1024:1024"); 125*0b57cec5SDimitry Andric } 126*0b57cec5SDimitry Andric 127*0b57cec5SDimitry Andric void getTargetDefines(const LangOptions &Opts, 128*0b57cec5SDimitry Andric MacroBuilder &Builder) const override; 129*0b57cec5SDimitry Andric }; 130*0b57cec5SDimitry Andric } // namespace targets 131*0b57cec5SDimitry Andric } // namespace clang 132*0b57cec5SDimitry Andric #endif // LLVM_CLANG_LIB_BASIC_TARGETS_SPIR_H 133