loki.transformations.inline
Collection of utility routines to perform code-level force-inlining.
Functions
|
Replace instances of variables with known constant values by Literals. |
|
Replaces InlineCall expression to elemental functions with the called functions body. |
|
Inline internal subroutines contained in an individual |
|
Inline |
|
Inline internal subroutines contained in an individual |
|
Replaces |
|
Inline a set of call to an individual |
|
Resolve arguments of a call and map to the called procedure body. |
|
Resolve sequence association in calls to all member procedures (if |
Classes
|
An expression mapper that defines symbolic substitution for inlining. |
|
|
- inline_constant_parameters(routine, external_only=True)
Replace instances of variables with known constant values by Literals.
Notes
The
.type.initial
property is used to derive the replacement value,a which means for symbols imported from external modules, the parentModule
needs to be supplied in thedefinitions
to the constructor when creating theSubroutine
.Variables that are replaced are also removed from their corresponding import statements, with empty import statements being removed alltogether.
- Parameters:
routine (
Subroutine
) – Procedure in which to inline/resolve constant parameters.external_only (bool, optional) – Do not replace variables declared in the local scope (default: True)
- inline_elemental_functions(routine)
Replaces InlineCall expression to elemental functions with the called functions body. This will attempt to resolve the elemental function into a single expression and perform a direct replacement at expression level.
Note, that InlineCall.function.type is used to determine if a function cal be inlined. For functions imported via module use statements. This implies that the module needs to be provided in the definitions argument to the original
Subroutine
constructor.
- inline_internal_procedures(routine, allowed_aliases=None)
Inline internal subroutines contained in an individual
Subroutine
.Please note that internal functions are not yet supported!
- Parameters:
routine (
Subroutine
) – The subroutine in which to inline all member routinesallowed_aliases (tuple or list of str or
Expression
, optional) – List of variables that will not be renamed in the parent scope, even if they alias with a local declaration.
- inline_member_procedures(routine, allowed_aliases=None)
Inline internal subroutines contained in an individual
Subroutine
.Please note that internal functions are not yet supported!
- Parameters:
routine (
Subroutine
) – The subroutine in which to inline all member routinesallowed_aliases (tuple or list of str or
Expression
, optional) – List of variables that will not be renamed in the parent scope, even if they alias with a local declaration.
- inline_marked_subroutines(routine, allowed_aliases=None, adjust_imports=True)
Inline
Subroutine
objects guided by pragma annotations.When encountering
CallStatement
objects that are marked with a!$loki inline
pragma, this utility will attempt to replace the call with the body of the called procedure and remap all passed arguments into the calling procedures scope.Please note that this utility requires
CallStatement
objects to be “enriched” with external type information.- Parameters:
routine (
Subroutine
) – The subroutine in which to look for pragma-marked procedures to inlineallowed_aliases (tuple or list of str or
Expression
, optional) – List of variables that will not be renamed in the parent scope, even if they alias with a local declaration.adjust_imports (bool) – Adjust imports by removing the symbol of the inlined routine or adding imports needed by the imported routine (optional, default: True)
- class InlineTransformation(inline_constants=False, inline_elementals=True, inline_stmt_funcs=False, inline_internals=False, inline_marked=True, remove_dead_code=True, allowed_aliases=None, adjust_imports=True, external_only=True, resolve_sequence_association=False)
Bases:
Transformation
Transformation
class to apply several types of source inlining when batch-processing large source trees via theScheduler
.- Parameters:
inline_constants (bool) – Replace instances of variables with known constant values by
Literal
(seeinline_constant_parameters
); default: False.inline_elementals (bool) – Replaces
InlineCall
expression to elemental functions with the called function’s body (seeinline_elemental_functions
); default: True.inline_stmt_funcs (bool) – Replaces
InlineCall
expression to statement functions with the corresponding rhs of the statement function if the statement function declaration is available; default: False.inline_internals (bool) – Inline internal procedure (see
inline_internal_procedures
); default: False.inline_marked (bool) – Inline
Subroutine
objects marked by pragma annotations (seeinline_marked_subroutines
); default: True.remove_dead_code (bool) – Perform dead code elimination, where unreachable branches are trimmed from the code (see
dead_code_elimination
); default: Trueallowed_aliases (tuple or list of str or
Expression
, optional) – List of variables that will not be renamed in the parent scope during internal and pragma-driven inlining.adjust_imports (bool) – Adjust imports by removing the symbol of the inlined routine or adding imports needed by the imported routine (optional, default: True)
external_only (bool, optional) – Do not replace variables declared in the local scope when inlining constants (default: True)
resolve_sequence_association (bool) – Resolve sequence association for routines that contain calls to inline (default: False)
- reverse_traversal = True
- creates_items = 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 methodapply()
.- Parameters:
routine (
Subroutine
) – The subroutine to be transformed.**kwargs (optional) – Keyword arguments for the transformation.
- inline_statement_functions(routine)
Replaces
InlineCall
expression to statement functions with the called statement functions rhs.