1 //===--- SPIR.h - Declare SPIR target feature support -----------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This file declares SPIR TargetInfo objects.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_SPIR_H
14 #define LLVM_CLANG_LIB_BASIC_TARGETS_SPIR_H
16 #include "clang/Basic/TargetInfo.h"
17 #include "clang/Basic/TargetOptions.h"
18 #include "llvm/ADT/Triple.h"
19 #include "llvm/Support/Compiler.h"
24 static const unsigned SPIRAddrSpaceMap[] = {
36 class LLVM_LIBRARY_VISIBILITY SPIRTargetInfo : public TargetInfo {
38 SPIRTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
39 : TargetInfo(Triple) {
40 assert(getTriple().getOS() == llvm::Triple::UnknownOS &&
41 "SPIR target must use unknown OS");
42 assert(getTriple().getEnvironment() == llvm::Triple::UnknownEnvironment &&
43 "SPIR target must use unknown environment type");
46 LongWidth = LongAlign = 64;
47 AddrSpaceMap = &SPIRAddrSpaceMap;
48 UseAddrSpaceMapMangling = true;
49 HasLegalHalfType = true;
51 // Define available target features
52 // These must be defined in sorted order!
56 void getTargetDefines(const LangOptions &Opts,
57 MacroBuilder &Builder) const override;
59 bool hasFeature(StringRef Feature) const override {
60 return Feature == "spir";
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; }
67 ArrayRef<Builtin::Info> getTargetBuiltins() const override { return None; }
69 const char *getClobbers() const override { return ""; }
71 ArrayRef<const char *> getGCCRegNames() const override { return None; }
73 bool validateAsmConstraint(const char *&Name,
74 TargetInfo::ConstraintInfo &info) const override {
78 ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override {
82 BuiltinVaListKind getBuiltinVaListKind() const override {
83 return TargetInfo::VoidPtrBuiltinVaList;
86 CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
87 return (CC == CC_SpirFunction || CC == CC_OpenCLKernel) ? CCCR_OK
91 CallingConv getDefaultCallingConv() const override {
92 return CC_SpirFunction;
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();
101 class LLVM_LIBRARY_VISIBILITY SPIR32TargetInfo : public SPIRTargetInfo {
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");
112 void getTargetDefines(const LangOptions &Opts,
113 MacroBuilder &Builder) const override;
116 class LLVM_LIBRARY_VISIBILITY SPIR64TargetInfo : public SPIRTargetInfo {
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");
127 void getTargetDefines(const LangOptions &Opts,
128 MacroBuilder &Builder) const override;
130 } // namespace targets
132 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_SPIR_H