[Mlir-commits] [openmp] [mlir] [flang] [Flang][OpenMP] Initial mapping of Fortran pointers and allocatables for target devices (PR #71766)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Dec 6 06:09:41 PST 2023
================
@@ -1710,30 +1710,76 @@ bool ClauseProcessor::processLink(
static mlir::omp::MapInfoOp
createMapInfoOp(fir::FirOpBuilder &builder, mlir::Location loc,
- mlir::Value baseAddr, std::stringstream &name,
- mlir::SmallVector<mlir::Value> bounds, uint64_t mapType,
- mlir::omp::VariableCaptureKind mapCaptureType,
- mlir::Type retTy) {
- mlir::Value varPtr, varPtrPtr;
- mlir::TypeAttr varType;
-
+ mlir::Value baseAddr, mlir::Value varPtrPtr, std::string name,
+ mlir::SmallVector<mlir::Value> bounds,
+ mlir::SmallVector<mlir::Value> members, uint64_t mapType,
+ mlir::omp::VariableCaptureKind mapCaptureType, mlir::Type retTy,
+ bool isVal = false) {
if (auto boxTy = baseAddr.getType().dyn_cast<fir::BaseBoxType>()) {
baseAddr = builder.create<fir::BoxAddrOp>(loc, baseAddr);
retTy = baseAddr.getType();
}
- varPtr = baseAddr;
- varType = mlir::TypeAttr::get(
+ mlir::TypeAttr varType = mlir::TypeAttr::get(
llvm::cast<mlir::omp::PointerLikeType>(retTy).getElementType());
mlir::omp::MapInfoOp op = builder.create<mlir::omp::MapInfoOp>(
- loc, retTy, varPtr, varType, varPtrPtr, bounds,
+ loc, retTy, baseAddr, varType, varPtrPtr, members, bounds,
builder.getIntegerAttr(builder.getIntegerType(64, false), mapType),
builder.getAttr<mlir::omp::VariableCaptureKindAttr>(mapCaptureType),
- builder.getStringAttr(name.str()));
+ builder.getStringAttr(name));
+
return op;
}
+static mlir::omp::MapInfoOp processDescriptorTypeMappings(
+ Fortran::semantics::SemanticsContext &semanticsContext,
+ Fortran::lower::StatementContext &stmtCtx,
+ Fortran::lower::AbstractConverter &converter, mlir::Location loc,
+ mlir::Value descriptorAddr, mlir::Value descDataBaseAddr,
+ mlir::ValueRange bounds, std::string asFortran,
+ llvm::omp::OpenMPOffloadMappingFlags mapCaptureType) {
+ llvm::SmallVector<mlir::Value> descriptorBaseAddrMembers;
+ fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
+
+ mlir::Value descriptor = descriptorAddr;
+
+ // The fir::BoxOffsetOp only works with !fir.ref<!fir.box<...>> types, as
+ // allowing it to access non-reference box operations can cause some
+ // problematic SSA IR. However, in the case of assumed shape's the type
+ // is not a !fir.ref, in these cases to retrieve the appropriate
+ // !fir.ref<!fir.box<...>> to access the data we need to map we must
+ // perform an alloca and then store to it and retrieve the data from the new
+ // alloca.
+ if (fir::isAssumedShape(fir::unwrapRefType(descriptorAddr.getType()))) {
+ mlir::OpBuilder::InsertPoint insPt = firOpBuilder.saveInsertionPoint();
+ firOpBuilder.setInsertionPointToStart(firOpBuilder.getAllocaBlock());
+ descriptor =
+ firOpBuilder.create<fir::AllocaOp>(loc, descriptorAddr.getType());
+ firOpBuilder.restoreInsertionPoint(insPt);
+ firOpBuilder.create<fir::StoreOp>(loc, descriptorAddr, descriptor);
----------------
agozillon wrote:
I could be incorrect or misunderstanding your question, but I believe currently with the previous ISA from above changes, all of the target regions symbols are replaced and bound to block arguments into the region (https://github.com/llvm/llvm-project/blob/e50fa9a64f0c37b7e4490bface684e9eff396830/flang/lib/Lower/OpenMP.cpp#L2584), and these block arguments correspond to each map operand (map_info inserted into the map operand list), so these uses are currently relinked in this function effectively when we replace the original descriptor with the newly generated alloca in the final map_info creation below, as the ISA changes effectively changed all of the symbols to block arguments, all that the target region cares about is if we put the right argument with the right type into the corresponding input block argument.
https://github.com/llvm/llvm-project/pull/71766
More information about the Mlir-commits
mailing list