clang 23.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 TargetInfo;
33class Type;
34} // namespace clang
35
36namespace mlir {
37class Type;
38}
39
40namespace clang::CIRGen {
41
42class CallArgList;
43class CIRGenBuilderTy;
44class CIRGenCXXABI;
45class CIRGenModule;
46
47/// This class organizes the cross-module state that is used while lowering
48/// AST types to CIR types.
50 CIRGenModule &cgm;
51 clang::ASTContext &astContext;
52 CIRGenBuilderTy &builder;
53 CIRGenCXXABI &theCXXABI;
54
55 const ABIInfo &theABIInfo;
56
57 /// Contains the CIR type for any converted RecordDecl.
58 llvm::DenseMap<const clang::Type *, std::unique_ptr<CIRGenRecordLayout>>
59 cirGenRecordLayouts;
60
61 /// Contains the CIR type for any converted RecordDecl
62 llvm::DenseMap<const clang::Type *, cir::RecordType> recordDeclTypes;
63
64 /// Hold memoized CIRGenFunctionInfo results
65 llvm::FoldingSet<CIRGenFunctionInfo> functionInfos;
66
67 /// This set keeps track of records that we're currently converting to a CIR
68 /// type. For example, when converting:
69 /// struct A { struct B { int x; } } when processing 'x', the 'A' and 'B'
70 /// types will be in this set.
72
74
75 /// Heper for convertType.
76 mlir::Type convertFunctionTypeInternal(clang::QualType ft);
77
78public:
81
82 CIRGenBuilderTy &getBuilder() const { return builder; }
83 CIRGenModule &getCGModule() const { return cgm; }
84
85 /// Utility to check whether a function type can be converted to a CIR type
86 /// (i.e. doesn't depend on an incomplete tag type).
89
90 /// Derives the 'this' type for CIRGen purposes, i.e. ignoring method CVR
91 /// qualification.
93 const clang::CXXMethodDecl *md);
94
95 /// This map of clang::Type to mlir::Type (which includes CIR type) is a
96 /// cache of types that have already been processed.
97 using TypeCacheTy = llvm::DenseMap<const clang::Type *, mlir::Type>;
99
100 mlir::MLIRContext &getMLIRContext() const;
101 clang::ASTContext &getASTContext() const { return astContext; }
102
103 bool isRecordLayoutComplete(const clang::Type *ty) const;
104 bool noRecordsBeingLaidOut() const { return recordsBeingLaidOut.empty(); }
105 bool isRecordBeingLaidOut(const clang::Type *ty) const {
106 return recordsBeingLaidOut.count(ty);
107 }
108
109 const ABIInfo &getABIInfo() const { return theABIInfo; }
110
111 /// Convert a Clang type into a mlir::Type.
112 mlir::Type convertType(clang::QualType type);
113
115
116 std::unique_ptr<CIRGenRecordLayout>
117 computeRecordLayout(const clang::RecordDecl *rd, cir::RecordType *ty);
118
119 std::string getRecordTypeName(const clang::RecordDecl *,
120 llvm::StringRef suffix);
121
123
124 /// Convert type T into an mlir::Type. This differs from convertType in that
125 /// it is used to convert to the memory representation for a type. For
126 /// example, the scalar representation for bool is i1, but the memory
127 /// representation is usually i8 or i32, depending on the target.
128 // TODO: convert this comment to account for MLIR's equivalence
129 mlir::Type convertTypeForMem(clang::QualType, bool forBitField = false);
130
131 /// Get the CIR function type for \arg Info.
132 cir::FuncType getFunctionType(const CIRGenFunctionInfo &info);
133
134 cir::FuncType getFunctionType(clang::GlobalDecl gd);
135
136 /// Determine if a C++ inheriting constructor should have parameters matching
137 /// those of its inherited constructor.
138 bool inheritingCtorHasParams(const InheritedConstructor &inherited,
140
141 // The arrangement methods are split into three families:
142 // - those meant to drive the signature and prologue/epilogue
143 // of a function declaration or definition,
144 // - those meant for the computation of the CIR type for an abstract
145 // appearance of a function, and
146 // - those meant for performing the CIR-generation of a call.
147 // They differ mainly in how they deal with optional (i.e. variadic)
148 // arguments, as well as unprototyped functions.
149 //
150 // Key points:
151 // - The CIRGenFunctionInfo for emitting a specific call site must include
152 // entries for the optional arguments.
153 // - The function type used at the call site must reflect the formal
154 // signature
155 // of the declaration being called, or else the call will go away.
156 // - For the most part, unprototyped functions are called by casting to a
157 // formal signature inferred from the specific argument types used at the
158 // call-site. However, some targets (e.g. x86-64) screw with this for
159 // compatability reasons.
160
162
163 /// UpdateCompletedType - when we find the full definition for a TagDecl,
164 /// replace the 'opaque' type we previously made for it if applicable.
165 void updateCompletedType(const clang::TagDecl *td);
166
167 /// Free functions are functions that are compatible with an ordinary C
168 /// function pointer type.
169 const CIRGenFunctionInfo &
171
172 /// Return whether a type can be zero-initialized (in the C++ sense) with an
173 /// LLVM zeroinitializer.
175 bool isZeroInitializable(const RecordDecl *rd);
176
178 const CallArgList &args, const clang::CXXConstructorDecl *d,
179 clang::CXXCtorType ctorKind, unsigned extraPrefixArgs,
180 unsigned extraSuffixArgs, bool passProtoArgs = true);
181
182 const CIRGenFunctionInfo &
185 RequiredArgs required, unsigned numPrefixArgs);
186
187 /// C++ methods have some special rules and also have implicit parameters.
188 const CIRGenFunctionInfo &
191
192 const CIRGenFunctionInfo &
194 const clang::FunctionProtoType *ftp,
195 const clang::CXXMethodDecl *md);
196
198 const FunctionType *fnType);
199
200 const CIRGenFunctionInfo &
203 FunctionType::ExtInfo info, RequiredArgs required);
204
205 const CIRGenFunctionInfo &
207 const CIRGenFunctionInfo &
209
210 unsigned getTargetAddressSpace(QualType ty) const;
211};
212
213} // namespace clang::CIRGen
214
215#endif
Enums/classes describing ABI related information about constructors, destructors and thunks.
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:226
Implements C++ ABI-specific code generation functions.
This class organizes the cross-function state that is used while generating CIR code.
This class handles record and union layout info while lowering AST types to CIR types.
CIRGenModule & getCGModule() const
Definition CIRGenTypes.h:83
const CIRGenFunctionInfo & arrangeGlobalDeclaration(GlobalDecl gd)
const CIRGenFunctionInfo & arrangeCXXMethodDeclaration(const clang::CXXMethodDecl *md)
C++ methods have some special rules and also have implicit parameters.
unsigned getTargetAddressSpace(QualType ty) const
const CIRGenFunctionInfo & arrangeCXXStructorDeclaration(clang::GlobalDecl gd)
const CIRGenFunctionInfo & arrangeCIRFunctionInfo(CanQualType returnType, bool isInstanceMethod, llvm::ArrayRef< CanQualType > argTypes, FunctionType::ExtInfo info, RequiredArgs required)
const CIRGenFunctionInfo & arrangeFreeFunctionCall(const CallArgList &args, const FunctionType *fnType)
const CIRGenFunctionInfo & arrangeFreeFunctionType(CanQual< FunctionProtoType > fpt)
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.
CIRGenTypes(CIRGenModule &cgm)
bool isRecordBeingLaidOut(const clang::Type *ty) const
CIRGenBuilderTy & getBuilder() const
Definition CIRGenTypes.h:82
const CIRGenFunctionInfo & arrangeCXXConstructorCall(const CallArgList &args, const clang::CXXConstructorDecl *d, clang::CXXCtorType ctorKind, unsigned extraPrefixArgs, unsigned extraSuffixArgs, bool passProtoArgs=true)
Arrange a call to a C++ method, passing the given arguments.
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...
mlir::MLIRContext & getMLIRContext() const
cir::FuncType getFunctionType(const CIRGenFunctionInfo &info)
Get the CIR function type for.
bool isFuncParamTypeConvertible(clang::QualType type)
Return true if the specified type in a function parameter or result position can be converted to a CI...
bool inheritingCtorHasParams(const InheritedConstructor &inherited, CXXCtorType type)
Determine if a C++ inheriting constructor should have parameters matching those of its inherited cons...
clang::CanQualType deriveThisType(const clang::CXXRecordDecl *rd, const clang::CXXMethodDecl *md)
Derives the 'this' type for CIRGen purposes, i.e.
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)
bool noRecordsBeingLaidOut() const
const ABIInfo & getABIInfo() const
const CIRGenFunctionInfo & arrangeFunctionDeclaration(const clang::FunctionDecl *fd)
Free functions are functions that are compatible with an ordinary C function pointer type.
clang::ASTContext & getASTContext() const
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.
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:97
A class for recording the number of arguments that a function signature requires.
Represents a C++ constructor within a class.
Definition DeclCXX.h:2624
Represents a static or instance method of a struct/union/class.
Definition DeclCXX.h:2136
Represents a C++ struct/union/class.
Definition DeclCXX.h:258
Represents a canonical, potentially-qualified type.
Represents a function declaration or definition.
Definition Decl.h:2015
Represents a prototype with parameter type info, e.g.
Definition TypeBase.h:5357
A class which abstracts out some details necessary for making a call.
Definition TypeBase.h:4664
FunctionType - C99 6.7.5.3 - Function Declarators.
Definition TypeBase.h:4553
GlobalDecl - represents a global declaration.
Definition GlobalDecl.h:57
Description of a constructor that was inherited from a base class.
Definition DeclCXX.h:2595
A (possibly-)qualified type.
Definition TypeBase.h:937
Represents a struct/union/class.
Definition Decl.h:4342
Represents the declaration of a struct/union/class/enum.
Definition Decl.h:3732
Exposes information about the current target.
Definition TargetInfo.h:227
The base class of the type hierarchy.
Definition TypeBase.h:1866
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.
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
CXXCtorType
C++ constructor types.
Definition ABI.h:24
bool isInstanceMethod(const Decl *D)
Definition Attr.h:120