Path: blob/main/contrib/llvm-project/clang/lib/CIR/CodeGen/CIRGenCXXABI.h
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#ifndef LLVM_CLANG_LIB_CIR_CIRGENCXXABI_H14#define LLVM_CLANG_LIB_CIR_CIRGENCXXABI_H1516#include "CIRGenCall.h"17#include "CIRGenFunction.h"18#include "CIRGenModule.h"1920#include "clang/AST/Mangle.h"2122namespace clang::CIRGen {2324/// Implements C++ ABI-specific code generation functions.25class CIRGenCXXABI {26protected:27CIRGenModule &cgm;28std::unique_ptr<clang::MangleContext> mangleContext;2930public:31// TODO(cir): make this protected when target-specific CIRGenCXXABIs are32// implemented.33CIRGenCXXABI(CIRGenModule &cgm)34: cgm(cgm), mangleContext(cgm.getASTContext().createMangleContext()) {}35virtual ~CIRGenCXXABI();3637void setCXXABIThisValue(CIRGenFunction &cgf, mlir::Value thisPtr);3839/// Emit a single constructor/destructor with the gen type from a C++40/// constructor/destructor Decl.41virtual void emitCXXStructor(clang::GlobalDecl gd) = 0;4243public:44clang::ImplicitParamDecl *getThisDecl(CIRGenFunction &cgf) {45return cgf.cxxabiThisDecl;46}4748/// Emit the ABI-specific prolog for the function49virtual void emitInstanceFunctionProlog(SourceLocation Loc,50CIRGenFunction &cgf) = 0;5152/// Get the type of the implicit "this" parameter used by a method. May return53/// zero if no specific type is applicable, e.g. if the ABI expects the "this"54/// parameter to point to some artificial offset in a complete object due to55/// vbases being reordered.56virtual const clang::CXXRecordDecl *57getThisArgumentTypeForMethod(const clang::CXXMethodDecl *md) {58return md->getParent();59}6061/// Return whether the given global decl needs a VTT (virtual table table)62/// parameter.63virtual bool needsVTTParameter(clang::GlobalDecl gd) { return false; }6465/// Build a parameter variable suitable for 'this'.66void buildThisParam(CIRGenFunction &cgf, FunctionArgList ¶ms);6768/// Loads the incoming C++ this pointer as it was passed by the caller.69mlir::Value loadIncomingCXXThis(CIRGenFunction &cgf);7071/// Emit constructor variants required by this ABI.72virtual void emitCXXConstructors(const clang::CXXConstructorDecl *d) = 0;7374/// Emit dtor variants required by this ABI.75virtual void emitCXXDestructors(const clang::CXXDestructorDecl *d) = 0;7677/// Returns true if the given destructor type should be emitted as a linkonce78/// delegating thunk, regardless of whether the dtor is defined in this TU or79/// not.80virtual bool useThunkForDtorVariant(const CXXDestructorDecl *dtor,81CXXDtorType dt) const = 0;8283virtual cir::GlobalLinkageKind84getCXXDestructorLinkage(GVALinkage linkage, const CXXDestructorDecl *dtor,85CXXDtorType dt) const;8687/// Returns true if the given constructor or destructor is one of the kinds88/// that the ABI says returns 'this' (only applies when called non-virtually89/// for destructors).90///91/// There currently is no way to indicate if a destructor returns 'this' when92/// called virtually, and CIR generation does not support this case.93virtual bool hasThisReturn(clang::GlobalDecl gd) const { return false; }9495virtual bool hasMostDerivedReturn(clang::GlobalDecl gd) const {96return false;97}9899/// Gets the mangle context.100clang::MangleContext &getMangleContext() { return *mangleContext; }101};102103/// Creates and Itanium-family ABI104CIRGenCXXABI *CreateCIRGenItaniumCXXABI(CIRGenModule &cgm);105106} // namespace clang::CIRGen107108#endif109110111