CodeGenTypeCache.h 3.3 KB

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