Debian Codegraph @

clang/lib/CIR/CodeGen/CIRGenTypeCache.h

raw
1 //===--- CIRGenTypeCache.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 CIR emission.
10 //
11 //===----------------------------------------------------------------------===//
12
13 #ifndef LLVM_CLANG_LIB_CIR_CIRGENTYPECACHE_H
14 #define LLVM_CLANG_LIB_CIR_CIRGENTYPECACHE_H
15
16 #include "clang/AST/CharUnits.h"
17 #include "clang/Basic/AddressSpaces.h"
18 #include "clang/CIR/Dialect/IR/CIRTypes.h"
19
20 namespace clang::CIRGen {
21
22 /// This structure provides a set of types that are commonly used
23 /// during IR emission. It's initialized once in CodeGenModule's
24 /// constructor and then copied around into new CIRGenFunction's.
25 struct CIRGenTypeCache {
26 CIRGenTypeCache() {}
27
28 // ClangIR void type
29 cir::VoidType voidTy;
30
31 // ClangIR signed integral types of common sizes
32 cir::IntType sInt8Ty;
33 cir::IntType sInt16Ty;
34 cir::IntType sInt32Ty;
35 cir::IntType sInt64Ty;
36 cir::IntType sInt128Ty;
37
38 // ClangIR unsigned integral type of common sizes
39 cir::IntType uInt8Ty;
40 cir::IntType uInt16Ty;
41 cir::IntType uInt32Ty;
42 cir::IntType uInt64Ty;
43 cir::IntType uInt128Ty;
44
45 // ClangIR floating-point types with fixed formats
46 cir::FP16Type fP16Ty;
47 cir::BF16Type bFloat16Ty;
48 cir::SingleType floatTy;
49 cir::DoubleType doubleTy;
50 cir::FP80Type fP80Ty;
51 cir::FP128Type fP128Ty;
52
53 /// ClangIR char
54 mlir::Type uCharTy;
55
56 /// intptr_t, size_t, and ptrdiff_t, which we assume are the same size.
57 union {
58 mlir::Type uIntPtrTy;
59 mlir::Type sizeTy;
60 };
61
62 mlir::Type ptrDiffTy;
63
64 /// void* in address space 0
65 cir::PointerType voidPtrTy;
66 cir::PointerType uInt8PtrTy;
67
68 /// void* in alloca address space
69 cir::PointerType allocaInt8PtrTy;
70
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
77 /// The size and alignment of size_t.
78 union {
79 unsigned char SizeSizeInBytes; // sizeof(size_t)
80 unsigned char SizeAlignInBytes;
81 };
82
83 cir::TargetAddressSpaceAttr cirAllocaAddressSpace;
84
85 clang::CharUnits getSizeSize() const {
86 return clang::CharUnits::fromQuantity(SizeSizeInBytes);
87 }
88 clang::CharUnits getSizeAlign() const {
89 return clang::CharUnits::fromQuantity(SizeAlignInBytes);
90 }
91
92 clang::CharUnits getPointerAlign() const {
93 return clang::CharUnits::fromQuantity(PointerAlignInBytes);
94 }
95
96 cir::TargetAddressSpaceAttr getCIRAllocaAddressSpace() const {
97 return cirAllocaAddressSpace;
98 }
99 };
100
101 } // namespace clang::CIRGen
102
103 #endif // LLVM_CLANG_LIB_CIR_CODEGEN_CIRGENTYPECACHE_H