[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-05-10 Thread via llvm-branch-commits

agozillon wrote:

I made a bit of a mistake not using SPR to land this PR series, so i've ended 
up having to directly commit the PR, the associated commit for this PR can be 
found here: 
https://github.com/llvm/llvm-project/commit/435e850ba97ab567a14b6c84d2b27cadb771cb27

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


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-05-10 Thread via llvm-branch-commits

https://github.com/agozillon closed 
https://github.com/llvm/llvm-project/pull/82853
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-05-10 Thread via llvm-branch-commits

https://github.com/agozillon updated 
https://github.com/llvm/llvm-project/pull/82853

>From 21b05eee943e4f1ad20fcd8f30bd14a0a3317db6 Mon Sep 17 00:00:00 2001
From: Andrew Gozillon 
Date: Fri, 15 Mar 2024 14:13:30 -0500
Subject: [PATCH] update with minor tidying up

Created using spr 1.3.4
---
 flang/lib/Lower/OpenMP/Utils.cpp  | 2 +-
 flang/lib/Lower/OpenMP/Utils.h| 2 --
 flang/lib/Optimizer/Transforms/CMakeLists.txt | 2 +-
 3 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/flang/lib/Lower/OpenMP/Utils.cpp b/flang/lib/Lower/OpenMP/Utils.cpp
index 60aea9f5b70ab..18728e2c4c1b0 100644
--- a/flang/lib/Lower/OpenMP/Utils.cpp
+++ b/flang/lib/Lower/OpenMP/Utils.cpp
@@ -13,7 +13,6 @@
 #include "Utils.h"
 #include "Clauses.h"
 
-#include 
 #include 
 #include 
 #include 
@@ -22,6 +21,7 @@
 #include 
 #include 
 
+#include 
 #include 
 
 llvm::cl::opt treatIndexAsSection(
diff --git a/flang/lib/Lower/OpenMP/Utils.h b/flang/lib/Lower/OpenMP/Utils.h
index f45e4490c2abe..942dd4c12d87b 100644
--- a/flang/lib/Lower/OpenMP/Utils.h
+++ b/flang/lib/Lower/OpenMP/Utils.h
@@ -14,7 +14,6 @@
 #include "mlir/IR/Location.h"
 #include "mlir/IR/Value.h"
 #include "llvm/Support/CommandLine.h"
-#include 
 
 extern llvm::cl::opt treatIndexAsSection;
 extern llvm::cl::opt enableDelayedPrivatization;
@@ -36,7 +35,6 @@ class Symbol;
 namespace parser {
 struct OmpObject;
 struct OmpObjectList;
-struct Designator;
 } // namespace parser
 
 namespace lower {
diff --git a/flang/lib/Optimizer/Transforms/CMakeLists.txt 
b/flang/lib/Optimizer/Transforms/CMakeLists.txt
index ce5ce3ed1bc48..63fbe2a0658d8 100644
--- a/flang/lib/Optimizer/Transforms/CMakeLists.txt
+++ b/flang/lib/Optimizer/Transforms/CMakeLists.txt
@@ -17,8 +17,8 @@ add_flang_library(FIRTransforms
   AddDebugFoundation.cpp
   PolymorphicOpConversion.cpp
   LoopVersioning.cpp
-  OMPMapInfoFinalization.cpp
   OMPFunctionFiltering.cpp
+  OMPMapInfoFinalization.cpp
   OMPMarkDeclareTarget.cpp
   VScaleAttr.cpp
   FunctionAttr.cpp

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-05-10 Thread via llvm-branch-commits

https://github.com/agozillon updated 
https://github.com/llvm/llvm-project/pull/82853

>From 21b05eee943e4f1ad20fcd8f30bd14a0a3317db6 Mon Sep 17 00:00:00 2001
From: Andrew Gozillon 
Date: Fri, 15 Mar 2024 14:13:30 -0500
Subject: [PATCH] update with minor tidying up

Created using spr 1.3.4
---
 flang/lib/Lower/OpenMP/Utils.cpp  | 2 +-
 flang/lib/Lower/OpenMP/Utils.h| 2 --
 flang/lib/Optimizer/Transforms/CMakeLists.txt | 2 +-
 3 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/flang/lib/Lower/OpenMP/Utils.cpp b/flang/lib/Lower/OpenMP/Utils.cpp
index 60aea9f5b70ab..18728e2c4c1b0 100644
--- a/flang/lib/Lower/OpenMP/Utils.cpp
+++ b/flang/lib/Lower/OpenMP/Utils.cpp
@@ -13,7 +13,6 @@
 #include "Utils.h"
 #include "Clauses.h"
 
-#include 
 #include 
 #include 
 #include 
@@ -22,6 +21,7 @@
 #include 
 #include 
 
+#include 
 #include 
 
 llvm::cl::opt treatIndexAsSection(
diff --git a/flang/lib/Lower/OpenMP/Utils.h b/flang/lib/Lower/OpenMP/Utils.h
index f45e4490c2abe..942dd4c12d87b 100644
--- a/flang/lib/Lower/OpenMP/Utils.h
+++ b/flang/lib/Lower/OpenMP/Utils.h
@@ -14,7 +14,6 @@
 #include "mlir/IR/Location.h"
 #include "mlir/IR/Value.h"
 #include "llvm/Support/CommandLine.h"
-#include 
 
 extern llvm::cl::opt treatIndexAsSection;
 extern llvm::cl::opt enableDelayedPrivatization;
@@ -36,7 +35,6 @@ class Symbol;
 namespace parser {
 struct OmpObject;
 struct OmpObjectList;
-struct Designator;
 } // namespace parser
 
 namespace lower {
diff --git a/flang/lib/Optimizer/Transforms/CMakeLists.txt 
b/flang/lib/Optimizer/Transforms/CMakeLists.txt
index ce5ce3ed1bc48..63fbe2a0658d8 100644
--- a/flang/lib/Optimizer/Transforms/CMakeLists.txt
+++ b/flang/lib/Optimizer/Transforms/CMakeLists.txt
@@ -17,8 +17,8 @@ add_flang_library(FIRTransforms
   AddDebugFoundation.cpp
   PolymorphicOpConversion.cpp
   LoopVersioning.cpp
-  OMPMapInfoFinalization.cpp
   OMPFunctionFiltering.cpp
+  OMPMapInfoFinalization.cpp
   OMPMarkDeclareTarget.cpp
   VScaleAttr.cpp
   FunctionAttr.cpp

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-05-07 Thread via llvm-branch-commits

agozillon wrote:

Thank you all very much for the reviews across the PR stack! 

I believe I have enough acceptance for the PR stack to land now, with at least 
two reviewers per PR. So I will seek to land this PR stack in the next few days 
(on Thursday) I'll perform the final adjustments requested, rebase and test 
prior to landing.

However, if anyone has any concerns or further review comments for any 
segments, please mention them now and I can hold off the PR until they are 
addressed if necessary :-) 

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


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-05-07 Thread Sergio Afonso via llvm-branch-commits


@@ -88,6 +91,175 @@ void gatherFuncAndVarSyms(
 symbolAndClause.emplace_back(clause, *object.id());
 }
 
+int getComponentPlacementInParent(
+const Fortran::semantics::Symbol *componentSym) {
+  const auto *derived =
+  componentSym->owner()
+  .derivedTypeSpec()
+  ->typeSymbol()
+  .detailsIf();
+  assert(derived &&
+ "expected derived type details when processing component symbol");
+  int placement = 0;
+  for (auto t : derived->componentNames()) {
+if (t == componentSym->name())
+  return placement;
+placement++;
+  }
+  return -1;
+}
+
+std::optional
+getCompObjOrNull(std::optional object,
+ Fortran::semantics::SemanticsContext ) {
+  if (!object)
+return std::nullopt;
+
+  auto ref = evaluate::ExtractDataRef(*object.value().ref());
+  if (!ref)
+return std::nullopt;
+
+  if (std::get_if(>u))
+return object;
+
+  auto baseObj = getBaseObject(object.value(), semaCtx);
+  if (!baseObj)
+return std::nullopt;
+
+  return getCompObjOrNull(baseObj.value(), semaCtx);
+}
+
+llvm::SmallVector
+generateMemberPlacementIndices(const Object ,
+   Fortran::semantics::SemanticsContext ) {
+  std::list indices;
+  auto compObj = getCompObjOrNull(object, semaCtx);
+  while (compObj) {
+indices.push_front(getComponentPlacementInParent(compObj->id()));
+compObj =
+getCompObjOrNull(getBaseObject(compObj.value(), semaCtx), semaCtx);
+  }
+
+  return llvm::SmallVector{std::begin(indices), std::end(indices)};
+}
+
+static void calculateShapeAndFillIndices(
+llvm::SmallVectorImpl ,
+llvm::SmallVector ) {
+  shape.push_back(memberPlacementData.size());
+  size_t largestIndicesSize =
+  std::max_element(memberPlacementData.begin(), memberPlacementData.end(),
+   [](auto a, auto b) {
+ return a.memberPlacementIndices.size() <
+b.memberPlacementIndices.size();
+   })
+  ->memberPlacementIndices.size();
+  shape.push_back(largestIndicesSize);
+
+  // DenseElementsAttr expects a rectangular shape for the data, so all
+  // index lists have to be of the same length, this implaces -1 as filler
+  // values
+  for (auto  : memberPlacementData)
+if (v.memberPlacementIndices.size() < largestIndicesSize) {
+  auto *prevEnd = v.memberPlacementIndices.end();
+  v.memberPlacementIndices.resize(largestIndicesSize);
+  std::fill(prevEnd, v.memberPlacementIndices.end(), -1);
+}
+}
+
+mlir::DenseIntElementsAttr createDenseElementsAttrFromIndices(
+llvm::SmallVector ,
+fir::FirOpBuilder ) {
+  llvm::SmallVector shape;
+  calculateShapeAndFillIndices(shape, memberPlacementData);
+
+  llvm::SmallVector indicesFlattened = std::accumulate(
+  memberPlacementData.begin(), memberPlacementData.end(),
+  llvm::SmallVector(),
+  [](llvm::SmallVector , OmpMapMemberIndicesData ) {
+x.insert(x.end(), y.memberPlacementIndices.begin(),
+ y.memberPlacementIndices.end());
+return x;
+  });
+
+  return mlir::DenseIntElementsAttr::get(
+  mlir::VectorType::get(llvm::ArrayRef(shape),
+mlir::IntegerType::get(builder.getContext(), 32)),
+  llvm::ArrayRef(indicesFlattened));
+}
+
+void insertChildMapInfoIntoParent(
+Fortran::lower::AbstractConverter ,
+std::map> ,
+llvm::SmallVectorImpl ,
+llvm::SmallVectorImpl *mapSymTypes,
+llvm::SmallVectorImpl *mapSymLocs,
+llvm::SmallVectorImpl *mapSymbols) {
+  for (auto indices : parentMemberIndices) {
+bool parentExists = false;
+size_t parentIdx;
+for (parentIdx = 0; parentIdx < mapSymbols->size(); ++parentIdx)
+  if ((*mapSymbols)[parentIdx] == indices.first) {
+parentExists = true;
+break;
+  }
+
+if (parentExists) {
+  auto mapOp = mlir::dyn_cast(

skatrak wrote:

That's a good point. If you have a more informative message for this case, I'm 
fine with you putting that in a separate assert.

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


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-05-07 Thread Sergio Afonso via llvm-branch-commits


@@ -88,6 +91,175 @@ void gatherFuncAndVarSyms(
 symbolAndClause.emplace_back(clause, *object.id());
 }
 
+int getComponentPlacementInParent(
+const Fortran::semantics::Symbol *componentSym) {
+  const auto *derived =
+  componentSym->owner()
+  .derivedTypeSpec()
+  ->typeSymbol()
+  .detailsIf();
+  assert(derived &&
+ "expected derived type details when processing component symbol");
+  int placement = 0;
+  for (auto t : derived->componentNames()) {
+if (t == componentSym->name())
+  return placement;
+placement++;
+  }
+  return -1;
+}
+
+std::optional
+getCompObjOrNull(std::optional object,
+ Fortran::semantics::SemanticsContext ) {
+  if (!object)
+return std::nullopt;
+
+  auto ref = evaluate::ExtractDataRef(*object.value().ref());
+  if (!ref)
+return std::nullopt;
+
+  if (std::get_if(>u))
+return object;
+
+  auto baseObj = getBaseObject(object.value(), semaCtx);
+  if (!baseObj)
+return std::nullopt;
+
+  return getCompObjOrNull(baseObj.value(), semaCtx);
+}
+
+llvm::SmallVector
+generateMemberPlacementIndices(const Object ,
+   Fortran::semantics::SemanticsContext ) {
+  std::list indices;
+  auto compObj = getCompObjOrNull(object, semaCtx);
+  while (compObj) {
+indices.push_front(getComponentPlacementInParent(compObj->id()));
+compObj =
+getCompObjOrNull(getBaseObject(compObj.value(), semaCtx), semaCtx);
+  }
+
+  return llvm::SmallVector{std::begin(indices), std::end(indices)};
+}
+
+static void calculateShapeAndFillIndices(
+llvm::SmallVectorImpl ,
+llvm::SmallVector ) {

skatrak wrote:

You're right, elements in `llvm::ArrayRef` are read-only. Sorry about that, I 
hope I didn't make you waste too much time trying this!

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


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-05-07 Thread Sergio Afonso via llvm-branch-commits


@@ -97,7 +269,7 @@ getOmpObjectSymbol(const Fortran::parser::OmpObject 
) {
 if (auto *arrayEle =
 Fortran::parser::Unwrap(
 designator)) {
-  sym = GetFirstName(arrayEle->base).symbol;
+  sym = GetLastName(arrayEle->base).symbol;

skatrak wrote:

Thank you for the explanation, it does make a lot of sense to me (and hopefully 
to whoever comes by and reads the comment later).

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


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-05-07 Thread Sergio Afonso via llvm-branch-commits


@@ -116,6 +119,216 @@ void gatherFuncAndVarSyms(
 symbolAndClause.emplace_back(clause, *object.id());
 }
 
+mlir::omp::MapInfoOp
+createMapInfoOp(fir::FirOpBuilder , mlir::Location loc,
+mlir::Value baseAddr, mlir::Value varPtrPtr, std::string name,
+llvm::ArrayRef bounds,
+llvm::ArrayRef members,
+mlir::DenseIntElementsAttr membersIndex, uint64_t mapType,
+mlir::omp::VariableCaptureKind mapCaptureType, mlir::Type 
retTy,
+bool partialMap) {
+  if (auto boxTy = baseAddr.getType().dyn_cast()) {
+baseAddr = builder.create(loc, baseAddr);
+retTy = baseAddr.getType();
+  }
+
+  mlir::TypeAttr varType = mlir::TypeAttr::get(
+  llvm::cast(retTy).getElementType());
+
+  mlir::omp::MapInfoOp op = builder.create(
+  loc, retTy, baseAddr, varType, varPtrPtr, members, membersIndex, bounds,
+  builder.getIntegerAttr(builder.getIntegerType(64, false), mapType),
+  builder.getAttr(mapCaptureType),
+  builder.getStringAttr(name), builder.getBoolAttr(partialMap));
+
+  return op;
+}
+
+static int
+getComponentPlacementInParent(const Fortran::semantics::Symbol *componentSym) {
+  const auto *derived =
+  componentSym->owner()
+  .derivedTypeSpec()
+  ->typeSymbol()
+  .detailsIf();
+  assert(derived &&
+ "expected derived type details when processing component symbol");
+  for (auto [placement, name] : llvm::enumerate(derived->componentNames()))
+if (name == componentSym->name())
+  return placement;
+  return -1;
+}
+
+static std::optional
+getComponentObject(std::optional object,
+   Fortran::semantics::SemanticsContext ) {
+  if (!object)
+return std::nullopt;
+
+  auto ref = evaluate::ExtractDataRef(*object.value().ref());
+  if (!ref)
+return std::nullopt;
+
+  if (std::holds_alternative(ref->u))
+return object;
+
+  auto baseObj = getBaseObject(object.value(), semaCtx);
+  if (!baseObj)
+return std::nullopt;
+
+  return getComponentObject(baseObj.value(), semaCtx);
+}
+
+static void
+generateMemberPlacementIndices(const Object ,
+   llvm::SmallVectorImpl ,
+   Fortran::semantics::SemanticsContext ) {
+  auto compObj = getComponentObject(object, semaCtx);
+  while (compObj) {
+indices.push_back(getComponentPlacementInParent(compObj->id()));
+compObj =
+getComponentObject(getBaseObject(compObj.value(), semaCtx), semaCtx);
+  }
+
+  indices = llvm::SmallVector{llvm::reverse(indices)};
+}
+
+void addChildIndexAndMapToParent(
+const omp::Object ,
+std::map> ,
+mlir::omp::MapInfoOp ,
+Fortran::semantics::SemanticsContext ) {
+  std::optional dataRef =
+  ExtractDataRef(object.designator);
+  assert(dataRef.has_value() &&
+ "DataRef could not be extracted during mapping of derived type "
+ "cannot proceed");
+  const Fortran::semantics::Symbol *parentSym = >GetFirstSymbol();
+  assert(parentSym && "Could not find parent symbol during lower of "
+  "a component member in OpenMP map clause");
+  llvm::SmallVector indices;
+  generateMemberPlacementIndices(object, indices, semaCtx);
+  parentMemberIndices[parentSym].push_back({indices, mapOp});
+}
+
+static void calculateShapeAndFillIndices(
+llvm::SmallVectorImpl ,
+llvm::SmallVectorImpl ) {
+  shape.push_back(memberPlacementData.size());
+  size_t largestIndicesSize =
+  std::max_element(memberPlacementData.begin(), memberPlacementData.end(),
+   [](auto a, auto b) {
+ return a.memberPlacementIndices.size() <
+b.memberPlacementIndices.size();
+   })
+  ->memberPlacementIndices.size();
+  shape.push_back(largestIndicesSize);
+
+  // DenseElementsAttr expects a rectangular shape for the data, so all
+  // index lists have to be of the same length, this emplaces -1 as filler

skatrak wrote:

```suggestion
  // index lists have to be of the same length, this emplaces -1 as filler.
```

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


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-05-07 Thread Sergio Afonso via llvm-branch-commits

https://github.com/skatrak approved this pull request.

Thank you Andrew, you've addressed all my concerns so this LGTM.

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


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-05-07 Thread Sergio Afonso via llvm-branch-commits

https://github.com/skatrak edited 
https://github.com/llvm/llvm-project/pull/82853
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-05-07 Thread Sergio Afonso via llvm-branch-commits


@@ -88,6 +91,175 @@ void gatherFuncAndVarSyms(
 symbolAndClause.emplace_back(clause, *object.id());
 }
 
+int getComponentPlacementInParent(
+const Fortran::semantics::Symbol *componentSym) {
+  const auto *derived =
+  componentSym->owner()
+  .derivedTypeSpec()
+  ->typeSymbol()
+  .detailsIf();
+  assert(derived &&
+ "expected derived type details when processing component symbol");
+  int placement = 0;
+  for (auto t : derived->componentNames()) {
+if (t == componentSym->name())
+  return placement;
+placement++;
+  }
+  return -1;
+}
+
+std::optional
+getCompObjOrNull(std::optional object,
+ Fortran::semantics::SemanticsContext ) {
+  if (!object)
+return std::nullopt;
+
+  auto ref = evaluate::ExtractDataRef(*object.value().ref());
+  if (!ref)
+return std::nullopt;
+
+  if (std::get_if(>u))
+return object;
+
+  auto baseObj = getBaseObject(object.value(), semaCtx);
+  if (!baseObj)
+return std::nullopt;
+
+  return getCompObjOrNull(baseObj.value(), semaCtx);
+}
+
+llvm::SmallVector

skatrak wrote:

Yeah, I haven't seen that done often either. The comment was mainly to avoid 
hardcoding some default `SmallVector` size in the public interface of the 
function (in this case, the default one for `int`), so passing a reference 
works for me too.

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


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-05-07 Thread Sergio Afonso via llvm-branch-commits


@@ -115,8 +115,7 @@ class ClauseProcessor {
   bool processMap(
   mlir::Location currentLocation, Fortran::lower::StatementContext 
,
   mlir::omp::MapClauseOps ,
-  llvm::SmallVectorImpl *mapSyms =
-  nullptr,
+  llvm::SmallVectorImpl *mapSyms,

skatrak wrote:

I agree it doesn't look great, but in my opinion it's better to do this than to 
force the caller to pass an output list even when it won't use it because it's 
needed internally. Maybe we'll be able to improve things later as we keep 
developing this.

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


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-05-03 Thread via llvm-branch-commits

https://github.com/agozillon updated 
https://github.com/llvm/llvm-project/pull/82853

>From 21b05eee943e4f1ad20fcd8f30bd14a0a3317db6 Mon Sep 17 00:00:00 2001
From: Andrew Gozillon 
Date: Fri, 15 Mar 2024 14:13:30 -0500
Subject: [PATCH] update with minor tidying up

Created using spr 1.3.4
---
 flang/lib/Lower/OpenMP/Utils.cpp  | 2 +-
 flang/lib/Lower/OpenMP/Utils.h| 2 --
 flang/lib/Optimizer/Transforms/CMakeLists.txt | 2 +-
 3 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/flang/lib/Lower/OpenMP/Utils.cpp b/flang/lib/Lower/OpenMP/Utils.cpp
index 60aea9f5b70aba..18728e2c4c1b06 100644
--- a/flang/lib/Lower/OpenMP/Utils.cpp
+++ b/flang/lib/Lower/OpenMP/Utils.cpp
@@ -13,7 +13,6 @@
 #include "Utils.h"
 #include "Clauses.h"
 
-#include 
 #include 
 #include 
 #include 
@@ -22,6 +21,7 @@
 #include 
 #include 
 
+#include 
 #include 
 
 llvm::cl::opt treatIndexAsSection(
diff --git a/flang/lib/Lower/OpenMP/Utils.h b/flang/lib/Lower/OpenMP/Utils.h
index f45e4490c2abe7..942dd4c12d87b6 100644
--- a/flang/lib/Lower/OpenMP/Utils.h
+++ b/flang/lib/Lower/OpenMP/Utils.h
@@ -14,7 +14,6 @@
 #include "mlir/IR/Location.h"
 #include "mlir/IR/Value.h"
 #include "llvm/Support/CommandLine.h"
-#include 
 
 extern llvm::cl::opt treatIndexAsSection;
 extern llvm::cl::opt enableDelayedPrivatization;
@@ -36,7 +35,6 @@ class Symbol;
 namespace parser {
 struct OmpObject;
 struct OmpObjectList;
-struct Designator;
 } // namespace parser
 
 namespace lower {
diff --git a/flang/lib/Optimizer/Transforms/CMakeLists.txt 
b/flang/lib/Optimizer/Transforms/CMakeLists.txt
index ce5ce3ed1bc48d..63fbe2a0658d83 100644
--- a/flang/lib/Optimizer/Transforms/CMakeLists.txt
+++ b/flang/lib/Optimizer/Transforms/CMakeLists.txt
@@ -17,8 +17,8 @@ add_flang_library(FIRTransforms
   AddDebugFoundation.cpp
   PolymorphicOpConversion.cpp
   LoopVersioning.cpp
-  OMPMapInfoFinalization.cpp
   OMPFunctionFiltering.cpp
+  OMPMapInfoFinalization.cpp
   OMPMarkDeclareTarget.cpp
   VScaleAttr.cpp
   FunctionAttr.cpp

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-05-03 Thread via llvm-branch-commits

https://github.com/agozillon updated 
https://github.com/llvm/llvm-project/pull/82853

>From 21b05eee943e4f1ad20fcd8f30bd14a0a3317db6 Mon Sep 17 00:00:00 2001
From: Andrew Gozillon 
Date: Fri, 15 Mar 2024 14:13:30 -0500
Subject: [PATCH] update with minor tidying up

Created using spr 1.3.4
---
 flang/lib/Lower/OpenMP/Utils.cpp  | 2 +-
 flang/lib/Lower/OpenMP/Utils.h| 2 --
 flang/lib/Optimizer/Transforms/CMakeLists.txt | 2 +-
 3 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/flang/lib/Lower/OpenMP/Utils.cpp b/flang/lib/Lower/OpenMP/Utils.cpp
index 60aea9f5b70aba..18728e2c4c1b06 100644
--- a/flang/lib/Lower/OpenMP/Utils.cpp
+++ b/flang/lib/Lower/OpenMP/Utils.cpp
@@ -13,7 +13,6 @@
 #include "Utils.h"
 #include "Clauses.h"
 
-#include 
 #include 
 #include 
 #include 
@@ -22,6 +21,7 @@
 #include 
 #include 
 
+#include 
 #include 
 
 llvm::cl::opt treatIndexAsSection(
diff --git a/flang/lib/Lower/OpenMP/Utils.h b/flang/lib/Lower/OpenMP/Utils.h
index f45e4490c2abe7..942dd4c12d87b6 100644
--- a/flang/lib/Lower/OpenMP/Utils.h
+++ b/flang/lib/Lower/OpenMP/Utils.h
@@ -14,7 +14,6 @@
 #include "mlir/IR/Location.h"
 #include "mlir/IR/Value.h"
 #include "llvm/Support/CommandLine.h"
-#include 
 
 extern llvm::cl::opt treatIndexAsSection;
 extern llvm::cl::opt enableDelayedPrivatization;
@@ -36,7 +35,6 @@ class Symbol;
 namespace parser {
 struct OmpObject;
 struct OmpObjectList;
-struct Designator;
 } // namespace parser
 
 namespace lower {
diff --git a/flang/lib/Optimizer/Transforms/CMakeLists.txt 
b/flang/lib/Optimizer/Transforms/CMakeLists.txt
index ce5ce3ed1bc48d..63fbe2a0658d83 100644
--- a/flang/lib/Optimizer/Transforms/CMakeLists.txt
+++ b/flang/lib/Optimizer/Transforms/CMakeLists.txt
@@ -17,8 +17,8 @@ add_flang_library(FIRTransforms
   AddDebugFoundation.cpp
   PolymorphicOpConversion.cpp
   LoopVersioning.cpp
-  OMPMapInfoFinalization.cpp
   OMPFunctionFiltering.cpp
+  OMPMapInfoFinalization.cpp
   OMPMarkDeclareTarget.cpp
   VScaleAttr.cpp
   FunctionAttr.cpp

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-05-02 Thread Jan Leyonberg via llvm-branch-commits

https://github.com/jsjodin approved this pull request.

LGTM

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


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-05-01 Thread via llvm-branch-commits

agozillon wrote:

Thanks for the review @jsjodin and @skatrak I've attempted to address both of 
your comments in recent updates. 

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


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-05-01 Thread via llvm-branch-commits

https://github.com/agozillon updated 
https://github.com/llvm/llvm-project/pull/82853

>From 21b05eee943e4f1ad20fcd8f30bd14a0a3317db6 Mon Sep 17 00:00:00 2001
From: Andrew Gozillon 
Date: Fri, 15 Mar 2024 14:13:30 -0500
Subject: [PATCH] update with minor tidying up

Created using spr 1.3.4
---
 flang/lib/Lower/OpenMP/Utils.cpp  | 2 +-
 flang/lib/Lower/OpenMP/Utils.h| 2 --
 flang/lib/Optimizer/Transforms/CMakeLists.txt | 2 +-
 3 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/flang/lib/Lower/OpenMP/Utils.cpp b/flang/lib/Lower/OpenMP/Utils.cpp
index 60aea9f5b70aba..18728e2c4c1b06 100644
--- a/flang/lib/Lower/OpenMP/Utils.cpp
+++ b/flang/lib/Lower/OpenMP/Utils.cpp
@@ -13,7 +13,6 @@
 #include "Utils.h"
 #include "Clauses.h"
 
-#include 
 #include 
 #include 
 #include 
@@ -22,6 +21,7 @@
 #include 
 #include 
 
+#include 
 #include 
 
 llvm::cl::opt treatIndexAsSection(
diff --git a/flang/lib/Lower/OpenMP/Utils.h b/flang/lib/Lower/OpenMP/Utils.h
index f45e4490c2abe7..942dd4c12d87b6 100644
--- a/flang/lib/Lower/OpenMP/Utils.h
+++ b/flang/lib/Lower/OpenMP/Utils.h
@@ -14,7 +14,6 @@
 #include "mlir/IR/Location.h"
 #include "mlir/IR/Value.h"
 #include "llvm/Support/CommandLine.h"
-#include 
 
 extern llvm::cl::opt treatIndexAsSection;
 extern llvm::cl::opt enableDelayedPrivatization;
@@ -36,7 +35,6 @@ class Symbol;
 namespace parser {
 struct OmpObject;
 struct OmpObjectList;
-struct Designator;
 } // namespace parser
 
 namespace lower {
diff --git a/flang/lib/Optimizer/Transforms/CMakeLists.txt 
b/flang/lib/Optimizer/Transforms/CMakeLists.txt
index ce5ce3ed1bc48d..63fbe2a0658d83 100644
--- a/flang/lib/Optimizer/Transforms/CMakeLists.txt
+++ b/flang/lib/Optimizer/Transforms/CMakeLists.txt
@@ -17,8 +17,8 @@ add_flang_library(FIRTransforms
   AddDebugFoundation.cpp
   PolymorphicOpConversion.cpp
   LoopVersioning.cpp
-  OMPMapInfoFinalization.cpp
   OMPFunctionFiltering.cpp
+  OMPMapInfoFinalization.cpp
   OMPMarkDeclareTarget.cpp
   VScaleAttr.cpp
   FunctionAttr.cpp

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-05-01 Thread via llvm-branch-commits

https://github.com/agozillon updated 
https://github.com/llvm/llvm-project/pull/82853

>From 21b05eee943e4f1ad20fcd8f30bd14a0a3317db6 Mon Sep 17 00:00:00 2001
From: Andrew Gozillon 
Date: Fri, 15 Mar 2024 14:13:30 -0500
Subject: [PATCH] update with minor tidying up

Created using spr 1.3.4
---
 flang/lib/Lower/OpenMP/Utils.cpp  | 2 +-
 flang/lib/Lower/OpenMP/Utils.h| 2 --
 flang/lib/Optimizer/Transforms/CMakeLists.txt | 2 +-
 3 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/flang/lib/Lower/OpenMP/Utils.cpp b/flang/lib/Lower/OpenMP/Utils.cpp
index 60aea9f5b70aba..18728e2c4c1b06 100644
--- a/flang/lib/Lower/OpenMP/Utils.cpp
+++ b/flang/lib/Lower/OpenMP/Utils.cpp
@@ -13,7 +13,6 @@
 #include "Utils.h"
 #include "Clauses.h"
 
-#include 
 #include 
 #include 
 #include 
@@ -22,6 +21,7 @@
 #include 
 #include 
 
+#include 
 #include 
 
 llvm::cl::opt treatIndexAsSection(
diff --git a/flang/lib/Lower/OpenMP/Utils.h b/flang/lib/Lower/OpenMP/Utils.h
index f45e4490c2abe7..942dd4c12d87b6 100644
--- a/flang/lib/Lower/OpenMP/Utils.h
+++ b/flang/lib/Lower/OpenMP/Utils.h
@@ -14,7 +14,6 @@
 #include "mlir/IR/Location.h"
 #include "mlir/IR/Value.h"
 #include "llvm/Support/CommandLine.h"
-#include 
 
 extern llvm::cl::opt treatIndexAsSection;
 extern llvm::cl::opt enableDelayedPrivatization;
@@ -36,7 +35,6 @@ class Symbol;
 namespace parser {
 struct OmpObject;
 struct OmpObjectList;
-struct Designator;
 } // namespace parser
 
 namespace lower {
diff --git a/flang/lib/Optimizer/Transforms/CMakeLists.txt 
b/flang/lib/Optimizer/Transforms/CMakeLists.txt
index ce5ce3ed1bc48d..63fbe2a0658d83 100644
--- a/flang/lib/Optimizer/Transforms/CMakeLists.txt
+++ b/flang/lib/Optimizer/Transforms/CMakeLists.txt
@@ -17,8 +17,8 @@ add_flang_library(FIRTransforms
   AddDebugFoundation.cpp
   PolymorphicOpConversion.cpp
   LoopVersioning.cpp
-  OMPMapInfoFinalization.cpp
   OMPFunctionFiltering.cpp
+  OMPMapInfoFinalization.cpp
   OMPMarkDeclareTarget.cpp
   VScaleAttr.cpp
   FunctionAttr.cpp

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-04-30 Thread Jan Leyonberg via llvm-branch-commits

https://github.com/jsjodin commented:

Looks good, just some minor nits/comments.

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


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-04-30 Thread Jan Leyonberg via llvm-branch-commits


@@ -88,6 +91,196 @@ void gatherFuncAndVarSyms(
 symbolAndClause.emplace_back(clause, *object.id());
 }
 
+mlir::omp::MapInfoOp
+createMapInfoOp(fir::FirOpBuilder , mlir::Location loc,
+mlir::Value baseAddr, mlir::Value varPtrPtr, std::string name,
+llvm::ArrayRef bounds,
+llvm::ArrayRef members,
+mlir::DenseIntElementsAttr membersIndex, uint64_t mapType,
+mlir::omp::VariableCaptureKind mapCaptureType, mlir::Type 
retTy,
+bool partialMap) {
+  if (auto boxTy = baseAddr.getType().dyn_cast()) {
+baseAddr = builder.create(loc, baseAddr);
+retTy = baseAddr.getType();
+  }
+
+  mlir::TypeAttr varType = mlir::TypeAttr::get(
+  llvm::cast(retTy).getElementType());
+
+  mlir::omp::MapInfoOp op = builder.create(
+  loc, retTy, baseAddr, varType, varPtrPtr, members, membersIndex, bounds,
+  builder.getIntegerAttr(builder.getIntegerType(64, false), mapType),
+  builder.getAttr(mapCaptureType),
+  builder.getStringAttr(name), builder.getBoolAttr(partialMap));
+
+  return op;
+}
+
+static int
+getComponentPlacementInParent(const Fortran::semantics::Symbol *componentSym) {
+  const auto *derived =
+  componentSym->owner()
+  .derivedTypeSpec()
+  ->typeSymbol()
+  .detailsIf();
+  assert(derived &&
+ "expected derived type details when processing component symbol");
+  for (auto [placement, name] : llvm::enumerate(derived->componentNames()))
+if (name == componentSym->name())
+  return placement;
+  return -1;
+}
+
+static std::optional
+getComponentObject(std::optional object,
+   Fortran::semantics::SemanticsContext ) {
+  if (!object)
+return std::nullopt;
+
+  auto ref = evaluate::ExtractDataRef(*object.value().ref());
+  if (!ref)
+return std::nullopt;
+
+  if (std::holds_alternative(ref->u))
+return object;
+
+  auto baseObj = getBaseObject(object.value(), semaCtx);
+  if (!baseObj)
+return std::nullopt;
+
+  return getComponentObject(baseObj.value(), semaCtx);
+}
+
+void generateMemberPlacementIndices(
+const Object , llvm::SmallVectorImpl ,
+Fortran::semantics::SemanticsContext ) {
+  auto compObj = getComponentObject(object, semaCtx);
+  while (compObj) {
+indices.push_back(getComponentPlacementInParent(compObj->id()));
+compObj =
+getComponentObject(getBaseObject(compObj.value(), semaCtx), semaCtx);
+  }
+
+  indices = llvm::SmallVector{llvm::reverse(indices)};
+}
+
+static void calculateShapeAndFillIndices(
+llvm::SmallVectorImpl ,
+llvm::SmallVectorImpl ) {
+  shape.push_back(memberPlacementData.size());
+  size_t largestIndicesSize =
+  std::max_element(memberPlacementData.begin(), memberPlacementData.end(),
+   [](auto a, auto b) {
+ return a.memberPlacementIndices.size() <
+b.memberPlacementIndices.size();
+   })
+  ->memberPlacementIndices.size();
+  shape.push_back(largestIndicesSize);
+
+  // DenseElementsAttr expects a rectangular shape for the data, so all
+  // index lists have to be of the same length, this emplaces -1 as filler
+  for (auto  : memberPlacementData) {
+if (v.memberPlacementIndices.size() < largestIndicesSize) {
+  auto *prevEnd = v.memberPlacementIndices.end();
+  v.memberPlacementIndices.resize(largestIndicesSize);
+  std::fill(prevEnd, v.memberPlacementIndices.end(), -1);
+}
+  }
+}
+
+static mlir::DenseIntElementsAttr createDenseElementsAttrFromIndices(
+llvm::SmallVectorImpl ,
+fir::FirOpBuilder ) {
+  llvm::SmallVector shape;
+  calculateShapeAndFillIndices(shape, memberPlacementData);
+
+  llvm::SmallVector indicesFlattened = std::accumulate(
+  memberPlacementData.begin(), memberPlacementData.end(),
+  llvm::SmallVector(),
+  [](llvm::SmallVector , OmpMapMemberIndicesData y) {
+x.insert(x.end(), y.memberPlacementIndices.begin(),
+ y.memberPlacementIndices.end());
+return x;
+  });
+
+  return mlir::DenseIntElementsAttr::get(
+  mlir::VectorType::get(shape,
+mlir::IntegerType::get(builder.getContext(), 32)),
+  indicesFlattened);
+}
+
+void insertChildMapInfoIntoParent(
+Fortran::lower::AbstractConverter ,
+std::map> ,
+llvm::SmallVectorImpl ,
+llvm::SmallVectorImpl ,
+llvm::SmallVectorImpl *mapSymTypes,
+llvm::SmallVectorImpl *mapSymLocs) {
+  for (auto indices : parentMemberIndices) {
+bool parentExists = false;
+size_t parentIdx;
+for (parentIdx = 0; parentIdx < mapSyms.size(); ++parentIdx) {
+  if (mapSyms[parentIdx] == indices.first) {
+parentExists = true;
+break;
+  }
+}
+
+if (parentExists) {
+  auto mapOp = llvm::cast(
+  mapOperands[parentIdx].getDefiningOp());
+
+  // NOTE: To maintain appropriate SSA ordering, we move 

[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-04-30 Thread Jan Leyonberg via llvm-branch-commits


@@ -0,0 +1,260 @@
+//===- OMPMapInfoFinalization.cpp
+//---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+//===--===//
+/// \file
+/// An OpenMP dialect related pass for FIR/HLFIR which performs some
+/// pre-processing of MapInfoOp's after the module has been lowered to
+/// finalize them.
+///
+/// For example, it expands MapInfoOp's containing descriptor related
+/// types (fir::BoxType's) into multiple MapInfoOp's containing the parent
+/// descriptor and pointer member components for individual mapping,
+/// treating the descriptor type as a record type for later lowering in the
+/// OpenMP dialect.
+///
+/// The pass also adds MapInfoOp's that are members of a parent object but are
+/// not directly used in the body of a target region to its BlockArgument list
+/// to maintain consistency across all MapInfoOp's tied to a region directly or
+/// indirectly via an parent object.
+//===--===//
+
+#include "flang/Optimizer/Builder/FIRBuilder.h"
+#include "flang/Optimizer/Dialect/FIRType.h"
+#include "flang/Optimizer/Dialect/Support/KindMapping.h"
+#include "flang/Optimizer/Transforms/Passes.h"
+#include "mlir/Dialect/Func/IR/FuncOps.h"
+#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
+#include "mlir/IR/BuiltinDialect.h"
+#include "mlir/IR/BuiltinOps.h"
+#include "mlir/IR/Operation.h"
+#include "mlir/IR/SymbolTable.h"
+#include "mlir/Pass/Pass.h"
+#include "mlir/Support/LLVM.h"
+#include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/Frontend/OpenMP/OMPConstants.h"
+#include 
+
+namespace fir {
+#define GEN_PASS_DEF_OMPMAPINFOFINALIZATIONPASS
+#include "flang/Optimizer/Transforms/Passes.h.inc"
+} // namespace fir
+
+namespace {
+class OMPMapInfoFinalizationPass
+: public fir::impl::OMPMapInfoFinalizationPassBase<
+  OMPMapInfoFinalizationPass> {
+
+  void genDescriptorMemberMaps(mlir::omp::MapInfoOp op,
+   fir::FirOpBuilder ,
+   mlir::Operation *target) {
+mlir::Location loc = op.getLoc();
+mlir::Value descriptor = op.getVarPtr();
+
+// If we enter this function, but the mapped type itself is not the
+// descriptor, then it's likely the address of the descriptor so we
+// must retrieve the descriptor SSA.
+if (!fir::isTypeWithDescriptor(op.getVarType())) {
+  if (auto addrOp = mlir::dyn_cast_if_present(
+  op.getVarPtr().getDefiningOp())) {
+descriptor = addrOp.getVal();
+  }
+}
+
+// The fir::BoxOffsetOp only works with !fir.ref> types, as
+// allowing it to access non-reference box operations can cause some
+// problematic SSA IR. However, in the case of assumed shape's the type
+// is not a !fir.ref, in these cases to retrieve the appropriate
+// !fir.ref> to access the data we need to map we must
+// perform an alloca and then store to it and retrieve the data from the 
new
+// alloca.
+if (mlir::isa(descriptor.getType())) {
+  mlir::OpBuilder::InsertPoint insPt = builder.saveInsertionPoint();
+  builder.setInsertionPointToStart(builder.getAllocaBlock());
+  auto alloca = builder.create(loc, descriptor.getType());
+  builder.restoreInsertionPoint(insPt);
+  builder.create(loc, descriptor, alloca);
+  descriptor = alloca;
+}
+
+mlir::Value baseAddrAddr = builder.create(
+loc, descriptor, fir::BoxFieldAttr::base_addr);
+
+// Member of the descriptor pointing at the allocated data
+mlir::Value baseAddr = builder.create(
+loc, baseAddrAddr.getType(), descriptor,
+mlir::TypeAttr::get(llvm::cast(
+fir::unwrapRefType(baseAddrAddr.getType()))
+.getElementType()),
+baseAddrAddr, /*members=*/mlir::SmallVector{},
+/*member_index=*/mlir::DenseIntElementsAttr{}, op.getBounds(),
+builder.getIntegerAttr(builder.getIntegerType(64, false),
+   op.getMapType().value()),
+builder.getAttr(
+mlir::omp::VariableCaptureKind::ByRef),
+/*name=*/builder.getStringAttr(""),
+/*partial_map=*/builder.getBoolAttr(false));
+
+// TODO: map the addendum segment of the descriptor, similarly to the
+// above base address/data pointer member.
+
+if (auto mapClauseOwner =
+llvm::dyn_cast(target)) {
+  llvm::SmallVector newMapOps;
+  mlir::OperandRange mapOperandsArr = mapClauseOwner.getMapOperands();
+
+  for (size_t i = 0; i < mapOperandsArr.size(); ++i) {
+if (mapOperandsArr[i] == 

[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-04-30 Thread Jan Leyonberg via llvm-branch-commits


@@ -88,6 +91,196 @@ void gatherFuncAndVarSyms(
 symbolAndClause.emplace_back(clause, *object.id());
 }
 
+mlir::omp::MapInfoOp
+createMapInfoOp(fir::FirOpBuilder , mlir::Location loc,
+mlir::Value baseAddr, mlir::Value varPtrPtr, std::string name,
+llvm::ArrayRef bounds,
+llvm::ArrayRef members,
+mlir::DenseIntElementsAttr membersIndex, uint64_t mapType,
+mlir::omp::VariableCaptureKind mapCaptureType, mlir::Type 
retTy,
+bool partialMap) {
+  if (auto boxTy = baseAddr.getType().dyn_cast()) {
+baseAddr = builder.create(loc, baseAddr);
+retTy = baseAddr.getType();
+  }
+
+  mlir::TypeAttr varType = mlir::TypeAttr::get(
+  llvm::cast(retTy).getElementType());
+
+  mlir::omp::MapInfoOp op = builder.create(
+  loc, retTy, baseAddr, varType, varPtrPtr, members, membersIndex, bounds,
+  builder.getIntegerAttr(builder.getIntegerType(64, false), mapType),
+  builder.getAttr(mapCaptureType),
+  builder.getStringAttr(name), builder.getBoolAttr(partialMap));
+
+  return op;
+}
+
+static int
+getComponentPlacementInParent(const Fortran::semantics::Symbol *componentSym) {
+  const auto *derived =
+  componentSym->owner()
+  .derivedTypeSpec()
+  ->typeSymbol()
+  .detailsIf();
+  assert(derived &&
+ "expected derived type details when processing component symbol");
+  for (auto [placement, name] : llvm::enumerate(derived->componentNames()))
+if (name == componentSym->name())
+  return placement;
+  return -1;
+}
+
+static std::optional
+getComponentObject(std::optional object,
+   Fortran::semantics::SemanticsContext ) {
+  if (!object)
+return std::nullopt;
+
+  auto ref = evaluate::ExtractDataRef(*object.value().ref());
+  if (!ref)
+return std::nullopt;
+
+  if (std::holds_alternative(ref->u))
+return object;
+
+  auto baseObj = getBaseObject(object.value(), semaCtx);
+  if (!baseObj)
+return std::nullopt;
+
+  return getComponentObject(baseObj.value(), semaCtx);
+}
+
+void generateMemberPlacementIndices(
+const Object , llvm::SmallVectorImpl ,
+Fortran::semantics::SemanticsContext ) {
+  auto compObj = getComponentObject(object, semaCtx);
+  while (compObj) {
+indices.push_back(getComponentPlacementInParent(compObj->id()));
+compObj =
+getComponentObject(getBaseObject(compObj.value(), semaCtx), semaCtx);
+  }
+
+  indices = llvm::SmallVector{llvm::reverse(indices)};
+}
+
+static void calculateShapeAndFillIndices(
+llvm::SmallVectorImpl ,
+llvm::SmallVectorImpl ) {
+  shape.push_back(memberPlacementData.size());
+  size_t largestIndicesSize =
+  std::max_element(memberPlacementData.begin(), memberPlacementData.end(),
+   [](auto a, auto b) {
+ return a.memberPlacementIndices.size() <
+b.memberPlacementIndices.size();
+   })
+  ->memberPlacementIndices.size();
+  shape.push_back(largestIndicesSize);
+
+  // DenseElementsAttr expects a rectangular shape for the data, so all
+  // index lists have to be of the same length, this emplaces -1 as filler
+  for (auto  : memberPlacementData) {
+if (v.memberPlacementIndices.size() < largestIndicesSize) {
+  auto *prevEnd = v.memberPlacementIndices.end();
+  v.memberPlacementIndices.resize(largestIndicesSize);
+  std::fill(prevEnd, v.memberPlacementIndices.end(), -1);
+}
+  }
+}
+
+static mlir::DenseIntElementsAttr createDenseElementsAttrFromIndices(
+llvm::SmallVectorImpl ,
+fir::FirOpBuilder ) {
+  llvm::SmallVector shape;
+  calculateShapeAndFillIndices(shape, memberPlacementData);
+
+  llvm::SmallVector indicesFlattened = std::accumulate(
+  memberPlacementData.begin(), memberPlacementData.end(),
+  llvm::SmallVector(),
+  [](llvm::SmallVector , OmpMapMemberIndicesData y) {
+x.insert(x.end(), y.memberPlacementIndices.begin(),
+ y.memberPlacementIndices.end());
+return x;
+  });
+
+  return mlir::DenseIntElementsAttr::get(
+  mlir::VectorType::get(shape,
+mlir::IntegerType::get(builder.getContext(), 32)),
+  indicesFlattened);
+}
+
+void insertChildMapInfoIntoParent(
+Fortran::lower::AbstractConverter ,
+std::map> ,
+llvm::SmallVectorImpl ,
+llvm::SmallVectorImpl ,
+llvm::SmallVectorImpl *mapSymTypes,
+llvm::SmallVectorImpl *mapSymLocs) {
+  for (auto indices : parentMemberIndices) {
+bool parentExists = false;
+size_t parentIdx;
+for (parentIdx = 0; parentIdx < mapSyms.size(); ++parentIdx) {
+  if (mapSyms[parentIdx] == indices.first) {
+parentExists = true;
+break;
+  }
+}
+
+if (parentExists) {
+  auto mapOp = llvm::cast(
+  mapOperands[parentIdx].getDefiningOp());
+
+  // NOTE: To maintain appropriate SSA ordering, we move 

[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-04-30 Thread Jan Leyonberg via llvm-branch-commits


@@ -0,0 +1,260 @@
+//===- OMPMapInfoFinalization.cpp
+//---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+//===--===//
+/// \file
+/// An OpenMP dialect related pass for FIR/HLFIR which performs some
+/// pre-processing of MapInfoOp's after the module has been lowered to
+/// finalize them.
+///
+/// For example, it expands MapInfoOp's containing descriptor related
+/// types (fir::BoxType's) into multiple MapInfoOp's containing the parent
+/// descriptor and pointer member components for individual mapping,
+/// treating the descriptor type as a record type for later lowering in the
+/// OpenMP dialect.
+///
+/// The pass also adds MapInfoOp's that are members of a parent object but are
+/// not directly used in the body of a target region to its BlockArgument list
+/// to maintain consistency across all MapInfoOp's tied to a region directly or
+/// indirectly via an parent object.
+//===--===//
+
+#include "flang/Optimizer/Builder/FIRBuilder.h"
+#include "flang/Optimizer/Dialect/FIRType.h"
+#include "flang/Optimizer/Dialect/Support/KindMapping.h"
+#include "flang/Optimizer/Transforms/Passes.h"
+#include "mlir/Dialect/Func/IR/FuncOps.h"
+#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
+#include "mlir/IR/BuiltinDialect.h"
+#include "mlir/IR/BuiltinOps.h"
+#include "mlir/IR/Operation.h"
+#include "mlir/IR/SymbolTable.h"
+#include "mlir/Pass/Pass.h"
+#include "mlir/Support/LLVM.h"
+#include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/Frontend/OpenMP/OMPConstants.h"
+#include 
+
+namespace fir {
+#define GEN_PASS_DEF_OMPMAPINFOFINALIZATIONPASS
+#include "flang/Optimizer/Transforms/Passes.h.inc"
+} // namespace fir
+
+namespace {
+class OMPMapInfoFinalizationPass
+: public fir::impl::OMPMapInfoFinalizationPassBase<
+  OMPMapInfoFinalizationPass> {
+
+  void genDescriptorMemberMaps(mlir::omp::MapInfoOp op,
+   fir::FirOpBuilder ,
+   mlir::Operation *target) {
+mlir::Location loc = op.getLoc();
+mlir::Value descriptor = op.getVarPtr();
+
+// If we enter this function, but the mapped type itself is not the
+// descriptor, then it's likely the address of the descriptor so we
+// must retrieve the descriptor SSA.
+if (!fir::isTypeWithDescriptor(op.getVarType())) {
+  if (auto addrOp = mlir::dyn_cast_if_present(
+  op.getVarPtr().getDefiningOp())) {
+descriptor = addrOp.getVal();
+  }
+}
+
+// The fir::BoxOffsetOp only works with !fir.ref> types, as
+// allowing it to access non-reference box operations can cause some
+// problematic SSA IR. However, in the case of assumed shape's the type
+// is not a !fir.ref, in these cases to retrieve the appropriate
+// !fir.ref> to access the data we need to map we must
+// perform an alloca and then store to it and retrieve the data from the 
new
+// alloca.
+if (mlir::isa(descriptor.getType())) {
+  mlir::OpBuilder::InsertPoint insPt = builder.saveInsertionPoint();
+  builder.setInsertionPointToStart(builder.getAllocaBlock());
+  auto alloca = builder.create(loc, descriptor.getType());
+  builder.restoreInsertionPoint(insPt);
+  builder.create(loc, descriptor, alloca);
+  descriptor = alloca;
+}
+
+mlir::Value baseAddrAddr = builder.create(
+loc, descriptor, fir::BoxFieldAttr::base_addr);
+
+// Member of the descriptor pointing at the allocated data
+mlir::Value baseAddr = builder.create(
+loc, baseAddrAddr.getType(), descriptor,
+mlir::TypeAttr::get(llvm::cast(
+fir::unwrapRefType(baseAddrAddr.getType()))
+.getElementType()),
+baseAddrAddr, /*members=*/mlir::SmallVector{},
+/*member_index=*/mlir::DenseIntElementsAttr{}, op.getBounds(),
+builder.getIntegerAttr(builder.getIntegerType(64, false),
+   op.getMapType().value()),
+builder.getAttr(
+mlir::omp::VariableCaptureKind::ByRef),
+/*name=*/builder.getStringAttr(""),
+/*partial_map=*/builder.getBoolAttr(false));
+
+// TODO: map the addendum segment of the descriptor, similarly to the
+// above base address/data pointer member.
+
+if (auto mapClauseOwner =
+llvm::dyn_cast(target)) {
+  llvm::SmallVector newMapOps;
+  mlir::OperandRange mapOperandsArr = mapClauseOwner.getMapOperands();
+
+  for (size_t i = 0; i < mapOperandsArr.size(); ++i) {
+if (mapOperandsArr[i] == 

[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-04-30 Thread Jan Leyonberg via llvm-branch-commits


@@ -218,17 +224,40 @@ bool ClauseProcessor::processMotionClauses(
   // Explicit map captures are captured ByRef by default,
   // optimisation passes may alter this to ByCopy or other capture
   // types to optimise
-  mlir::Value mapOp = createMapInfoOp(
-  firOpBuilder, clauseLocation, symAddr, mlir::Value{},
-  asFortran.str(), bounds, {},
+  mlir::omp::MapInfoOp mapOp = createMapInfoOp(
+  firOpBuilder, clauseLocation, symAddr,
+  /*varPtrPtr=*/mlir::Value{}, asFortran.str(), bounds,
+  /*members=*/{}, /*membersIndex=*/mlir::DenseIntElementsAttr{},
   static_cast<
   
std::underlying_type_t>(
   mapTypeBits),
   mlir::omp::VariableCaptureKind::ByRef, symAddr.getType());
 
-  result.mapVars.push_back(mapOp);
+  if (object.id()->owner().IsDerivedType()) {
+std::optional dataRef =

jsjodin wrote:

Would it be possible to create a function for the code inside the 'if'? It 
seems like the same code exists above.

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


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-04-30 Thread Jan Leyonberg via llvm-branch-commits


@@ -0,0 +1,260 @@
+//===- OMPMapInfoFinalization.cpp
+//---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+//===--===//
+/// \file
+/// An OpenMP dialect related pass for FIR/HLFIR which performs some
+/// pre-processing of MapInfoOp's after the module has been lowered to
+/// finalize them.
+///
+/// For example, it expands MapInfoOp's containing descriptor related
+/// types (fir::BoxType's) into multiple MapInfoOp's containing the parent
+/// descriptor and pointer member components for individual mapping,
+/// treating the descriptor type as a record type for later lowering in the
+/// OpenMP dialect.
+///
+/// The pass also adds MapInfoOp's that are members of a parent object but are
+/// not directly used in the body of a target region to its BlockArgument list
+/// to maintain consistency across all MapInfoOp's tied to a region directly or
+/// indirectly via an parent object.

jsjodin wrote:

Nit: an -> a

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


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-04-30 Thread Jan Leyonberg via llvm-branch-commits

https://github.com/jsjodin edited 
https://github.com/llvm/llvm-project/pull/82853
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-04-24 Thread via llvm-branch-commits

agozillon wrote:

Performed a rebase across the entire PR stack (my appologies, I forgot that 
might make the review a little more irritating before I performed it), and made 
an attempt to address all reviewer comments and where things didn't quite work 
as expected left replies on the comments. 

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


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-04-24 Thread via llvm-branch-commits

https://github.com/agozillon updated 
https://github.com/llvm/llvm-project/pull/82853

>From 21b05eee943e4f1ad20fcd8f30bd14a0a3317db6 Mon Sep 17 00:00:00 2001
From: Andrew Gozillon 
Date: Fri, 15 Mar 2024 14:13:30 -0500
Subject: [PATCH] update with minor tidying up

Created using spr 1.3.4
---
 flang/lib/Lower/OpenMP/Utils.cpp  | 2 +-
 flang/lib/Lower/OpenMP/Utils.h| 2 --
 flang/lib/Optimizer/Transforms/CMakeLists.txt | 2 +-
 3 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/flang/lib/Lower/OpenMP/Utils.cpp b/flang/lib/Lower/OpenMP/Utils.cpp
index 60aea9f5b70aba..18728e2c4c1b06 100644
--- a/flang/lib/Lower/OpenMP/Utils.cpp
+++ b/flang/lib/Lower/OpenMP/Utils.cpp
@@ -13,7 +13,6 @@
 #include "Utils.h"
 #include "Clauses.h"
 
-#include 
 #include 
 #include 
 #include 
@@ -22,6 +21,7 @@
 #include 
 #include 
 
+#include 
 #include 
 
 llvm::cl::opt treatIndexAsSection(
diff --git a/flang/lib/Lower/OpenMP/Utils.h b/flang/lib/Lower/OpenMP/Utils.h
index f45e4490c2abe7..942dd4c12d87b6 100644
--- a/flang/lib/Lower/OpenMP/Utils.h
+++ b/flang/lib/Lower/OpenMP/Utils.h
@@ -14,7 +14,6 @@
 #include "mlir/IR/Location.h"
 #include "mlir/IR/Value.h"
 #include "llvm/Support/CommandLine.h"
-#include 
 
 extern llvm::cl::opt treatIndexAsSection;
 extern llvm::cl::opt enableDelayedPrivatization;
@@ -36,7 +35,6 @@ class Symbol;
 namespace parser {
 struct OmpObject;
 struct OmpObjectList;
-struct Designator;
 } // namespace parser
 
 namespace lower {
diff --git a/flang/lib/Optimizer/Transforms/CMakeLists.txt 
b/flang/lib/Optimizer/Transforms/CMakeLists.txt
index ce5ce3ed1bc48d..63fbe2a0658d83 100644
--- a/flang/lib/Optimizer/Transforms/CMakeLists.txt
+++ b/flang/lib/Optimizer/Transforms/CMakeLists.txt
@@ -17,8 +17,8 @@ add_flang_library(FIRTransforms
   AddDebugFoundation.cpp
   PolymorphicOpConversion.cpp
   LoopVersioning.cpp
-  OMPMapInfoFinalization.cpp
   OMPFunctionFiltering.cpp
+  OMPMapInfoFinalization.cpp
   OMPMarkDeclareTarget.cpp
   VScaleAttr.cpp
   FunctionAttr.cpp

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-04-24 Thread via llvm-branch-commits

https://github.com/agozillon updated 
https://github.com/llvm/llvm-project/pull/82853

>From 21b05eee943e4f1ad20fcd8f30bd14a0a3317db6 Mon Sep 17 00:00:00 2001
From: Andrew Gozillon 
Date: Fri, 15 Mar 2024 14:13:30 -0500
Subject: [PATCH] update with minor tidying up

Created using spr 1.3.4
---
 flang/lib/Lower/OpenMP/Utils.cpp  | 2 +-
 flang/lib/Lower/OpenMP/Utils.h| 2 --
 flang/lib/Optimizer/Transforms/CMakeLists.txt | 2 +-
 3 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/flang/lib/Lower/OpenMP/Utils.cpp b/flang/lib/Lower/OpenMP/Utils.cpp
index 60aea9f5b70aba..18728e2c4c1b06 100644
--- a/flang/lib/Lower/OpenMP/Utils.cpp
+++ b/flang/lib/Lower/OpenMP/Utils.cpp
@@ -13,7 +13,6 @@
 #include "Utils.h"
 #include "Clauses.h"
 
-#include 
 #include 
 #include 
 #include 
@@ -22,6 +21,7 @@
 #include 
 #include 
 
+#include 
 #include 
 
 llvm::cl::opt treatIndexAsSection(
diff --git a/flang/lib/Lower/OpenMP/Utils.h b/flang/lib/Lower/OpenMP/Utils.h
index f45e4490c2abe7..942dd4c12d87b6 100644
--- a/flang/lib/Lower/OpenMP/Utils.h
+++ b/flang/lib/Lower/OpenMP/Utils.h
@@ -14,7 +14,6 @@
 #include "mlir/IR/Location.h"
 #include "mlir/IR/Value.h"
 #include "llvm/Support/CommandLine.h"
-#include 
 
 extern llvm::cl::opt treatIndexAsSection;
 extern llvm::cl::opt enableDelayedPrivatization;
@@ -36,7 +35,6 @@ class Symbol;
 namespace parser {
 struct OmpObject;
 struct OmpObjectList;
-struct Designator;
 } // namespace parser
 
 namespace lower {
diff --git a/flang/lib/Optimizer/Transforms/CMakeLists.txt 
b/flang/lib/Optimizer/Transforms/CMakeLists.txt
index ce5ce3ed1bc48d..63fbe2a0658d83 100644
--- a/flang/lib/Optimizer/Transforms/CMakeLists.txt
+++ b/flang/lib/Optimizer/Transforms/CMakeLists.txt
@@ -17,8 +17,8 @@ add_flang_library(FIRTransforms
   AddDebugFoundation.cpp
   PolymorphicOpConversion.cpp
   LoopVersioning.cpp
-  OMPMapInfoFinalization.cpp
   OMPFunctionFiltering.cpp
+  OMPMapInfoFinalization.cpp
   OMPMarkDeclareTarget.cpp
   VScaleAttr.cpp
   FunctionAttr.cpp

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-04-24 Thread via llvm-branch-commits


@@ -88,6 +91,175 @@ void gatherFuncAndVarSyms(
 symbolAndClause.emplace_back(clause, *object.id());
 }
 
+int getComponentPlacementInParent(
+const Fortran::semantics::Symbol *componentSym) {
+  const auto *derived =
+  componentSym->owner()
+  .derivedTypeSpec()
+  ->typeSymbol()
+  .detailsIf();
+  assert(derived &&
+ "expected derived type details when processing component symbol");
+  int placement = 0;
+  for (auto t : derived->componentNames()) {
+if (t == componentSym->name())
+  return placement;
+placement++;
+  }
+  return -1;
+}
+
+std::optional
+getCompObjOrNull(std::optional object,
+ Fortran::semantics::SemanticsContext ) {
+  if (!object)
+return std::nullopt;
+
+  auto ref = evaluate::ExtractDataRef(*object.value().ref());
+  if (!ref)
+return std::nullopt;
+
+  if (std::get_if(>u))
+return object;
+
+  auto baseObj = getBaseObject(object.value(), semaCtx);
+  if (!baseObj)
+return std::nullopt;
+
+  return getCompObjOrNull(baseObj.value(), semaCtx);
+}
+
+llvm::SmallVector

agozillon wrote:

Opted to take it in as an argument as opposed to a return type, as returning a 
local SmallVector to a SmallVectorImpl doesn't seem like it's allowed (perhaps 
I tried it incorrectly however, but I couldn't grep a case where it seemed done 
in LLVM, my grep capabilities are possibly lacking though)

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


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-04-24 Thread via llvm-branch-commits


@@ -88,6 +91,175 @@ void gatherFuncAndVarSyms(
 symbolAndClause.emplace_back(clause, *object.id());
 }
 
+int getComponentPlacementInParent(
+const Fortran::semantics::Symbol *componentSym) {
+  const auto *derived =
+  componentSym->owner()
+  .derivedTypeSpec()
+  ->typeSymbol()
+  .detailsIf();
+  assert(derived &&
+ "expected derived type details when processing component symbol");
+  int placement = 0;
+  for (auto t : derived->componentNames()) {
+if (t == componentSym->name())
+  return placement;
+placement++;
+  }
+  return -1;
+}
+
+std::optional
+getCompObjOrNull(std::optional object,
+ Fortran::semantics::SemanticsContext ) {
+  if (!object)
+return std::nullopt;
+
+  auto ref = evaluate::ExtractDataRef(*object.value().ref());
+  if (!ref)
+return std::nullopt;
+
+  if (std::get_if(>u))
+return object;
+
+  auto baseObj = getBaseObject(object.value(), semaCtx);
+  if (!baseObj)
+return std::nullopt;
+
+  return getCompObjOrNull(baseObj.value(), semaCtx);
+}
+
+llvm::SmallVector
+generateMemberPlacementIndices(const Object ,
+   Fortran::semantics::SemanticsContext ) {
+  std::list indices;
+  auto compObj = getCompObjOrNull(object, semaCtx);
+  while (compObj) {
+indices.push_front(getComponentPlacementInParent(compObj->id()));
+compObj =
+getCompObjOrNull(getBaseObject(compObj.value(), semaCtx), semaCtx);
+  }
+
+  return llvm::SmallVector{std::begin(indices), std::end(indices)};
+}
+
+static void calculateShapeAndFillIndices(
+llvm::SmallVectorImpl ,
+llvm::SmallVector ) {

agozillon wrote:

I've opted to not change these to llvm::ArrayRef's but rather 
llvm::SmallVectorImpl's, as ArrayRef doesn't seem to play particularly nicely 
with the resize and fill.

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


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-04-24 Thread via llvm-branch-commits


@@ -0,0 +1,260 @@
+//===- OMPMapInfoFinalization.cpp
+//---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+//===--===//
+/// \file
+/// An OpenMP dialect related pass for FIR/HLFIR which performs some
+/// pre-processing of MapInfoOp's after the module has been lowered to
+/// finalize them.
+///
+/// For example, it expands MapInfoOp's containing descriptor related
+/// types (fir::BoxType's) into multiple MapInfoOp's containing the parent
+/// descriptor and pointer member components for individual mapping,
+/// treating the descriptor type as a record type for later lowering in the
+/// OpenMP dialect.
+///
+/// The pass also adds MapInfoOp's that are members of a parent object but are
+/// not directly used in the body of a target region to it's BlockArgument list
+/// to maintain consistency across all MapInfoOp's tied to a region directly or
+/// indirectly via an parent object.
+//===--===//
+
+#include "flang/Optimizer/Builder/FIRBuilder.h"
+#include "flang/Optimizer/Dialect/FIRType.h"
+#include "flang/Optimizer/Dialect/Support/KindMapping.h"
+#include "flang/Optimizer/Transforms/Passes.h"
+#include "mlir/Dialect/Func/IR/FuncOps.h"
+#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
+#include "mlir/IR/BuiltinDialect.h"
+#include "mlir/IR/BuiltinOps.h"
+#include "mlir/IR/Operation.h"
+#include "mlir/IR/SymbolTable.h"
+#include "mlir/Pass/Pass.h"
+#include "mlir/Support/LLVM.h"
+#include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/Frontend/OpenMP/OMPConstants.h"
+#include 
+
+namespace fir {
+#define GEN_PASS_DEF_OMPMAPINFOFINALIZATIONPASS
+#include "flang/Optimizer/Transforms/Passes.h.inc"
+} // namespace fir
+
+namespace {
+class OMPMapInfoFinalizationPass
+: public fir::impl::OMPMapInfoFinalizationPassBase<
+  OMPMapInfoFinalizationPass> {
+
+  void genDescriptorMemberMaps(mlir::omp::MapInfoOp op,
+   fir::FirOpBuilder ,
+   mlir::Operation *target) {
+mlir::Location loc = builder.getUnknownLoc();
+mlir::Value descriptor = op.getVarPtr();
+
+// If we enter this function, but the mapped type itself is not the
+// descriptor, then it's likely the address of the descriptor so we
+// must retrieve the descriptor SSA.
+if (!fir::isTypeWithDescriptor(op.getVarType())) {
+  if (auto addrOp = mlir::dyn_cast_if_present(
+  op.getVarPtr().getDefiningOp())) {
+descriptor = addrOp.getVal();
+  }
+}
+
+// The fir::BoxOffsetOp only works with !fir.ref> types, as
+// allowing it to access non-reference box operations can cause some
+// problematic SSA IR. However, in the case of assumed shape's the type
+// is not a !fir.ref, in these cases to retrieve the appropriate
+// !fir.ref> to access the data we need to map we must
+// perform an alloca and then store to it and retrieve the data from the 
new
+// alloca.
+if (mlir::isa(descriptor.getType())) {
+  mlir::OpBuilder::InsertPoint insPt = builder.saveInsertionPoint();
+  builder.setInsertionPointToStart(builder.getAllocaBlock());
+  auto alloca = builder.create(loc, descriptor.getType());
+  builder.restoreInsertionPoint(insPt);
+  builder.create(loc, descriptor, alloca);
+  descriptor = alloca;
+}
+
+mlir::Value baseAddrAddr = builder.create(
+loc, descriptor, fir::BoxFieldAttr::base_addr);
+
+// Member of the descriptor pointing at the allocated data
+mlir::Value baseAddr = builder.create(
+loc, baseAddrAddr.getType(), descriptor,
+mlir::TypeAttr::get(llvm::cast(
+fir::unwrapRefType(baseAddrAddr.getType()))
+.getElementType()),
+baseAddrAddr, mlir::SmallVector{},
+mlir::DenseIntElementsAttr{}, op.getBounds(),
+builder.getIntegerAttr(builder.getIntegerType(64, false),
+   op.getMapType().value()),
+builder.getAttr(
+mlir::omp::VariableCaptureKind::ByRef),
+builder.getStringAttr("") /*name*/,
+builder.getBoolAttr(false) /*partial_map*/);
+
+// TODO: map the addendum segment of the descriptor, similarly to the
+// above base address/data pointer member.
+
+if (auto mapClauseOwner =
+llvm::dyn_cast(target)) {
+  llvm::SmallVector newMapOps;
+  mlir::OperandRange mapOperandsArr = mapClauseOwner.getMapOperands();
+
+  for (size_t i = 0; i < mapOperandsArr.size(); ++i) {
+if (mapOperandsArr[i] == op) {
+  

[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-04-24 Thread via llvm-branch-commits


@@ -22,6 +22,10 @@ namespace fir {
 class FirOpBuilder;
 } // namespace fir
 
+namespace llvm::omp {
+enum class OpenMPOffloadMappingFlags : uint64_t;
+} // namespace llvm::omp

agozillon wrote:

It is no longer used! Thank you for pointing that out.

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


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-04-24 Thread via llvm-branch-commits


@@ -97,7 +269,7 @@ getOmpObjectSymbol(const Fortran::parser::OmpObject 
) {
 if (auto *arrayEle =
 Fortran::parser::Unwrap(
 designator)) {
-  sym = GetFirstName(arrayEle->base).symbol;
+  sym = GetLastName(arrayEle->base).symbol;

agozillon wrote:

>From my understanding (and someone do please chime in if I am incorrect or 
>misunderstanding), it will get the far right symbol, whereas previously it 
>would get the far left symbol. 

So given the following:

dtype1%dtype2%array[2:10]

The getFirstName method would have retrieved "dtype1", not ideal as that's not 
what the ompObject is really referencing or what we care about in the case of 
unwrapping an array as it isn't the arrays symbol.

In the case of getLastName, we'd end up with "array", which is more what we'd 
expect.  

As we never really used constructs like this with getOmpObjectSymbol before 
(from what I can tell at least) it wasn't noticeable I believe. As for 
array[2:10] either getFirstName or getLastName will resolve to "array". 

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


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-04-24 Thread via llvm-branch-commits


@@ -88,6 +91,175 @@ void gatherFuncAndVarSyms(
 symbolAndClause.emplace_back(clause, *object.id());
 }
 
+int getComponentPlacementInParent(
+const Fortran::semantics::Symbol *componentSym) {
+  const auto *derived =
+  componentSym->owner()
+  .derivedTypeSpec()
+  ->typeSymbol()
+  .detailsIf();
+  assert(derived &&
+ "expected derived type details when processing component symbol");
+  int placement = 0;
+  for (auto t : derived->componentNames()) {
+if (t == componentSym->name())
+  return placement;
+placement++;
+  }
+  return -1;
+}
+
+std::optional
+getCompObjOrNull(std::optional object,
+ Fortran::semantics::SemanticsContext ) {
+  if (!object)
+return std::nullopt;
+
+  auto ref = evaluate::ExtractDataRef(*object.value().ref());
+  if (!ref)
+return std::nullopt;
+
+  if (std::get_if(>u))
+return object;
+
+  auto baseObj = getBaseObject(object.value(), semaCtx);
+  if (!baseObj)
+return std::nullopt;
+
+  return getCompObjOrNull(baseObj.value(), semaCtx);
+}
+
+llvm::SmallVector
+generateMemberPlacementIndices(const Object ,
+   Fortran::semantics::SemanticsContext ) {
+  std::list indices;
+  auto compObj = getCompObjOrNull(object, semaCtx);
+  while (compObj) {
+indices.push_front(getComponentPlacementInParent(compObj->id()));
+compObj =
+getCompObjOrNull(getBaseObject(compObj.value(), semaCtx), semaCtx);
+  }
+
+  return llvm::SmallVector{std::begin(indices), std::end(indices)};
+}
+
+static void calculateShapeAndFillIndices(
+llvm::SmallVectorImpl ,
+llvm::SmallVector ) {
+  shape.push_back(memberPlacementData.size());
+  size_t largestIndicesSize =
+  std::max_element(memberPlacementData.begin(), memberPlacementData.end(),
+   [](auto a, auto b) {
+ return a.memberPlacementIndices.size() <
+b.memberPlacementIndices.size();
+   })
+  ->memberPlacementIndices.size();
+  shape.push_back(largestIndicesSize);
+
+  // DenseElementsAttr expects a rectangular shape for the data, so all
+  // index lists have to be of the same length, this implaces -1 as filler
+  // values
+  for (auto  : memberPlacementData)
+if (v.memberPlacementIndices.size() < largestIndicesSize) {
+  auto *prevEnd = v.memberPlacementIndices.end();
+  v.memberPlacementIndices.resize(largestIndicesSize);
+  std::fill(prevEnd, v.memberPlacementIndices.end(), -1);
+}
+}
+
+mlir::DenseIntElementsAttr createDenseElementsAttrFromIndices(
+llvm::SmallVector ,
+fir::FirOpBuilder ) {
+  llvm::SmallVector shape;
+  calculateShapeAndFillIndices(shape, memberPlacementData);
+
+  llvm::SmallVector indicesFlattened = std::accumulate(
+  memberPlacementData.begin(), memberPlacementData.end(),
+  llvm::SmallVector(),
+  [](llvm::SmallVector , OmpMapMemberIndicesData ) {
+x.insert(x.end(), y.memberPlacementIndices.begin(),
+ y.memberPlacementIndices.end());
+return x;
+  });
+
+  return mlir::DenseIntElementsAttr::get(
+  mlir::VectorType::get(llvm::ArrayRef(shape),
+mlir::IntegerType::get(builder.getContext(), 32)),
+  llvm::ArrayRef(indicesFlattened));
+}
+
+void insertChildMapInfoIntoParent(
+Fortran::lower::AbstractConverter ,
+std::map> ,
+llvm::SmallVectorImpl ,
+llvm::SmallVectorImpl *mapSymTypes,
+llvm::SmallVectorImpl *mapSymLocs,
+llvm::SmallVectorImpl *mapSymbols) {
+  for (auto indices : parentMemberIndices) {
+bool parentExists = false;
+size_t parentIdx;
+for (parentIdx = 0; parentIdx < mapSymbols->size(); ++parentIdx)
+  if ((*mapSymbols)[parentIdx] == indices.first) {
+parentExists = true;
+break;
+  }
+
+if (parentExists) {
+  auto mapOp = mlir::dyn_cast(

agozillon wrote:

I like the idea of more information in my asserts, but happy to swap to it :-)

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


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-04-24 Thread via llvm-branch-commits


@@ -88,6 +91,175 @@ void gatherFuncAndVarSyms(
 symbolAndClause.emplace_back(clause, *object.id());
 }
 
+int getComponentPlacementInParent(
+const Fortran::semantics::Symbol *componentSym) {
+  const auto *derived =
+  componentSym->owner()
+  .derivedTypeSpec()
+  ->typeSymbol()
+  .detailsIf();
+  assert(derived &&
+ "expected derived type details when processing component symbol");
+  int placement = 0;
+  for (auto t : derived->componentNames()) {
+if (t == componentSym->name())
+  return placement;
+placement++;
+  }
+  return -1;
+}
+
+std::optional
+getCompObjOrNull(std::optional object,
+ Fortran::semantics::SemanticsContext ) {
+  if (!object)
+return std::nullopt;
+
+  auto ref = evaluate::ExtractDataRef(*object.value().ref());
+  if (!ref)
+return std::nullopt;
+
+  if (std::get_if(>u))
+return object;
+
+  auto baseObj = getBaseObject(object.value(), semaCtx);
+  if (!baseObj)
+return std::nullopt;
+
+  return getCompObjOrNull(baseObj.value(), semaCtx);
+}
+
+llvm::SmallVector
+generateMemberPlacementIndices(const Object ,
+   Fortran::semantics::SemanticsContext ) {
+  std::list indices;
+  auto compObj = getCompObjOrNull(object, semaCtx);
+  while (compObj) {
+indices.push_front(getComponentPlacementInParent(compObj->id()));
+compObj =
+getCompObjOrNull(getBaseObject(compObj.value(), semaCtx), semaCtx);
+  }
+
+  return llvm::SmallVector{std::begin(indices), std::end(indices)};

agozillon wrote:

makes a lot of sense, thanks :-) 

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


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-04-24 Thread via llvm-branch-commits


@@ -115,8 +115,7 @@ class ClauseProcessor {
   bool processMap(
   mlir::Location currentLocation, Fortran::lower::StatementContext 
,
   mlir::omp::MapClauseOps ,
-  llvm::SmallVectorImpl *mapSyms =
-  nullptr,
+  llvm::SmallVectorImpl *mapSyms,

agozillon wrote:

I had this originally, it felt a little messy to me from what I recall so I 
opted for this! But if you prefer the other option and it makes more sense to 
you, I am perfectly happy with it as well :-) 

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


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-04-24 Thread via llvm-branch-commits


@@ -185,7 +184,12 @@ template 
 bool ClauseProcessor::processMotionClauses(

agozillon wrote:

I agree and have been thinking about it, as there isn't a whole lot of 
dissimilarities, most changes to processMapClauses need replicated to 
processMotionClauses and it would make testing a lot simpler! But it'd also be 
up to @ergawy I am unsure if he'd like to keep them distinct and has some 
insights into motion clauses that might make merging the two functions unideal! 

But I can make a follow up PR after the stack has landed to merge them if we 
are all happy doing so.

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


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-04-24 Thread via llvm-branch-commits


@@ -903,24 +908,39 @@ bool ClauseProcessor::processMap(
   // Explicit map captures are captured ByRef by default,
   // optimisation passes may alter this to ByCopy or other capture
   // types to optimise
-  mlir::Value mapOp = createMapInfoOp(
+  mlir::omp::MapInfoOp mapOp = createMapInfoOp(
   firOpBuilder, clauseLocation, symAddr, mlir::Value{},
-  asFortran.str(), bounds, {},
+  asFortran.str(), bounds, {}, mlir::DenseIntElementsAttr{},
   static_cast<
   
std::underlying_type_t>(
   mapTypeBits),
   mlir::omp::VariableCaptureKind::ByRef, symAddr.getType());
 
-  result.mapVars.push_back(mapOp);
-
-  if (mapSyms)
+  if (object.id()->owner().IsDerivedType()) {
+if (auto dataRef{ExtractDataRef(object.designator)}) {

agozillon wrote:

It's expected behavior as there's nothing we can really do without the 
information, we'd be missing the parent symbol required to perform the next 
steps unfortunately. So I'll emit an assert in this case, as there likely is no 
fallback (at least that I can think of).

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


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-04-24 Thread via llvm-branch-commits


@@ -811,9 +811,10 @@ mlir::omp::MapInfoOp
 createMapInfoOp(fir::FirOpBuilder , mlir::Location loc,

agozillon wrote:

I can move it :-) the implementation just seems to have missed the migration as 
the declaration exists in the Utils header. 

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


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-04-23 Thread Sergio Afonso via llvm-branch-commits


@@ -903,24 +908,39 @@ bool ClauseProcessor::processMap(
   // Explicit map captures are captured ByRef by default,
   // optimisation passes may alter this to ByCopy or other capture
   // types to optimise
-  mlir::Value mapOp = createMapInfoOp(
+  mlir::omp::MapInfoOp mapOp = createMapInfoOp(
   firOpBuilder, clauseLocation, symAddr, mlir::Value{},
-  asFortran.str(), bounds, {},
+  asFortran.str(), bounds, {}, mlir::DenseIntElementsAttr{},
   static_cast<
   
std::underlying_type_t>(
   mapTypeBits),
   mlir::omp::VariableCaptureKind::ByRef, symAddr.getType());
 
-  result.mapVars.push_back(mapOp);
-
-  if (mapSyms)
+  if (object.id()->owner().IsDerivedType()) {
+if (auto dataRef{ExtractDataRef(object.designator)}) {

skatrak wrote:

If it's a derived type and `ExtractDataRef` returns `std::nullopt`, then 
nothing will be done with the created `mapOp`, without letting the user know. 
Is that the expected behavior? If `ExtractDataRef` is always expected to return 
something in this case, then maybe we could assert instead. If not, maybe it 
should error out or at least emit a warning.

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


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-04-23 Thread Sergio Afonso via llvm-branch-commits


@@ -0,0 +1,260 @@
+//===- OMPMapInfoFinalization.cpp
+//---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+//===--===//
+/// \file
+/// An OpenMP dialect related pass for FIR/HLFIR which performs some
+/// pre-processing of MapInfoOp's after the module has been lowered to
+/// finalize them.
+///
+/// For example, it expands MapInfoOp's containing descriptor related
+/// types (fir::BoxType's) into multiple MapInfoOp's containing the parent
+/// descriptor and pointer member components for individual mapping,
+/// treating the descriptor type as a record type for later lowering in the
+/// OpenMP dialect.
+///
+/// The pass also adds MapInfoOp's that are members of a parent object but are
+/// not directly used in the body of a target region to it's BlockArgument list
+/// to maintain consistency across all MapInfoOp's tied to a region directly or
+/// indirectly via an parent object.
+//===--===//
+
+#include "flang/Optimizer/Builder/FIRBuilder.h"
+#include "flang/Optimizer/Dialect/FIRType.h"
+#include "flang/Optimizer/Dialect/Support/KindMapping.h"
+#include "flang/Optimizer/Transforms/Passes.h"
+#include "mlir/Dialect/Func/IR/FuncOps.h"
+#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
+#include "mlir/IR/BuiltinDialect.h"
+#include "mlir/IR/BuiltinOps.h"
+#include "mlir/IR/Operation.h"
+#include "mlir/IR/SymbolTable.h"
+#include "mlir/Pass/Pass.h"
+#include "mlir/Support/LLVM.h"
+#include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/Frontend/OpenMP/OMPConstants.h"
+#include 
+
+namespace fir {
+#define GEN_PASS_DEF_OMPMAPINFOFINALIZATIONPASS
+#include "flang/Optimizer/Transforms/Passes.h.inc"
+} // namespace fir
+
+namespace {
+class OMPMapInfoFinalizationPass
+: public fir::impl::OMPMapInfoFinalizationPassBase<
+  OMPMapInfoFinalizationPass> {
+
+  void genDescriptorMemberMaps(mlir::omp::MapInfoOp op,
+   fir::FirOpBuilder ,
+   mlir::Operation *target) {
+mlir::Location loc = builder.getUnknownLoc();
+mlir::Value descriptor = op.getVarPtr();
+
+// If we enter this function, but the mapped type itself is not the
+// descriptor, then it's likely the address of the descriptor so we
+// must retrieve the descriptor SSA.
+if (!fir::isTypeWithDescriptor(op.getVarType())) {
+  if (auto addrOp = mlir::dyn_cast_if_present(
+  op.getVarPtr().getDefiningOp())) {
+descriptor = addrOp.getVal();
+  }
+}
+
+// The fir::BoxOffsetOp only works with !fir.ref> types, as
+// allowing it to access non-reference box operations can cause some
+// problematic SSA IR. However, in the case of assumed shape's the type
+// is not a !fir.ref, in these cases to retrieve the appropriate
+// !fir.ref> to access the data we need to map we must
+// perform an alloca and then store to it and retrieve the data from the 
new
+// alloca.
+if (mlir::isa(descriptor.getType())) {
+  mlir::OpBuilder::InsertPoint insPt = builder.saveInsertionPoint();
+  builder.setInsertionPointToStart(builder.getAllocaBlock());
+  auto alloca = builder.create(loc, descriptor.getType());
+  builder.restoreInsertionPoint(insPt);
+  builder.create(loc, descriptor, alloca);
+  descriptor = alloca;
+}
+
+mlir::Value baseAddrAddr = builder.create(
+loc, descriptor, fir::BoxFieldAttr::base_addr);
+
+// Member of the descriptor pointing at the allocated data
+mlir::Value baseAddr = builder.create(
+loc, baseAddrAddr.getType(), descriptor,
+mlir::TypeAttr::get(llvm::cast(
+fir::unwrapRefType(baseAddrAddr.getType()))
+.getElementType()),
+baseAddrAddr, mlir::SmallVector{},
+mlir::DenseIntElementsAttr{}, op.getBounds(),
+builder.getIntegerAttr(builder.getIntegerType(64, false),
+   op.getMapType().value()),
+builder.getAttr(
+mlir::omp::VariableCaptureKind::ByRef),
+builder.getStringAttr("") /*name*/,
+builder.getBoolAttr(false) /*partial_map*/);
+
+// TODO: map the addendum segment of the descriptor, similarly to the
+// above base address/data pointer member.
+
+if (auto mapClauseOwner =
+llvm::dyn_cast(target)) {
+  llvm::SmallVector newMapOps;
+  mlir::OperandRange mapOperandsArr = mapClauseOwner.getMapOperands();
+
+  for (size_t i = 0; i < mapOperandsArr.size(); ++i) {
+if (mapOperandsArr[i] == op) {
+  

[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-04-23 Thread Sergio Afonso via llvm-branch-commits


@@ -19,7 +19,7 @@
 
 subroutine foo()
   implicit none
-
+  

skatrak wrote:

Nit: Accidental change?

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


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-04-23 Thread Sergio Afonso via llvm-branch-commits


@@ -88,6 +91,175 @@ void gatherFuncAndVarSyms(
 symbolAndClause.emplace_back(clause, *object.id());
 }
 
+int getComponentPlacementInParent(
+const Fortran::semantics::Symbol *componentSym) {
+  const auto *derived =
+  componentSym->owner()
+  .derivedTypeSpec()
+  ->typeSymbol()
+  .detailsIf();
+  assert(derived &&
+ "expected derived type details when processing component symbol");
+  int placement = 0;
+  for (auto t : derived->componentNames()) {
+if (t == componentSym->name())
+  return placement;
+placement++;
+  }
+  return -1;
+}
+
+std::optional
+getCompObjOrNull(std::optional object,

skatrak wrote:

```suggestion
getComponentObject(std::optional object,
```

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


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-04-23 Thread Sergio Afonso via llvm-branch-commits


@@ -88,6 +91,175 @@ void gatherFuncAndVarSyms(
 symbolAndClause.emplace_back(clause, *object.id());
 }
 
+int getComponentPlacementInParent(
+const Fortran::semantics::Symbol *componentSym) {
+  const auto *derived =
+  componentSym->owner()
+  .derivedTypeSpec()
+  ->typeSymbol()
+  .detailsIf();
+  assert(derived &&
+ "expected derived type details when processing component symbol");
+  int placement = 0;
+  for (auto t : derived->componentNames()) {
+if (t == componentSym->name())
+  return placement;
+placement++;
+  }
+  return -1;
+}
+
+std::optional
+getCompObjOrNull(std::optional object,
+ Fortran::semantics::SemanticsContext ) {
+  if (!object)
+return std::nullopt;
+
+  auto ref = evaluate::ExtractDataRef(*object.value().ref());
+  if (!ref)
+return std::nullopt;
+
+  if (std::get_if(>u))

skatrak wrote:

```suggestion
  if (std::holds_alternative(ref->u))
```

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


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-04-23 Thread Sergio Afonso via llvm-branch-commits


@@ -966,6 +966,7 @@ genBodyOfTargetOp(Fortran::lower::AbstractConverter 
,
 mlir::Value mapOp = createMapInfoOp(
 firOpBuilder, copyVal.getLoc(), copyVal, mlir::Value{}, name.str(),
 bounds, llvm::SmallVector{},
+mlir::DenseIntElementsAttr{},

skatrak wrote:

Nit: Add comments for unnamed arguments.

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


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-04-23 Thread Sergio Afonso via llvm-branch-commits


@@ -0,0 +1,260 @@
+//===- OMPMapInfoFinalization.cpp
+//---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+//===--===//
+/// \file
+/// An OpenMP dialect related pass for FIR/HLFIR which performs some
+/// pre-processing of MapInfoOp's after the module has been lowered to
+/// finalize them.
+///
+/// For example, it expands MapInfoOp's containing descriptor related
+/// types (fir::BoxType's) into multiple MapInfoOp's containing the parent
+/// descriptor and pointer member components for individual mapping,
+/// treating the descriptor type as a record type for later lowering in the
+/// OpenMP dialect.
+///
+/// The pass also adds MapInfoOp's that are members of a parent object but are
+/// not directly used in the body of a target region to it's BlockArgument list
+/// to maintain consistency across all MapInfoOp's tied to a region directly or
+/// indirectly via an parent object.
+//===--===//
+
+#include "flang/Optimizer/Builder/FIRBuilder.h"
+#include "flang/Optimizer/Dialect/FIRType.h"
+#include "flang/Optimizer/Dialect/Support/KindMapping.h"
+#include "flang/Optimizer/Transforms/Passes.h"
+#include "mlir/Dialect/Func/IR/FuncOps.h"
+#include "mlir/Dialect/OpenMP/OpenMPDialect.h"
+#include "mlir/IR/BuiltinDialect.h"
+#include "mlir/IR/BuiltinOps.h"
+#include "mlir/IR/Operation.h"
+#include "mlir/IR/SymbolTable.h"
+#include "mlir/Pass/Pass.h"
+#include "mlir/Support/LLVM.h"
+#include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/Frontend/OpenMP/OMPConstants.h"
+#include 
+
+namespace fir {
+#define GEN_PASS_DEF_OMPMAPINFOFINALIZATIONPASS
+#include "flang/Optimizer/Transforms/Passes.h.inc"
+} // namespace fir
+
+namespace {
+class OMPMapInfoFinalizationPass
+: public fir::impl::OMPMapInfoFinalizationPassBase<
+  OMPMapInfoFinalizationPass> {
+
+  void genDescriptorMemberMaps(mlir::omp::MapInfoOp op,
+   fir::FirOpBuilder ,
+   mlir::Operation *target) {
+mlir::Location loc = builder.getUnknownLoc();

skatrak wrote:

```suggestion
mlir::Location loc = op.getLoc();
```

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


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-04-23 Thread Sergio Afonso via llvm-branch-commits


@@ -88,6 +91,175 @@ void gatherFuncAndVarSyms(
 symbolAndClause.emplace_back(clause, *object.id());
 }
 
+int getComponentPlacementInParent(
+const Fortran::semantics::Symbol *componentSym) {
+  const auto *derived =
+  componentSym->owner()
+  .derivedTypeSpec()
+  ->typeSymbol()
+  .detailsIf();
+  assert(derived &&
+ "expected derived type details when processing component symbol");
+  int placement = 0;
+  for (auto t : derived->componentNames()) {
+if (t == componentSym->name())
+  return placement;
+placement++;
+  }
+  return -1;
+}
+
+std::optional
+getCompObjOrNull(std::optional object,
+ Fortran::semantics::SemanticsContext ) {
+  if (!object)
+return std::nullopt;
+
+  auto ref = evaluate::ExtractDataRef(*object.value().ref());
+  if (!ref)
+return std::nullopt;
+
+  if (std::get_if(>u))
+return object;
+
+  auto baseObj = getBaseObject(object.value(), semaCtx);
+  if (!baseObj)
+return std::nullopt;
+
+  return getCompObjOrNull(baseObj.value(), semaCtx);
+}
+
+llvm::SmallVector
+generateMemberPlacementIndices(const Object ,
+   Fortran::semantics::SemanticsContext ) {
+  std::list indices;
+  auto compObj = getCompObjOrNull(object, semaCtx);
+  while (compObj) {
+indices.push_front(getComponentPlacementInParent(compObj->id()));
+compObj =
+getCompObjOrNull(getBaseObject(compObj.value(), semaCtx), semaCtx);
+  }
+
+  return llvm::SmallVector{std::begin(indices), std::end(indices)};
+}
+
+static void calculateShapeAndFillIndices(
+llvm::SmallVectorImpl ,
+llvm::SmallVector ) {
+  shape.push_back(memberPlacementData.size());
+  size_t largestIndicesSize =
+  std::max_element(memberPlacementData.begin(), memberPlacementData.end(),
+   [](auto a, auto b) {
+ return a.memberPlacementIndices.size() <
+b.memberPlacementIndices.size();
+   })
+  ->memberPlacementIndices.size();
+  shape.push_back(largestIndicesSize);
+
+  // DenseElementsAttr expects a rectangular shape for the data, so all
+  // index lists have to be of the same length, this implaces -1 as filler
+  // values
+  for (auto  : memberPlacementData)

skatrak wrote:

Nit: Add braces, since the nested `if` is braced: 
https://llvm.org/docs/CodingStandards.html#id60.

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


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-04-23 Thread Sergio Afonso via llvm-branch-commits


@@ -218,17 +223,34 @@ bool ClauseProcessor::processMotionClauses(
   // Explicit map captures are captured ByRef by default,
   // optimisation passes may alter this to ByCopy or other capture
   // types to optimise
-  mlir::Value mapOp = createMapInfoOp(
+  mlir::omp::MapInfoOp mapOp = createMapInfoOp(
   firOpBuilder, clauseLocation, symAddr, mlir::Value{},
-  asFortran.str(), bounds, {},
+  asFortran.str(), bounds, {}, mlir::DenseIntElementsAttr{},
   static_cast<
   
std::underlying_type_t>(
   mapTypeBits),
   mlir::omp::VariableCaptureKind::ByRef, symAddr.getType());
 
-  result.mapVars.push_back(mapOp);
+  if (object.id()->owner().IsDerivedType()) {
+if (auto dataRef{ExtractDataRef(object.designator)}) {
+  const Fortran::semantics::Symbol *parentSym =
+  >GetFirstSymbol();
+  assert(parentSym &&
+ "Could not find parent symbol during lower of "
+ "a component member in OpenMP map clause");
+  parentMemberIndices[parentSym].push_back(
+  {generateMemberPlacementIndices(object, semaCtx), mapOp});
+}
+  } else {
+result.mapVars.push_back(mapOp);
+mapSymbols.push_back(object.id());
+  }
 }
   });
+
+  insertChildMapInfoIntoParent(converter, parentMemberIndices, result.mapVars,
+   nullptr, nullptr, );

skatrak wrote:

Nit: Add comments for unnamed arguments.

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


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-04-23 Thread Sergio Afonso via llvm-branch-commits


@@ -115,8 +115,7 @@ class ClauseProcessor {
   bool processMap(
   mlir::Location currentLocation, Fortran::lower::StatementContext 
,
   mlir::omp::MapClauseOps ,
-  llvm::SmallVectorImpl *mapSyms =
-  nullptr,
+  llvm::SmallVectorImpl *mapSyms,

skatrak wrote:

If `mapSyms` is no longer optional, then it should be passed as a reference 
rather than as a pointer here. However, I don't think it should be, since it's 
not always needed by the caller (at least currently).

I think the proper solution would be to do something like this in `processMap`:
```c++
llvm::SmallVector localMapSyms;
llvm::SmallVectorImpl *ptrMapSyms =
mapSyms ? mapSyms : 
// Use ptrMapSyms instead of mapSyms...
```
Let me know what you think.

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


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-04-23 Thread Sergio Afonso via llvm-branch-commits


@@ -1664,7 +1667,7 @@ genTargetOp(Fortran::lower::AbstractConverter ,
 
 mlir::Value mapOp = createMapInfoOp(
 firOpBuilder, baseOp.getLoc(), baseOp, mlir::Value{}, name.str(),
-bounds, {},
+bounds, {}, mlir::DenseIntElementsAttr{},

skatrak wrote:

Nit: Add comments for unnamed arguments.

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


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-04-23 Thread Sergio Afonso via llvm-branch-commits


@@ -811,9 +811,10 @@ mlir::omp::MapInfoOp
 createMapInfoOp(fir::FirOpBuilder , mlir::Location loc,

skatrak wrote:

It looks like this function belongs in Utils.cpp, rather than here. I suppose 
that change doesn't belong in this PR, but it's something to keep in mind.

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


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-04-23 Thread Sergio Afonso via llvm-branch-commits


@@ -185,7 +184,12 @@ template 
 bool ClauseProcessor::processMotionClauses(

skatrak wrote:

Not for this patch, but perhaps we should think about refactoring `processMap` 
and `processMotionClauses` to avoid code duplication for those parts that are 
shared between them.

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


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-04-23 Thread Sergio Afonso via llvm-branch-commits


@@ -903,24 +908,39 @@ bool ClauseProcessor::processMap(
   // Explicit map captures are captured ByRef by default,
   // optimisation passes may alter this to ByCopy or other capture
   // types to optimise
-  mlir::Value mapOp = createMapInfoOp(
+  mlir::omp::MapInfoOp mapOp = createMapInfoOp(
   firOpBuilder, clauseLocation, symAddr, mlir::Value{},
-  asFortran.str(), bounds, {},
+  asFortran.str(), bounds, {}, mlir::DenseIntElementsAttr{},
   static_cast<
   
std::underlying_type_t>(
   mapTypeBits),
   mlir::omp::VariableCaptureKind::ByRef, symAddr.getType());
 
-  result.mapVars.push_back(mapOp);
-
-  if (mapSyms)
+  if (object.id()->owner().IsDerivedType()) {
+if (auto dataRef{ExtractDataRef(object.designator)}) {

skatrak wrote:

```suggestion
if (auto dataRef = ExtractDataRef(object.designator)) {
```

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


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-04-23 Thread Sergio Afonso via llvm-branch-commits


@@ -1177,10 +1178,11 @@ static void genTargetDataClauses(
 llvm::SmallVectorImpl ,
 llvm::SmallVectorImpl ,
 llvm::SmallVectorImpl ) {
+  llvm::SmallVector mapSyms;

skatrak wrote:

Changes to this function can probably be reverted if `mapSyms` is made optional 
again.

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


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-04-23 Thread Sergio Afonso via llvm-branch-commits


@@ -218,17 +223,34 @@ bool ClauseProcessor::processMotionClauses(
   // Explicit map captures are captured ByRef by default,
   // optimisation passes may alter this to ByCopy or other capture
   // types to optimise
-  mlir::Value mapOp = createMapInfoOp(
+  mlir::omp::MapInfoOp mapOp = createMapInfoOp(
   firOpBuilder, clauseLocation, symAddr, mlir::Value{},

skatrak wrote:

Nit: Add comments for unnamed arguments.

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


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-04-23 Thread Sergio Afonso via llvm-branch-commits

https://github.com/skatrak commented:

Thank you for all the work here Andrew, I've got some comments but they should 
be relatively easy to address.

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


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-04-23 Thread Sergio Afonso via llvm-branch-commits


@@ -903,24 +908,39 @@ bool ClauseProcessor::processMap(
   // Explicit map captures are captured ByRef by default,
   // optimisation passes may alter this to ByCopy or other capture
   // types to optimise
-  mlir::Value mapOp = createMapInfoOp(
+  mlir::omp::MapInfoOp mapOp = createMapInfoOp(
   firOpBuilder, clauseLocation, symAddr, mlir::Value{},

skatrak wrote:

```suggestion
  firOpBuilder, clauseLocation, symAddr, 
/*varPtrPtr=*/mlir::Value{},
```

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


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-04-23 Thread Sergio Afonso via llvm-branch-commits


@@ -903,24 +908,39 @@ bool ClauseProcessor::processMap(
   // Explicit map captures are captured ByRef by default,
   // optimisation passes may alter this to ByCopy or other capture
   // types to optimise
-  mlir::Value mapOp = createMapInfoOp(
+  mlir::omp::MapInfoOp mapOp = createMapInfoOp(
   firOpBuilder, clauseLocation, symAddr, mlir::Value{},
-  asFortran.str(), bounds, {},
+  asFortran.str(), bounds, {}, mlir::DenseIntElementsAttr{},

skatrak wrote:

```suggestion
  asFortran.str(), bounds, /*members=*/{}, 
/*membersIndex=*/mlir::DenseIntElementsAttr{},
```

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


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-04-23 Thread Sergio Afonso via llvm-branch-commits

https://github.com/skatrak edited 
https://github.com/llvm/llvm-project/pull/82853
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-04-19 Thread via llvm-branch-commits

https://github.com/agozillon updated 
https://github.com/llvm/llvm-project/pull/82853

>From 21b05eee943e4f1ad20fcd8f30bd14a0a3317db6 Mon Sep 17 00:00:00 2001
From: Andrew Gozillon 
Date: Fri, 15 Mar 2024 14:13:30 -0500
Subject: [PATCH] update with minor tidying up

Created using spr 1.3.4
---
 flang/lib/Lower/OpenMP/Utils.cpp  | 2 +-
 flang/lib/Lower/OpenMP/Utils.h| 2 --
 flang/lib/Optimizer/Transforms/CMakeLists.txt | 2 +-
 3 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/flang/lib/Lower/OpenMP/Utils.cpp b/flang/lib/Lower/OpenMP/Utils.cpp
index 60aea9f5b70aba..18728e2c4c1b06 100644
--- a/flang/lib/Lower/OpenMP/Utils.cpp
+++ b/flang/lib/Lower/OpenMP/Utils.cpp
@@ -13,7 +13,6 @@
 #include "Utils.h"
 #include "Clauses.h"
 
-#include 
 #include 
 #include 
 #include 
@@ -22,6 +21,7 @@
 #include 
 #include 
 
+#include 
 #include 
 
 llvm::cl::opt treatIndexAsSection(
diff --git a/flang/lib/Lower/OpenMP/Utils.h b/flang/lib/Lower/OpenMP/Utils.h
index f45e4490c2abe7..942dd4c12d87b6 100644
--- a/flang/lib/Lower/OpenMP/Utils.h
+++ b/flang/lib/Lower/OpenMP/Utils.h
@@ -14,7 +14,6 @@
 #include "mlir/IR/Location.h"
 #include "mlir/IR/Value.h"
 #include "llvm/Support/CommandLine.h"
-#include 
 
 extern llvm::cl::opt treatIndexAsSection;
 extern llvm::cl::opt enableDelayedPrivatization;
@@ -36,7 +35,6 @@ class Symbol;
 namespace parser {
 struct OmpObject;
 struct OmpObjectList;
-struct Designator;
 } // namespace parser
 
 namespace lower {
diff --git a/flang/lib/Optimizer/Transforms/CMakeLists.txt 
b/flang/lib/Optimizer/Transforms/CMakeLists.txt
index ce5ce3ed1bc48d..63fbe2a0658d83 100644
--- a/flang/lib/Optimizer/Transforms/CMakeLists.txt
+++ b/flang/lib/Optimizer/Transforms/CMakeLists.txt
@@ -17,8 +17,8 @@ add_flang_library(FIRTransforms
   AddDebugFoundation.cpp
   PolymorphicOpConversion.cpp
   LoopVersioning.cpp
-  OMPMapInfoFinalization.cpp
   OMPFunctionFiltering.cpp
+  OMPMapInfoFinalization.cpp
   OMPMarkDeclareTarget.cpp
   VScaleAttr.cpp
   FunctionAttr.cpp

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-04-19 Thread via llvm-branch-commits

https://github.com/agozillon updated 
https://github.com/llvm/llvm-project/pull/82853

>From 21b05eee943e4f1ad20fcd8f30bd14a0a3317db6 Mon Sep 17 00:00:00 2001
From: Andrew Gozillon 
Date: Fri, 15 Mar 2024 14:13:30 -0500
Subject: [PATCH] update with minor tidying up

Created using spr 1.3.4
---
 flang/lib/Lower/OpenMP/Utils.cpp  | 2 +-
 flang/lib/Lower/OpenMP/Utils.h| 2 --
 flang/lib/Optimizer/Transforms/CMakeLists.txt | 2 +-
 3 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/flang/lib/Lower/OpenMP/Utils.cpp b/flang/lib/Lower/OpenMP/Utils.cpp
index 60aea9f5b70aba..18728e2c4c1b06 100644
--- a/flang/lib/Lower/OpenMP/Utils.cpp
+++ b/flang/lib/Lower/OpenMP/Utils.cpp
@@ -13,7 +13,6 @@
 #include "Utils.h"
 #include "Clauses.h"
 
-#include 
 #include 
 #include 
 #include 
@@ -22,6 +21,7 @@
 #include 
 #include 
 
+#include 
 #include 
 
 llvm::cl::opt treatIndexAsSection(
diff --git a/flang/lib/Lower/OpenMP/Utils.h b/flang/lib/Lower/OpenMP/Utils.h
index f45e4490c2abe7..942dd4c12d87b6 100644
--- a/flang/lib/Lower/OpenMP/Utils.h
+++ b/flang/lib/Lower/OpenMP/Utils.h
@@ -14,7 +14,6 @@
 #include "mlir/IR/Location.h"
 #include "mlir/IR/Value.h"
 #include "llvm/Support/CommandLine.h"
-#include 
 
 extern llvm::cl::opt treatIndexAsSection;
 extern llvm::cl::opt enableDelayedPrivatization;
@@ -36,7 +35,6 @@ class Symbol;
 namespace parser {
 struct OmpObject;
 struct OmpObjectList;
-struct Designator;
 } // namespace parser
 
 namespace lower {
diff --git a/flang/lib/Optimizer/Transforms/CMakeLists.txt 
b/flang/lib/Optimizer/Transforms/CMakeLists.txt
index ce5ce3ed1bc48d..63fbe2a0658d83 100644
--- a/flang/lib/Optimizer/Transforms/CMakeLists.txt
+++ b/flang/lib/Optimizer/Transforms/CMakeLists.txt
@@ -17,8 +17,8 @@ add_flang_library(FIRTransforms
   AddDebugFoundation.cpp
   PolymorphicOpConversion.cpp
   LoopVersioning.cpp
-  OMPMapInfoFinalization.cpp
   OMPFunctionFiltering.cpp
+  OMPMapInfoFinalization.cpp
   OMPMarkDeclareTarget.cpp
   VScaleAttr.cpp
   FunctionAttr.cpp

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-04-16 Thread via llvm-branch-commits

agozillon wrote:

Back from vacation, would very much love if a kind reviewer or two could please 
allocate some time to review this PR stack so I can hopefully move it further 
along in the next few weeks :-) Thank you ahead of time!

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


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-03-26 Thread via llvm-branch-commits

agozillon wrote:

Small ping for review of this PR stack if possible. I'll be away on vacation 
for two and a half weeks, but it would be excellent to come back to review 
comments on this PR stack that I can address and then make some forward 
progress on. No rush obviously as there will be a 2 week time lag before it's 
all addressed but reviews would be appreciated!  

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


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-03-22 Thread via llvm-branch-commits

agozillon wrote:

Rebased the entire stack on recent upstream changes, there was quite a few 
changes that meant some sizeable alterations to the Fortran lowering segment of 
the PR stack, but otherwise it all went smoothly. However, please do point out 
if you see anything out of the ordinary across the change set that may look 
like a rebase artifact when reviewing!

Otherwise, this PR stack is now fully ready for review so please do so if you 
have some time, it would be greatly appreciated. 


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


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-03-22 Thread via llvm-branch-commits

https://github.com/agozillon updated 
https://github.com/llvm/llvm-project/pull/82853

>From 21b05eee943e4f1ad20fcd8f30bd14a0a3317db6 Mon Sep 17 00:00:00 2001
From: Andrew Gozillon 
Date: Fri, 15 Mar 2024 14:13:30 -0500
Subject: [PATCH] update with minor tidying up

Created using spr 1.3.4
---
 flang/lib/Lower/OpenMP/Utils.cpp  | 2 +-
 flang/lib/Lower/OpenMP/Utils.h| 2 --
 flang/lib/Optimizer/Transforms/CMakeLists.txt | 2 +-
 3 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/flang/lib/Lower/OpenMP/Utils.cpp b/flang/lib/Lower/OpenMP/Utils.cpp
index 60aea9f5b70aba..18728e2c4c1b06 100644
--- a/flang/lib/Lower/OpenMP/Utils.cpp
+++ b/flang/lib/Lower/OpenMP/Utils.cpp
@@ -13,7 +13,6 @@
 #include "Utils.h"
 #include "Clauses.h"
 
-#include 
 #include 
 #include 
 #include 
@@ -22,6 +21,7 @@
 #include 
 #include 
 
+#include 
 #include 
 
 llvm::cl::opt treatIndexAsSection(
diff --git a/flang/lib/Lower/OpenMP/Utils.h b/flang/lib/Lower/OpenMP/Utils.h
index f45e4490c2abe7..942dd4c12d87b6 100644
--- a/flang/lib/Lower/OpenMP/Utils.h
+++ b/flang/lib/Lower/OpenMP/Utils.h
@@ -14,7 +14,6 @@
 #include "mlir/IR/Location.h"
 #include "mlir/IR/Value.h"
 #include "llvm/Support/CommandLine.h"
-#include 
 
 extern llvm::cl::opt treatIndexAsSection;
 extern llvm::cl::opt enableDelayedPrivatization;
@@ -36,7 +35,6 @@ class Symbol;
 namespace parser {
 struct OmpObject;
 struct OmpObjectList;
-struct Designator;
 } // namespace parser
 
 namespace lower {
diff --git a/flang/lib/Optimizer/Transforms/CMakeLists.txt 
b/flang/lib/Optimizer/Transforms/CMakeLists.txt
index ce5ce3ed1bc48d..63fbe2a0658d83 100644
--- a/flang/lib/Optimizer/Transforms/CMakeLists.txt
+++ b/flang/lib/Optimizer/Transforms/CMakeLists.txt
@@ -17,8 +17,8 @@ add_flang_library(FIRTransforms
   AddDebugFoundation.cpp
   PolymorphicOpConversion.cpp
   LoopVersioning.cpp
-  OMPMapInfoFinalization.cpp
   OMPFunctionFiltering.cpp
+  OMPMapInfoFinalization.cpp
   OMPMarkDeclareTarget.cpp
   VScaleAttr.cpp
   FunctionAttr.cpp

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-03-22 Thread via llvm-branch-commits

https://github.com/agozillon updated 
https://github.com/llvm/llvm-project/pull/82853

>From 21b05eee943e4f1ad20fcd8f30bd14a0a3317db6 Mon Sep 17 00:00:00 2001
From: Andrew Gozillon 
Date: Fri, 15 Mar 2024 14:13:30 -0500
Subject: [PATCH] update with minor tidying up

Created using spr 1.3.4
---
 flang/lib/Lower/OpenMP/Utils.cpp  | 2 +-
 flang/lib/Lower/OpenMP/Utils.h| 2 --
 flang/lib/Optimizer/Transforms/CMakeLists.txt | 2 +-
 3 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/flang/lib/Lower/OpenMP/Utils.cpp b/flang/lib/Lower/OpenMP/Utils.cpp
index 60aea9f5b70aba..18728e2c4c1b06 100644
--- a/flang/lib/Lower/OpenMP/Utils.cpp
+++ b/flang/lib/Lower/OpenMP/Utils.cpp
@@ -13,7 +13,6 @@
 #include "Utils.h"
 #include "Clauses.h"
 
-#include 
 #include 
 #include 
 #include 
@@ -22,6 +21,7 @@
 #include 
 #include 
 
+#include 
 #include 
 
 llvm::cl::opt treatIndexAsSection(
diff --git a/flang/lib/Lower/OpenMP/Utils.h b/flang/lib/Lower/OpenMP/Utils.h
index f45e4490c2abe7..942dd4c12d87b6 100644
--- a/flang/lib/Lower/OpenMP/Utils.h
+++ b/flang/lib/Lower/OpenMP/Utils.h
@@ -14,7 +14,6 @@
 #include "mlir/IR/Location.h"
 #include "mlir/IR/Value.h"
 #include "llvm/Support/CommandLine.h"
-#include 
 
 extern llvm::cl::opt treatIndexAsSection;
 extern llvm::cl::opt enableDelayedPrivatization;
@@ -36,7 +35,6 @@ class Symbol;
 namespace parser {
 struct OmpObject;
 struct OmpObjectList;
-struct Designator;
 } // namespace parser
 
 namespace lower {
diff --git a/flang/lib/Optimizer/Transforms/CMakeLists.txt 
b/flang/lib/Optimizer/Transforms/CMakeLists.txt
index ce5ce3ed1bc48d..63fbe2a0658d83 100644
--- a/flang/lib/Optimizer/Transforms/CMakeLists.txt
+++ b/flang/lib/Optimizer/Transforms/CMakeLists.txt
@@ -17,8 +17,8 @@ add_flang_library(FIRTransforms
   AddDebugFoundation.cpp
   PolymorphicOpConversion.cpp
   LoopVersioning.cpp
-  OMPMapInfoFinalization.cpp
   OMPFunctionFiltering.cpp
+  OMPMapInfoFinalization.cpp
   OMPMarkDeclareTarget.cpp
   VScaleAttr.cpp
   FunctionAttr.cpp

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-03-15 Thread via llvm-branch-commits

agozillon wrote:

The current PR stack has been updated with the aims to extend support to 
explicit derived type member mapping at arbitrary depths, and not just top 
level member mapping. The change set is slightly different, primarily in the 
sense that we now need to handle index generation in Flang and then first/last 
member selection in the lowering differently due to the new attribute type in 
use for member placement tracking (DenseIntElementsAttr, for N-D indices). 

These are the encompassing PR stack that were updated:

https://github.com/llvm/llvm-project/pull/82853
https://github.com/llvm/llvm-project/pull/82852
https://github.com/llvm/llvm-project/pull/82851
https://github.com/llvm/llvm-project/pull/82850

The only PR from the stack that is still a little in flux so I would recommend 
not reviewing for a little while (I'll add a comment when it's ready), is the 
MLIR -> LLVM-IR lowering (https://github.com/llvm/llvm-project/pull/82852), as 
it has a partially duplicate change set that's segmented into another PR 
(https://github.com/llvm/llvm-project/pull/84349) for hopefully easier/quicker 
review. Once the other has landed I hope to perform a rebase to align the stack 
completely. That being said, if you do review it, I'll do my best to apply the 
requests to the relevant PR.

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


[llvm-branch-commits] [flang] [Flang][OpenMP][MLIR] Initial derived type member map support (PR #82853)

2024-03-15 Thread via llvm-branch-commits

https://github.com/agozillon updated 
https://github.com/llvm/llvm-project/pull/82853

>From 21b05eee943e4f1ad20fcd8f30bd14a0a3317db6 Mon Sep 17 00:00:00 2001
From: Andrew Gozillon 
Date: Fri, 15 Mar 2024 14:13:30 -0500
Subject: [PATCH] update with minor tidying up

Created using spr 1.3.4
---
 flang/lib/Lower/OpenMP/Utils.cpp  | 2 +-
 flang/lib/Lower/OpenMP/Utils.h| 2 --
 flang/lib/Optimizer/Transforms/CMakeLists.txt | 2 +-
 3 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/flang/lib/Lower/OpenMP/Utils.cpp b/flang/lib/Lower/OpenMP/Utils.cpp
index 60aea9f5b70aba..18728e2c4c1b06 100644
--- a/flang/lib/Lower/OpenMP/Utils.cpp
+++ b/flang/lib/Lower/OpenMP/Utils.cpp
@@ -13,7 +13,6 @@
 #include "Utils.h"
 #include "Clauses.h"
 
-#include 
 #include 
 #include 
 #include 
@@ -22,6 +21,7 @@
 #include 
 #include 
 
+#include 
 #include 
 
 llvm::cl::opt treatIndexAsSection(
diff --git a/flang/lib/Lower/OpenMP/Utils.h b/flang/lib/Lower/OpenMP/Utils.h
index f45e4490c2abe7..942dd4c12d87b6 100644
--- a/flang/lib/Lower/OpenMP/Utils.h
+++ b/flang/lib/Lower/OpenMP/Utils.h
@@ -14,7 +14,6 @@
 #include "mlir/IR/Location.h"
 #include "mlir/IR/Value.h"
 #include "llvm/Support/CommandLine.h"
-#include 
 
 extern llvm::cl::opt treatIndexAsSection;
 extern llvm::cl::opt enableDelayedPrivatization;
@@ -36,7 +35,6 @@ class Symbol;
 namespace parser {
 struct OmpObject;
 struct OmpObjectList;
-struct Designator;
 } // namespace parser
 
 namespace lower {
diff --git a/flang/lib/Optimizer/Transforms/CMakeLists.txt 
b/flang/lib/Optimizer/Transforms/CMakeLists.txt
index ce5ce3ed1bc48d..63fbe2a0658d83 100644
--- a/flang/lib/Optimizer/Transforms/CMakeLists.txt
+++ b/flang/lib/Optimizer/Transforms/CMakeLists.txt
@@ -17,8 +17,8 @@ add_flang_library(FIRTransforms
   AddDebugFoundation.cpp
   PolymorphicOpConversion.cpp
   LoopVersioning.cpp
-  OMPMapInfoFinalization.cpp
   OMPFunctionFiltering.cpp
+  OMPMapInfoFinalization.cpp
   OMPMarkDeclareTarget.cpp
   VScaleAttr.cpp
   FunctionAttr.cpp

___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits