// RUN: fir-opt --fir-add-alias-tags %s | FileCheck --check-prefixes=ALL %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 target dummy arguments go here // | |- "target data/_QMdataEglobt" // | |- "target data/_QMdataEglobat" // | |- "target data/_QFtest1Elocalt" // | |- "target data/_QFtest1Elocalat" // | // |- "global data" // | | // | |- "global data/_QMdataEglob" // | // |- "direct data" // | | // | |- "direct data/_QMdataEgloba" // | // |- "allocated data" // | // |- "allocated data/_QFtest1Elocal" // |- "allocated data/_QFtest1Elocala" // ALL: #[[FUNCROOT:.+]] = #llvm.tbaa_root // ALL: #[[ANYACCESS:.+]] = #llvm.tbaa_type_desc}> // ALL: #[[ANYDATA:.+]] = #llvm.tbaa_type_desc}> // ALL: #[[GLOBALDATA:.+]] = #llvm.tbaa_type_desc}> // ALL: #[[TARGETDATA:.+]] = #llvm.tbaa_type_desc}> // ALL: #[[DIRECTDATA:.+]] = #llvm.tbaa_type_desc}> // ALL: #[[DUMMYDATA:.+]] = #llvm.tbaa_type_desc}> // ALL: #[[LOCALDATA:.+]] = #llvm.tbaa_type_desc}> // ALL: #[[TARGETTAG:.+]] = #llvm.tbaa_tag // ALL: #[[GLOBVAR:.+]] = #llvm.tbaa_type_desc}> // ALL: #[[GLOBTVAR:.+]] = #llvm.tbaa_type_desc}> // ALL: #[[GLOBAVAR:.+]] = #llvm.tbaa_type_desc}> // ALL: #[[GLOBATVAR:.+]] = #llvm.tbaa_type_desc}> // ALL: #[[DUMMYFVAR:.+]] = #llvm.tbaa_type_desc}> // ALL: #[[DUMMYASVAR:.+]] = #llvm.tbaa_type_desc}> // ALL: #[[DUMMYAVAR:.+]] = #llvm.tbaa_type_desc}> // ALL: #[[LOCALVAR:.+]] = #llvm.tbaa_type_desc}> // ALL: #[[LOCALTVAR:.+]] = #llvm.tbaa_type_desc}> // ALL: #[[LOCALAVAR:.+]] = #llvm.tbaa_type_desc}> // ALL: #[[LOCALATVAR:.+]] = #llvm.tbaa_type_desc}> // ALL: #[[GLOBTAG:.+]] = #llvm.tbaa_tag // ALL: #[[GLOBTTAG:.+]] = #llvm.tbaa_tag // ALL: #[[GLOBATAG:.+]] = #llvm.tbaa_tag // ALL: #[[GLOBATTAG:.+]] = #llvm.tbaa_tag // ALL: #[[DUMMYFTAG:.+]] = #llvm.tbaa_tag // ALL: #[[DUMMYASTAG:.+]] = #llvm.tbaa_tag // ALL: #[[DUMMYATAG:.+]] = #llvm.tbaa_tag // ALL: #[[LOCALTAG:.+]] = #llvm.tbaa_tag // ALL: #[[LOCALTTAG:.+]] = #llvm.tbaa_tag // ALL: #[[LOCALATAG:.+]] = #llvm.tbaa_tag // ALL: #[[LOCALATTAG:.+]] = #llvm.tbaa_tag module attributes {dlti.dl_spec = #dlti.dl_spec : vector<4xi64>, i1 = dense<8> : vector<2xi64>, i8 = dense<8> : vector<2xi64>, i16 = dense<16> : vector<2xi64>, i32 = dense<32> : vector<2xi64>, i64 = dense<[32, 64]> : vector<2xi64>, f16 = dense<16> : vector<2xi64>, f64 = dense<64> : vector<2xi64>, f128 = dense<128> : vector<2xi64>, "dlti.endianness" = "little">, llvm.data_layout = ""} { fir.global @_QMdataEglob : !fir.array<10xf32> { %0 = fir.zero_bits !fir.array<10xf32> fir.has_value %0 : !fir.array<10xf32> } fir.global @_QMdataEgloba : !fir.box>> { %c0 = arith.constant 0 : index %0 = fir.zero_bits !fir.heap> %1 = fir.shape %c0 : (index) -> !fir.shape<1> %2 = fir.embox %0(%1) : (!fir.heap>, !fir.shape<1>) -> !fir.box>> fir.has_value %2 : !fir.box>> } fir.global @_QMdataEglobat target : !fir.box>> { %c0 = arith.constant 0 : index %0 = fir.zero_bits !fir.heap> %1 = fir.shape %c0 : (index) -> !fir.shape<1> %2 = fir.embox %0(%1) : (!fir.heap>, !fir.shape<1>) -> !fir.box>> fir.has_value %2 : !fir.box>> } fir.global @_QMdataEglobp : !fir.box>> { %c0 = arith.constant 0 : index %0 = fir.zero_bits !fir.ptr> %1 = fir.shape %c0 : (index) -> !fir.shape<1> %2 = fir.embox %0(%1) : (!fir.ptr>, !fir.shape<1>) -> !fir.box>> fir.has_value %2 : !fir.box>> } fir.global @_QMdataEglobt target : !fir.array<10xf32> { %0 = fir.zero_bits !fir.array<10xf32> fir.has_value %0 : !fir.array<10xf32> } // ALL-LABEL: func.func @_QPtest1( func.func @_QPtest1(%arg0: !fir.ref> {fir.bindc_name = "dummyf"}, %arg1: !fir.ref> {fir.bindc_name = "dummyft", fir.target}, %arg2: !fir.box> {fir.bindc_name = "dummyas"}, %arg3: !fir.box> {fir.bindc_name = "dummyast", fir.target}, %arg4: !fir.ref>>> {fir.bindc_name = "dummya"}, %arg5: !fir.ref>>> {fir.bindc_name = "dummyat", fir.target}, %arg6: !fir.ref>>> {fir.bindc_name = "dummyp"}) { %c0_i64 = arith.constant 0 : i64 %c1 = arith.constant 1 : index %cst = arith.constant 1.000000e+00 : f32 %c0 = arith.constant 0 : index %c10 = arith.constant 10 : index %0 = fir.dummy_scope : !fir.dscope %1 = fir.declare %arg4 dummy_scope %0 {fortran_attrs = #fir.var_attrs, uniq_name = "_QFtest1Edummya"} : (!fir.ref>>>, !fir.dscope) -> !fir.ref>>> %2 = fir.declare %arg2 dummy_scope %0 {uniq_name = "_QFtest1Edummyas"} : (!fir.box>, !fir.dscope) -> !fir.box> %3 = fir.declare %arg3 dummy_scope %0 {fortran_attrs = #fir.var_attrs, uniq_name = "_QFtest1Edummyast"} : (!fir.box>, !fir.dscope) -> !fir.box> %4 = fir.declare %arg5 dummy_scope %0 {fortran_attrs = #fir.var_attrs, uniq_name = "_QFtest1Edummyat"} : (!fir.ref>>>, !fir.dscope) -> !fir.ref>>> %5 = fir.shape %c10 : (index) -> !fir.shape<1> %6 = fir.declare %arg0(%5) dummy_scope %0 {uniq_name = "_QFtest1Edummyf"} : (!fir.ref>, !fir.shape<1>, !fir.dscope) -> !fir.ref> %7 = fir.declare %arg1(%5) dummy_scope %0 {fortran_attrs = #fir.var_attrs, uniq_name = "_QFtest1Edummyft"} : (!fir.ref>, !fir.shape<1>, !fir.dscope) -> !fir.ref> %8 = fir.declare %arg6 dummy_scope %0 {fortran_attrs = #fir.var_attrs, uniq_name = "_QFtest1Edummyp"} : (!fir.ref>>>, !fir.dscope) -> !fir.ref>>> %9 = fir.address_of(@_QMdataEglob) : !fir.ref> %10 = fir.declare %9(%5) {uniq_name = "_QMdataEglob"} : (!fir.ref>, !fir.shape<1>) -> !fir.ref> %11 = fir.address_of(@_QMdataEgloba) : !fir.ref>>> %12 = fir.declare %11 {fortran_attrs = #fir.var_attrs, uniq_name = "_QMdataEgloba"} : (!fir.ref>>>) -> !fir.ref>>> %13 = fir.address_of(@_QMdataEglobat) : !fir.ref>>> %14 = fir.declare %13 {fortran_attrs = #fir.var_attrs, uniq_name = "_QMdataEglobat"} : (!fir.ref>>>) -> !fir.ref>>> %15 = fir.address_of(@_QMdataEglobp) : !fir.ref>>> %16 = fir.declare %15 {fortran_attrs = #fir.var_attrs, uniq_name = "_QMdataEglobp"} : (!fir.ref>>>) -> !fir.ref>>> %17 = fir.address_of(@_QMdataEglobt) : !fir.ref> %18 = fir.declare %17(%5) {fortran_attrs = #fir.var_attrs, uniq_name = "_QMdataEglobt"} : (!fir.ref>, !fir.shape<1>) -> !fir.ref> %19 = fir.alloca !fir.array<10xf32> {bindc_name = "local", uniq_name = "_QFtest1Elocal"} %20 = fir.declare %19(%5) {uniq_name = "_QFtest1Elocal"} : (!fir.ref>, !fir.shape<1>) -> !fir.ref> %21 = fir.alloca !fir.box>> {bindc_name = "locala", uniq_name = "_QFtest1Elocala"} %22 = fir.zero_bits !fir.heap> %23 = fir.shape %c0 : (index) -> !fir.shape<1> %24 = fir.embox %22(%23) : (!fir.heap>, !fir.shape<1>) -> !fir.box>> // ALL-NOT: fir.store{{.*}}tbaa fir.store %24 to %21 : !fir.ref>>> %25 = fir.declare %21 {fortran_attrs = #fir.var_attrs, uniq_name = "_QFtest1Elocala"} : (!fir.ref>>>) -> !fir.ref>>> %26 = fir.alloca !fir.box>> {bindc_name = "localat", fir.target, uniq_name = "_QFtest1Elocalat"} // ALL-NOT: fir.store{{.*}}tbaa fir.store %24 to %26 : !fir.ref>>> %27 = fir.declare %26 {fortran_attrs = #fir.var_attrs, uniq_name = "_QFtest1Elocalat"} : (!fir.ref>>>) -> !fir.ref>>> %28 = fir.alloca !fir.box>> {bindc_name = "localp", uniq_name = "_QFtest1Elocalp"} %29 = fir.zero_bits !fir.ptr> %30 = fir.embox %29(%23) : (!fir.ptr>, !fir.shape<1>) -> !fir.box>> // ALL-NOT: fir.store{{.*}}tbaa fir.store %30 to %28 : !fir.ref>>> %31 = fir.declare %28 {fortran_attrs = #fir.var_attrs, uniq_name = "_QFtest1Elocalp"} : (!fir.ref>>>) -> !fir.ref>>> %32 = fir.alloca !fir.array<10xf32> {bindc_name = "localt", fir.target, uniq_name = "_QFtest1Elocalt"} %33 = fir.declare %32(%5) {fortran_attrs = #fir.var_attrs, uniq_name = "_QFtest1Elocalt"} : (!fir.ref>, !fir.shape<1>) -> !fir.ref> %34 = fir.array_coor %10(%5) %c1 : (!fir.ref>, !fir.shape<1>, index) -> !fir.ref // module data :: real :: glob(10) // ALL: fir.store{{.*}}{tbaa = [#[[GLOBTAG]]]} : !fir.ref fir.store %cst to %34 : !fir.ref %35 = fir.array_coor %18(%5) %c1 : (!fir.ref>, !fir.shape<1>, index) -> !fir.ref // module data :: real, target :: globt(10) // ALL: fir.store{{.*}}{tbaa = [#[[GLOBTTAG]]]} : !fir.ref fir.store %cst to %35 : !fir.ref // ALL-NOT: fir.load{{.*}}tbaa %36 = fir.load %12 : !fir.ref>>> %37 = fir.box_addr %36 : (!fir.box>>) -> !fir.heap> %38:3 = fir.box_dims %36, %c0 : (!fir.box>>, index) -> (index, index, index) %39 = fir.shape_shift %38#0, %38#1 : (index, index) -> !fir.shapeshift<1> %40 = fir.array_coor %37(%39) %c1 : (!fir.heap>, !fir.shapeshift<1>, index) -> !fir.ref // module data :: real, allocatable :: globa(:) // ALL: fir.store{{.*}}{tbaa = [#[[GLOBATAG]]]} : !fir.ref fir.store %cst to %40 : !fir.ref // ALL-NOT: fir.load{{.*}}tbaa %41 = fir.load %14 : !fir.ref>>> %42 = fir.box_addr %41 : (!fir.box>>) -> !fir.heap> %43:3 = fir.box_dims %41, %c0 : (!fir.box>>, index) -> (index, index, index) %44 = fir.shape_shift %43#0, %43#1 : (index, index) -> !fir.shapeshift<1> %45 = fir.array_coor %42(%44) %c1 : (!fir.heap>, !fir.shapeshift<1>, index) -> !fir.ref // module data :: real, allocatable, target :: globat(:) // ALL: fir.store{{.*}}{tbaa = [#[[GLOBATTAG]]]} : !fir.ref fir.store %cst to %45 : !fir.ref // ALL-NOT: fir.load{{.*}}tbaa %46 = fir.load %16 : !fir.ref>>> %47:3 = fir.box_dims %46, %c0 : (!fir.box>>, index) -> (index, index, index) %48 = fir.shift %47#0 : (index) -> !fir.shift<1> %49 = fir.array_coor %46(%48) %c1 : (!fir.box>>, !fir.shift<1>, index) -> !fir.ref // module data :: real, pointer :: globp(:) // ALL: fir.store{{.*}}{tbaa = [#[[TARGETTAG]]]} : !fir.ref fir.store %cst to %49 : !fir.ref %50 = fir.array_coor %6(%5) %c1 : (!fir.ref>, !fir.shape<1>, index) -> !fir.ref // real :: dummyf(10) // ALL: fir.store{{.*}}{tbaa = [#[[DUMMYFTAG]]]} : !fir.ref fir.store %cst to %50 : !fir.ref %51 = fir.array_coor %7(%5) %c1 : (!fir.ref>, !fir.shape<1>, index) -> !fir.ref // real, target :: dummyft(10) // ALL: fir.store{{.*}}{tbaa = [#[[TARGETTAG]]]} : !fir.ref fir.store %cst to %51 : !fir.ref %52 = fir.array_coor %2 %c1 : (!fir.box>, index) -> !fir.ref // real :: dummyas(:) // ALL: fir.store{{.*}}{tbaa = [#[[DUMMYASTAG]]]} : !fir.ref fir.store %cst to %52 : !fir.ref %53 = fir.array_coor %3 %c1 : (!fir.box>, index) -> !fir.ref // real, target :: dummyast(:) // ALL: fir.store{{.*}}{tbaa = [#[[TARGETTAG]]]} : !fir.ref fir.store %cst to %53 : !fir.ref // ALL-NOT: fir.load{{.*}}tbaa %54 = fir.load %1 : !fir.ref>>> %55 = fir.box_addr %54 : (!fir.box>>) -> !fir.heap> %56:3 = fir.box_dims %54, %c0 : (!fir.box>>, index) -> (index, index, index) %57 = fir.shape_shift %56#0, %56#1 : (index, index) -> !fir.shapeshift<1> %58 = fir.array_coor %55(%57) %c1 : (!fir.heap>, !fir.shapeshift<1>, index) -> !fir.ref // real, allocatable :: dummya(:) // ALL: fir.store{{.*}}{tbaa = [#[[DUMMYATAG]]]} : !fir.ref fir.store %cst to %58 : !fir.ref // ALL-NOT: fir.load{{.*}}tbaa %59 = fir.load %4 : !fir.ref>>> %60 = fir.box_addr %59 : (!fir.box>>) -> !fir.heap> %61:3 = fir.box_dims %59, %c0 : (!fir.box>>, index) -> (index, index, index) %62 = fir.shape_shift %61#0, %61#1 : (index, index) -> !fir.shapeshift<1> %63 = fir.array_coor %60(%62) %c1 : (!fir.heap>, !fir.shapeshift<1>, index) -> !fir.ref // real, allocatable, target :: dummyat(:) // ALL: fir.store{{.*}}{tbaa = [#[[TARGETTAG]]]} : !fir.ref fir.store %cst to %63 : !fir.ref // ALL-NOT: fir.load{{.*}}tbaa %64 = fir.load %8 : !fir.ref>>> %65:3 = fir.box_dims %64, %c0 : (!fir.box>>, index) -> (index, index, index) %66 = fir.shift %65#0 : (index) -> !fir.shift<1> %67 = fir.array_coor %64(%66) %c1 : (!fir.box>>, !fir.shift<1>, index) -> !fir.ref // real, pointer :: dummyp(:) // ALL: fir.store{{.*}}{tbaa = [#[[TARGETTAG]]]} : !fir.ref fir.store %cst to %67 : !fir.ref %68 = fir.array_coor %20(%5) %c1 : (!fir.ref>, !fir.shape<1>, index) -> !fir.ref // real :: local(10) // ALL: fir.store{{.*}}{tbaa = [#[[LOCALTAG]]]} : !fir.ref fir.store %cst to %68 : !fir.ref %69 = fir.array_coor %33(%5) %c1 : (!fir.ref>, !fir.shape<1>, index) -> !fir.ref // real, target :: localt(10) // ALL: fir.store{{.*}}{tbaa = [#[[LOCALTTAG]]]} : !fir.ref fir.store %cst to %69 : !fir.ref // ALL-NOT: fir.load{{.*}}tbaa %70 = fir.load %25 : !fir.ref>>> %71 = fir.box_addr %70 : (!fir.box>>) -> !fir.heap> %72:3 = fir.box_dims %70, %c0 : (!fir.box>>, index) -> (index, index, index) %73 = fir.shape_shift %72#0, %72#1 : (index, index) -> !fir.shapeshift<1> %74 = fir.array_coor %71(%73) %c1 : (!fir.heap>, !fir.shapeshift<1>, index) -> !fir.ref // real, allocatable :: locala(:) // ALL: fir.store{{.*}}{tbaa = [#[[LOCALATAG]]]} : !fir.ref fir.store %cst to %74 : !fir.ref // ALL-NOT: fir.load{{.*}}tbaa %75 = fir.load %27 : !fir.ref>>> %76 = fir.box_addr %75 : (!fir.box>>) -> !fir.heap> %77:3 = fir.box_dims %75, %c0 : (!fir.box>>, index) -> (index, index, index) %78 = fir.shape_shift %77#0, %77#1 : (index, index) -> !fir.shapeshift<1> %79 = fir.array_coor %76(%78) %c1 : (!fir.heap>, !fir.shapeshift<1>, index) -> !fir.ref // real, allocatable, target :: localat(:) // ALL: fir.store{{.*}}{tbaa = [#[[LOCALATTAG]]]} : !fir.ref fir.store %cst to %79 : !fir.ref // ALL-NOT: fir.load{{.*}}tbaa %80 = fir.load %31 : !fir.ref>>> %81:3 = fir.box_dims %80, %c0 : (!fir.box>>, index) -> (index, index, index) %82 = fir.shift %81#0 : (index) -> !fir.shift<1> %83 = fir.array_coor %80(%82) %c1 : (!fir.box>>, !fir.shift<1>, index) -> !fir.ref // real, pointer :: localp(:) // ALL: fir.store{{.*}}{tbaa = [#[[TARGETTAG]]]} : !fir.ref fir.store %cst to %83 : !fir.ref // ALL-NOT: fir.load{{.*}}tbaa %84 = fir.load %27 : !fir.ref>>> %85 = fir.box_addr %84 : (!fir.box>>) -> !fir.heap> %86 = fir.convert %85 : (!fir.heap>) -> i64 %87 = arith.cmpi ne, %86, %c0_i64 : i64 fir.if %87 { // ALL-NOT: fir.load{{.*}}tbaa %92 = fir.load %27 : !fir.ref>>> %93 = fir.box_addr %92 : (!fir.box>>) -> !fir.heap> fir.freemem %93 : !fir.heap> // ALL-NOT: fir.store{{.*}}tbaa fir.store %24 to %27 : !fir.ref>>> } // ALL-NOT: fir.load{{.*}}tbaa %88 = fir.load %25 : !fir.ref>>> %89 = fir.box_addr %88 : (!fir.box>>) -> !fir.heap> %90 = fir.convert %89 : (!fir.heap>) -> i64 %91 = arith.cmpi ne, %90, %c0_i64 : i64 fir.if %91 { // ALL-NOT: fir.load{{.*}}tbaa %92 = fir.load %25 : !fir.ref>>> %93 = fir.box_addr %92 : (!fir.box>>) -> !fir.heap> fir.freemem %93 : !fir.heap> // ALL-NOT: fir.store{{.*}}tbaa fir.store %24 to %25 : !fir.ref>>> } return } }