[flang-commits] [flang] [Flang][OpenMP]Support for lowering task_reduction and in_reduction to MLIR (PR #111155)

Sergio Afonso via flang-commits flang-commits at lists.llvm.org
Fri Dec 6 07:22:47 PST 2024


================
@@ -1901,22 +1904,35 @@ genTaskOp(lower::AbstractConverter &converter, lower::SymMap &symTable,
   EntryBlockArgs taskArgs;
   taskArgs.priv.syms = dsp.getDelayedPrivSymbols();
   taskArgs.priv.vars = clauseOps.privateVars;
+  taskArgs.inReduction.syms = InReductionSyms;
+  taskArgs.inReduction.vars = clauseOps.inReductionVars;
 
   auto genRegionEntryCB = [&](mlir::Operation *op) {
     genEntryBlock(converter.getFirOpBuilder(), taskArgs, op->getRegion(0));
     bindEntryBlockArgs(converter,
                        llvm::cast<mlir::omp::BlockArgOpenMPOpInterface>(op),
                        taskArgs);
-    return llvm::to_vector(taskArgs.priv.syms);
+    return llvm::to_vector(taskArgs.getSyms());
   };
 
-  return genOpWithBody<mlir::omp::TaskOp>(
+  OpWithBodyGenInfo genInfo =
       OpWithBodyGenInfo(converter, symTable, semaCtx, loc, eval,
                         llvm::omp::Directive::OMPD_task)
           .setClauses(&item->clauses)
           .setDataSharingProcessor(&dsp)
-          .setGenRegionEntryCb(genRegionEntryCB),
-      queue, item, clauseOps);
+          .setGenRegionEntryCb(genRegionEntryCB);
+
+  auto taskOp =
+      genOpWithBody<mlir::omp::TaskOp>(genInfo, queue, item, clauseOps);
+
+  llvm::SmallVector<mlir::Type> inReductionTypes;
+  for (const auto &inreductionVar : clauseOps.inReductionVars)
+    inReductionTypes.push_back(inreductionVar.getType());
+
+  // Add reduction variables as entry block arguments to the task region
+  llvm::SmallVector<mlir::Location> blockArgLocs(InReductionSyms.size(), loc);
+  taskOp->getRegion(0).addArguments(inReductionTypes, blockArgLocs);
----------------
skatrak wrote:

This isn't necessary. It's done by the call to `genEntryBlock` inside of `genRegionEntryCB`.

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


More information about the flang-commits mailing list