[flang-commits] [flang] [mlir] [OpenMP][flang][MLIR] Decouple alloc, init, and copy regions for `omp.private|declare_reduction` ops (PR #125699)

Tom Eccles via flang-commits flang-commits at lists.llvm.org
Wed Feb 5 02:30:42 PST 2025


================
@@ -1376,17 +1377,49 @@ initPrivateVar(llvm::IRBuilderBase &builder,
   return llvm::Error::success();
 }
 
+static llvm::Error
+initPrivateVars(llvm::IRBuilderBase &builder,
+                LLVM::ModuleTranslation &moduleTranslation,
+                MutableArrayRef<BlockArgument> privateBlockArgs,
+                MutableArrayRef<omp::PrivateClauseOp> privateDecls,
+                MutableArrayRef<mlir::Value> mlirPrivateVars,
+                llvm::SmallVectorImpl<llvm::Value *> &llvmPrivateVars,
+                llvm::DenseMap<Value, Value> *mappedPrivateVars = nullptr) {
+  if (privateBlockArgs.empty())
+    return llvm::Error::success();
+
+  llvm::BasicBlock *privInitBlock = splitBB(builder, true, "omp.private.init");
+  setInsertPointForPossiblyEmptyBlock(builder, privInitBlock);
+
+  unsigned idx = 0;
+  for (auto [privDecl, mlirPrivVar, blockArg] :
+       llvm::zip_equal(privateDecls, mlirPrivateVars, privateBlockArgs)) {
----------------
tblah wrote:

I guess this is down to personal preference but I think manually incrementing `idx` is easy to forget, so I don't like doing it unless there are paths through the loop where it should not be incremented.

```suggestion
  for (auto  [idx, zip] :
       llvm::enumerate(llvm::zip_equal(privateDecls, mlirPrivateVars, privateBlockArgs))) {
       auto [privDecl, mlirPrivVar, blockArg] = zip;
```

https://github.com/llvm/llvm-project/pull/125699


More information about the flang-commits mailing list