[flang] [OpenMP] Predetermined rule for sequential loop index (flang-compiler/f18#976)
This commit implements rule: A loop iteration variable for a sequential loop in a parallel or task generating construct is private in the innermost such construct that encloses the loop. A Simple example: ``` i = -1 <== Scope 0 j = -1 !$omp parallel <== Scope 1 print *,i,j <-- both are shared (Scope 0) !$omp parallel <== Scope 2 print *,i,j <-- a) i is shared (Scope 0), j is private (Scope 2) !$omp do <== Scope 3 do i=1, 10 <-- i is private (Scope 3) do j=1, 10 <-- b) j is private (Scope 2, not 3!) enddo enddo print *,i,j <-- c) i is shared (Scope 0), j is private (Scope 2) !$omp end parallel print *,i,j <-- both are shared (Scope 0) !$omp end parallel print *,i,j <-- both are shared (Scope 0) end ``` Ideally the above rule solves a), b), and c) but a) is left as a TODO because it is better to handle the data-sharing attribute conflicts along with the rules for "Predetermined DSA on Clauses". The basic idea is when visiting the `DoConstruct` node within an OpenMP construct, if the do-loop is not associated (like `i` loop is associated with `!$omp do`) AND the do-loop is in the parallel/task generating construct, resolve the loop index to be private to that innermost construct. In the above example, `j` loop is not associated (then it is sequential) and the innermost parallel/task generating construct that encloses the `j` loop is the `parallel` construct marked with `<== Scope 2`, so `j` is private to that construct. To do that, I also need to change the prototype of those `ResolveOmp*` functions to allow specifiying the `scope` because the new symbol for `j` should be created in Scope 2 and all the `symbol` field of `Name j` in that `parallel` construct should be fixed, such as c). Original-commit: flang-compiler/f18@69a845283b058a3644053ec58b00d3361f4d4a59 Reviewed-on: https://github.com/flang-compiler/f18/pull/976
Loading
Please sign in to comment