[Mlir-commits] [mlir] [NFC][OpenMP][MLIR] Refactor code related to collecting privatizer info into a shared util (PR #131582)

Sergio Afonso llvmlistbot at llvm.org
Tue Mar 18 05:47:31 PDT 2025


================
@@ -696,20 +696,42 @@ convertOmpCritical(Operation &opInst, llvm::IRBuilderBase &builder,
   return success();
 }
 
-/// Populates `privatizations` with privatization declarations used for the
-/// given op.
-template <class OP>
-static void collectPrivatizationDecls(
-    OP op, SmallVectorImpl<omp::PrivateClauseOp> &privatizations) {
-  std::optional<ArrayAttr> attr = op.getPrivateSyms();
-  if (!attr)
-    return;
+/// A util to collect info needed to convert delayed privatizers from MLIR to
+/// LLVM.
+struct PrivateVarsInfo {
+  template <typename OP>
+  PrivateVarsInfo(OP op)
+      : privateBlockArgs(
+            cast<omp::BlockArgOpenMPOpInterface>(*op).getPrivateBlockArgs()) {
+    mlirPrivateVars.reserve(privateBlockArgs.size());
+    llvmPrivateVars.reserve(privateBlockArgs.size());
+    collectPrivatizationDecls<OP>(op, privateDecls);
 
-  privatizations.reserve(privatizations.size() + attr->size());
-  for (auto symbolRef : attr->getAsRange<SymbolRefAttr>()) {
-    privatizations.push_back(findPrivatizer(op, symbolRef));
+    for (mlir::Value privateVar : op.getPrivateVars())
+      mlirPrivateVars.push_back(privateVar);
   }
-}
+
+  MutableArrayRef<BlockArgument> privateBlockArgs;
+  SmallVector<mlir::Value> mlirPrivateVars;
+  SmallVector<llvm::Value *> llvmPrivateVars;
+  SmallVector<omp::PrivateClauseOp> privateDecls;
----------------
skatrak wrote:

Nit: This is already in a private-specific structure, so maybe names can be simplified to `blockArgs`, `mlirVars`, etc. and avoid redundant information.

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


More information about the Mlir-commits mailing list