This is an archive of the discontinued LLVM Phabricator instance.

[Flang][OpenMP] Fix for unstructured regions in OpenMP constructs - 2
ClosedPublic

Authored by kiranchandramohan on May 25 2022, 6:26 AM.

Details

Summary

The following changes are made for OpenMP operations with unstructured region,

  1. For combined constructs the outer operation is considered a structured

region and the inner one as the unstructured.

  1. Added a condition to ensure that we create new blocks only once for nested

unstructured OpenMP constructs.

Tests are added for checking the structure of the CFG.

Note: This is part of upstreaming from the fir-dev branch of
https://github.com/flang-compiler/f18-llvm-project. Code originally reviewed
at https://github.com/flang-compiler/f18-llvm-project/pull/1394.

Diff Detail

Event Timeline

Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptMay 25 2022, 6:26 AM
kiranchandramohan requested review of this revision.May 25 2022, 6:26 AM
kiranchandramohan retitled this revision from [OpenMP] Fix for unstructured regions in OpenMP constructs to [Flang][OpenMP] Fix for unstructured regions in OpenMP constructs - 2.May 25 2022, 6:27 AM
vdonaldson accepted this revision.May 25 2022, 11:00 AM

Looks ok to me

This revision is now accepted and ready to land.May 25 2022, 11:00 AM
shraiysh accepted this revision.May 25 2022, 11:18 AM

LGTM. I can see that one condition has been added for the first point in patch summary. I am unable to spot the condition for the second point, can you please tell me where that check happens?

flang/lib/Lower/OpenMP.cpp
159

@shraiysh the second check is here.

peixin accepted this revision.May 26 2022, 4:02 AM

LGTM

shraiysh added inline comments.May 26 2022, 7:43 AM
flang/lib/Lower/OpenMP.cpp
159

This check checks that we did it only for constructs but this doesn't check for the "only once" condition right? I thought that was the emphasis for the second point.

flang/lib/Lower/OpenMP.cpp
159

createEmptyRegionBlocks is called for all OpenMP regions from createBodyOfOp. When there are nested constructs, like a do inside a parallel, without this check, it will be called two times for the doregion, first the nested case from parallel and second the direct case for do.

So if this check is not there it will be effectively called more than once.

schweitz added inline comments.May 27 2022, 11:41 AM
flang/test/Lower/OpenMP/omp-unstructured.f90
126

Wasn't there some work to turn these sorts of guards into structured code?

276

Shouldn't there be an omp.wsloop near here? Do you want to verify that it is there?

vdonaldson added inline comments.May 27 2022, 12:28 PM
flang/test/Lower/OpenMP/omp-unstructured.f90
126

Subroutine ss4 initially generates structured fir in the fir sense of the term. Since the RUN directive for the test does not specify emit-fir, the CHECK directives apply to an mlir file that has explicit basic blocks. That may not matter here. Output for "-fopenmp -fdebug-dump-pre-fir" shows structured code. With "-emit-fir", the mlir file does as well.

1 Subroutine ss4: subroutine ss4(n)
  1 <<OpenMPConstruct>>
    <<DoConstruct>> -> 11
      2 NonLabelDoStmt -> 10: do i = 1, 3
      3 <<^OpenMPConstruct>>
        <<DoConstruct>> -> 10
          4 NonLabelDoStmt -> 9: do j = 1, 3
          <<IfConstruct>> -> 9
            5 ^IfStmt [negate] -> 9: if(j .eq. n) cycle
            8 ^PrintStmt: print*, 'ss4', j
            7 EndIfStmt
          <<End IfConstruct>>
          9 EndDoStmt -> 4: enddo
        <<End DoConstruct>>
        OmpEndLoopDirective
      <<End OpenMPConstruct>>
      10 EndDoStmt -> 2: enddo
    <<End DoConstruct>>
    11 ContinueStmt
  <<End OpenMPConstruct>>
  12 EndSubroutineStmt: end
End Subroutine ss4
shraiysh added inline comments.May 27 2022, 12:30 PM
flang/lib/Lower/OpenMP.cpp
159

Okay, understood. Thanks for clarifying.

I am going ahead with this patch. If there are further comments then will address in a separate patch.

flang/test/Lower/OpenMP/omp-unstructured.f90
126

Thanks @vdonaldson for clarifying. It does not matter here, we are checking that all these cases generate correct code and do not crash.

276

@schweitz In ss9 we only have a parallel and not a parallel do, so there is no omp.wsloop.