loki.transformations.argument_shape
Inter-procedural analysis passes to derive and augment argument array shapes.
A pair of utility Transformation classes that allows thea shape
of array arguments with deferred dimensions to be derived from the
calling context via inter-procedural analysis.
To infer the declared dimensions of array arguments
ArgumentArrayShapeAnalysis needs to be applied first to set the
shape property on respective Array symbols, before
ExplicitArgumentArrayShapeTransformation can be applied in a
reverse traversal order to apply the necessary changes to argument
declarations and call signatures.
Classes
Infer shape of array arguments with deferred shape. |
|
Add dimensions to array arguments and adjust call signatures. |
- class ArgumentArrayShapeAnalysis
Bases:
TransformationInfer shape of array arguments with deferred shape.
An inter-procedural analysis pass that passively infers the shape symbols for argument arrays from calling contexts and sets the
shapeattribute onArraysymbols accordingly.The shape information is propagated from a caller to the called subroutine in a forward traversal of the call-tree. If the call-side shape of an array argument is either set, or has already been derived (possibly with conflicting information), this transformation will have no effect.
Note: This transformation does not affect the generated source code, as it only sets the
shapeproperty, which is ignored during the code generation step (fgen). To actively change the argument array declarations and the resulting source code, theExplicitArgumentArrayShapeTransformationneeds to be applied after this transformation.- 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.
- class ExplicitArgumentArrayShapeTransformation
Bases:
TransformationAdd dimensions to array arguments and adjust call signatures.
Adjusts array argument declarations by inserting explicit shape variables according to the
shapeproperty of theArraysymbol. This property can be derived from the calling context viaArgumentArrayShapeAnalysis.If the
Scalarsymbol defining an array dimension is not yet known in the localSubroutine, it gets added to the call signature. In the caller routine, the respectiveScalarargument is added to theCallStatementvia keyword-argument notation.Note: Since the
CallStatementneeds updating after the calledSubroutinesignature, this transformation has to be applied in reverse order viaScheduler.process(..., reverse=True).- reverse_traversal = 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.