Strategies for Context Sensitive Program Transformation
暂无分享,去创建一个
In this thesis we study the implementation of program transformations at a high abstraction level. We believe this leads to better productivity of the transformation developer. A program transformation system is a computer program which main goal is the transformation of programs. There are several reasons for generating a program from another one. For instance to obtain an optimised version or to improve the clarity of the code for maintenance purposes. The specification of program transformation requires the specification of how and when to transform. For the specification of how to transform, rewriting is a natural and elegant paradigm to describe modifications to a program. Term rewriting is a computational model based on rewrite rules. A rewrite rule represents a single stepwise modification to a program. The specification of when to transform refers to the identification of all the enabling conditions of a particular transformation to take place. To find all information for activating an optimisation, a program transformation requires the aid of program analysis techniques. How and when to transform are known as program transformation and analysis respectively. Typically this tasks are separately implemented. For the implementation of program transformations we use Stratego; a domain-specific programming language for the specification of program transformation systems based on strategic rewriting. Stratego differentiates from a pure rewriting system in the use of an strategy (a Stratego program) to control the rewriting process. We focus on the implementation of data-flow optimisations. A data-flow optimisation requires to collect information which is valid on any possible execution path of a program. This information is exploited to perform optimisations to a program. Simple rewrite systems only based on rewrite rules can only access the information available in the term that is being transformed. However data-flow optimisations need to collect information which is located at different points of a program, thus a data-flow optimisation requires context-sensitive information for its realisation. Dynamic rules (a Stratego extension) are designed to overcome this need. Dynamic rules are generated at run-time and can access information available from their definition context. A dynamic rule application allows to access information from a different program point. Our implementation of data-flow optimisations use dynamic rules to provide contex-sensitive information. We have introduced operations on dynamic rules which enabled us to describe data-flow optimisations such as constant-propagation, copy-propagation, common sub-expression elimination and dead code elimination at a high level of abstraction. A nice feature of our implementation is that integrates analysis and transformation into one task. We have defined generic data-flow frameworks for data-flow optimisations. The frameworks capture the similarities of data-flow optimisations and allow to be parameterized with different dynamic rules and strategies. The strategy parameters are applied at certain stages of the transformation to tune a transformation. The generic propagation strategies can combine different analyses and transformations by combining elements from several one-issue transformations. When two or more transformations share specific transformation features, it is possible to define a combination of transformations. Thus, a super-optimiser is presented which combines renaming, constant propagation, copy propagation and common sub-expression elimination.