clang 22.0.0git
CIRGenTypes.h
Go to the documentation of this file.
1//===--- CIRGenTypes.h - Type translation for CIR CodeGen -------*- 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 is the code that handles AST -> CIR type lowering.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_LIB_CODEGEN_CODEGENTYPES_H
14#define LLVM_CLANG_LIB_CODEGEN_CODEGENTYPES_H
15
16#include "ABIInfo.h"
17#include "CIRGenFunctionInfo.h"
18#include "CIRGenRecordLayout.h"
19
20#include "clang/AST/DeclCXX.h"
21#include "clang/AST/Type.h"
22#include "clang/Basic/ABI.h"
24
25#include "llvm/ADT/SmallPtrSet.h"
26
27namespace clang {
28class ASTContext;
29class FunctionType;
30class GlobalDecl;
31class QualType;
32class Type;
33} // namespace clang
34
35namespace mlir {
36class Type;
37}
38
39namespace clang::CIRGen {
40
41class CallArgList;
42class CIRGenBuilderTy;
43class CIRGenCXXABI;
44class CIRGenModule;
45
46/// This class organizes the cross-module state that is used while lowering
47/// AST types to CIR types.
49 CIRGenModule &cgm;
50 clang::ASTContext &astContext;
51 CIRGenBuilderTy &builder;
52 CIRGenCXXABI &theCXXABI;
53
54 const ABIInfo &theABIInfo;
55
56 /// Contains the CIR type for any converted RecordDecl.
57 llvm::DenseMap<const clang::Type *, std::unique_ptr<CIRGenRecordLayout>>
58 cirGenRecordLayouts;
59
60 /// Contains the CIR type for any converted RecordDecl
61 llvm::DenseMap<const clang::Type *, cir::RecordType> recordDeclTypes;
62
63 /// Hold memoized CIRGenFunctionInfo results
64 llvm::FoldingSet<CIRGenFunctionInfo> functionInfos;
65
66 /// This set keeps track of records that we're currently converting to a CIR
67 /// type. For example, when converting:
68 /// struct A { struct B { int x; } } when processing 'x', the 'A' and 'B'
69 /// types will be in this set.
71
73
74 /// Heper for convertType.
75 mlir::Type convertFunctionTypeInternal(clang::QualType ft);
76
77public:
80
81 CIRGenBuilderTy &getBuilder() const { return builder; }
82 CIRGenModule &getCGModule() const { return cgm; }
83
84 /// Utility to check whether a function type can be converted to a CIR type
85 /// (i.e. doesn't depend on an incomplete tag type).
88
89 /// Derives the 'this' type for CIRGen purposes, i.e. ignoring method CVR
90 /// qualification.
92 const clang::CXXMethodDecl *md);
93
94 /// This map of clang::Type to mlir::Type (which includes CIR type) is a
95 /// cache of types that have already been processed.
96 using TypeCacheTy = llvm::DenseMap<const clang::Type *, mlir::Type>;
98
99 mlir::MLIRContext &getMLIRContext() const;
100 clang::ASTContext &getASTContext() const { return astContext; }
101
102 bool isRecordLayoutComplete(const clang::Type *ty) const;
103 bool noRecordsBeingLaidOut() const { return recordsBeingLaidOut.empty(); }
104 bool isRecordBeingLaidOut(const clang::Type *ty) const {
105 return recordsBeingLaidOut.count(ty);
106 }
107
108 const ABIInfo &getABIInfo() const { return theABIInfo; }
109
110 /// Convert a Clang type into a mlir::Type.
111 mlir::Type convertType(clang::QualType type);
112
114
115 std::unique_ptr<CIRGenRecordLayout>
116 computeRecordLayout(const clang::RecordDecl *rd, cir::RecordType *ty);
117
118 std::string getRecordTypeName(const clang::RecordDecl *,
119 llvm::StringRef suffix);
120
122
123 /// Convert type T into an mlir::Type. This differs from convertType in that
124 /// it is used to convert to the memory representation for a type. For
125 /// example, the scalar representation for bool is i1, but the memory
126 /// representation is usually i8 or i32, depending on the target.
127 // TODO: convert this comment to account for MLIR's equivalence
128 mlir::Type convertTypeForMem(clang::QualType, bool forBitField = false);
129
130 /// Get the CIR function type for \arg Info.
131 cir::FuncType getFunctionType(const CIRGenFunctionInfo &info);
132
133 cir::FuncType getFunctionType(clang::GlobalDecl gd);
134
135 /// Get the CIR function type for use in a vtable, given a CXXMethodDecl. If
136 /// the method has an incomplete return type, and/or incomplete argument
137 /// types, this will return the opaque type.
139
140 // The arrangement methods are split into three families:
141 // - those meant to drive the signature and prologue/epilogue
142 // of a function declaration or definition,
143 // - those meant for the computation of the CIR type for an abstract
144 // appearance of a function, and
145 // - those meant for performing the CIR-generation of a call.
146 // They differ mainly in how they deal with optional (i.e. variadic)
147 // arguments, as well as unprototyped functions.
148 //
149 // Key points:
150 // - The CIRGenFunctionInfo for emitting a specific call site must include
151 // entries for the optional arguments.
152 // - The function type used at the call site must reflect the formal
153 // signature
154 // of the declaration being called, or else the call will go away.
155 // - For the most part, unprototyped functions are called by casting to a
156 // formal signature inferred from the specific argument types used at the
157 // call-site. However, some targets (e.g. x86-64) screw with this for
158 // compatability reasons.
159
161
162 /// UpdateCompletedType - when we find the full definition for a TagDecl,
163 /// replace the 'opaque' type we previously made for it if applicable.
164 void updateCompletedType(const clang::TagDecl *td);
165
166 /// Free functions are functions that are compatible with an ordinary C
167 /// function pointer type.
168 const CIRGenFunctionInfo &
170
171 /// Return whether a type can be zero-initialized (in the C++ sense) with an
172 /// LLVM zeroinitializer.
174 bool isZeroInitializable(const RecordDecl *rd);
175
177 const CallArgList &args, const clang::CXXConstructorDecl *d,
178 clang::CXXCtorType ctorKind, bool passProtoArgs = true);
179
180 const CIRGenFunctionInfo &
183 RequiredArgs required, unsigned numPrefixArgs);
184
185 /// C++ methods have some special rules and also have implicit parameters.
186 const CIRGenFunctionInfo &
189
190 const CIRGenFunctionInfo &
192 const clang::FunctionProtoType *ftp,
193 const clang::CXXMethodDecl *md);
194
196 const FunctionType *fnType);
197
198 const CIRGenFunctionInfo &
201 RequiredArgs required);
202
203 const CIRGenFunctionInfo &
205 const CIRGenFunctionInfo &
207};
208
209} // namespace clang::CIRGen
210
211#endif
Enums/classes describing ABI related information about constructors, destructors and thunks.
MatchType Type
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
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:188
Implements C++ ABI-specific code generation functions.
Definition: CIRGenCXXABI.h:26
This class organizes the cross-function state that is used while generating CIR code.
Definition: CIRGenModule.h:56
This class handles record and union layout info while lowering AST types to CIR types.
This class organizes the cross-module state that is used while lowering AST types to CIR types.
Definition: CIRGenTypes.h:48
CIRGenModule & getCGModule() const
Definition: CIRGenTypes.h:82
const CIRGenFunctionInfo & arrangeGlobalDeclaration(GlobalDecl gd)
const CIRGenFunctionInfo & arrangeCXXMethodDeclaration(const clang::CXXMethodDecl *md)
C++ methods have some special rules and also have implicit parameters.
Definition: CIRGenCall.cpp:396
const CIRGenFunctionInfo & arrangeCXXStructorDeclaration(clang::GlobalDecl gd)
Definition: CIRGenCall.cpp:179
const CIRGenFunctionInfo & arrangeFreeFunctionCall(const CallArgList &args, const FunctionType *fnType)
Definition: CIRGenCall.cpp:387
const CIRGenFunctionInfo & arrangeFreeFunctionType(CanQual< FunctionProtoType > fpt)
Definition: CIRGenCall.cpp:487
bool isZeroInitializable(clang::QualType ty)
Return whether a type can be zero-initialized (in the C++ sense) with an LLVM zeroinitializer.
bool isFuncTypeConvertible(const clang::FunctionType *ft)
Utility to check whether a function type can be converted to a CIR type (i.e.
Definition: CIRGenTypes.cpp:53
cir::FuncType getFunctionTypeForVTable(clang::GlobalDecl gd)
Get the CIR function type for use in a vtable, given a CXXMethodDecl.
Definition: CIRGenCall.cpp:63
bool isRecordBeingLaidOut(const clang::Type *ty) const
Definition: CIRGenTypes.h:104
CIRGenBuilderTy & getBuilder() const
Definition: CIRGenTypes.h:81
const CIRGenFunctionInfo & arrangeCXXMethodType(const clang::CXXRecordDecl *rd, const clang::FunctionProtoType *ftp, const clang::CXXMethodDecl *md)
Arrange the argument and result information for a call to an unknown C++ non-static member function o...
Definition: CIRGenCall.cpp:419
mlir::MLIRContext & getMLIRContext() const
Definition: CIRGenTypes.cpp:26
const CIRGenFunctionInfo & arrangeCIRFunctionInfo(CanQualType returnType, llvm::ArrayRef< CanQualType > argTypes, RequiredArgs required)
cir::FuncType getFunctionType(const CIRGenFunctionInfo &info)
Get the CIR function type for.
Definition: CIRGenCall.cpp:50
bool isFuncParamTypeConvertible(clang::QualType type)
Return true if the specified type in a function parameter or result position can be converted to a CI...
Definition: CIRGenTypes.cpp:34
clang::CanQualType deriveThisType(const clang::CXXRecordDecl *rd, const clang::CXXMethodDecl *md)
Derives the 'this' type for CIRGen purposes, i.e.
Definition: CIRGenCall.cpp:224
void updateCompletedType(const clang::TagDecl *td)
UpdateCompletedType - when we find the full definition for a TagDecl, replace the 'opaque' type we pr...
std::string getRecordTypeName(const clang::RecordDecl *, llvm::StringRef suffix)
Definition: CIRGenTypes.cpp:94
bool noRecordsBeingLaidOut() const
Definition: CIRGenTypes.h:103
const ABIInfo & getABIInfo() const
Definition: CIRGenTypes.h:108
const CIRGenFunctionInfo & arrangeCXXConstructorCall(const CallArgList &args, const clang::CXXConstructorDecl *d, clang::CXXCtorType ctorKind, bool passProtoArgs=true)
Arrange a call to a C++ method, passing the given arguments.
Definition: CIRGenCall.cpp:329
const CIRGenFunctionInfo & arrangeFunctionDeclaration(const clang::FunctionDecl *fd)
Free functions are functions that are compatible with an ordinary C function pointer type.
Definition: CIRGenCall.cpp:436
clang::ASTContext & getASTContext() const
Definition: CIRGenTypes.h:100
bool isRecordLayoutComplete(const clang::Type *ty) const
Return true if the specified type is already completely laid out.
const CIRGenFunctionInfo & arrangeCXXMethodCall(const CallArgList &args, const clang::FunctionProtoType *type, RequiredArgs required, unsigned numPrefixArgs)
Arrange a call to a C++ method, passing the given arguments.
Definition: CIRGenCall.cpp:367
mlir::Type convertType(clang::QualType type)
Convert a Clang type into a mlir::Type.
const CIRGenRecordLayout & getCIRGenRecordLayout(const clang::RecordDecl *rd)
Return record layout info for the given record decl.
std::unique_ptr< CIRGenRecordLayout > computeRecordLayout(const clang::RecordDecl *rd, cir::RecordType *ty)
mlir::Type convertRecordDeclType(const clang::RecordDecl *recordDecl)
Lay out a tagged decl type like struct or union.
mlir::Type convertTypeForMem(clang::QualType, bool forBitField=false)
Convert type T into an mlir::Type.
llvm::DenseMap< const clang::Type *, mlir::Type > TypeCacheTy
This map of clang::Type to mlir::Type (which includes CIR type) is a cache of types that have already...
Definition: CIRGenTypes.h:96
A class for recording the number of arguments that a function signature requires.
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2604
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2129
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
Represents a function declaration or definition.
Definition: Decl.h:1999
Represents a prototype with parameter type info, e.g.
Definition: TypeBase.h:5282
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition: TypeBase.h:4478
GlobalDecl - represents a global declaration.
Definition: GlobalDecl.h:57
A (possibly-)qualified type.
Definition: TypeBase.h:937
Represents a struct/union/class.
Definition: Decl.h:4309
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3714
The base class of the type hierarchy.
Definition: TypeBase.h:1833
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const internal::VariadicDynCastAllOfMatcher< Decl, RecordDecl > recordDecl
Matches class, struct, and union declarations.
The JSON file list parser is used to communicate input to InstallAPI.
CXXCtorType
C++ constructor types.
Definition: ABI.h:24