17f416cc4SJohn McCall //===--- CodeGenTypeCache.h - Commonly used LLVM types and info -*- C++ -*-===//
27f416cc4SJohn McCall //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
67f416cc4SJohn McCall //
77f416cc4SJohn McCall //===----------------------------------------------------------------------===//
87f416cc4SJohn McCall //
97f416cc4SJohn McCall // This structure provides a set of common types useful during IR emission.
107f416cc4SJohn McCall //
117f416cc4SJohn McCall //===----------------------------------------------------------------------===//
127f416cc4SJohn McCall 
137f416cc4SJohn McCall #ifndef LLVM_CLANG_LIB_CODEGEN_CODEGENTYPECACHE_H
147f416cc4SJohn McCall #define LLVM_CLANG_LIB_CODEGEN_CODEGENTYPECACHE_H
157f416cc4SJohn McCall 
167f416cc4SJohn McCall #include "clang/AST/CharUnits.h"
176d989436SAlexander Richardson #include "clang/Basic/AddressSpaces.h"
187f416cc4SJohn McCall #include "llvm/IR/CallingConv.h"
197f416cc4SJohn McCall 
207f416cc4SJohn McCall namespace llvm {
217f416cc4SJohn McCall   class Type;
227f416cc4SJohn McCall   class IntegerType;
237f416cc4SJohn McCall   class PointerType;
247f416cc4SJohn McCall }
257f416cc4SJohn McCall 
267f416cc4SJohn McCall namespace clang {
277f416cc4SJohn McCall namespace CodeGen {
287f416cc4SJohn McCall 
297f416cc4SJohn McCall /// This structure provides a set of types that are commonly used
307f416cc4SJohn McCall /// during IR emission.  It's initialized once in CodeGenModule's
317f416cc4SJohn McCall /// constructor and then copied around into new CodeGenFunctions.
327f416cc4SJohn McCall struct CodeGenTypeCache {
337f416cc4SJohn McCall   /// void
347f416cc4SJohn McCall   llvm::Type *VoidTy;
357f416cc4SJohn McCall 
367f416cc4SJohn McCall   /// i8, i16, i32, and i64
377f416cc4SJohn McCall   llvm::IntegerType *Int8Ty, *Int16Ty, *Int32Ty, *Int64Ty;
38ecd682bbSTies Stuij   /// half, bfloat, float, double
39ecd682bbSTies Stuij   llvm::Type *HalfTy, *BFloatTy, *FloatTy, *DoubleTy;
407f416cc4SJohn McCall 
417f416cc4SJohn McCall   /// int
427f416cc4SJohn McCall   llvm::IntegerType *IntTy;
437f416cc4SJohn McCall 
44ea2cfda3SBjorn Pettersson   /// char
45ea2cfda3SBjorn Pettersson   llvm::IntegerType *CharTy;
46ea2cfda3SBjorn Pettersson 
477f416cc4SJohn McCall   /// intptr_t, size_t, and ptrdiff_t, which we assume are the same size.
487f416cc4SJohn McCall   union {
497f416cc4SJohn McCall     llvm::IntegerType *IntPtrTy;
507f416cc4SJohn McCall     llvm::IntegerType *SizeTy;
517f416cc4SJohn McCall     llvm::IntegerType *PtrDiffTy;
527f416cc4SJohn McCall   };
537f416cc4SJohn McCall 
547f416cc4SJohn McCall   /// void* in address space 0
557f416cc4SJohn McCall   union {
567f416cc4SJohn McCall     llvm::PointerType *VoidPtrTy;
577f416cc4SJohn McCall     llvm::PointerType *Int8PtrTy;
587f416cc4SJohn McCall   };
597f416cc4SJohn McCall 
607f416cc4SJohn McCall   /// void** in address space 0
617f416cc4SJohn McCall   union {
627f416cc4SJohn McCall     llvm::PointerType *VoidPtrPtrTy;
637f416cc4SJohn McCall     llvm::PointerType *Int8PtrPtrTy;
647f416cc4SJohn McCall   };
657f416cc4SJohn McCall 
667f7f323eSYaxun Liu   /// void* in alloca address space
677f7f323eSYaxun Liu   union {
687f7f323eSYaxun Liu     llvm::PointerType *AllocaVoidPtrTy;
697f7f323eSYaxun Liu     llvm::PointerType *AllocaInt8PtrTy;
707f7f323eSYaxun Liu   };
717f7f323eSYaxun Liu 
72*7cab90a7SAlex Richardson   /// void* in default globals address space
73*7cab90a7SAlex Richardson   union {
74*7cab90a7SAlex Richardson     llvm::PointerType *GlobalsVoidPtrTy;
75*7cab90a7SAlex Richardson     llvm::PointerType *GlobalsInt8PtrTy;
76*7cab90a7SAlex Richardson   };
77*7cab90a7SAlex Richardson 
787f416cc4SJohn McCall   /// The size and alignment of the builtin C type 'int'.  This comes
797f416cc4SJohn McCall   /// up enough in various ABI lowering tasks to be worth pre-computing.
807f416cc4SJohn McCall   union {
817f416cc4SJohn McCall     unsigned char IntSizeInBytes;
827f416cc4SJohn McCall     unsigned char IntAlignInBytes;
837f416cc4SJohn McCall   };
getIntSizeCodeGenTypeCache847f416cc4SJohn McCall   CharUnits getIntSize() const {
857f416cc4SJohn McCall     return CharUnits::fromQuantity(IntSizeInBytes);
867f416cc4SJohn McCall   }
getIntAlignCodeGenTypeCache877f416cc4SJohn McCall   CharUnits getIntAlign() const {
887f416cc4SJohn McCall     return CharUnits::fromQuantity(IntAlignInBytes);
897f416cc4SJohn McCall   }
907f416cc4SJohn McCall 
917f416cc4SJohn McCall   /// The width of a pointer into the generic address space.
927f416cc4SJohn McCall   unsigned char PointerWidthInBits;
937f416cc4SJohn McCall 
947f416cc4SJohn McCall   /// The size and alignment of a pointer into the generic address space.
957f416cc4SJohn McCall   union {
967f416cc4SJohn McCall     unsigned char PointerAlignInBytes;
977f416cc4SJohn McCall     unsigned char PointerSizeInBytes;
9826f7566fSYaxun Liu   };
9926f7566fSYaxun Liu 
10026f7566fSYaxun Liu   /// The size and alignment of size_t.
10126f7566fSYaxun Liu   union {
1027f416cc4SJohn McCall     unsigned char SizeSizeInBytes; // sizeof(size_t)
1037f416cc4SJohn McCall     unsigned char SizeAlignInBytes;
1047f416cc4SJohn McCall   };
10526f7566fSYaxun Liu 
1066d989436SAlexander Richardson   LangAS ASTAllocaAddressSpace;
1076d96f163SYaxun Liu 
getSizeSizeCodeGenTypeCache1087f416cc4SJohn McCall   CharUnits getSizeSize() const {
1097f416cc4SJohn McCall     return CharUnits::fromQuantity(SizeSizeInBytes);
1107f416cc4SJohn McCall   }
getSizeAlignCodeGenTypeCache1117f416cc4SJohn McCall   CharUnits getSizeAlign() const {
1127f416cc4SJohn McCall     return CharUnits::fromQuantity(SizeAlignInBytes);
1137f416cc4SJohn McCall   }
getPointerSizeCodeGenTypeCache1147f416cc4SJohn McCall   CharUnits getPointerSize() const {
1157f416cc4SJohn McCall     return CharUnits::fromQuantity(PointerSizeInBytes);
1167f416cc4SJohn McCall   }
getPointerAlignCodeGenTypeCache1177f416cc4SJohn McCall   CharUnits getPointerAlign() const {
1187f416cc4SJohn McCall     return CharUnits::fromQuantity(PointerAlignInBytes);
1197f416cc4SJohn McCall   }
1207f416cc4SJohn McCall 
1217f416cc4SJohn McCall   llvm::CallingConv::ID RuntimeCC;
getRuntimeCCCodeGenTypeCache1227f416cc4SJohn McCall   llvm::CallingConv::ID getRuntimeCC() const { return RuntimeCC; }
1236d96f163SYaxun Liu 
getASTAllocaAddressSpaceCodeGenTypeCache1246d989436SAlexander Richardson   LangAS getASTAllocaAddressSpace() const { return ASTAllocaAddressSpace; }
1257f416cc4SJohn McCall };
1267f416cc4SJohn McCall 
1277f416cc4SJohn McCall }  // end namespace CodeGen
1287f416cc4SJohn McCall }  // end namespace clang
1297f416cc4SJohn McCall 
1307f416cc4SJohn McCall #endif
131