Hi Chung-Lin,
On 07.10.21 15:59, Chung-Lin Tang wrote:
this patch add support for "strictly-structured blocks" introduced in
OpenMP 5.1,
basically allowing BLOCK constructs to serve as the body for directives:
!$omp target
block
...
end block
[!$omp end target] !! end directive is optional
Pre-remark: That OpenMP feature causes ambiguities.
I have filled an OpenMP spec issue to discuss this, Issue 3154.
Namely the following is unclear:
!$omp parallel
!$omp parallel
block
x= x+ 1
end block
!$omp end parallel
Does the 'end parallel' end the inner strictly structured block
or the outer loosely structured block?
In principle, a compiler could defer this until later during
parsing, but this requires a tremendous state tracking and it
is surely not simple to do in gfortran (and probably all other
compilers). — Thus, I think the spec will change and probably
in the way which this patch has implemented.
NOTE: It takes the kind of directive into account, i.e.
'omp end target' vs. 'omp end parallel' aren't ambiguous.
The parsing loop in parse_omp_structured_block() has been modified to
allow
a BLOCK construct after the first statement has been detected to be
ST_BLOCK.
This is done by a hard modification of the state into (the new)
COMP_OMP_STRICTLY_STRUCTURED_BLOCK
after the statement is known (I'm not sure if there's a way to 'peek'
the next
statement/token in the Fortran FE, open to suggestions on how to
better write this)
Tested with no regressions on trunk, is this okay to commit?
LGTM – unless Jakub has further comments.
However, I have two requests:
First, can you include an update of the implementation status
in libgomp/libgomp.texi (+ fix the ...ppp... typo):
"@item Suppport of strictly structured blocks in Fortran @tab N @tab"
Secondly, can you extend the testcase a bit to include
nesting a BLOCK inside the other BLOCK – and nesting
the directive with a strictly structured block inside
another (different) directive to ensure that the
'omp end ...' is correctly matched.
I mean something like:
integer :: x
!$omp target map(i)
!$omp parallel
block
block
x = x + 1
end block
end block
!$omp end target
!$omp target map(i)
!$omp parallel
block
block
x = x + 1
end block
end block
!$omp end parallel
!$omp end target
end
Thanks,
Tobias
2021-10-07 Chung-Lin Tang <clt...@codesourcery.com>
gcc/fortran/ChangeLog:
* decl.c (gfc_match_end): Add COMP_OMP_STRICTLY_STRUCTURED_BLOCK case
together with COMP_BLOCK.
* parse.c (parse_omp_structured_block): Adjust declaration, add
'bool strictly_structured_block' default true parameter, add handling
for strictly-structured block case, adjust recursive calls to
parse_omp_structured_block.
(parse_executable): Adjust calls to parse_omp_structured_block.
* parse.h (enum gfc_compile_state): Add
COMP_OMP_STRICTLY_STRUCTURED_BLOCK.
* trans-openmp.c (gfc_trans_omp_workshare): Add EXEC_BLOCK case
handling.
gcc/testsuite/ChangeLog:
* gfortran.dg/gomp/strictly-structured-block-1.f90: New test.
-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634
München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas
Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht
München, HRB 106955