Skip to content

Commit

Permalink
Updates for the review
Browse files Browse the repository at this point in the history
  • Loading branch information
LonelyCat124 committed Dec 11, 2023
1 parent b763d6a commit 3d1c115
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/psyclone/psyir/transformations/inline_trans.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ def apply(self, node, options=None):
for ref in refs[:]:
self._replace_formal_arg(ref, node, formal_args)

# Store the Routine level symbol table and node's current scope
# so we can merge symbol tables later if required.
ancestor_table = node.ancestor(Routine).scope.symbol_table
scope = node.scope
# Copy the nodes from the Routine into the call site.
Expand Down Expand Up @@ -210,7 +212,11 @@ def apply(self, node, options=None):
idx += 1
parent.addchild(child, idx)

if(ancestor_table is not scope.symbol_table):
# If the scope we merged the inlined functions symbol table into
# is not a Routine scope then we now merge that symbol table into
# the ancestor Routine. This avoids issues like #2424 when
# applying ParallelLoopTrans to loops containing inlined calls.
if ancestor_table is not scope.symbol_table:
ancestor_table.merge(scope.symbol_table)
replacement = type(scope.symbol_table)()
scope.symbol_table.detach()
Expand Down
32 changes: 32 additions & 0 deletions src/psyclone/tests/psyir/transformations/inline_trans_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2406,3 +2406,35 @@ def test_find_routine_in_container(fortran_reader):
call_node, call_node.routine.interface.container_symbol)
assert isinstance(result, Routine)
assert result.name == "sub"


def test_apply_merges_symbol_table_with_routine(fortran_reader):
'''
Check that the apply method merges the inlined function's symbol table to
the containing Routine when the call node is inside a child ScopingNode.
'''
code = (
"module test_mod\n"
"contains\n"
" subroutine run_it()\n"
" integer :: i\n"
" real :: a(10)\n"
" do i=1,10\n"
" call sub(a, i)\n"
" end do\n"
" end subroutine run_it\n"
" subroutine sub(x, ivar)\n"
" real, intent(inout), dimension(10) :: x\n"
" integer, intent(in) :: ivar\n"
" integer :: i\n"
" do i = 1, 10\n"
" x(i) = 2.0*ivar\n"
" end do\n"
" end subroutine sub\n"
"end module test_mod\n")
psyir = fortran_reader.psyir_from_source(code)
routine = psyir.walk(Call)[0]
inline_trans = InlineTrans()
inline_trans.apply(routine)
# The i_1 symbol is the renamed i from the inlined call.
assert psyir.walk(Routine)[0].symbol_table.get_symbols()['i_1'] is not None

0 comments on commit 3d1c115

Please sign in to comment.