Loop Quasi-Invariant Chunk Detection
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 [8, 10] - 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.
In this paper, we introduce the theory around this concept and present a prototype analysis pass implemented on LLVM. We already implemented a proof of concept on a toy C parser (https://github.com/ThomasRuby/LQICM_On_C_Toy_Parser) analysing and transforming the AST representation. In a very near future, we will implement the corresponding transformation within our prototype LLVM pass and provide benchmarks comparisons.
KeywordsStatic analysis Transformations Optimization Compilers Loop invariants Complexity Quasi-invariants
- 4.Cobham, A.: The intrinsic computational difficulty of functions. In: Bar-Hillel, Y. (ed.) CLMPS (1962)Google Scholar
- 7.Hofmann, M.: Linear types and non-size increasing polynomial time computation. In: LICS, pp. 464–473 (1999)Google Scholar
- 8.Kristiansen, L.: Notes on code motion. Private communicationGoogle Scholar
- 10.Kuck, D.J., Kuhn, R.H., Padua, D.A., Leasure, B., Wolfe, M.: Dependence graphs and compiler optimizations. In: POPL (1981)Google Scholar
- 11.Laird, J., McCusker, G., Manzonetto, G., Pagani, M.: Weighted relational models of typed lambda-calculi. In: IEEE/ACM LICS (2013)Google Scholar
- 12.Lee, C.S., Jones, N.D., Ben-Amram, A.M.: The size-change principle for program termination. In: POPL (2001)Google Scholar
- 15.Seiller, T.: Interaction graphs: full linear logic. In: IEEE/ACM LICS (2016)Google Scholar
- 16.Song, L., Futamura, Y., Glück, R., Hu, Z.: A loop optimization technique based on quasi-invariance (2000)Google Scholar