|
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, |
@@ -625,50 +581,6 @@ static void genLoopVars( |
625 | 581 | firOpBuilder.setInsertionPointAfter(storeOp); |
626 | 582 | } |
627 | 583 |
|
628 | | -/// Create an entry block for the given region, including the clause-defined |
629 | | -/// arguments specified. |
630 | | -/// |
631 | | -/// \param [in] converter - PFT to MLIR conversion interface. |
632 | | -/// \param [in] args - entry block arguments information for the given |
633 | | -/// operation. |
634 | | -/// \param [in] region - Empty region in which to create the entry block. |
635 | | -static mlir::Block *genEntryBlock(lower::AbstractConverter &converter, |
636 | | - const EntryBlockArgs &args, |
637 | | - mlir::Region ®ion) { |
638 | | - assert(args.isValid() && "invalid args"); |
639 | | - assert(region.empty() && "non-empty region"); |
640 | | - fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder(); |
641 | | - |
642 | | - llvm::SmallVector<mlir::Type> types; |
643 | | - llvm::SmallVector<mlir::Location> locs; |
644 | | - unsigned numVars = args.inReduction.vars.size() + args.map.vars.size() + |
645 | | - args.priv.vars.size() + args.reduction.vars.size() + |
646 | | - args.taskReduction.vars.size() + |
647 | | - args.useDeviceAddr.vars.size() + |
648 | | - args.useDevicePtr.vars.size(); |
649 | | - types.reserve(numVars); |
650 | | - locs.reserve(numVars); |
651 | | - |
652 | | - auto extractTypeLoc = [&types, &locs](llvm::ArrayRef<mlir::Value> vals) { |
653 | | - llvm::transform(vals, std::back_inserter(types), |
654 | | - [](mlir::Value v) { return v.getType(); }); |
655 | | - llvm::transform(vals, std::back_inserter(locs), |
656 | | - [](mlir::Value v) { return v.getLoc(); }); |
657 | | - }; |
658 | | - |
659 | | - // Populate block arguments in clause name alphabetical order to match |
660 | | - // expected order by the BlockArgOpenMPOpInterface. |
661 | | - extractTypeLoc(args.inReduction.vars); |
662 | | - extractTypeLoc(args.map.vars); |
663 | | - extractTypeLoc(args.priv.vars); |
664 | | - extractTypeLoc(args.reduction.vars); |
665 | | - extractTypeLoc(args.taskReduction.vars); |
666 | | - extractTypeLoc(args.useDeviceAddr.vars); |
667 | | - extractTypeLoc(args.useDevicePtr.vars); |
668 | | - |
669 | | - return firOpBuilder.createBlock(®ion, {}, types, locs); |
670 | | -} |
671 | | - |
672 | 584 | static void |
673 | 585 | markDeclareTarget(mlir::Operation *op, lower::AbstractConverter &converter, |
674 | 586 | mlir::omp::DeclareTargetCaptureClause captureClause, |
@@ -921,7 +833,7 @@ static void genBodyOfTargetDataOp( |
921 | 833 | ConstructQueue::const_iterator item) { |
922 | 834 | fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder(); |
923 | 835 |
|
924 | | - genEntryBlock(converter, args, dataOp.getRegion()); |
| 836 | + genEntryBlock(firOpBuilder, args, dataOp.getRegion()); |
925 | 837 | bindEntryBlockArgs(converter, dataOp, args); |
926 | 838 |
|
927 | 839 | // Insert dummy instruction to remember the insertion position. The |
@@ -998,7 +910,7 @@ static void genBodyOfTargetOp( |
998 | 910 | auto argIface = llvm::cast<mlir::omp::BlockArgOpenMPOpInterface>(*targetOp); |
999 | 911 |
|
1000 | 912 | mlir::Region ®ion = targetOp.getRegion(); |
1001 | | - mlir::Block *entryBlock = genEntryBlock(converter, args, region); |
| 913 | + mlir::Block *entryBlock = genEntryBlock(firOpBuilder, args, region); |
1002 | 914 | bindEntryBlockArgs(converter, targetOp, args); |
1003 | 915 |
|
1004 | 916 | // Check if cloning the bounds introduced any dependency on the outer region. |
@@ -1124,7 +1036,7 @@ static OpTy genWrapperOp(lower::AbstractConverter &converter, |
1124 | 1036 | auto op = firOpBuilder.create<OpTy>(loc, clauseOps); |
1125 | 1037 |
|
1126 | 1038 | // Create entry block with arguments. |
1127 | | - genEntryBlock(converter, args, op.getRegion()); |
| 1039 | + genEntryBlock(firOpBuilder, args, op.getRegion()); |
1128 | 1040 |
|
1129 | 1041 | return op; |
1130 | 1042 | } |
@@ -1590,7 +1502,7 @@ genParallelOp(lower::AbstractConverter &converter, lower::SymMap &symTable, |
1590 | 1502 | const EntryBlockArgs &args, DataSharingProcessor *dsp, |
1591 | 1503 | bool isComposite = false) { |
1592 | 1504 | auto genRegionEntryCB = [&](mlir::Operation *op) { |
1593 | | - genEntryBlock(converter, args, op->getRegion(0)); |
| 1505 | + genEntryBlock(converter.getFirOpBuilder(), args, op->getRegion(0)); |
1594 | 1506 | bindEntryBlockArgs( |
1595 | 1507 | converter, llvm::cast<mlir::omp::BlockArgOpenMPOpInterface>(op), args); |
1596 | 1508 | return llvm::to_vector(args.getSyms()); |
@@ -1663,12 +1575,12 @@ genSectionsOp(lower::AbstractConverter &converter, lower::SymMap &symTable, |
1663 | 1575 | args.reduction.syms = reductionSyms; |
1664 | 1576 | args.reduction.vars = clauseOps.reductionVars; |
1665 | 1577 |
|
1666 | | - genEntryBlock(converter, args, sectionsOp.getRegion()); |
| 1578 | + genEntryBlock(builder, args, sectionsOp.getRegion()); |
1667 | 1579 | mlir::Operation *terminator = |
1668 | 1580 | lower::genOpenMPTerminator(builder, sectionsOp, loc); |
1669 | 1581 |
|
1670 | 1582 | auto genRegionEntryCB = [&](mlir::Operation *op) { |
1671 | | - genEntryBlock(converter, args, op->getRegion(0)); |
| 1583 | + genEntryBlock(builder, args, op->getRegion(0)); |
1672 | 1584 | bindEntryBlockArgs( |
1673 | 1585 | converter, llvm::cast<mlir::omp::BlockArgOpenMPOpInterface>(op), args); |
1674 | 1586 | return llvm::to_vector(args.getSyms()); |
@@ -1991,7 +1903,7 @@ genTaskOp(lower::AbstractConverter &converter, lower::SymMap &symTable, |
1991 | 1903 | taskArgs.priv.vars = clauseOps.privateVars; |
1992 | 1904 |
|
1993 | 1905 | auto genRegionEntryCB = [&](mlir::Operation *op) { |
1994 | | - genEntryBlock(converter, taskArgs, op->getRegion(0)); |
| 1906 | + genEntryBlock(converter.getFirOpBuilder(), taskArgs, op->getRegion(0)); |
1995 | 1907 | bindEntryBlockArgs(converter, |
1996 | 1908 | llvm::cast<mlir::omp::BlockArgOpenMPOpInterface>(op), |
1997 | 1909 | taskArgs); |
|
0 commit comments