15#include "llvm/Config/llvm-config.h"
21#if LLVM_ENABLE_ONDISK_CAS
36class DataAllocatorHandle {
39 TableHandle::TableKind::DataAllocator;
42 TableHandle::Header GenericHeader;
43 std::atomic<int64_t> AllocatorOffset;
44 const uint64_t UserHeaderSize;
47 operator TableHandle()
const {
50 return TableHandle(*Region,
H->GenericHeader);
53 Expected<MutableArrayRef<char>> allocate(MappedFileRegionArena &
Alloc,
58 return Ptr.takeError();
62 explicit operator bool()
const {
return H; }
63 const Header &getHeader()
const {
return *
H; }
66 MutableArrayRef<uint8_t> getUserHeader() {
71 static Expected<DataAllocatorHandle>
72 create(MappedFileRegionArena &
Alloc, StringRef Name, uint32_t UserHeaderSize);
74 DataAllocatorHandle() =
default;
78 : DataAllocatorHandle(
91 DataAllocatorHandle
Store;
99 Alloc.allocateOffset(
sizeof(Header) + UserHeaderSize +
Name.size() + 1);
101 return Offset.takeError();
104 assert(
Name.size() <= UINT16_MAX &&
"Expected smaller table name");
108 static_cast<int32_t
>(
sizeof(Header) + UserHeaderSize)},
112 char *UserHeader =
reinterpret_cast<char *
>(
H + 1);
113 memset(UserHeader, 0, UserHeaderSize);
115 char *NameStorage = UserHeader + UserHeaderSize;
117 NameStorage[
Name.size()] = 0;
118 return DataAllocatorHandle(
Alloc.getRegion(), *
H);
123 std::optional<uint64_t> NewFileInitialSize,
uint32_t UserHeaderSize,
125 assert(!UserHeaderSize || UserHeaderInit);
126 SmallString<128> PathStorage;
128 SmallString<128> TableNameStorage;
129 StringRef TableName = TableNameTwine.
toStringRef(TableNameStorage);
132 auto NewDBConstructor = [&](DatabaseFile &
DB) ->
Error {
134 DataAllocatorHandle::create(
DB.getAlloc(), TableName, UserHeaderSize);
136 return Store.takeError();
138 if (
auto E =
DB.addTable(*Store))
142 UserHeaderInit(
Store->getUserHeader().data());
147 Expected<DatabaseFile>
File =
150 return File.takeError();
153 std::optional<TableHandle> Table =
File->findTable(TableName);
156 TableName,
"table not found");
158 (
size_t)Table->getHeader().Kind, Path, TableName))
160 auto Store = Table->cast<DataAllocatorHandle>();
161 assert(Store &&
"Already checked the kind");
164 OnDiskDataAllocator::ImplType Impl{DatabaseFile(std::move(*File)),
Store};
168Expected<OnDiskDataAllocator::OnDiskPtr>
170 auto Data = Impl->Store.allocate(Impl->File.getAlloc(),
Size);
172 return Data.takeError();
174 return OnDiskPtr(FileOffset(
Data->data() - Impl->Store.getRegion().data()),
182 if (
Offset.get() +
Size >= Impl->File.getAlloc().size())
184 "requested size too large in allocator");
185 return ArrayRef<char>{Impl->File.getRegion().data() +
Offset.get(),
Size};
189 return Impl->Store.getUserHeader();
194 return Impl->File.getRegion().size();
198 : Impl(std::
move(Impl)) {}
206 std::optional<uint64_t> NewFileInitialSize,
uint32_t UserHeaderSize,
209 "OnDiskDataAllocator is not supported");
215 "OnDiskDataAllocator is not supported");
221 "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 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.
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.
Expected< OnDiskPtr > allocate(size_t Size)
Allocate at least Size with 8-byte alignment.
Expected< ArrayRef< char > > get(FileOffset Offset, size_t Size) const
Get the data of Size stored at the given Offset.
static Expected< OnDiskDataAllocator > create(const Twine &Path, const Twine &TableName, uint64_t MaxFileSize, std::optional< uint64_t > NewFileInitialSize, uint32_t UserHeaderSize=0, function_ref< void(void *)> UserHeaderInit=nullptr)
OnDiskDataAllocator & operator=(OnDiskDataAllocator &&RHS)
OnDiskDataAllocator(OnDiskDataAllocator &&RHS)
MutableArrayRef< uint8_t > getUserHeader()
static Expected< DatabaseFile > create(const Twine &Path, uint64_t Capacity, 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.