20#include "llvm/Support/SaveAndRestore.h"
36 if (!
cgm.getCodeGenOpts().OptimizationLevel)
43 mlir::Value sizeValue = builder.getConstInt(loc, builder.getSInt64Ty(),
44 static_cast<int64_t
>(width));
49 cir::LLVMIntrinsicCallOp::create(
50 builder, loc, builder.getStringAttr(
"invariant.start"), addr.getType(),
51 mlir::ValueRange{sizeValue, addr});
55 cir::GlobalOp globalOp) {
56 assert((
varDecl->hasGlobalStorage() ||
59 "VarDecl must have global or local (in the case of OpenCL) storage!");
60 assert(!
varDecl->getType()->isReferenceType() &&
61 "Should not call emitDeclInit on a reference!");
66 mlir::OpBuilder::InsertionGuard guard(builder);
67 mlir::Block *block = builder.createBlock(&globalOp.getCtorRegion());
69 builder.getInsertionBlock()};
71 builder.setInsertionPointToStart(block);
98 builder.setInsertionPointToEnd(block);
99 cir::YieldOp::create(builder, globalOp.getLoc());
103 cir::GlobalOp addr) {
125 assert(!vd->
getTLSKind() &&
"should have rejected this");
133 mlir::OpBuilder::InsertionGuard guard(builder);
134 mlir::Block *block = builder.createBlock(&addr.getDtorRegion());
136 builder.getInsertionBlock()};
138 builder.setInsertionPointToStart(block);
148 bool canRegisterDestructor =
149 record && (!cgm.
getCXXABI().hasThisReturn(
157 if (record && (canRegisterDestructor || cgm.
getCodeGenOpts().CXAAtExit)) {
169 mlir::FlatSymbolRefAttr::get(fnOp.getSymNameAttr()),
170 mlir::ValueRange{cgm.getAddrOfGlobalVar(vd)});
171 assert(fnOp &&
"expected cir.func");
190 builder.setInsertionPointToEnd(block);
191 if (block->empty()) {
194 builder.clearInsertionPoint();
196 cir::YieldOp::create(builder, addr.getLoc());
210 mlir::OpBuilder::InsertionGuard guard(builder);
215 setNonAliasAttributes(gd, fn);
255 curCGF->curFn = addr;
267 bool isConstantStorage =
274 if (isConstantStorage) {
276 mlir::OpBuilder::InsertionGuard guard(builder);
278 if (!addr.getCtorRegion().empty()) {
279 mlir::Block *block = &addr.getCtorRegion().back();
281 mlir::Operation *yieldOp = block->getTerminator();
283 builder.setInsertionPoint(yieldOp);
288 }
else if (isConstantStorage) {
292 if (!isConstantStorage)
297 mlir::OpBuilder::InsertionGuard guard(builder);
298 auto *block = builder.createBlock(&addr.getCtorRegion());
300 builder.getInsertionBlock()};
302 builder.setInsertionPointToStart(block);
303 mlir::Value getGlobal = builder.createGetGlobal(addr);
306 assert(performInit &&
"cannot have a constant initializer which needs "
307 "destruction for reference");
310 mlir::OpBuilder::InsertionGuard guard(builder);
311 mlir::Operation *rvalDefOp = rv.
getValue().getDefiningOp();
312 if (rvalDefOp && rvalDefOp->getBlock()) {
313 mlir::Block *rvalSrcBlock = rvalDefOp->getBlock();
316 mlir::Operation &front = rvalSrcBlock->front();
317 getGlobal.getDefiningOp()->moveBefore(&front);
325 builder.setInsertionPointToEnd(block);
326 cir::YieldOp::create(builder, addr->getLoc());
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)
mlir::Value createGetGlobal(mlir::Location loc, cir::GlobalOp global, bool threadLocal=false)
cir::CallOp createCallOp(mlir::Location loc, mlir::SymbolRefAttr callee, mlir::Type returnType, mlir::ValueRange operands, llvm::ArrayRef< mlir::NamedAttribute > attrs={}, llvm::ArrayRef< mlir::NamedAttrList > argAttrs={}, llvm::ArrayRef< mlir::NamedAttribute > resAttrs={})
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.
RValue emitReferenceBindingToExpr(const Expr *e)
Emits a reference binding to the passed in expression.
mlir::Type convertTypeForMem(QualType t)
void emitStoreOfScalar(mlir::Value value, Address addr, bool isVolatile, clang::QualType ty, LValueBaseInfo baseInfo, bool isInit=false, bool isNontemporal=false)
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.
mlir::MLIRContext & getMLIRContext()
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.
This trivial value class is used to represent the result of an expression that is evaluated.
mlir::Value getValue() const
Return the value of this scalar value.
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.
bool isa(CodeGen::Address addr)
@ Dtor_Complete
Complete object dtor.
U cast(CodeGen::Address addr)
static bool addressSpace()
static bool aggValueSlotGC()
Represents a scope, including function bodies, compound statements, and the substatements of if/while...