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 ¶ms) { |
27 | const auto *md = cast<CXXMethodDecl>(Val: 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(Name: "this" ), |
34 | md->getThisType(), ImplicitParamKind::CXXThis); |
35 | params.push_back(Elt: 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 | mlir::Value CIRGenCXXABI::loadIncomingCXXThis(CIRGenFunction &cgf) { |
45 | ImplicitParamDecl *vd = getThisDecl(cgf); |
46 | Address addr = cgf.getAddrOfLocalVar(vd); |
47 | return cgf.getBuilder().create<cir::LoadOp>( |
48 | cgf.getLoc(vd->getLocation()), addr.getElementType(), addr.getPointer()); |
49 | } |
50 | |
51 | void CIRGenCXXABI::setCXXABIThisValue(CIRGenFunction &cgf, |
52 | mlir::Value thisPtr) { |
53 | /// Initialize the 'this' slot. |
54 | assert(getThisDecl(cgf) && "no 'this' variable for function" ); |
55 | cgf.cxxabiThisValue = thisPtr; |
56 | } |
57 | |