loki.transformations.utilities
Collection of utility routines to deal with general language conversion.
Functions
|
Check if routine is marked as sequential or has already been processed. |
|
Converts all variables and symbols in a subroutine to lower-case. |
|
Eliminate any imported symbols (or imports alltogether) that are not in the set of used symbols. |
|
Find all unused imported symbols and eliminate them from their import statements in the given routine and all contained members. |
|
Find and return all driver loops of a given routine. |
|
Find a local variable in the routine, or create an integer-typed one. |
|
Collect all local temporary array symbols in a given section. |
|
Check loop bounds for a particular |
|
Test/check whether a given loop is a driver loop. |
|
Utility function to apply a substitution map for expressions to itself |
|
Rename symbols/variables including (routine) arguments. |
|
Replace known intrinsic functions and symbols. |
|
Find all uses of |
|
Sanitise imports by removing unused symbols and eliminating imports with empty symbol lists. |
|
Modify/extend variable declarations to |
|
Helper routine that yields the symbol names for the different types of symbols we may encounter. |
Classes
|
Mapper to convert other Fortran kind specifications to their definitions from |
- convert_to_lower_case(routine)
Converts all variables and symbols in a subroutine to lower-case.
Note, this is intended for conversion to case-sensitive languages.
TODO: Should be extended to Module objects.
- replace_intrinsics(routine, function_map=None, symbol_map=None, case_sensitive=False)
Replace known intrinsic functions and symbols.
- Parameters:
routine (
Subroutine
) – The subroutine object in which to replace intrinsic callsfunction_map (dict[str, str]) – Mapping from function names (
InlineCall
names) to their replacementsymbol_map (dict[str, str]) – Mapping from intrinsic symbol names to their replacement
case_sensitive (bool) – Match case for name lookups in
function_map
andsymbol_map
- rename_variables(routine, symbol_map=None)
Rename symbols/variables including (routine) arguments.
- Parameters:
routine (
Subroutine
) – The subroutine object in which to rename variables.symbol_map (dict[str, str]) – Mapping from symbol/variable names to their replacement.
- sanitise_imports(module_or_routine)
Sanitise imports by removing unused symbols and eliminating imports with empty symbol lists.
Note that this is currently limited to imports that are identified to be
Scalar
,Array
, orProcedureSymbol
.
- replace_selected_kind(routine)
Find all uses of
selected_real_kind
orselected_int_kind
and replace them by theiriso_fortran_env
counterparts.This inserts imports for all used constants from
iso_fortran_env
.
- single_variable_declaration(routine, variables=None, group_by_shape=False)
Modify/extend variable declarations to
default: only declare one variable each time while preserving the order if
variables=None
andgroup_by_shape=False
declare variables specified in
variables``in single/unique declarations if ``variables
is a tuple of variablesvariable declarations to be grouped according to their shapes if
group_by_shape=True
- Parameters:
routine (
Subroutine
) – The subroutine in which to modify the variable declarationsvariables (tuple) – Variables to grant unique/single declaration for
group_by_shape (bool) – Whether to strictly make unique variable declarations or to only disassemble non-arrays and arrays and among arrays, arrays with differing shapes.
- recursive_expression_map_update(expr_map, max_iterations=10, mapper_cls=<class 'loki.expression.mappers.SubstituteExpressionsMapper'>)
Utility function to apply a substitution map for expressions to itself
The expression substitution mechanism
SubstituteExpressions
and the underlying mapperSubstituteExpressionsMapper
replace nodes that are found in the substitution map by their corresponding replacement.However, expression nodes can be nested inside other expression nodes, e.g. via the
parent
ordimensions
properties of variables. In situations, where such expression nodes as well as expression nodes appearing inside such properties are marked for substitution, it may be necessary to apply the substitution map to itself first. This utility routine takes care of that.- Parameters:
expr_map (dict) – The substitution map that should be updated
max_iterations (int) – Maximum number of iterations, corresponds to the maximum level of nesting that can be replaced.
mapper_cls (
SubstituteExpressionsMapper
) – The underlying mapper to be used (default:SubstituteExpressionsMapper
).
- get_integer_variable(routine, name)
Find a local variable in the routine, or create an integer-typed one.
- Parameters:
routine (
Subroutine
) – The subroutine in which to find the variablename (string) – Name of the variable to find the in the routine.
- get_loop_bounds(routine, dimension)
Check loop bounds for a particular
Dimension
in aSubroutine
.- Parameters:
routine (
Subroutine
) – Subroutine to perform checks on.dimension (
Dimension
) –Dimension
object describing the variable conventions used to define the data dimension and iteration space.
- find_driver_loops(routine, targets)
Find and return all driver loops of a given routine.
A driver loop is specified either by a call to a routine within targets or by the pragma !$loki driver-loop.
- Parameters:
routine (
Subroutine
) – The subroutine in which to find the driver loops.targets (list or string) – List of subroutines that are to be considered as part of the transformation call tree.
- get_local_arrays(routine, section, unique=True)
Collect all local temporary array symbols in a given section.
- Parameters:
routine (
Subroutine
) – The subroutine in which to find local arrays.section (
Section
or tuple ofNode
) – The section or list of nodes to scan for local temporary symbols.unique (bool, optional) – Flag whether to return unique instances of each symbol; default:
False
- check_routine_pragmas(routine, directive)
Check if routine is marked as sequential or has already been processed.
- Parameters:
routine (
Subroutine
) – Subroutine to perform checks on.directive (string or None) – Directives flavour to use for parallelism annotations; either
'openacc'
orNone
.