[flang-commits] [flang] [mlir] [mlir][flang][openmp] Rework parallel reduction operations (PR #79308)

Kiran Chandramohan via flang-commits flang-commits at lists.llvm.org
Fri Jan 26 08:21:53 PST 2024


================
@@ -2261,24 +2275,32 @@ static void createBodyOfOp(
   // argument. Also update the symbol's address with the mlir argument value.
   // e.g. For loops the argument is the induction variable. And all further
   // uses of the induction variable should use this mlir value.
-  if (args.size()) {
+  if (loopArgs.size()) {
     std::size_t loopVarTypeSize = 0;
-    for (const Fortran::semantics::Symbol *arg : args)
+    for (const Fortran::semantics::Symbol *arg : loopArgs)
       loopVarTypeSize = std::max(loopVarTypeSize, arg->GetUltimate().size());
     mlir::Type loopVarType = getLoopVarType(converter, loopVarTypeSize);
-    llvm::SmallVector<mlir::Type> tiv(args.size(), loopVarType);
-    llvm::SmallVector<mlir::Location> locs(args.size(), loc);
+    llvm::SmallVector<mlir::Type> tiv(loopArgs.size(), loopVarType);
+    llvm::SmallVector<mlir::Location> locs(loopArgs.size(), loc);
     firOpBuilder.createBlock(&op.getRegion(), {}, tiv, locs);
     // The argument is not currently in memory, so make a temporary for the
     // argument, and store it there, then bind that location to the argument.
     mlir::Operation *storeOp = nullptr;
-    for (auto [argIndex, argSymbol] : llvm::enumerate(args)) {
+    for (auto [argIndex, argSymbol] : llvm::enumerate(loopArgs)) {
       mlir::Value indexVal =
           fir::getBase(op.getRegion().front().getArgument(argIndex));
       storeOp =
           createAndSetPrivatizedLoopVar(converter, loc, indexVal, argSymbol);
     }
     firOpBuilder.setInsertionPointAfter(storeOp);
+  } else if (reductionArgs.size()) {
----------------
kiranchandramohan wrote:

Nit: Add a TODO to remove the else when reduction support for worksharing loop is added in the same way as this patch for parallel.

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


More information about the flang-commits mailing list