loki.transformations.remove_code
Collection of utilities to automatically remove code elements or section and to perform Dead Code Elimination.
Functions
|
Utility routine to remove all |
|
Perform Dead Code Elimination on the given |
|
Utility routine to remove code regions marked with |
Classes
|
A |
|
A |
|
|
|
A |
- class RemoveCodeTransformation(remove_marked_regions=True, mark_with_comment=True, remove_dead_code=False, use_simplify=True, call_names=None, intrinsic_names=None, remove_imports=True, kernel_only=False)
Bases:
TransformationA
Transformationthat provides named call and import removal, code removal of pragma-marked regions and Dead Code Elimination for batch processing vis theScheduler.The transformation will apply the following methods in order:
- Parameters:
remove_marked_regions (boolean) – Flag to trigger the use of
remove_marked_regions(); default:Truemark_with_comment (boolean) – Flag to trigger the insertion of a marker comment when removing a region; default:
True.remove_dead_code (boolean) – Flag to trigger the use of
remove_dead_code(); default:Falseuse_simplify (boolean) – Use
simplifywhen branch pruning in duringremove_dead_code().call_names (list of str) – List of subroutine names against which to match
CallStatementnodes duringremove_calls().intrinsic_names (list of str) – List of module names against which to match
Intrinsicnodes duringremove_calls().remove_imports (boolean) – Flag indicating whether to remove symbols from
Importobjects duringremove_calls(); default:Truekernel_only (boolean) – Only apply the configured removal to subroutines marked as “kernel”; default:
False
- recurse_to_internal_procedures = True
- 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.
- do_remove_dead_code(routine, use_simplify=True)
Perform Dead Code Elimination on the given
Subroutineobject.- Parameters:
routine (
Subroutine) – The subroutine to which to apply dead code elimination.simplify (boolean) – Use
simplifywhen evaluating expressions for branch pruning.
- class RemoveDeadCodeTransformer(use_simplify=True, **kwargs)
Bases:
TransformerTransformerclass that removes provably unreachable code paths.The primary modification performed is to prune individual code branches under
Conditionalnodes.- Parameters:
use_simplify (boolean) – Use
simplifywhen evaluating expressions for branch pruning.
- visit_Conditional(o, **kwargs)
- do_remove_marked_regions(routine, mark_with_comment=True)
Utility routine to remove code regions marked with
!$loki removepragmas from a subroutine’s body.- Parameters:
routine (
Subroutine) – The subroutine to which to apply dead code elimination.mark_with_comment (boolean) – Flag to trigger the insertion of a marker comment when removing a region; default:
True.
- class RemoveRegionTransformer(mark_with_comment=True, **kwargs)
Bases:
TransformerA
Transformerthat removes code regions marked with!$loki removepragmas.This
Transformeronly removesPragmaRegionnodes, and thus requires the IR tree to have pragma regions attached, for example viapragma_regions_attached().When removing a marked code region the transformer may leave a comment in the source to mark the previous location, or remove the code region entirely.
- Parameters:
mark_with_comment (boolean) – Flag to trigger the insertion of a marker comment when removing a region; default:
True.
- visit_PragmaRegion(o, **kwargs)
Remove
PragmaRegionnodes with!$loki removepragmas
- do_remove_calls(routine, call_names=None, intrinsic_names=None, remove_imports=True)
Utility routine to remove all
CallStatementnodes to specific named subroutines in aSubroutine.For more information, see
RemoveCallsTransformer.- Parameters:
call_names (list of str) – List of subroutine names against which to match
CallStatementnodes.intrinsic_names (list of str) – List of module names against which to match
Intrinsicnodes.remove_imports (boolean) – Flag indicating whether to remove the respective procedure symbols from
Importobjects; default:True.
- class RemoveCallsTransformer(call_names=None, intrinsic_names=None, remove_imports=True, **kwargs)
Bases:
TransformerA
Transformerthat removes allCallStatementnodes to specific named subroutines.This
Transformerwill by default also remove the enclosing inline-conditional when encountering calls of the form`if (flag) call named_procedure().This
Transformerwill also attempt to match and removeIntrinsicnodes against a given list of name strings. This allows removing intrinsic calls likewrite (*,*) "...".In addition, this
Transformercan also attempt to match and removeImportnodes if given a list of strings to match. This can be used to remove the associated imports of the removed subroutines.- Parameters:
call_names (list of str) – List of subroutine names against which to match
CallStatementnodes.intrinsic_names (list of str) – List of module names against which to match
Intrinsicnodes.remove_imports (boolean) – Flag indicating whether to remove the respective procedure symbols from
Importobjects; default:True.
- visit_CallStatement(o, **kwargs)
Match and remove
CallStatementnodes against name patterns
- visit_Conditional(o, **kwargs)
Remove inline-conditionals after recursing into their body
- visit_Import(o, **kwargs)
Remove the symbol of any named calls from Import nodes