SPIR.h 4.4 KB

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