This is an archive of the discontinued LLVM Phabricator instance.

CGExprCXX: emit family and allockind attributes
Needs ReviewPublic

Authored by durin42 on Jun 7 2023, 3:05 PM.

Details

Reviewers
nikic
Summary

This allows us to remove most of the special knowledge about C++
allocation from LLVM, instead trusting attributes to communicate the
important properties.

Annoyingly, clang has to grow a little bit of hard-coded knowledge about
mangled symbol names in order to actually get the most-basic-matching
::operator::new when working out the alloc-family attribute. I spent
some time trying to do this "right" by looking up the available
operators new and finding the best one, but that's super tricky and this
has the virtue of working and being pretty obviously correct when
compared to the old code.

Happily, clang now emits allocator family attributes correctly even for
custom allocators like the one on new_hot_cold.cpp, which is similar
to tcmalloc per the comments. As a result, clang/llvm should correctly
optimize custom allocators like this without needing specialized
knowledge going forward.

Diff Detail

Event Timeline

durin42 created this revision.Jun 7 2023, 3:05 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 7 2023, 3:05 PM
durin42 requested review of this revision.Jun 7 2023, 3:05 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJun 7 2023, 3:05 PM
durin42 updated this revision to Diff 529617.Jun 8 2023, 8:49 AM
durin42 edited the summary of this revision. (Show Details)

FYI: this is ready for review.

As a result, clang/llvm should correctly
optimize custom allocators like this without needing specialized
knowledge going forward.

Not exactly: we still need knowledge of this in clang (isReplaceableGlobalAllocationFunction was taught that the variant with a __hot_cold_t parameter is a replaceable global allocation function, without which knowledge this optimization cannot apply). However we do get rid of that from llvm, which is a nice cleanup!