arXivDaily arXiv每日学术速递 周一至周五更新
北美退伍军人节(Veterans Day),12 日无更新
arXiv 2003.04228cs.PLcs.PF
收藏

LLVM中虚指针不变性的建模

Modeling the Invariance of Virtual Pointers in LLVM

Piotr Padlewski, Krzysztof Pszeniczny, Richard Smith

摘要:

去虚拟化是一种编译器优化,它将间接(虚拟)函数调用替换为直接调用。它在面向对象的语言中特别有效,如Java或C++,其中虚方法通常很丰富。我们提出了一种新的抽象模型来表达C++动态对象的生命周期和LLVM中间表示中虚表指针的不变性。Clang和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.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑