Skip to content

Commit 63e1034

Browse files
[Flang] Check if two ArrayConstructor's are Equal
This also includes comparing the two ImpliedDo Details: - For ArrayConstructor, check if x and y have the same elements and type - For ImpliedDo, check if x and y have the same lower, upper, stride and values
1 parent 814902a commit 63e1034

File tree

1 file changed

+43
-1
lines changed
  • flang/include/flang/Lower/Support

1 file changed

+43
-1
lines changed

flang/include/flang/Lower/Support/Utils.h

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,9 +545,51 @@ class IsEqualEvaluateExpr {
545545
return isEqual(x.proc(), y.proc()) && isEqual(x.arguments(), y.arguments());
546546
}
547547
template <typename A>
548+
static bool isEqual(const Fortran::evaluate::ImpliedDo<A> &x,
549+
const Fortran::evaluate::ImpliedDo<A> &y) {
550+
using Expr = Fortran::evaluate::Expr<A>;
551+
for (const auto &[xValue, yValue] : llvm::zip(x.values(), y.values())) {
552+
bool checkValue = Fortran::common::visit(
553+
common::visitors{
554+
[&](const Expr &v, const Expr &w) { return isEqual(v, w); },
555+
[&](const auto &, const auto &) {
556+
llvm::report_fatal_error("isEqual is not handled yet for "
557+
"the element type in ImpliedDo");
558+
return false;
559+
},
560+
},
561+
xValue.u, yValue.u);
562+
if (!checkValue) {
563+
return false;
564+
}
565+
}
566+
return isEqual(x.lower(), y.lower()) && isEqual(x.upper(), y.upper()) &&
567+
isEqual(x.stride(), y.stride());
568+
}
569+
template <typename A>
548570
static bool isEqual(const Fortran::evaluate::ArrayConstructor<A> &x,
549571
const Fortran::evaluate::ArrayConstructor<A> &y) {
550-
llvm::report_fatal_error("not implemented");
572+
for (const auto &[xValue, yValue] : llvm::zip(x, y)) {
573+
using Expr = Fortran::evaluate::Expr<A>;
574+
using ImpliedDo = Fortran::evaluate::ImpliedDo<A>;
575+
bool checkElement = Fortran::common::visit(
576+
common::visitors{
577+
[&](const Expr &v, const Expr &w) { return isEqual(v, w); },
578+
[&](const ImpliedDo &v, const ImpliedDo &w) {
579+
return isEqual(v, w);
580+
},
581+
[&](const auto &, const auto &) {
582+
llvm::report_fatal_error("isEqual is not handled yet for "
583+
"the element type in ImpliedDo");
584+
return false;
585+
},
586+
},
587+
xValue.u, yValue.u);
588+
if (!checkElement) {
589+
return false;
590+
}
591+
}
592+
return x.GetType() == y.GetType();
551593
}
552594
static bool isEqual(const Fortran::evaluate::ImpliedDoIndex &x,
553595
const Fortran::evaluate::ImpliedDoIndex &y) {

0 commit comments

Comments
 (0)