[flang-commits] [flang] [Flang] add support for collapsed io calls for implicit do loops (PR #212646)
via flang-commits
flang-commits at lists.llvm.org
Wed Jul 29 02:00:50 PDT 2026
================
@@ -701,6 +701,244 @@ static mlir::func::FuncOp getOutputFunc(mlir::Location loc,
builder);
}
+/// Return the evaluate expression of a non-implied-do io item, or nullptr if
+/// the item is itself an io-implied-do.
+static const Fortran::lower::SomeExpr *
+getIoItemLeafExpr(const Fortran::parser::OutputItem &item) {
+ if (const auto *parserExpr = std::get_if<Fortran::parser::Expr>(&item.u))
+ return Fortran::semantics::GetExpr(*parserExpr);
+ return nullptr;
+}
+static const Fortran::lower::SomeExpr *
+getIoItemLeafExpr(const Fortran::parser::InputItem &item) {
+ if (const auto *var = std::get_if<Fortran::parser::Variable>(&item.u))
+ return Fortran::semantics::GetExpr(*var);
+ return nullptr;
+}
+
+template <typename A>
+static bool ioExprReferencesSymbol(const A &expr,
+ const Fortran::semantics::Symbol &sym) {
+ const Fortran::semantics::Symbol &ultimate = sym.GetUltimate();
+ for (const Fortran::semantics::SymbolRef &ref :
+ Fortran::evaluate::CollectSymbols(expr)) {
+ if (&ref->GetUltimate() == &ultimate)
+ return true;
+ }
+ return false;
+}
----------------
jeanPerier wrote:
Looking at the symbol is likely not enough, the symbol could be associated to another one appearing in the expression via equivalence, pointer association, associate construct, or anything in Fortran that allows two symbols to point to the same thing.
I think this may justify delaying it to an IR rewrite so that we can leverage FIR alias analysis.
https://github.com/llvm/llvm-project/pull/212646
More information about the flang-commits
mailing list