|
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" |
|
40 | 41 | #include "llvm/Frontend/OpenMP/OMPConstants.h" |
41 | 42 |
|
42 | 43 | using namespace Fortran::lower::omp; |
| 44 | +using namespace Fortran::openmp::common; |
43 | 45 |
|
44 | 46 | //===----------------------------------------------------------------------===// |
45 | 47 | // Code generation helper functions |
46 | 48 | //===----------------------------------------------------------------------===// |
47 | 49 |
|
48 | | -namespace { |
49 | | -/// Structure holding the information needed to create and bind entry block |
50 | | -/// arguments associated to a single clause. |
51 | | -struct EntryBlockArgsEntry { |
52 | | - llvm::ArrayRef<const semantics::Symbol *> syms; |
53 | | - llvm::ArrayRef<mlir::Value> vars; |
54 | | - |
55 | | - bool isValid() const { |
56 | | - // This check allows specifying a smaller number of symbols than values |
57 | | - // because in some case cases a single symbol generates multiple block |
58 | | - // arguments. |
59 | | - return syms.size() <= vars.size(); |
60 | | - } |
61 | | -}; |
62 | | - |
63 | | -/// Structure holding the information needed to create and bind entry block |
64 | | -/// arguments associated to all clauses that can define them. |
65 | | -struct EntryBlockArgs { |
66 | | - EntryBlockArgsEntry inReduction; |
67 | | - EntryBlockArgsEntry map; |
68 | | - EntryBlockArgsEntry priv; |
69 | | - EntryBlockArgsEntry reduction; |
70 | | - EntryBlockArgsEntry taskReduction; |
71 | | - EntryBlockArgsEntry useDeviceAddr; |
72 | | - EntryBlockArgsEntry useDevicePtr; |
73 | | - |
74 | | - bool isValid() const { |
75 | | - return inReduction.isValid() && map.isValid() && priv.isValid() && |
76 | | - reduction.isValid() && taskReduction.isValid() && |
77 | | - useDeviceAddr.isValid() && useDevicePtr.isValid(); |
78 | | - } |
79 | | - |
80 | | - auto getSyms() const { |
81 | | - return llvm::concat<const semantics::Symbol *const>( |
82 | | - inReduction.syms, map.syms, priv.syms, reduction.syms, |
83 | | - taskReduction.syms, useDeviceAddr.syms, useDevicePtr.syms); |
84 | | - } |
85 | | - |
86 | | - auto getVars() const { |
87 | | - return llvm::concat<const mlir::Value>( |
88 | | - inReduction.vars, map.vars, priv.vars, reduction.vars, |
89 | | - taskReduction.vars, useDeviceAddr.vars, useDevicePtr.vars); |
90 | | - } |
91 | | -}; |
92 | | -} // namespace |
93 | | - |
94 | 50 | static void genOMPDispatch(lower::AbstractConverter &converter, |
95 | 51 | lower::SymMap &symTable, |
96 | 52 | semantics::SemanticsContext &semaCtx, |
@@ -622,50 +578,6 @@ static void genLoopVars( |
622 | 578 | firOpBuilder.setInsertionPointAfter(storeOp); |
623 | 579 | } |
624 | 580 |
|
625 | | -/// Create an entry block for the given region, including the clause-defined |
626 | | -/// arguments specified. |
627 | | -/// |
628 | | -/// \param [in] converter - PFT to MLIR conversion interface. |
629 | | -/// \param [in] args - entry block arguments information for the given |
630 | | -/// operation. |
631 | | -/// \param [in] region - Empty region in which to create the entry block. |
632 | | -static mlir::Block *genEntryBlock(lower::AbstractConverter &converter, |
633 | | - const EntryBlockArgs &args, |
634 | | - mlir::Region ®ion) { |
635 | | - assert(args.isValid() && "invalid args"); |
636 | | - assert(region.empty() && "non-empty region"); |
637 | | - fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder(); |
638 | | - |
639 | | - llvm::SmallVector<mlir::Type> types; |
640 | | - llvm::SmallVector<mlir::Location> locs; |
641 | | - unsigned numVars = args.inReduction.vars.size() + args.map.vars.size() + |
642 | | - args.priv.vars.size() + args.reduction.vars.size() + |
643 | | - args.taskReduction.vars.size() + |
644 | | - args.useDeviceAddr.vars.size() + |
645 | | - args.useDevicePtr.vars.size(); |
646 | | - types.reserve(numVars); |
647 | | - locs.reserve(numVars); |
648 | | - |
649 | | - auto extractTypeLoc = [&types, &locs](llvm::ArrayRef<mlir::Value> vals) { |
650 | | - llvm::transform(vals, std::back_inserter(types), |
651 | | - [](mlir::Value v) { return v.getType(); }); |
652 | | - llvm::transform(vals, std::back_inserter(locs), |
653 | | - [](mlir::Value v) { return v.getLoc(); }); |
654 | | - }; |
655 | | - |
656 | | - // Populate block arguments in clause name alphabetical order to match |
657 | | - // expected order by the BlockArgOpenMPOpInterface. |
658 | | - extractTypeLoc(args.inReduction.vars); |
659 | | - extractTypeLoc(args.map.vars); |
660 | | - extractTypeLoc(args.priv.vars); |
661 | | - extractTypeLoc(args.reduction.vars); |
662 | | - extractTypeLoc(args.taskReduction.vars); |
663 | | - extractTypeLoc(args.useDeviceAddr.vars); |
664 | | - extractTypeLoc(args.useDevicePtr.vars); |
665 | | - |
666 | | - return firOpBuilder.createBlock(®ion, {}, types, locs); |
667 | | -} |
668 | | - |
669 | 581 | static void |
670 | 582 | markDeclareTarget(mlir::Operation *op, lower::AbstractConverter &converter, |
671 | 583 | mlir::omp::DeclareTargetCaptureClause captureClause, |
@@ -918,7 +830,7 @@ static void genBodyOfTargetDataOp( |
918 | 830 | ConstructQueue::const_iterator item) { |
919 | 831 | fir::FirOpBuilder &firOpBuilder = converter.getFirOpBuilder(); |
920 | 832 |
|
921 | | - genEntryBlock(converter, args, dataOp.getRegion()); |
| 833 | + genEntryBlock(converter.getFirOpBuilder(), args, dataOp.getRegion()); |
922 | 834 | bindEntryBlockArgs(converter, dataOp, args); |
923 | 835 |
|
924 | 836 | // Insert dummy instruction to remember the insertion position. The |
@@ -995,7 +907,8 @@ static void genBodyOfTargetOp( |
995 | 907 | auto argIface = llvm::cast<mlir::omp::BlockArgOpenMPOpInterface>(*targetOp); |
996 | 908 |
|
997 | 909 | mlir::Region ®ion = targetOp.getRegion(); |
998 | | - mlir::Block *entryBlock = genEntryBlock(converter, args, region); |
| 910 | + mlir::Block *entryBlock = |
| 911 | + genEntryBlock(converter.getFirOpBuilder(), args, region); |
999 | 912 | bindEntryBlockArgs(converter, targetOp, args); |
1000 | 913 |
|
1001 | 914 | // Check if cloning the bounds introduced any dependency on the outer region. |
@@ -1121,7 +1034,7 @@ static OpTy genWrapperOp(lower::AbstractConverter &converter, |
1121 | 1034 | auto op = firOpBuilder.create<OpTy>(loc, clauseOps); |
1122 | 1035 |
|
1123 | 1036 | // Create entry block with arguments. |
1124 | | - genEntryBlock(converter, args, op.getRegion()); |
| 1037 | + genEntryBlock(converter.getFirOpBuilder(), args, op.getRegion()); |
1125 | 1038 |
|
1126 | 1039 | return op; |
1127 | 1040 | } |
@@ -1544,7 +1457,7 @@ genParallelOp(lower::AbstractConverter &converter, lower::SymMap &symTable, |
1544 | 1457 | const EntryBlockArgs &args, DataSharingProcessor *dsp, |
1545 | 1458 | bool isComposite = false) { |
1546 | 1459 | auto genRegionEntryCB = [&](mlir::Operation *op) { |
1547 | | - genEntryBlock(converter, args, op->getRegion(0)); |
| 1460 | + genEntryBlock(converter.getFirOpBuilder(), args, op->getRegion(0)); |
1548 | 1461 | bindEntryBlockArgs( |
1549 | 1462 | converter, llvm::cast<mlir::omp::BlockArgOpenMPOpInterface>(op), args); |
1550 | 1463 | return llvm::to_vector(args.getSyms()); |
@@ -1617,12 +1530,12 @@ genSectionsOp(lower::AbstractConverter &converter, lower::SymMap &symTable, |
1617 | 1530 | args.reduction.syms = reductionSyms; |
1618 | 1531 | args.reduction.vars = clauseOps.reductionVars; |
1619 | 1532 |
|
1620 | | - genEntryBlock(converter, args, sectionsOp.getRegion()); |
| 1533 | + genEntryBlock(converter.getFirOpBuilder(), args, sectionsOp.getRegion()); |
1621 | 1534 | mlir::Operation *terminator = |
1622 | 1535 | lower::genOpenMPTerminator(builder, sectionsOp, loc); |
1623 | 1536 |
|
1624 | 1537 | auto genRegionEntryCB = [&](mlir::Operation *op) { |
1625 | | - genEntryBlock(converter, args, op->getRegion(0)); |
| 1538 | + genEntryBlock(converter.getFirOpBuilder(), args, op->getRegion(0)); |
1626 | 1539 | bindEntryBlockArgs( |
1627 | 1540 | converter, llvm::cast<mlir::omp::BlockArgOpenMPOpInterface>(op), args); |
1628 | 1541 | return llvm::to_vector(args.getSyms()); |
|
0 commit comments