@@ -2757,11 +2757,8 @@ class ArrayExprLowering {
2757
2757
const Fortran::evaluate::Expr<Fortran::evaluate::SomeType> &exp) {
2758
2758
auto resTy = explicitSpace ? destination->getResult (0 ).getType ()
2759
2759
: converter.genType (exp);
2760
- bool explicitScalar = explicitSpace && exp.Rank () == 0 ;
2761
2760
return std::visit (
2762
- [&](const auto &e) {
2763
- return lowerArrayExpression (genarr (e), resTy, explicitScalar);
2764
- },
2761
+ [&](const auto &e) { return lowerArrayExpression (genarr (e), resTy); },
2765
2762
exp.u );
2766
2763
}
2767
2764
ExtValue lowerArrayExpression (const ExtValue &exv) {
@@ -2788,15 +2785,15 @@ class ArrayExprLowering {
2788
2785
// / Otherwise, \p resultTy is ignored and the expression is evaluated
2789
2786
// / in the destination. \p f is a continuation built from an
2790
2787
// / evaluate::Expr or an ExtendedValue.
2791
- ExtValue lowerArrayExpression (CC f, mlir::Type resultTy,
2792
- bool explicitScalar = false ) {
2788
+ ExtValue lowerArrayExpression (CC f, mlir::Type resultTy) {
2793
2789
auto loc = getLoc ();
2794
2790
auto [iterSpace, insPt] = genIterSpace (resultTy);
2795
- auto rhsIterSpace = iterSpace;
2791
+ # if 0
2796
2792
if (explicitScalar)
2797
2793
rhsIterSpace.removeImplicit();
2794
+ #endif
2798
2795
auto innerArg = iterSpace.innerArgument ();
2799
- auto exv = f (rhsIterSpace );
2796
+ auto exv = f (iterSpace );
2800
2797
mlir::Value upd;
2801
2798
if (ccDest.hasValue ()) {
2802
2799
auto element = fir::getBase (exv);
@@ -4435,7 +4432,8 @@ class ArrayExprLowering {
4435
4432
4436
4433
RaiseRT
4437
4434
raiseToArray (const Fortran::evaluate::DataRef &x,
4438
- llvm::ArrayRef<const Fortran::semantics::Symbol *> ctrlSet) {
4435
+ llvm::ArrayRef<const Fortran::semantics::Symbol *> ctrlSet,
4436
+ bool isScalar) {
4439
4437
return std::visit (
4440
4438
Fortran::common::visitors{
4441
4439
[&](const Fortran::semantics::SymbolRef &s) -> RaiseRT {
@@ -4449,13 +4447,16 @@ class ArrayExprLowering {
4449
4447
TODO (getLoc (), " coarray reference" );
4450
4448
return {llvm::None, mlir::Type{}, false , false };
4451
4449
},
4452
- [&](const auto &y) -> RaiseRT { return raiseToArray (y, ctrlSet); }},
4450
+ [&](const auto &y) -> RaiseRT {
4451
+ return raiseToArray (y, ctrlSet, isScalar);
4452
+ }},
4453
4453
x.u );
4454
4454
}
4455
4455
RaiseRT
4456
4456
raiseToArray (const Fortran::evaluate::Component &x,
4457
- llvm::ArrayRef<const Fortran::semantics::Symbol *> ctrlSet) {
4458
- auto [fopt, ty, inrank, ranked] = raiseToArray (x.base (), ctrlSet);
4457
+ llvm::ArrayRef<const Fortran::semantics::Symbol *> ctrlSet,
4458
+ bool isScalar) {
4459
+ auto [fopt, ty, inrank, ranked] = raiseToArray (x.base (), ctrlSet, isScalar);
4459
4460
if (fopt.hasValue ()) {
4460
4461
if (!ranked && x.Rank () > 0 ) {
4461
4462
auto [fopt2, ty2] = raiseRankedComponent (fopt, x, ty);
@@ -4472,7 +4473,8 @@ class ArrayExprLowering {
4472
4473
}
4473
4474
RaiseRT
4474
4475
raiseToArray (const Fortran::evaluate::ArrayRef &x,
4475
- llvm::ArrayRef<const Fortran::semantics::Symbol *> ctrlSet) {
4476
+ llvm::ArrayRef<const Fortran::semantics::Symbol *> ctrlSet,
4477
+ bool isScalar) {
4476
4478
const auto &base = x.base ();
4477
4479
auto accessUsesControlVariable = [&]() {
4478
4480
for (const auto &subs : x.subscript ())
@@ -4502,16 +4504,16 @@ class ArrayExprLowering {
4502
4504
}
4503
4505
// Otherwise, it's a component.
4504
4506
auto [fopt, ty, inrank, ranked] =
4505
- raiseToArray (base.GetComponent (), ctrlSet);
4507
+ raiseToArray (base.GetComponent (), ctrlSet, isScalar );
4506
4508
if (fopt.hasValue ())
4507
- return RaiseRT{fopt, ty, inrank, ranked };
4509
+ return RaiseRT{fopt, ty, inrank, x. Rank () > 0 };
4508
4510
if (x.Rank () > 0 || accessUsesControlVariable ()) {
4509
4511
auto [fopt2, ty2] = raiseBase (base.GetComponent ());
4510
4512
return RaiseRT{fopt2, ty2, inrank, x.Rank () > 0 };
4511
4513
}
4512
4514
return RaiseRT{fopt, ty, inrank, ranked};
4513
4515
}(),
4514
- x);
4516
+ x, isScalar );
4515
4517
}
4516
4518
static mlir::Type unwrapBoxEleTy (mlir::Type ty) {
4517
4519
if (auto boxTy = ty.dyn_cast <fir::BoxType>()) {
@@ -4556,7 +4558,7 @@ class ArrayExprLowering {
4556
4558
return {};
4557
4559
}
4558
4560
RaiseRT raiseSubscript (const RaiseRT &tup,
4559
- const Fortran::evaluate::ArrayRef &x) {
4561
+ const Fortran::evaluate::ArrayRef &x, bool isScalar ) {
4560
4562
auto fopt = std::get<llvm::Optional<CC>>(tup);
4561
4563
if (fopt.hasValue ()) {
4562
4564
auto arrTy = std::get<mlir::Type>(tup);
@@ -4635,8 +4637,14 @@ class ArrayExprLowering {
4635
4637
}
4636
4638
}
4637
4639
auto one = builder.createIntegerConstant (loc, idxTy, 1 );
4640
+ llvm::errs () << " DBG: " << isScalar << ' ' << implicitArguments << ' '
4641
+ << x.GetFirstSymbol () << ' \n ' ;
4638
4642
auto pc = [=](IterSpace iters) {
4639
4643
IterationSpace newIters = iters;
4644
+ if (isScalar) {
4645
+ newIters.removeImplicit ();
4646
+ assert (!implicitArguments);
4647
+ }
4640
4648
const auto firstImplicitIndex = iters.beginImplicitIndex ();
4641
4649
auto implicitIndex = iters.endImplicitIndex ();
4642
4650
assert (firstImplicitIndex <= implicitIndex);
@@ -4724,7 +4732,7 @@ class ArrayExprLowering {
4724
4732
// / variables, i.e. `array(func(i))`, are not.
4725
4733
template <typename A>
4726
4734
CC raiseToArray (const A &x) {
4727
- auto tup = raiseToArray (x, collectControlSymbols ());
4735
+ auto tup = raiseToArray (x, collectControlSymbols (), x. Rank () == 0 );
4728
4736
auto fopt = std::get<llvm::Optional<CC>>(tup);
4729
4737
assert (fopt.hasValue () && " continuation must be returned" );
4730
4738
return fopt.getValue ();
0 commit comments