[Mlir-commits] [flang] [mlir] [mlir][OpenMP] rewrite conversion of privatisation for omp.parallel (PR #111844)
Leandro Lupori
llvmlistbot at llvm.org
Fri Oct 11 14:53:15 PDT 2024
================
@@ -1421,12 +1449,56 @@ convertOmpParallel(omp::ParallelOp opInst, llvm::IRBuilderBase &builder,
deferredStores, isByRef)))
bodyGenStatus = failure();
+ // Apply copy region for firstprivate.
+ if (!privateBlockArgs.empty()) {
+ // Find the end of the allocation blocks
+ assert(afterAllocas->getSinglePredecessor());
+ builder.SetInsertPoint(
+ afterAllocas->getSinglePredecessor()->getTerminator());
+ llvm::BasicBlock *copyBlock = splitBB(builder, true, "omp.private.copy");
+ builder.SetInsertPoint(copyBlock->getFirstNonPHIOrDbgOrAlloca());
+ }
+ for (unsigned i = 0; i < privateBlockArgs.size(); ++i) {
+ if (privateDecls[i].getDataSharingType() !=
+ omp::DataSharingClauseType::FirstPrivate)
+ continue;
+
+ // copyRegion implements `lhs = rhs`
+ Region ©Region = privateDecls[i].getCopyRegion();
+
+ // map copyRegion rhs arg
+ llvm::Value *nonPrivateVar =
+ moduleTranslation.lookupValue(opInst.getPrivateVars()[i]);
+ assert(nonPrivateVar);
+ moduleTranslation.mapValue(copyRegion.getArgument(0), nonPrivateVar);
+
+ // map copyRegion lhs arg
+ moduleTranslation.mapValue(copyRegion.getArgument(1), llvmPrivateVars[i]);
+
+ // in-place convert copy region
+ builder.SetInsertPoint(builder.GetInsertBlock()->getTerminator());
+ if (failed(inlineConvertOmpRegions(copyRegion, "omp.private.copy",
+ builder, moduleTranslation))) {
+ bodyGenStatus = failure();
+ return;
+ }
+
+ // ignore unused value yielded value from copy region
----------------
luporl wrote:
```suggestion
// ignore unused value yielded from copy region
```
https://github.com/llvm/llvm-project/pull/111844
More information about the Mlir-commits
mailing list