clang 23.0.0git
QualTypeMapper.h
Go to the documentation of this file.
1//==---- QualTypeMapper.h - Maps Clang QualType to LLVMABI Types -----------==//
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/// \file
10/// Maps Clang QualType instances to corresponding LLVM ABI type
11/// representations. This mapper translates high-level type information from the
12/// AST into low-level ABI-specific types that encode size, alignment, and
13/// layout details required for code generation and cross-language
14/// interoperability.
15///
16//===----------------------------------------------------------------------===//
17#ifndef CLANG_LIB_CODEGEN_QUALTYPE_MAPPER_H
18#define CLANG_LIB_CODEGEN_QUALTYPE_MAPPER_H
19
21#include "clang/AST/Decl.h"
22#include "clang/AST/Type.h"
24#include "llvm/ABI/Types.h"
25#include "llvm/ADT/DenseMap.h"
26#include "llvm/IR/DataLayout.h"
27#include "llvm/Support/Allocator.h"
28
29namespace clang {
30namespace CodeGen {
31
33private:
34 clang::ASTContext &ASTCtx;
35 const llvm::DataLayout &DL;
36 llvm::abi::TypeBuilder Builder;
37
38 llvm::DenseMap<QualType, const llvm::abi::Type *> TypeCache;
39
40 const llvm::abi::Type *convertTypeImpl(QualType QT);
41 const llvm::abi::Type *convertBuiltinType(const clang::BuiltinType *BT);
42 const llvm::abi::Type *convertArrayType(const clang::ArrayType *AT);
43 const llvm::abi::Type *convertVectorType(const clang::VectorType *VT);
44 const llvm::abi::Type *convertRecordType(const clang::RecordType *RT);
45 const llvm::abi::Type *convertEnumType(const clang::EnumType *ET);
46 const llvm::abi::Type *convertComplexType(const ComplexType *CT);
47 const llvm::abi::Type *
48 convertMemberPointerType(const clang::MemberPointerType *MPT);
49 const llvm::abi::Type *convertMatrixType(const ConstantMatrixType *MT);
50
51 const llvm::abi::RecordType *convertStructType(const clang::RecordDecl *RD);
52 const llvm::abi::RecordType *convertUnionType(const clang::RecordDecl *RD);
53 const llvm::abi::Type *createPointerTypeForPointee(QualType PointeeType);
54 const llvm::abi::RecordType *convertCXXRecordType(const CXXRecordDecl *RD);
55
56 void computeFieldInfo(const clang::RecordDecl *RD,
58 const clang::ASTRecordLayout &Layout);
59
60 llvm::TypeSize getTypeSize(clang::QualType QT) const;
61 llvm::Align getTypeAlign(clang::QualType QT) const;
62 uint64_t getPointerSize() const;
63 uint64_t getPointerAlign() const;
64
65public:
66 explicit QualTypeMapper(clang::ASTContext &Ctx, const llvm::DataLayout &DL,
67 llvm::BumpPtrAllocator &Alloc)
68 : ASTCtx(Ctx), DL(DL), Builder(Alloc) {}
69
70 const llvm::abi::Type *convertType(clang::QualType QT);
71
72 void clearCache() { TypeCache.clear(); }
73
74 llvm::abi::TypeBuilder getTypeBuilder() { return Builder; }
75};
76
77} // namespace CodeGen
78} // namespace clang
79
80#endif // CLANG_LIB_CODEGEN_QUALTYPE_MAPPER_H
Defines the clang::ASTContext interface.
Allows QualTypes to be sorted and hence used in maps and sets.
C Language Family Type Representation.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:226
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Definition TypeBase.h:3730
This class is used for builtin types like 'int'.
Definition TypeBase.h:3172
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
QualTypeMapper(clang::ASTContext &Ctx, const llvm::DataLayout &DL, llvm::BumpPtrAllocator &Alloc)
llvm::abi::TypeBuilder getTypeBuilder()
const llvm::abi::Type * convertType(clang::QualType QT)
Main entry point for converting Clang QualType to LLVM ABI Type.
Complex values, per C99 6.2.5p11.
Definition TypeBase.h:3283
Represents a concrete matrix type with constant number of rows and columns.
Definition TypeBase.h:4395
A pointer to member type per C++ 8.3.3 - Pointers to members.
Definition TypeBase.h:3661
A (possibly-)qualified type.
Definition TypeBase.h:937
Represents a struct/union/class.
Definition Decl.h:4327
Represents a GCC generic vector type.
Definition TypeBase.h:4183
The JSON file list parser is used to communicate input to InstallAPI.