|
19 | 19 | #include "DirectivesCommon.h"
|
20 | 20 | #include "ReductionProcessor.h"
|
21 | 21 | #include "Utils.h"
|
| 22 | +#include "flang/Common/OpenMP-utils.h" |
22 | 23 | #include "flang/Common/idioms.h"
|
23 | 24 | #include "flang/Lower/Bridge.h"
|
24 | 25 | #include "flang/Lower/ConvertExpr.h"
|
|
41 | 42 | #include "llvm/Frontend/OpenMP/OMPConstants.h"
|
42 | 43 |
|
43 | 44 | using namespace Fortran::lower::omp;
|
| 45 | +using namespace Fortran::common::openmp; |
44 | 46 |
|
45 | 47 | //===----------------------------------------------------------------------===//
|
46 | 48 | // Code generation helper functions
|
47 | 49 | //===----------------------------------------------------------------------===//
|
48 | 50 |
|
49 |
| -namespace { |
50 |
| -/// Structure holding the information needed to create and bind entry block |
51 |
| -/// arguments associated to a single clause. |
52 |
| -struct EntryBlockArgsEntry { |
53 |
| - llvm::ArrayRef<const semantics::Symbol *> syms; |
54 |
| - llvm::ArrayRef<mlir::Value> vars; |
55 |
| - |
56 |
| - bool isValid() const { |
57 |
| - // This check allows specifying a smaller number of symbols than values |
58 |
| - // because in some case cases a single symbol generates multiple block |
59 |
| - // arguments. |
60 |
| - return syms.size() <= vars.size(); |
61 |
| - } |
62 |
| -}; |
63 |
| - |
64 |
| -/// Structure holding the information needed to create and bind entry block |
65 |
| -/// arguments associated to all clauses that can define them. |
66 |
| -struct EntryBlockArgs { |
67 |
| - EntryBlockArgsEntry inReduction; |
68 |
| - EntryBlockArgsEntry map; |
69 |
| - EntryBlockArgsEntry priv; |
70 |
| - EntryBlockArgsEntry reduction; |
71 |
| - EntryBlockArgsEntry taskReduction; |
72 |
| - EntryBlockArgsEntry useDeviceAddr; |
73 |
| - EntryBlockArgsEntry useDevicePtr; |
74 |
| - |
75 |
| - bool isValid() const { |
76 |
| - return inReduction.isValid() && map.isValid() && priv.isValid() && |
77 |
| - reduction.isValid() && taskReduction.isValid() && |
78 |
| - useDeviceAddr.isValid() && useDevicePtr.isValid(); |
79 |
| - } |
80 |
| - |
81 |
| - auto getSyms() const { |
82 |
| - return llvm::concat<const semantics::Symbol *const>( |
83 |
| - inReduction.syms, map.syms, priv.syms, reduction.syms, |
84 |
| - taskReduction.syms, useDeviceAddr.syms, useDevicePtr.syms); |
85 |
| - } |
86 |
| - |
87 |
| - auto getVars() const { |
88 |
| - return llvm::concat<const mlir::Value>( |
89 |
| - inReduction.vars, map.vars, priv.vars, reduction.vars, |
90 |
| - taskReduction.vars, useDeviceAddr.vars, useDevicePtr.vars); |
91 |
| - } |
92 |
| -}; |
93 |
| -} // namespace |
94 |
| - |
95 | 51 | static void genOMPDispatch(lower::AbstractConverter &converter,
|
96 | 52 | lower::SymMap &symTable,
|
97 | 53 | semantics::SemanticsContext &semaCtx,
|
@@ -623,50 +579,6 @@ static void genLoopVars(
|
623 | 579 | firOpBuilder.setInsertionPointAfter(storeOp);
|
624 | 580 | }
|
625 | 581 |
|
626 |
| -/// Create an entry block for the given region, including the clause-defined |
627 |
| -/// arguments specified. |
628 |
| -/// |
629 |
| -/// \param [in] converter - PFT to MLIR conversion interface. |
630 |
| -/// \param [in] args - entry block arguments information for the given |
631 |
| -/// operation. |
632 |
| -/// \param [in] region - Empty region in which to create the entry block. |
633 |
| -static mlir::Block *genEntryBlock(lower::AbstractConverter &converter, |
634 |
| - const EntryBlockArgs &args, |
635 |
| - mlir::Region ®ion) { |
636 |
| - assert(args.isValid() && "invalid args"); |
637 |
| - assert(region.empty() && "non-empty region"); |
638 |
| - fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder(); |
639 |
| - |
640 |
| - llvm::SmallVector<mlir::Type> types; |
641 |
| - llvm::SmallVector<mlir::Location> locs; |
642 |
| - unsigned numVars = args.inReduction.vars.size() + args.map.vars.size() + |
643 |
| - args.priv.vars.size() + args.reduction.vars.size() + |
644 |
| - args.taskReduction.vars.size() + |
645 |
| - args.useDeviceAddr.vars.size() + |
646 |
| - args.useDevicePtr.vars.size(); |
647 |
| - types.reserve(numVars); |
648 |
| - locs.reserve(numVars); |
649 |
| - |
650 |
| - auto extractTypeLoc = [&types, &locs](llvm::ArrayRef<mlir::Value> vals) { |
651 |
| - llvm::transform(vals, std::back_inserter(types), |
652 |
| - [](mlir::Value v) { return v.getType(); }); |
653 |
| - llvm::transform(vals, std::back_inserter(locs), |
654 |
| - [](mlir::Value v) { return v.getLoc(); }); |
655 |
| - }; |
656 |
| - |
657 |
| - // Populate block arguments in clause name alphabetical order to match |
658 |
| - // expected order by the BlockArgOpenMPOpInterface. |
659 |
| - extractTypeLoc(args.inReduction.vars); |
660 |
| - extractTypeLoc(args.map.vars); |
661 |
| - extractTypeLoc(args.priv.vars); |
662 |
| - extractTypeLoc(args.reduction.vars); |
663 |
| - extractTypeLoc(args.taskReduction.vars); |
664 |
| - extractTypeLoc(args.useDeviceAddr.vars); |
665 |
| - extractTypeLoc(args.useDevicePtr.vars); |
666 |
| - |
667 |
| - return firOpBuilder.createBlock(®ion, {}, types, locs); |
668 |
| -} |
669 |
| - |
670 | 582 | static void
|
671 | 583 | markDeclareTarget(mlir::Operation *op, lower::AbstractConverter &converter,
|
672 | 584 | mlir::omp::DeclareTargetCaptureClause captureClause,
|
@@ -919,7 +831,7 @@ static void genBodyOfTargetDataOp(
|
919 | 831 | ConstructQueue::const_iterator item) {
|
920 | 832 | fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder();
|
921 | 833 |
|
922 |
| - genEntryBlock(converter, args, dataOp.getRegion()); |
| 834 | + genEntryBlock(firOpBuilder, args, dataOp.getRegion()); |
923 | 835 | bindEntryBlockArgs(converter, dataOp, args);
|
924 | 836 |
|
925 | 837 | // Insert dummy instruction to remember the insertion position. The
|
@@ -996,7 +908,7 @@ static void genBodyOfTargetOp(
|
996 | 908 | auto argIface = llvm::cast<mlir::omp::BlockArgOpenMPOpInterface>(*targetOp);
|
997 | 909 |
|
998 | 910 | mlir::Region ®ion = targetOp.getRegion();
|
999 |
| - mlir::Block *entryBlock = genEntryBlock(converter, args, region); |
| 911 | + mlir::Block *entryBlock = genEntryBlock(firOpBuilder, args, region); |
1000 | 912 | bindEntryBlockArgs(converter, targetOp, args);
|
1001 | 913 |
|
1002 | 914 | // Check if cloning the bounds introduced any dependency on the outer region.
|
@@ -1122,7 +1034,7 @@ static OpTy genWrapperOp(lower::AbstractConverter &converter,
|
1122 | 1034 | auto op = firOpBuilder.create<OpTy>(loc, clauseOps);
|
1123 | 1035 |
|
1124 | 1036 | // Create entry block with arguments.
|
1125 |
| - genEntryBlock(converter, args, op.getRegion()); |
| 1037 | + genEntryBlock(firOpBuilder, args, op.getRegion()); |
1126 | 1038 |
|
1127 | 1039 | return op;
|
1128 | 1040 | }
|
@@ -1588,7 +1500,7 @@ genParallelOp(lower::AbstractConverter &converter, lower::SymMap &symTable,
|
1588 | 1500 | const EntryBlockArgs &args, DataSharingProcessor *dsp,
|
1589 | 1501 | bool isComposite = false) {
|
1590 | 1502 | auto genRegionEntryCB = [&](mlir::Operation *op) {
|
1591 |
| - genEntryBlock(converter, args, op->getRegion(0)); |
| 1503 | + genEntryBlock(converter.getFirOpBuilder(), args, op->getRegion(0)); |
1592 | 1504 | bindEntryBlockArgs(
|
1593 | 1505 | converter, llvm::cast<mlir::omp::BlockArgOpenMPOpInterface>(op), args);
|
1594 | 1506 | return llvm::to_vector(args.getSyms());
|
@@ -1661,12 +1573,12 @@ genSectionsOp(lower::AbstractConverter &converter, lower::SymMap &symTable,
|
1661 | 1573 | args.reduction.syms = reductionSyms;
|
1662 | 1574 | args.reduction.vars = clauseOps.reductionVars;
|
1663 | 1575 |
|
1664 |
| - genEntryBlock(converter, args, sectionsOp.getRegion()); |
| 1576 | + genEntryBlock(builder, args, sectionsOp.getRegion()); |
1665 | 1577 | mlir::Operation *terminator =
|
1666 | 1578 | lower::genOpenMPTerminator(builder, sectionsOp, loc);
|
1667 | 1579 |
|
1668 | 1580 | auto genRegionEntryCB = [&](mlir::Operation *op) {
|
1669 |
| - genEntryBlock(converter, args, op->getRegion(0)); |
| 1581 | + genEntryBlock(builder, args, op->getRegion(0)); |
1670 | 1582 | bindEntryBlockArgs(
|
1671 | 1583 | converter, llvm::cast<mlir::omp::BlockArgOpenMPOpInterface>(op), args);
|
1672 | 1584 | return llvm::to_vector(args.getSyms());
|
@@ -1989,7 +1901,7 @@ genTaskOp(lower::AbstractConverter &converter, lower::SymMap &symTable,
|
1989 | 1901 | taskArgs.priv.vars = clauseOps.privateVars;
|
1990 | 1902 |
|
1991 | 1903 | auto genRegionEntryCB = [&](mlir::Operation *op) {
|
1992 |
| - genEntryBlock(converter, taskArgs, op->getRegion(0)); |
| 1904 | + genEntryBlock(converter.getFirOpBuilder(), taskArgs, op->getRegion(0)); |
1993 | 1905 | bindEntryBlockArgs(converter,
|
1994 | 1906 | llvm::cast<mlir::omp::BlockArgOpenMPOpInterface>(op),
|
1995 | 1907 | taskArgs);
|
|
0 commit comments