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