[flang-commits] [flang] [flang] add tbaa tags to global variables (PR #68727)
Tom Eccles via flang-commits
flang-commits at lists.llvm.org
Wed Oct 11 05:57:04 PDT 2023
================
@@ -406,7 +406,7 @@ AliasAnalysis::Source AliasAnalysis::getSource(mlir::Value v) {
attributes.set(Attribute::Pointer);
}
- if (type == SourceKind::Global)
+ if (type == SourceKind::Global || type == SourceKind::Direct)
----------------
tblah wrote:
So `SourceKind::Direct` isn't necessarily a global?
The use case for the tbaa alias analysis is we want to be able to add tags to global arrays. These can be boxed. The specific case I care about is
```
module mod
real, dimension(:), allocatable :: glbl
subroutine func(arg)
real, intent(in), dimension(:) :: arg
! glbl can't alias with arg
end subroutine
end module
```
The generated code looks something like
```
fir.global @_QMmodEglbl : !fir.box<!fir.heap<!fir.array<?xf32>>> { [...]}
func.func @_QMmodPfunc([...]) {
[...]
%glbl_addr = fir.address_of(@_QmodEa) : !fir.ref<!fir.box<!fir.heap<!fir.array<?xf32>>>>
%decl = fir.declare %glbl_addr [...]
[...]
%box = fir.load %decl
%addr = fir.box_addr %box : (!fir.box<!fir.heap<!fir.array<?xf32>>>) -> !fir.heap<!fir.array<?xf32>>
[...]
%element = fir.array_coor %addr(%shape) %index
%val = fir.array_coor %element
```
What I want to happen here is to notice that `%val` comes from a global variable and to tag that load as such. This is a lot clearer from the fortran source than the FIR so maybe we need to store more information somewhere.
As I understand it, you're saying that we can't know much about this variable because the global variable is boxed. Why is the box special?
https://github.com/llvm/llvm-project/pull/68727
More information about the flang-commits
mailing list