16#include "mlir/IR/Location.h"
18#include "clang/AST/Attrs.inc"
33 mlir::OpBuilder::InsertPoint ip) {
47 "emitAutoVarAlloca: decl escaping by reference");
71 getContext().getBaseElementType(ty)->isObjCObjectPointerType()) &&
85 (
cgm.getCodeGenOpts().MergeAllConstants && !nrvo &&
105 if (
const auto *cxxrd = dyn_cast<CXXRecordDecl>(rd);
106 (cxxrd && !cxxrd->hasTrivialDestructor()) ||
107 rd->isNonTrivialToPrimitiveDestroy()) {
112 cir::ConstantOp falseNVRO = builder.getFalse(loc);
116 assert(builder.getInsertionBlock());
117 builder.createStore(loc, falseNVRO, nrvoFlag);
129 nullptr,
nullptr, ip);
140 cgm.getDataLayout().getAlignment(defaultTy,
false));
143 mlir::Value v = builder.createStackSave(loc, defaultTy);
145 builder.createStore(loc, v, stack);
160 nullptr, builder.saveInsertionPoint());
168 emission.
addr = address;
182 if (constructor->isTrivial() && constructor->isDefaultConstructor() &&
183 !construct->requiresZeroInitialization())
192 mlir::TypedAttr constant) {
193 mlir::Type ty = constant.getType();
214 mlir::Location loc = builder.getUnknownLoc();
228 assert(emission.
variable &&
"emission was not valid!");
244 if (!init &&
type.isNonTrivialToPrimitiveDefaultInitialize() ==
247 "emitAutoVarInit: non-trivial to default initialize");
262 : (d.
getAttr<UninitializedAttr>()
266 auto initializeWhatIsTechnicallyUninitialized = [&](
Address addr) {
267 if (trivialAutoVarInit ==
275 initializeWhatIsTechnicallyUninitialized(addr);
279 mlir::Attribute constant;
288 if (constant && !mlir::isa<cir::ZeroAttr>(constant) &&
289 (trivialAutoVarInit !=
301 initializeWhatIsTechnicallyUninitialized(addr);
309 assert(addr.
isValid() &&
"Should have an address");
311 assert(allocaOp &&
"Address should come straight out of the alloca");
313 if (!allocaOp.use_empty())
321 auto typedConstant = mlir::dyn_cast<mlir::TypedAttr>(constant);
322 assert(typedConstant &&
"expected typed attribute");
326 assert(init &&
"expected initializer");
330 RValue::get(builder.getConstant(initLoc, typedConstant)), lv);
376 cir::GlobalLinkageKind linkage =
cgm.getCIRLinkageVarDefinition(&d);
390 CIRGenFunction::VarDeclContext varDeclCtx{*
this, &d};
400 std::string contextName;
402 if (
auto *cd = dyn_cast<CapturedDecl>(dc))
404 if (
const auto *fd = dyn_cast<FunctionDecl>(dc))
408 "getStaticDeclName: block decl context for static var");
411 "getStaticDeclName: ObjC decl context for static var");
414 "getStaticDeclName: Unknown context for static var decl");
424 cir::GlobalLinkageKind linkage) {
446 mlir::Attribute init =
nullptr;
448 d.
hasAttr<CUDASharedAttr>() || d.
hasAttr<LoaderUninitializedAttr>())
449 init = cir::UndefAttr::get(lty);
453 cir::GlobalOp gv = builder.createVersionedGlobal(
458 gv.setInitialValueAttr(init);
459 gv.setAlignment(
getASTContext().getDeclAlign(&d).getAsAlign().value());
494 if (
const auto *cd = dyn_cast<CXXConstructorDecl>(dc))
496 else if (
const auto *dd = dyn_cast<CXXDestructorDecl>(dc))
498 else if (
const auto *fd = dyn_cast<FunctionDecl>(dc))
510 "OpenMP: DisableAutoDeclareTargetRAII for static local");
519 mlir::Attribute constAttr,
521 auto functionName = [&](
const DeclContext *dc) -> std::string {
522 if (
const auto *fd = dyn_cast<FunctionDecl>(dc)) {
523 if (
const auto *cc = dyn_cast<CXXConstructorDecl>(fd))
524 return cc->getNameAsString();
525 if (
const auto *cd = dyn_cast<CXXDestructorDecl>(fd))
526 return cd->getNameAsString();
528 }
else if (
const auto *om = dyn_cast<ObjCMethodDecl>(dc)) {
529 return om->getNameAsString();
535 llvm_unreachable(
"expected a function or method");
542 if (!cacheEntry || cacheEntry.getInitialValue() != constAttr) {
543 auto ty = mlir::cast<mlir::TypedAttr>(constAttr).getType();
544 bool isConstant =
true;
550 name = (
"__const." + functionName(dc) +
"." + d.
getName()).str();
552 llvm_unreachable(
"local variable has no parent function or method");
555 cir::GlobalOp gv = builder.createVersionedGlobal(
557 cir::GlobalLinkageKind::PrivateLinkage);
561 cir::GlobalLinkageKind::PrivateLinkage));
562 gv.setInitialValueAttr(constAttr);
563 gv.setAlignment(align.getAsAlign().value());
567 }
else if (cacheEntry.getAlignment() < align.getQuantity()) {
568 cacheEntry.setAlignment(align.getAsAlign().value());
573 mlir::Type eltTy = mlir::cast<mlir::TypedAttr>(constAttr).getType();
574 auto ptrTy = builder.getPointerTo(cacheEntry.getSymType());
575 mlir::Value globalPtr = cir::GetGlobalOp::create(
577 return Address(globalPtr, eltTy, align);
584 const VarDecl &d, cir::GlobalOp gv, cir::GetGlobalOp gvAddr) {
586 mlir::TypedAttr init = mlir::dyn_cast_if_present<mlir::TypedAttr>(
594 "constant l-value expression");
600 gv.setConstant(
false);
602 gvAddr.setStaticLocal(
true);
616 if (gv.getSymType() != init.getType()) {
617 gv.setSymType(init.getType());
625 gvAddr.getAddr().setType(builder.getPointerTo(init.getType()));
633 gv.setInitialValueAttr(init);
642 gvAddr.setStaticLocal(
true);
649 cir::GlobalLinkageKind linkage) {
653 cir::GlobalOp globalOp =
cgm.getOrCreateStaticVarDecl(d, linkage);
658 auto getAddrOp = addr.getDefiningOp<cir::GetGlobalOp>();
659 assert(getAddrOp &&
"expected cir::GetGlobalOp");
673 "emitStaticVarDecl: variably modified type");
677 mlir::Type expectedType = addr.getType();
679 cir::GlobalOp var = globalOp;
687 var.setAlignment(alignment.
getAsAlign().value());
692 cgm.addGlobalAnnotations(&d, var);
693 if (d.
getAttr<PragmaClangBSSSectionAttr>())
695 "emitStaticVarDecl: CIR global BSS section attribute");
696 if (d.
getAttr<PragmaClangDataSectionAttr>())
698 "emitStaticVarDecl: CIR global Data section attribute");
699 if (d.
getAttr<PragmaClangRodataSectionAttr>())
701 "emitStaticVarDecl: CIR global Rodata section attribute");
702 if (d.
getAttr<PragmaClangRelroSectionAttr>())
704 "emitStaticVarDecl: CIR global Relro section attribute");
708 "emitStaticVarDecl: CIR global object file section attribute");
710 if (
cgm.getCodeGenOpts().KeepPersistentStorageVariables)
719 mlir::Value castedAddr =
720 builder.createBitcast(getAddrOp.getAddr(), expectedType);
722 cgm.setStaticLocalDeclAddress(&d, var);
729 LValue lvalue,
bool capturedByInit) {
734 if (capturedByInit) {
743 LValue lvalue,
bool capturedByInit) {
745 if (capturedByInit) {
752 if (
type->isReferenceType()) {
767 "emitExprAsInit: complex type captured by init");
782 llvm_unreachable(
"bad evaluation kind");
787 case Decl::BuiltinTemplate:
788 case Decl::TranslationUnit:
789 case Decl::ExternCContext:
790 case Decl::Namespace:
791 case Decl::UnresolvedUsingTypename:
792 case Decl::ClassTemplateSpecialization:
793 case Decl::ClassTemplatePartialSpecialization:
794 case Decl::VarTemplateSpecialization:
795 case Decl::VarTemplatePartialSpecialization:
796 case Decl::TemplateTypeParm:
797 case Decl::UnresolvedUsingValue:
798 case Decl::NonTypeTemplateParm:
799 case Decl::CXXDeductionGuide:
800 case Decl::CXXMethod:
801 case Decl::CXXConstructor:
802 case Decl::CXXDestructor:
803 case Decl::CXXConversion:
805 case Decl::MSProperty:
806 case Decl::IndirectField:
808 case Decl::ObjCAtDefsField:
810 case Decl::ImplicitParam:
811 case Decl::ClassTemplate:
812 case Decl::VarTemplate:
813 case Decl::FunctionTemplate:
814 case Decl::TypeAliasTemplate:
815 case Decl::TemplateTemplateParm:
816 case Decl::ObjCMethod:
817 case Decl::ObjCCategory:
818 case Decl::ObjCProtocol:
819 case Decl::ObjCInterface:
820 case Decl::ObjCCategoryImpl:
821 case Decl::ObjCImplementation:
822 case Decl::ObjCProperty:
823 case Decl::ObjCCompatibleAlias:
824 case Decl::PragmaComment:
825 case Decl::PragmaDetectMismatch:
826 case Decl::AccessSpec:
827 case Decl::LinkageSpec:
829 case Decl::ObjCPropertyImpl:
830 case Decl::FileScopeAsm:
832 case Decl::FriendTemplate:
834 case Decl::OutlinedFunction:
836 case Decl::UsingShadow:
837 case Decl::ConstructorUsingShadow:
838 case Decl::ObjCTypeParam:
840 case Decl::UnresolvedUsingIfExists:
841 case Decl::HLSLBuffer:
842 case Decl::HLSLRootSignature:
843 llvm_unreachable(
"Declaration should not be in declstmts!");
846 case Decl::EnumConstant:
847 case Decl::ExplicitInstantiation:
848 case Decl::StaticAssert:
852 case Decl::TemplateParamObject:
855 case Decl::LifetimeExtendedTemporary:
856 case Decl::RequiresExprBody:
857 case Decl::UnnamedGlobalConstant:
863 case Decl::CXXRecord:
864 case Decl::NamespaceAlias:
866 case Decl::UsingEnum:
867 case Decl::UsingDirective:
871 case Decl::Decomposition: {
874 "Should not see file-scope variables inside a function!");
876 if (evaluateConditionDecl)
880 case Decl::OpenACCDeclare:
883 case Decl::OpenACCRoutine:
886 case Decl::OMPThreadPrivate:
889 case Decl::OMPGroupPrivate:
892 case Decl::OMPAllocate:
895 case Decl::OMPCapturedExpr:
898 case Decl::OMPRequires:
901 case Decl::OMPDeclareMapper:
904 case Decl::OMPDeclareReduction:
908 case Decl::TypeAlias: {
915 case Decl::ImplicitConceptSpecialization:
916 case Decl::TopLevelStmt:
917 case Decl::UsingPack:
919 std::string(
"emitDecl: unhandled decl type: ") +
926 if (!
sanOpts.has(SanitizerKind::NullabilityAssign))
936 : addr(addr),
type(
type), destroyer(destroyer) {
951 DestroyNRVOVariable(Address addr, QualType
type, mlir::Value nrvoFlag)
952 : nrvoFlag(nrvoFlag), addr(addr), ty(
type) {}
954 mlir::Value nrvoFlag;
958 void emit(CIRGenFunction &cgf, Flags flags)
override {
960 bool nrvo = flags.isForNormalCleanup() && nrvoFlag;
963 mlir::OpBuilder::InsertionGuard guard(builder);
966 mlir::Location loc = addr.
getPointer().getLoc();
968 mlir::Value notNRVO = builder.
createNot(didNRVO);
969 cir::IfOp::create(builder, loc, notNRVO,
false,
970 [&](mlir::OpBuilder &b, mlir::Location) {
971 static_cast<Derived *
>(
this)->emitDestructorCall(cgf);
975 static_cast<Derived *
>(
this)->emitDestructorCall(cgf);
979 virtual ~DestroyNRVOVariable() =
default;
982struct DestroyNRVOVariableCXX final
983 : DestroyNRVOVariable<DestroyNRVOVariableCXX> {
984 DestroyNRVOVariableCXX(Address addr, QualType
type,
985 const CXXDestructorDecl *dtor, mlir::Value nrvoFlag)
986 : DestroyNRVOVariable<DestroyNRVOVariableCXX>(addr,
type, nrvoFlag),
989 const CXXDestructorDecl *dtor;
991 void emitDestructorCall(CIRGenFunction &cgf) {
1000 CallStackRestore(Address stack) : stack(stack) {}
1001 void emit(CIRGenFunction &cgf, Flags flags)
override {
1002 mlir::Location loc = stack.
getPointer().getLoc();
1011 mlir::Value arrayBegin;
1013 QualType elementType;
1014 CharUnits elementAlign;
1017 IrregularPartialArrayDestroy(mlir::Value arrayBegin, Address arrayEndPointer,
1018 QualType elementType, CharUnits elementAlign,
1020 : arrayBegin(arrayBegin), arrayEndPointer(arrayEndPointer),
1021 elementType(elementType), elementAlign(elementAlign),
1022 destroyer(destroyer) {}
1024 void emit(CIRGenFunction &cgf, Flags flags)
override {
1026 mlir::Location loc = arrayBegin.getLoc();
1028 mlir::Value arrayEnd = builder.
createLoad(loc, arrayEndPointer);
1034 cir::PointerType ptrToElmType = builder.
getPointerTo(cirElementType);
1036 mlir::Value ne = cir::CmpOp::create(builder, loc, cir::CmpOpKind::ne,
1037 arrayEnd, arrayBegin);
1039 builder, loc, ne,
false,
1040 [&](mlir::OpBuilder &b, mlir::Location loc) {
1047 [&](mlir::OpBuilder &b, mlir::Location loc) {
1048 mlir::Value cur = builder.
createLoad(loc, iterAddr);
1049 mlir::Value cmp = cir::CmpOp::create(
1050 builder, loc, cir::CmpOpKind::ne, cur, arrayBegin);
1054 [&](mlir::OpBuilder &b, mlir::Location loc) {
1055 mlir::Value cur = builder.
createLoad(loc, iterAddr);
1057 loc, mlir::cast<cir::IntType>(cgf.
ptrDiffTy), -1);
1058 mlir::Value prev = cir::PtrStrideOp::create(
1059 builder, loc, ptrToElmType, cur, negOne);
1062 destroyer(cgf, elemAddr, elementType);
1082 ehStack.pushCleanup<IrregularPartialArrayDestroy>(
1083 EHCleanup, arrayBegin, arrayEndPointer, elementType, elementAlign,
1102 assert(dtorKind &&
"cannot push destructor for trivial type");
1115 assert(dtorKind &&
"cannot push destructor for trivial type");
1124 bool useEHCleanupForArray) {
1133 bool useEHCleanupForArray) {
1135 cgm.errorNYI(
"conditional lifetime-extended destroy");
1142 useEHCleanupForArray);
1169 mlir::Value numElements,
1178 cir::PointerType ptrToElmType = builder.getPointerTo(cirElementType);
1180 auto regionBuilder = [&](mlir::OpBuilder &b, mlir::Location loc) {
1181 mlir::BlockArgument arg =
1182 b.getInsertionBlock()->addArgument(ptrToElmType, loc);
1187 destroyer(*
this, curAddr, elementType);
1189 cir::YieldOp::create(b, loc);
1193 if (
auto constantCount = numElements.getDefiningOp<cir::ConstantOp>()) {
1195 if (
auto constIntAttr = constantCount.getValueAttr<cir::IntAttr>())
1196 size = constIntAttr.getUInt();
1197 auto arrayTy = cir::ArrayType::get(cirElementType, size);
1198 mlir::Value arrayOp = builder.createPtrBitcast(begin, arrayTy);
1199 cir::ArrayDtor::create(builder, *
currSrcLoc, arrayOp, regionBuilder);
1204 mlir::Value elemBegin = builder.createPtrBitcast(begin, cirElementType);
1205 cir::ArrayDtor::create(builder, *
currSrcLoc, elemBegin, numElements,
1220 return destroyer(*
this, addr,
type);
1228 auto constantCount =
length.getDefiningOp<cir::ConstantOp>();
1229 if (constantCount) {
1230 auto constIntAttr = mlir::dyn_cast<cir::IntAttr>(constantCount.getValue());
1231 if (constIntAttr && constIntAttr.getUInt() == 0)
1240 if (constantCount && constantCount.use_empty())
1241 constantCount.erase();
1248 llvm_unreachable(
"no destroyer for trivial dtor");
1254 cgm.errorNYI(
"getDestroyer: other destruction kind");
1257 llvm_unreachable(
"Unknown DestructionKind");
1261 ehStack.pushCleanup<CallStackRestore>(
kind, spMem);
1282 llvm_unreachable(
"no cleanup for trivially-destructible variable");
1288 assert(!
type->isArrayType());
1290 ehStack.pushCleanup<DestroyNRVOVariableCXX>(cleanupKind, addr,
type, dtor,
1300 cgm.errorNYI(var->getSourceRange(),
1301 "emitAutoVarTypeCleanup: other dtor kind");
1310 ehStack.pushCleanup<DestroyObject>(cleanupKind, addr,
type, destroyer);
1314 if (
auto *dd = dyn_cast_if_present<DecompositionDecl>(vd)) {
1315 for (
auto *b : dd->flat_bindings())
1316 if (
auto *hd = b->getHoldingVar())
static void emit(Program &P, llvm::SmallVectorImpl< std::byte > &Code, const T &Val, bool &Success)
Helper to write bytecode and bail out if 32-bit offsets become invalid.
static void emitStoresForConstant(CIRGenModule &cgm, const VarDecl &d, Address addr, bool isVolatile, CIRGenBuilderTy &builder, mlir::TypedAttr constant)
static std::string getStaticDeclName(CIRGenModule &cgm, const VarDecl &d)
This file defines OpenACC nodes for declarative directives.
Defines the clang::Expr interface and subclasses for C++ expressions.
*collection of selector each with an associated kind and an ordered *collection of selectors A selector has a kind
cir::ConditionOp createCondition(mlir::Value condition)
Create a loop condition.
cir::ConstantOp getConstant(mlir::Location loc, mlir::TypedAttr attr)
cir::PointerType getPointerTo(mlir::Type ty)
cir::DoWhileOp createDoWhile(mlir::Location loc, llvm::function_ref< void(mlir::OpBuilder &, mlir::Location)> condBuilder, llvm::function_ref< void(mlir::OpBuilder &, mlir::Location)> bodyBuilder)
Create a do-while operation.
mlir::Value createNot(mlir::Location loc, mlir::Value value)
cir::YieldOp createYield(mlir::Location loc, mlir::ValueRange value={})
Create a yield operation.
cir::LoadOp createFlagLoad(mlir::Location loc, mlir::Value addr)
Emit a load from an boolean flag variable.
llvm::TypeSize getTypeAllocSize(mlir::Type ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
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.
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
Represents an array type, per C99 6.7.5.2 - Array Declarators.
mlir::Value getPointer() const
mlir::Type getElementType() const
Address withElementType(CIRGenBuilderTy &builder, mlir::Type ElemTy) const
Return address with different element type, a bitcast pointer, and the same alignment.
clang::CharUnits getAlignment() const
cir::AllocaOp getUnderlyingAllocaOp() const
Return the underlying alloca for this address, if any.
static AggValueSlot forLValue(const LValue &LV, IsDestructed_t isDestructed, IsAliased_t isAliased, Overlap_t mayOverlap, IsZeroed_t isZeroed=IsNotZeroed)
cir::StackRestoreOp createStackRestore(mlir::Location loc, mlir::Value v)
cir::StoreOp createStore(mlir::Location loc, mlir::Value val, Address dst, bool isVolatile=false, mlir::IntegerAttr align={}, cir::SyncScopeKindAttr scope={}, cir::MemOrderAttr order={})
cir::ConstantOp getConstInt(mlir::Location loc, llvm::APSInt intVal)
cir::LoadOp createLoad(mlir::Location loc, Address addr, bool isVolatile=false)
void emitOpenACCRoutine(const OpenACCRoutineDecl &d)
cir::GlobalOp addInitializerToStaticVarDecl(const VarDecl &d, cir::GlobalOp gv, cir::GetGlobalOp gvAddr)
Add the initializer for 'd' to the global variable that has already been created for it.
static cir::TypeEvaluationKind getEvaluationKind(clang::QualType type)
Return the cir::TypeEvaluationKind of QualType type.
AutoVarEmission emitAutoVarAlloca(const clang::VarDecl &d, mlir::OpBuilder::InsertPoint ip={})
void emitAutoVarTypeCleanup(const AutoVarEmission &emission, clang::QualType::DestructionKind dtorKind)
Enter a destroy cleanup for the given local variable.
void emitVariablyModifiedType(QualType ty)
const clang::LangOptions & getLangOpts() const
cir::AllocaOp createTempAlloca(mlir::Type ty, mlir::Location loc, const Twine &name="tmp", mlir::Value arraySize=nullptr, bool insertIntoFnEntryBlock=false)
This creates an alloca and inserts it into the entry block if ArraySize is nullptr,...
bool isInConditionalBranch() const
void emitOMPRequiresDecl(const OMPRequiresDecl &d)
VlaSizePair getVLASize(const VariableArrayType *type)
Returns an MLIR::Value+QualType pair that corresponds to the size, in non-variably-sized elements,...
void emitStaticVarDecl(const VarDecl &d, cir::GlobalLinkageKind linkage)
mlir::Value emitComplexExpr(const Expr *e)
Emit the computation of the specified expression of complex type, returning the result.
bool isTrivialInitializer(const Expr *init)
Determine whether the given initializer is trivial in the sense that it requires no code to be genera...
void emitOpenACCDeclare(const OpenACCDeclareDecl &d)
void pushIrregularPartialArrayCleanup(mlir::Value arrayBegin, Address arrayEndPointer, QualType elementType, CharUnits elementAlign, Destroyer *destroyer)
Push an EH cleanup to destroy already-constructed elements of the given array.
void pushCleanupAndDeferDeactivation(CleanupKind kind, As... a)
Push a cleanup and record it for deferred deactivation.
mlir::Location getLoc(clang::SourceLocation srcLoc)
Helpers to convert Clang's SourceLocation to a MLIR Location.
void emitOMPDeclareReduction(const OMPDeclareReductionDecl &d)
void emitExprAsInit(const clang::Expr *init, const clang::ValueDecl *d, LValue lvalue, bool capturedByInit=false)
Emit an expression as an initializer for an object (variable, field, etc.) at the given location.
void emitCXXGuardedInit(const VarDecl &varDecl, cir::GlobalOp globalOp, bool performInit)
Emit a guarded initializer for a static local variable.
mlir::Value emitArrayLength(const clang::ArrayType *arrayType, QualType &baseType, Address &addr)
Computes the length of an array in elements, as well as the base element type and a properly-typed fi...
RValue emitReferenceBindingToExpr(const Expr *e)
Emits a reference binding to the passed in expression.
void pushDestroyAndDeferDeactivation(QualType::DestructionKind dtorKind, Address addr, QualType type)
CleanupKind getCleanupKind(QualType::DestructionKind kind)
void emitOMPAllocateDecl(const OMPAllocateDecl &d)
void emitOMPDeclareMapper(const OMPDeclareMapperDecl &d)
EHScopeStack ehStack
Tracks function scope overall cleanup handling.
clang::SanitizerSet sanOpts
Sanitizers enabled for this function.
mlir::Type convertTypeForMem(QualType t)
void pushDestroy(QualType::DestructionKind dtorKind, Address addr, QualType type)
Push the standard destructor for the given type as at least a normal cleanup.
void emitVarDecl(const clang::VarDecl &d)
This method handles emission of any variable declaration inside a function, including static vars etc...
static Destroyer destroyCXXObject
Address returnValue
The temporary alloca to hold the return value.
void emitArrayDestroy(mlir::Value begin, mlir::Value numElements, QualType elementType, CharUnits elementAlign, Destroyer *destroyer)
Destroys all the elements of the given array, beginning from last to first.
void emitStoreOfComplex(mlir::Location loc, mlir::Value v, LValue dest, bool isInit)
EmitStoreOfComplex - Store a complex number into the specified l-value.
void emitScalarInit(const clang::Expr *init, mlir::Location loc, LValue lvalue, bool capturedByInit=false)
void emitAutoVarInit(const AutoVarEmission &emission)
Emit the initializer for an allocated variable.
void maybeEmitDeferredVarDeclInit(const VarDecl *vd)
mlir::Value emitScalarExpr(const clang::Expr *e, bool ignoreResultAssign=false)
Emit the computation of the specified expression of scalar type.
void pushStackRestore(CleanupKind kind, Address spMem)
void emitAutoVarDecl(const clang::VarDecl &d)
Emit code and set up symbol table for a variable declaration with auto, register, or no storage class...
bool needsEHCleanup(QualType::DestructionKind kind)
Determines whether an EH cleanup is required to destroy a type with the given destruction kind.
CIRGenBuilderTy & getBuilder()
bool didCallStackSave
Whether a cir.stacksave operation has been added.
void emitDecl(const clang::Decl &d, bool evaluateConditionDecl=false)
void emitDestroy(Address addr, QualType type, Destroyer *destroyer)
Immediately perform the destruction of the given object.
void pushPendingCleanupToEHStack(const PendingCleanupEntry &entry)
Promote a single pending cleanup entry onto the EH scope stack.
llvm::DenseMap< const VarDecl *, mlir::Value > nrvoFlags
A mapping from NRVO variables to the flags used to indicate when the NRVO has been applied to this va...
mlir::MLIRContext & getMLIRContext()
Destroyer * getDestroyer(clang::QualType::DestructionKind kind)
void Destroyer(CIRGenFunction &cgf, Address addr, QualType ty)
DeclMapTy localDeclMap
This keeps track of the CIR allocas or globals for local C declarations.
void pushEHDestroyIfNeeded(QualType::DestructionKind dtorKind, Address addr, QualType type)
pushEHDestroyIfNeeded - Push the standard destructor for the given type as an EH-only cleanup.
void emitOMPThreadPrivateDecl(const OMPThreadPrivateDecl &d)
void emitOMPGroupPrivateDecl(const OMPGroupPrivateDecl &d)
LValue makeAddrLValue(Address addr, QualType ty, AlignmentSource source=AlignmentSource::Type)
void emitCXXDestructorCall(const CXXDestructorDecl *dd, CXXDtorType type, bool forVirtualBase, bool delegating, Address thisAddr, QualType thisTy)
void pushFullExprCleanup(CleanupKind kind, As... a)
Push a cleanup to be run at the end of the current full-expression.
std::optional< mlir::Location > currSrcLoc
Use to track source locations across nested visitor traversals.
clang::ASTContext & getContext() const
void setAddrOfLocalVar(const clang::VarDecl *vd, Address addr)
Set the address of a local variable.
void pushCleanupAfterFullExpr(CleanupKind kind, Address addr, QualType type, Destroyer *destroyer)
Queue a cleanup to be pushed after finishing the current full-expression.
void emitNullabilityCheck(LValue lhs, mlir::Value rhs, clang::SourceLocation loc)
Given an assignment *lhs = rhs, emit a test that checks if rhs is nonnull, if 1LHS is marked _Nonnull...
void emitOMPCapturedExpr(const OMPCapturedExprDecl &d)
void emitStoreThroughLValue(RValue src, LValue dst, bool isInit=false)
Store the specified rvalue into the specified lvalue, where both are guaranteed to the have the same ...
void pushLifetimeExtendedDestroy(CleanupKind kind, Address addr, QualType type, Destroyer *destroyer, bool useEHCleanupForArray)
void emitAggExpr(const clang::Expr *e, AggValueSlot slot)
void emitAutoVarCleanups(const AutoVarEmission &emission)
This class organizes the cross-function state that is used while generating CIR code.
llvm::StringRef getMangledName(clang::GlobalDecl gd)
cir::GlobalOp getOrCreateStaticVarDecl(const VarDecl &d, cir::GlobalLinkageKind linkage)
DiagnosticBuilder errorNYI(SourceLocation, llvm::StringRef)
Helpers to emit "not yet implemented" error diagnostics.
clang::ASTContext & getASTContext() const
void insertGlobalSymbol(mlir::Operation *op)
mlir::Type convertType(clang::QualType type)
llvm::DenseMap< const VarDecl *, cir::GlobalOp > initializerConstants
void setGVProperties(mlir::Operation *op, const NamedDecl *d) const
Set visibility, dllimport/dllexport and dso_local.
static mlir::SymbolTable::Visibility getMLIRVisibilityFromCIRLinkage(cir::GlobalLinkageKind GLK)
void setTLSMode(mlir::Operation *op, const VarDecl &d, bool isExtendingDecl=false)
Set TLS mode for the given operation based on the given variable declaration.
const clang::LangOptions & getLangOpts() const
void setStaticLocalDeclAddress(const VarDecl *d, cir::GlobalOp c)
mlir::Location getLoc(clang::SourceLocation cLoc)
Helpers to convert the presumed location of Clang's SourceLocation to an MLIR Location.
mlir::ModuleOp getModule() const
bool supportsCOMDAT() const
mlir::MLIRContext & getMLIRContext()
mlir::Operation * getAddrOfGlobal(clang::GlobalDecl gd, ForDefinition_t isForDefinition=NotForDefinition)
cir::GlobalOp getStaticLocalDeclAddress(const VarDecl *d)
Address createUnnamedGlobalFrom(const VarDecl &d, mlir::Attribute constAttr, CharUnits align)
mlir::Type convertTypeForMem(clang::QualType, bool forBitField=false)
Convert type T into an mlir::Type.
void finalize(cir::GlobalOp gv)
mlir::Attribute tryEmitForInitializer(const VarDecl &d)
Try to emit the initializer of the given declaration as an abstract constant.
mlir::Attribute tryEmitAbstractForInitializer(const VarDecl &d)
Try to emit the initializer of the given declaration as an abstract constant.
A cleanup scope which generates the cleanup blocks lazily.
void setTestFlagInEHCleanup(bool value)
void setTestFlagInNormalCleanup(bool value)
bool isNormalCleanup() const
void setActiveFlag(Address var)
Information for lazily generating a cleanup.
Address getAddress() const
This trivial value class is used to represent the result of an expression that is evaluated.
static RValue get(mlir::Value v)
Represents a call to a C++ constructor.
Represents a C++ constructor within a class.
Represents a C++ destructor within a class.
CharUnits - This is an opaque type for sizes expressed in character units.
llvm::Align getAsAlign() const
getAsAlign - Returns Quantity as a valid llvm::Align, Beware llvm::Align assumes power of two 8-bit b...
static CharUnits One()
One - Construct a CharUnits quantity of one.
CharUnits alignmentOfArrayElement(CharUnits elementSize) const
Given that this is the alignment of the first element of an array, return the minimum alignment of an...
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
const DeclContext * getParentFunctionOrMethod(bool LexicalParent=false) const
If this decl is defined inside a function/method/block it returns the corresponding DeclContext,...
Decl * getNonClosureContext()
Find the innermost non-closure ancestor of this declaration, walking up through blocks,...
SourceLocation getLocation() const
const char * getDeclKindName() const
DeclContext * getDeclContext()
virtual SourceRange getSourceRange() const LLVM_READONLY
Source range that this declaration covers.
This represents one expression.
bool isConstantInitializer(ASTContext &Ctx, bool ForRef=false, const Expr **Culprit=nullptr) const
Returns true if this expression can be emitted to IR as a constant, and thus can be used as a constan...
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
GlobalDecl - represents a global declaration.
const Decl * getDecl() const
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
std::string getNameAsString() const
Get a human-readable name for the declaration, even if it is one of the special kinds of names (C++ c...
bool isExternallyVisible() const
A (possibly-)qualified type.
@ DK_objc_strong_lifetime
@ PDIK_Struct
The type is a struct containing a field whose type is not PCK_Trivial.
LangAS getAddressSpace() const
Return the address space of this type.
bool isConstantStorage(const ASTContext &Ctx, bool ExcludeCtor, bool ExcludeDtor)
bool isPODType(const ASTContext &Context) const
Determine whether this is a Plain Old Data (POD) type (C++ 3.9p10).
Represents a struct/union/class.
Encodes a location in the source.
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
bool isConstantSizeType() const
Return true if this is not a variable sized type, according to the rules of C99 6....
bool isVariablyModifiedType() const
Whether this type is a variably-modified type (C99 6.7.5).
bool isVectorType() const
bool isRecordType() const
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Represents a variable declaration or definition.
bool isConstexpr() const
Whether this variable is (C++11) constexpr.
TLSKind getTLSKind() const
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
bool hasFlexibleArrayInit(const ASTContext &Ctx) const
Whether this variable has a flexible array member initialized with one or more elements.
bool hasGlobalStorage() const
Returns true for all variables that do not have local storage.
bool mightBeUsableInConstantExpressions(const ASTContext &C) const
Determine whether this variable's value might be usable in a constant expression, according to the re...
bool isNRVOVariable() const
Determine whether this local variable can be used with the named return value optimization (NRVO).
QualType::DestructionKind needsDestruction(const ASTContext &Ctx) const
Would the destruction of this variable have any effect, and if so, what kind?
const Expr * getInit() const
bool hasExternalStorage() const
Returns true if a variable has extern or private_extern storage.
bool hasLocalStorage() const
Returns true if a variable with function scope is a non-static local variable.
@ TLS_None
Not a TLS variable.
bool isLocalVarDecl() const
Returns true for local variable declarations other than parameters.
StorageDuration getStorageDuration() const
Get the storage duration of this variable, per C++ [basic.stc].
bool isEscapingByref() const
Indicates the capture is a __block variable that is captured by a block that can potentially escape (...
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
@ EHCleanup
Denotes a cleanup that should run when a scope is exited using exceptional control flow (a throw stat...
@ NormalCleanup
Denotes a cleanup that should run when a scope is exited using normal control flow (falling off the e...
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const AstTypeMatcher< ArrayType > arrayType
@ Address
A pointer to a ValueDecl.
The JSON file list parser is used to communicate input to InstallAPI.
@ Ctor_Base
Base object ctor.
bool isa(CodeGen::Address addr)
@ SD_Automatic
Automatic storage duration (most local variables).
@ Dtor_Base
Base object dtor.
@ Dtor_Complete
Complete object dtor.
U cast(CodeGen::Address addr)
float __ovld __cnfn length(float)
Return the length of vector p, i.e., sqrt(p.x2 + p.y 2 + ...)
static bool objCLifetime()
static bool addAutoInitAnnotation()
static bool addressSpace()
static bool emitNullabilityCheck()
static bool useEHCleanupForArray()
static bool vectorConstants()
static bool aggValueSlotMayOverlap()
static bool dtorCleanups()
static bool dataLayoutTypeAllocSize()
static bool opAllocaCaptureByInit()
static bool opAllocaPreciseLifetime()
static bool cudaSupport()
static bool generateDebugInfo()
bool wasEmittedAsGlobal() const
bool isEscapingByRef
True if the variable is a __block variable that is captured by an escaping block.
Address addr
The address of the alloca for languages with explicit address space (e.g.
const clang::VarDecl * variable
bool isConstantAggregate
True if the variable is of aggregate type and has a constant initializer.
bool wasEmittedAsOffloadClause() const
Address getObjectAddress(CIRGenFunction &cgf) const
Returns the address of the object within this declaration.
A cleanup entry that will be promoted onto the EH scope stack at a later point.
clang::CharUnits getPointerAlign() const
cir::PointerType allocaInt8PtrTy
void* in alloca address space