19#include "llvm/Support/SaveAndRestore.h"
35 if (!
cgm.getCodeGenOpts().OptimizationLevel)
42 mlir::Value sizeValue = builder.getConstInt(loc, builder.getSInt64Ty(),
43 static_cast<int64_t
>(width));
48 cir::LLVMIntrinsicCallOp::create(
49 builder, loc, builder.getStringAttr(
"invariant.start"), addr.getType(),
50 mlir::ValueRange{sizeValue, addr});
54 cir::GlobalOp globalOp) {
55 assert((
varDecl->hasGlobalStorage() ||
58 "VarDecl must have global or local (in the case of OpenCL) storage!");
59 assert(!
varDecl->getType()->isReferenceType() &&
60 "Should not call emitDeclInit on a reference!");
65 mlir::OpBuilder::InsertionGuard guard(builder);
66 mlir::Block *block = builder.createBlock(&globalOp.getCtorRegion());
68 builder.getInsertionBlock()};
70 builder.setInsertionPointToStart(block);
97 builder.setInsertionPointToEnd(block);
98 cir::YieldOp::create(builder, globalOp.getLoc());
102 cir::GlobalOp addr) {
124 assert(!vd->
getTLSKind() &&
"should have rejected this");
132 mlir::OpBuilder::InsertionGuard guard(builder);
133 mlir::Block *block = builder.createBlock(&addr.getDtorRegion());
135 builder.getInsertionBlock()};
137 builder.setInsertionPointToStart(block);
147 bool canRegisterDestructor =
148 record && (!cgm.
getCXXABI().hasThisReturn(
156 if (record && (canRegisterDestructor || cgm.
getCodeGenOpts().CXAAtExit)) {
168 mlir::FlatSymbolRefAttr::get(fnOp.getSymNameAttr()),
169 mlir::ValueRange{cgm.getAddrOfGlobalVar(vd)});
170 assert(fnOp &&
"expected cir.func");
189 builder.setInsertionPointToEnd(block);
190 if (block->empty()) {
193 builder.clearInsertionPoint();
195 cir::YieldOp::create(builder, addr.getLoc());
209 mlir::OpBuilder::InsertionGuard guard(builder);
214 setNonAliasAttributes(gd, fn);
254 curCGF->curFn = addr;
266 bool isConstantStorage =
273 if (isConstantStorage) {
275 mlir::OpBuilder::InsertionGuard guard(builder);
277 if (!addr.getCtorRegion().empty()) {
278 mlir::Block *block = &addr.getCtorRegion().back();
280 mlir::Operation *yieldOp = block->getTerminator();
282 builder.setInsertionPoint(yieldOp);
287 }
else if (isConstantStorage) {
291 if (!isConstantStorage)
static void emitDeclInvariant(CIRGenFunction &cgf, const VarDecl *d)
Emit code to cause the variable at the given address to be considered as constant from this point onw...
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={})
mlir::Value createGetGlobal(mlir::Location loc, cir::GlobalOp global, bool threadLocal=false)
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.
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
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)
void emitInvariantStart(CharUnits size, mlir::Value addr, mlir::Location loc)
mlir::Location getLoc(clang::SourceLocation srcLoc)
Helpers to convert Clang's SourceLocation to a MLIR Location.
mlir::Type convertTypeForMem(QualType t)
void emitScalarInit(const clang::Expr *init, mlir::Location loc, LValue lvalue, bool capturedByInit=false)
CIRGenBuilderTy & getBuilder()
void emitDestroy(Address addr, QualType type, Destroyer *destroyer)
Immediately perform the destruction of the given object.
Destroyer * getDestroyer(clang::QualType::DestructionKind kind)
void emitComplexExprIntoLValue(const Expr *e, LValue dest, bool isInit)
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 setCIRFunctionAttributesForDefinition(const clang::FunctionDecl *fd, cir::FuncOp f)
Set extra attributes (inline, etc.) for a function.
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.
CharUnits - This is an opaque type for sizes expressed in character units.
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
This represents one expression.
GlobalDecl - represents a global declaration.
const Decl * getDecl() const
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 astVarDeclInterface()
Represents a scope, including function bodies, compound statements, and the substatements of if/while...