26 const mlir::DataLayout &dataLayout,
28 mlir::Value &numElements, mlir::Value &allocPtr,
34 auto ptrTy = mlir::cast<cir::PointerType>(elementPtr.getType());
37 mlir::Value bytePtr = cir::CastOp::create(builder, loc, u8PtrTy,
38 cir::CastKind::bitcast, elementPtr);
40 mlir::Value negCookieSize = cir::ConstantOp::create(
41 builder, loc, cir::IntAttr::get(ptrDiffTy, -cookieSize.
getQuantity()));
42 mlir::Value allocBytePtr =
43 cir::PtrStrideOp::create(builder, loc, u8PtrTy, bytePtr, negCookieSize);
45 allocPtr = cir::CastOp::create(builder, loc, voidPtrTy,
46 cir::CastKind::bitcast, allocBytePtr);
52 dataLayout.getTypePreferredAlignment(ptrTy.getPointee()));
54 cookieAlignment, dataLayout, builder);
virtual clang::CharUnits getArrayCookieSizeImpl(mlir::Type elementType, const mlir::DataLayout &dataLayout) const =0
Returns the cookie size in bytes for a dynamically-allocated array of elements with the given type.
void readArrayCookie(mlir::Location loc, mlir::Value elementPtr, const mlir::DataLayout &dataLayout, CIRBaseBuilderTy &builder, mlir::Value &numElements, mlir::Value &allocPtr, clang::CharUnits &cookieSize) const
Read the array cookie for a dynamically-allocated array whose first element is at elementPtr.
virtual mlir::Value readArrayCookieImpl(mlir::Location loc, mlir::Value allocPtr, clang::CharUnits cookieSize, clang::CharUnits cookieAlignment, const mlir::DataLayout &dataLayout, CIRBaseBuilderTy &builder) const =0
Reads the element count from an array cookie.