loki.transformations.sanitise

A small selection of utility transformations that resolve certain code constructs to unify code structure and make reasoning about Fortran code easier.

Functions

check_if_scalar_syntax(arg, dummy)

Check if an array argument, arg, is passed to an array dummy argument, dummy, using scalar syntax.

resolve_associates(routine)

Resolve Associate mappings in the body of a given routine.

transform_sequence_association(routine)

Housekeeping routine to replace scalar syntax when passing arrays as arguments For example, a call like

transform_sequence_association_append_map(...)

Check if call contains the sequence association pattern in one of the arguments, and if so, add the necessary transform data to call_map.

Classes

ResolveAssociatesTransformer([mapper, ...])

Transformer class to resolve Associate nodes in IR trees

SanitiseTransformation([...])

Transformation object to apply several code sanitisation steps when batch-processing large source trees via the Scheduler.

class SanitiseTransformation(resolve_associate_mappings=True, resolve_sequence_association=False)

Bases: Transformation

Transformation object to apply several code sanitisation steps when batch-processing large source trees via the Scheduler.

Parameters:
  • resolve_associate_mappings (bool) – Resolve ASSOCIATE mappings in body of processed subroutines; default: True.

  • resolve_sequence_association (bool) – Replace scalars that are passed to array arguments with array ranges; default: False.

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.

resolve_associates(routine)

Resolve Associate mappings in the body of a given routine.

Parameters:

routine (Subroutine) – The subroutine for which to resolve all associate blocks.

class ResolveAssociatesTransformer(mapper=None, invalidate_source=True, inplace=False, rebuild_scopes=False)

Bases: NestedTransformer

Transformer class to resolve Associate nodes in IR trees

This will replace each Associate node with its own body, where all identifier symbols have been replaced with the corresponding selector expression defined in associations.

visit_Associate(o, **kwargs)
transform_sequence_association(routine)

Housekeeping routine to replace scalar syntax when passing arrays as arguments For example, a call like

real :: a(m,n)

call myroutine(a(i,j))

where myroutine looks like

subroutine myroutine(a)
    real :: a(5)
end subroutine myroutine

should be changed to

call myroutine(a(i:m,j)
Parameters:

routine (Subroutine) – The subroutine where calls will be changed

transform_sequence_association_append_map(call_map, call)

Check if call contains the sequence association pattern in one of the arguments, and if so, add the necessary transform data to call_map.