10#include "llvm/ADT/TypeSwitch.h"
17 const auto arrayPtrTy = mlir::cast<cir::PointerType>(arrayPtr.getType());
18 const auto arrayTy = mlir::dyn_cast<cir::ArrayType>(arrayPtrTy.getPointee());
21 const cir::PointerType flatPtrTy =
getPointerTo(arrayTy.getElementType());
22 return create<cir::CastOp>(loc, flatPtrTy, cir::CastKind::array_to_ptrdecay,
26 assert(arrayPtrTy.getPointee() == eltTy &&
27 "flat pointee type must match original array element type");
32 mlir::Location arrayLocEnd,
34 mlir::Type eltTy, mlir::Value idx,
36 mlir::Value basePtr = arrayPtr;
39 const mlir::Type flatPtrTy = basePtr.getType();
40 return create<cir::PtrStrideOp>(arrayLocEnd, flatPtrTy, basePtr, idx);
44 llvm::APSInt intVal) {
45 bool isSigned = intVal.isSigned();
46 unsigned width = intVal.getBitWidth();
49 isSigned ? intVal.getSExtValue() : intVal.getZExtValue());
59 assert(mlir::isa<cir::IntType>(t) &&
"expected cir::IntType");
60 return create<cir::ConstantOp>(loc, cir::IntAttr::get(t,
c));
65 llvm::APFloat fpVal) {
66 assert(mlir::isa<cir::FPTypeInterface>(t) &&
"expected floating point type");
67 return create<cir::ConstantOp>(loc, cir::FPAttr::get(t, fpVal));
76 auto getIndexAndNewOffset =
77 [](int64_t offset, int64_t eltSize) -> std::pair<int64_t, int64_t> {
78 int64_t divRet = offset / eltSize;
81 int64_t modRet = offset - (divRet * eltSize);
82 return {divRet, modRet};
86 llvm::TypeSwitch<mlir::Type, mlir::Type>(ty)
87 .Case<cir::ArrayType>([&](
auto arrayTy) {
89 const auto [index, newOffset] =
90 getIndexAndNewOffset(offset, eltSize);
91 indices.push_back(index);
93 return arrayTy.getElementType();
95 .Case<cir::RecordType>([&](
auto recordTy) {
98 for (
size_t i = 0; i < elts.size(); ++i) {
102 if (recordTy.getPacked())
108 if (!recordTy.isUnion())
109 pos = (pos + alignMask) & ~alignMask;
111 if (offset < pos + eltSize) {
112 indices.push_back(i);
117 if (!recordTy.isUnion())
120 llvm_unreachable(
"offset was not found within the record");
122 .
Default([](mlir::Type otherTy) {
123 llvm_unreachable(
"unexpected type");
136 mlir::Type elemTy)
const {
__device__ __2f16 float c
cir::PointerType getPointerTo(mlir::Type ty)
mlir::Value createPtrBitcast(mlir::Value src, mlir::Type newPointeeTy)
llvm::TypeSize getTypeAllocSize(mlir::Type ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
llvm::Align getABITypeAlign(mlir::Type ty) 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::Value getBasePointer() const
cir::IntType getSIntNTy(int n)
mlir::Value maybeBuildArrayDecay(mlir::Location loc, mlir::Value arrayPtr, mlir::Type eltTy)
Returns a decayed pointer to the first element of the array pointed to by arrayPtr.
cir::ConstantOp getConstFP(mlir::Location loc, mlir::Type t, llvm::APFloat fpVal)
cir::ConstantOp getConstInt(mlir::Location loc, llvm::APSInt intVal)
void computeGlobalViewIndicesFromFlatOffset(int64_t offset, mlir::Type ty, cir::CIRDataLayout layout, llvm::SmallVectorImpl< int64_t > &indices)
cir::IntType getUIntNTy(int n)
mlir::Value getArrayElement(mlir::Location arrayLocBegin, mlir::Location arrayLocEnd, mlir::Value arrayPtr, mlir::Type eltTy, mlir::Value idx, bool shouldDecay)
Create a cir.ptr_stride operation to get access to an array element.
static bool addressPointerAuthInfo()
static bool addressOffset()
static bool addressIsKnownNonNull()