llvm / llvm/llvm-project

[flang][fir] Redundant DeclareOps for assumed rank arrays.

Open
#159,596 0 comments 0 reactions 0 assignees View on GitHub
flang:codegen
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Consider the following fortran code.

```
program main
implicit none
integer :: d0,d1(3),d2(3,3),d3(3,3,3)
d0 = 5
d1 = 6
d2 = 7
d3 = 8
print *, mean(d0)
print *, mean(d1)
print *, mean(d2)
print *, mean(d3)

contains

function mean(x) result(y)
integer, intent(in) :: x(..)
integer :: y
select rank(x)
rank(0) ; y = 0
rank(1) ; y = rank(x)
rank(2) ; y = rank(x)
rank(3) ; y = rank(x)
rank default ; y = 100
end select

end function mean

end program main

```

generate the fir using the following command

`flang -fc1 -emit-mlir test.f90 -mmlir -mlir-print-debuginfo -debug-info-kind=standalone -O0`

You will notice that it has around 6 `declare.op` for variable `x` which is an assumed rank array. We end up generating multiple entries for this in the debug information which is not only waste of space but also confuses the debugger.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.