Loop Quasi-Invariant Chunk Motion by peeling with statement composition

Several techniques for analysis and transformations are used in compilers. Among them, the peeling of loops for hoisting quasi-invariants can be used to optimize generated code, or simply ease developers' lives. In this paper, we introduce a new concept of dependency analysis borrowed from the field of Implicit Computational Complexity (ICC), allowing to work with composed statements called Chunks to detect more quasi-invariants. Based on an optimization idea given on a WHILE language, we provide a transformation method - reusing ICC concepts and techniques - to compilers. This new analysis computes an invariance degree for each statement or chunks of statements by building a new kind of dependency graph, finds the maximum or worst dependency graph for loops, and recognizes if an entire block is Quasi-Invariant or not. This block could be an inner loop, and in that case the computational complexity of the overall program can be decreased. We already implemented a proof of concept on a toy C parser 1 analysing and transforming the AST representation. In this paper, we introduce the theory around this concept and present a prototype analysis pass implemented on LLVM. In a very near future, we will implement the corresponding transformation and provide benchmarks comparisons.

[1]  Yoshihiko Futamura,et al.  A Loop Optimization Technique Based on Quasi- Invariance , 2000 .

[2]  Thorsten Altenkirch,et al.  Under Consideration for Publication in J. Functional Programming a Predicative Analysis of Structural Recursion , 2022 .

[3]  Yehoshua Bar-Hillel,et al.  The Intrinsic Computational Difficulty of Functions , 1969 .

[4]  Neil D. Jones,et al.  The size-change principle for program termination , 2001, POPL '01.

[5]  Thomas Seiller,et al.  Interaction graphs: Additives , 2012, Ann. Pure Appl. Log..

[6]  Stephen A. Cook,et al.  A new recursion-theoretic characterization of the polytime functions , 1992, STOC '92.

[7]  Giulio Manzonetto,et al.  Weighted Relational Models of Typed Lambda-Calculi , 2013, 2013 28th Annual ACM/IEEE Symposium on Logic in Computer Science.

[8]  Thomas Seiller Interaction Graphs: Full Linear Logic , 2016, 2016 31st Annual ACM/IEEE Symposium on Logic in Computer Science (LICS).

[9]  Jean-Yves Girard,et al.  Linear Logic , 1987, Theor. Comput. Sci..

[10]  Martin Hofmann,et al.  Linear types and non-size-increasing polynomial time computation , 1999, Proceedings. 14th Symposium on Logic in Computer Science (Cat. No. PR00158).

[11]  Neil D. Jones,et al.  A flow calculus of mwp-bounds for complexity analysis , 2009, TOCL.

[12]  J. Cocke Global common subexpression elimination , 1970, Symposium on Compiler Optimization.

[13]  Stephen A. Cook Cobham Alan. The intrinsic computational difficulty of functions. Logic, methodology and philosophy of science, Proceedings of the 1964 International Congress , edited by Bar-Hillel Yehoshua, Studies in logic and the foundations of mathematics, North-Holland Publishing Company, Amsterdam 1965, pp. 2 , 1969 .

[14]  Kazushige Terui,et al.  Light types for polynomial time computation in lambda-calculus , 2004, Proceedings of the 19th Annual IEEE Symposium on Logic in Computer Science, 2004..

[15]  Jean-Yves Moyen,et al.  Resource control graphs , 2009, TOCL.

[16]  David A. Padua,et al.  Dependence graphs and compiler optimizations , 1981, POPL '81.