[flang-commits] [flang] [flang] Restructured TBAA trees in AddAliasTags pass. (PR #136725)
Slava Zakharin via flang-commits
flang-commits at lists.llvm.org
Wed Apr 23 12:52:24 PDT 2025
================
@@ -0,0 +1,331 @@
+// RUN: fir-opt --fir-add-alias-tags %s | FileCheck --check-prefixes=ALL,DEFAULT %s
+// RUN: fir-opt --fir-add-alias-tags --local-alloc-tbaa %s | FileCheck --check-prefixes=ALL,LOCAL %s
+
+// Test AddAliasTagsPass creating sub-tree for TARGET/POINTER variables.
+
+// module data
+// real :: glob(10)
+// real, target :: globt(10)
+// real, allocatable :: globa(:)
+// real, allocatable, target :: globat(:)
+// real, pointer :: globp(:)
+// end module data
+// subroutine test1(dummyf, dummyft, dummyas, dummyast, dummya, dummyat, dummyp)
+// use data
+// real :: dummyf(10)
+// real, target :: dummyft(10)
+// real :: dummyas(:)
+// real, target :: dummyast(:)
+// real, allocatable :: dummya(:)
+// real, allocatable, target :: dummyat(:)
+// real, pointer :: dummyp(:)
+// real :: local(10)
+// real, target :: localt(10)
+// real, allocatable :: locala(:)
+// real, allocatable, target :: localat(:)
+// real, pointer :: localp(:)
+// glob(1) = 1.0
+// globt(1) = 1.0
+// globa(1) = 1.0
+// globat(1) = 1.0
+// globp(1) = 1.0
+// dummyf(1) = 1.0
+// dummyft(1) = 1.0
+// dummyas(1) = 1.0
+// dummyast(1) = 1.0
+// dummya(1) = 1.0
+// dummyat(1) = 1.0
+// dummyp(1) = 1.0
+// local(1) = 1.0
+// localt(1) = 1.0
+// locala(1) = 1.0
+// localat(1) = 1.0
+// localp(1) = 1.0
+// end subroutine test1
+
+// "Flang function root _QPtest1"
+// |
+// "any access"
+// |
+// |- "descriptor member"
+// |- "any data access"
+// |
+// |- "dummy arg data"
+// | |
+// | |- "dummy arg data/_QFtest1Edummyf"
+// | |- "dummy arg data/_QFtest1Edummyas"
+// | |- "dummy arg data/_QFtest1Edummya"
+// |
+// |- "target data" <- all pointers and taget dummys
+// |
+// |- "global data"
+// | |
+// | |- "global data/_QMdataEglob"
+// | |- "global data/_QMdataEglobt"
+// |
+// |- "direct data" - "direct data/_QMdataEgloba"
+// | |
+// | |- "direct data/_QMdataEgloba"
+// | |- "direct data/_QMdataEglobat"
+// |
+// |- "allocated data"
+// |
+// |- "allocated data/_QFtest1Elocal"
+// |- "allocated data/_QFtest1Elocalt"
+// |- "allocated data/_QFtest1Elocala"
+// |- "allocated data/_QFtest1Elocalat"
----------------
vzakhari wrote:
> I wonder if creating tags for each variables in "allocated data" and "global data" really makes a difference. I would imagine LLVM is already clever enough to know/deduce that two global addresses cannot alias if they do not come from the same global (and the same with alloca). I am not against it, but I imagine this is growing the metadata size a bit.
I think it does not make a difference, indeed. I will experiment with this in a separate PR. Thanks for noticing it!
> Also, for common block, will it create different tags for each common block members, or just one with the common block global name? Since they technically share the same storage, it would be safer to have a single tag for them I think. Same with local/global equivalences, but here I think we should probably fall into the POINTER cases currently (worth adding a test though).
I will add a new test for common and equivalence. In short:
* Yes, we will create a single type descriptor and a tag for all member of the same common block.
* We will also create a single type descriptor and a tag for all member of an equivalence, though, accesses of local equivalences won't have any tag unless `--local-alloc-tbaa` experimental option is enabled.
I want to try to enable `--local-alloc-tbaa` by default as well, but I will have to make sure WRF and other tests pass.
https://github.com/llvm/llvm-project/pull/136725
More information about the flang-commits
mailing list