https://github.com/TIFitis created https://github.com/llvm/llvm-project/pull/121001
Add Lowering support for OpenMP mapper field in mapInfoOp. Depends on #120994. >From 30611f81421028ccc8fceed006e06f8afc6848b9 Mon Sep 17 00:00:00 2001 From: Akash Banerjee <akash.baner...@amd.com> Date: Mon, 23 Dec 2024 19:05:30 +0000 Subject: [PATCH 1/2] Add mapper field to mapInfoOp. --- flang/test/Lower/OpenMP/map-mapper.f90 | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 flang/test/Lower/OpenMP/map-mapper.f90 diff --git a/flang/test/Lower/OpenMP/map-mapper.f90 b/flang/test/Lower/OpenMP/map-mapper.f90 new file mode 100644 index 00000000000000..e7fded3034406e --- /dev/null +++ b/flang/test/Lower/OpenMP/map-mapper.f90 @@ -0,0 +1,15 @@ +! RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=50 %s -o - | FileCheck %s +program p + integer, parameter :: n = 256 + real(8) :: a(256) + type t1 + integer :: x + end type t1 + !$omp declare mapper(xx : t1 :: nn) map(nn, nn%x) + !$omp target map(mapper(xx), from:a) +!CHECK: not yet implemented: Support for mapper modifiers is not implemented yet + do i = 1, n + a(i) = 4.2 + end do + !$omp end target +end program p >From ea048f78cdec2ea749562f17ae6d3614c2ef1f46 Mon Sep 17 00:00:00 2001 From: Akash Banerjee <akash.baner...@amd.com> Date: Mon, 23 Dec 2024 21:13:42 +0000 Subject: [PATCH 2/2] Add flang lowering changes for mapper field in map clause. --- flang/lib/Lower/OpenMP/ClauseProcessor.cpp | 32 +++++++++++++++++---- flang/lib/Lower/OpenMP/ClauseProcessor.h | 3 +- flang/test/Lower/OpenMP/Todo/map-mapper.f90 | 16 ----------- flang/test/Lower/OpenMP/map-mapper.f90 | 20 +++++++++---- 4 files changed, 43 insertions(+), 28 deletions(-) delete mode 100644 flang/test/Lower/OpenMP/Todo/map-mapper.f90 diff --git a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp index 3c9831120351ee..0bc9f4919330e4 100644 --- a/flang/lib/Lower/OpenMP/ClauseProcessor.cpp +++ b/flang/lib/Lower/OpenMP/ClauseProcessor.cpp @@ -936,8 +936,10 @@ void ClauseProcessor::processMapObjects( llvm::omp::OpenMPOffloadMappingFlags mapTypeBits, std::map<Object, OmpMapParentAndMemberData> &parentMemberIndices, llvm::SmallVectorImpl<mlir::Value> &mapVars, - llvm::SmallVectorImpl<const semantics::Symbol *> &mapSyms) const { + llvm::SmallVectorImpl<const semantics::Symbol *> &mapSyms, + std::string mapperIdName) const { fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder(); + mlir::FlatSymbolRefAttr mapperId; for (const omp::Object &object : objects) { llvm::SmallVector<mlir::Value> bounds; @@ -970,6 +972,20 @@ void ClauseProcessor::processMapObjects( } } + if (!mapperIdName.empty()) { + if (mapperIdName == "default") { + auto &typeSpec = object.sym()->owner().IsDerivedType() + ? *object.sym()->owner().derivedTypeSpec() + : object.sym()->GetType()->derivedTypeSpec(); + mapperIdName = typeSpec.name().ToString() + ".default"; + mapperIdName = converter.mangleName(mapperIdName, *typeSpec.GetScope()); + } + assert(converter.getMLIRSymbolTable()->lookup(mapperIdName) && + "mapper not found"); + mapperId = mlir::FlatSymbolRefAttr::get(&converter.getMLIRContext(), + mapperIdName); + mapperIdName.clear(); + } // Explicit map captures are captured ByRef by default, // optimisation passes may alter this to ByCopy or other capture // types to optimise @@ -983,7 +999,8 @@ void ClauseProcessor::processMapObjects( static_cast< std::underlying_type_t<llvm::omp::OpenMPOffloadMappingFlags>>( mapTypeBits), - mlir::omp::VariableCaptureKind::ByRef, baseOp.getType()); + mlir::omp::VariableCaptureKind::ByRef, baseOp.getType(), false, + mapperId); if (parentObj.has_value()) { parentMemberIndices[parentObj.value()].addChildIndexAndMapToParent( @@ -1014,6 +1031,7 @@ bool ClauseProcessor::processMap( const auto &[mapType, typeMods, mappers, iterator, objects] = clause.t; llvm::omp::OpenMPOffloadMappingFlags mapTypeBits = llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_NONE; + std::string mapperIdName; // If the map type is specified, then process it else Tofrom is the // default. Map::MapType type = mapType.value_or(Map::MapType::Tofrom); @@ -1057,13 +1075,17 @@ bool ClauseProcessor::processMap( "Support for iterator modifiers is not implemented yet"); } if (mappers) { - TODO(currentLocation, - "Support for mapper modifiers is not implemented yet"); + assert(mappers->size() == 1 && "more than one mapper"); + mapperIdName = mappers->front().v.id().symbol->name().ToString(); + if (mapperIdName != "default") + mapperIdName = converter.mangleName( + mapperIdName, mappers->front().v.id().symbol->owner()); } processMapObjects(stmtCtx, clauseLocation, std::get<omp::ObjectList>(clause.t), mapTypeBits, - parentMemberIndices, result.mapVars, *ptrMapSyms); + parentMemberIndices, result.mapVars, *ptrMapSyms, + mapperIdName); }; bool clauseFound = findRepeatableClause<omp::clause::Map>(process); diff --git a/flang/lib/Lower/OpenMP/ClauseProcessor.h b/flang/lib/Lower/OpenMP/ClauseProcessor.h index 7b047d4a7567ad..34eebf16ca17b0 100644 --- a/flang/lib/Lower/OpenMP/ClauseProcessor.h +++ b/flang/lib/Lower/OpenMP/ClauseProcessor.h @@ -171,7 +171,8 @@ class ClauseProcessor { llvm::omp::OpenMPOffloadMappingFlags mapTypeBits, std::map<Object, OmpMapParentAndMemberData> &parentMemberIndices, llvm::SmallVectorImpl<mlir::Value> &mapVars, - llvm::SmallVectorImpl<const semantics::Symbol *> &mapSyms) const; + llvm::SmallVectorImpl<const semantics::Symbol *> &mapSyms, + std::string mapperIdName = "") const; lower::AbstractConverter &converter; semantics::SemanticsContext &semaCtx; diff --git a/flang/test/Lower/OpenMP/Todo/map-mapper.f90 b/flang/test/Lower/OpenMP/Todo/map-mapper.f90 deleted file mode 100644 index 9554ffd5fda7bd..00000000000000 --- a/flang/test/Lower/OpenMP/Todo/map-mapper.f90 +++ /dev/null @@ -1,16 +0,0 @@ -! RUN: not %flang_fc1 -emit-fir -fopenmp -fopenmp-version=50 %s 2>&1 | FileCheck %s -program p - integer, parameter :: n = 256 - real(8) :: a(256) - !! TODO: Add declare mapper, when it works to lower this construct - !!type t1 - !! integer :: x - !!end type t1 - !!!$omp declare mapper(xx : t1 :: nn) map(nn, nn%x) - !$omp target map(mapper(xx), from:a) -!CHECK: not yet implemented: Support for mapper modifiers is not implemented yet - do i=1,n - a(i) = 4.2 - end do - !$omp end target -end program p diff --git a/flang/test/Lower/OpenMP/map-mapper.f90 b/flang/test/Lower/OpenMP/map-mapper.f90 index e7fded3034406e..856fff834643e4 100644 --- a/flang/test/Lower/OpenMP/map-mapper.f90 +++ b/flang/test/Lower/OpenMP/map-mapper.f90 @@ -1,15 +1,23 @@ ! RUN: %flang_fc1 -emit-hlfir -fopenmp -fopenmp-version=50 %s -o - | FileCheck %s program p integer, parameter :: n = 256 - real(8) :: a(256) type t1 - integer :: x + integer :: x(256) end type t1 - !$omp declare mapper(xx : t1 :: nn) map(nn, nn%x) - !$omp target map(mapper(xx), from:a) -!CHECK: not yet implemented: Support for mapper modifiers is not implemented yet + + !$omp declare mapper(xx : t1 :: nn) map(to: nn, nn%x) + !$omp declare mapper(t1 :: nn) map(from: nn) + + !CHECK-LABEL: omp.declare_mapper @_QQFt1.default : !fir.type<_QFTt1{x:!fir.array<256xi32>}> + !CHECK-LABEL: omp.declare_mapper @_QQFxx : !fir.type<_QFTt1{x:!fir.array<256xi32>}> + + type(t1) :: a, b + !CHECK: %[[MAP_A:.*]] = omp.map.info var_ptr(%{{.*}} : {{.*}}, {{.*}}) mapper(@_QQFxx) map_clauses(tofrom) capture(ByRef) -> {{.*}} {name = "a"} + !CHECK: %[[MAP_B:.*]] = omp.map.info var_ptr(%{{.*}} : {{.*}}, {{.*}}) mapper(@_QQFt1.default) map_clauses(tofrom) capture(ByRef) -> {{.*}} {name = "b"} + !CHECK: omp.target map_entries(%[[MAP_A]] -> %{{.*}}, %[[MAP_B]] -> %{{.*}}, %{{.*}} -> %{{.*}}, %{{.*}} -> %{{.*}} : {{.*}}, {{.*}}, {{.*}}, {{.*}}) { + !$omp target map(mapper(xx) : a) map(mapper(default) : b) do i = 1, n - a(i) = 4.2 + b%x(i) = a%x(i) end do !$omp end target end program p _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits