[lldb] [libc] [compiler-rt] [libcxxabi] [flang] [libcxx] [clang-tools-extra] [lld] [clang] [llvm] [Flang][OpenMP] Push genEval calls to individual operations, NFC (PR #77758)

2024-01-12 Thread Krzysztof Parzyszek via cfe-commits


@@ -3655,8 +3661,7 @@ void Fortran::lower::genOpenMPDeclarativeConstruct(
 Fortran::lower::pft::Evaluation ,
 const Fortran::parser::OpenMPDeclarativeConstruct ) {
   genOMP(converter, eval, omp);

kparzysz wrote:

I made all `genOMP` functions have the same interface.  That required a small 
change in Bridge.cpp to pass two extra arguments, and in OpenMP.h to reflect 
the change in a function header.

https://github.com/llvm/llvm-project/pull/77758
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[lldb] [libc] [compiler-rt] [libcxxabi] [flang] [libcxx] [clang-tools-extra] [lld] [clang] [llvm] [Flang][OpenMP] Push genEval calls to individual operations, NFC (PR #77758)

2024-01-12 Thread Krzysztof Parzyszek via cfe-commits

https://github.com/kparzysz updated 
https://github.com/llvm/llvm-project/pull/77758

>From 62f31654ec66fe0e2a27200d0484d3c70d4ce2c1 Mon Sep 17 00:00:00 2001
From: Krzysztof Parzyszek 
Date: Wed, 20 Dec 2023 15:12:04 -0600
Subject: [PATCH 1/5] [Flang][OpenMP] Separate creation of work-sharing and
 SIMD loops, NFC

These two constructs were both handled in `genOMP` for loop constructs.
There is some shared code between the two, but there are also enough
differences to separate these two cases into individual functions.

The shared code may be placed into a helper function later if needed.

Recursive lowering [1/5]
---
 flang/lib/Lower/OpenMP.cpp | 252 ++---
 1 file changed, 153 insertions(+), 99 deletions(-)

diff --git a/flang/lib/Lower/OpenMP.cpp b/flang/lib/Lower/OpenMP.cpp
index c3a570bf15ea0d..350cb29121da93 100644
--- a/flang/lib/Lower/OpenMP.cpp
+++ b/flang/lib/Lower/OpenMP.cpp
@@ -2968,24 +2968,150 @@ genOMP(Fortran::lower::AbstractConverter ,
   standaloneConstruct.u);
 }
 
-static void genOMP(Fortran::lower::AbstractConverter ,
-   Fortran::lower::pft::Evaluation ,
-   Fortran::semantics::SemanticsContext ,
-   const Fortran::parser::OpenMPLoopConstruct ) {
+static void
+createSimdLoop(Fortran::lower::AbstractConverter ,
+   Fortran::lower::pft::Evaluation ,
+   llvm::omp::Directive ompDirective,
+   const Fortran::parser::OmpClauseList ,
+   mlir::Location loc) {
   fir::FirOpBuilder  = converter.getFirOpBuilder();
-  llvm::SmallVector lowerBound, upperBound, step, linearVars,
-  linearStepVars, reductionVars;
+  DataSharingProcessor dsp(converter, loopOpClauseList, eval);
+  dsp.processStep1();
+
+  Fortran::lower::StatementContext stmtCtx;
   mlir::Value scheduleChunkClauseOperand;
-  mlir::IntegerAttr orderedClauseOperand;
+  llvm::SmallVector lowerBound, upperBound, step, reductionVars;
+  llvm::SmallVector iv;
+  llvm::SmallVector reductionDeclSymbols;
+  mlir::omp::ClauseOrderKindAttr orderClauseOperand;
+  std::size_t loopVarTypeSize;
+
+  ClauseProcessor cp(converter, loopOpClauseList);
+  cp.processCollapse(loc, eval, lowerBound, upperBound, step, iv,
+ loopVarTypeSize);
+  cp.processScheduleChunk(stmtCtx, scheduleChunkClauseOperand);
+  cp.processReduction(loc, reductionVars, reductionDeclSymbols);
+  cp.processTODO(loc, ompDirective);
+
+  // The types of lower bound, upper bound, and step are converted into the
+  // type of the loop variable if necessary.
+  mlir::Type loopVarType = getLoopVarType(converter, loopVarTypeSize);
+  for (unsigned it = 0; it < (unsigned)lowerBound.size(); it++) {
+lowerBound[it] =
+firOpBuilder.createConvert(loc, loopVarType, lowerBound[it]);
+upperBound[it] =
+firOpBuilder.createConvert(loc, loopVarType, upperBound[it]);
+step[it] = firOpBuilder.createConvert(loc, loopVarType, step[it]);
+  }
+
+  llvm::SmallVector alignedVars, nontemporalVars;
+  mlir::Value ifClauseOperand;
+  mlir::IntegerAttr simdlenClauseOperand, safelenClauseOperand;
+  cp.processIf(Fortran::parser::OmpIfClause::DirectiveNameModifier::Simd,
+   ifClauseOperand);
+  cp.processSimdlen(simdlenClauseOperand);
+  cp.processSafelen(safelenClauseOperand);
+  cp.processTODO(loc, ompDirective);
+
+  mlir::TypeRange resultType;
+  auto simdLoopOp = firOpBuilder.create(
+  loc, resultType, lowerBound, upperBound, step, alignedVars,
+  /*alignment_values=*/nullptr, ifClauseOperand, nontemporalVars,
+  orderClauseOperand, simdlenClauseOperand, safelenClauseOperand,
+  /*inclusive=*/firOpBuilder.getUnitAttr());
+  createBodyOfOp(simdLoopOp, converter, loc, eval,
+, iv,
+/*outer=*/false, );
+}
+
+static void createWsLoop(Fortran::lower::AbstractConverter ,
+ Fortran::lower::pft::Evaluation ,
+ llvm::omp::Directive ompDirective,
+ const Fortran::parser::OmpClauseList ,
+ const Fortran::parser::OmpClauseList *endClauseList,
+ mlir::Location loc) {
+  fir::FirOpBuilder  = converter.getFirOpBuilder();
+  DataSharingProcessor dsp(converter, beginClauseList, eval);
+  dsp.processStep1();
+
+  Fortran::lower::StatementContext stmtCtx;
+  mlir::Value scheduleChunkClauseOperand;
+  llvm::SmallVector lowerBound, upperBound, step, reductionVars,
+  linearVars, linearStepVars;
+  llvm::SmallVector iv;
+  llvm::SmallVector reductionDeclSymbols;
   mlir::omp::ClauseOrderKindAttr orderClauseOperand;
   mlir::omp::ClauseScheduleKindAttr scheduleValClauseOperand;
-  mlir::omp::ScheduleModifierAttr scheduleModClauseOperand;
   mlir::UnitAttr nowaitClauseOperand, scheduleSimdClauseOperand;
-  llvm::SmallVector reductionDeclSymbols;
-  Fortran::lower::StatementContext stmtCtx;
+  mlir::IntegerAttr