This is an archive of the discontinued LLVM Phabricator instance.

[Support][Allocator] Add C++17 memory_resource adaptor for LLVM allocators
AbandonedPublic

Authored by jfurtek on Jun 23 2023, 3:20 PM.

Details

Summary

C++17 added support for polymorphic memory resources to the standard library:

https://isocpp.org/files/papers/N3916.pdf

Prior to polymorphic memory resources, the allocator was part of the compile-
time type for C++ containers. (As an example, std::vector instances with
different allocators were distinct C++ types.) With polymorphic memory
resources, the memory_resource abstract base class provides an interface that
different allocators can implement, allowing containers with different
allocators to have the same type. Runtime allocator dispatch occurs via a
virtual function call.

This diff adds a memory_resource adaptor for LLVM allocators (and in
particular, the BumpPtrAllocator). This is an opt-in modification: no existing
uses of the ubiquitous BumpPtrAllocator are affected.

With the new adaptor, LLVM code that uses the BumpPtrAllocator can make use of
the standard C++ library containers with PMR support (i.e. std::pmr::vector<>,
std::pmr::list<>, std::pmr::string, ...), with container allocations using
the LLVM BumpPtrAllocator.

Future MLIR diffs may use this feature. Those are being kept separate from this
diff to facilitate review.

Diff Detail

Event Timeline

jfurtek created this revision.Jun 23 2023, 3:20 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 23 2023, 3:20 PM
jfurtek requested review of this revision.Jun 23 2023, 3:20 PM

Have you checked that the minimal supported compilers/versions support pmr? I have the latest Xcode with libc++ version 15 and there is no pmr support.

Have you checked that the minimal supported compilers/versions support pmr? I have the latest Xcode with libc++ version 15 and there is no pmr support.

I had not checked, but you are right: there is a red square here:

https://en.cppreference.com/w/cpp/compiler_support/17#C.2B.2B17_library_features

It looks there might be support in Xcode 15 Beta, whereas LLVM 17 must work with 10.0. So I'm only off by 5 or 6 versions. ;-)

https://developer.apple.com/documentation/xcode-release-notes/xcode-15-release-notes
https://developer.apple.com/xcode/cpp/

Closing.

jfurtek abandoned this revision.Jun 24 2023, 11:05 AM