Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HoistVariablesAnalysis: remove unused explicit interfaces after inlining #319

Merged
merged 4 commits into from
Jun 12, 2024

Conversation

awnawab
Copy link
Contributor

@awnawab awnawab commented May 28, 2024

This small PR implements two bug fixes:

  • HoistVariablesAnalysis now skips successors that might no longer be present (e.g. they were inlined)
  • Unused explicit interfaces of inlined subroutines are now removed

Copy link

Documentation for this branch can be viewed at https://sites.ecmwf.int/docs/loki/319/index.html

@awnawab awnawab force-pushed the naan-hoist-after-inline branch from 067b768 to a66737f Compare May 28, 2024 15:53
Copy link

codecov bot commented May 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.16%. Comparing base (eb793e2) to head (b9132db).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #319      +/-   ##
==========================================
+ Coverage   95.15%   95.16%   +0.01%     
==========================================
  Files         168      168              
  Lines       35454    35538      +84     
==========================================
+ Hits        33737    33821      +84     
  Misses       1717     1717              
Flag Coverage Δ
lint_rules 96.38% <ø> (ø)
loki 95.14% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@awnawab awnawab requested review from mlange05 and reuterbal May 28, 2024 16:30
@awnawab
Copy link
Contributor Author

awnawab commented Jun 10, 2024

Hi. Can I push a small update here?

@awnawab awnawab force-pushed the naan-hoist-after-inline branch from a66737f to be5a4f9 Compare June 10, 2024 12:07
Copy link
Collaborator

@reuterbal reuterbal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks really great! Three small comments/questions regarding implementation details but nothing too important really.

@@ -152,6 +152,11 @@ def transform_subroutine(self, routine, **kwargs):
for child in successors:
if not isinstance(child, ProcedureItem):
continue

# skip successors that might have been inlined
if not call_map.get(child.local_name, None):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't that simply be

Suggested change
if not call_map.get(child.local_name, None):
if child.local_name not in call_map:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed offline, this can be dropped now because InlineTransformation.creates_items = True if inline_marked = True.

@@ -606,6 +606,18 @@ def inline_marked_subroutines(routine, allowed_aliases=None, adjust_imports=True
# Remove import if no further symbols used, otherwise clone with new symbols
import_map[impt] = impt.clone(symbols=new_symbols) if new_symbols else None

# Remove explicit interfaces of inlined routines
for intf in FindNodes(Interface).visit(routine.ir):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need to go over routine.ir here? Or couldn't we simply use

Suggested change
for intf in FindNodes(Interface).visit(routine.ir):
for intf in routine.interfaces:

Comment on lines 612 to 615
_body = []
for s in intf.symbols:
if s.name not in callees or s.name in not_inlined:
_body += [s.type.dtype.procedure,]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be done with a list comprehension:

Suggested change
_body = []
for s in intf.symbols:
if s.name not in callees or s.name in not_inlined:
_body += [s.type.dtype.procedure,]
_body = tuple(
s.type.dtype.procedure for s in intf.symbols
if s.name not in callees or s.name in not_inlined
)

Also allows to directly build a tuple, avoiding the as_tuple further down.

@awnawab awnawab force-pushed the naan-hoist-after-inline branch from 410e3c5 to 714075a Compare June 11, 2024 09:44
Copy link
Collaborator

@reuterbal reuterbal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many thanks, all good for me now!

@reuterbal reuterbal changed the title Skip inlined successors in HoistVariablesAnalysis and remove unused explicit interfaces after inlining HoistVariablesAnalysis: remove unused explicit interfaces after inlining Jun 11, 2024
@reuterbal reuterbal added the ready for merge This PR has been approved and is ready to be merged label Jun 11, 2024
Copy link
Collaborator

@mlange05 mlange05 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice! Clean and well tested, GTG from me. :shipit:

@reuterbal reuterbal merged commit 815aa12 into main Jun 12, 2024
12 checks passed
@reuterbal reuterbal deleted the naan-hoist-after-inline branch June 12, 2024 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready for merge This PR has been approved and is ready to be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants