Gaining the code re-use advantages of object oriented programming requires dynamic function binding, which allows a new subclass to override a function of a superclass. Dynamic binding is obtained in C++ through the use of virtual functions. Unfortunately, virtual functions have two negative impacts on performance. First, they are traditionally compiled into indirect call instructions, which take longer to execute than direct call instructions. Second, it is difficult for the compiler to perform optimization since summary information from called procedures is hard or even impossible to obtain. The net effect is that C++ programmers avoid the use of virtual functions. We present a new optimization that (1) removes the indirect function calls used for virtual functions, (2) enables other compiler optimizations such as inlining and constant propagation, and (3) requires no extensive dataflow analysis or profile information and thus is easily implemented in an existing compiler. We includ...
Bradley M. Kuhn, David Binkley