Skip to content

Commit

Permalink
Merge pull request #163 from rolfhm/sbrm_contained_routine_transforma…
Browse files Browse the repository at this point in the history
…tions

Call remove call and remove hook  transformations on contained subroutines
  • Loading branch information
reuterbal authored Oct 10, 2023
2 parents d89e2ee + 780256c commit 0709e18
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
35 changes: 35 additions & 0 deletions transformations/tests/test_utility_routines.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,29 @@ def fixture_source(srcdir):
if (dave) call abor1('[INLINE CONDITIONAL]')
call never_gonna_run_around()
WRITE(NULOUT,*) "[WRITE INTRINSIC]"
if (.not. dave) WRITE(NULOUT, *) "[WRITE INTRINSIC]"
if (lhook) call dr_hook('never_gonna_give',1,zhook_handle)
contains
subroutine never_gonna_run_around
implicit none
if (lhook) call dr_hook('never_gonna_run_around',0,zhook_handle)
if (dave) call abor1('[INLINE CONDITIONAL]')
WRITE(NULOUT,*) "[WRITE INTRINSIC]"
if (.not. dave) WRITE(NULOUT, *) "[WRITE INTRINSIC]"
if (lhook) call dr_hook('never_gonna_run_around',1,zhook_handle)
end subroutine never_gonna_run_around
end subroutine
subroutine i_hope_you_havent_let_me_down
real(kind=jprb) :: zhook_handle
Expand Down Expand Up @@ -156,6 +175,15 @@ def test_dr_hook_transformation_remove(frontend, config, source):
imp for imp in FindNodes(Import).visit(item.routine.ir)
if imp.module == 'yomhook'
]
for r in item.routine.members:
drhook_calls += [
call for call in FindNodes(CallStatement).visit(r.ir)
if call.name == 'dr_hook'
]
drhook_imports += [
imp for imp in FindNodes(Import).visit(item.routine.ir)
if imp.module == 'yomhook'
]
if item.role == 'driver':
assert len(drhook_calls) == 2
assert len(drhook_imports) == 1
Expand Down Expand Up @@ -196,6 +224,13 @@ def test_utility_routine_removal(frontend, config, source, include_intrinsics, k
assert ('[WRITE INTRINSIC]' not in transformed) == include_intrinsics
assert 'zhook_handle' not in routine.variables

for r in routine.members:
transformed = r.to_fortran()
assert '[SUBROUTINE CALL]' not in transformed
assert '[INLINE CONDITIONAL]' not in transformed
assert ('dave' not in transformed) == include_intrinsics
assert 'zhook_handle' not in routine.variables

routine = Sourcefile.from_file(source/'never_gonna_give.F90', frontend=frontend)['i_hope_you_havent_let_me_down']
assert 'zhook_handle' in routine.variables
assert len([call for call in FindNodes(CallStatement).visit(routine.body) if call.name == 'dr_hook']) == 2
Expand Down
6 changes: 6 additions & 0 deletions transformations/transformations/utility_routines.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ def transform_subroutine(self, routine, **kwargs):
if role == 'driver':
return

for r in routine.members:
self.transform_subroutine(r, **kwargs)

mapper = {}
for call in FindNodes(CallStatement).visit(routine.body):
# Lazily changing the DrHook label in-place
Expand Down Expand Up @@ -122,6 +125,9 @@ def transform_subroutine(self, routine, **kwargs):
if role and role == 'driver' and self.kernel_only:
return

for r in routine.members:
self.transform_subroutine(r, **kwargs)

mapper = {}

# First remove inline conditionals with calls to specified routines or intrinsics
Expand Down

0 comments on commit 0709e18

Please sign in to comment.