@@ -607,6 +607,12 @@ class ClauseProcessor {
607
607
llvm::SmallVectorImpl<const Fortran::semantics::Symbol *>
608
608
&useDeviceSymbols) const ;
609
609
610
+ template <typename T>
611
+ bool
612
+ processMotionClauses (Fortran::semantics::SemanticsContext &semanticsContext,
613
+ Fortran::lower::StatementContext &stmtCtx,
614
+ llvm::SmallVectorImpl<mlir::Value> &mapOperands);
615
+
610
616
// Call this method for these clauses that should be supported but are not
611
617
// implemented yet. It triggers a compilation error if any of the given
612
618
// clauses is found.
@@ -1893,6 +1899,47 @@ bool ClauseProcessor::processUseDevicePtr(
1893
1899
});
1894
1900
}
1895
1901
1902
+ template <typename T>
1903
+ bool ClauseProcessor::processMotionClauses (
1904
+ Fortran::semantics::SemanticsContext &semanticsContext,
1905
+ Fortran::lower::StatementContext &stmtCtx,
1906
+ llvm::SmallVectorImpl<mlir::Value> &mapOperands) {
1907
+ return findRepeatableClause<T>(
1908
+ [&](const T *motionClause, const Fortran::parser::CharBlock &source) {
1909
+ mlir::Location clauseLocation = converter.genLocation (source);
1910
+ fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder ();
1911
+
1912
+ static_assert (std::is_same_v<T, ClauseProcessor::ClauseTy::To> ||
1913
+ std::is_same_v<T, ClauseProcessor::ClauseTy::From>);
1914
+
1915
+ // TODO Support motion modifiers: present, mapper, iterator.
1916
+ constexpr llvm::omp::OpenMPOffloadMappingFlags mapTypeBits =
1917
+ std::is_same_v<T, ClauseProcessor::ClauseTy::To>
1918
+ ? llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_TO
1919
+ : llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_FROM;
1920
+
1921
+ for (const Fortran::parser::OmpObject &ompObject : motionClause->v .v ) {
1922
+ llvm::SmallVector<mlir::Value> bounds;
1923
+ std::stringstream asFortran;
1924
+ Fortran::lower::AddrAndBoundsInfo info =
1925
+ Fortran::lower::gatherDataOperandAddrAndBounds<
1926
+ Fortran::parser::OmpObject, mlir::omp::DataBoundsOp,
1927
+ mlir::omp::DataBoundsType>(
1928
+ converter, firOpBuilder, semanticsContext, stmtCtx, ompObject,
1929
+ clauseLocation, asFortran, bounds, treatIndexAsSection);
1930
+
1931
+ mlir::Value mapOp = createMapInfoOp (
1932
+ firOpBuilder, clauseLocation, info.addr , asFortran, bounds,
1933
+ static_cast <
1934
+ std::underlying_type_t <llvm::omp::OpenMPOffloadMappingFlags>>(
1935
+ mapTypeBits),
1936
+ mlir::omp::VariableCaptureKind::ByRef, info.addr .getType ());
1937
+
1938
+ mapOperands.push_back (mapOp);
1939
+ }
1940
+ });
1941
+ }
1942
+
1896
1943
template <typename ... Ts>
1897
1944
void ClauseProcessor::processTODO (mlir::Location currentLocation,
1898
1945
llvm::omp::Directive directive) const {
@@ -2416,10 +2463,10 @@ genDataOp(Fortran::lower::AbstractConverter &converter,
2416
2463
2417
2464
template <typename OpTy>
2418
2465
static OpTy
2419
- genEnterExitDataOp (Fortran::lower::AbstractConverter &converter,
2420
- Fortran::semantics::SemanticsContext &semanticsContext,
2421
- mlir::Location currentLocation,
2422
- const Fortran::parser::OmpClauseList &clauseList) {
2466
+ genEnterExitUpdateDataOp (Fortran::lower::AbstractConverter &converter,
2467
+ Fortran::semantics::SemanticsContext &semanticsContext,
2468
+ mlir::Location currentLocation,
2469
+ const Fortran::parser::OmpClauseList &clauseList) {
2423
2470
fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder ();
2424
2471
Fortran::lower::StatementContext stmtCtx;
2425
2472
mlir::Value ifClauseOperand, deviceOperand;
@@ -2436,6 +2483,10 @@ genEnterExitDataOp(Fortran::lower::AbstractConverter &converter,
2436
2483
directiveName =
2437
2484
Fortran::parser::OmpIfClause::DirectiveNameModifier::TargetExitData;
2438
2485
directive = llvm::omp::Directive::OMPD_target_exit_data;
2486
+ } else if constexpr (std::is_same_v<OpTy, mlir::omp::UpdateDataOp>) {
2487
+ directiveName =
2488
+ Fortran::parser::OmpIfClause::DirectiveNameModifier::TargetUpdate;
2489
+ directive = llvm::omp::Directive::OMPD_target_update;
2439
2490
} else {
2440
2491
return nullptr ;
2441
2492
}
@@ -2444,8 +2495,18 @@ genEnterExitDataOp(Fortran::lower::AbstractConverter &converter,
2444
2495
cp.processIf (directiveName, ifClauseOperand);
2445
2496
cp.processDevice (stmtCtx, deviceOperand);
2446
2497
cp.processNowait (nowaitAttr);
2447
- cp.processMap (currentLocation, directive, semanticsContext, stmtCtx,
2448
- mapOperands);
2498
+
2499
+ if constexpr (std::is_same_v<OpTy, mlir::omp::UpdateDataOp>) {
2500
+ cp.processMotionClauses <Fortran::parser::OmpClause::To>(
2501
+ semanticsContext, stmtCtx, mapOperands);
2502
+ cp.processMotionClauses <Fortran::parser::OmpClause::From>(
2503
+ semanticsContext, stmtCtx, mapOperands);
2504
+
2505
+ } else {
2506
+ cp.processMap (currentLocation, directive, semanticsContext, stmtCtx,
2507
+ mapOperands);
2508
+ }
2509
+
2449
2510
cp.processTODO <Fortran::parser::OmpClause::Depend>(currentLocation,
2450
2511
directive);
2451
2512
@@ -2847,15 +2908,17 @@ genOmpSimpleStandalone(Fortran::lower::AbstractConverter &converter,
2847
2908
genDataOp (converter, eval, semanticsContext, currentLocation, opClauseList);
2848
2909
break ;
2849
2910
case llvm::omp::Directive::OMPD_target_enter_data:
2850
- genEnterExitDataOp <mlir::omp::EnterDataOp>(converter, semanticsContext,
2851
- currentLocation, opClauseList);
2911
+ genEnterExitUpdateDataOp <mlir::omp::EnterDataOp>(
2912
+ converter, semanticsContext, currentLocation, opClauseList);
2852
2913
break ;
2853
2914
case llvm::omp::Directive::OMPD_target_exit_data:
2854
- genEnterExitDataOp <mlir::omp::ExitDataOp>(converter, semanticsContext,
2855
- currentLocation, opClauseList);
2915
+ genEnterExitUpdateDataOp <mlir::omp::ExitDataOp>(
2916
+ converter, semanticsContext, currentLocation, opClauseList);
2856
2917
break ;
2857
2918
case llvm::omp::Directive::OMPD_target_update:
2858
- TODO (currentLocation, " OMPD_target_update" );
2919
+ genEnterExitUpdateDataOp<mlir::omp::UpdateDataOp>(
2920
+ converter, semanticsContext, currentLocation, opClauseList);
2921
+ break ;
2859
2922
case llvm::omp::Directive::OMPD_ordered:
2860
2923
TODO (currentLocation, " OMPD_ordered" );
2861
2924
}
0 commit comments