xref: /freebsd/contrib/llvm-project/clang/lib/CIR/CodeGen/CIRGenTypeCache.h (revision 700637cbb5e582861067a11aaca4d053546871d2)
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/CIR/Dialect/IR/CIRTypes.h"
18 
19 namespace clang::CIRGen {
20 
21 /// This structure provides a set of types that are commonly used
22 /// during IR emission. It's initialized once in CodeGenModule's
23 /// constructor and then copied around into new CIRGenFunction's.
24 struct CIRGenTypeCache {
CIRGenTypeCacheCIRGenTypeCache25   CIRGenTypeCache() {}
26 
27   // ClangIR void type
28   cir::VoidType VoidTy;
29 
30   // ClangIR signed integral types of common sizes
31   cir::IntType SInt8Ty;
32   cir::IntType SInt16Ty;
33   cir::IntType SInt32Ty;
34   cir::IntType SInt64Ty;
35   cir::IntType SInt128Ty;
36 
37   // ClangIR unsigned integral type of common sizes
38   cir::IntType UInt8Ty;
39   cir::IntType UInt16Ty;
40   cir::IntType UInt32Ty;
41   cir::IntType UInt64Ty;
42   cir::IntType UInt128Ty;
43 
44   // ClangIR floating-point types with fixed formats
45   cir::FP16Type FP16Ty;
46   cir::BF16Type BFloat16Ty;
47   cir::SingleType FloatTy;
48   cir::DoubleType DoubleTy;
49   cir::FP80Type FP80Ty;
50   cir::FP128Type FP128Ty;
51 
52   /// intptr_t, size_t, and ptrdiff_t, which we assume are the same size.
53   union {
54     mlir::Type UIntPtrTy;
55     mlir::Type SizeTy;
56   };
57 
58   mlir::Type PtrDiffTy;
59 
60   /// void* in address space 0
61   cir::PointerType VoidPtrTy;
62 
63   /// The size and alignment of a pointer into the generic address space.
64   union {
65     unsigned char PointerAlignInBytes;
66     unsigned char PointerSizeInBytes;
67   };
68 
69   /// The alignment of size_t.
70   unsigned char SizeAlignInBytes;
71 
getSizeAlignCIRGenTypeCache72   clang::CharUnits getSizeAlign() const {
73     return clang::CharUnits::fromQuantity(SizeAlignInBytes);
74   }
75 
getPointerAlignCIRGenTypeCache76   clang::CharUnits getPointerAlign() const {
77     return clang::CharUnits::fromQuantity(PointerAlignInBytes);
78   }
79 };
80 
81 } // namespace clang::CIRGen
82 
83 #endif // LLVM_CLANG_LIB_CIR_CODEGEN_CIRGENTYPECACHE_H
84