19#include "llvm/Support/SaveAndRestore.h"
25 cir::GlobalOp globalOp) {
26 assert((
varDecl->hasGlobalStorage() ||
29 "VarDecl must have global or local (in the case of OpenCL) storage!");
30 assert(!
varDecl->getType()->isReferenceType() &&
31 "Should not call emitDeclInit on a reference!");
36 mlir::OpBuilder::InsertionGuard guard(builder);
37 mlir::Block *block = builder.createBlock(&globalOp.getCtorRegion());
39 builder.getInsertionBlock()};
41 builder.setInsertionPointToStart(block);
68 builder.setInsertionPointToEnd(block);
69 cir::YieldOp::create(builder, globalOp.getLoc());
95 assert(!vd->
getTLSKind() &&
"should have rejected this");
103 mlir::OpBuilder::InsertionGuard guard(builder);
104 mlir::Block *block = builder.createBlock(&addr.getDtorRegion());
106 builder.getInsertionBlock()};
108 builder.setInsertionPointToStart(block);
118 bool canRegisterDestructor =
119 record && (!cgm.
getCXXABI().hasThisReturn(
127 if (record && (canRegisterDestructor || cgm.
getCodeGenOpts().CXAAtExit)) {
140 mlir::FlatSymbolRefAttr::get(fnOp.getSymNameAttr()),
141 mlir::ValueRange{cgm.getAddrOfGlobalVar(vd)});
145 assert(fnOp &&
"expected cir.func");
148 builder.setInsertionPointToEnd(block);
149 if (block->empty()) {
152 builder.clearInsertionPoint();
154 builder.create<cir::YieldOp>(addr.getLoc());
168 mlir::OpBuilder::InsertionGuard guard(builder);
173 setNonAliasAttributes(gd, fn);
212 curCGF->curFn = addr;
static void emitDeclDestroy(CIRGenFunction &cgf, const VarDecl *vd, cir::GlobalOp addr)
static void emitDeclInit(CIRGenFunction &cgf, const VarDecl *varDecl, cir::GlobalOp globalOp)
cir::CallOp createCallOp(mlir::Location loc, mlir::SymbolRefAttr callee, mlir::Type returnType, mlir::ValueRange operands, llvm::ArrayRef< mlir::NamedAttribute > attrs={})
const LangOptions & getLangOpts() const
CharUnits getDeclAlign(const Decl *D, bool ForAlignof=false) const
Return a conservative estimate of the alignment of the specified decl D.
static AggValueSlot forLValue(const LValue &LV, IsDestructed_t isDestructed, IsAliased_t isAliased, Overlap_t mayOverlap, IsZeroed_t isZeroed=IsNotZeroed)
virtual void registerGlobalDtor(const VarDecl *vd, cir::FuncOp dtor, mlir::Value addr)=0
Emit code to force the execution of a destructor during global teardown.
virtual bool canCallMismatchedFunctionType() const
Returns true if the target allows calling a function through a pointer with a different signature tha...
static cir::TypeEvaluationKind getEvaluationKind(clang::QualType type)
Return the cir::TypeEvaluationKind of QualType type.
cir::FuncOp generateCode(clang::GlobalDecl gd, cir::FuncOp fn, cir::FuncType funcType)
mlir::Location getLoc(clang::SourceLocation srcLoc)
Helpers to convert Clang's SourceLocation to a MLIR Location.
void emitScalarInit(const clang::Expr *init, mlir::Location loc, LValue lvalue, bool capturedByInit=false)
CIRGenBuilderTy & getBuilder()
LValue makeAddrLValue(Address addr, QualType ty, AlignmentSource source=AlignmentSource::Type)
clang::ASTContext & getContext() const
void emitAggExpr(const clang::Expr *e, AggValueSlot slot)
This class organizes the cross-function state that is used while generating CIR code.
void emitCXXGlobalVarDeclInit(const VarDecl *varDecl, cir::GlobalOp addr, bool performInit)
Emit the function that initializes the specified global.
DiagnosticBuilder errorNYI(SourceLocation, llvm::StringRef)
Helpers to emit "not yet implemented" error diagnostics.
clang::ASTContext & getASTContext() const
cir::FuncOp getAddrOfCXXStructor(clang::GlobalDecl gd, const CIRGenFunctionInfo *fnInfo=nullptr, cir::FuncType fnType=nullptr, bool dontDefer=false, ForDefinition_t isForDefinition=NotForDefinition)
std::pair< cir::FuncType, cir::FuncOp > getAddrAndTypeOfCXXStructor(clang::GlobalDecl gd, const CIRGenFunctionInfo *fnInfo=nullptr, cir::FuncType fnType=nullptr, bool dontDefer=false, ForDefinition_t isForDefinition=NotForDefinition)
mlir::Value getAddrOfGlobalVar(const VarDecl *d, mlir::Type ty={}, ForDefinition_t isForDefinition=NotForDefinition)
Return the mlir::Value for the address of the given global variable.
const clang::CodeGenOptions & getCodeGenOpts() const
cir::FuncOp codegenCXXStructor(clang::GlobalDecl gd)
mlir::Location getLoc(clang::SourceLocation cLoc)
Helpers to convert the presumed location of Clang's SourceLocation to an MLIR Location.
CIRGenCXXABI & getCXXABI() const
void setFunctionLinkage(GlobalDecl gd, cir::FuncOp f)
const CIRGenFunctionInfo & arrangeCXXStructorDeclaration(clang::GlobalDecl gd)
cir::FuncType getFunctionType(const CIRGenFunctionInfo &info)
Get the CIR function type for.
Represents a C++ destructor within a class.
Represents a C++ struct/union/class.
bool hasTrivialDestructor() const
Determine whether this class has a trivial destructor (C++ [class.dtor]p3)
CXXDestructorDecl * getDestructor() const
Returns the destructor decl for this class.
This represents one expression.
GlobalDecl - represents a global declaration.
A (possibly-)qualified type.
@ DK_objc_strong_lifetime
bool isReferenceType() const
Represents a variable declaration or definition.
TLSKind getTLSKind() const
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
QualType::DestructionKind needsDestruction(const ASTContext &Ctx) const
Would the destruction of this variable have any effect, and if so, what kind?
const internal::VariadicDynCastAllOfMatcher< Decl, VarDecl > varDecl
Matches variable declarations.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
The JSON file list parser is used to communicate input to InstallAPI.
@ Dtor_Complete
Complete object dtor.
static bool addressSpace()
static bool aggValueSlotGC()
static bool opFuncAttributesForDefinition()
static bool astVarDeclInterface()
Represents a scope, including function bodies, compound statements, and the substatements of if/while...