16#include "mlir/IR/Location.h"
18#include "clang/AST/Attrs.inc"
32 mlir::OpBuilder::InsertPoint ip) {
45 "emitAutoVarAlloca: decl escaping by reference");
69 getContext().getBaseElementType(ty)->isObjCObjectPointerType()) &&
83 (
cgm.getCodeGenOpts().MergeAllConstants && !nrvo &&
103 if (
const auto *cxxrd = dyn_cast<CXXRecordDecl>(rd);
104 (cxxrd && !cxxrd->hasTrivialDestructor()) ||
105 rd->isNonTrivialToPrimitiveDestroy()) {
110 cir::ConstantOp falseNVRO = builder.getFalse(loc);
114 assert(builder.getInsertionBlock());
115 builder.createStore(loc, falseNVRO, nrvoFlag);
127 nullptr,
nullptr, ip);
138 cgm.getDataLayout().getAlignment(defaultTy,
false));
141 mlir::Value v = builder.createStackSave(loc, defaultTy);
143 builder.createStore(loc, v, stack);
158 nullptr, builder.saveInsertionPoint());
166 emission.
addr = address;
180 if (constructor->isTrivial() && constructor->isDefaultConstructor() &&
181 !construct->requiresZeroInitialization())
190 mlir::TypedAttr constant) {
191 mlir::Type ty = constant.getType();
212 mlir::Location loc = builder.getUnknownLoc();
226 assert(emission.
variable &&
"emission was not valid!");
242 if (!init &&
type.isNonTrivialToPrimitiveDefaultInitialize() ==
245 "emitAutoVarInit: non-trivial to default initialize");
260 : (d.
getAttr<UninitializedAttr>()
264 auto initializeWhatIsTechnicallyUninitialized = [&](
Address addr) {
265 if (trivialAutoVarInit ==
273 initializeWhatIsTechnicallyUninitialized(addr);
277 mlir::Attribute constant;
286 if (constant && !mlir::isa<cir::ZeroAttr>(constant) &&
287 (trivialAutoVarInit !=
299 initializeWhatIsTechnicallyUninitialized(addr);
307 assert(val &&
"Should have an address");
308 auto allocaOp = val.getDefiningOp<cir::AllocaOp>();
309 assert(allocaOp &&
"Address should come straight out of the alloca");
311 if (!allocaOp.use_empty())
319 auto typedConstant = mlir::dyn_cast<mlir::TypedAttr>(constant);
320 assert(typedConstant &&
"expected typed attribute");
324 assert(init &&
"expected initializer");
328 RValue::get(builder.getConstant(initLoc, typedConstant)), lv);
374 cir::GlobalLinkageKind linkage =
cgm.getCIRLinkageVarDefinition(&d);
388 CIRGenFunction::VarDeclContext varDeclCtx{*
this, &d};
398 std::string contextName;
400 if (
auto *cd = dyn_cast<CapturedDecl>(dc))
402 if (
const auto *fd = dyn_cast<FunctionDecl>(dc))
406 "getStaticDeclName: block decl context for static var");
409 "getStaticDeclName: ObjC decl context for static var");
412 "getStaticDeclName: Unknown context for static var decl");
422 cir::GlobalLinkageKind linkage) {
444 mlir::Attribute init =
nullptr;
446 d.
hasAttr<CUDASharedAttr>() || d.
hasAttr<LoaderUninitializedAttr>())
447 init = cir::UndefAttr::get(lty);
451 cir::GlobalOp gv = builder.createVersionedGlobal(
456 gv.setInitialValueAttr(init);
457 gv.setAlignment(
getASTContext().getDeclAlign(&d).getAsAlign().value());
494 else if (
const auto *fd = dyn_cast<FunctionDecl>(dc))
510 mlir::Attribute constAttr,
512 auto functionName = [&](
const DeclContext *dc) -> std::string {
513 if (
const auto *fd = dyn_cast<FunctionDecl>(dc)) {
514 if (
const auto *cc = dyn_cast<CXXConstructorDecl>(fd))
515 return cc->getNameAsString();
516 if (
const auto *cd = dyn_cast<CXXDestructorDecl>(fd))
517 return cd->getNameAsString();
519 }
else if (
const auto *om = dyn_cast<ObjCMethodDecl>(dc)) {
520 return om->getNameAsString();
526 llvm_unreachable(
"expected a function or method");
533 if (!cacheEntry || cacheEntry.getInitialValue() != constAttr) {
534 auto ty = mlir::cast<mlir::TypedAttr>(constAttr).getType();
535 bool isConstant =
true;
541 name = (
"__const." + functionName(dc) +
"." + d.
getName()).str();
543 llvm_unreachable(
"local variable has no parent function or method");
546 cir::GlobalOp gv = builder.createVersionedGlobal(
548 cir::GlobalLinkageKind::PrivateLinkage);
552 cir::GlobalLinkageKind::PrivateLinkage));
553 gv.setInitialValueAttr(constAttr);
554 gv.setAlignment(align.getAsAlign().value());
558 }
else if (cacheEntry.getAlignment() < align.getQuantity()) {
559 cacheEntry.setAlignment(align.getAsAlign().value());
564 mlir::Type eltTy = mlir::cast<mlir::TypedAttr>(constAttr).getType();
565 auto ptrTy = builder.getPointerTo(cacheEntry.getSymType());
566 mlir::Value globalPtr = cir::GetGlobalOp::create(
568 return Address(globalPtr, eltTy, align);
575 const VarDecl &d, cir::GlobalOp gv, cir::GetGlobalOp gvAddr) {
577 mlir::TypedAttr init = mlir::dyn_cast_if_present<mlir::TypedAttr>(
585 "constant l-value expression");
591 gv.setConstant(
false);
593 gvAddr.setStaticLocal(
true);
607 if (gv.getSymType() != init.getType()) {
608 gv.setSymType(init.getType());
616 gvAddr.getAddr().setType(builder.getPointerTo(init.getType()));
624 gv.setInitialValueAttr(init);
633 gvAddr.setStaticLocal(
true);
640 cir::GlobalLinkageKind linkage) {
644 cir::GlobalOp globalOp =
cgm.getOrCreateStaticVarDecl(d, linkage);
649 auto getAddrOp = addr.getDefiningOp<cir::GetGlobalOp>();
650 assert(getAddrOp &&
"expected cir::GetGlobalOp");
664 "emitStaticVarDecl: variably modified type");
668 mlir::Type expectedType = addr.getType();
670 cir::GlobalOp var = globalOp;
678 var.setAlignment(alignment.
getAsAlign().value());
683 cgm.addGlobalAnnotations(&d, var);
684 if (d.
getAttr<PragmaClangBSSSectionAttr>())
686 "emitStaticVarDecl: CIR global BSS section attribute");
687 if (d.
getAttr<PragmaClangDataSectionAttr>())
689 "emitStaticVarDecl: CIR global Data section attribute");
690 if (d.
getAttr<PragmaClangRodataSectionAttr>())
692 "emitStaticVarDecl: CIR global Rodata section attribute");
693 if (d.
getAttr<PragmaClangRelroSectionAttr>())
695 "emitStaticVarDecl: CIR global Relro section attribute");
699 "emitStaticVarDecl: CIR global object file section attribute");
701 if (
cgm.getCodeGenOpts().KeepPersistentStorageVariables)
710 mlir::Value castedAddr =
711 builder.createBitcast(getAddrOp.getAddr(), expectedType);
713 cgm.setStaticLocalDeclAddress(&d, var);
720 LValue lvalue,
bool capturedByInit) {
725 if (capturedByInit) {
734 LValue lvalue,
bool capturedByInit) {
736 if (capturedByInit) {
743 if (
type->isReferenceType()) {
758 "emitExprAsInit: complex type captured by init");
773 llvm_unreachable(
"bad evaluation kind");
778 case Decl::BuiltinTemplate:
779 case Decl::TranslationUnit:
780 case Decl::ExternCContext:
781 case Decl::Namespace:
782 case Decl::UnresolvedUsingTypename:
783 case Decl::ClassTemplateSpecialization:
784 case Decl::ClassTemplatePartialSpecialization:
785 case Decl::VarTemplateSpecialization:
786 case Decl::VarTemplatePartialSpecialization:
787 case Decl::TemplateTypeParm:
788 case Decl::UnresolvedUsingValue:
789 case Decl::NonTypeTemplateParm:
790 case Decl::CXXDeductionGuide:
791 case Decl::CXXMethod:
792 case Decl::CXXConstructor:
793 case Decl::CXXDestructor:
794 case Decl::CXXConversion:
796 case Decl::MSProperty:
797 case Decl::IndirectField:
799 case Decl::ObjCAtDefsField:
801 case Decl::ImplicitParam:
802 case Decl::ClassTemplate:
803 case Decl::VarTemplate:
804 case Decl::FunctionTemplate:
805 case Decl::TypeAliasTemplate:
806 case Decl::TemplateTemplateParm:
807 case Decl::ObjCMethod:
808 case Decl::ObjCCategory:
809 case Decl::ObjCProtocol:
810 case Decl::ObjCInterface:
811 case Decl::ObjCCategoryImpl:
812 case Decl::ObjCImplementation:
813 case Decl::ObjCProperty:
814 case Decl::ObjCCompatibleAlias:
815 case Decl::PragmaComment:
816 case Decl::PragmaDetectMismatch:
817 case Decl::AccessSpec:
818 case Decl::LinkageSpec:
820 case Decl::ObjCPropertyImpl:
821 case Decl::FileScopeAsm:
823 case Decl::FriendTemplate:
825 case Decl::OutlinedFunction:
827 case Decl::UsingShadow:
828 case Decl::ConstructorUsingShadow:
829 case Decl::ObjCTypeParam:
831 case Decl::UnresolvedUsingIfExists:
832 case Decl::HLSLBuffer:
833 case Decl::HLSLRootSignature:
834 llvm_unreachable(
"Declaration should not be in declstmts!");
837 case Decl::EnumConstant:
838 case Decl::ExplicitInstantiation:
839 case Decl::StaticAssert:
843 case Decl::TemplateParamObject:
846 case Decl::LifetimeExtendedTemporary:
847 case Decl::RequiresExprBody:
848 case Decl::UnnamedGlobalConstant:
854 case Decl::CXXRecord:
855 case Decl::NamespaceAlias:
857 case Decl::UsingEnum:
858 case Decl::UsingDirective:
862 case Decl::Decomposition: {
865 "Should not see file-scope variables inside a function!");
867 if (evaluateConditionDecl)
871 case Decl::OpenACCDeclare:
874 case Decl::OpenACCRoutine:
877 case Decl::OMPThreadPrivate:
880 case Decl::OMPGroupPrivate:
883 case Decl::OMPAllocate:
886 case Decl::OMPCapturedExpr:
889 case Decl::OMPRequires:
892 case Decl::OMPDeclareMapper:
895 case Decl::OMPDeclareReduction:
899 case Decl::TypeAlias: {
906 case Decl::ImplicitConceptSpecialization:
907 case Decl::TopLevelStmt:
908 case Decl::UsingPack:
910 std::string(
"emitDecl: unhandled decl type: ") +
917 if (!
sanOpts.has(SanitizerKind::NullabilityAssign))
927 : addr(addr),
type(
type), destroyer(destroyer) {
942 DestroyNRVOVariable(Address addr, QualType
type, mlir::Value nrvoFlag)
943 : nrvoFlag(nrvoFlag), addr(addr), ty(
type) {}
945 mlir::Value nrvoFlag;
949 void emit(CIRGenFunction &cgf, Flags flags)
override {
951 bool nrvo = flags.isForNormalCleanup() && nrvoFlag;
954 mlir::OpBuilder::InsertionGuard guard(builder);
957 mlir::Location loc = addr.
getPointer().getLoc();
959 mlir::Value notNRVO = builder.
createNot(didNRVO);
960 cir::IfOp::create(builder, loc, notNRVO,
false,
961 [&](mlir::OpBuilder &
b, mlir::Location) {
962 static_cast<Derived *
>(
this)->emitDestructorCall(cgf);
966 static_cast<Derived *
>(
this)->emitDestructorCall(cgf);
970 virtual ~DestroyNRVOVariable() =
default;
973struct DestroyNRVOVariableCXX final
974 : DestroyNRVOVariable<DestroyNRVOVariableCXX> {
975 DestroyNRVOVariableCXX(Address addr, QualType
type,
976 const CXXDestructorDecl *dtor, mlir::Value nrvoFlag)
977 : DestroyNRVOVariable<DestroyNRVOVariableCXX>(addr,
type, nrvoFlag),
980 const CXXDestructorDecl *dtor;
982 void emitDestructorCall(CIRGenFunction &cgf) {
991 CallStackRestore(Address stack) : stack(stack) {}
992 void emit(CIRGenFunction &cgf, Flags flags)
override {
993 mlir::Location loc = stack.
getPointer().getLoc();
1002 mlir::Value arrayBegin;
1004 QualType elementType;
1005 CharUnits elementAlign;
1008 IrregularPartialArrayDestroy(mlir::Value arrayBegin, Address arrayEndPointer,
1009 QualType elementType, CharUnits elementAlign,
1011 : arrayBegin(arrayBegin), arrayEndPointer(arrayEndPointer),
1012 elementType(elementType), elementAlign(elementAlign),
1013 destroyer(destroyer) {}
1015 void emit(CIRGenFunction &cgf, Flags flags)
override {
1017 mlir::Location loc = arrayBegin.getLoc();
1019 mlir::Value arrayEnd = builder.
createLoad(loc, arrayEndPointer);
1025 cir::PointerType ptrToElmType = builder.
getPointerTo(cirElementType);
1027 mlir::Value ne = cir::CmpOp::create(builder, loc, cir::CmpOpKind::ne,
1028 arrayEnd, arrayBegin);
1030 builder, loc, ne,
false,
1031 [&](mlir::OpBuilder &
b, mlir::Location loc) {
1038 [&](mlir::OpBuilder &
b, mlir::Location loc) {
1039 mlir::Value cur = builder.
createLoad(loc, iterAddr);
1040 mlir::Value cmp = cir::CmpOp::create(
1041 builder, loc, cir::CmpOpKind::ne, cur, arrayBegin);
1045 [&](mlir::OpBuilder &
b, mlir::Location loc) {
1046 mlir::Value cur = builder.
createLoad(loc, iterAddr);
1048 loc, mlir::cast<cir::IntType>(cgf.
ptrDiffTy), -1);
1049 mlir::Value prev = cir::PtrStrideOp::create(
1050 builder, loc, ptrToElmType, cur, negOne);
1053 destroyer(cgf, elemAddr, elementType);
1073 ehStack.pushCleanup<IrregularPartialArrayDestroy>(
1074 EHCleanup, arrayBegin, arrayEndPointer, elementType, elementAlign,
1093 assert(dtorKind &&
"cannot push destructor for trivial type");
1106 assert(dtorKind &&
"cannot push destructor for trivial type");
1115 bool useEHCleanupForArray) {
1124 bool useEHCleanupForArray) {
1126 cgm.errorNYI(
"conditional lifetime-extended destroy");
1133 useEHCleanupForArray);
1160 mlir::Value numElements,
1169 cir::PointerType ptrToElmType = builder.getPointerTo(cirElementType);
1171 auto regionBuilder = [&](mlir::OpBuilder &
b, mlir::Location loc) {
1172 mlir::BlockArgument arg =
1173 b.getInsertionBlock()->addArgument(ptrToElmType, loc);
1178 destroyer(*
this, curAddr, elementType);
1180 cir::YieldOp::create(
b, loc);
1184 if (
auto constantCount = numElements.getDefiningOp<cir::ConstantOp>()) {
1186 if (
auto constIntAttr = constantCount.getValueAttr<cir::IntAttr>())
1187 size = constIntAttr.getUInt();
1188 auto arrayTy = cir::ArrayType::get(cirElementType, size);
1189 mlir::Value arrayOp = builder.createPtrBitcast(begin, arrayTy);
1190 cir::ArrayDtor::create(builder, *
currSrcLoc, arrayOp, regionBuilder);
1195 mlir::Value elemBegin = builder.createPtrBitcast(begin, cirElementType);
1196 cir::ArrayDtor::create(builder, *
currSrcLoc, elemBegin, numElements,
1211 return destroyer(*
this, addr,
type);
1219 auto constantCount =
length.getDefiningOp<cir::ConstantOp>();
1220 if (constantCount) {
1221 auto constIntAttr = mlir::dyn_cast<cir::IntAttr>(constantCount.getValue());
1222 if (constIntAttr && constIntAttr.getUInt() == 0)
1231 if (constantCount && constantCount.use_empty())
1232 constantCount.erase();
1239 llvm_unreachable(
"no destroyer for trivial dtor");
1245 cgm.errorNYI(
"getDestroyer: other destruction kind");
1248 llvm_unreachable(
"Unknown DestructionKind");
1252 ehStack.pushCleanup<CallStackRestore>(
kind, spMem);
1273 llvm_unreachable(
"no cleanup for trivially-destructible variable");
1279 assert(!
type->isArrayType());
1281 ehStack.pushCleanup<DestroyNRVOVariableCXX>(cleanupKind, addr,
type, dtor,
1291 cgm.errorNYI(var->getSourceRange(),
1292 "emitAutoVarTypeCleanup: other dtor kind");
1301 ehStack.pushCleanup<DestroyObject>(cleanupKind, addr,
type, destroyer);
1305 if (
auto *dd = dyn_cast_if_present<DecompositionDecl>(vd)) {
1306 for (
auto *
b : dd->flat_bindings())
1307 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
mlir::Operation * getDefiningOp() const
Get the operation which defines this address.
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)
Set TLS mode for the given operation based on the given variable declaration.
const clang::LangOptions & getLangOpts() const
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()
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.
bool isa(CodeGen::Address addr)
@ SD_Automatic
Automatic storage duration (most local variables).
@ 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