Path: blob/main/contrib/llvm-project/clang/lib/CIR/CodeGen/CIRGenCXXABI.cpp
213799 views
//===----------------------------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This provides an abstract class for C++ code generation. Concrete subclasses9// of this implement code generation for specific C++ ABIs.10//11//===----------------------------------------------------------------------===//1213#include "CIRGenCXXABI.h"14#include "CIRGenFunction.h"1516#include "clang/AST/Decl.h"17#include "clang/AST/GlobalDecl.h"1819using namespace clang;20using namespace clang::CIRGen;2122CIRGenCXXABI::~CIRGenCXXABI() {}2324void CIRGenCXXABI::buildThisParam(CIRGenFunction &cgf,25FunctionArgList ¶ms) {26const auto *md = cast<CXXMethodDecl>(cgf.curGD.getDecl());2728// FIXME: I'm not entirely sure I like using a fake decl just for code29// generation. Maybe we can come up with a better way?30auto *thisDecl =31ImplicitParamDecl::Create(cgm.getASTContext(), nullptr, md->getLocation(),32&cgm.getASTContext().Idents.get("this"),33md->getThisType(), ImplicitParamKind::CXXThis);34params.push_back(thisDecl);35cgf.cxxabiThisDecl = thisDecl;3637// Classic codegen computes the alignment of thisDecl and saves it in38// CodeGenFunction::CXXABIThisAlignment, but it is only used in emitTypeCheck39// in CodeGenFunction::StartFunction().40assert(!cir::MissingFeatures::cxxabiThisAlignment());41}4243cir::GlobalLinkageKind CIRGenCXXABI::getCXXDestructorLinkage(44GVALinkage linkage, const CXXDestructorDecl *dtor, CXXDtorType dt) const {45// Delegate back to cgm by default.46return cgm.getCIRLinkageForDeclarator(dtor, linkage,47/*isConstantVariable=*/false);48}4950mlir::Value CIRGenCXXABI::loadIncomingCXXThis(CIRGenFunction &cgf) {51ImplicitParamDecl *vd = getThisDecl(cgf);52Address addr = cgf.getAddrOfLocalVar(vd);53return cgf.getBuilder().create<cir::LoadOp>(54cgf.getLoc(vd->getLocation()), addr.getElementType(), addr.getPointer());55}5657void CIRGenCXXABI::setCXXABIThisValue(CIRGenFunction &cgf,58mlir::Value thisPtr) {59/// Initialize the 'this' slot.60assert(getThisDecl(cgf) && "no 'this' variable for function");61cgf.cxxabiThisValue = thisPtr;62}636465