clang 22.0.0git
CIRGenCXXABI.cpp
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#include "CIRGenCXXABI.h"
15#include "CIRGenFunction.h"
16
17#include "clang/AST/Decl.h"
19
20using namespace clang;
21using namespace clang::CIRGen;
22
24
27 bool forVirtualBase, bool delegating, CallArgList &args) {
28 AddedStructorArgs addedArgs =
29 getImplicitConstructorArgs(cgf, d, type, forVirtualBase, delegating);
30 for (auto [idx, prefixArg] : llvm::enumerate(addedArgs.prefix))
31 args.insert(args.begin() + 1 + idx,
32 CallArg(RValue::get(prefixArg.value), prefixArg.type));
33 for (const auto &arg : addedArgs.suffix)
34 args.add(RValue::get(arg.value), arg.type);
35 return AddedStructorArgCounts(addedArgs.prefix.size(),
36 addedArgs.suffix.size());
37}
38
40 FunctionArgList &params) {
41 const auto *md = cast<CXXMethodDecl>(cgf.curGD.getDecl());
42
43 // FIXME: I'm not entirely sure I like using a fake decl just for code
44 // generation. Maybe we can come up with a better way?
45 auto *thisDecl =
46 ImplicitParamDecl::Create(cgm.getASTContext(), nullptr, md->getLocation(),
47 &cgm.getASTContext().Idents.get("this"),
48 md->getThisType(), ImplicitParamKind::CXXThis);
49 params.push_back(thisDecl);
50 cgf.cxxabiThisDecl = thisDecl;
51
52 // Classic codegen computes the alignment of thisDecl and saves it in
53 // CodeGenFunction::CXXABIThisAlignment, but it is only used in emitTypeCheck
54 // in CodeGenFunction::StartFunction().
56}
57
59 GVALinkage linkage, const CXXDestructorDecl *dtor, CXXDtorType dt) const {
60 // Delegate back to cgm by default.
61 return cgm.getCIRLinkageForDeclarator(dtor, linkage,
62 /*isConstantVariable=*/false);
63}
64
67 Address addr = cgf.getAddrOfLocalVar(vd);
68 return cgf.getBuilder().create<cir::LoadOp>(
69 cgf.getLoc(vd->getLocation()), addr.getElementType(), addr.getPointer());
70}
71
73 mlir::Value thisPtr) {
74 /// Initialize the 'this' slot.
75 assert(getThisDecl(cgf) && "no 'this' variable for function");
76 cgf.cxxabiThisValue = thisPtr;
77}
mlir::Value getPointer() const
Definition Address.h:81
mlir::Type getElementType() const
Definition Address.h:101
AddedStructorArgCounts addImplicitConstructorArgs(CIRGenFunction &cgf, const CXXConstructorDecl *d, CXXCtorType type, bool forVirtualBase, bool delegating, CallArgList &args)
clang::ImplicitParamDecl * getThisDecl(CIRGenFunction &cgf)
virtual AddedStructorArgs getImplicitConstructorArgs(CIRGenFunction &cgf, const CXXConstructorDecl *d, CXXCtorType type, bool forVirtualBase, bool delegating)=0
void setCXXABIThisValue(CIRGenFunction &cgf, mlir::Value thisPtr)
mlir::Value loadIncomingCXXThis(CIRGenFunction &cgf)
Loads the incoming C++ this pointer as it was passed by the caller.
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'.
clang::GlobalDecl curGD
The GlobalDecl for the current function being compiled or the global variable currently being initial...
ImplicitParamDecl * cxxabiThisDecl
CXXThisDecl - When generating code for a C++ member function, this will hold the implicit 'this' decl...
Address getAddrOfLocalVar(const clang::VarDecl *vd)
Return the address of a local variable.
mlir::Location getLoc(clang::SourceLocation srcLoc)
Helpers to convert Clang's SourceLocation to a MLIR Location.
CIRGenBuilderTy & getBuilder()
void add(RValue rvalue, clang::QualType type)
Definition CIRGenCall.h:231
Type for representing both the decl and type of parameters to a function.
Definition CIRGenCall.h:191
static RValue get(mlir::Value v)
Definition CIRGenValue.h:82
Represents a C++ constructor within a class.
Definition DeclCXX.h:2604
Represents a C++ destructor within a class.
Definition DeclCXX.h:2869
SourceLocation getLocation() const
Definition DeclBase.h:439
const Decl * getDecl() const
Definition GlobalDecl.h:106
static ImplicitParamDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, ImplicitParamKind ParamKind)
Create implicit parameter.
Definition Decl.cpp:5470
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
The JSON file list parser is used to communicate input to InstallAPI.
CXXCtorType
C++ constructor types.
Definition ABI.h:24
GVALinkage
A more specific kind of linkage than enum Linkage.
Definition Linkage.h:72
CXXDtorType
C++ destructor types.
Definition ABI.h:34
U cast(CodeGen::Address addr)
Definition Address.h:327
@ CXXThis
Parameter for C++ 'this' argument.
Definition Decl.h:1733
static bool cxxabiThisAlignment()
Similar to AddedStructorArgs, but only notes the number of additional arguments.
Additional implicit arguments to add to the beginning (Prefix) and end (Suffix) of a constructor / de...