clang 22.0.0git
CIRGenCXXABI.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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 provides an abstract class for C++ code generation. Concrete subclasses
10// of this implement code generation for specific C++ ABIs.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_LIB_CIR_CIRGENCXXABI_H
15#define LLVM_CLANG_LIB_CIR_CIRGENCXXABI_H
16
17#include "CIRGenCall.h"
18#include "CIRGenFunction.h"
19#include "CIRGenModule.h"
20
21#include "clang/AST/Mangle.h"
22
23namespace clang::CIRGen {
24
25/// Implements C++ ABI-specific code generation functions.
27protected:
29 std::unique_ptr<clang::MangleContext> mangleContext;
30
31public:
32 // TODO(cir): make this protected when target-specific CIRGenCXXABIs are
33 // implemented.
35 : cgm(cgm), mangleContext(cgm.getASTContext().createMangleContext()) {}
36 virtual ~CIRGenCXXABI();
37
38 void setCXXABIThisValue(CIRGenFunction &cgf, mlir::Value thisPtr);
39
40 /// Emit the code to initialize hidden members required to handle virtual
41 /// inheritance, if needed by the ABI.
42 virtual void
44 const CXXRecordDecl *rd) {}
45
46 /// Emit a single constructor/destructor with the gen type from a C++
47 /// constructor/destructor Decl.
48 virtual void emitCXXStructor(clang::GlobalDecl gd) = 0;
49
50public:
52 return cgf.cxxabiThisDecl;
53 }
54
55 /// Emit the ABI-specific prolog for the function
57 CIRGenFunction &cgf) = 0;
58
59 virtual void emitRethrow(CIRGenFunction &cgf, bool isNoReturn) = 0;
60
61 /// Get the type of the implicit "this" parameter used by a method. May return
62 /// zero if no specific type is applicable, e.g. if the ABI expects the "this"
63 /// parameter to point to some artificial offset in a complete object due to
64 /// vbases being reordered.
65 virtual const clang::CXXRecordDecl *
67 return md->getParent();
68 }
69
70 /// Return whether the given global decl needs a VTT (virtual table table)
71 /// parameter.
72 virtual bool needsVTTParameter(clang::GlobalDecl gd) { return false; }
73
74 /// Perform ABI-specific "this" argument adjustment required prior to
75 /// a call of a virtual function.
76 /// The "VirtualCall" argument is true iff the call itself is virtual.
79 Address thisPtr,
80 bool virtualCall) {
81 return thisPtr;
82 }
83
84 /// Build a parameter variable suitable for 'this'.
86
87 /// Loads the incoming C++ this pointer as it was passed by the caller.
88 mlir::Value loadIncomingCXXThis(CIRGenFunction &cgf);
89
90 /// Emit constructor variants required by this ABI.
92
93 /// Emit dtor variants required by this ABI.
94 virtual void emitCXXDestructors(const clang::CXXDestructorDecl *d) = 0;
95
98 bool forVirtualBase, bool delegating,
99 Address thisAddr, QualType thisTy) = 0;
100
101 /// Checks if ABI requires extra virtual offset for vtable field.
102 virtual bool
104 CIRGenFunction::VPtr vptr) = 0;
105
106 /// Emits the VTable definitions required for the given record type.
108 const CXXRecordDecl *rd) = 0;
109
110 /// Returns true if the given destructor type should be emitted as a linkonce
111 /// delegating thunk, regardless of whether the dtor is defined in this TU or
112 /// not.
114 CXXDtorType dt) const = 0;
115
116 virtual cir::GlobalLinkageKind
118 CXXDtorType dt) const;
119
120 /// Get the address of the vtable for the given record decl which should be
121 /// used for the vptr at the given offset in RD.
122 virtual cir::GlobalOp getAddrOfVTable(const CXXRecordDecl *rd,
123 CharUnits vptrOffset) = 0;
124
125 /// Build a virtual function pointer in the ABI-specific way.
128 Address thisAddr,
129 mlir::Type ty,
130 SourceLocation loc) = 0;
131
132 /// Get the address point of the vtable for the given base subobject.
133 virtual mlir::Value
135 const CXXRecordDecl *vtableClass) = 0;
136
137 /// Get the address point of the vtable for the given base subobject while
138 /// building a constructor or a destructor.
140 CIRGenFunction &cgf, const CXXRecordDecl *vtableClass, BaseSubobject base,
141 const CXXRecordDecl *nearestVBase) = 0;
142
143 /// Checks if ABI requires to initialize vptrs for given dynamic class.
144 virtual bool
146
147 /// Returns true if the given constructor or destructor is one of the kinds
148 /// that the ABI says returns 'this' (only applies when called non-virtually
149 /// for destructors).
150 ///
151 /// There currently is no way to indicate if a destructor returns 'this' when
152 /// called virtually, and CIR generation does not support this case.
153 virtual bool hasThisReturn(clang::GlobalDecl gd) const { return false; }
154
156 return false;
157 }
158
159 /// Gets the mangle context.
161};
162
163/// Creates and Itanium-family ABI
164CIRGenCXXABI *CreateCIRGenItaniumCXXABI(CIRGenModule &cgm);
165
166} // namespace clang::CIRGen
167
168#endif
Implements C++ ABI-specific code generation functions.
Definition: CIRGenCXXABI.h:26
CIRGenCXXABI(CIRGenModule &cgm)
Definition: CIRGenCXXABI.h:34
virtual void emitInstanceFunctionProlog(SourceLocation loc, CIRGenFunction &cgf)=0
Emit the ABI-specific prolog for the function.
virtual void emitCXXConstructors(const clang::CXXConstructorDecl *d)=0
Emit constructor variants required by this ABI.
virtual Address adjustThisArgumentForVirtualFunctionCall(CIRGenFunction &cgf, clang::GlobalDecl gd, Address thisPtr, bool virtualCall)
Perform ABI-specific "this" argument adjustment required prior to a call of a virtual function.
Definition: CIRGenCXXABI.h:77
clang::ImplicitParamDecl * getThisDecl(CIRGenFunction &cgf)
Definition: CIRGenCXXABI.h:51
virtual const clang::CXXRecordDecl * getThisArgumentTypeForMethod(const clang::CXXMethodDecl *md)
Get the type of the implicit "this" parameter used by a method.
Definition: CIRGenCXXABI.h:66
virtual void emitCXXDestructors(const clang::CXXDestructorDecl *d)=0
Emit dtor variants required by this ABI.
virtual cir::GlobalOp getAddrOfVTable(const CXXRecordDecl *rd, CharUnits vptrOffset)=0
Get the address of the vtable for the given record decl which should be used for the vptr at the give...
virtual CIRGenCallee getVirtualFunctionPointer(CIRGenFunction &cgf, clang::GlobalDecl gd, Address thisAddr, mlir::Type ty, SourceLocation loc)=0
Build a virtual function pointer in the ABI-specific way.
virtual bool hasThisReturn(clang::GlobalDecl gd) const
Returns true if the given constructor or destructor is one of the kinds that the ABI says returns 'th...
Definition: CIRGenCXXABI.h:153
clang::MangleContext & getMangleContext()
Gets the mangle context.
Definition: CIRGenCXXABI.h:160
virtual void emitVTableDefinitions(CIRGenVTables &cgvt, const CXXRecordDecl *rd)=0
Emits the VTable definitions required for the given record type.
virtual bool useThunkForDtorVariant(const CXXDestructorDecl *dtor, CXXDtorType dt) const =0
Returns true if the given destructor type should be emitted as a linkonce delegating thunk,...
virtual bool needsVTTParameter(clang::GlobalDecl gd)
Return whether the given global decl needs a VTT (virtual table table) parameter.
Definition: CIRGenCXXABI.h:72
virtual mlir::Value getVTableAddressPointInStructor(CIRGenFunction &cgf, const CXXRecordDecl *vtableClass, BaseSubobject base, const CXXRecordDecl *nearestVBase)=0
Get the address point of the vtable for the given base subobject while building a constructor or a de...
void setCXXABIThisValue(CIRGenFunction &cgf, mlir::Value thisPtr)
virtual mlir::Value getVTableAddressPoint(BaseSubobject base, const CXXRecordDecl *vtableClass)=0
Get the address point of the vtable for the given base subobject.
std::unique_ptr< clang::MangleContext > mangleContext
Definition: CIRGenCXXABI.h:29
virtual void emitDestructorCall(CIRGenFunction &cgf, const CXXDestructorDecl *dd, CXXDtorType type, bool forVirtualBase, bool delegating, Address thisAddr, QualType thisTy)=0
virtual void emitCXXStructor(clang::GlobalDecl gd)=0
Emit a single constructor/destructor with the gen type from a C++ constructor/destructor Decl.
mlir::Value loadIncomingCXXThis(CIRGenFunction &cgf)
Loads the incoming C++ this pointer as it was passed by the caller.
virtual bool hasMostDerivedReturn(clang::GlobalDecl gd) const
Definition: CIRGenCXXABI.h:155
virtual void initializeHiddenVirtualInheritanceMembers(CIRGenFunction &cgf, const CXXRecordDecl *rd)
Emit the code to initialize hidden members required to handle virtual inheritance,...
Definition: CIRGenCXXABI.h:43
virtual bool isVirtualOffsetNeededForVTableField(CIRGenFunction &cgf, CIRGenFunction::VPtr vptr)=0
Checks if ABI requires extra virtual offset for vtable field.
virtual void emitRethrow(CIRGenFunction &cgf, bool isNoReturn)=0
virtual bool doStructorsInitializeVPtrs(const clang::CXXRecordDecl *vtableClass)=0
Checks if ABI requires to initialize vptrs for given dynamic class.
virtual cir::GlobalLinkageKind getCXXDestructorLinkage(GVALinkage linkage, const CXXDestructorDecl *dtor, CXXDtorType dt) const
void buildThisParam(CIRGenFunction &cgf, FunctionArgList &params)
Build a parameter variable suitable for 'this'.
ImplicitParamDecl * cxxabiThisDecl
CXXThisDecl - When generating code for a C++ member function, this will hold the implicit 'this' decl...
This class organizes the cross-function state that is used while generating CIR code.
Definition: CIRGenModule.h:56
Type for representing both the decl and type of parameters to a function.
Definition: CIRGenCall.h:191
Represents a C++ constructor within a class.
Definition: DeclCXX.h:2604
Represents a C++ destructor within a class.
Definition: DeclCXX.h:2869
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2129
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
Definition: DeclCXX.h:2255
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
CharUnits - This is an opaque type for sizes expressed in character units.
Definition: CharUnits.h:38
GlobalDecl - represents a global declaration.
Definition: GlobalDecl.h:57
MangleContext - Context for tracking state which persists across multiple calls to the C++ name mangl...
Definition: Mangle.h:52
A (possibly-)qualified type.
Definition: TypeBase.h:937
Encodes a location in the source.
CIRGenCXXABI * CreateCIRGenItaniumCXXABI(CIRGenModule &cgm)
Creates and Itanium-family ABI.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
GVALinkage
A more specific kind of linkage than enum Linkage.
Definition: Linkage.h:72
CXXDtorType
C++ destructor types.
Definition: ABI.h:33