[clang] [CIR] Add index support for global_view (PR #153254)
Bruno Cardoso Lopes via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 13 14:54:53 PDT 2025
================
@@ -66,6 +66,62 @@ clang::CIRGen::CIRGenBuilderTy::getConstFP(mlir::Location loc, mlir::Type t,
return create<cir::ConstantOp>(loc, cir::FPAttr::get(t, fpVal));
}
+void CIRGenBuilderTy::computeGlobalViewIndicesFromFlatOffset(
+ int64_t offset, mlir::Type ty, cir::CIRDataLayout layout,
+ llvm::SmallVectorImpl<int64_t> &indices) {
+ if (!offset)
+ return;
+
+ mlir::Type subType;
+
+ auto getIndexAndNewOffset =
+ [](int64_t offset, int64_t eltSize) -> std::pair<int64_t, int64_t> {
+ int64_t divRet = offset / eltSize;
+ if (divRet < 0)
+ divRet -= 1; // make sure offset is positive
+ int64_t modRet = offset - (divRet * eltSize);
+ return {divRet, modRet};
+ };
+
+ if (auto arrayTy = mlir::dyn_cast<cir::ArrayType>(ty)) {
----------------
bcardosolopes wrote:
Should we use `TypeSwitch` here and it's result is directly into `subType`?
https://github.com/llvm/llvm-project/pull/153254
More information about the cfe-commits
mailing list