|
7 | 7 | //===----------------------------------------------------------------------===//
|
8 | 8 |
|
9 | 9 | #include "flang/Support/OpenMP-utils.h"
|
10 |
| -#include "flang/Optimizer/Builder/DirectivesCommon.h" |
11 |
| -#include "flang/Optimizer/Builder/FIRBuilder.h" |
12 |
| -#include "flang/Optimizer/Builder/HLFIRTools.h" |
13 | 10 |
|
14 |
| -#include "mlir/Dialect/OpenMP/OpenMPDialect.h" |
15 | 11 | #include "mlir/IR/OpDefinition.h"
|
16 |
| -#include "mlir/Transforms/RegionUtils.h" |
17 |
| - |
18 |
| -#include "llvm/Frontend/OpenMP/OMPConstants.h" |
19 | 12 |
|
20 | 13 | namespace Fortran::common::openmp {
|
21 | 14 | mlir::Block *genEntryBlock(mlir::OpBuilder &builder, const EntryBlockArgs &args,
|
@@ -54,146 +47,4 @@ mlir::Block *genEntryBlock(mlir::OpBuilder &builder, const EntryBlockArgs &args,
|
54 | 47 |
|
55 | 48 | return builder.createBlock(®ion, {}, types, locs);
|
56 | 49 | }
|
57 |
| - |
58 |
| -mlir::omp::MapInfoOp createMapInfoOp(mlir::OpBuilder &builder, |
59 |
| - mlir::Location loc, mlir::Value baseAddr, mlir::Value varPtrPtr, |
60 |
| - llvm::StringRef name, llvm::ArrayRef<mlir::Value> bounds, |
61 |
| - llvm::ArrayRef<mlir::Value> members, mlir::ArrayAttr membersIndex, |
62 |
| - uint64_t mapType, mlir::omp::VariableCaptureKind mapCaptureType, |
63 |
| - mlir::Type retTy, bool partialMap, mlir::FlatSymbolRefAttr mapperId) { |
64 |
| - |
65 |
| - if (auto boxTy = llvm::dyn_cast<fir::BaseBoxType>(baseAddr.getType())) { |
66 |
| - baseAddr = fir::BoxAddrOp::create(builder, loc, baseAddr); |
67 |
| - retTy = baseAddr.getType(); |
68 |
| - } |
69 |
| - |
70 |
| - mlir::TypeAttr varType = mlir::TypeAttr::get( |
71 |
| - llvm::cast<mlir::omp::PointerLikeType>(retTy).getElementType()); |
72 |
| - |
73 |
| - // For types with unknown extents such as <2x?xi32> we discard the incomplete |
74 |
| - // type info and only retain the base type. The correct dimensions are later |
75 |
| - // recovered through the bounds info. |
76 |
| - if (auto seqType = llvm::dyn_cast<fir::SequenceType>(varType.getValue())) |
77 |
| - if (seqType.hasDynamicExtents()) |
78 |
| - varType = mlir::TypeAttr::get(seqType.getEleTy()); |
79 |
| - |
80 |
| - mlir::omp::MapInfoOp op = |
81 |
| - mlir::omp::MapInfoOp::create(builder, loc, retTy, baseAddr, varType, |
82 |
| - builder.getIntegerAttr(builder.getIntegerType(64, false), mapType), |
83 |
| - builder.getAttr<mlir::omp::VariableCaptureKindAttr>(mapCaptureType), |
84 |
| - varPtrPtr, members, membersIndex, bounds, mapperId, |
85 |
| - builder.getStringAttr(name), builder.getBoolAttr(partialMap)); |
86 |
| - return op; |
87 |
| -} |
88 |
| - |
89 |
| -mlir::Value mapTemporaryValue(fir::FirOpBuilder &firOpBuilder, |
90 |
| - mlir::omp::TargetOp targetOp, mlir::Value val, llvm::StringRef name) { |
91 |
| - mlir::OpBuilder::InsertionGuard guard(firOpBuilder); |
92 |
| - mlir::Operation *valOp = val.getDefiningOp(); |
93 |
| - |
94 |
| - if (valOp) |
95 |
| - firOpBuilder.setInsertionPointAfter(valOp); |
96 |
| - else |
97 |
| - // This means val is a block argument |
98 |
| - firOpBuilder.setInsertionPoint(targetOp); |
99 |
| - |
100 |
| - auto copyVal = firOpBuilder.createTemporary(val.getLoc(), val.getType()); |
101 |
| - firOpBuilder.createStoreWithConvert(copyVal.getLoc(), val, copyVal); |
102 |
| - |
103 |
| - fir::factory::AddrAndBoundsInfo info = fir::factory::getDataOperandBaseAddr( |
104 |
| - firOpBuilder, val, /*isOptional=*/false, val.getLoc()); |
105 |
| - llvm::SmallVector<mlir::Value> bounds = |
106 |
| - fir::factory::genImplicitBoundsOps<mlir::omp::MapBoundsOp, |
107 |
| - mlir::omp::MapBoundsType>(firOpBuilder, info, |
108 |
| - hlfir::translateToExtendedValue( |
109 |
| - val.getLoc(), firOpBuilder, hlfir::Entity{val}) |
110 |
| - .first, |
111 |
| - /*dataExvIsAssumedSize=*/false, val.getLoc()); |
112 |
| - |
113 |
| - firOpBuilder.setInsertionPoint(targetOp); |
114 |
| - |
115 |
| - llvm::omp::OpenMPOffloadMappingFlags mapFlag = |
116 |
| - llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_IMPLICIT; |
117 |
| - mlir::omp::VariableCaptureKind captureKind = |
118 |
| - mlir::omp::VariableCaptureKind::ByRef; |
119 |
| - |
120 |
| - mlir::Type eleType = copyVal.getType(); |
121 |
| - if (auto refType = mlir::dyn_cast<fir::ReferenceType>(copyVal.getType())) { |
122 |
| - eleType = refType.getElementType(); |
123 |
| - } |
124 |
| - |
125 |
| - if (fir::isa_trivial(eleType) || fir::isa_char(eleType)) { |
126 |
| - captureKind = mlir::omp::VariableCaptureKind::ByCopy; |
127 |
| - } else if (!fir::isa_builtin_cptr_type(eleType)) { |
128 |
| - mapFlag |= llvm::omp::OpenMPOffloadMappingFlags::OMP_MAP_TO; |
129 |
| - } |
130 |
| - |
131 |
| - mlir::Value mapOp = Fortran::common::openmp::createMapInfoOp(firOpBuilder, |
132 |
| - copyVal.getLoc(), copyVal, |
133 |
| - /*varPtrPtr=*/mlir::Value{}, name.str(), bounds, |
134 |
| - /*members=*/llvm::SmallVector<mlir::Value>{}, |
135 |
| - /*membersIndex=*/mlir::ArrayAttr{}, |
136 |
| - static_cast<std::underlying_type_t<llvm::omp::OpenMPOffloadMappingFlags>>( |
137 |
| - mapFlag), |
138 |
| - captureKind, copyVal.getType()); |
139 |
| - |
140 |
| - auto argIface = llvm::cast<mlir::omp::BlockArgOpenMPOpInterface>(*targetOp); |
141 |
| - mlir::Region ®ion = targetOp.getRegion(); |
142 |
| - |
143 |
| - // Get the index of the first non-map argument before modifying mapVars, |
144 |
| - // then append an element to mapVars and an associated entry block |
145 |
| - // argument at that index. |
146 |
| - unsigned insertIndex = |
147 |
| - argIface.getMapBlockArgsStart() + argIface.numMapBlockArgs(); |
148 |
| - targetOp.getMapVarsMutable().append(mapOp); |
149 |
| - mlir::Value clonedValArg = |
150 |
| - region.insertArgument(insertIndex, copyVal.getType(), copyVal.getLoc()); |
151 |
| - |
152 |
| - mlir::Block *entryBlock = ®ion.getBlocks().front(); |
153 |
| - firOpBuilder.setInsertionPointToStart(entryBlock); |
154 |
| - auto loadOp = |
155 |
| - firOpBuilder.create<fir::LoadOp>(clonedValArg.getLoc(), clonedValArg); |
156 |
| - return loadOp.getResult(); |
157 |
| -} |
158 |
| - |
159 |
| -void cloneOrMapRegionOutsiders(fir::FirOpBuilder &firOpBuilder, |
160 |
| - mlir::omp::TargetOp targetOp) { |
161 |
| - mlir::Region ®ion = targetOp.getRegion(); |
162 |
| - mlir::Block *entryBlock = ®ion.getBlocks().front(); |
163 |
| - |
164 |
| - llvm::SetVector<mlir::Value> valuesDefinedAbove; |
165 |
| - mlir::getUsedValuesDefinedAbove(region, valuesDefinedAbove); |
166 |
| - while (!valuesDefinedAbove.empty()) { |
167 |
| - for (mlir::Value val : valuesDefinedAbove) { |
168 |
| - mlir::Operation *valOp = val.getDefiningOp(); |
169 |
| - |
170 |
| - // NOTE: We skip BoxDimsOp's as the lesser of two evils is to map the |
171 |
| - // indices separately, as the alternative is to eventually map the Box, |
172 |
| - // which comes with a fairly large overhead comparatively. We could be |
173 |
| - // more robust about this and check using a BackwardsSlice to see if we |
174 |
| - // run the risk of mapping a box. |
175 |
| - if (valOp && mlir::isMemoryEffectFree(valOp) && |
176 |
| - !mlir::isa<fir::BoxDimsOp>(valOp)) { |
177 |
| - mlir::Operation *clonedOp = valOp->clone(); |
178 |
| - entryBlock->push_front(clonedOp); |
179 |
| - |
180 |
| - auto replace = [entryBlock](mlir::OpOperand &use) { |
181 |
| - return use.getOwner()->getBlock() == entryBlock; |
182 |
| - }; |
183 |
| - |
184 |
| - valOp->getResults().replaceUsesWithIf(clonedOp->getResults(), replace); |
185 |
| - valOp->replaceUsesWithIf(clonedOp, replace); |
186 |
| - } else { |
187 |
| - mlir::Value mappedTemp = Fortran::common::openmp::mapTemporaryValue( |
188 |
| - firOpBuilder, targetOp, val, |
189 |
| - /*name=*/{}); |
190 |
| - val.replaceUsesWithIf(mappedTemp, [entryBlock](mlir::OpOperand &use) { |
191 |
| - return use.getOwner()->getBlock() == entryBlock; |
192 |
| - }); |
193 |
| - } |
194 |
| - } |
195 |
| - valuesDefinedAbove.clear(); |
196 |
| - mlir::getUsedValuesDefinedAbove(region, valuesDefinedAbove); |
197 |
| - } |
198 |
| -} |
199 | 50 | } // namespace Fortran::common::openmp
|
0 commit comments