16#include "llvm/Config/llvm-config.h"
22#if LLVM_ENABLE_ONDISK_CAS
37class DataAllocatorHandle {
40 TableHandle::TableKind::DataAllocator;
43 TableHandle::Header GenericHeader;
44 std::atomic<int64_t> AllocatorOffset;
45 const uint64_t UserHeaderSize;
48 operator TableHandle()
const {
51 return TableHandle(*Region,
H->GenericHeader);
54 Expected<MutableArrayRef<char>> allocate(MappedFileRegionArena &
Alloc,
59 return Ptr.takeError();
63 explicit operator bool()
const {
return H; }
64 const Header &getHeader()
const {
return *
H; }
67 MutableArrayRef<uint8_t> getUserHeader() {
72 static Expected<DataAllocatorHandle>
73 create(MappedFileRegionArena &
Alloc, StringRef Name, uint32_t UserHeaderSize);
75 DataAllocatorHandle() =
default;
79 : DataAllocatorHandle(
92 DataAllocatorHandle
Store;
100 Alloc.allocateOffset(
sizeof(Header) + UserHeaderSize +
Name.size() + 1);
102 return Offset.takeError();
105 assert(
Name.size() <= UINT16_MAX &&
"Expected smaller table name");
109 static_cast<int32_t
>(
sizeof(Header) + UserHeaderSize)},
113 char *UserHeader =
reinterpret_cast<char *
>(
H + 1);
114 memset(UserHeader, 0, UserHeaderSize);
116 char *NameStorage = UserHeader + UserHeaderSize;
118 NameStorage[
Name.size()] = 0;
119 return DataAllocatorHandle(
Alloc.getRegion(), *
H);
124 std::optional<uint64_t> NewFileInitialSize,
uint32_t UserHeaderSize,
125 std::shared_ptr<ondisk::OnDiskCASLogger>
Logger,
127 assert(!UserHeaderSize || UserHeaderInit);
128 SmallString<128> PathStorage;
130 SmallString<128> TableNameStorage;
131 StringRef TableName = TableNameTwine.
toStringRef(TableNameStorage);
134 auto NewDBConstructor = [&](DatabaseFile &
DB) ->
Error {
136 DataAllocatorHandle::create(
DB.getAlloc(), TableName, UserHeaderSize);
138 return Store.takeError();
140 if (
auto E =
DB.addTable(*Store))
144 UserHeaderInit(
Store->getUserHeader().data());
149 Expected<DatabaseFile>
File =
152 return File.takeError();
155 std::optional<TableHandle> Table =
File->findTable(TableName);
158 TableName,
"table not found");
160 (
size_t)Table->getHeader().Kind, Path, TableName))
162 auto Store = Table->cast<DataAllocatorHandle>();
163 assert(Store &&
"Already checked the kind");
166 OnDiskDataAllocator::ImplType Impl{DatabaseFile(std::move(*File)),
Store};
170Expected<OnDiskDataAllocator::OnDiskPtr>
172 auto Data = Impl->Store.allocate(Impl->File.getAlloc(),
Size);
174 return Data.takeError();
176 return OnDiskPtr(FileOffset(
Data->data() - Impl->Store.getRegion().data()),
184 if (
Offset.get() +
Size >= Impl->File.getAlloc().size())
186 "requested size too large in allocator");
187 return ArrayRef<char>{Impl->File.getRegion().data() +
Offset.get(),
Size};
191 return Impl->Store.getUserHeader();
196 return Impl->File.getRegion().size();
200 : Impl(std::
move(Impl)) {}
208 std::optional<uint64_t> NewFileInitialSize,
uint32_t UserHeaderSize,
209 std::shared_ptr<ondisk::OnDiskCASLogger>
Logger,
212 "OnDiskDataAllocator is not supported");
218 "OnDiskDataAllocator is not supported");
224 "OnDiskDataAllocator is not supported");
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
AMDGPU Prepare AGPR Alloc
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_UNLIKELY(EXPR)
This file declares the common interface for a DatabaseFile that is used to implement OnDiskCAS.
This file declares interface for OnDiskCASLogger, an interface that can be used to log CAS events to ...
This file declares interface for OnDiskDataAllocator, a file backed data pool can be used to allocate...
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Logging utility - given an ordered specification of features, and assuming a scalar reward,...
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
StringRef - Represent a constant reference to a string, i.e.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
StringRef toStringRef(SmallVectorImpl< char > &Out) const
This returns the twine as a single StringRef if it can be represented as such.
FileOffset is a wrapper around uint64_t to represent the offset of data from the beginning of the fil...
Allocator for an owned mapped file region that supports thread-safe and process-safe bump pointer all...
A pointer to data stored on disk.
LLVM_ABI_FOR_TEST ~OnDiskDataAllocator()
MutableArrayRef< uint8_t > getUserHeader() const
LLVM_ABI_FOR_TEST Expected< OnDiskPtr > allocate(size_t Size)
Allocate at least Size with 8-byte alignment.
LLVM_ABI_FOR_TEST Expected< ArrayRef< char > > get(FileOffset Offset, size_t Size) const
Get the data of Size stored at the given Offset.
static LLVM_ABI_FOR_TEST Expected< OnDiskDataAllocator > create(const Twine &Path, const Twine &TableName, uint64_t MaxFileSize, std::optional< uint64_t > NewFileInitialSize, uint32_t UserHeaderSize=0, std::shared_ptr< ondisk::OnDiskCASLogger > Logger=nullptr, function_ref< void(void *)> UserHeaderInit=nullptr)
LLVM_ABI_FOR_TEST size_t size() const
LLVM_ABI_FOR_TEST OnDiskDataAllocator & operator=(OnDiskDataAllocator &&RHS)
LLVM_ABI_FOR_TEST OnDiskDataAllocator(OnDiskDataAllocator &&RHS)
LLVM_ABI_FOR_TEST size_t capacity() const
static Expected< DatabaseFile > create(const Twine &Path, uint64_t Capacity, std::shared_ptr< OnDiskCASLogger > Logger, function_ref< Error(DatabaseFile &)> NewDBConstructor)
Create the DatabaseFile at Path with Capacity.
An efficient, type-erasing, non-owning reference to a callable.
Error createTableConfigError(std::errc ErrC, StringRef Path, StringRef TableName, const Twine &Msg)
MappedFileRegionArena::RegionT MappedFileRegion
Error checkTable(StringRef Label, size_t Expected, size_t Observed, StringRef Path, StringRef TrieName)
This is an optimization pass for GlobalISel generic memory operations.
std::error_code make_error_code(BitcodeError E)
FunctionAddr VTableAddr uintptr_t uintptr_t DataSize
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
MutableArrayRef(T &OneElt) -> MutableArrayRef< T >
FunctionAddr VTableAddr uintptr_t uintptr_t Data
OutputIt copy(R &&Range, OutputIt Out)
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.