This is an archive of the discontinued LLVM Phabricator instance.

[flang] Lower component-ref to hlfir.designate
ClosedPublic

Authored by jeanPerier on Jan 11 2023, 1:50 AM.

Details

Summary

Implement the visit of component refs in DesignatorBuilder.
The ArrayRef code has to be updated a bit to cope with the
case where the base is an array and the component is also an
array.

Improve the result type of array sections designators (only return
a fir.box if the array section is not contiguous/has dynamic extent).
This required exposing IsContiguous entry point for different
front-end designator nodes (the implementation already existed,
but was internal to check-expression.cpp).

Diff Detail

Event Timeline

jeanPerier created this revision.Jan 11 2023, 1:50 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 11 2023, 1:50 AM
jeanPerier requested review of this revision.Jan 11 2023, 1:50 AM
PeteSteinfeld requested changes to this revision.Jan 11 2023, 7:34 AM

A few nits and questions, but my build failed and should be fixed.

flang/include/flang/Optimizer/Builder/HLFIRTools.h
228

Should read "is not allowed"

flang/lib/Lower/ConvertExprToHLFIR.cpp
110

Should read "need a fir.box"

385–389

Shouldn't this function be checking the value of the lower bound?

426–503

This sentence is a little awkward. Does this work -- "Called from contexts where the component is expected to be the base of an ArrayRef."?

449

"compute" should read "computes".

451

Did you leave something out here? The sentence "This entry points allows." seems incomplete.

flang/lib/Optimizer/Builder/HLFIRTools.cpp
348–349

When I build this code, I get a compilation error here. I'm using GCC 9.3.0. Here's the relevant excerpt from the build's log file:

/local/home/psteinfeld/main/cref/flang/lib/Optimizer/Builder/HLFIRTools.cpp: In function ‘llvm::SmallVector<std::pair<mlir::Value, mlir::Value> > hlfir::genBounds(mlir::Location, fir::FirOpBuilder&, mlir::Value)’:
/local/home/psteinfeld/main/cref/flang/lib/Optimizer/Builder/HLFIRTools.cpp:349:48: error: suggest parentheses around ‘&&’ within ‘||’ [-Werror=parentheses]
  349 |          shape.getType().isa<fir::ShapeType>() && "shape must contain extents");
      |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
At global scope:
cc1plus: error: unrecognized command line option ‘-Wno-ctad-maybe-unsupported’ [-Werror]
cc1plus: all warnings being treated as errors
This revision now requires changes to proceed.Jan 11 2023, 7:34 AM
jeanPerier marked 5 inline comments as done.

Fix warning caught by Pete's build and rephrase some comments
as suggested (thanks Pete!).

A few nits and questions, but my build failed and should be fixed.

Thanks @PeteSteinfeld, I rephrased the comments and the warning should be gone.

flang/lib/Lower/ConvertExprToHLFIR.cpp
385–389

You mean, to check that they are not all ones ?

No, this was already done when generating the fir.shift/fir.shape_shift (either here via the hasNonDefaultLowerBounds that checks for the value for component array lower bounds (when possible of course), or when converting symbols specification expression at [1] before lowering the subprogram body). Worst case, it is not a correctness issue to do computation with lower bounds that are all ones.

[1] https://github.com/llvm/llvm-project/blob/b71bbbb64ff92184e13a793b71982df4cdee0271/flang/lib/Lower/ConvertVariable.cpp#L1192

426–503

Thanks, I meant the reverse. I rephrased your suggestion to "Called from contexts where the component is not the base of an ArrayRef."

451

Whoops. Rephrased to: "The result shape will be computed after processing a following ArrayRef, if any, and in "visit" otherwise."

PeteSteinfeld accepted this revision.Jan 11 2023, 9:22 AM

Thanks, Jean!

All builds and tests correctly and looks good.

This revision is now accepted and ready to land.Jan 11 2023, 9:22 AM
This revision was automatically updated to reflect the committed changes.