This is an archive of the discontinued LLVM Phabricator instance.

[Flang] Cray pointer Lowering
ClosedPublic

Authored by madanial on May 25 2023, 11:25 AM.

Details

Summary

This patch is to add cray pointer (aka integer pointer) support to flang. Syntax and semantic checking were already available in flang.
Cray pointers reference (https://gcc.gnu.org/onlinedocs/gfortran/Cray-pointers.html)

In order to implement the feature we create the following sequence for a simple scalar load and store:

integer pte, i
pointer(ptr, pte)
i = pte
%1 = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFEi"}
%2 = fir.alloca i32 {bindc_name = "pte", uniq_name = "_QFEpte"}
%3 = fir.alloca i64 {bindc_name = "ptr", uniq_name = "_QFEptr"}
...
%7 = fir.embox %3 : (!fir.ref<i64>) -> !fir.box<i64>
%8 = fir.box_addr %7 : (!fir.box<i64>) -> !fir.ref<i64>
%9 = fir.convert %8 : (!fir.ref<i64>) -> !fir.ref<!fir.ptr<i32>>
%10 = fir.load %9 : !fir.ref<!fir.ptr<i32>>
%11 = fir.load %10 : !fir.ptr<i32>
fir.store %11 to %1 : !fir.ref<i32>
integer pte, i
pointer(ptr, pte)
pte = i
%1 = fir.alloca i32 {bindc_name = "i", uniq_name = "_QFEi"}
%2 = fir.alloca i32 {bindc_name = "pte", uniq_name = "_QFEpte"}
%3 = fir.alloca i64 {bindc_name = "ptr", uniq_name = "_QFEptr"}

%7 = fir.load %1 : !fir.ref<i32>
%8 = fir.embox %3 : (!fir.ref<i64>) -> !fir.box<i64>
%9 = fir.box_addr %8 : (!fir.box<i64>) -> !fir.ref<i64>
%10 = fir.convert %9 : (!fir.ref<i64>) -> !fir.ref<!fir.ptr<i32>>
%11 = fir.load %10 : !fir.ref<!fir.ptr<i32>>
fir.store %7 to %11 : !fir.ptr<i32>

The sequence is very similar for array element cases with the addition of fir.coordinate_of for the specific element.
The whole array case is slightly different but uses the same sequence before the fir.array_load and fir.array_merge_store.

Diff Detail

Event Timeline

madanial created this revision.May 25 2023, 11:25 AM
madanial requested review of this revision.May 25 2023, 11:25 AM
clementval added inline comments.May 25 2023, 1:54 PM
flang/lib/Lower/ConvertExpr.cpp
864–874

Spell auto.

1571–1580

Spell auto.

madanial updated this revision to Diff 527081.May 31 2023, 9:25 AM

Spelling out auto as suggested.

madanial updated this revision to Diff 527119.May 31 2023, 10:46 AM

Fix Clang-Format Issues

madanial marked 2 inline comments as done.May 31 2023, 10:51 AM
klausler resigned from this revision.Jun 5 2023, 11:52 AM

I am assuming that there is further work in Semantics that is required for full support of cray pointers. I guess the information about module variables is not stored in the module file and hence the use of symbols might not work correctly in lowering. The following testcase fails.
https://github.com/llvm/llvm-test-suite/blob/main/Fortran/gfortran/regression/cray_pointers_10.f90

madanial retitled this revision from [Flang] Cray pointer support to [Flang] Cray pointer Lowering.Jun 29 2023, 2:44 PM

This patch focuses on the lowering required to support cray pointer, a quick look at cray pointer use in module indicated that lowering sequence will not need to be changed but the getPointer method will need to look at the pointer-pointee map in the module scope. We will submit a separate patch for the module support if the reviewers are okay with it.

This patch focuses on the lowering required to support cray pointer, a quick look at cray pointer use in module indicated that lowering sequence will not need to be changed but the getPointer method will need to look at the pointer-pointee map in the module scope. We will submit a separate patch for the module support if the reviewers are okay with it.

OK, that is fine.

kkwli0 accepted this revision.Aug 16 2023, 12:53 PM

LG. Please wait for a day to see if anyone has further comments.

This revision is now accepted and ready to land.Aug 16 2023, 12:53 PM
This revision was automatically updated to reflect the committed changes.