[clang] [Clang] Add support for GCC bound member functions extension (PR #135649)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 18 22:14:46 PDT 2025
rockeet wrote:
We used this extension to improve virtual function calling performance, there are simple and small virtual functions which are frequently called and can not be eliminated and it is in a delegation thus compiler can not optimize, so we use pmf to bound the virtual function, like this:
```c++
#if defined(_MSC_VER) || defined(__clang__)
#define IF_BOUND_PMF(Then, Else) Else
#else
#define IF_BOUND_PMF(Then, Else) Then
#endif
void SetSubReader(const ToplingZipSubReader* sub) {
subReader_ = sub;
iter_ = sub->index_->NewIterator();
store_ = sub->store_.get();
get_record_append_ = store_->m_get_record_append_CacheOffsets;
#if defined(_MSC_VER) || defined(__clang__)
#else
iter_next_ = (IterScanFN)(iter_->*(&COIndex::Iterator::Next));
iter_prev_ = (IterScanFN)(iter_->*(&COIndex::Iterator::Prev));
#endif
tag_rs_kind_ = sub->tag_rs_kind_;
}
inline bool IndexIterInvokeNext() {
return IF_BOUND_PMF(iter_next_(iter_), iter_->Next());
}
inline bool IndexIterInvokePrev() {
return IF_BOUND_PMF(iter_prev_(iter_), iter_->Prev());
}
```
In which `iter_->Next()` is a small virtual function for different index type, we save the pmf as a member, thus reduced the virtual function calling overhead.
https://github.com/llvm/llvm-project/pull/135649
More information about the cfe-commits
mailing list