1 / 17

Compiler Support for Profiling C++ Template Metaprograms

Compiler Support for Profiling C++ Template Metaprograms. József Mihalicza , Norbert Pataki , Zoltán Porkoláb Eötvös Loránd University Faculty of Informatics Dept. Of Programming Languages and Compilers. Outline. Templates in C++ Template metaprograms

tayten
Download Presentation

Compiler Support for Profiling C++ Template Metaprograms

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Compiler Support for Profiling C++ Template Metaprograms József Mihalicza, Norbert Pataki, Zoltán PorkolábEötvös Loránd UniversityFaculty of Informatics Dept. Of Programming Languages and Compilers

  2. Outline Templates in C++ Template metaprograms Efficiency problems with C++ templates Earlier efforts / Related works Our solution Examples SPLST’11

  3. C++ templates Parametric polymorphism Fundamental tools for generic programming Unconstrained Implemented by instantiation Typical solution: multiply header files Examples: standard library, inlc. STL SPLST’11

  4. Template metaprograms Unruh 1994: prime numbers Has been proved to be Turing-complete Functional programming paradigm Recursion + pattern matching Referential transparency No assignment (Almost) no i/o SPLST’11

  5. Template metaprograms 2 template <int N> struct Factorial { enum { value = Factorial<N-1>::value * N }; }; template <> struct Factorial<0> { enum { value = 1 }; }; int main() { int fact5 = Factorial<5>::value; } SPLST’11

  6. Template metaprogram usage Expression templates (blitz++, …) Parser generators (boost::spirit, …) Static interface checking (boost::concept, …) Configuration management (boost::math, …) Active libraries (…) DSL integration (Porkolab-Sinkovics,GPCE2010) SPLST’11

  7. Efficiency issues Recursive header inclusions Data structures (recursive templates) Imitating data manipulations Complex, unclear syntax Compilers was not optimized for TMPs Hard to predict compilation time and memory usage SPLST’11

  8. Earlier efforts Veldhuizen (1996- ) Ad-hoc measurement, non-standard tools Gurtovoy – Abrahams (2004) Measuring full programs to identify idioms Porkolab-Mihalicza Debugging (GPCE 2006) + Profiling (Splst 2007) Steven Watanabe (2008) Boost library extension Compilers was not optimized for TMPs Hard to predict compilation time and memory usage SPLST’11

  9. Measuring compilation units Advantages Easy, platform and compiler independent Get the big picture, understand behaviour Statistically correct Drawbacks Artificial problems Not revealing details in complex programs Overheads (code generation, preprocessor) SPLST’11

  10. Preprocessor overhead SPLST’11

  11. Instrumentation framework

  12. Code instrumentation

  13. Code instrumentation 2

  14. Warning generation Overhead Deviation of overhead

  15. Modified compiler

  16. Summary • We have to measure template metaprograms (and perhaps all large projects with many templates) • Measuring compilation units are not feasible in real-world industrial projects • Preprocessing step has a significant overhead • Instrumentation has a linear distortion • Modification of compiler can eliminate warning overhead • Template metaprogram profiling is still learned

  17. Thank you for your attention! Questions? József Mihalicza, Norbert Pataki, Zoltán Porkolábjmihalicza@gmail.hu, patakino@elte.hu, gsd@elte.hu

More Related