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:
Transformation
Infer 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
shape
attribute onArray
symbols 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
shape
property, which is ignored during the code generation step (fgen
). To actively change the argument array declarations and the resulting source code, theExplicitArgumentArrayShapeTransformation
needs to be applied after this transformation.- 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.
- class ExplicitArgumentArrayShapeTransformation
Bases:
Transformation
Add dimensions to array arguments and adjust call signatures.
Adjusts array argument declarations by inserting explicit shape variables according to the
shape
property of theArray
symbol. This property can be derived from the calling context viaArgumentArrayShapeAnalysis
.If the
Scalar
symbol defining an array dimension is not yet known in the localSubroutine
, it gets added to the call signature. In the caller routine, the respectiveScalar
argument is added to theCallStatement
via keyword-argument notation.Note: Since the
CallStatement
needs updating after the calledSubroutine
signature, 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
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.