[Mlir-commits] [flang] [mlir] [Flang][MLIR][OpenMP] - Add support for firstprivate when translating omp.target ops from MLIR to LLVMIR (PR #131213)
Tom Eccles
llvmlistbot at llvm.org
Mon Mar 31 02:13:59 PDT 2025
================
@@ -158,5 +169,50 @@ class MapsForPrivatizedSymbolsPass
}
}
}
+ // As the name suggests, this function examines var to determine if
+ // it has dynamic size. If true, this pass'll have to extract these
+ // bounds from descriptor of var and add the bounds to the resultant
+ // MapInfoOp.
+ bool needsBoundsOps(mlir::Value var) {
+ assert(mlir::isa<omp::PointerLikeType>(var.getType()) &&
+ "needsBoundsOps can deal only with pointer types");
+ mlir::Type t = fir::unwrapRefType(var.getType());
+ // t could be a box, so look inside the box
+ auto innerType = fir::dyn_cast_ptrOrBoxEleTy(t);
+ if (innerType)
+ return fir::hasDynamicSize(innerType);
+ return fir::hasDynamicSize(t);
+ }
+ void genBoundsOps(fir::FirOpBuilder &builder, mlir::Value var,
+ llvm::SmallVector<mlir::Value> &boundsOps) {
+ if (!fir::isBoxAddress(var.getType()))
+ return;
+
+ unsigned int rank = 0;
+ rank = fir::getBoxRank(fir::unwrapRefType(var.getType()));
+ mlir::Location loc = var.getLoc();
+ mlir::Type idxTy = builder.getIndexType();
+ mlir::Value one = builder.createIntegerConstant(loc, idxTy, 1);
+ mlir::Type boundTy = builder.getType<omp::MapBoundsType>();
+ mlir::Value box = builder.create<fir::LoadOp>(loc, var);
+ for (unsigned int i = 0; i < rank; ++i) {
+ mlir::Value dimNo = builder.createIntegerConstant(loc, idxTy, i);
+ auto dimInfo =
+ builder.create<fir::BoxDimsOp>(loc, idxTy, idxTy, idxTy, box, dimNo);
+ auto normalizedLB = builder.create<mlir::arith::ConstantOp>(
+ loc, idxTy, builder.getIntegerAttr(idxTy, 0));
+ mlir::Value lb = dimInfo.getLowerBound();
+ mlir::Value extent = dimInfo.getExtent();
+ mlir::Value byteStride = dimInfo.getByteStride();
+ mlir::Value ub = builder.create<mlir::arith::SubIOp>(loc, extent, one);
----------------
tblah wrote:
Why do you subtract 1 here?
https://github.com/llvm/llvm-project/pull/131213
More information about the Mlir-commits
mailing list