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
26 FunctionArgList &params) {
27 const auto *md = cast<CXXMethodDecl>(cgf.curGD.getDecl());
28
29 // FIXME: I'm not entirely sure I like using a fake decl just for code
30 // generation. Maybe we can come up with a better way?
31 auto *thisDecl =
32 ImplicitParamDecl::Create(cgm.getASTContext(), nullptr, md->getLocation(),
33 &cgm.getASTContext().Idents.get("this"),
34 md->getThisType(), ImplicitParamKind::CXXThis);
35 params.push_back(thisDecl);
36 cgf.cxxabiThisDecl = thisDecl;
37
38 // Classic codegen computes the alignment of thisDecl and saves it in
39 // CodeGenFunction::CXXABIThisAlignment, but it is only used in emitTypeCheck
40 // in CodeGenFunction::StartFunction().
42}
43
45 GVALinkage linkage, const CXXDestructorDecl *dtor, CXXDtorType dt) const {
46 // Delegate back to cgm by default.
47 return cgm.getCIRLinkageForDeclarator(dtor, linkage,
48 /*isConstantVariable=*/false);
49}
50
53 Address addr = cgf.getAddrOfLocalVar(vd);
54 return cgf.getBuilder().create<cir::LoadOp>(
55 cgf.getLoc(vd->getLocation()), addr.getElementType(), addr.getPointer());
56}
57
59 mlir::Value thisPtr) {
60 /// Initialize the 'this' slot.
61 assert(getThisDecl(cgf) && "no 'this' variable for function");
62 cgf.cxxabiThisValue = thisPtr;
63}
IdentifierTable & Idents
Definition: ASTContext.h:740
mlir::Value getPointer() const
Definition: Address.h:81
mlir::Type getElementType() const
Definition: Address.h:101
clang::ImplicitParamDecl * getThisDecl(CIRGenFunction &cgf)
Definition: CIRGenCXXABI.h:51
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()
clang::ASTContext & getASTContext() const
Definition: CIRGenModule.h:102
cir::GlobalLinkageKind getCIRLinkageForDeclarator(const DeclaratorDecl *dd, GVALinkage linkage, bool isConstantVariable)
Type for representing both the decl and type of parameters to a function.
Definition: CIRGenCall.h:191
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
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
static ImplicitParamDecl * Create(ASTContext &C, DeclContext *DC, SourceLocation IdLoc, IdentifierInfo *Id, QualType T, ImplicitParamKind ParamKind)
Create implicit parameter.
Definition: Decl.cpp:5466
The JSON file list parser is used to communicate input to InstallAPI.
GVALinkage
A more specific kind of linkage than enum Linkage.
Definition: Linkage.h:72
CXXDtorType
C++ destructor types.
Definition: ABI.h:33
@ CXXThis
Parameter for C++ 'this' argument.
static bool cxxabiThisAlignment()