A Library for Explicit Dynamic Code Generation and Optimisation in C++ Olav Beckmann, Peter Fordham, Alastair Houghton and Paul Kelly Department of Computing, Imperial College London 180 Queen s Gate, London SW7 2BZ United Kingdom Email {o.beckmann,p.kelly}@ic.ac.uk Abstract ======== The TaskGraph Library is a C++ library for dynamic code generation, which combines specialisation with dependence analysis and loop restructuring. A TaskGraph represents a fragment of code which is constructed and manipulated at run-time, then compiled, dynamically linked and executed. TaskGraphs are initialised using macros and overloading, which forms a simplified, C-like sub-language with first-class arrays and no pointer arithmetic. Once a TaskGraph has been constructed, we can analyse dependence structure and perform optimisations. In this paper, we present the design of the TaskGraph library, present several sample applications for this library which demonstrate its use for runtime code specialisation and optimisation and discuss related work and future applications and developments of the library.