Download presentation
Presentation is loading. Please wait.
Published byVictoria Riley Modified over 9 years ago
1
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
2
SPLST’11 Outline Templates in C++ Templates in C++ Template metaprograms Template metaprograms Efficiency problems with C++ templates Efficiency problems with C++ templates Earlier efforts / Related works Earlier efforts / Related works Our solution Our solution Examples Examples
3
SPLST’11 C++ templates Parametric polymorphism Parametric polymorphism Fundamental tools for generic programming Fundamental tools for generic programming Unconstrained Unconstrained Implemented by instantiation Implemented by instantiation Typical solution: multiply header files Typical solution: multiply header files Examples: standard library, inlc. STL Examples: standard library, inlc. STL
4
SPLST’11 Template metaprograms Unruh 1994: prime numbers Unruh 1994: prime numbers Has been proved to be Turing-complete Has been proved to be Turing-complete Functional programming paradigm Functional programming paradigm Recursion + pattern matching Recursion + pattern matching Referential transparency Referential transparency No assignment No assignment (Almost) no i/o (Almost) no i/o
5
SPLST’11 Template metaprograms 2 template template struct Factorial { enum { value = Factorial ::value * N }; enum { value = Factorial ::value * N };}; template <> struct Factorial struct Factorial { enum { value = 1 }; enum { value = 1 };}; int main() { int fact5 = Factorial ::value; int fact5 = Factorial ::value;}
6
SPLST’11 Template metaprogram usage Expression templates (blitz++, …) Expression templates (blitz++, …) Parser generators (boost::spirit, …) Parser generators (boost::spirit, …) Static interface checking (boost::concept, …) Static interface checking (boost::concept, …) Configuration management (boost::math, …) Configuration management (boost::math, …) Active libraries (…) Active libraries (…) DSL integration (Porkolab-Sinkovics,GPCE2010) DSL integration (Porkolab-Sinkovics,GPCE2010)
7
SPLST’11 Efficiency issues Recursive header inclusions Recursive header inclusions Data structures (recursive templates) Data structures (recursive templates) Imitating data manipulations Imitating data manipulations Complex, unclear syntax Complex, unclear syntax Compilers was not optimized for TMPs Compilers was not optimized for TMPs Hard to predict compilation time and memory usage Hard to predict compilation time and memory usage
8
SPLST’11 Earlier efforts Veldhuizen (1996- ) Veldhuizen (1996- ) Ad-hoc measurement, non-standard tools Ad-hoc measurement, non-standard tools Gurtovoy – Abrahams (2004) Gurtovoy – Abrahams (2004) Measuring full programs to identify idioms Measuring full programs to identify idioms Porkolab-Mihalicza Porkolab-Mihalicza Debugging (GPCE 2006) + Profiling (Splst 2007) Debugging (GPCE 2006) + Profiling (Splst 2007) Steven Watanabe (2008) Steven Watanabe (2008) Boost library extension Boost library extension Compilers was not optimized for TMPs Compilers was not optimized for TMPs Hard to predict compilation time and memory usage Hard to predict compilation time and memory usage
9
SPLST’11 Measuring compilation units Advantages Advantages Easy, platform and compiler independent Easy, platform and compiler independent Get the big picture, understand behaviour Get the big picture, understand behaviour Statistically correct Statistically correct Drawbacks Drawbacks Artificial problems Artificial problems Not revealing details in complex programs Not revealing details in complex programs Overheads (code generation, preprocessor) Overheads (code generation, preprocessor)
10
SPLST’11 Preprocessor overhead
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 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 Measuring compilation units are not feasible in real-world industrial projects Preprocessing step has a significant overhead Preprocessing step has a significant overhead Instrumentation has a linear distortion Instrumentation has a linear distortion Modification of compiler can eliminate warning overhead Modification of compiler can eliminate warning overhead Template metaprogram profiling is still learned Template metaprogram profiling is still learned
17
Thank you for your attention! Questions? József Mihalicza, Norbert Pataki, Zoltán Porkoláb jmihalicza@gmail.hu, patakino@elte.hu, gsd@elte.hu
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.