[flang-commits] [flang] [flang][Lower] Convert OMP Map and related functions to evaluate::Expr (PR #81626)

Krzysztof Parzyszek via flang-commits flang-commits at lists.llvm.org
Wed Mar 20 06:24:57 PDT 2024


================
@@ -993,150 +1065,157 @@ genBoundsOps(fir::FirOpBuilder &builder, mlir::Location loc,
   return bounds;
 }
 
-template <typename ObjectType, typename BoundsOp, typename BoundsType>
+namespace detail {
+template <typename Ref, typename Expr> //
+std::optional<Ref> getRef(Expr &&expr) {
+  if constexpr (std::is_same_v<llvm::remove_cvref_t<Expr>,
+                               Fortran::evaluate::DataRef>) {
+    if (auto *ref = std::get_if<Ref>(&expr.u))
+      return *ref;
+    return std::nullopt;
+  } else {
+    auto maybeRef = Fortran::evaluate::ExtractDataRef(expr);
+    if (!maybeRef || !std::holds_alternative<Ref>(maybeRef->u))
+      return std::nullopt;
+    return std::get<Ref>(maybeRef->u);
+  }
+}
+} // namespace detail
+
+template <typename BoundsOp, typename BoundsType>
 AddrAndBoundsInfo gatherDataOperandAddrAndBounds(
     Fortran::lower::AbstractConverter &converter, fir::FirOpBuilder &builder,
-    Fortran::semantics::SemanticsContext &semanticsContext,
-    Fortran::lower::StatementContext &stmtCtx, const ObjectType &object,
+    semantics::SemanticsContext &semaCtx,
+    Fortran::lower::StatementContext &stmtCtx,
+    Fortran::semantics::SymbolRef symbol,
+    const Fortran::semantics::MaybeExpr &maybeDesignator,
     mlir::Location operandLocation, std::stringstream &asFortran,
     llvm::SmallVector<mlir::Value> &bounds, bool treatIndexAsSection = false) {
+  using namespace Fortran;
+
   AddrAndBoundsInfo info;
-  std::visit(
----------------
kparzysz wrote:

The biggest change in this code was eliminating the call to `std::visit`, and instead handling the two cases for a former OmpObject object individually:
- if the object was just a Name, it won't have a designator (which is now provided as an argument)
- otherwise the designator will be non-nullopt.

In addition to that the nested call to AnalyzeExpr was no longer needed, which together shifted the code starting at line 1009 (in the old version) to the left.  The new version is basically the interior of the "designator" visitor reformatted, with potential adjustments to handle new arguments instead of the old ones.

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


More information about the flang-commits mailing list