@@ -89,8 +89,14 @@ mlir::omp::MapInfoOp createMapInfoOp(mlir::OpBuilder &builder,
89
89
mlir::Value mapTemporaryValue (fir::FirOpBuilder &firOpBuilder,
90
90
mlir::omp::TargetOp targetOp, mlir::Value val, llvm::StringRef name) {
91
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);
92
99
93
- firOpBuilder.setInsertionPointAfterValue (val);
94
100
auto copyVal = firOpBuilder.createTemporary (val.getLoc (), val.getType ());
95
101
firOpBuilder.createStoreWithConvert (copyVal.getLoc (), val, copyVal);
96
102
@@ -160,14 +166,13 @@ void cloneOrMapRegionOutsiders(fir::FirOpBuilder &firOpBuilder,
160
166
while (!valuesDefinedAbove.empty ()) {
161
167
for (mlir::Value val : valuesDefinedAbove) {
162
168
mlir::Operation *valOp = val.getDefiningOp ();
163
- assert (valOp != nullptr );
164
169
165
170
// NOTE: We skip BoxDimsOp's as the lesser of two evils is to map the
166
171
// indices separately, as the alternative is to eventually map the Box,
167
172
// which comes with a fairly large overhead comparatively. We could be
168
173
// more robust about this and check using a BackwardsSlice to see if we
169
174
// run the risk of mapping a box.
170
- if (mlir::isMemoryEffectFree (valOp) &&
175
+ if (valOp && mlir::isMemoryEffectFree (valOp) &&
171
176
!mlir::isa<fir::BoxDimsOp>(valOp)) {
172
177
mlir::Operation *clonedOp = valOp->clone ();
173
178
entryBlock->push_front (clonedOp);
0 commit comments