论文标题

在LLVM中建模虚拟指针的不变性

Modeling the Invariance of Virtual Pointers in LLVM

论文作者

Padlewski, Piotr, Pszeniczny, Krzysztof, Smith, Richard

论文摘要

Devirtualization是一种编译器优化,用直接调用替换间接(虚拟)函数。它在面向对象的语言中特别有效,例如Java或C ++,其中虚拟方法通常很丰富。 我们提出了一个新颖的抽象模型,以表达LLVM中间表示中C ++动态对象的寿命和虚拟表指针的不变性。每当动态类型在静态已知并消除冗余虚拟表负载时,模型和LLVM中的相应实现就可以对虚拟呼叫进行完整的虚拟调用。 由于C ++的复杂性,到目前为止,任何其他C ++编译器尚未实现这一目标。尽管我们的模型是为C ++设计的,但它也适用于使用虚拟调度的其他语言。我们的基准测试表明,现实世界中C ++计划的平均性能提高了0.8%,在某些情况下,速度超过30%。该实现已经是上游LLVM/Clang的一部分,可以使用-fstrict-vtable-pointers标志启用。

Devirtualization is a compiler optimization that replaces indirect (virtual) function calls with direct calls. It is particularly effective in object-oriented languages, such as Java or C++, in which virtual methods are typically abundant. We present a novel abstract model to express the lifetimes of C++ dynamic objects and invariance of virtual table pointers in the LLVM intermediate representation. The model and the corresponding implementation in Clang and LLVM enable full devirtualization of virtual calls whenever the dynamic type is statically known and elimination of redundant virtual table loads in other cases. Due to the complexity of C++, this has not been achieved by any other C++ compiler so far. Although our model was designed for C++, it is also applicable to other languages that use virtual dispatch. Our benchmarks show an average of 0.8% performance improvement on real-world C++ programs, with more than 30% speedup in some cases. The implementation is already a part of the upstream LLVM/Clang and can be enabled with the -fstrict-vtable-pointers flag.

扫码加入交流群

加入微信交流群

微信交流群二维码

扫码加入学术交流群,获取更多资源