[Mlir-commits] [mlir] [OpenMP][Flang] Add "IsolatedFromAbove" trait to omp.target (PR #67164)
Kiran Chandramohan
llvmlistbot at llvm.org
Mon Oct 30 04:49:25 PDT 2023
================
@@ -2463,10 +2556,113 @@ genTargetOp(Fortran::lower::AbstractConverter &converter,
Fortran::parser::OmpClause::Defaultmap>(
currentLocation, llvm::omp::Directive::OMPD_target);
- return genOpWithBody<mlir::omp::TargetOp>(
- converter, eval, currentLocation, outerCombined, &clauseList,
- ifClauseOperand, deviceOperand, threadLimitOperand, nowaitAttr,
- mapOperands);
+ auto captureImplicitMap = [&](const Fortran::semantics::Symbol &sym) {
+ if (llvm::find(mapSymbols, &sym) == mapSymbols.end()) {
+ mlir::Value baseOp = converter.getSymbolAddress(sym);
+ if (!baseOp)
+ if (const auto *details = sym.template detailsIf<
+ Fortran::semantics::HostAssocDetails>()) {
+ baseOp = converter.getSymbolAddress(details->symbol());
+ converter.copySymbolBinding(details->symbol(), sym);
+ }
+
+ if (baseOp) {
+ llvm::SmallVector<mlir::Value> bounds;
+ std::stringstream name;
+ fir::ExtendedValue dataExv = converter.getSymbolExtendedValue(sym);
+ name << sym.name().ToString();
+
+ mlir::Value baseAddr =
+ getDataOperandBaseAddr(converter, converter.getFirOpBuilder(), sym,
+ converter.getCurrentLocation());
+ if (fir::unwrapRefType(baseAddr.getType()).isa<fir::BaseBoxType>())
+ bounds =
+ Fortran::lower::genBoundsOpsFromBox<mlir::omp::DataBoundsOp,
+ mlir::omp::DataBoundsType>(
+ converter.getFirOpBuilder(), converter.getCurrentLocation(),
+ converter, dataExv, baseAddr);
+ if (fir::unwrapRefType(baseAddr.getType()).isa<fir::SequenceType>())
+ bounds = Fortran::lower::genBaseBoundsOps<mlir::omp::DataBoundsOp,
+ mlir::omp::DataBoundsType>(
+ converter.getFirOpBuilder(), converter.getCurrentLocation(),
+ converter, dataExv, baseAddr);
+
+ llvm::omp::OpenMPOffloadMappingFlags mapFlag =
+ llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_IMPLICIT;
+ mlir::omp::VariableCaptureKind captureKind =
+ mlir::omp::VariableCaptureKind::ByRef;
+ if (auto refType = baseOp.getType().dyn_cast<fir::ReferenceType>()) {
+ auto eleType = refType.getElementType();
+ if (fir::isa_trivial(eleType) || fir::isa_char(eleType)) {
+ // mapFlag |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_LITERAL;
+ captureKind = mlir::omp::VariableCaptureKind::ByCopy;
+ } else if (!fir::isa_builtin_cptr_type(eleType)) {
+ mapFlag |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_TO;
+ mapFlag |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_FROM;
+ }
+ }
+
+ mlir::Value mapOp = createMapInfoOp(
+ converter.getFirOpBuilder(), baseOp.getLoc(), baseOp, name, bounds,
+ static_cast<
+ std::underlying_type_t<llvm::omp::OpenMPOffloadMappingFlags>>(
+ mapFlag),
+ captureKind, baseOp.getType());
+
+ mapOperands.push_back(mapOp);
+ mapSymTypes.push_back(baseOp.getType());
+ mapSymLocs.push_back(baseOp.getLoc());
+ mapSymbols.push_back(&sym);
+ }
+ }
+ };
+ Fortran::lower::pft::visitAllSymbols(eval, captureImplicitMap);
+
+ // Add the bounds and extents for box values to mapOperands
+ auto addBoundsInfo = [&](const auto &bounds) {
----------------
kiranchandramohan wrote:
Nit: Rename this to addMapInfoForBounds?
https://github.com/llvm/llvm-project/pull/67164
More information about the Mlir-commits
mailing list