Skip to content

Devirtualization

Ziyang Xu edited this page Sep 21, 2020 · 1 revision

Overview

Devirtualization is important for C++ programs with heavy use of classes to de-virtualize virtual functions. The virtual functions will show as indirect function calls in the bitcode and hinder interprocedure analysis. To get ride of these virtual functions, we can compare function signatures to find a list of possible functions and create a chain of comparison/direct-call blocks. Or we can use profiling to directly get the called functions and create blocks as before.

In CPF, we also can assume we have the whole program visibility (except standard library calls). With strong IPA or heavy inlining, the compiler should be able to figure out the concrete object type for most callsites and directly retrieve the function from the vtable (virtual function table).

Currently, we use two devirtualization methods. First is the profile-guided one pgo-icall-prom that comes with LLVM. Second is the static CPF one here liberty/lib/Devirt/.

LLVM PGO Indirect Call Promotion

This transformation uses LLVM profiling. LLVM comes with two profiling within as shown in PGOInstrumentation.

CPF Devirtualization

Analysis: liberty/lib/Analysis/Devirtualize.cpp Transformation: liberty/lib/Devirt/Devirtualize.cpp

Clone this wiki locally