C and tcc: a language and compiler for dynamic code generation

Dynamic code generation allows programmers to use run-time information in order to achieve performance and expressiveness superior to those of static code. The 'C(Tick C) language is a superset of ANSI C that supports efficient and high-level use of dynamic code generation. 'C provides dynamic code generation at the level of C expressions and statements and supports the composition of dynamic code at run time. These features enable programmers to add dynamic code generation to existing C code incrementally and to write important applications (such as “just-in-time” compilers) easily. The article presents many examples of how 'C can be used to solve practical problems. The tcc compiler is an efficient, portable, and freely available implementation of 'C. tcc allows programmers to trade dynamic compilation speed for dynamic code quality: in some aplications, it is most important to generate code quickly, while in others code quality matters more than compilation speed. The overhead of dynamic compilation is on the order of 100 to 600 cycles per generated instruction, depending on the level of dynamic optimizaton. Measurements show that the use of dynamic code generation can improve performance by almost an order of magnitude; two- to four-fold speedups are common. In most cases, the overhead of dynamic compilation is recovered in under 100 uses of the dynamic code; sometimes it can be recovered within one use.

[1]  Dawson R. Engler,et al.  tcc: a system for fast, flexible, and high-level dynamic code generation , 1997, PLDI '97.

[2]  Dawson R. Engler,et al.  C: a language for high-level, efficient, and machine-independent dynamic code generation , 1995, POPL '96.

[3]  Christopher W. Fraser,et al.  A code generation interface for ANSI C , 1991, Softw. Pract. Exp..

[4]  Rajiv Gupta,et al.  Register allocation via clique separators , 1989, PLDI '89.

[5]  Charles Consel,et al.  A general approach for run-time specialization and its application to C , 1996, POPL '96.

[6]  Dawson R. Engler,et al.  Exokernel: an operating system architecture for application-level resource management , 1995, SOSP.

[7]  Larry Wall,et al.  Programming Perl , 1991 .

[8]  Christopher W. Fraser,et al.  A Retargetable C Compiler: Design and Implementation , 1995 .

[9]  Mendel Rosenblum,et al.  Embra: fast and flexible machine simulation , 1996, SIGMETRICS '96.

[10]  R. Kent Dybvig,et al.  Revised5 Report on the Algorithmic Language Scheme , 1986, SIGP.

[11]  Calton Pu,et al.  Optimistic incremental specialization: streamlining a commercial operating system , 1995, SOSP.

[12]  Charles N. Fischer,et al.  On the Minimization of Loads/Stores in Local Register Allocation , 1989, IEEE Transactions on Software Engineering.

[13]  Thomas R. Gross,et al.  Global Register Allocation Based on Graph Fusion , 1996, LCPC.

[14]  David D. Clark,et al.  Architectural considerations for a new generation of protocols , 1990, SIGCOMM '90.

[15]  Calton Pu,et al.  The Synthesis Kernel , 1988, Comput. Syst..

[16]  Peter Sestoft,et al.  MIX: A Self-Applicable Partial Evaluator for Experiments in Compiler Generation (Extended Abstract) , 1987, MFPS.

[17]  Jr. Guy L. Steele,et al.  Common LISP: the language (2nd ed.) , 1990 .

[18]  Scott Draves Lightweight Languages for Interactive Graphics , 1995 .

[19]  Todd A. Proebsting Simple and efficient BURS table generation , 1992, PLDI '92.

[20]  Brian N. Bershad,et al.  Extensibility safety and performance in the SPIN operating system , 1995, SOSP.

[21]  Gregory J. Chaitin,et al.  Register allocation and spilling via graph coloring , 2004, SIGP.

[22]  Michael A. Malcolm,et al.  Computer methods for mathematical computations , 1977 .

[23]  John Cocke,et al.  A methodology for the real world , 1981 .

[24]  Vivek Sarkar,et al.  Linear scan register allocation , 1999, TOPL.

[25]  L. Peter Deutsch,et al.  Efficient implementation of the smalltalk-80 system , 1984, POPL.

[26]  Guy L. Steele,et al.  C, a reference manual , 1984 .

[27]  Robert J. Fowler,et al.  MINT: a front end for efficient simulation of shared-memory multiprocessors , 1994, Proceedings of International Workshop on Modeling, Analysis and Simulation of Computer and Telecommunication Systems.

[28]  Dawson R. Engler,et al.  VCODE: a retargetable, extensible, very fast dynamic code generation system , 1996, PLDI '96.

[29]  Qunyan Wu Register Allocation via Hierarchical Graph Coloring , 1996 .

[30]  David L Weaver,et al.  The SPARC architecture manual : version 9 , 1994 .

[31]  Dawson R. Engler,et al.  DCG: an efficient, retargetable dynamic code generation system , 1994, ASPLOS VI.

[32]  John Cocke,et al.  Register Allocation Via Coloring , 1981, Comput. Lang..

[33]  Brian N. Bershad,et al.  Fast, effective dynamic compilation , 1996, PLDI '96.

[34]  R. A. Freiburghouse,et al.  Register allocation via usage counts , 1974, CACM.

[35]  Markus Mock,et al.  Annotation-Directed Run-Time Specialization in C , 1997, PEPM.

[36]  John K. Ousterhout,et al.  Tcl and the Tk Toolkit , 1994 .

[37]  Christopher W. Fraser,et al.  BURG: fast optimal instruction selection and tree parsing , 1992, SIGP.

[38]  湯浅 太一,et al.  Common Lisp(パネル討論会) , 1986 .

[39]  Henry M. Levy,et al.  Limits to low-latency communication on high-speed networks , 1993, TOCS.

[40]  Andrew Birrell,et al.  Implementing remote procedure calls , 1984, TOCS.

[41]  Robert L. Bernstein Multiplication by integer constants , 1986, Softw. Pract. Exp..

[42]  Mark Leone,et al.  Dynamo: A Staged Compiler Architecture for Dynamic Program Optimization , 1997 .

[43]  Richard L. Sites,et al.  Alpha AXP architecture , 1993, CACM.

[44]  Urs Hölzle,et al.  Optimizing dynamically-dispatched calls with run-time type feedback , 1994, PLDI '94.

[45]  Rob Pike,et al.  Hardware/software trade‐offs for bitmap graphics on the blit , 1985, Softw. Pract. Exp..

[46]  Jonathan Rees,et al.  Revised3 report on the algorithmic language scheme , 1986, SIGP.

[47]  Olivier Danvy,et al.  Tutorial notes on partial evaluation , 1993, POPL '93.

[48]  Peter Lee,et al.  Optimizing ML with run-time code generation , 1996, PLDI '96.

[49]  Guy L. Steele,et al.  C, a reference manual (2nd ed.) , 1986 .

[50]  Susan J. Eggers,et al.  A case for runtime code generation , 1993 .

[51]  John L. Hennessy,et al.  Register allocation by priority-based coloring , 1984, SIGPLAN '84.

[52]  David Keppel,et al.  A portable interface for on-the-fly instruction space modification , 1991, ASPLOS IV.

[53]  William H. Press,et al.  Numerical recipes in C (2nd ed.): the art of scientific computing , 1992 .

[54]  H. G. Schaeffer,et al.  Book Reviews : Computer Methods for Mathematical Computations: G.E. Forsythe et al. Englewood Cliffs, NJ, Prentice-Hall, Inc., 1977 , 1979 .