[flang-commits] [flang] [Flang][OpenMP][MLIR] Align declare mapper pass handling with other map and global operations (PR #176852)
via flang-commits
flang-commits at lists.llvm.org
Mon Jan 19 20:22:02 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-codegen
Author: None (agozillon)
<details>
<summary>Changes</summary>
This PR makes a couple of minor tweaks to the lowering for declare_mapper operations:
1) Add declare_mapper operations to the list of global operations to have optimisation passes
executed on them. Primarily just to make sure we keep it inline with other global operations
that contain regions. Prevents oddities where we embed FIR/HLFIR into the mapper that needs
lowered before being converted to LLVM-IR. One example that springs to mind is if we ever
decide to remove the single block condition on the operation to allow conditional checks
for mapped data.
2) Add a CodeGenOpenMP.cpp conversion for DeclareMapperOp to make sure we convert the return
type correctly from a BoxType to a struct type rather than an opaque pointer when lowering.
Currently, I've left out the block argument types from being converted as they're wrapped
in a fir.ref and would be opauqe pointers in either case.
So some minor additions to keep declare_mapper a little more inline with the rest of the OpenMP operations.
---
Full diff: https://github.com/llvm/llvm-project/pull/176852.diff
7 Files Affected:
- (modified) flang/lib/Optimizer/CodeGen/CodeGenOpenMP.cpp (+16)
- (modified) flang/lib/Optimizer/Passes/Pipelines.cpp (+3-2)
- (modified) flang/test/Driver/bbc-mlir-pass-pipeline.f90 (+7-2)
- (modified) flang/test/Driver/mlir-debug-pass-pipeline.f90 (+13-4)
- (modified) flang/test/Driver/mlir-pass-pipeline.f90 (+26-7)
- (modified) flang/test/Fir/basic-program.fir (+26-9)
- (added) flang/test/Transforms/OpenMP/conversion-declare-mapper.mlir (+19)
``````````diff
diff --git a/flang/lib/Optimizer/CodeGen/CodeGenOpenMP.cpp b/flang/lib/Optimizer/CodeGen/CodeGenOpenMP.cpp
index f74d635d50a75..3e1fe1d2b1613 100644
--- a/flang/lib/Optimizer/CodeGen/CodeGenOpenMP.cpp
+++ b/flang/lib/Optimizer/CodeGen/CodeGenOpenMP.cpp
@@ -260,6 +260,21 @@ struct TargetAllocMemOpConversion
return mlir::success();
}
};
+
+struct DeclareMapperOpConversion
+ : public OpenMPFIROpConversion<mlir::omp::DeclareMapperOp> {
+ using OpenMPFIROpConversion::OpenMPFIROpConversion;
+
+ llvm::LogicalResult
+ matchAndRewrite(mlir::omp::DeclareMapperOp curOp, OpAdaptor adaptor,
+ mlir::ConversionPatternRewriter &rewriter) const override {
+ rewriter.startOpModification(curOp);
+ curOp.setType(convertObjectType(lowerTy(), curOp.getType()));
+ rewriter.finalizeOpModification(curOp);
+ return mlir::success();
+ }
+};
+
} // namespace
void fir::populateOpenMPFIRToLLVMConversionPatterns(
@@ -267,4 +282,5 @@ void fir::populateOpenMPFIRToLLVMConversionPatterns(
patterns.add<MapInfoOpConversion>(converter);
patterns.add<PrivateClauseOpConversion>(converter);
patterns.add<TargetAllocMemOpConversion>(converter);
+ patterns.add<DeclareMapperOpConversion>(converter);
}
diff --git a/flang/lib/Optimizer/Passes/Pipelines.cpp b/flang/lib/Optimizer/Passes/Pipelines.cpp
index cdac494c97e3a..6054675643c64 100644
--- a/flang/lib/Optimizer/Passes/Pipelines.cpp
+++ b/flang/lib/Optimizer/Passes/Pipelines.cpp
@@ -20,8 +20,9 @@ namespace fir {
template <typename F>
void addNestedPassToAllTopLevelOperations(mlir::PassManager &pm, F ctor) {
- addNestedPassToOps<F, mlir::func::FuncOp, mlir::omp::DeclareReductionOp,
- mlir::omp::PrivateClauseOp, fir::GlobalOp>(pm, ctor);
+ addNestedPassToOps<F, mlir::func::FuncOp, mlir::omp::DeclareMapperOp,
+ mlir::omp::DeclareReductionOp, mlir::omp::PrivateClauseOp,
+ fir::GlobalOp>(pm, ctor);
}
template <typename F>
diff --git a/flang/test/Driver/bbc-mlir-pass-pipeline.f90 b/flang/test/Driver/bbc-mlir-pass-pipeline.f90
index bf2712d547a82..21697485a2a89 100644
--- a/flang/test/Driver/bbc-mlir-pass-pipeline.f90
+++ b/flang/test/Driver/bbc-mlir-pass-pipeline.f90
@@ -17,12 +17,14 @@
! CHECK-NEXT: (S) 0 num-cse'd - Number of operations CSE'd
! CHECK-NEXT: (S) 0 num-dce'd - Number of operations DCE'd
-! CHECK-NEXT: Pipeline Collection : ['fir.global', 'func.func', 'omp.declare_reduction', 'omp.private']
+! CHECK-NEXT: Pipeline Collection : ['fir.global', 'func.func', 'omp.declare_mapper', 'omp.declare_reduction', 'omp.private']
! CHECK-NEXT: 'fir.global' Pipeline
! CHECK-NEXT: CharacterConversion
! CHECK-NEXT: 'func.func' Pipeline
! CHECK-NEXT: ArrayValueCopy
! CHECK-NEXT: CharacterConversion
+! CHECK-NEXT: 'omp.declare_mapper' Pipeline
+! CHECK-NEXT: CharacterConversion
! CHECK-NEXT: 'omp.declare_reduction' Pipeline
! CHECK-NEXT: CharacterConversion
! CHECK-NEXT: 'omp.private' Pipeline
@@ -52,13 +54,16 @@
! CHECK-NEXT: LowerRepackArraysPass
! CHECK-NEXT: SimplifyFIROperations
-! CHECK-NEXT: Pipeline Collection : ['fir.global', 'func.func', 'omp.declare_reduction', 'omp.private']
+! CHECK-NEXT: Pipeline Collection : ['fir.global', 'func.func', 'omp.declare_mapper', 'omp.declare_reduction', 'omp.private']
! CHECK-NEXT: 'fir.global' Pipeline
! CHECK-NEXT: StackReclaim
! CHECK-NEXT: CFGConversion
! CHECK-NEXT: 'func.func' Pipeline
! CHECK-NEXT: StackReclaim
! CHECK-NEXT: CFGConversion
+! CHECK-NEXT: 'omp.declare_mapper' Pipeline
+! CHECK-NEXT: StackReclaim
+! CHECK-NEXT: CFGConversion
! CHECK-NEXT: 'omp.declare_reduction' Pipeline
! CHECK-NEXT: StackReclaim
! CHECK-NEXT: CFGConversion
diff --git a/flang/test/Driver/mlir-debug-pass-pipeline.f90 b/flang/test/Driver/mlir-debug-pass-pipeline.f90
index 0138d9b152744..3f6bde2ded67b 100644
--- a/flang/test/Driver/mlir-debug-pass-pipeline.f90
+++ b/flang/test/Driver/mlir-debug-pass-pipeline.f90
@@ -28,11 +28,13 @@
! ALL: Pass statistics report
! ALL: Fortran::lower::VerifierPass
-! ALL-NEXT: Pipeline Collection : ['fir.global', 'func.func', 'omp.declare_reduction', 'omp.private']
+! ALL-NEXT: Pipeline Collection : ['fir.global', 'func.func', 'omp.declare_mapper', 'omp.declare_reduction', 'omp.private']
! ALL-NEXT: 'fir.global' Pipeline
! ALL-NEXT: InlineElementals
! ALL-NEXT: 'func.func' Pipeline
! ALL-NEXT: InlineElementals
+! ALL-NEXT: 'omp.declare_mapper' Pipeline
+! ALL-NEXT: InlineElementals
! ALL-NEXT: 'omp.declare_reduction' Pipeline
! ALL-NEXT: InlineElementals
! ALL-NEXT: 'omp.private' Pipeline
@@ -49,12 +51,14 @@
! ALL-NEXT: (S) 0 num-cse'd - Number of operations CSE'd
! ALL-NEXT: (S) 0 num-dce'd - Number of operations DCE'd
-! ALL-NEXT: Pipeline Collection : ['fir.global', 'func.func', 'omp.declare_reduction', 'omp.private']
+! ALL-NEXT: Pipeline Collection : ['fir.global', 'func.func', 'omp.declare_mapper', 'omp.declare_reduction', 'omp.private']
! ALL-NEXT: 'fir.global' Pipeline
! ALL-NEXT: CharacterConversion
! ALL-NEXT: 'func.func' Pipeline
! ALL-NEXT: ArrayValueCopy
! ALL-NEXT: CharacterConversion
+! ALL-NEXT: 'omp.declare_mapper' Pipeline
+! ALL-NEXT: CharacterConversion
! ALL-NEXT: 'omp.declare_reduction' Pipeline
! ALL-NEXT: CharacterConversion
! ALL-NEXT: 'omp.private' Pipeline
@@ -80,13 +84,16 @@
! ALL-NEXT: LowerRepackArraysPass
! ALL-NEXT: SimplifyFIROperations
-! ALL-NEXT: Pipeline Collection : ['fir.global', 'func.func', 'omp.declare_reduction', 'omp.private']
+! ALL-NEXT: Pipeline Collection : ['fir.global', 'func.func', 'omp.declare_mapper', 'omp.declare_reduction', 'omp.private']
! ALL-NEXT: 'fir.global' Pipeline
! ALL-NEXT: StackReclaim
! ALL-NEXT: CFGConversion
! ALL-NEXT: 'func.func' Pipeline
! ALL-NEXT: StackReclaim
! ALL-NEXT: CFGConversion
+! ALL-NEXT: 'omp.declare_mapper' Pipeline
+! ALL-NEXT: StackReclaim
+! ALL-NEXT: CFGConversion
! ALL-NEXT: 'omp.declare_reduction' Pipeline
! ALL-NEXT: StackReclaim
! ALL-NEXT: CFGConversion
@@ -103,7 +110,7 @@
! ALL-NEXT: MIFOpConversion
! ALL-NEXT: BoxedProcedurePass
-! ALL-NEXT: Pipeline Collection : ['fir.global', 'func.func', 'gpu.module', 'omp.declare_reduction', 'omp.private']
+! ALL-NEXT: Pipeline Collection : ['fir.global', 'func.func', 'gpu.module', 'omp.declare_mapper', 'omp.declare_reduction', 'omp.private']
! ALL-NEXT: 'fir.global' Pipeline
! ALL-NEXT: AbstractResultOpt
! ALL-NEXT: 'func.func' Pipeline
@@ -114,6 +121,8 @@
! ALL-NEXT: AbstractResultOpt
! ALL-NEXT: 'gpu.func' Pipeline
! ALL-NEXT: AbstractResultOpt
+! ALL-NEXT: 'omp.declare_mapper' Pipeline
+! ALL-NEXT: AbstractResultOpt
! ALL-NEXT: 'omp.declare_reduction' Pipeline
! ALL-NEXT: AbstractResultOpt
! ALL-NEXT: 'omp.private' Pipeline
diff --git a/flang/test/Driver/mlir-pass-pipeline.f90 b/flang/test/Driver/mlir-pass-pipeline.f90
index 0d68191fedc1e..630076a7947ff 100644
--- a/flang/test/Driver/mlir-pass-pipeline.f90
+++ b/flang/test/Driver/mlir-pass-pipeline.f90
@@ -15,23 +15,28 @@
! ALL: Pass statistics report
! ALL: Fortran::lower::VerifierPass
-! O2-NEXT: Pipeline Collection : ['fir.global', 'func.func', 'omp.declare_reduction', 'omp.private']
+! O2-NEXT: Pipeline Collection : ['fir.global', 'func.func', 'omp.declare_mapper', 'omp.declare_reduction', 'omp.private']
! O2-NEXT: 'fir.global' Pipeline
! O2-NEXT: ExpressionSimplification
! O2-NEXT: 'func.func' Pipeline
! O2-NEXT: ExpressionSimplification
+! O2-NEXT: 'omp.declare_mapper' Pipeline
+! O2-NEXT: ExpressionSimplification
! O2-NEXT: 'omp.declare_reduction' Pipeline
! O2-NEXT: ExpressionSimplification
! O2-NEXT: 'omp.private' Pipeline
! O2-NEXT: ExpressionSimplification
! O2-NEXT: Canonicalizer
-! ALL: Pipeline Collection : ['fir.global', 'func.func', 'omp.declare_reduction', 'omp.private']
+! ALL: Pipeline Collection : ['fir.global', 'func.func', 'omp.declare_mapper', 'omp.declare_reduction', 'omp.private']
! ALL-NEXT:'fir.global' Pipeline
! O2-NEXT: SimplifyHLFIRIntrinsics
! ALL: InlineElementals
! ALL-NEXT:'func.func' Pipeline
! O2-NEXT: SimplifyHLFIRIntrinsics
! ALL: InlineElementals
+! ALL-NEXT:'omp.declare_mapper' Pipeline
+! O2-NEXT: SimplifyHLFIRIntrinsics
+! ALL: InlineElementals
! ALL-NEXT:'omp.declare_reduction' Pipeline
! O2-NEXT: SimplifyHLFIRIntrinsics
! ALL: InlineElementals
@@ -42,7 +47,7 @@
! O2-NEXT: CSE
! O2-NEXT: (S) {{.*}} num-cse'd
! O2-NEXT: (S) {{.*}} num-dce'd
-! O2-NEXT: Pipeline Collection : ['fir.global', 'func.func', 'omp.declare_reduction', 'omp.private']
+! O2-NEXT: Pipeline Collection : ['fir.global', 'func.func', 'omp.declare_mapper', 'omp.declare_reduction', 'omp.private']
! O2-NEXT: 'fir.global' Pipeline
! O2-NEXT: SimplifyHLFIRIntrinsics
! O2-NEXT: PropagateFortranVariableAttributes
@@ -53,6 +58,11 @@
! O2-NEXT: PropagateFortranVariableAttributes
! O2-NEXT: OptimizedBufferization
! O2-NEXT: InlineHLFIRAssign
+! O2-NEXT: 'omp.declare_mapper' Pipeline
+! O2-NEXT: SimplifyHLFIRIntrinsics
+! O2-NEXT: PropagateFortranVariableAttributes
+! O2-NEXT: OptimizedBufferization
+! O2-NEXT: InlineHLFIRAssign
! O2-NEXT: 'omp.declare_reduction' Pipeline
! O2-NEXT: SimplifyHLFIRIntrinsics
! O2-NEXT: PropagateFortranVariableAttributes
@@ -66,11 +76,13 @@
! ALL: LowerHLFIROrderedAssignments
! ALL-NEXT: LowerHLFIRIntrinsics
! ALL-NEXT: BufferizeHLFIR
-! O2-NEXT: Pipeline Collection : ['fir.global', 'func.func', 'omp.declare_reduction', 'omp.private']
+! O2-NEXT: Pipeline Collection : ['fir.global', 'func.func', 'omp.declare_mapper', 'omp.declare_reduction', 'omp.private']
! O2-NEXT: 'fir.global' Pipeline
! O2-NEXT: InlineHLFIRAssign
! O2-NEXT: 'func.func' Pipeline
! O2-NEXT: InlineHLFIRAssign
+! O2-NEXT: 'omp.declare_mapper' Pipeline
+! O2-NEXT: InlineHLFIRAssign
! O2-NEXT: 'omp.declare_reduction' Pipeline
! O2-NEXT: InlineHLFIRAssign
! O2-NEXT: 'omp.private' Pipeline
@@ -84,12 +96,14 @@
! ALL-NEXT: (S) 0 num-cse'd - Number of operations CSE'd
! ALL-NEXT: (S) 0 num-dce'd - Number of operations DCE'd
-! ALL-NEXT: Pipeline Collection : ['fir.global', 'func.func', 'omp.declare_reduction', 'omp.private']
+! ALL-NEXT: Pipeline Collection : ['fir.global', 'func.func', 'omp.declare_mapper', 'omp.declare_reduction', 'omp.private']
! ALL-NEXT: 'fir.global' Pipeline
! ALL-NEXT: CharacterConversion
! ALL-NEXT: 'func.func' Pipeline
! ALL-NEXT: ArrayValueCopy
! ALL-NEXT: CharacterConversion
+! ALL-NEXT: 'omp.declare_mapper' Pipeline
+! ALL-NEXT: CharacterConversion
! ALL-NEXT: 'omp.declare_reduction' Pipeline
! ALL-NEXT: CharacterConversion
! ALL-NEXT: 'omp.private' Pipeline
@@ -119,13 +133,16 @@
! ALL-NEXT: LowerRepackArraysPass
! ALL-NEXT: SimplifyFIROperations
-! ALL-NEXT: Pipeline Collection : ['fir.global', 'func.func', 'omp.declare_reduction', 'omp.private']
+! ALL-NEXT: Pipeline Collection : ['fir.global', 'func.func', 'omp.declare_mapper', 'omp.declare_reduction', 'omp.private']
! ALL-NEXT: 'fir.global' Pipeline
! ALL-NEXT: StackReclaim
! ALL-NEXT: CFGConversion
! ALL-NEXT: 'func.func' Pipeline
! ALL-NEXT: StackReclaim
! ALL-NEXT: CFGConversion
+! ALL-NEXT: 'omp.declare_mapper' Pipeline
+! ALL-NEXT: StackReclaim
+! ALL-NEXT: CFGConversion
! ALL-NEXT: 'omp.declare_reduction' Pipeline
! ALL-NEXT: StackReclaim
! ALL-NEXT: CFGConversion
@@ -146,7 +163,7 @@
! ALL-NEXT: BoxedProcedurePass
! O2-NEXT: AddAliasTags
-! ALL-NEXT: Pipeline Collection : ['fir.global', 'func.func', 'gpu.module', 'omp.declare_reduction', 'omp.private']
+! ALL-NEXT: Pipeline Collection : ['fir.global', 'func.func', 'gpu.module', 'omp.declare_mapper', 'omp.declare_reduction', 'omp.private']
! ALL-NEXT: 'fir.global' Pipeline
! ALL-NEXT: AbstractResultOpt
! ALL-NEXT: 'func.func' Pipeline
@@ -157,6 +174,8 @@
! ALL-NEXT: AbstractResultOpt
! ALL-NEXT: 'gpu.func' Pipeline
! ALL-NEXT: AbstractResultOpt
+! ALL-NEXT: 'omp.declare_mapper' Pipeline
+! ALL-NEXT: AbstractResultOpt
! ALL-NEXT: 'omp.declare_reduction' Pipeline
! ALL-NEXT: AbstractResultOpt
! ALL-NEXT: 'omp.private' Pipeline
diff --git a/flang/test/Fir/basic-program.fir b/flang/test/Fir/basic-program.fir
index 6d2beae4da1c8..5f84395b36037 100644
--- a/flang/test/Fir/basic-program.fir
+++ b/flang/test/Fir/basic-program.fir
@@ -17,13 +17,16 @@ func.func @_QQmain() {
// PASSES: Pass statistics report
// PASSES: Canonicalizer
-// PASSES-NEXT: Pipeline Collection : ['fir.global', 'func.func', 'omp.declare_reduction', 'omp.private']
+// PASSES-NEXT: Pipeline Collection : ['fir.global', 'func.func', 'omp.declare_mapper', 'omp.declare_reduction', 'omp.private']
// PASSES-NEXT: 'fir.global' Pipeline
// PASSES-NEXT: SimplifyHLFIRIntrinsics
// PASSES-NEXT: InlineElementals
// PASSES-NEXT: 'func.func' Pipeline
// PASSES-NEXT: SimplifyHLFIRIntrinsics
// PASSES-NEXT: InlineElementals
+// PASSES-NEXT: 'omp.declare_mapper' Pipeline
+// PASSES-NEXT: SimplifyHLFIRIntrinsics
+// PASSES-NEXT: InlineElementals
// PASSES-NEXT: 'omp.declare_reduction' Pipeline
// PASSES-NEXT: SimplifyHLFIRIntrinsics
// PASSES-NEXT: InlineElementals
@@ -34,7 +37,7 @@ func.func @_QQmain() {
// PASSES-NEXT: CSE
// PASSES-NEXT: (S) 0 num-cse'd - Number of operations CSE'd
// PASSES-NEXT: (S) 0 num-dce'd - Number of operations DCE'd
-// PASSES-NEXT: Pipeline Collection : ['fir.global', 'func.func', 'omp.declare_reduction', 'omp.private']
+// PASSES-NEXT: Pipeline Collection : ['fir.global', 'func.func', 'omp.declare_mapper', 'omp.declare_reduction', 'omp.private']
// PASSES-NEXT: 'fir.global' Pipeline
// PASSES-NEXT: SimplifyHLFIRIntrinsics
// PASSES-NEXT: PropagateFortranVariableAttributes
@@ -45,6 +48,11 @@ func.func @_QQmain() {
// PASSES-NEXT: PropagateFortranVariableAttributes
// PASSES-NEXT: OptimizedBufferization
// PASSES-NEXT: InlineHLFIRAssign
+// PASSES-NEXT: 'omp.declare_mapper' Pipeline
+// PASSES-NEXT: SimplifyHLFIRIntrinsics
+// PASSES-NEXT: PropagateFortranVariableAttributes
+// PASSES-NEXT: OptimizedBufferization
+// PASSES-NEXT: InlineHLFIRAssign
// PASSES-NEXT: 'omp.declare_reduction' Pipeline
// PASSES-NEXT: SimplifyHLFIRIntrinsics
// PASSES-NEXT: PropagateFortranVariableAttributes
@@ -58,11 +66,13 @@ func.func @_QQmain() {
// PASSES-NEXT: LowerHLFIROrderedAssignments
// PASSES-NEXT: LowerHLFIRIntrinsics
// PASSES-NEXT: BufferizeHLFIR
-// PASSES-NEXT: Pipeline Collection : ['fir.global', 'func.func', 'omp.declare_reduction', 'omp.private']
+// PASSES-NEXT: Pipeline Collection : ['fir.global', 'func.func', 'omp.declare_mapper', 'omp.declare_reduction', 'omp.private']
// PASSES-NEXT: 'fir.global' Pipeline
// PASSES-NEXT: InlineHLFIRAssign
// PASSES-NEXT: 'func.func' Pipeline
// PASSES-NEXT: InlineHLFIRAssign
+// PASSES-NEXT: 'omp.declare_mapper' Pipeline
+// PASSES-NEXT: InlineHLFIRAssign
// PASSES-NEXT: 'omp.declare_reduction' Pipeline
// PASSES-NEXT: InlineHLFIRAssign
// PASSES-NEXT: 'omp.private' Pipeline
@@ -74,12 +84,14 @@ func.func @_QQmain() {
// PASSES-NEXT: (S) 0 num-cse'd - Number of operations CSE'd
// PASSES-NEXT: (S) 0 num-dce'd - Number of operations DCE'd
-// PASSES-NEXT: Pipeline Collection : ['fir.global', 'func.func', 'omp.declare_reduction', 'omp.private']
+// PASSES-NEXT: Pipeline Collection : ['fir.global', 'func.func', 'omp.declare_mapper', 'omp.declare_reduction', 'omp.private']
// PASSES-NEXT: 'fir.global' Pipeline
// PASSES-NEXT: CharacterConversion
// PASSES-NEXT: 'func.func' Pipeline
// PASSES-NEXT: ArrayValueCopy
// PASSES-NEXT: CharacterConversion
+// PASSES-NEXT: 'omp.declare_mapper' Pipeline
+// PASSES-NEXT: CharacterConversion
// PASSES-NEXT: 'omp.declare_reduction' Pipeline
// PASSES-NEXT: CharacterConversion
// PASSES-NEXT: 'omp.private' Pipeline
@@ -109,13 +121,16 @@ func.func @_QQmain() {
// PASSES-NEXT: LowerRepackArraysPass
// PASSES-NEXT: SimplifyFIROperations
-// PASSES-NEXT: Pipeline Collection : ['fir.global', 'func.func', 'omp.declare_reduction', 'omp.private']
+// PASSES-NEXT: Pipeline Collection : ['fir.global', 'func.func', 'omp.declare_mapper', 'omp.declare_reduction', 'omp.private']
// PASSES-NEXT: 'fir.global' Pipeline
// PASSES-NEXT: StackReclaim
// PASSES-NEXT: CFGConversion
// PASSES-NEXT: 'func.func' Pipeline
// PASSES-NEXT: StackReclaim
// PASSES-NEXT: CFGConversion
+// PASSES-NEXT: 'omp.declare_mapper' Pipeline
+// PASSES-NEXT: StackReclaim
+// PASSES-NEXT: CFGConversion
// PASSES-NEXT: 'omp.declare_reduction' Pipeline
// PASSES-NEXT: StackReclaim
// PASSES-NEXT: CFGConversion
@@ -136,17 +151,19 @@ func.func @_QQmain() {
// PASSES-NEXT: BoxedProcedurePass
// PASSES-NEXT: AddAliasTags
-// PASSES-NEXT: Pipeline Collection : ['fir.global', 'func.func', 'gpu.module', 'omp.declare_reduction', 'omp.private']
+// PASSES-NEXT: Pipeline Collection : ['fir.global', 'func.func', 'gpu.module', 'omp.declare_mapper', 'omp.declare_reduction', 'omp.private']
// PASSES-NEXT: 'fir.global' Pipeline
// PASSES-NEXT: AbstractResultOpt
// PASSES-NEXT: 'func.func' Pipeline
// PASSES-NEXT: AbstractResultOpt
// PASSES-NEXT: 'gpu.module' Pipeline
-// PASSES-NEXT: Pipeline Collection : ['func.func', 'gpu.func']
-// PASSES-NEXT: 'func.func' Pipeline
+// PASSES-NEXT: Pipeline Collection : ['func.func', 'gpu.func']
+// PASSES-NEXT: 'func.func' Pipeline
// PASSES-NEXT: AbstractResultOpt
-// PASSES-NEXT: 'gpu.func' Pipeline
+// PASSES-NEXT: 'gpu.func' Pipeline
// PASSES-NEXT: AbstractResultOpt
+// PASSES-NEXT: 'omp.declare_mapper' Pipeline
+// PASSES-NEXT: AbstractResultOpt
// PASSES-NEXT: 'omp.declare_reduction' Pipeline
// PASSES-NEXT: AbstractResultOpt
// PASSES-NEXT: 'omp.private' Pipeline
diff --git a/flang/test/Transforms/OpenMP/conversion-declare-mapper.mlir b/flang/test/Transforms/OpenMP/conversion-declare-mapper.mlir
new file mode 100644
index 0000000000000..a5078a9600cf6
--- /dev/null
+++ b/flang/test/Transforms/OpenMP/conversion-declare-mapper.mlir
@@ -0,0 +1,19 @@
+// Tests that LLVM conversion for declare mapper types is applied to
+// `omp.declare_mapper` ops and correctly converts the declare mapper
+// type when it's a box.
+
+// RUN: fir-opt --convert-hlfir-to-fir --cg-rewrite --fir-to-llvm-ir %s -o - | \
+// RUN: FileCheck %s
+
+module {
+ omp.declare_mapper @_QQFdeclare_mapper_1my_type_omp_default_mapper : !fir.box<!fir.heap<!fir.array<?xi32>>> {
+ ^bb0(%arg0: !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>):
+ %0 = fir.box_offset %arg0 base_addr : (!fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>) -> !fir.llvm_ptr<!fir.ref<!fir.array<?xi32>>>
+ %1 = omp.map.info var_ptr(%arg0 : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>, i32) map_clauses(tofrom) capture(ByRef) var_ptr_ptr(%0 : !fir.llvm_ptr<!fir.ref<!fir.array<?xi32>>>) -> !fir.llvm_ptr<!fir.ref<!fir.array<?xi32>>> {name = ""}
+ %2 = omp.map.info var_ptr(%arg0 : !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>, !fir.box<!fir.heap<!fir.array<?xi32>>>) map_clauses(always, to) capture(ByRef) -> !fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>> {name = "var%values(1:var%num_vals)"}
+ omp.declare_mapper.info map_entries(%2, %1 :!fir.ref<!fir.box<!fir.heap<!fir.array<?xi32>>>>, !fir.llvm_ptr<!fir.ref<!fir.array<?xi32>>>)
+ }
+}
+
+// CHECK: omp.declare_mapper @_QQFdeclare_mapper_1my_type_omp_default_mapper : !llvm.struct<(ptr, i64, i32, i8, i8, i8, i8, array<1 x array<3 x i64>>)> {
+// CHECK: ^bb0(%arg0: !llvm.ptr):
``````````
</details>
https://github.com/llvm/llvm-project/pull/176852
More information about the flang-commits
mailing list