19#include "mlir/Dialect/Ptr/IR/MemorySpaceInterfaces.h"
20#include "mlir/IR/BuiltinAttributes.h"
21#include "mlir/IR/Value.h"
74 llvm::StringRef fieldName,
75 unsigned fieldIndex) {
80 bool addressedByFieldIndex =
84 if (!addressedByFieldIndex)
100 auto fieldPtr = cir::PointerType::get(fieldType, addrSpace);
101 bool needsBitcast =
false;
105 fieldPtr = cir::PointerType::get(memberType, addrSpace);
112 mlir::Value addr = builder.createGetMember(loc, fieldPtr, base.
getPointer(),
113 fieldName, fieldIndex);
119 addr = builder.createPtrBitcast(addr, fieldType);
131 assert(
expr->getType()->isPointerType() ||
132 expr->getType()->isObjCObjectPointerType());
136 if (
auto const *ce = dyn_cast<CastExpr>(
expr)) {
137 if (
const auto *ece = dyn_cast<ExplicitCastExpr>(ce))
138 cgm.emitExplicitCastExprType(ece);
140 switch (ce->getCastKind()) {
144 case CK_AddressSpaceConversion: {
145 if (
const auto *ptrTy =
146 ce->getSubExpr()->getType()->getAs<
PointerType>()) {
147 if (ptrTy->getPointeeType()->isVoidType())
155 *baseInfo = innerBaseInfo;
175 const mlir::Type eltTy =
179 if (ce->getCastKind() == CK_AddressSpaceConversion)
189 case CK_ArrayToPointerDecay:
192 case CK_UncheckedDerivedToBase:
193 case CK_DerivedToBase: {
198 ce->getSubExpr()->getType()->getPointeeCXXRecordDecl();
204 case CK_AnyPointerToBlockPointerCast:
205 case CK_BaseToDerived:
206 case CK_BaseToDerivedMemberPointer:
207 case CK_BlockPointerToObjCPointerCast:
208 case CK_BuiltinFnToFnPtr:
209 case CK_CPointerToObjCPointerCast:
210 case CK_DerivedToBaseMemberPointer:
212 case CK_FunctionToPointerDecay:
213 case CK_IntegralToPointer:
214 case CK_LValueToRValue:
215 case CK_LValueToRValueBitCast:
216 case CK_NullToMemberPointer:
217 case CK_NullToPointer:
218 case CK_ReinterpretMemberPointer:
219 case CK_UserDefinedConversion:
225 case CK_ARCConsumeObject:
226 case CK_ARCExtendBlockObject:
227 case CK_ARCProduceObject:
228 case CK_ARCReclaimReturnedObject:
229 case CK_AtomicToNonAtomic:
230 case CK_BooleanToSignedIntegral:
231 case CK_ConstructorConversion:
232 case CK_CopyAndAutoreleaseBlockObject:
234 case CK_FixedPointCast:
235 case CK_FixedPointToBoolean:
236 case CK_FixedPointToFloating:
237 case CK_FixedPointToIntegral:
238 case CK_FloatingCast:
239 case CK_FloatingComplexCast:
240 case CK_FloatingComplexToBoolean:
241 case CK_FloatingComplexToIntegralComplex:
242 case CK_FloatingComplexToReal:
243 case CK_FloatingRealToComplex:
244 case CK_FloatingToBoolean:
245 case CK_FloatingToFixedPoint:
246 case CK_FloatingToIntegral:
247 case CK_HLSLAggregateSplatCast:
248 case CK_HLSLArrayRValue:
249 case CK_HLSLElementwiseCast:
250 case CK_HLSLVectorTruncation:
251 case CK_HLSLMatrixTruncation:
252 case CK_IntToOCLSampler:
253 case CK_IntegralCast:
254 case CK_IntegralComplexCast:
255 case CK_IntegralComplexToBoolean:
256 case CK_IntegralComplexToFloatingComplex:
257 case CK_IntegralComplexToReal:
258 case CK_IntegralRealToComplex:
259 case CK_IntegralToBoolean:
260 case CK_IntegralToFixedPoint:
261 case CK_IntegralToFloating:
262 case CK_LValueBitCast:
264 case CK_MemberPointerToBoolean:
265 case CK_NonAtomicToAtomic:
266 case CK_ObjCObjectLValueCast:
267 case CK_PointerToBoolean:
268 case CK_PointerToIntegral:
272 case CK_ZeroToOCLOpaqueType:
277 cgm.errorNYI(ce->getSourceRange(),
278 "unexpected cast for emitPointerWithAlignment: ",
279 ce->getCastKindName());
287 if (uo->getOpcode() == UO_AddrOf) {
297 if (
auto const *call = dyn_cast<CallExpr>(
expr)) {
298 switch (call->getBuiltinCallee()) {
301 case Builtin::BIaddressof:
302 case Builtin::BI__addressof:
303 case Builtin::BI__builtin_addressof: {
321 auto getScalarSizeInBits = [&](mlir::Type ty) ->
unsigned {
322 mlir::Type scalarTy = mlir::isa<cir::VectorType>(ty)
323 ? mlir::cast<cir::VectorType>(ty).getElementType()
329 mlir::Value srcVal = src.
getValue();
332 getScalarSizeInBits(srcVal.getType())) {
335 "emitStoreThroughExtVectorComponentLValue: dstTySize > srcTysize");
341 "emitStoreThroughExtVectorComponentLValue: HLSL");
351 mlir::Value vec = builder.createLoad(loc, dstAddr, dst.
isVolatile());
353 unsigned numSrcElts = vecTy->getNumElements();
355 if (numDstElts == numSrcElts) {
360 for (
unsigned i = 0; i != numDstElts; ++i)
363 vec = builder.createVecShuffle(loc, srcVal, mask);
364 }
else if (numDstElts > numSrcElts) {
370 std::iota(extMask.begin(), extMask.begin() + numSrcElts, 0);
372 mlir::Value extSrcVal = builder.createVecShuffle(loc, srcVal, extMask);
376 std::iota(mask.begin(), mask.begin() + numDstElts, 0);
385 for (
unsigned i = 0; i != numSrcElts; ++i)
388 vec = builder.createVecShuffle(loc, vec, extSrcVal, mask);
391 llvm_unreachable(
"unexpected shorten vector length");
397 cir::ConstantOp elt = builder.getSInt64(inIdx, loc);
398 vec = cir::VecInsertOp::create(builder, loc, vec, srcVal, elt);
411 const mlir::Value vector =
413 const mlir::Value newVector = cir::VecInsertOp::create(
424 const mlir::Location loc = dst.
getPointer().getLoc();
429 const mlir::Value matrix =
431 const mlir::Value newMatrix = builder.createMatrixInsert(
440 cgm.errorNYI(
"emitStoreThroughLValue: !dst.isSimple() && isMatrixRow");
444 assert(dst.
isBitField() &&
"Unknown LValue type");
452 assert(src.
isScalar() &&
"Can't emit an aggregate store with this method");
459 std::optional<OMPDeclareTargetDeclAttr::MapTypeTy> res =
460 OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(vd);
464 if (*res == OMPDeclareTargetDeclAttr::MT_Local)
467 if ((*res == OMPDeclareTargetDeclAttr::MT_To ||
468 *res == OMPDeclareTargetDeclAttr::MT_Enter) &&
472 "emitDeclTargetVarDeclLValue: indirect access");
495 cir::PointerType realPtrTy = cir::PointerType::get(
496 realVarTy, mlir::cast<cir::PointerType>(v.getType()).getAddrSpace());
497 if (realPtrTy != v.getType())
501 Address addr(v, realVarTy, alignment);
515 bool isNontemporal) {
521 if (clangVecTy->getNumElements() == 3 && !
getLangOpts().PreserveVec3Type)
523 "emitStoreOfScalar Vec3 & PreserveVec3Type disabled");
537 assert(addr.
getPointer() &&
"expected pointer to exist");
539 if (currVarDecl && srcAlloca) {
540 const VarDecl *vd = currVarDecl;
541 assert(vd &&
"VarDecl expected");
546 assert(
currSrcLoc &&
"must pass in source location");
564 assert(
currSrcLoc &&
"must pass in source location");
590 mlir::Type fieldType,
593 cir::PointerType fieldPtr =
600 rec.getElementOffset(
cgm.getDataLayout().layout,
index));
608 cgm.getTypes().getCIRGenRecordLayout(field->
getParent());
618 addr = builder.createElementBitCast(loc, addr, info.storageType);
641 if (
auto *classDecl = dyn_cast<CXXRecordDecl>(rec)) {
642 if (
cgm.getCodeGenOpts().StrictVTablePointers &&
643 classDecl->isDynamicClass()) {
645 "emitLValueForField: strict vtable for dynamic class");
651 llvm::StringRef fieldName = field->
getName();
653 if (
cgm.lambdaFieldToName.count(field))
654 fieldName =
cgm.lambdaFieldToName[field];
661 cgm.getTypes().getCIRGenRecordLayout(field->
getParent());
691 if (field->
hasAttr<AnnotateAttr>())
700 "emitLValueForField: __weak attribute");
716 cgm.getTypes().getCIRGenRecordLayout(field->
getParent());
742 ty = atomicTy->getValueType();
745 cgm.errorNYI(
"emitToMemory: ConstantMatrixBoolType");
756 ty = atomicTy->getValueType();
759 cgm.errorNYI(
"emitFromMemory: PackedVectorBoolType");
775 bool isNontemporal) {
782 if (clangVecTy->getNumElements() == 3 && !
getLangOpts().PreserveVec3Type)
784 "emitLoadOfScalar Vec3 & PreserveVec3Type disabled");
792 if (mlir::isa<cir::VoidType>(eltTy))
793 cgm.errorNYI(loc,
"emitLoadOfScalar: void type");
798 builder.createLoad(
getLoc(loc), addr, isVolatile, isNontemporal);
821 loc,
"emitLoadOfMatrixLValue: HLSL & hlsl_constant address space");
845 const mlir::Value load =
857 const mlir::Location mlirLoc =
getLoc(loc);
858 const mlir::Value matrix =
864 cgm.errorNYI(loc,
"emitLoadOfLValue");
869 const mlir::ArrayAttr elts) {
870 auto elt = mlir::cast<mlir::IntegerAttr>(elts[idx]);
884 !mlir::isa<cir::VectorType, cir::MatrixType>(vec.getType())) {
885 auto dstTy = cir::VectorType::get(
886 vec.getType(), llvm::ElementCount::get(1,
false));
887 cir::ConstantOp poison =
888 builder.getConstant(loc, cir::PoisonAttr::get(dstTy));
889 vec = builder.createInsertElement(loc, poison, vec, 0);
892 assert((mlir::isa<cir::VectorType, cir::MatrixType>(vec.getType())) &&
893 "ExtVecElement with non vector or matrix type on non-HLSL mode");
902 cir::ConstantOp
index =
903 builder.getConstInt(loc, builder.getSInt64Ty(), indexValue);
904 if (mlir::isa<cir::VectorType>(vec.getType()))
907 cir::ConstantOp columnIdx =
908 builder.getConstInt(loc, builder.getSInt64Ty(), 0);
909 mlir::Value element =
910 cir::MatrixExtractOp::create(builder, loc, vec,
index, columnIdx);
916 for (
auto i : llvm::seq<unsigned>(0, exprVecTy->getNumElements()))
919 cir::VecShuffleOp resultVec = builder.createVecShuffle(loc, vec, mask);
921 cgm.errorNYI(loc,
"emitLoadOfExtVectorElementLValue: ExtVectorBoolType");
931 "unexpected binary operator opcode");
946 memberPtrTy, &baseInfo);
948 return makeAddrLValue(memberAddr, memberPtrTy->getPointeeType(), baseInfo);
953 mlir::Location loc) {
956 mlir::Type vectorElementTy =
cgm.getTypes().convertType(elementTy);
962 mlir::Value idxValue =
963 builder.getConstInt(loc, mlir::cast<cir::IntType>(
ptrDiffTy), idx);
965 mlir::Value elementValue = builder.getArrayElement(
966 loc, loc, castToPointerElement.
getPointer(), vectorElementTy, idxValue,
972 return Address(elementValue, vectorElementTy, alignment);
977 if (fd->hasAttr<WeakRefAttr>())
983 mlir::Value thisValue) {
991 mlir::Value thisValue) {
992 bool hasExplicitObjectParameter =
false;
993 const auto *md = dyn_cast_if_present<CXXMethodDecl>(
curCodeDecl);
996 hasExplicitObjectParameter = md->isExplicitObjectMemberFunction();
997 assert(md->getParent()->isLambda());
998 assert(md->getParent() == field->
getParent());
1001 if (hasExplicitObjectParameter) {
1004 assert(it !=
localDeclMap.end() &&
"explicit parameter not loaded?");
1005 Address addrOfExplicitObject = it->second;
1017 if (thisTy != lambdaTy) {
1021 llvm::make_range(basePathArray.begin(), basePathArray.end()),
1047 mlir::Type fnTy = funcOp.getFunctionType();
1048 mlir::ptr::MemorySpaceAttrInterface fnAddrSpace =
1050 mlir::Type ptrTy = cir::PointerType::get(fnTy, fnAddrSpace);
1058 fd->
hasAttr<CUDAGlobalAttr>()) {
1059 auto handle = mlir::cast<cir::GlobalOp>(
1061 cir::PointerType handlePtrTy = cir::PointerType::get(handle.getSymType());
1062 mlir::Value handleAddr = cir::GetGlobalOp::create(
1063 cgf.
getBuilder(), loc, handlePtrTy, handle.getSymName());
1064 addr = cir::CastOp::create(cgf.
getBuilder(), loc, ptrTy,
1065 cir::CastKind::bitcast, handleAddr);
1069 addr = cir::GetGlobalOp::create(cgf.
getBuilder(), loc, ptrTy,
1070 funcOp.getSymName());
1074 ptrTy = cir::PointerType::get(fnTy, fnAddrSpace);
1076 addr = cir::CastOp::create(cgf.
getBuilder(), addr.getLoc(), ptrTy,
1077 cir::CastKind::bitcast, addr);
1124 case cir::GlobalLinkageKind::ExternalLinkage:
1125 case cir::GlobalLinkageKind::LinkOnceODRLinkage:
1126 case cir::GlobalLinkageKind::WeakODRLinkage:
1127 case cir::GlobalLinkageKind::InternalLinkage:
1128 case cir::GlobalLinkageKind::PrivateLinkage:
1140 "should not emit an unevaluated operand");
1142 if (
const auto *vd = dyn_cast<VarDecl>(nd)) {
1144 if (vd->getStorageClass() ==
SC_Register && vd->hasAttr<AsmLabelAttr>() &&
1145 !vd->isLocalVarDecl()) {
1147 "emitDeclRefLValue: Global Named registers access");
1152 (vd->getType()->isReferenceType() ||
1154 vd->getAnyInitializer(vd);
1156 e->
getLocation(), *vd->evaluateValue(), vd->getType());
1157 assert(val &&
"failed to emit constant expression");
1160 if (!vd->getType()->isReferenceType()) {
1162 addr =
cgm.createUnnamedGlobalFrom(*vd, val,
1165 auto ptrTy = mlir::cast<cir::PointerType>(addr.
getPointer().getType());
1166 if (ptrTy.getPointee() != varTy) {
1185 vd = vd->getCanonicalDecl();
1198 "Should not use decl without marking it used!");
1202 if (
const auto *vd = dyn_cast<VarDecl>(nd);
1203 vd && vd->hasAttr<WeakRefAttr>()) {
1205 mlir::cast_or_null<cir::GlobalOp>(
cgm.getWeakRefReference(vd));
1215 if (
const auto *vd = dyn_cast<VarDecl>(nd)) {
1225 if (vd->hasLinkage() || vd->isStaticDataMember())
1233 addr = iter->second;
1235 }
else if (vd->isStaticLocal()) {
1239 cgm.getOrCreateStaticVarDecl(*vd,
cgm.getCIRLinkageVarDefinition(vd));
1240 mlir::Value getGlobVal = builder.createGetGlobal(var);
1241 auto getGlob = getGlobVal.getDefiningOp<cir::GetGlobalOp>();
1242 getGlob.setStaticLocal(var.getDynamicInitGuard().has_value());
1244 addr =
Address(
cgm.castGlobalToDeclAddrSpace(getGlob, *vd),
1248 llvm_unreachable(
"DeclRefExpr for Decl not entered in localDeclMap?");
1260 assert((vd->isStaticLocal() ||
symbolTable.count(vd)) &&
1261 "non-static locals should be already mapped");
1266 if (
const auto *bd = dyn_cast<BindingDecl>(nd)) {
1274 if (
const auto *fd = dyn_cast<FunctionDecl>(nd)) {
1278 if (
getContext().getTargetInfo().allowDebugInfoForExternalRef())
1285 "emitDeclRefLValue: unhandled MS Guid Decl");
1287 if (
const auto *tpo = dyn_cast<TemplateParamObjectDecl>(nd)) {
1288 CharUnits alignment =
cgm.getNaturalTypeAlignment(tpo->getType());
1289 cir::GetGlobalOp atpo =
1290 builder.createGetGlobal(
cgm.getAddrOfTemplateParamObject(tpo));
1292 "Do an address space conversion if necessary");
1299 llvm_unreachable(
"Unhandled DeclRefExpr");
1309 "evaluateExprAsBool: member pointer type");
1325 if (op == UO_Extension)
1331 assert(!t.
isNull() &&
"CodeGenFunction::EmitUnaryOpLValue: Illegal type");
1351 assert(lv.
isSimple() &&
"real/imag on non-ordinary l-value");
1366 ? builder.createComplexRealPtr(loc, lv.
getAddress())
1367 : builder.createComplexImagPtr(loc, lv.
getAddress());
1377 assert(e->
isPrefix() &&
"Prefix operator in unexpected state!");
1387 llvm_unreachable(
"UnaryOperator extension should be handled above!");
1396 llvm_unreachable(
"UnaryOperator of non-lvalue kind!");
1398 llvm_unreachable(
"Unknown unary operator kind!");
1406 const auto *
castExpr = dyn_cast<CastExpr>(e);
1420 if (
auto constantOp = idx.getDefiningOp<cir::ConstantOp>())
1421 return constantOp.getValueAttr<cir::IntAttr>();
1430 const CharUnits offset = constantIdx.getValue().getZExtValue() * eltSize;
1441 while (mlir::Operation *op = ptr.getDefiningOp()) {
1442 if (mlir::isa<cir::AllocaOp>(op))
1444 if (
auto elementOp = mlir::dyn_cast<cir::GetElementOp>(op))
1445 ptr = elementOp.getBase();
1446 else if (
auto strideOp = mlir::dyn_cast<cir::PtrStrideOp>(op))
1447 ptr = strideOp.getBase();
1448 else if (
auto castOp = mlir::dyn_cast<cir::CastOp>(op);
1449 castOp && (castOp.isAllocaPreservingCast() ||
1450 castOp.getKind() == cir::CastKind::array_to_ptrdecay))
1451 ptr = castOp.getSrc();
1463 bool signedIndices) {
1471 auto arrayTy = mlir::dyn_cast<cir::ArrayType>(
1472 mlir::cast<cir::PointerType>(ptr.getType()).getPointee());
1473 bool isSectionSubscript =
1474 cgf.
getLangOpts().OpenMPIsTargetDevice && arrayTy &&
1475 mlir::isa<cir::ArrayType>(arrayTy.getElementType()) &&
1479 if (!isSectionSubscript)
1487 mlir::Location beginLoc,
1488 mlir::Location endLoc, mlir::Value ptr,
1489 mlir::Type eltTy, mlir::Value idx,
1490 bool signedIndices,
bool shouldDecay) {
1494 beginLoc, endLoc, ptr, eltTy, idx, shouldDecay,
1499 mlir::Location beginLoc,
1500 mlir::Location endLoc,
Address addr,
1502 mlir::Location loc,
bool signedIndices,
1520 signedIndices, shouldDecay);
1522 return Address(eltPtr, elementType, eltAlign);
1537 const bool signedIndices =
1540 auto emitIdxAfterBase = [&, idxPre](
bool promote) -> mlir::Value {
1541 mlir::Value idx = idxPre;
1543 assert(e->
getRHS() == e->
getIdx() &&
"index was neither LHS nor RHS");
1555 if (idx.getType() != desiredIdxTy) {
1556 cir::CastKind
kind = mlir::isa<cir::BoolType>(idx.getType())
1557 ? cir::CastKind::bool_to_int
1558 : cir::CastKind::integral;
1559 idx = builder.createOrFold<cir::CastOp>(idx.getLoc(), desiredIdxTy,
1568 idxPre = mlir::Value();
1575 const mlir::Value idx = emitIdxAfterBase(
false);
1590 const mlir::Value idx = emitIdxAfterBase(
true);
1597 signedIndices,
false);
1608 mlir::Value idx = emitIdxAfterBase(
true);
1612 idx = builder.createIntCast(idx, numElements.getType());
1618 cir::OverflowFlags overflowFlags =
getLangOpts().PointerOverflowDefined
1619 ? cir::OverflowFlags::None
1620 : cir::OverflowFlags::NoSignedWrap;
1621 idx = builder.createMul(
cgm.getLoc(e->
getExprLoc()), idx, numElements,
1627 signedIndices,
false);
1634 if (
const auto *ase = dyn_cast<ArraySubscriptExpr>(array))
1638 mlir::Value idx = emitIdxAfterBase(
true);
1642 *
this,
cgm.getLoc(array->getBeginLoc()),
cgm.getLoc(array->getEndLoc()),
1644 signedIndices,
true);
1657 "The base must be a pointer");
1661 const mlir::Value idx = emitIdxAfterBase(
true);
1679 "incomplete matrix subscript expressions should be rejected in Sema");
1686 "emitMatrixSubscriptExpr: row-major matrix");
1702 const auto *clangPtrTy =
1704 base =
makeAddrLValue(ptr, clangPtrTy->getPointeeType(), baseInfo);
1705 base.getQuals().removeObjCGCAttr();
1714 "Result must be a vector");
1722 "emitExtVectorElementExpr: ExtVectorBoolType & !HLSL");
1725 builder.createStore(vec.getLoc(), vec, vecMem);
1738 mlir::ArrayAttr elts = builder.getI64ArrayAttr(attrElts);
1748 assert(base.
isExtVectorElt() &&
"Can only subscript lvalue vec elts here!");
1751 for (
unsigned idx : indices)
1753 mlir::ArrayAttr cv = builder.getI64ArrayAttr(elts);
1780 const auto *matrixTy =
1783 for (uint32_t &idx : indices) {
1785 unsigned row = idx / numCols;
1786 unsigned column = idx % numCols;
1788 idx = matrixTy->getColumnMajorFlattenedIndex(row, column);
1798 "emitMatrixElementExpr simple & HLSL address space hlsl_constant");
1803 mlir::ArrayAttr elts = builder.getI64ArrayAttr(attrElts);
1813 llvm::StringRef name) {
1814 cir::GlobalOp globalOp =
cgm.getGlobalForStringLiteral(e, name);
1815 assert(globalOp.getAlignment() &&
"expected alignment for string literal");
1816 unsigned align = *(globalOp.getAlignment());
1819 mlir::ptr::MemorySpaceAttrInterface destAS =
1820 cgm.getTypes().getPointerAddressSpace(e->
getType());
1821 if (mlir::cast<cir::PointerType>(addr.getType()).getAddrSpace() != destAS)
1823 addr, builder.getPointerTo(globalOp.getSymType(), destAS));
1839 case CK_LValueToRValueBitCast:
1840 case CK_ArrayToPointerDecay:
1841 case CK_FunctionToPointerDecay:
1842 case CK_NullToMemberPointer:
1843 case CK_NullToPointer:
1844 case CK_IntegralToPointer:
1845 case CK_PointerToIntegral:
1846 case CK_PointerToBoolean:
1847 case CK_IntegralCast:
1848 case CK_BooleanToSignedIntegral:
1849 case CK_IntegralToBoolean:
1850 case CK_IntegralToFloating:
1851 case CK_FloatingToIntegral:
1852 case CK_FloatingToBoolean:
1853 case CK_FloatingCast:
1854 case CK_FloatingRealToComplex:
1855 case CK_FloatingComplexToReal:
1856 case CK_FloatingComplexToBoolean:
1857 case CK_FloatingComplexCast:
1858 case CK_FloatingComplexToIntegralComplex:
1859 case CK_IntegralRealToComplex:
1860 case CK_IntegralComplexToReal:
1861 case CK_IntegralComplexToBoolean:
1862 case CK_IntegralComplexCast:
1863 case CK_IntegralComplexToFloatingComplex:
1864 case CK_DerivedToBaseMemberPointer:
1865 case CK_BaseToDerivedMemberPointer:
1866 case CK_MemberPointerToBoolean:
1867 case CK_ReinterpretMemberPointer:
1868 case CK_AnyPointerToBlockPointerCast:
1869 case CK_ARCProduceObject:
1870 case CK_ARCConsumeObject:
1871 case CK_ARCReclaimReturnedObject:
1872 case CK_ARCExtendBlockObject:
1873 case CK_CopyAndAutoreleaseBlockObject:
1874 case CK_IntToOCLSampler:
1875 case CK_FloatingToFixedPoint:
1876 case CK_FixedPointToFloating:
1877 case CK_FixedPointCast:
1878 case CK_FixedPointToBoolean:
1879 case CK_FixedPointToIntegral:
1880 case CK_IntegralToFixedPoint:
1882 case CK_HLSLVectorTruncation:
1883 case CK_HLSLMatrixTruncation:
1884 case CK_HLSLArrayRValue:
1885 case CK_HLSLElementwiseCast:
1886 case CK_HLSLAggregateSplatCast:
1887 llvm_unreachable(
"unexpected cast lvalue");
1890 llvm_unreachable(
"dependent cast kind in IR gen!");
1892 case CK_BuiltinFnToFnPtr:
1893 llvm_unreachable(
"builtin functions are handled elsewhere");
1906 case CK_ConstructorConversion:
1907 case CK_UserDefinedConversion:
1908 case CK_CPointerToObjCPointerCast:
1909 case CK_BlockPointerToObjCPointerCast:
1910 case CK_LValueToRValue:
1913 case CK_NonAtomicToAtomic:
1914 case CK_AtomicToNonAtomic:
1915 case CK_ObjCObjectLValueCast:
1916 case CK_VectorSplat: {
1920 case CK_AddressSpaceConversion: {
1931 case CK_LValueBitCast: {
1935 cgm.emitExplicitCastExprType(ce,
this);
1959 auto toTy = dyn_cast<cir::ArrayType>(ty);
1960 if (!fromTy || !toTy ||
1961 fromTy.getElementType() != toTy.getElementType() ||
1962 toTy.getSize() != 0)
1964 "emitCastLValue NoOp not array-shrink case");
1974 case CK_UncheckedDerivedToBase:
1975 case CK_DerivedToBase: {
1993 case CK_BaseToDerived: {
2009 case CK_ZeroToOCLOpaqueType:
2010 llvm_unreachable(
"NULL to OpenCL opaque type lvalue cast is not valid");
2013 llvm_unreachable(
"Invalid cast kind");
2050 if (
auto *field = dyn_cast<FieldDecl>(nd)) {
2064 if (
const auto *fd = dyn_cast<FunctionDecl>(nd))
2067 llvm_unreachable(
"Unhandled member declaration!");
2097 llvm_unreachable(
"bad evaluation kind");
2102 const Expr *inner) {
2113 cir::AllocaOp extDeclAlloca;
2117 extDeclAlloca = extDeclAddrIter->second.getUnderlyingAllocaOp();
2119 mlir::OpBuilder::InsertPoint ip;
2120 if (extDeclAlloca) {
2121 ip = {extDeclAlloca->getBlock(), extDeclAlloca->getIterator()};
2139 assert(addr.getAlignment().has_value() &&
2140 "This should always have an alignment");
2146 llvm_unreachable(
"temporary can't have dynamic storage duration");
2148 llvm_unreachable(
"unknown storage duration");
2172 if (
const auto *classDecl =
2176 referenceTemporaryDtor = classDecl->getDestructor();
2178 if (!referenceTemporaryDtor)
2187 auto registerOp = cir::RegisterExitDtorOp::create(
2188 builder, loc, globalOp.getSymNameAttr().getValue());
2189 mlir::OpBuilder::InsertionGuard guard(builder);
2190 builder.setInsertionPointToStart(
2191 builder.createBlock(®isterOp.getBody()));
2202 builder.
createCallOp(loc, dtorFn, mlir::ValueRange{tempAddr},
2204 dtorFn.getCallingConv());
2206 cir::YieldOp::create(builder, loc);
2223 llvm_unreachable(
"temporary cannot have dynamic storage duration");
2233 "Reference should never be pseudo-strong!");
2241 "emitMaterializeTemporaryExpr: ObjCLifetime");
2249 for (
const Expr *ignored : commaLHSs)
2254 "emitMaterializeTemporaryExpr: OpaqueValueExpr");
2260 cir::GlobalOp var =
nullptr;
2261 if (
auto getGlobalOp =
object.getPointer().getDefiningOp<cir::GetGlobalOp>())
2262 var = mlir::dyn_cast_or_null<cir::GlobalOp>(
2263 cgm.getGlobalValue(getGlobalOp.getName()));
2266 if (!var.getInitialValue().has_value()) {
2267 var.setInitialValueAttr(builder.getZeroInitAttr(var.getSymType()));
2281 switch (adjustment.Kind) {
2285 adjustment.DerivedToBase.BasePath->path(),
2292 "materialized temporary field is not a simple lvalue");
2299 e,
object, ptr, adjustment.Ptr.MPT,
nullptr);
2316 assert(e->
isUnique() &&
"LValue for a nonunique OVE hasn't been emitted");
2328 assert(e->
isUnique() &&
"RValue for a nonunique OVE hasn't been emitted");
2342 ".compoundliteral");
2353 "emitCompoundLiteralLValue: non C++ DestructedType");
2368 "Can't have a scalar return unless the return type is a "
2386 "binding l-value to type which needs a temporary");
2402 assert(e->
getOpcode() == BO_Assign &&
"unexpected binary l-value");
2438 llvm_unreachable(
"bad evaluation kind");
2444 bool ignoreResult) {
2451 if (!ignoreResult && aggSlot.
isIgnored())
2458 llvm_unreachable(
"bad evaluation kind");
2464 auto noBuiltins = fn->getAttrOfType<mlir::ArrayAttr>(
2465 cir::CIRDialect::getNoBuiltinsAttrName());
2468 return noBuiltins.empty() ||
2469 llvm::is_contained(noBuiltins,
2470 mlir::StringAttr::get(fn.getContext(), name));
2473CIRGenCallee CIRGenFunction::emitDirectCallee(
const GlobalDecl &gd) {
2476 if (
unsigned builtinID = fd->getBuiltinID()) {
2477 StringRef ident =
cgm.getMangledName(gd);
2478 std::string fdInlineName = (ident +
".inline").str();
2480 bool isPredefinedLibFunction =
2481 cgm.getASTContext().BuiltinInfo.isPredefinedLibFunction(builtinID);
2482 auto fn = dyn_cast<cir::FuncOp>(
curFn);
2487 if ((!fn || fn.getName() != fdInlineName) &&
2490 mlir::cast_or_null<cir::FuncOp>(
cgm.getGlobalValue(fdInlineName));
2495 cir::FuncOp calleeFunc =
cgm.getRawFunctionPointer(gd);
2496 mlir::OpBuilder::InsertionGuard guard(builder);
2497 builder.setInsertionPointToStart(
cgm.getModule().getBody());
2499 clone = cir::FuncOp::create(builder, calleeFunc.getLoc(), fdInlineName,
2500 calleeFunc.getFunctionType());
2501 cgm.insertGlobalSymbol(clone);
2502 clone.setLinkageAttr(cir::GlobalLinkageKindAttr::get(
2503 &
cgm.getMLIRContext(), cir::GlobalLinkageKind::InternalLinkage));
2504 clone.setSymVisibility(
"private");
2505 clone.setInlineKind(cir::InlineKind::AlwaysInline);
2516 else if (!isPredefinedLibFunction || !hasAttributeNoBuiltin)
2520 cir::FuncOp callee =
cgm.getRawFunctionPointer(gd);
2522 return CIRGenCallee();
2524 if ((
cgm.getLangOpts().CUDA ||
cgm.getLangOpts().HIP) &&
2525 !
cgm.getLangOpts().CUDAIsDevice && fd->hasAttr<CUDAGlobalAttr>()) {
2526 mlir::Operation *handle =
cgm.getCUDARuntime().getKernelHandle(callee, gd);
2528 mlir::cast<cir::FuncOp>(*
cgm.getCUDARuntime().getKernelStub(handle));
2536 return builder.getConstant(loc, cir::UndefAttr::get(cirTy));
2543 mlir::Location loc = builder.getUnknownLoc();
2550 mlir::Value v = builder.createComplexCreate(loc, undefElem, undefElem);
2565 llvm_unreachable(
"bad evaluation kind");
2575 "Callee must have function pointer type!");
2598 if (
const auto *oce = dyn_cast<CXXOperatorCallExpr>(e)) {
2599 if (
const auto *md =
2600 dyn_cast_if_present<CXXMethodDecl>(oce->getCalleeDecl());
2601 md && md->isStatic()) {
2603 arguments = llvm::drop_begin(arguments, 1);
2607 emitCallArgs(args, dyn_cast<FunctionProtoType>(fnType), arguments,
2611 cgm.getTypes().arrangeFreeFunctionCall(args, fnType);
2633 calleeTy = cir::FuncType::get(calleeTy.getInputs(),
2634 calleeTy.getReturnType(),
false);
2635 auto calleePtrTy = cir::PointerType::get(calleeTy);
2639 if (
auto funcOp = mlir::dyn_cast<cir::FuncOp>(fn)) {
2640 addr = cir::GetGlobalOp::create(
2642 cir::PointerType::get(funcOp.getFunctionType()), funcOp.getSymName());
2644 addr = fn->getResult(0);
2647 fn = builder.createBitcast(addr, calleePtrTy).getDefiningOp();
2663 auto handlePtrTy = mlir::cast<cir::PointerType>(handleAddr.getType());
2664 mlir::Value handleAddrAddr =
2665 builder.createBitcast(handleAddr, cir::PointerType::get(handlePtrTy));
2666 cir::LoadOp stub = builder.createLoad(
2671 cir::CIRCallOpInterface callOp;
2684 if (
const auto *implicitCast = dyn_cast<ImplicitCastExpr>(e)) {
2685 if (implicitCast->getCastKind() == CK_FunctionToPointerDecay ||
2686 implicitCast->getCastKind() == CK_BuiltinFnToFnPtr) {
2687 return emitCallee(implicitCast->getSubExpr());
2695 }
else if (
const auto *declRef = dyn_cast<DeclRefExpr>(e)) {
2697 if (
const auto *funcDecl = dyn_cast<FunctionDecl>(declRef->getDecl()))
2698 return emitDirectCallee(funcDecl);
2699 }
else if (
auto me = dyn_cast<MemberExpr>(e)) {
2700 if (
const auto *fd = dyn_cast<FunctionDecl>(me->getMemberDecl())) {
2702 return emitDirectCallee(fd);
2705 }
else if (
auto *pde = dyn_cast<CXXPseudoDestructorExpr>(e)) {
2710 mlir::Value calleePtr;
2722 if (
const auto *vd =
2727 CIRGenCallee callee(calleeInfo, calleePtr.getDefiningOp());
2738 std::string(
"emitCallExpr: block pointer type"));
2742 if (
const auto *ce = dyn_cast<CXXMemberCallExpr>(e))
2753 if (
const auto *operatorCall = dyn_cast<CXXOperatorCallExpr>(e)) {
2754 if (
const auto *md =
2755 dyn_cast_if_present<CXXMethodDecl>(operatorCall->getCalleeDecl());
2756 md && md->isImplicitObjectMemberFunction())
2791 "Array to pointer decay must have array source type!");
2803 assert(mlir::isa<cir::ArrayType>(arrayTy) &&
"expected array");
2814 mlir::Value ptr = builder.maybeBuildArrayDecay(
2832 llvm_unreachable(
"bad evaluation kind");
2839 const Stmt *elseS) {
2841 std::optional<mlir::Location> elseLoc;
2845 mlir::LogicalResult resThen = mlir::success(), resElse = mlir::success();
2848 [&](mlir::OpBuilder &, mlir::Location) {
2849 LexicalScope lexScope{*
this, thenLoc, builder.getInsertionBlock()};
2854 [&](mlir::OpBuilder &, mlir::Location) {
2855 assert(elseLoc &&
"Invalid location for elseS.");
2856 LexicalScope lexScope{*
this, *elseLoc, builder.getInsertionBlock()};
2861 return mlir::LogicalResult::success(resThen.succeeded() &&
2862 resElse.succeeded());
2870 std::optional<mlir::Location> elseLoc) {
2876 ifLocs.push_back(*elseLoc);
2877 mlir::Location loc = mlir::FusedLoc::get(&
getMLIRContext(), ifLocs);
2888 std::optional<mlir::Location> elseLoc) {
2889 cir::IfOp ifOp = cir::IfOp::create(builder, loc, condV, elseLoc.has_value(),
2893 assert((elseLoc.has_value() || ifOp.getElseRegion().empty()) &&
2894 "else region created with no else location");
2895 if (elseLoc.has_value())
2914 Expr *trueExpr = condOp->getTrueExpr();
2915 Expr *falseExpr = condOp->getFalseExpr();
2918 mlir::Value ternaryOpRes =
2919 cir::TernaryOp::create(
2920 builder, loc, condV,
2921 [
this, trueExpr](mlir::OpBuilder &b, mlir::Location loc) {
2923 cir::YieldOp::create(b, loc, lhs);
2926 [
this, falseExpr](mlir::OpBuilder &b, mlir::Location loc) {
2928 cir::YieldOp::create(b, loc, rhs);
2937 cgm.errorNYI(
"NYI");
2951 mlir::Location loc,
CharUnits alignment,
2952 bool insertIntoFnEntryBlock,
2953 mlir::Value arraySize) {
2954 mlir::Block *entryBlock = insertIntoFnEntryBlock
2963 llvm::dyn_cast_if_present<cir::TryOp>(entryBlock->getParentOp())) {
2964 if (auto scopeOp = llvm::dyn_cast<cir::ScopeOp>(tryOp->getParentOp()))
2965 entryBlock = &scopeOp.getScopeRegion().front();
2973 mlir::Location loc,
CharUnits alignment,
2974 mlir::OpBuilder::InsertPoint ip,
2975 mlir::Value arraySize) {
2979 cir::PointerType localVarPtrTy =
2981 mlir::IntegerAttr alignIntAttr =
cgm.
getSize(alignment);
2985 mlir::OpBuilder::InsertionGuard guard(builder);
2986 builder.restoreInsertionPoint(ip);
2988 alignIntAttr, arraySize);
3008 assert(!md->isStatic() &&
3009 "static member call is unexpected in emitCXXMemberCallExpr");
3011 bool hasQualifier = me->hasQualifier();
3013 bool isArrow = me->isArrow();
3014 const Expr *base = me->getBase();
3017 ce, md,
returnValue, hasQualifier, qualifier, isArrow, base);
3034 cgm.errorNYI(loc,
"load of volatile reference");
3060 cir::TrapOp::create(builder, loc);
3062 builder.createBlock(builder.getBlock()->getParent());
3066 bool createNewBlock) {
3068 cir::UnreachableOp::create(builder,
getLoc(loc));
3070 builder.createBlock(builder.getBlock()->getParent());
3077 return builder.createDummyValue(loc, t, alignment);
3086 const Twine &name) {
3092 const Twine &name,
Address *alloca,
3093 mlir::OpBuilder::InsertPoint ip) {
3100 mlir::Location loc,
const Twine &name,
3102 mlir::OpBuilder::InsertPoint ip) {
3105 name,
nullptr, alloca, ip);
3112 mlir::Type ty,
CharUnits align, mlir::Location loc,
const Twine &name,
3113 mlir::Value arraySize, mlir::OpBuilder::InsertPoint ip) {
3114 cir::AllocaOp alloca = ip.isSet()
3117 alloca.setAlignmentAttr(
cgm.getSize(align));
3118 return Address(alloca, ty, align);
3122 mlir::Location loc,
const Twine &name,
3123 mlir::Value arraySize,
3125 mlir::OpBuilder::InsertPoint ip) {
3131 Address alloca, mlir::ptr::MemorySpaceAttrInterface destAddrSpace,
3132 mlir::Value arraySize) {
3151 if (srcAddrSpace == destAddrSpace)
3154 mlir::OpBuilder::InsertionGuard guard(builder);
3156 builder.setInsertionPointAfter(allocaOp);
3157 }
else if (!arraySize) {
3159 builder.restoreInsertionPoint(builder.getBestAllocaInsertPoint(entryBlock));
3162 mlir::Type destPtrTy =
3172 mlir::Type ty, mlir::ptr::MemorySpaceAttrInterface destAddrSpace,
3173 CharUnits align, mlir::Location loc,
const Twine &name,
3174 mlir::Value arraySize,
Address *allocaAddr,
3175 mlir::OpBuilder::InsertPoint ip) {
3179 *allocaAddr = alloca;
3189 mlir::Value arraySize,
3190 bool insertIntoFnEntryBlock) {
3192 insertIntoFnEntryBlock, arraySize)
3200 mlir::OpBuilder::InsertPoint ip,
3201 mlir::Value arraySize) {
3202 assert(ip.isSet() &&
"Insertion point is not set");
3203 return mlir::cast<cir::AllocaOp>(
3214 const Twine &name) {
3234 else if (
const auto *var = dyn_cast<VarDecl>(value))
3244 bool resultIsReference;
3250 resultIsReference =
false;
3254 resultIsReference =
true;
3255 resultType = value->
getType();
3273 auto *md = dyn_cast_or_null<CXXMethodDecl>(
curCodeDecl);
3274 if (
isLambdaMethod(md) && md->getOverloadedOperator() == OO_Call) {
3277 if (
const auto *vd = dyn_cast<const VarDecl>(d)) {
3278 if (!vd->hasAttr<CUDADeviceAttr>())
3290 mlir::TypedAttr cstToEmit = mlir::dyn_cast_if_present<mlir::TypedAttr>(c);
3298 if (resultIsReference)
3313 assert(constant &&
"not a constant");
3323 assert(sl !=
nullptr &&
"No StringLiteral name in PredefinedExpr");
3325 StringRef fnName = fn.getName();
3326 fnName.consume_front(
"\01");
3327 std::array<StringRef, 2> nameItems = {
3329 std::string gvName = llvm::join(nameItems,
".");
3344std::optional<LValue> handleConditionalOperatorLValueSimpleCase(
3347 llvm::APSInt condExprVal;
3349 return std::nullopt;
3352 if (!condExprVal.getBoolValue())
3353 std::swap(live, dead);
3356 return std::nullopt;
3363 if (
auto *throwExpr = dyn_cast<CXXThrowExpr>(live->
IgnoreParens())) {
3367 mlir::Type elemTy = cgf.
convertType(dead->getType());
3368 mlir::Value undefPtr =
3370 cgf.
getLoc(throwExpr->getSourceRange()));
3380static std::optional<LValue> emitLValueOrThrowExpression(
CIRGenFunction &cgf,
3381 const Expr *operand) {
3382 if (
auto *throwExpr = dyn_cast<CXXThrowExpr>(operand->
IgnoreParens())) {
3384 return std::nullopt;
3393template <
typename FuncTy>
3396 const FuncTy &branchGenFunc) {
3405 auto emitBranch = [&](mlir::OpBuilder &b, mlir::Location loc,
3406 const Expr *
expr, std::optional<LValue> &resultLV) {
3410 mlir::Value resultPtr;
3417 resultLV = branchGenFunc(*
this,
expr);
3418 resultPtr = resultLV ? resultLV->getPointer() : mlir::Value();
3426 cir::YieldOp::create(b, loc, resultPtr);
3429 cir::TernaryOp ternary = cir::TernaryOp::create(
3430 builder, loc, condV,
3432 [&](mlir::OpBuilder &b, mlir::Location loc) {
3436 [&](mlir::OpBuilder &b, mlir::Location loc) {
3445 info.result = ternary.getResult();
3451 if (!
expr->isGLValue()) {
3454 "Unexpected conditional operator!");
3459 if (std::optional<LValue> res =
3460 handleConditionalOperatorLValueSimpleCase(*
this,
expr))
3465 return emitLValueOrThrowExpression(cgf, e);
3468 if ((info.lhs && !info.lhs->isSimple()) ||
3469 (info.rhs && !info.rhs->isSimple())) {
3470 cgm.errorNYI(
expr->getSourceRange(),
3471 "unsupported conditional operator with non-simple lvalue");
3475 if (info.lhs && info.rhs) {
3476 Address lhsAddr = info.lhs->getAddress();
3477 Address rhsAddr = info.rhs->getAddress();
3481 std::max(info.lhs->getBaseInfo().getAlignmentSource(),
3482 info.rhs->getBaseInfo().getAlignmentSource());
3487 assert((info.lhs || info.rhs) &&
3488 "both operands of glvalue conditional are throw-expressions?");
3492 const LValue &survivingLV = info.lhs ? *info.lhs : *info.rhs;
3504 if (!
cgm.getLangOpts().MSVolatile)
3507 cgm.errorNYI(
"LValueSuitableForInlineAtomic LangOpts MSVolatile");
This file provides some common utility functions for processing Lambda related AST Constructs.
Provides definitions for the various language-specific address spaces.
llvm::function_ref< void(mlir::OpBuilder &, mlir::Location)> BuilderCallbackRef
static cir::PtrOffsetFlags getArraySubscriptFlags(CIRGenFunction &cgf, mlir::Value ptr, bool signedIndices)
Return the no-wrap flags for an array subscript of ptr: none when pointer overflow is defined,...
static std::optional< LValue > emitDeclTargetVarDeclLValue(CIRGenFunction &cgf, const Expr *e, const VarDecl *vd)
static Address createReferenceTemporary(CIRGenFunction &cgf, const MaterializeTemporaryExpr *m, const Expr *inner)
static LValue emitFunctionDeclLValue(CIRGenFunction &cgf, const Expr *e, GlobalDecl gd)
static bool isBasedOnAlloca(mlir::Value ptr)
Return true if ptr is derived from a cir.alloca through cir.get_element, cir.ptr_stride,...
static CharUnits getArrayElementAlign(CharUnits arrayAlign, mlir::Value idx, CharUnits eltSize)
static void pushTemporaryCleanup(CIRGenFunction &cgf, const MaterializeTemporaryExpr *m, const Expr *e, Address referenceTemporary)
static RValue emitLoadOfMatrixLValue(LValue lv, SourceLocation loc, CIRGenFunction &cgf)
static cir::IntAttr getConstantIndexOrNull(mlir::Value idx)
static bool hasNoBuiltinAttr(cir::FuncOp fn, StringRef name)
static const Expr * getSimpleArrayDecayOperand(const Expr *e)
If the specified expr is a simple decay from an array to pointer, return the array subexpression.
static mlir::Value emitArraySubscriptPtr(CIRGenFunction &cgf, mlir::Location beginLoc, mlir::Location endLoc, mlir::Value ptr, mlir::Type eltTy, mlir::Value idx, bool signedIndices, bool shouldDecay)
static bool canEmitSpuriousReferenceToVariable(CIRGenFunction &cgf, const DeclRefExpr *e, const VarDecl *vd)
Determine whether we can emit a reference to vd from the current context, despite not necessarily hav...
static DeclRefExpr * tryToConvertMemberExprToDeclRefExpr(CIRGenFunction &cgf, const MemberExpr *me)
static LValue emitGlobalVarDeclLValue(CIRGenFunction &cgf, const Expr *e, const VarDecl *vd)
static LValue emitCapturedFieldLValue(CIRGenFunction &cgf, const FieldDecl *fd, mlir::Value thisValue)
static Address emitAddrOfZeroSizeField(CIRGenFunction &cgf, Address base, const FieldDecl *field)
Get the address of a zero-sized field within a record.
Defines the clang::Expr interface and subclasses for C++ expressions.
Defines AST-level helper utilities for matrix types.
*collection of selector each with an associated kind and an ordered *collection of selectors A selector has a kind
cir::ConstantOp getConstant(mlir::Location loc, mlir::TypedAttr attr)
cir::PtrStrideOp createPtrStride(mlir::Location loc, mlir::Value base, mlir::Value stride)
static OpBuilder::InsertPoint getBestAllocaInsertPoint(mlir::Block *block)
cir::PointerType getPointerTo(mlir::Type ty)
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={}, cir::CallingConv callingConv=cir::CallingConv::C)
cir::ConstantOp getNullPtr(mlir::Type ty, mlir::Location loc)
mlir::Value createPtrBitcast(mlir::Value src, mlir::Type newPointeeTy)
cir::GetGlobalOp createGetGlobal(mlir::Location loc, cir::GlobalOp global, bool threadLocal=false)
mlir::Value createAlloca(mlir::Location loc, cir::PointerType addrType, llvm::StringRef name, mlir::IntegerAttr alignment, mlir::Value dynAllocSize)
mlir::Value createBitcast(mlir::Value src, mlir::Type newTy)
llvm::TypeSize getTypeSizeInBits(mlir::Type ty) const
llvm::ArrayRef< mlir::Type > getMembers() const
uint64_t getElementOffset(const mlir::DataLayout &dataLayout, unsigned idx) const
const LValueBase getLValueBase() const
CharUnits getTypeAlignInChars(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in characters.
uint64_t getFieldOffset(const ValueDecl *FD) const
Get the offset of a FieldDecl or IndirectFieldDecl, in bits.
static CanQualType getCanonicalType(QualType T)
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
llvm::DenseMap< const CXXMethodDecl *, CXXCastPath > LambdaCastPaths
For capturing lambdas with an explicit object parameter whose type is derived from the lambda type,...
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.
const VariableArrayType * getAsVariableArrayType(QualType T) const
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
CanQualType getCanonicalTagType(const TagDecl *TD) const
AbstractConditionalOperator - An abstract base class for ConditionalOperator and BinaryConditionalOpe...
Expr * getCond() const
getCond - Return the expression representing the condition for the ?
Expr * getTrueExpr() const
getTrueExpr - Return the subexpression representing the value of the expression if the condition eval...
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression representing the value of the expression if the condition eva...
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
SourceLocation getExprLoc() const LLVM_READONLY
Expr * getLHS()
An array access can be written A[4] or 4[A] (both are equivalent).
SourceLocation getBeginLoc() const LLVM_READONLY
SourceLocation getEndLoc() const
QualType getElementType() const
A builtin binary operation expression such as "x + y" or "x <= y".
Address withPointer(mlir::Value newPtr) const
Return address with different pointer, but same element type and alignment.
mlir::ptr::MemorySpaceAttrInterface getAddressSpace() const
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::Type getType() const
cir::AllocaOp getUnderlyingAllocaOp() const
Return the underlying alloca for this address, if any.
mlir::Operation * getDefiningOp() const
Get the operation which defines this address.
IsDestructed_t
This is set to true if the slot might be aliased and it's not undefined behavior to access it through...
static AggValueSlot forAddr(Address addr, clang::Qualifiers quals, IsDestructed_t isDestructed, IsAliased_t isAliased, Overlap_t mayOverlap, IsZeroed_t isZeroed=IsNotZeroed)
Address getAddress() const
void setExternallyDestructed(bool destructed=true)
static AggValueSlot ignored()
Returns an aggregate value slot indicating that the aggregate value is being ignored.
cir::IntType getUInt8Ty()
cir::ConstantOp getUInt64(uint64_t c, mlir::Location loc)
Address createGetMember(mlir::Location loc, Address base, llvm::StringRef name, unsigned index, const cir::CIRDataLayout &layout)
Address createElementBitCast(mlir::Location loc, Address addr, mlir::Type destType)
Cast the element type of the given address to a different type, preserving information like the align...
mlir::Value getArrayElement(mlir::Location arrayLocBegin, mlir::Location arrayLocEnd, mlir::Value arrayPtr, mlir::Type eltTy, mlir::Value idx, bool shouldDecay, cir::PtrOffsetFlags flags=cir::PtrOffsetFlags::None)
Create a cir.get_element or cir.ptr_stride operation to get access to an array element.
virtual mlir::Operation * getKernelHandle(cir::FuncOp fn, GlobalDecl gd)=0
Abstract information about a function or function prototype.
clang::GlobalDecl getCalleeDecl() const
bool isPseudoDestructor() const
void setFunctionPointer(mlir::Operation *functionPtr)
const clang::FunctionDecl * getBuiltinDecl() const
const CXXPseudoDestructorExpr * getPseudoDestructorExpr() const
static CIRGenCallee forDirect(mlir::Operation *funcPtr, const CIRGenCalleeInfo &abstractInfo=CIRGenCalleeInfo())
unsigned getBuiltinID() const
CIRGenCalleeInfo getAbstractInfo() const
static CIRGenCallee forBuiltin(unsigned builtinID, const clang::FunctionDecl *builtinDecl)
mlir::Operation * getFunctionPointer() const
static CIRGenCallee forPseudoDestructor(const clang::CXXPseudoDestructorExpr *expr)
An object to manage conditionally-evaluated expressions.
static ConstantEmission forReference(mlir::TypedAttr c)
static ConstantEmission forValue(mlir::TypedAttr c)
LValue getReferenceLValue(CIRGenFunction &cgf, const Expr *refExpr) const
mlir::TypedAttr getValue() const
static bool shouldBindAsLValue(const Expr *expr)
An RAII object to set (and then clear) a mapping for an OpaqueValueExpr.
static bool shouldBindAsLValue(const Expr *expr)
Enters a new scope for capturing cleanups, all of which will be executed once the scope is exited.
void forceCleanup(ArrayRef< mlir::Value * > valuesToReload={})
Force the emission of cleanups now, instead of waiting until this object is destroyed.
mlir::Value emitComplexToScalarConversion(mlir::Value src, QualType srcTy, QualType dstTy, SourceLocation loc)
Emit a conversion from the specified complex type to the specified destination type,...
mlir::Type convertType(clang::QualType t)
LValue emitCXXBindTemporaryLValue(const CXXBindTemporaryExpr *e)
LValue emitOpaqueValueLValue(const OpaqueValueExpr *e)
static cir::TypeEvaluationKind getEvaluationKind(clang::QualType type)
Return the cir::TypeEvaluationKind of QualType type.
RValue convertTempToRValue(Address addr, clang::QualType type, clang::SourceLocation loc)
Given the address of a temporary variable, produce an r-value of its type.
Address emitCXXMemberDataPointerAddress(const Expr *e, Address base, mlir::Value memberPtr, const MemberPointerType *memberPtrType, LValueBaseInfo *baseInfo)
Address emitFieldAnnotations(const clang::FieldDecl *field, Address addr)
Annotate the address of field; accesses must use the result.
CIRGenTypes & getTypes() const
Address emitPointerWithAlignment(const clang::Expr *expr, LValueBaseInfo *baseInfo=nullptr)
Given an expression with a pointer type, emit the value and compute our best estimate of the alignmen...
void emitVariablyModifiedType(QualType ty)
RValue emitLoadOfLValue(LValue lv, SourceLocation loc)
Given an expression that represents a value lvalue, this method emits the address of the lvalue,...
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,...
void emitTrap(mlir::Location loc, bool createNewBlock)
Emit a trap instruction, which is used to abort the program in an abnormal way, usually for debugging...
mlir::Block * getCurFunctionEntryBlock()
RValue emitCXXMemberCallExpr(const clang::CXXMemberCallExpr *e, ReturnValueSlot returnValue)
RValue emitCXXMemberPointerCallExpr(const CXXMemberCallExpr *ce, ReturnValueSlot returnValue)
bool isInConditionalBranch() const
LValue emitLValueForBitField(LValue base, const FieldDecl *field)
mlir::LogicalResult emitIfOnBoolExpr(const clang::Expr *cond, const clang::Stmt *thenS, const clang::Stmt *elseS)
Emit an if on a boolean condition to the specified blocks.
VlaSizePair getVLASize(const VariableArrayType *type)
Returns an MLIR::Value+QualType pair that corresponds to the size, in non-variably-sized elements,...
cir::IfOp emitIfOnBoolValue(mlir::Value condV, mlir::Location loc, BuilderCallbackRef thenBuilder, mlir::Location thenLoc, BuilderCallbackRef elseBuilder, std::optional< mlir::Location > elseLoc={})
Build the cir.if for an already-emitted condition value.
mlir::Value emitComplexExpr(const Expr *e)
Emit the computation of the specified expression of complex type, returning the result.
LValue makeNaturalAlignPointeeAddrLValue(mlir::Value v, clang::QualType t)
Given a value of type T* that may not be to a complete object, construct an l-vlaue withi the natural...
RValue emitCallExpr(const clang::CallExpr *e, ReturnValueSlot returnValue=ReturnValueSlot())
LValue emitMemberExpr(const MemberExpr *e)
LValue emitConditionalOperatorLValue(const AbstractConditionalOperator *expr)
LValue emitLValue(const clang::Expr *e)
Emit code to compute a designator that specifies the location of the expression.
Address makeNaturalAddressForPointer(mlir::Value ptr, QualType t, CharUnits alignment, bool forPointeeType=false, LValueBaseInfo *baseInfo=nullptr)
Construct an address with the natural alignment of T.
LValue emitLValueForLambdaField(const FieldDecl *field)
mlir::Value evaluateExprAsBool(const clang::Expr *e)
Perform the usual unary conversions on the specified expression and compare the result against zero,...
std::string getCounterRefTmpAsString()
LValue makeNaturalAlignAddrLValue(mlir::Value val, QualType ty)
bool constantFoldsToSimpleInteger(const clang::Expr *cond, llvm::APSInt &resultInt, bool allowLabels=false)
If the specified expression does not fold to a constant, or if it does fold but contains a label,...
mlir::Location getLoc(clang::SourceLocation srcLoc)
Helpers to convert Clang's SourceLocation to a MLIR Location.
mlir::Value emitOpOnBoolExpr(mlir::Location loc, const clang::Expr *cond)
TODO(cir): see EmitBranchOnBoolExpr for extra ideas).
void emitStoreThroughExtVectorComponentLValue(RValue src, LValue dst)
CodeGenUtils::EvaluationOrder EvaluationOrder
void emitCallArgs(CallArgList &args, PrototypeWrapper prototype, llvm::iterator_range< clang::CallExpr::const_arg_iterator > argRange, AbstractCallee callee=AbstractCallee(), unsigned paramsToSkip=0, EvaluationOrder order=EvaluationOrder::Default)
Address getAddressOfBaseClass(Address value, const CXXRecordDecl *derived, llvm::iterator_range< CastExpr::path_const_iterator > path, bool nullCheckValue, SourceLocation loc)
LValue emitLoadOfReferenceLValue(Address refAddr, mlir::Location loc, QualType refTy, AlignmentSource source)
void emitAnyExprToMem(const Expr *e, Address location, Qualifiers quals, bool isInitializer)
Emits the code necessary to evaluate an arbitrary expression into the given memory location.
LValue getOrCreateOpaqueLValueMapping(const OpaqueValueExpr *e)
Given an opaque value expression, return its LValue mapping if it exists, otherwise create one.
mlir::Value performAddrSpaceCast(mlir::Value v, mlir::Type destTy) const
RValue emitReferenceBindingToExpr(const Expr *e)
Emits a reference binding to the passed in expression.
LValue emitArraySubscriptExpr(const clang::ArraySubscriptExpr *e)
RValue emitCUDAKernelCallExpr(const CUDAKernelCallExpr *expr, ReturnValueSlot returnValue)
mlir::Operation * curFn
The current function or global initializer that is generated code for.
Address emitExtVectorElementLValue(LValue lv, mlir::Location loc)
Generates lvalue for partial ext_vector access.
mlir::Value emitScalarConversion(mlir::Value src, clang::QualType srcType, clang::QualType dstType, clang::SourceLocation loc)
Emit a conversion from the specified type to the specified destination type, both of which are CIR sc...
Address getAddressOfDerivedClass(mlir::Location loc, Address baseAddr, const CXXRecordDecl *derived, llvm::iterator_range< CastExpr::path_const_iterator > path, bool nullCheckValue)
Address maybeCastStackAddressSpace(Address alloca, mlir::ptr::MemorySpaceAttrInterface destAddrSpace, mlir::Value arraySize=nullptr)
RValue emitAtomicLoad(LValue lvalue, SourceLocation loc, AggValueSlot slot=AggValueSlot::ignored())
AggValueSlot createAggTemp(QualType ty, mlir::Location loc, const Twine &name="tmp", Address *alloca=nullptr)
Create a temporary memory object for the given aggregate type.
RValue emitLoadOfExtVectorElementLValue(LValue lv)
mlir::Value emitCXXTypeidExpr(const CXXTypeidExpr *e)
mlir::Type convertTypeForMem(QualType t)
mlir::Value emitAlloca(llvm::StringRef name, mlir::Type ty, mlir::Location loc, clang::CharUnits alignment, bool insertIntoFnEntryBlock, mlir::Value arraySize=nullptr)
mlir::Value emitComplexPrePostIncDec(const UnaryOperator *e, LValue lv)
void emitUnreachable(clang::SourceLocation loc, bool createNewBlock)
Emit a reached-unreachable diagnostic if loc is valid and runtime checking is enabled.
mlir::Value createDummyValue(mlir::Location loc, clang::QualType qt)
void emitCXXConstructExpr(const clang::CXXConstructExpr *e, AggValueSlot dest)
mlir::Value emitLoadOfComplex(LValue src, SourceLocation loc)
Load a complex number from the specified l-value.
LValue emitAggExprToLValue(const Expr *e)
void emitStoreOfScalar(mlir::Value value, Address addr, bool isVolatile, clang::QualType ty, LValueBaseInfo baseInfo, bool isInit=false, bool isNontemporal=false)
void pushDestroy(QualType::DestructionKind dtorKind, Address addr, QualType type)
Push the standard destructor for the given type as at least a normal cleanup.
static Destroyer destroyCXXObject
RValue getUndefRValue(clang::QualType ty)
Get an appropriate 'undef' rvalue for the given type.
Address returnValue
The temporary alloca to hold the return value.
static bool hasAggregateEvaluationKind(clang::QualType type)
LValue emitPointerToDataMemberBinaryExpr(const BinaryOperator *e)
const CallExpr * mustTailCall
std::string getCounterAggTmpAsString()
LValue emitUnaryOpLValue(const clang::UnaryOperator *e)
LValue emitMatrixSubscriptExpr(const MatrixSubscriptExpr *e)
RValue emitLoadOfBitfieldLValue(LValue lv, SourceLocation loc)
LValue emitComplexAssignmentLValue(const BinaryOperator *e)
const clang::Decl * curCodeDecl
This is the inner-most code context, which includes blocks.
LValue emitLValueForFieldInitialization(LValue base, const clang::FieldDecl *field, llvm::StringRef fieldName)
Like emitLValueForField, excpet that if the Field is a reference, this will return the address of the...
LValue emitCallExprLValue(const clang::CallExpr *e)
void emitCXXTemporary(const CXXTemporary *temporary, QualType tempType, Address ptr)
Emits all the code to cause the given temporary to be cleaned up.
LValue emitStringLiteralLValue(const StringLiteral *e, llvm::StringRef name=".str")
mlir::Value getUndefConstant(mlir::Location loc, mlir::Type cirTy)
Return a CIR constant for an undefined value of cirTy.
mlir::Value emitToMemory(mlir::Value value, clang::QualType ty)
Given a value and its clang type, returns the value casted to its memory representation.
LValue emitLValueForField(LValue base, const clang::FieldDecl *field)
mlir::Value emitScalarExpr(const clang::Expr *e, bool ignoreResultAssign=false)
Emit the computation of the specified expression of scalar type.
void pushLifetimeExtendedDestroy(CleanupKind kind, Address addr, QualType type, Destroyer *destroyer, bool useEHCleanupForArray, const clang::ValueDecl *extendingDecl)
Address emitLoadOfReference(LValue refLVal, mlir::Location loc, LValueBaseInfo *pointeeBaseInfo)
bool shouldNullCheckClassCastValue(const CastExpr *ce)
CIRGenBuilderTy & getBuilder()
LValue emitBinaryOperatorLValue(const BinaryOperator *e)
Address getAddrOfBitFieldStorage(LValue base, const clang::FieldDecl *field, mlir::Type fieldType, unsigned index)
void emitDestroy(Address addr, QualType type, Destroyer *destroyer)
Immediately perform the destruction of the given object.
CIRGenModule & getCIRGenModule()
mlir::MLIRContext & getMLIRContext()
std::optional< SourceRange > currSrcLoc
Use to track source locations across nested visitor traversals.
LValue emitCastLValue(const CastExpr *e)
Casts are never lvalues unless that cast is to a reference type.
LValue emitCXXTypeidLValue(const CXXTypeidExpr *e)
mlir::Value emitLoadOfScalar(LValue lvalue, SourceLocation loc)
EmitLoadOfScalar - Load a scalar value from an address, taking care to appropriately convert from the...
mlir::Value emitScalarPrePostIncDec(const UnaryOperator *e, LValue lv)
bool containsLabel(const clang::Stmt *s, bool ignoreCaseStmts=false)
Return true if the statement contains a label in it.
DeclMapTy localDeclMap
This keeps track of the CIR allocas or globals for local C declarations.
LValue emitDeclRefLValue(const clang::DeclRefExpr *e)
void emitComplexExprIntoLValue(const Expr *e, LValue dest, bool isInit)
llvm::DenseMap< const clang::ValueDecl *, clang::FieldDecl * > lambdaCaptureFields
ConstantEmission tryEmitAsConstant(const DeclRefExpr *refExpr)
Try to emit a reference to the given value without producing it as an l-value.
RValue emitCall(const CIRGenFunctionInfo &funcInfo, const CIRGenCallee &callee, ReturnValueSlot returnValue, const CallArgList &args, cir::CIRCallOpInterface *callOp, bool isMustTail, SourceRange clangLoc)
void emitCXXThrowExpr(const CXXThrowExpr *e)
LValue makeAddrLValue(Address addr, QualType ty, AlignmentSource source=AlignmentSource::Type)
LValue emitMatrixElementExpr(const MatrixElementExpr *e)
int64_t getAccessedFieldNo(unsigned idx, mlir::ArrayAttr elts)
LValue emitPredefinedLValue(const PredefinedExpr *e)
RValue emitAnyExpr(const clang::Expr *e, AggValueSlot aggSlot=AggValueSlot::ignored(), bool ignoreResult=false)
Emit code to compute the specified expression which can have any type.
llvm::DenseMap< const OpaqueValueExpr *, RValue > opaqueRValues
Address emitArrayToPointerDecay(const Expr *e, LValueBaseInfo *baseInfo=nullptr)
LexicalScope * curLexScope
void emitAtomicStore(RValue rvalue, LValue dest, bool isInit)
mlir::Value emitStoreThroughBitfieldLValue(RValue src, LValue dstresult)
llvm::DenseMap< const OpaqueValueExpr *, LValue > opaqueLValues
Keeps track of the current set of opaque value expressions.
CIRGenFunction(CIRGenModule &cgm, CIRGenBuilderTy &builder, bool suppressNewContext=false)
void terminateStructuredRegionBody(mlir::Region &r, mlir::Location loc)
Address createMemTempWithoutCast(QualType t, mlir::Location loc, const Twine &name="tmp")
LValue emitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *e)
LValue emitExtVectorElementExpr(const ExtVectorElementExpr *e)
clang::ASTContext & getContext() const
RValue emitCXXMemberOrOperatorMemberCallExpr(const clang::CallExpr *ce, const clang::CXXMethodDecl *md, ReturnValueSlot returnValue, bool hasQualifier, clang::NestedNameSpecifier qualifier, bool isArrow, const clang::Expr *base)
mlir::Value emitScalarConstant(const ConstantEmission &constant, Expr *e)
RValue emitBuiltinExpr(const clang::GlobalDecl &gd, unsigned builtinID, const clang::CallExpr *e, ReturnValueSlot returnValue)
RValue emitCXXOperatorMemberCallExpr(const CXXOperatorCallExpr *e, const CXXMethodDecl *md, ReturnValueSlot returnValue)
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 ...
mlir::Value cxxabiThisValue
bool isLValueSuitableForInlineAtomic(LValue lv)
An LValue is a candidate for having its loads and stores be made atomic if we are operating under /vo...
mlir::LogicalResult emitStmt(const clang::Stmt *s, bool useCurrentScope, llvm::ArrayRef< const Attr * > attrs={})
RValue getOrCreateOpaqueRValueMapping(const OpaqueValueExpr *e)
Given an opaque value expression, return its RValue mapping if it exists, otherwise create one.
Address createTempAllocaWithoutCast(mlir::Type ty, CharUnits align, mlir::Location loc, const Twine &name="tmp", mlir::Value arraySize=nullptr, mlir::OpBuilder::InsertPoint ip={})
This creates a alloca and inserts it into the entry block of the current region.
mlir::Value emitFromMemory(mlir::Value value, clang::QualType ty)
EmitFromMemory - Change a scalar value from its memory representation to its value representation.
void emitIgnoredExpr(const clang::Expr *e)
Emit code to compute the specified expression, ignoring the result.
Address createMemTemp(QualType t, mlir::Location loc, const Twine &name="tmp", Address *alloca=nullptr, mlir::OpBuilder::InsertPoint ip={})
Create a temporary memory object of the given type, with appropriate alignmen and cast it to the defa...
mlir::Value emitDynamicCast(Address thisAddr, const CXXDynamicCastExpr *dce)
void emitAggExpr(const clang::Expr *e, AggValueSlot slot)
ConditionalInfo emitConditionalBlocks(const AbstractConditionalOperator *e, const FuncTy &branchGenFunc)
Address createDefaultAlignTempAlloca(mlir::Type ty, mlir::Location loc, const Twine &name)
CreateDefaultAlignTempAlloca - This creates an alloca with the default alignment of the corresponding...
LValue emitCXXConstructLValue(const CXXConstructExpr *e)
RValue emitCXXPseudoDestructorExpr(const CXXPseudoDestructorExpr *expr)
LValue emitCompoundLiteralLValue(const CompoundLiteralExpr *e)
CIRGenCallee emitCallee(const clang::Expr *e)
Address emitAddrOfFieldStorage(Address base, const FieldDecl *field, llvm::StringRef fieldName, unsigned fieldIndex)
This class organizes the cross-function state that is used while generating CIR code.
DiagnosticBuilder errorNYI(SourceLocation, llvm::StringRef)
Helpers to emit "not yet implemented" error diagnostics.
cir::GlobalLinkageKind getCIRLinkageVarDefinition(const VarDecl *vd)
mlir::Operation * getWeakRefReference(const clang::ValueDecl *vd)
Return the symbol that a weakref declaration refers to: the cir.func or cir.global named by its alias...
CIRGenCUDARuntime & getCUDARuntime()
mlir::IntegerAttr getSize(CharUnits size)
CIRGenBuilderTy & getBuilder()
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)
cir::FuncOp getRawFunctionPointer(GlobalDecl GD)
Return a function pointer for a reference to the given function.
cir::FuncOp getAddrOfFunction(clang::GlobalDecl gd, mlir::Type funcType=nullptr, bool forVTable=false, bool dontDefer=false, ForDefinition_t isForDefinition=NotForDefinition)
Return the address of the given function.
mlir::Operation * getAddrOfGlobalTemporary(const MaterializeTemporaryExpr *mte, const Expr *init)
Returns a pointer to a global variable representing a temporary with static or thread storage duratio...
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::LangOptions & getLangOpts() const
mlir::Location getLoc(clang::SourceLocation cLoc)
Helpers to convert the presumed location of Clang's SourceLocation to an MLIR Location.
cir::FuncOp getFunctionPointer(GlobalDecl GD)
Return the ABI-correct function pointer value for a reference to the given function.
CIRGenOpenMPRuntime & getOpenMPRuntime()
bool hasRequiresUnifiedSharedMemory() const
Return whether unified shared memory is required.
This class handles record and union layout info while lowering AST types to CIR types.
cir::RecordType getCIRType() const
Return the "complete object" LLVM type associated with this record.
const CIRGenBitFieldInfo & getBitFieldInfo(const clang::FieldDecl *fd) const
Return the BitFieldInfo that corresponds to the field FD.
unsigned getCIRFieldNo(const clang::FieldDecl *fd) const
Return cir::RecordType element number that corresponds to the field FD.
bool hasCIRField(const clang::FieldDecl *fd) const
mlir::ptr::MemorySpaceAttrInterface getPointerAddressSpace(clang::QualType pointeeTy) const
Returns the CIR address space for a pointer/reference to pointeeTy, or a null attribute for the defau...
cir::FuncType getFunctionType(const CIRGenFunctionInfo &info)
Get the CIR function type for.
mlir::Type convertTypeForMem(clang::QualType, bool forBitField=false)
Convert type T into an mlir::Type.
mlir::Attribute emitAbstract(const Expr *e, QualType destType)
Emit the result of the given expression as an abstract constant, asserting that it succeeded.
AlignmentSource getAlignmentSource() const
void mergeForCast(const LValueBaseInfo &info)
bool isExtVectorElt() const
mlir::Value getVectorPointer() const
const clang::Qualifiers & getQuals() const
mlir::Value getExtVectorPointer() const
static LValue makeExtVectorElt(Address vecAddress, mlir::ArrayAttr elts, clang::QualType type, LValueBaseInfo baseInfo)
mlir::Value getVectorIdx() const
Address getAddress() const
static LValue makeAddr(Address address, clang::QualType t, LValueBaseInfo baseInfo)
mlir::ArrayAttr getExtVectorElts() const
static LValue makeVectorElt(Address vecAddress, mlir::Value index, clang::QualType t, LValueBaseInfo baseInfo)
RValue asAggregateRValue() const
unsigned getVRQualifiers() const
clang::QualType getType() const
static LValue makeBitfield(Address addr, const CIRGenBitFieldInfo &info, clang::QualType type, LValueBaseInfo baseInfo)
Create a new object to represent a bit-field access.
mlir::Value getPointer() const
Address getMatrixAddress() const
void setNontemporal(bool v)
bool isVolatileQualified() const
Address getVectorAddress() const
clang::CharUnits getAlignment() const
LValueBaseInfo getBaseInfo() const
mlir::Value getMatrixColumnIdx() const
bool isNontemporal() const
static LValue makeMatrixElt(Address matAddress, mlir::Value rowIdx, mlir::Value colIdx, clang::QualType t, LValueBaseInfo baseInfo)
const CIRGenBitFieldInfo & getBitFieldInfo() const
Address getBitFieldAddress() const
Address getExtVectorAddress() const
mlir::Value getMatrixRowIdx() const
This trivial value class is used to represent the result of an expression that is evaluated.
Address getAggregateAddress() const
Return the value of the address of the aggregate.
static RValue get(mlir::Value v)
static RValue getAggregate(Address addr, bool isVolatile=false)
Convert an Address to an RValue.
static RValue getComplex(mlir::Value v)
mlir::Value getValue() const
Return the value of this scalar value.
Contains the address where the return value of a function can be stored, and whether the address is v...
Represents binding an expression to a temporary.
CXXTemporary * getTemporary()
const Expr * getSubExpr() const
Represents a call to a C++ constructor.
Represents a C++ destructor within a class.
Represents a call to a member function that may be written either with member call syntax (e....
Represents a C++ struct/union/class.
bool hasTrivialDestructor() const
Determine whether this class has a trivial destructor (C++ [class.dtor]p3)
A C++ typeid expression (C++ [expr.typeid]), which gets the type_info that corresponds to the supplie...
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return null.
QualType getCallReturnType(const ASTContext &Ctx) const
getCallReturnType - Get the return type of the call expr.
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
CastKind getCastKind() const
llvm::iterator_range< path_iterator > path()
Path through the class hierarchy taken by casts between base and derived classes (see implementation ...
bool changesVolatileQualification() const
Return.
This is an opaque type for sizes expressed in character units.
CharUnits alignmentAtOffset(CharUnits offset) const
Given that this is a non-zero alignment value, what is the alignment at the given offset?
bool isZero() const
Test whether the quantity equals zero.
QuantityType getQuantity() const
Get the raw integer representation of this quantity.
static CharUnits 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)
Construct a CharUnits quantity from a raw integer type.
Complex values, per C99 6.2.5p11.
CompoundLiteralExpr - [C99 6.5.2.5].
const Expr * getInitializer() const
ConditionalOperator - The ?
Represents a concrete matrix type with constant number of rows and columns.
unsigned getNumColumns() const
Returns the number of columns in the matrix.
A reference to a declared variable, function, enum, etc.
bool refersToEnclosingVariableOrCapture() const
Does this DeclRefExpr refer to an enclosing local or a captured variable?
static DeclRefExpr * Create(const ASTContext &Context, NestedNameSpecifierLoc QualifierLoc, SourceLocation TemplateKWLoc, ValueDecl *D, bool RefersToEnclosingVariableOrCapture, SourceLocation NameLoc, QualType T, ExprValueKind VK, NamedDecl *FoundD=nullptr, const TemplateArgumentListInfo *TemplateArgs=nullptr, NonOdrUseReason NOUR=NOUR_None)
NonOdrUseReason isNonOdrUse() const
Is this expression a non-odr-use reference, and if so, why?
SourceLocation getLocation() const
Decl - This represents one declaration (or definition), e.g.
SourceLocation getLocation() const
bool isUsed(bool CheckUsedAttr=true) const
Whether any (re-)declaration of the entity was used, meaning that a definition is required.
DeclContext * getDeclContext()
const Expr * getBase() const
This represents one expression.
const Expr * skipRValueSubobjectAdjustments(SmallVectorImpl< const Expr * > &CommaLHS, SmallVectorImpl< SubobjectAdjustment > &Adjustments) const
Walk outwards from an expression we want to bind a reference to and find the expression whose lifetim...
ExprValueKind getValueKind() const
getValueKind - The value kind that this expression produces.
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
bool EvaluateAsLValue(EvalResult &Result, const ASTContext &Ctx, bool InConstantContext=false) const
EvaluateAsLValue - Evaluate an expression to see if we can fold it to an lvalue with link time known ...
bool EvaluateAsRValue(EvalResult &Result, const ASTContext &Ctx, bool InConstantContext=false) const
EvaluateAsRValue - Return true if this is a constant which we can fold to an rvalue using any crazy t...
Decl * getReferencedDeclOfCallee()
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
ExtVectorElementExpr - This represents access to specific elements of a vector, and may occur on the ...
bool isArrow() const
isArrow - Return true if the base expression is a pointer to vector, return false if the base express...
void getEncodedElementAccess(SmallVectorImpl< uint32_t > &Elts) const
getEncodedElementAccess - Encode the elements accessed into an llvm aggregate Constant of ConstantInt...
Represents a member of a struct/union/class.
bool isBitField() const
Determines whether this field is a bitfield.
SourceRange getSourceRange() const override LLVM_READONLY
Source range that this declaration covers.
unsigned getFieldIndex() const
Returns the index of this field within its record, as appropriate for passing to ASTRecordLayout::get...
const RecordDecl * getParent() const
Returns the parent of this field declaration, which is the struct in which this field is defined.
bool isPotentiallyOverlapping() const
Determine if this field is of potentially-overlapping class type, that is, subobject with the [[no_un...
Represents a function declaration or definition.
Represents a prototype with parameter type info, e.g.
GlobalDecl - represents a global declaration.
const Decl * getDecl() const
Represents a prvalue temporary that is written into memory so that a reference can bind to it.
StorageDuration getStorageDuration() const
Retrieve the storage duration for the materialized temporary.
Expr * getSubExpr() const
Retrieve the temporary-generating subexpression whose value will be materialized into a glvalue.
ValueDecl * getExtendingDecl()
Get the declaration which triggered the lifetime-extension of this temporary, if any.
void getEncodedElementAccess(SmallVectorImpl< uint32_t > &Elts) const
getEncodedElementAccess - Encode the elements accessed into an llvm aggregate Constant of ConstantInt...
MatrixSubscriptExpr - Matrix subscript expression for the MatrixType extension.
bool isIncomplete() const
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
ValueDecl * getMemberDecl() const
Retrieve the member declaration to which this expression refers.
NonOdrUseReason isNonOdrUse() const
Is this expression a non-odr-use reference, and if so, why?
SourceLocation getExprLoc() const LLVM_READONLY
A pointer to member type per C++ 8.3.3 - Pointers to members.
This represents a decl that may have a name.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
A C++ nested-name-specifier augmented with source location information.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Expr * getSourceExpr() const
The source expression of an opaque value expression is the expression which originally generated the ...
PointerType - C99 6.7.5.1 - Pointer Declarators.
[C99 6.4.2.2] - A predefined identifier such as func.
StringRef getIdentKindName() const
PredefinedIdentKind getIdentKind() const
StringLiteral * getFunctionName()
A (possibly-)qualified type.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
LangAS getAddressSpace() const
Return the address space of this type.
Qualifiers getQualifiers() const
Retrieve the set of qualifiers applied to this type.
Qualifiers::ObjCLifetime getObjCLifetime() const
Returns lifetime attribute of this type.
QualType getNonReferenceType() const
If Type is a reference type (e.g., const int&), returns the type that the reference refers to ("const...
QualType getUnqualifiedType() const
Retrieve the unqualified variant of the given type, removing as little sugar as possible.
QualType withCVRQualifiers(unsigned CVR) const
DestructionKind isDestructedType() const
Returns a nonzero value if objects of this type require non-trivial work to clean up after.
The collection of all-type qualifiers we support.
unsigned getCVRQualifiers() const
@ OCL_ExplicitNone
This object can be modified without requiring retains or releases.
@ OCL_None
There is no lifetime qualification on this type.
void addCVRQualifiers(unsigned mask)
void addQualifiers(Qualifiers Q)
Add the qualifiers from the given set to this set.
Represents a struct/union/class.
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
Stmt - This represents one statement.
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
StringLiteral - This represents a string literal expression, e.g.
bool isBlockPointerType() const
bool isSignedIntegerOrEnumerationType() const
Determines whether this is an integer type that is signed or an enumeration types whose underlying ty...
bool isPackedVectorBoolType(const ASTContext &ctx) const
const ArrayType * castAsArrayTypeUnsafe() const
A variant of castAs<> for array type which silently discards qualifiers from the outermost type.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
bool isFunctionPointerType() const
CXXRecordDecl * castAsCXXRecordDecl() const
bool isArithmeticType() const
bool isConstantMatrixType() const
bool isPointerType() const
const T * castAs() const
Member-template castAs<specific type>.
bool isReferenceType() const
bool isVariableArrayType() const
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee.
bool isExtVectorBoolType() const
bool isConstantMatrixBoolType() const
bool isAnyComplexType() const
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
bool isAtomicType() const
bool isVariablyModifiedType() const
Whether this type is a variably-modified type (C99 6.7.5).
bool isFunctionType() const
bool isVectorType() const
bool isSubscriptableVectorType() const
const T * getAs() const
Member-template getAs<specific type>'.
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
SourceLocation getExprLoc() const
Expr * getSubExpr() const
static bool isPrefix(Opcode Op)
isPrefix - Return true if this is a prefix operation, like –x.
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.
VarDecl * getDefinition(ASTContext &)
Get the real (not just tentative) definition for this declaration.
bool hasLocalStorage() const
Returns true if a variable with function scope is a non-static local variable.
@ TLS_None
Not a TLS variable.
Represents a C array with a specified size that is not an integer-constant-expression.
Represents a GCC generic vector type.
Defines the clang::TargetInfo interface.
mlir::ptr::MemorySpaceAttrInterface toCIRAddressSpaceAttr(mlir::MLIRContext &ctx, clang::LangAS langAS)
Convert an AST LangAS to the appropriate CIR address space attribute interface.
mlir::ptr::MemorySpaceAttrInterface normalizeDefaultAddressSpace(mlir::ptr::MemorySpaceAttrInterface addrSpace)
Normalize LangAddressSpace::Default to null (empty attribute).
PtrOffsetFlags
No-wrap flags of a pointer offset computation: the subset of llvm::GEPNoWrapFlags that cir....
AlignmentSource
The source of the alignment of an l-value; an expression of confidence in the alignment actually matc...
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
static AlignmentSource getFieldAlignmentSource(AlignmentSource source)
Given that the base address has the given alignment source, what's our confidence in the alignment of...
bool isAAPCS(const TargetInfo &TargetInfo)
Helper method to check if the underlying ABI is AAPCS.
QualType getFixedSizeElementType(const ASTContext &Ctx, const VariableArrayType *VLA)
Strip off the variably-modified array types wrapping VLA and return the first element type that has a...
bool onlyHasInlineBuiltinDeclaration(const FunctionDecl *FD)
Detect the unusual situation where an inline version of a builtin is shadowed by a non-inline version...
EvaluationOrder getCallArgEvaluationOrder(const CallExpr *E)
Returns the argument evaluation order the language requires for the given call.
ConstantEmissionKind checkVarTypeForConstantEmission(QualType Type)
Can we constant-emit a load of a reference to a variable of the given type?
bool isEmptyFieldForLayout(const ASTContext &Ctx, const FieldDecl *FD)
Return true iff the field is "empty", that is, either a zero-width bit-field or an isEmptyRecordForLa...
ConstantEmissionKind
How a reference to a variable can be emitted as a constant.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const AstTypeMatcher< FunctionType > functionType
const internal::VariadicDynCastAllOfMatcher< Stmt, CUDAKernelCallExpr > cudaKernelCallExpr
const internal::VariadicDynCastAllOfMatcher< Stmt, Expr > expr
Matches expressions.
const internal::VariadicDynCastAllOfMatcher< Stmt, CastExpr > castExpr
Matches any cast nodes of Clang's AST.
Top level wrappers for InstallAPI frontend operations.
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
bool isa(CodeGen::Address addr)
QualType pointeeType(QualType T)
bool isMatrixRowMajor(const LangOptions &LangOpts, QualType T)
Returns true if matrices of T should be laid out in row-major order.
@ SD_Thread
Thread storage duration.
@ SD_Static
Static storage duration.
@ SD_FullExpression
Full-expression storage duration (for temporaries).
@ SD_Automatic
Automatic storage duration (most local variables).
@ SD_Dynamic
Dynamic storage duration.
@ Dtor_Complete
Complete object dtor.
SmallVector< CXXBaseSpecifier *, 4 > CXXCastPath
A simple array of base specifiers.
U cast(CodeGen::Address addr)
bool isLambdaMethod(const DeclContext *DC)
@ NOUR_Unevaluated
This name appears in an unevaluated operand.
@ NOUR_Constant
This name appears as a potential result of an lvalue-to-rvalue conversion that is a constant expressi...
static bool objCLifetime()
static bool emitLifetimeMarkers()
static bool opLoadEmitScalarRangeCheck()
static bool addressSpace()
static bool opAllocaNonGC()
static bool opAllocaOpenMPThreadPrivate()
static bool preservedAccessIndexRegion()
static bool mergeAllConstants()
static bool opLoadStoreTbaa()
static bool opCallChain()
static bool opAllocaImpreciseLifetime()
static bool opAllocaStaticLocal()
static bool opAllocaTLS()
static bool emitCheckedInBoundsGEP()
static bool openMPNontemporalDecl()
static bool setObjCGCLValueClass()
static bool cirgenABIInfo()
static bool opLoadStoreObjC()
static bool pointerAuthentication()
static bool insertBuiltinUnpredictable()
static bool matrixTypeIndexAssumption()
static bool shouldReverseUnaryCondOnBoolExpr()
static bool addressIsKnownNonNull()
static bool openMPLastprivateConditional()
static bool astVarDeclInterface()
static bool cgCapturedStmtInfo()
static bool opAllocaEscapeByReference()
static bool opCallFnInfoOpts()
static bool generateDebugInfo()
static bool incrementProfileCounter()
Record with information about how a bitfield should be accessed.
Represents a scope, including function bodies, compound statements, and the substatements of if/while...
clang::CharUnits getPointerAlign() const
mlir::ptr::MemorySpaceAttrInterface getCIRAllocaAddressSpace() const
EvalResult is a struct with detailed info about an evaluated expression.
APValue Val
Val - This is the value the expression can be folded to.
bool HasSideEffects
Whether the evaluated expression has side effects.
An adjustment to be made to the temporary created when emitting a reference binding,...
@ DerivedToBaseAdjustment
@ MemberPointerAdjustment