TargetBuiltins.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===--- TargetBuiltins.h - Target specific builtin IDs ---------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. ///
  14. /// \file
  15. /// Enumerates target-specific builtins in their own namespaces within
  16. /// namespace ::clang.
  17. ///
  18. //===----------------------------------------------------------------------===//
  19. #ifndef LLVM_CLANG_BASIC_TARGETBUILTINS_H
  20. #define LLVM_CLANG_BASIC_TARGETBUILTINS_H
  21. #include <algorithm>
  22. #include <stdint.h>
  23. #include "clang/Basic/Builtins.h"
  24. #include "llvm/Support/MathExtras.h"
  25. #undef PPC
  26. namespace clang {
  27. namespace NEON {
  28. enum {
  29. LastTIBuiltin = clang::Builtin::FirstTSBuiltin - 1,
  30. #define BUILTIN(ID, TYPE, ATTRS) BI##ID,
  31. #include "clang/Basic/BuiltinsNEON.def"
  32. FirstTSBuiltin
  33. };
  34. }
  35. /// ARM builtins
  36. namespace ARM {
  37. enum {
  38. LastTIBuiltin = clang::Builtin::FirstTSBuiltin-1,
  39. LastNEONBuiltin = NEON::FirstTSBuiltin - 1,
  40. #define BUILTIN(ID, TYPE, ATTRS) BI##ID,
  41. #include "clang/Basic/BuiltinsARM.def"
  42. LastTSBuiltin
  43. };
  44. }
  45. namespace SVE {
  46. enum {
  47. LastNEONBuiltin = NEON::FirstTSBuiltin - 1,
  48. #define BUILTIN(ID, TYPE, ATTRS) BI##ID,
  49. #include "clang/Basic/BuiltinsSVE.def"
  50. FirstTSBuiltin,
  51. };
  52. }
  53. /// AArch64 builtins
  54. namespace AArch64 {
  55. enum {
  56. LastTIBuiltin = clang::Builtin::FirstTSBuiltin - 1,
  57. LastNEONBuiltin = NEON::FirstTSBuiltin - 1,
  58. FirstSVEBuiltin = NEON::FirstTSBuiltin,
  59. LastSVEBuiltin = SVE::FirstTSBuiltin - 1,
  60. #define BUILTIN(ID, TYPE, ATTRS) BI##ID,
  61. #include "clang/Basic/BuiltinsAArch64.def"
  62. LastTSBuiltin
  63. };
  64. }
  65. /// BPF builtins
  66. namespace BPF {
  67. enum {
  68. LastTIBuiltin = clang::Builtin::FirstTSBuiltin - 1,
  69. #define BUILTIN(ID, TYPE, ATTRS) BI##ID,
  70. #include "clang/Basic/BuiltinsBPF.def"
  71. LastTSBuiltin
  72. };
  73. }
  74. /// PPC builtins
  75. namespace PPC {
  76. enum {
  77. LastTIBuiltin = clang::Builtin::FirstTSBuiltin-1,
  78. #define BUILTIN(ID, TYPE, ATTRS) BI##ID,
  79. #include "clang/Basic/BuiltinsPPC.def"
  80. LastTSBuiltin
  81. };
  82. }
  83. /// NVPTX builtins
  84. namespace NVPTX {
  85. enum {
  86. LastTIBuiltin = clang::Builtin::FirstTSBuiltin-1,
  87. #define BUILTIN(ID, TYPE, ATTRS) BI##ID,
  88. #include "clang/Basic/BuiltinsNVPTX.def"
  89. LastTSBuiltin
  90. };
  91. }
  92. /// AMDGPU builtins
  93. namespace AMDGPU {
  94. enum {
  95. LastTIBuiltin = clang::Builtin::FirstTSBuiltin - 1,
  96. #define BUILTIN(ID, TYPE, ATTRS) BI##ID,
  97. #include "clang/Basic/BuiltinsAMDGPU.def"
  98. LastTSBuiltin
  99. };
  100. }
  101. /// X86 builtins
  102. namespace X86 {
  103. enum {
  104. LastTIBuiltin = clang::Builtin::FirstTSBuiltin - 1,
  105. #define BUILTIN(ID, TYPE, ATTRS) BI##ID,
  106. #include "clang/Basic/BuiltinsX86.def"
  107. FirstX86_64Builtin,
  108. LastX86CommonBuiltin = FirstX86_64Builtin - 1,
  109. #define BUILTIN(ID, TYPE, ATTRS) BI##ID,
  110. #include "clang/Basic/BuiltinsX86_64.def"
  111. LastTSBuiltin
  112. };
  113. }
  114. /// VE builtins
  115. namespace VE {
  116. enum { LastTIBuiltin = clang::Builtin::FirstTSBuiltin - 1, LastTSBuiltin };
  117. }
  118. namespace RISCVVector {
  119. enum {
  120. LastTIBuiltin = clang::Builtin::FirstTSBuiltin - 1,
  121. #define BUILTIN(ID, TYPE, ATTRS) BI##ID,
  122. #include "clang/Basic/BuiltinsRISCVVector.def"
  123. FirstTSBuiltin,
  124. };
  125. }
  126. /// RISCV builtins
  127. namespace RISCV {
  128. enum {
  129. LastTIBuiltin = clang::Builtin::FirstTSBuiltin - 1,
  130. FirstRVVBuiltin = clang::Builtin::FirstTSBuiltin,
  131. LastRVVBuiltin = RISCVVector::FirstTSBuiltin - 1,
  132. #define BUILTIN(ID, TYPE, ATTRS) BI##ID,
  133. #include "clang/Basic/BuiltinsRISCV.def"
  134. LastTSBuiltin
  135. };
  136. } // namespace RISCV
  137. /// Flags to identify the types for overloaded Neon builtins.
  138. ///
  139. /// These must be kept in sync with the flags in utils/TableGen/NeonEmitter.h.
  140. class NeonTypeFlags {
  141. enum {
  142. EltTypeMask = 0xf,
  143. UnsignedFlag = 0x10,
  144. QuadFlag = 0x20
  145. };
  146. uint32_t Flags;
  147. public:
  148. enum EltType {
  149. Int8,
  150. Int16,
  151. Int32,
  152. Int64,
  153. Poly8,
  154. Poly16,
  155. Poly64,
  156. Poly128,
  157. Float16,
  158. Float32,
  159. Float64,
  160. BFloat16
  161. };
  162. NeonTypeFlags(unsigned F) : Flags(F) {}
  163. NeonTypeFlags(EltType ET, bool IsUnsigned, bool IsQuad) : Flags(ET) {
  164. if (IsUnsigned)
  165. Flags |= UnsignedFlag;
  166. if (IsQuad)
  167. Flags |= QuadFlag;
  168. }
  169. EltType getEltType() const { return (EltType)(Flags & EltTypeMask); }
  170. bool isPoly() const {
  171. EltType ET = getEltType();
  172. return ET == Poly8 || ET == Poly16 || ET == Poly64;
  173. }
  174. bool isUnsigned() const { return (Flags & UnsignedFlag) != 0; }
  175. bool isQuad() const { return (Flags & QuadFlag) != 0; }
  176. };
  177. /// Flags to identify the types for overloaded SVE builtins.
  178. class SVETypeFlags {
  179. uint64_t Flags;
  180. unsigned EltTypeShift;
  181. unsigned MemEltTypeShift;
  182. unsigned MergeTypeShift;
  183. unsigned SplatOperandMaskShift;
  184. public:
  185. #define LLVM_GET_SVE_TYPEFLAGS
  186. #include "clang/Basic/arm_sve_typeflags.inc"
  187. #undef LLVM_GET_SVE_TYPEFLAGS
  188. enum EltType {
  189. #define LLVM_GET_SVE_ELTTYPES
  190. #include "clang/Basic/arm_sve_typeflags.inc"
  191. #undef LLVM_GET_SVE_ELTTYPES
  192. };
  193. enum MemEltType {
  194. #define LLVM_GET_SVE_MEMELTTYPES
  195. #include "clang/Basic/arm_sve_typeflags.inc"
  196. #undef LLVM_GET_SVE_MEMELTTYPES
  197. };
  198. enum MergeType {
  199. #define LLVM_GET_SVE_MERGETYPES
  200. #include "clang/Basic/arm_sve_typeflags.inc"
  201. #undef LLVM_GET_SVE_MERGETYPES
  202. };
  203. enum ImmCheckType {
  204. #define LLVM_GET_SVE_IMMCHECKTYPES
  205. #include "clang/Basic/arm_sve_typeflags.inc"
  206. #undef LLVM_GET_SVE_IMMCHECKTYPES
  207. };
  208. SVETypeFlags(uint64_t F) : Flags(F) {
  209. EltTypeShift = llvm::countTrailingZeros(EltTypeMask);
  210. MemEltTypeShift = llvm::countTrailingZeros(MemEltTypeMask);
  211. MergeTypeShift = llvm::countTrailingZeros(MergeTypeMask);
  212. SplatOperandMaskShift = llvm::countTrailingZeros(SplatOperandMask);
  213. }
  214. EltType getEltType() const {
  215. return (EltType)((Flags & EltTypeMask) >> EltTypeShift);
  216. }
  217. MemEltType getMemEltType() const {
  218. return (MemEltType)((Flags & MemEltTypeMask) >> MemEltTypeShift);
  219. }
  220. MergeType getMergeType() const {
  221. return (MergeType)((Flags & MergeTypeMask) >> MergeTypeShift);
  222. }
  223. unsigned getSplatOperand() const {
  224. return ((Flags & SplatOperandMask) >> SplatOperandMaskShift) - 1;
  225. }
  226. bool hasSplatOperand() const {
  227. return Flags & SplatOperandMask;
  228. }
  229. bool isLoad() const { return Flags & IsLoad; }
  230. bool isStore() const { return Flags & IsStore; }
  231. bool isGatherLoad() const { return Flags & IsGatherLoad; }
  232. bool isScatterStore() const { return Flags & IsScatterStore; }
  233. bool isStructLoad() const { return Flags & IsStructLoad; }
  234. bool isStructStore() const { return Flags & IsStructStore; }
  235. bool isZExtReturn() const { return Flags & IsZExtReturn; }
  236. bool isByteIndexed() const { return Flags & IsByteIndexed; }
  237. bool isOverloadNone() const { return Flags & IsOverloadNone; }
  238. bool isOverloadWhile() const { return Flags & IsOverloadWhile; }
  239. bool isOverloadDefault() const { return !(Flags & OverloadKindMask); }
  240. bool isOverloadWhileRW() const { return Flags & IsOverloadWhileRW; }
  241. bool isOverloadCvt() const { return Flags & IsOverloadCvt; }
  242. bool isPrefetch() const { return Flags & IsPrefetch; }
  243. bool isReverseCompare() const { return Flags & ReverseCompare; }
  244. bool isAppendSVALL() const { return Flags & IsAppendSVALL; }
  245. bool isInsertOp1SVALL() const { return Flags & IsInsertOp1SVALL; }
  246. bool isGatherPrefetch() const { return Flags & IsGatherPrefetch; }
  247. bool isReverseUSDOT() const { return Flags & ReverseUSDOT; }
  248. bool isUndef() const { return Flags & IsUndef; }
  249. bool isTupleCreate() const { return Flags & IsTupleCreate; }
  250. bool isTupleGet() const { return Flags & IsTupleGet; }
  251. bool isTupleSet() const { return Flags & IsTupleSet; }
  252. uint64_t getBits() const { return Flags; }
  253. bool isFlagSet(uint64_t Flag) const { return Flags & Flag; }
  254. };
  255. /// Hexagon builtins
  256. namespace Hexagon {
  257. enum {
  258. LastTIBuiltin = clang::Builtin::FirstTSBuiltin-1,
  259. #define BUILTIN(ID, TYPE, ATTRS) BI##ID,
  260. #include "clang/Basic/BuiltinsHexagon.def"
  261. LastTSBuiltin
  262. };
  263. }
  264. /// MIPS builtins
  265. namespace Mips {
  266. enum {
  267. LastTIBuiltin = clang::Builtin::FirstTSBuiltin-1,
  268. #define BUILTIN(ID, TYPE, ATTRS) BI##ID,
  269. #include "clang/Basic/BuiltinsMips.def"
  270. LastTSBuiltin
  271. };
  272. }
  273. /// XCore builtins
  274. namespace XCore {
  275. enum {
  276. LastTIBuiltin = clang::Builtin::FirstTSBuiltin-1,
  277. #define BUILTIN(ID, TYPE, ATTRS) BI##ID,
  278. #include "clang/Basic/BuiltinsXCore.def"
  279. LastTSBuiltin
  280. };
  281. }
  282. /// SystemZ builtins
  283. namespace SystemZ {
  284. enum {
  285. LastTIBuiltin = clang::Builtin::FirstTSBuiltin-1,
  286. #define BUILTIN(ID, TYPE, ATTRS) BI##ID,
  287. #include "clang/Basic/BuiltinsSystemZ.def"
  288. LastTSBuiltin
  289. };
  290. }
  291. /// WebAssembly builtins
  292. namespace WebAssembly {
  293. enum {
  294. LastTIBuiltin = clang::Builtin::FirstTSBuiltin-1,
  295. #define BUILTIN(ID, TYPE, ATTRS) BI##ID,
  296. #include "clang/Basic/BuiltinsWebAssembly.def"
  297. LastTSBuiltin
  298. };
  299. }
  300. static constexpr uint64_t LargestBuiltinID = std::max<uint64_t>(
  301. {ARM::LastTSBuiltin, AArch64::LastTSBuiltin, BPF::LastTSBuiltin,
  302. PPC::LastTSBuiltin, NVPTX::LastTSBuiltin, AMDGPU::LastTSBuiltin,
  303. X86::LastTSBuiltin, VE::LastTSBuiltin, RISCV::LastTSBuiltin,
  304. Hexagon::LastTSBuiltin, Mips::LastTSBuiltin, XCore::LastTSBuiltin,
  305. SystemZ::LastTSBuiltin, WebAssembly::LastTSBuiltin});
  306. } // end namespace clang.
  307. #endif
  308. #ifdef __GNUC__
  309. #pragma GCC diagnostic pop
  310. #endif