Skip to content

Fix evaluation semantics of FORALL constructs per 10.2.4.2.4. #1063

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 16, 2021

Conversation

schweitzpgi
Copy link

When lowering of FORALL was refactored to split the work between the
bridge and array expression lowering, the individual statements in a
forall construct body were no longer being lowered one at a time. These
changes add back the proper lowering.

Changes include:

  • Factoring the rhs array base analysis to be by statement.
  • Fix bug with finalization of context stack.
  • Fix bug with rerunning the analysis.
  • Merge aspects of cleanup code gen.
  • Restructure loop nest lowering such that each assignment resides in
    its own copy of a loop nest.
  • Add a lazy shape buffer. Thread lazy mask buffers through the loop
    nest so that cached results are available.
  • Regenerate checks for tests.
  • Fixes for p9.

auto *list = lhs ? &lhsBases : &rhsBases;
list->append(bases.begin(), bases.end());
if (rhsBases.empty())
endAssign();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like from this logic that rhsBases can only ever contain one llvm::SmallVector<ArrayBases> or be empty. Is really the case ? If so, why not making it a llvm::Optional<llvm::SmallVector<ArrayBases>> ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is a bit of "lazy instantiation". On the first assignment we're processing, we won't have already placed a new set of rhs bases on the end of the list. This just creates that bucket.

Each assignment has 0 or 1 lhs and 0 to n rhs arrays.

innerArgsStack.clear();
outerLoopStack.clear();
ccLoopNest.clear();
stmtCtx.reset();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has this stmtCtx already been finalized somewhere ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. It is finalized immediately before the fir.result in the innermost region.

@@ -176,7 +176,7 @@ createSomeArrayTempValue(AbstractConverter &converter,
fir::ExtendedValue
createLazyArrayTempValue(AbstractConverter &converter,
const evaluate::Expr<evaluate::SomeType> &expr,
mlir::Value var, SymMap &symMap,
mlir::Value var, mlir::Value shape, SymMap &symMap,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name shape here can be slightly confusing because mlir::Value shape is very often used for mlir::ShapeOp result, and here this is the address of a temp holding the temp mask extenta. You could maybe use shapeBuffer here too (I saw it somewhere else for this value in the PR) ?

mlir::Value shapeBuffer, ExtValue tmp) {
auto loc = getLoc();
auto unknown = fir::SequenceType::getUnknownExtent();
auto size = tmp.match(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use size = tmp.rank() here ?

When lowering of FORALL was refactored to split the work between the
bridge and array expression lowering, the individual statements in a
forall construct body were no longer being lowered one at a time. These
changes add back the proper lowering.

Changes include:

  - Factoring the rhs array base analysis to be by statement.
  - Fix bug with finalization of context stack.
  - Fix bug with rerunning the analysis.
  - Merge aspects of cleanup code gen.
  - Restructure loop nest lowering such that each assignment resides in
    its own copy of a loop nest.
  - Add a lazy shape buffer. Thread lazy mask buffers through the loop
    nest so that cached results are available.
  - Regenerate checks for tests.
  - Fixes for p9.

Make forall-2.f90 source file name independent.

Fix for k6 test, among others. Using incorrect statement context.

Fix bug exposed by m7.

Fix m7 bug.

review comments
@schweitzpgi schweitzpgi merged commit 2af3c27 into flang-compiler:fir-dev Sep 16, 2021
@schweitzpgi schweitzpgi deleted the ch-forall branch September 16, 2021 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants