Compiler optimizations that attempt to reduce program execution time have become increasingly more aggressive. Modern compilers perform a variety of intraprocedural and interprocedural optimizations (e.g., branch prediction, code motion, constant propagation, and subprogram inlining). To safely apply these optimizations requires summary information from called procedures; thus, a call to a function that cannot be resolved at compile time will invalidate or severely restrict optimization. C++ virtual functions produce such calls. This is unfortunate, as many functions in object-oriented programs are small and therefore excellent candidates for inlining. Because optimization is hampered by virtual functions, programmers hesitate to use them.
Reducing the cost of virtual functions is becoming increasingly important as programmers become more familiar with object-oriented design and programming techniques and, consequently, include more virtual functions in their code. For example, recent versions of the Interviews framework use more virtual functions and virtual function calls that a previous version .
This paper describes an optimization that improves the performance of C++ programs that contain virtual functions. The optimization is an enabling optimization: it attempts to enable other optimizations by replacing indirect function calls with direct functions calls. This allows existing compiler optimizations to be more effective. For example, enabling inlining can increase basic block size, which makes it easier to keep multiple pipelined functional units busy in today's modern super-scalar pipelined architectures such as the Pentium and powerPC. Finally, unlike other optimizations for the same problem [3,10], our optimization requires no extensive data-flow analysis or profile information.
The next section describes our optimization. Following this, Section 3 presents performance data obtained by applying our optimization to a collection of C++ programs. Next, Section 4 describes related work, and finally, Section 5 provides a summary of our results.
Copyright © 1995, 1996 Bradley M. Kuhn, David W. Binkley.
Verbatim copying and distribution of this entire paper is permitted in any medium, provided this notice is preserved.