Commit f42fffb
Razvan Lupusoru
[flang][acc] Improve acc lowering around fir.box and arrays
When the acc dialect was first introduced, explicit expansion of
semantics of frontend was required. More specifically, the
following logic was included as part of lowering of OpenACC:
- Creation of `acc.bounds` operations for all arrays, including those
whose dimensions are captured in the type (eg `!fir.array<100xf32>`)
- Explicit expansion of box types by only putting the box's address
in the data clause. The address was extracted with a `fir.box_addr`
operation and the bounds were filled with `fir.box_dims` operation.
However, with the creation of the new type interface `MappableType`,
the idea is that specific type-based semantics can now be used. This
also really simplifies representation in the IR. Consider the
following example:
```
subroutine sub(arr)
real :: arr(:)
!$acc enter data copyin(arr)
end subroutine
```
Before the current PR, the relevant acc dialect IR looked like:
```
func.func @_QPsub(%arg0: !fir.box<!fir.array<?xf32>> {fir.bindc_name =
"arr"}) {
...
%1:2 = hlfir.declare %arg0 dummy_scope %0 {uniq_name = "_QFsubEarr"} :
(!fir.box<!fir.array<?xf32>>, !fir.dscope) ->
(!fir.box<!fir.array<?xf32>>, !fir.box<!fir.array<?xf32>>)
%c1 = arith.constant 1 : index
%c0 = arith.constant 0 : index
%2:3 = fir.box_dims %1#0, %c0 : (!fir.box<!fir.array<?xf32>>, index)
-> (index, index, index)
%c0_0 = arith.constant 0 : index
%3 = arith.subi %2#1, %c1 : index
%4 = acc.bounds lowerbound(%c0_0 : index) upperbound(%3 : index)
extent(%2#1 : index) stride(%2#2 : index) startIdx(%c1 : index)
{strideInBytes = true}
%5 = fir.box_addr %1#0 : (!fir.box<!fir.array<?xf32>>) ->
!fir.ref<!fir.array<?xf32>>
%6 = acc.copyin varPtr(%5 : !fir.ref<!fir.array<?xf32>>) bounds(%4) ->
!fir.ref<!fir.array<?xf32>> {name = "arr", structured = false}
acc.enter_data dataOperands(%6 : !fir.ref<!fir.array<?xf32>>)
```
After the current change, it looks like:
```
func.func @_QPsub(%arg0: !fir.box<!fir.array<?xf32>> {fir.bindc_name =
"arr"}) {
...
%1:2 = hlfir.declare %arg0 dummy_scope %0 {uniq_name = "_QFsubEarr"} :
(!fir.box<!fir.array<?xf32>>, !fir.dscope) ->
(!fir.box<!fir.array<?xf32>>, !fir.box<!fir.array<?xf32>>)
%2 = acc.copyin var(%1#0 : !fir.box<!fir.array<?xf32>>) ->
!fir.box<!fir.array<?xf32>> {name = "arr", structured = false}
acc.enter_data dataOperands(%2 : !fir.box<!fir.array<?xf32>>)
```
Restoring the old behavior can be done with following command line
options:
--openacc-unwrap-fir-box=true --openacc-generate-default-bounds=true1 parent fe8b323 commit f42fffb
File tree
30 files changed
+4395
-1086
lines changed- flang
- include/flang
- Lower
- Optimizer/Builder
- lib/Lower
- test/Lower/OpenACC
- mlir
- include/mlir/Dialect/OpenACC
- lib/Dialect/OpenACC/IR
30 files changed
+4395
-1086
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
584 | 584 | | |
585 | 585 | | |
586 | 586 | | |
587 | | - | |
| 587 | + | |
| 588 | + | |
588 | 589 | | |
589 | 590 | | |
590 | | - | |
| 591 | + | |
591 | 592 | | |
592 | 593 | | |
593 | 594 | | |
| |||
880 | 881 | | |
881 | 882 | | |
882 | 883 | | |
883 | | - | |
| 884 | + | |
| 885 | + | |
884 | 886 | | |
885 | 887 | | |
886 | 888 | | |
887 | 889 | | |
888 | 890 | | |
889 | | - | |
| 891 | + | |
| 892 | + | |
890 | 893 | | |
891 | 894 | | |
892 | 895 | | |
| |||
930 | 933 | | |
931 | 934 | | |
932 | 935 | | |
933 | | - | |
| 936 | + | |
| 937 | + | |
934 | 938 | | |
935 | 939 | | |
936 | 940 | | |
| |||
947 | 951 | | |
948 | 952 | | |
949 | 953 | | |
950 | | - | |
| 954 | + | |
951 | 955 | | |
952 | 956 | | |
953 | 957 | | |
| |||
958 | 962 | | |
959 | 963 | | |
960 | 964 | | |
961 | | - | |
962 | | - | |
963 | | - | |
964 | | - | |
965 | | - | |
966 | | - | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
967 | 975 | | |
968 | | - | |
969 | 976 | | |
970 | 977 | | |
971 | 978 | | |
| |||
977 | 984 | | |
978 | 985 | | |
979 | 986 | | |
980 | | - | |
981 | | - | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
982 | 990 | | |
983 | 991 | | |
984 | 992 | | |
| |||
990 | 998 | | |
991 | 999 | | |
992 | 1000 | | |
993 | | - | |
994 | | - | |
995 | | - | |
996 | | - | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
997 | 1005 | | |
998 | 1006 | | |
999 | 1007 | | |
1000 | 1008 | | |
1001 | 1009 | | |
1002 | 1010 | | |
1003 | | - | |
| 1011 | + | |
| 1012 | + | |
1004 | 1013 | | |
1005 | 1014 | | |
1006 | 1015 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
| 57 | + | |
| 58 | + | |
58 | 59 | | |
59 | 60 | | |
60 | 61 | | |
| |||
80 | 81 | | |
81 | 82 | | |
82 | 83 | | |
83 | | - | |
| 84 | + | |
84 | 85 | | |
85 | 86 | | |
86 | 87 | | |
| |||
0 commit comments