1 //===--- CodeGenTypeCache.h - Commonly used LLVM types and info -*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This structure provides a set of common types useful during IR emission.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_CLANG_LIB_CODEGEN_CODEGENTYPECACHE_H
14 #define LLVM_CLANG_LIB_CODEGEN_CODEGENTYPECACHE_H
16 #include "clang/AST/CharUnits.h"
17 #include "clang/Basic/AddressSpaces.h"
18 #include "llvm/IR/CallingConv.h"
29 /// This structure provides a set of types that are commonly used
30 /// during IR emission. It's initialized once in CodeGenModule's
31 /// constructor and then copied around into new CodeGenFunctions.
32 struct CodeGenTypeCache
{
36 /// i8, i16, i32, and i64
37 llvm::IntegerType
*Int8Ty
, *Int16Ty
, *Int32Ty
, *Int64Ty
;
38 /// half, bfloat, float, double
39 llvm::Type
*HalfTy
, *BFloatTy
, *FloatTy
, *DoubleTy
;
42 llvm::IntegerType
*IntTy
;
45 llvm::IntegerType
*CharTy
;
47 /// intptr_t, size_t, and ptrdiff_t, which we assume are the same size.
49 llvm::IntegerType
*IntPtrTy
;
50 llvm::IntegerType
*SizeTy
;
51 llvm::IntegerType
*PtrDiffTy
;
54 /// void* in address space 0
56 llvm::PointerType
*VoidPtrTy
;
57 llvm::PointerType
*Int8PtrTy
;
60 /// void** in address space 0
62 llvm::PointerType
*VoidPtrPtrTy
;
63 llvm::PointerType
*Int8PtrPtrTy
;
66 /// void* in alloca address space
68 llvm::PointerType
*AllocaVoidPtrTy
;
69 llvm::PointerType
*AllocaInt8PtrTy
;
72 /// void* in default globals address space
74 llvm::PointerType
*GlobalsVoidPtrTy
;
75 llvm::PointerType
*GlobalsInt8PtrTy
;
78 /// void* in the address space for constant globals
79 llvm::PointerType
*ConstGlobalsPtrTy
;
81 /// The size and alignment of the builtin C type 'int'. This comes
82 /// up enough in various ABI lowering tasks to be worth pre-computing.
84 unsigned char IntSizeInBytes
;
85 unsigned char IntAlignInBytes
;
87 CharUnits
getIntSize() const {
88 return CharUnits::fromQuantity(IntSizeInBytes
);
90 CharUnits
getIntAlign() const {
91 return CharUnits::fromQuantity(IntAlignInBytes
);
94 /// The width of a pointer into the generic address space.
95 unsigned char PointerWidthInBits
;
97 /// The size and alignment of a pointer into the generic address space.
99 unsigned char PointerAlignInBytes
;
100 unsigned char PointerSizeInBytes
;
103 /// The size and alignment of size_t.
105 unsigned char SizeSizeInBytes
; // sizeof(size_t)
106 unsigned char SizeAlignInBytes
;
109 LangAS ASTAllocaAddressSpace
;
111 CharUnits
getSizeSize() const {
112 return CharUnits::fromQuantity(SizeSizeInBytes
);
114 CharUnits
getSizeAlign() const {
115 return CharUnits::fromQuantity(SizeAlignInBytes
);
117 CharUnits
getPointerSize() const {
118 return CharUnits::fromQuantity(PointerSizeInBytes
);
120 CharUnits
getPointerAlign() const {
121 return CharUnits::fromQuantity(PointerAlignInBytes
);
124 llvm::CallingConv::ID RuntimeCC
;
125 llvm::CallingConv::ID
getRuntimeCC() const { return RuntimeCC
; }
127 LangAS
getASTAllocaAddressSpace() const { return ASTAllocaAddressSpace
; }
130 } // end namespace CodeGen
131 } // end namespace clang