loki.transformations.routine_signatures

Collection of utilities and transformations altering routine signatures.

Functions

modify_variable_declarations(routine[, ...])

Utility to modify variable declarations by either removing symbols or renaming symbols.

remove_duplicate_args_from_calls(routine[, ...])

Utility to remove duplicate arguments from calls in routine

Classes

RemoveDuplicateArgs([recurse_to_kernels, ...])

Transformation to remove duplicate arguments for both caller and callee.

class RemoveDuplicateArgs(recurse_to_kernels=True, rename_common=False)

Bases: Transformation

Transformation to remove duplicate arguments for both caller and callee.

Warning

this won’t work properly for multiple calls to the same routine with differing duplicate arguments

Parameters:
  • recurse_to_kernels (bool, optional) – Remove duplicate arguments only at the driver level or recurse to (nested) kernels (Default: True).

  • rename_common (bool, optional) – Try to rename dummy arguments in called routines that received the same argument on the caller side, by finding a common name pattern in those names (Default: False).

item_filter = (<class 'loki.batch.item.ProcedureItem'>,)
transform_subroutine(routine, **kwargs)

Defines the transformation to apply to Subroutine items.

For transformations that modify Subroutine objects, this method should be implemented. It gets called via the dispatch method apply().

Parameters:
  • routine (Subroutine) – The subroutine to be transformed.

  • **kwargs (optional) – Keyword arguments for the transformation.

remove_duplicate_args_from_calls(routine, rename_common=False)

Utility to remove duplicate arguments from calls in routine

This updates the calls as well as the called routines. It requires calls to be enriched with interprocedural information.

Warning

this won’t work properly for multiple calls to the same routine with differing duplicate arguments

Parameters:
  • routine (Subroutine) – The subroutine where calls should be transformed.

  • rename_common (bool, optional) – Try to rename dummy arguments in called routines that received the same argument on the caller side, by finding a common name pattern in those names (Default: False).

modify_variable_declarations(routine, remove_symbols=(), rename_symbols=None)

Utility to modify variable declarations by either removing symbols or renaming symbols.

Note

This utility only works on the variable declarations itself and won’t modify variable/symbol usages elsewhere!

Parameters:
  • routine (Subroutine) – The subroutine to be transformed.

  • remove_symbols (list, tuple) – List of symbols for which their declaration should be removed.

  • rename_symbols (dict) – Dict/Map of symbols for which their declaration should be renamed.