Compile-time disambiguation of MATLAB types through concrete interpretation with automatic run-time fallback

While the popularity of MATLAB for scientific and engineering applications is unabated, its poor performance compared to traditional languages, such as Fortran or even C, for a general class of problems continues to impede its deployment in full-scale simulations and data analysis. To ameliorate performance, we have been developing a MATLAB and Octave compiler that leverages the interpreter to implement some of the optimizations as concrete partial evaluations. Specifically, this paper describes constant propagation and type inference, using a high-level tree-transformation tool that has built-in support for solving dataflow problems. The approach allows propagation and folding of constants in cases that would be impractically difficult otherwise. The idea, when extended to infer variable types, provides a natural way to disambiguate types at compile time while leaving the fallback code in place for run-time evaluation. Experimental evaluation on pieces of real MATLAB code demonstrates the effectiveness of the approach.

[1]  Eelco Visser,et al.  Turning dynamic typing into static typing by program specialization in a compiler front-end for Octave , 2003, Proceedings Third IEEE International Workshop on Source Code Analysis and Manipulation.

[2]  David A. Padua,et al.  Techniques for the translation of MATLAB programs into Fortran 90 , 1999, TOPL.

[3]  José Nelson Amaral,et al.  A Dimension Abstraction Approach to Vectorization in Matlab , 2007, International Symposium on Code Generation and Optimization (CGO'07).

[4]  Cheryl McCosh,et al.  Type-based specialization in a telescoping compiler for Matlab , 2003 .

[5]  Prithviraj Banerjee,et al.  An algebraic array shape inference system for MATLAB® , 2006, TOPL.

[6]  Ken Kennedy,et al.  Slice-Hoisting for Array-Size Inference in MATLAB , 2003, LCPC.

[7]  Arun Chauhan,et al.  Library Function Selection in Compiling Octave , 2007, 2007 IEEE International Parallel and Distributed Processing Symposium.

[8]  Urs Hölzle,et al.  Reconciling responsiveness with performance in pure object-oriented languages , 1996, TOPL.

[9]  Walid Taha,et al.  Multi-Stage Programming: Its Theory and Applications , 1999 .

[10]  K. Kennedy,et al.  Automatic Type-Driven Library Generation for Telescoping Languages , 2003, ACM/IEEE SC 2003 Conference (SC'03).

[11]  Eelco Visser,et al.  Program Transformation with Scoped Dynamic Rewrite Rules , 2006, Fundam. Informaticae.

[12]  David A. Padua,et al.  MaJIC: compiling MATLAB for speed and responsiveness , 2002, PLDI '02.

[13]  Ken Kennedy,et al.  Reducing and Vectorizing Procedures for Telescoping Languages , 2004, International Journal of Parallel Programming.

[14]  Mark N. Wegman,et al.  Constant propagation with conditional branches , 1985, POPL.

[15]  Paul Klint,et al.  The syntax definition formalism SDF—reference manual— , 1989, SIGP.

[16]  David Grove,et al.  Selective specialization for object-oriented languages , 1995, PLDI '95.