Generic flow-sensitive optimizing transformations in C++ with concepts

Compilers are typically hardwired to attempt optimizations only on expressions involving particular built-in types. Ideally, an optimizing compiler can recognize a rewrite opportunity whenever the operands in an expression satisfy the (algebraic) properties that justify the rewrite. This paper applies the principles and techniques of generic programming and the planned "concepts" language feature of C++ to approximate this ideal. Concretely, a concept defines the signature and algebraic laws of a class of types. We attach rewrite rules to a concept, so that the rules apply to all types in the class defined by a concept. The annotation burden to a programmer is thus small---the declaration that a type models a particular concept is simultaneously taken as an annotation that enables optimizations. To increase the applicability of generic rewrite rules, we instantiate them to type-specific rules, enabling the use of data-flow information from the compiler's existing analyses, and interleave the application of rewrite rules with function inlining. Our prototype is implemented as an extension of the ConceptGCC compiler; our experiments show the approach is effective in eliminating abstraction penalties.

[1]  Shigeru Chiba,et al.  A metaobject protocol for C++ , 1995, OOPSLA.

[2]  Todd L. Veldhuizen,et al.  Active libraries and universal languages , 2004 .

[3]  Sorin Lerner,et al.  Automatically proving the correctness of compiler optimizations , 2003, PLDI '03.

[4]  D. J. Edelsohn,et al.  A generalized expression optimization hook for C++ on a high-performance architectures , 1994, Proceedings of IEEE Scalable High Performance Computing Conference.

[5]  Arch D. Robison,et al.  Impact of economics on compiler optimization , 2001, JGI '01.

[6]  Tony Field,et al.  A Declarative Framework for Analysis and Optimization , 2007, CC.

[7]  Douglas Gregor,et al.  Proposed Wording for Concepts (Revision 3) , 2007 .

[8]  Eelco Visser,et al.  Stratego: A Language for Program Transformation Based on Rewriting Strategies , 2001, RTA.

[9]  D. Quinlan,et al.  ROSE: Compiler Support for Object-Oriented Frameworks , 1999, Parallel Process. Lett..

[10]  Eelco Visser,et al.  Composing Source-to-Source Data-Flow Transformations with Rewriting Strategies and Dependent Dynamic Rewrite Rules , 2005, CC.

[11]  Dennis Gannon,et al.  Active Libraries: Rethinking the roles of compilers and libraries , 1998, ArXiv.

[12]  Magne Haveraaen,et al.  Domain-Specific Optimisation with User-Defined Rules in CodeBoost , 2003, Electron. Notes Theor. Comput. Sci..

[13]  M. James,et al.  The TAMPR Program Transformation System : Design and Applications , 1997 .

[14]  Bjarne Stroustrup,et al.  Concepts: linguistic support for generic programming in C++ , 2006, OOPSLA '06.

[15]  Alexander A. Stepanov,et al.  Fundamentals of Generic Programming , 1998, Generic Programming.

[16]  Calvin Lin,et al.  Broadway: A Compiler for Exploiting the Domain-Specific Semantics of Software Libraries , 2005, Proceedings of the IEEE.

[17]  Jason Merrill Generic and gimple: A new tree represen-tation for entire functions , 2003 .

[18]  Sibylle Schupp,et al.  Library transformations , 2001, Proceedings First IEEE International Workshop on Source Code Analysis and Manipulation.

[19]  Simon Peyton Jones,et al.  Playing by the rules: rewriting as a practical optimisation technique in GHC , 2001 .

[20]  Xiaolong Tang,et al.  Concept-based optimization , 2007, LCSD '07.

[21]  Andrew Lumsdaine,et al.  Reusable, generic program analyses and transformations , 2009, GPCE '09.