[flang-commits] [flang] [flang][openacc] Keep constant bounds in reduction recipe when it is all constants (PR #67827)

Slava Zakharin via flang-commits flang-commits at lists.llvm.org
Mon Oct 2 13:57:28 PDT 2023


================
@@ -478,6 +478,34 @@ mlir::acc::FirstprivateRecipeOp Fortran::lower::createOrGetFirstprivateRecipe(
   return recipe;
 }
 
+/// Get a string representation of the bounds.
+std::string getBoundsString(llvm::SmallVector<mlir::Value> &bounds) {
+  std::stringstream boundStr;
+  bool addSeparator = false;
+  if (!bounds.empty())
+    boundStr << "_section_";
+  for (auto bound : bounds) {
+    auto boundsOp =
+        mlir::dyn_cast<mlir::acc::DataBoundsOp>(bound.getDefiningOp());
+    if (boundsOp.getLowerbound() &&
+        fir::getIntIfConstant(boundsOp.getLowerbound()) &&
+        boundsOp.getUpperbound() &&
+        fir::getIntIfConstant(boundsOp.getUpperbound())) {
+      boundStr << "lb" << *fir::getIntIfConstant(boundsOp.getUpperbound())
+               << ".ub" << *fir::getIntIfConstant(boundsOp.getLowerbound());
+    } else if (boundsOp.getExtent() &&
+               fir::getIntIfConstant(boundsOp.getExtent())) {
+      boundStr << "ext" << *fir::getIntIfConstant(boundsOp.getExtent());
+    } else {
+      boundStr << "?";
+    }
+    if (addSeparator)
+      boundStr << "x";
----------------
vzakhari wrote:

I am not sure I understand the separator placement.  Did you want to do this at the beginning of the loop?  If yes, then probably `llvm::interleave` is a better choice here.

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


More information about the flang-commits mailing list