Skip to content

Commit 1f1e094

Browse files
[flang] run CFG conversion on omp reduction declare ops (#84953)
Most FIR passes only look for FIR operations inside of functions (either because they run only on func.func or they run on the module but iterate over functions internally). But there can also be FIR operations inside of fir.global, some OpenMP and OpenACC container operations. This has worked so far for fir.global and OpenMP reductions because they only contained very simple FIR code which doesn't need most passes to be lowered into LLVM IR. I am not sure how OpenACC works. In the long run, I hope to see a more systematic approach to making sure that every pass runs on all of these container operations. I will write an RFC for this soon. In the meantime, this pass duplicates the CFG conversion pass to also run on omp reduction operations. This is similar to how the AbstractResult pass is already duplicated for fir.global operations. OpenMP array reductions 2/6 Previous PR: #84952 Next PR: #84954 --------- Co-authored-by: Mats Petersson <[email protected]>
1 parent d032638 commit 1f1e094

File tree

16 files changed

+143
-38
lines changed

16 files changed

+143
-38
lines changed

flang/include/flang/Optimizer/Transforms/Passes.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "flang/Optimizer/Dialect/FIROps.h"
1313
#include "mlir/Dialect/LLVMIR/LLVMAttrs.h"
14+
#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
1415
#include "mlir/Pass/Pass.h"
1516
#include "mlir/Pass/PassRegistry.h"
1617
#include <memory>
@@ -37,7 +38,8 @@ namespace fir {
3738
#define GEN_PASS_DECL_ANNOTATECONSTANTOPERANDS
3839
#define GEN_PASS_DECL_ARRAYVALUECOPY
3940
#define GEN_PASS_DECL_CHARACTERCONVERSION
40-
#define GEN_PASS_DECL_CFGCONVERSION
41+
#define GEN_PASS_DECL_CFGCONVERSIONONFUNC
42+
#define GEN_PASS_DECL_CFGCONVERSIONONREDUCTION
4143
#define GEN_PASS_DECL_EXTERNALNAMECONVERSION
4244
#define GEN_PASS_DECL_MEMREFDATAFLOWOPT
4345
#define GEN_PASS_DECL_SIMPLIFYINTRINSICS
@@ -53,7 +55,8 @@ std::unique_ptr<mlir::Pass> createAbstractResultOnGlobalOptPass();
5355
std::unique_ptr<mlir::Pass> createAffineDemotionPass();
5456
std::unique_ptr<mlir::Pass>
5557
createArrayValueCopyPass(fir::ArrayValueCopyOptions options = {});
56-
std::unique_ptr<mlir::Pass> createFirToCfgPass();
58+
std::unique_ptr<mlir::Pass> createFirToCfgOnFuncPass();
59+
std::unique_ptr<mlir::Pass> createFirToCfgOnReductionPass();
5760
std::unique_ptr<mlir::Pass> createCharacterConversionPass();
5861
std::unique_ptr<mlir::Pass> createExternalNameConversionPass();
5962
std::unique_ptr<mlir::Pass>
@@ -96,6 +99,9 @@ createFunctionAttrPass(FunctionAttrTypes &functionAttr, bool noInfsFPMath,
9699
bool noNaNsFPMath, bool approxFuncFPMath,
97100
bool noSignedZerosFPMath, bool unsafeFPMath);
98101

102+
void populateCfgConversionRewrites(mlir::RewritePatternSet &patterns,
103+
bool forceLoopToExecuteOnce = false);
104+
99105
// declarative passes
100106
#define GEN_PASS_REGISTRATION
101107
#include "flang/Optimizer/Transforms/Passes.h.inc"

flang/include/flang/Optimizer/Transforms/Passes.td

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ def CharacterConversion : Pass<"character-conversion"> {
145145
];
146146
}
147147

148-
def CFGConversion : Pass<"cfg-conversion", "::mlir::func::FuncOp"> {
148+
class CFGConversionBase<string optExt, string operation>
149+
: Pass<"cfg-conversion-on-" # optExt # "-opt", operation> {
149150
let summary = "Convert FIR structured control flow ops to CFG ops.";
150151
let description = [{
151152
Transform the `fir.do_loop`, `fir.if`, `fir.iterate_while` and
@@ -154,7 +155,6 @@ def CFGConversion : Pass<"cfg-conversion", "::mlir::func::FuncOp"> {
154155

155156
This pass is required before code gen to the LLVM IR dialect.
156157
}];
157-
let constructor = "::fir::createFirToCfgPass()";
158158
let dependentDialects = [
159159
"fir::FIROpsDialect", "mlir::func::FuncDialect"
160160
];
@@ -165,6 +165,14 @@ def CFGConversion : Pass<"cfg-conversion", "::mlir::func::FuncOp"> {
165165
];
166166
}
167167

168+
def CFGConversionOnFunc : CFGConversionBase<"func", "mlir::func::FuncOp"> {
169+
let constructor = "::fir::createFirToCfgOnFuncPass()";
170+
}
171+
172+
def CFGConversionOnReduction : CFGConversionBase<"reduce", "mlir::omp::ReductionDeclareOp"> {
173+
let constructor = "::fir::createFirToCfgOnReductionPass()";
174+
}
175+
168176
def ExternalNameConversion : Pass<"external-name-interop", "mlir::ModuleOp"> {
169177
let summary = "Convert name for external interoperability";
170178
let description = [{

flang/include/flang/Tools/CLOptions.inc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ static void addCanonicalizerPassWithoutRegionSimplification(
123123

124124
inline void addCfgConversionPass(mlir::PassManager &pm) {
125125
addNestedPassConditionally<mlir::func::FuncOp>(
126-
pm, disableCfgConversion, fir::createFirToCfgPass);
126+
pm, disableCfgConversion, fir::createFirToCfgOnFuncPass);
127+
addNestedPassConditionally<mlir::omp::ReductionDeclareOp>(
128+
pm, disableCfgConversion, fir::createFirToCfgOnReductionPass);
127129
}
128130

129131
inline void addAVC(

flang/lib/Optimizer/Transforms/ControlFlowConverter.cpp

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
#include "llvm/Support/CommandLine.h"
2525

2626
namespace fir {
27-
#define GEN_PASS_DEF_CFGCONVERSION
27+
#define GEN_PASS_DEF_CFGCONVERSIONONFUNC
28+
#define GEN_PASS_DEF_CFGCONVERSIONONREDUCTION
2829
#include "flang/Optimizer/Transforms/Passes.h.inc"
2930
} // namespace fir
3031

@@ -308,13 +309,13 @@ class CfgIterWhileConv : public mlir::OpRewritePattern<fir::IterWhileOp> {
308309
};
309310

310311
/// Convert FIR structured control flow ops to CFG ops.
311-
class CfgConversion : public fir::impl::CFGConversionBase<CfgConversion> {
312+
template <typename Pass, template <typename> class PassBase>
313+
class CfgConversionTemplate : public PassBase<Pass> {
312314
public:
313315
void runOnOperation() override {
314-
auto *context = &getContext();
316+
auto *context = &this->getContext();
315317
mlir::RewritePatternSet patterns(context);
316-
patterns.insert<CfgLoopConv, CfgIfConv, CfgIterWhileConv>(
317-
context, forceLoopToExecuteOnce);
318+
fir::populateCfgConversionRewrites(patterns, this->forceLoopToExecuteOnce);
318319
mlir::ConversionTarget target(*context);
319320
target.addLegalDialect<mlir::affine::AffineDialect,
320321
mlir::cf::ControlFlowDialect, FIROpsDialect,
@@ -323,19 +324,38 @@ class CfgConversion : public fir::impl::CFGConversionBase<CfgConversion> {
323324
// apply the patterns
324325
target.addIllegalOp<ResultOp, DoLoopOp, IfOp, IterWhileOp>();
325326
target.markUnknownOpDynamicallyLegal([](Operation *) { return true; });
326-
if (mlir::failed(mlir::applyPartialConversion(getOperation(), target,
327+
if (mlir::failed(mlir::applyPartialConversion(this->getOperation(), target,
327328
std::move(patterns)))) {
328329
mlir::emitError(mlir::UnknownLoc::get(context),
329330
"error in converting to CFG\n");
330-
signalPassFailure();
331+
this->signalPassFailure();
331332
}
332333
}
333334
};
335+
336+
class CfgConversionOnFunc
337+
: public CfgConversionTemplate<CfgConversionOnFunc,
338+
::fir::impl::CFGConversionOnFuncBase> {};
339+
340+
class CfgConversionOnReduction
341+
: public CfgConversionTemplate<CfgConversionOnReduction,
342+
::fir::impl::CFGConversionOnReductionBase> {
343+
};
334344
} // namespace
335345

346+
/// Expose conversion rewriters to other passes
347+
void fir::populateCfgConversionRewrites(mlir::RewritePatternSet &patterns,
348+
bool forceLoopToExecuteOnce) {
349+
patterns.insert<CfgLoopConv, CfgIfConv, CfgIterWhileConv>(
350+
patterns.getContext(), forceLoopToExecuteOnce);
351+
}
352+
336353
/// Convert FIR's structured control flow ops to CFG ops. This
337354
/// conversion enables the `createLowerToCFGPass` to transform these to CFG
338355
/// form.
339-
std::unique_ptr<mlir::Pass> fir::createFirToCfgPass() {
340-
return std::make_unique<CfgConversion>();
356+
std::unique_ptr<mlir::Pass> fir::createFirToCfgOnFuncPass() {
357+
return std::make_unique<CfgConversionOnFunc>();
358+
}
359+
std::unique_ptr<mlir::Pass> fir::createFirToCfgOnReductionPass() {
360+
return std::make_unique<CfgConversionOnReduction>();
341361
}

flang/test/Driver/bbc-mlir-pass-pipeline.f90

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,12 @@
3838
! CHECK-NEXT: (S) 0 num-cse'd - Number of operations CSE'd
3939
! CHECK-NEXT: (S) 0 num-dce'd - Number of operations DCE'd
4040

41+
! CHECK-NEXT: Pipeline Collection : ['func.func', 'omp.reduction.declare']
4142
! CHECK-NEXT: 'func.func' Pipeline
4243
! CHECK-NEXT: PolymorphicOpConversion
43-
! CHECK-NEXT: CFGConversion
44+
! CHECK-NEXT: CFGConversionOnFunc
45+
! CHECK-NEXT: 'omp.reduction.declare' Pipeline
46+
! CHECK-NEXT: CFGConversionOnReduction
4447

4548
! CHECK-NEXT: SCFToControlFlow
4649
! CHECK-NEXT: Canonicalizer

flang/test/Driver/mlir-debug-pass-pipeline.f90

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,12 @@
5858
! ALL-NEXT: (S) 0 num-cse'd - Number of operations CSE'd
5959
! ALL-NEXT: (S) 0 num-dce'd - Number of operations DCE'd
6060

61-
! ALL-NEXT: 'func.func' Pipeline
62-
! ALL-NEXT: PolymorphicOpConversion
63-
! ALL-NEXT: CFGConversion
64-
61+
! ALL-NEXT: Pipeline Collection : ['func.func', 'omp.reduction.declare']
62+
! ALL-NEXT: 'func.func' Pipeline
63+
! ALL-NEXT: PolymorphicOpConversion
64+
! ALL-NEXT: CFGConversionOnFunc
65+
! ALL-NEXT: 'omp.reduction.declare' Pipeline
66+
! ALL-NEXT: CFGConversionOnReduction
6567
! ALL-NEXT: SCFToControlFlow
6668
! ALL-NEXT: Canonicalizer
6769
! ALL-NEXT: SimplifyRegionLite
@@ -72,9 +74,9 @@
7274

7375
! ALL-NEXT: Pipeline Collection : ['fir.global', 'func.func']
7476
! ALL-NEXT: 'fir.global' Pipeline
75-
! ALL-NEXT: AbstractResultOnGlobalOpt
76-
! ALL-NEXT: 'func.func' Pipeline
77-
! ALL-NEXT: AbstractResultOnFuncOpt
77+
! ALL-NEXT: AbstractResultOnGlobalOpt
78+
! ALL-NEXT: 'func.func' Pipeline
79+
! ALL-NEXT: AbstractResultOnFuncOpt
7880

7981
! ALL-NEXT: CodeGenRewrite
8082
! ALL-NEXT: (S) 0 num-dce'd - Number of operations eliminated

flang/test/Driver/mlir-pass-pipeline.f90

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
! Test the MLIR pass pipeline
22

3-
! RUN: %flang_fc1 -S -mmlir --mlir-pass-statistics -mmlir --mlir-pass-statistics-display=pipeline -o /dev/null %s 2>&1 | FileCheck --check-prefixes=ALL %s
3+
! RUN: %flang_fc1 -S -mmlir --mlir-pass-statistics -mmlir --mlir-pass-statistics-display=pipeline -o /dev/null %s 2>&1 | FileCheck --check-prefixes=ALL,NOTO2 %s
44
! -O0 is the default:
5-
! RUN: %flang_fc1 -S -mmlir --mlir-pass-statistics -mmlir --mlir-pass-statistics-display=pipeline %s -O0 -o /dev/null 2>&1 | FileCheck --check-prefixes=ALL %s
5+
! RUN: %flang_fc1 -S -mmlir --mlir-pass-statistics -mmlir --mlir-pass-statistics-display=pipeline %s -O0 -o /dev/null 2>&1 | FileCheck --check-prefixes=ALL,NOTO2 %s
66
! RUN: %flang_fc1 -S -mmlir --mlir-pass-statistics -mmlir --mlir-pass-statistics-display=pipeline %s -O2 -o /dev/null 2>&1 | FileCheck --check-prefixes=ALL,O2 %s
77

88
! REQUIRES: asserts
@@ -49,11 +49,15 @@
4949
! ALL-NEXT: (S) 0 num-cse'd - Number of operations CSE'd
5050
! ALL-NEXT: (S) 0 num-dce'd - Number of operations DCE'd
5151

52-
! ALL-NEXT: 'func.func' Pipeline
53-
! ALL-NEXT: PolymorphicOpConversion
52+
! O2-NEXT: 'func.func' Pipeline
53+
! O2-NEXT: PolymorphicOpConversion
5454
! O2-NEXT: AddAliasTags
55-
! O2-NEXT: 'func.func' Pipeline
56-
! ALL-NEXT: CFGConversion
55+
! ALL-NEXT: Pipeline Collection : ['func.func', 'omp.reduction.declare']
56+
! ALL-NEXT: 'func.func' Pipeline
57+
! NOTO2-NEXT: PolymorphicOpConversion
58+
! ALL-NEXT: CFGConversionOnFunc
59+
! ALL-NEXT: 'omp.reduction.declare' Pipeline
60+
! ALL-NEXT: CFGConversionOnReduction
5761

5862
! ALL-NEXT: SCFToControlFlow
5963
! ALL-NEXT: Canonicalizer

flang/test/Fir/array-value-copy-2.fir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: fir-opt --array-value-copy --cfg-conversion %s | FileCheck %s
2-
// RUN: fir-opt --array-value-copy="optimize-conflicts=true" --cfg-conversion %s | FileCheck %s
1+
// RUN: fir-opt --array-value-copy --cfg-conversion-on-func-opt %s | FileCheck %s
2+
// RUN: fir-opt --array-value-copy="optimize-conflicts=true" --cfg-conversion-on-func-opt %s | FileCheck %s
33

44
// CHECK-LABEL: func @_QPslice1(
55
// CHECK-NOT: fir.allocmem

flang/test/Fir/basic-program.fir

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,11 @@ func.func @_QQmain() {
6060

6161
// PASSES-NEXT: AddAliasTags
6262

63+
// PASSES-NEXT: Pipeline Collection : ['func.func', 'omp.reduction.declare']
6364
// PASSES-NEXT: 'func.func' Pipeline
64-
// PASSES-NEXT: CFGConversion
65+
// PASSES-NEXT: CFGConversionOnFunc
66+
// PASSES-NEXT: 'omp.reduction.declare' Pipeline
67+
// PASSES-NEXT: CFGConversionOnReduction
6568

6669
// PASSES-NEXT: SCFToControlFlow
6770
// PASSES-NEXT: Canonicalizer

flang/test/Fir/convert-to-llvm-openmp-and-fir.fir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: fir-opt --split-input-file --cfg-conversion --fir-to-llvm-ir="target=aarch64-unknown-linux-gnu" %s | FileCheck %s
1+
// RUN: fir-opt --split-input-file --cfg-conversion-on-func-opt --fir-to-llvm-ir="target=aarch64-unknown-linux-gnu" %s | FileCheck %s
22

33
func.func @_QPsb1(%arg0: !fir.ref<i32> {fir.bindc_name = "n"}, %arg1: !fir.ref<!fir.array<?xi32>> {fir.bindc_name = "arr"}) {
44
%c1_i64 = arith.constant 1 : i64

flang/test/Fir/loop01.fir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: fir-opt --split-input-file --cfg-conversion %s | FileCheck %s
1+
// RUN: fir-opt --split-input-file --cfg-conversion-on-func-opt %s | FileCheck %s
22

33
func.func @x(%lb : index, %ub : index, %step : index, %b : i1, %addr : !fir.ref<index>) {
44
fir.do_loop %iv = %lb to %ub step %step unordered {

flang/test/Fir/loop02.fir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: fir-opt --cfg-conversion="always-execute-loop-body=true" %s | FileCheck %s
2-
// RUN: fir-opt --cfg-conversion %s | FileCheck %s --check-prefix=NOOPT
1+
// RUN: fir-opt --cfg-conversion-on-func-opt="always-execute-loop-body=true" %s | FileCheck %s
2+
// RUN: fir-opt --cfg-conversion-on-func-opt %s | FileCheck %s --check-prefix=NOOPT
33

44
func.func @x(%addr : !fir.ref<index>) {
55
%bound = arith.constant 452 : index

flang/test/Lower/OpenMP/FIR/flush.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
! This test checks lowering of OpenMP Flush Directive.
22

33
!RUN: %flang_fc1 -emit-fir -flang-deprecated-no-hlfir -fopenmp %s -o - | FileCheck %s --check-prefixes="FIRDialect,OMPDialect"
4-
!RUN: %flang_fc1 -emit-fir -flang-deprecated-no-hlfir -fopenmp %s -o - | fir-opt --cfg-conversion | fir-opt --fir-to-llvm-ir | FileCheck %s --check-prefixes="LLVMIRDialect,OMPDialect"
4+
!RUN: %flang_fc1 -emit-fir -flang-deprecated-no-hlfir -fopenmp %s -o - | fir-opt --cfg-conversion-on-func-opt | fir-opt --fir-to-llvm-ir | FileCheck %s --check-prefixes="LLVMIRDialect,OMPDialect"
55

66
subroutine flush_standalone(a, b, c)
77
integer, intent(inout) :: a, b, c

flang/test/Lower/OpenMP/FIR/master.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
!RUN: %flang_fc1 -emit-fir -flang-deprecated-no-hlfir -fopenmp %s -o - | FileCheck %s --check-prefixes="FIRDialect,OMPDialect"
2-
!RUN: %flang_fc1 -emit-fir -flang-deprecated-no-hlfir -fopenmp %s -o - | fir-opt --cfg-conversion | fir-opt --fir-to-llvm-ir | FileCheck %s --check-prefixes="OMPDialect"
2+
!RUN: %flang_fc1 -emit-fir -flang-deprecated-no-hlfir -fopenmp %s -o - | fir-opt --cfg-conversion-on-func-opt | fir-opt --fir-to-llvm-ir | FileCheck %s --check-prefixes="OMPDialect"
33

44
!===============================================================================
55
! parallel construct with function call which has master construct internally

flang/test/Lower/OpenMP/FIR/parallel-sections.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
!RUN: %flang_fc1 -emit-fir -flang-deprecated-no-hlfir -fopenmp %s -o - | FileCheck %s --check-prefixes="FIRDialect,OMPDialect"
2-
!RUN: %flang_fc1 -emit-fir -flang-deprecated-no-hlfir -fopenmp %s -o - | fir-opt --cfg-conversion | fir-opt --fir-to-llvm-ir | FileCheck %s --check-prefixes="OMPDialect,LLVMDialect"
2+
!RUN: %flang_fc1 -emit-fir -flang-deprecated-no-hlfir -fopenmp %s -o - | fir-opt --cfg-conversion-on-func-opt | fir-opt --fir-to-llvm-ir | FileCheck %s --check-prefixes="OMPDialect,LLVMDialect"
33

44
!===============================================================================
55
! Parallel sections construct
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// RUN: fir-opt --cfg-conversion-on-reduce-opt %s | FileCheck %s
2+
3+
omp.reduction.declare @add_reduction_i_32_box_3_byref : !fir.ref<!fir.box<!fir.array<3xi32>>> init {
4+
^bb0(%arg0: !fir.ref<!fir.box<!fir.array<3xi32>>>):
5+
%c4_i32 = arith.constant 4 : i32
6+
%c0_i32 = arith.constant 0 : i32
7+
%c3 = arith.constant 3 : index
8+
%0 = fir.alloca !fir.box<!fir.array<3xi32>>
9+
%1 = fir.alloca !fir.array<3xi32> {bindc_name = "omp.reduction.array.init"}
10+
%2 = fir.shape %c3 : (index) -> !fir.shape<1>
11+
%3 = fir.declare %1(%2) {uniq_name = "omp.reduction.array.init"} : (!fir.ref<!fir.array<3xi32>>, !fir.shape<1>) -> !fir.ref<!fir.array<3xi32>>
12+
%4 = fir.embox %3(%2) : (!fir.ref<!fir.array<3xi32>>, !fir.shape<1>) -> !fir.box<!fir.array<3xi32>>
13+
%5 = fir.alloca i32
14+
fir.store %c0_i32 to %5 : !fir.ref<i32>
15+
%6 = fir.embox %5 : (!fir.ref<i32>) -> !fir.box<i32>
16+
fir.store %4 to %0 : !fir.ref<!fir.box<!fir.array<3xi32>>>
17+
%7 = fir.address_of(@_QQclX9a9fdf8c5fd329fbbf2b0c08e2ca9a1e) : !fir.ref<!fir.char<1,40>>
18+
%8 = fir.convert %0 : (!fir.ref<!fir.box<!fir.array<3xi32>>>) -> !fir.ref<!fir.box<none>>
19+
%9 = fir.convert %6 : (!fir.box<i32>) -> !fir.box<none>
20+
%10 = fir.convert %7 : (!fir.ref<!fir.char<1,40>>) -> !fir.ref<i8>
21+
%11 = fir.call @_FortranAAssign(%8, %9, %10, %c4_i32) : (!fir.ref<!fir.box<none>>, !fir.box<none>, !fir.ref<i8>, i32) -> none
22+
%12 = fir.alloca !fir.box<!fir.array<3xi32>>
23+
fir.store %4 to %12 : !fir.ref<!fir.box<!fir.array<3xi32>>>
24+
omp.yield(%12 : !fir.ref<!fir.box<!fir.array<3xi32>>>)
25+
} combiner {
26+
^bb0(%arg0: !fir.ref<!fir.box<!fir.array<3xi32>>>, %arg1: !fir.ref<!fir.box<!fir.array<3xi32>>>):
27+
%c1 = arith.constant 1 : index
28+
%c0 = arith.constant 0 : index
29+
%0 = fir.load %arg0 : !fir.ref<!fir.box<!fir.array<3xi32>>>
30+
%1 = fir.load %arg1 : !fir.ref<!fir.box<!fir.array<3xi32>>>
31+
%2:3 = fir.box_dims %0, %c0 : (!fir.box<!fir.array<3xi32>>, index) -> (index, index, index)
32+
%3 = fir.shape_shift %2#0, %2#1 : (index, index) -> !fir.shapeshift<1>
33+
fir.do_loop %arg2 = %c1 to %2#1 step %c1 unordered {
34+
%4 = fir.array_coor %0(%3) %arg2 : (!fir.box<!fir.array<3xi32>>, !fir.shapeshift<1>, index) -> !fir.ref<i32>
35+
%5 = fir.array_coor %1(%3) %arg2 : (!fir.box<!fir.array<3xi32>>, !fir.shapeshift<1>, index) -> !fir.ref<i32>
36+
%6 = fir.load %4 : !fir.ref<i32>
37+
%7 = fir.load %5 : !fir.ref<i32>
38+
%8 = arith.addi %6, %7 : i32
39+
fir.store %8 to %4 : !fir.ref<i32>
40+
}
41+
omp.yield(%arg0 : !fir.ref<!fir.box<!fir.array<3xi32>>>)
42+
}
43+
44+
// ensure cfg conversion has run on the do loop
45+
// CHECK: combiner {
46+
// CHECK-NOT: fir.do_loop
47+
// CHECK: ^bb0({{.*}}):
48+
// ...
49+
// CHECK: cf.br ^bb1
50+
// CHECK: ^bb1({{.*}}):
51+
// ...
52+
// CHECK: cf.cond_br %{{.*}} ^bb2, ^bb3
53+
// CHECK: ^bb2:
54+
// ...
55+
// CHECK: cf.br ^bb1
56+
// CHECK: ^bb3:
57+

0 commit comments

Comments
 (0)