Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/contrib/llvm-project/clang/lib/CIR/CodeGen/CIRGenCXXABI.cpp
213799 views
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"
18
#include "clang/AST/GlobalDecl.h"
19
20
using namespace clang;
21
using namespace clang::CIRGen;
22
23
CIRGenCXXABI::~CIRGenCXXABI() {}
24
25
void CIRGenCXXABI::buildThisParam(CIRGenFunction &cgf,
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().
41
assert(!cir::MissingFeatures::cxxabiThisAlignment());
42
}
43
44
cir::GlobalLinkageKind CIRGenCXXABI::getCXXDestructorLinkage(
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
51
mlir::Value CIRGenCXXABI::loadIncomingCXXThis(CIRGenFunction &cgf) {
52
ImplicitParamDecl *vd = getThisDecl(cgf);
53
Address addr = cgf.getAddrOfLocalVar(vd);
54
return cgf.getBuilder().create<cir::LoadOp>(
55
cgf.getLoc(vd->getLocation()), addr.getElementType(), addr.getPointer());
56
}
57
58
void CIRGenCXXABI::setCXXABIThisValue(CIRGenFunction &cgf,
59
mlir::Value thisPtr) {
60
/// Initialize the 'this' slot.
61
assert(getThisDecl(cgf) && "no 'this' variable for function");
62
cgf.cxxabiThisValue = thisPtr;
63
}
64
65