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.initialproperty is used to derive the replacement value,a which means for symbols imported from external modules, the parentModuleneeds to be supplied in thedefinitionsto 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
Subroutineconstructor.
- 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
Subroutineobjects guided by pragma annotations.When encountering
CallStatementobjects that are marked with a!$loki inlinepragma, 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
CallStatementobjects 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:
TransformationTransformationclass 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
InlineCallexpression to elemental functions with the called function’s body (seeinline_elemental_functions); default: True.inline_stmt_funcs (bool) – Replaces
InlineCallexpression 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
Subroutineobjects 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
Subroutineitems.For transformations that modify
Subroutineobjects, 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
InlineCallexpression to statement functions with the called statement functions rhs.