Skip to content

Conversation

@Mittagskogel
Copy link

This PR extends the capabilities of the _track_local_consts() AST desugaring transformation.

By introducing a new spec generator find_indexed_dataref_component_spec(), we enable constant replacement of Part_Refs and Data_Refs like a(5) or a % b(4) % c(7,3). These Data_Refs get turned into specs like ('main', ('a', 5)) or (('main', 'a'), (a, ('b', 4), ('c', 7, 3)). Furthermore, the constant tracker can detect and replace array pointer references:

SUBROUTINE foo(var)
REAL, TARGET arr(4, 6)
REAL, POINTER arrptr
REAL, INTENT(IN) :: var

arrptr => arr(:,:)
arrptr(2,3) = var  ! This gets replaced with arr(2,3) = var
END SUBROUTINE foo

Additionally, we fix a bug in which variable pointer assignments are propagated. For example:

SUBROUTINE bar(idx)
REAL, TARGET :: arr(6)
REAL, POINTER :: ptr

REAL :: var
INTEGER, INTENT(IN) :: idx

ptr => arr(idx)
idx = idx + 1
var = ptr  ! arr(idx) cannot be propagated here because idx has changed!
END SUBROUTINE bar

The fix checks whether Data_Ref nodes on the RHS of the pointer assignment contain any variables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant