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[] = {
39 class LLVM_LIBRARY_VISIBILITY SPIRTargetInfo : public TargetInfo {
41 SPIRTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
42 : TargetInfo(Triple) {
43 assert(getTriple().getOS() == llvm::Triple::UnknownOS &&
44 "SPIR target must use unknown OS");
45 assert(getTriple().getEnvironment() == llvm::Triple::UnknownEnvironment &&
46 "SPIR target must use unknown environment type");
49 LongWidth = LongAlign = 64;
50 AddrSpaceMap = &SPIRAddrSpaceMap;
51 UseAddrSpaceMapMangling = true;
52 HasLegalHalfType = true;
54 // Define available target features
55 // These must be defined in sorted order!
59 void getTargetDefines(const LangOptions &Opts,
60 MacroBuilder &Builder) const override;
62 bool hasFeature(StringRef Feature) const override {
63 return Feature == "spir";
66 // SPIR supports the half type and the only llvm intrinsic allowed in SPIR is
67 // memcpy as per section 3 of the SPIR spec.
68 bool useFP16ConversionIntrinsics() const override { return false; }
70 ArrayRef<Builtin::Info> getTargetBuiltins() const override { return None; }
72 const char *getClobbers() const override { return ""; }
74 ArrayRef<const char *> getGCCRegNames() const override { return None; }
76 bool validateAsmConstraint(const char *&Name,
77 TargetInfo::ConstraintInfo &info) const override {
81 ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override {
85 BuiltinVaListKind getBuiltinVaListKind() const override {
86 return TargetInfo::VoidPtrBuiltinVaList;
89 CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
90 return (CC == CC_SpirFunction || CC == CC_OpenCLKernel) ? CCCR_OK
94 CallingConv getDefaultCallingConv() const override {
95 return CC_SpirFunction;
98 void setSupportedOpenCLOpts() override {
99 // Assume all OpenCL extensions and optional core features are supported
100 // for SPIR since it is a generic target.
101 getSupportedOpenCLOpts().supportAll();
104 class LLVM_LIBRARY_VISIBILITY SPIR32TargetInfo : public SPIRTargetInfo {
106 SPIR32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
107 : SPIRTargetInfo(Triple, Opts) {
108 PointerWidth = PointerAlign = 32;
109 SizeType = TargetInfo::UnsignedInt;
110 PtrDiffType = IntPtrType = TargetInfo::SignedInt;
111 resetDataLayout("e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-"
112 "v96:128-v192:256-v256:256-v512:512-v1024:1024");
115 void getTargetDefines(const LangOptions &Opts,
116 MacroBuilder &Builder) const override;
119 class LLVM_LIBRARY_VISIBILITY SPIR64TargetInfo : public SPIRTargetInfo {
121 SPIR64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
122 : SPIRTargetInfo(Triple, Opts) {
123 PointerWidth = PointerAlign = 64;
124 SizeType = TargetInfo::UnsignedLong;
125 PtrDiffType = IntPtrType = TargetInfo::SignedLong;
126 resetDataLayout("e-i64:64-v16:16-v24:32-v32:32-v48:64-"
127 "v96:128-v192:256-v256:256-v512:512-v1024:1024");
130 void getTargetDefines(const LangOptions &Opts,
131 MacroBuilder &Builder) const override;
133 } // namespace targets
135 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_SPIR_H