CodeGenTypeCache.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. //===--- CodeGenTypeCache.h - Commonly used LLVM types and info -*- 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 structure provides a set of common types useful during IR emission.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #ifndef LLVM_CLANG_LIB_CODEGEN_CODEGENTYPECACHE_H
  13. #define LLVM_CLANG_LIB_CODEGEN_CODEGENTYPECACHE_H
  14. #include "clang/AST/CharUnits.h"
  15. #include "clang/Basic/AddressSpaces.h"
  16. #include "llvm/IR/CallingConv.h"
  17. namespace llvm {
  18. class Type;
  19. class IntegerType;
  20. class PointerType;
  21. }
  22. namespace clang {
  23. namespace CodeGen {
  24. /// This structure provides a set of types that are commonly used
  25. /// during IR emission. It's initialized once in CodeGenModule's
  26. /// constructor and then copied around into new CodeGenFunctions.
  27. struct CodeGenTypeCache {
  28. /// void
  29. llvm::Type *VoidTy;
  30. /// i8, i16, i32, and i64
  31. llvm::IntegerType *Int8Ty, *Int16Ty, *Int32Ty, *Int64Ty;
  32. /// float, double
  33. llvm::Type *HalfTy, *FloatTy, *DoubleTy;
  34. /// int
  35. llvm::IntegerType *IntTy;
  36. /// intptr_t, size_t, and ptrdiff_t, which we assume are the same size.
  37. union {
  38. llvm::IntegerType *IntPtrTy;
  39. llvm::IntegerType *SizeTy;
  40. llvm::IntegerType *PtrDiffTy;
  41. };
  42. /// void* in address space 0
  43. union {
  44. llvm::PointerType *VoidPtrTy;
  45. llvm::PointerType *Int8PtrTy;
  46. };
  47. /// void** in address space 0
  48. union {
  49. llvm::PointerType *VoidPtrPtrTy;
  50. llvm::PointerType *Int8PtrPtrTy;
  51. };
  52. /// void* in alloca address space
  53. union {
  54. llvm::PointerType *AllocaVoidPtrTy;
  55. llvm::PointerType *AllocaInt8PtrTy;
  56. };
  57. /// The size and alignment of the builtin C type 'int'. This comes
  58. /// up enough in various ABI lowering tasks to be worth pre-computing.
  59. union {
  60. unsigned char IntSizeInBytes;
  61. unsigned char IntAlignInBytes;
  62. };
  63. CharUnits getIntSize() const {
  64. return CharUnits::fromQuantity(IntSizeInBytes);
  65. }
  66. CharUnits getIntAlign() const {
  67. return CharUnits::fromQuantity(IntAlignInBytes);
  68. }
  69. /// The width of a pointer into the generic address space.
  70. unsigned char PointerWidthInBits;
  71. /// The size and alignment of a pointer into the generic address space.
  72. union {
  73. unsigned char PointerAlignInBytes;
  74. unsigned char PointerSizeInBytes;
  75. };
  76. /// The size and alignment of size_t.
  77. union {
  78. unsigned char SizeSizeInBytes; // sizeof(size_t)
  79. unsigned char SizeAlignInBytes;
  80. };
  81. LangAS ASTAllocaAddressSpace;
  82. CharUnits getSizeSize() const {
  83. return CharUnits::fromQuantity(SizeSizeInBytes);
  84. }
  85. CharUnits getSizeAlign() const {
  86. return CharUnits::fromQuantity(SizeAlignInBytes);
  87. }
  88. CharUnits getPointerSize() const {
  89. return CharUnits::fromQuantity(PointerSizeInBytes);
  90. }
  91. CharUnits getPointerAlign() const {
  92. return CharUnits::fromQuantity(PointerAlignInBytes);
  93. }
  94. llvm::CallingConv::ID RuntimeCC;
  95. llvm::CallingConv::ID getRuntimeCC() const { return RuntimeCC; }
  96. LangAS getASTAllocaAddressSpace() const { return ASTAllocaAddressSpace; }
  97. };
  98. } // end namespace CodeGen
  99. } // end namespace clang
  100. #endif