LLVM 23.0.0git
OnDiskDataAllocator.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9/// \file
10/// This file declares interface for OnDiskDataAllocator, a file backed data
11/// pool can be used to allocate space to store data packed in a single file. It
12/// is based on MappedFileRegionArena and includes a header in the beginning to
13/// provide metadata.
14///
15//===----------------------------------------------------------------------===//
16
17#ifndef LLVM_CAS_ONDISKDATAALLOCATOR_H
18#define LLVM_CAS_ONDISKDATAALLOCATOR_H
19
20#include "llvm/ADT/ArrayRef.h"
21#include "llvm/CAS/FileOffset.h"
23#include "llvm/Support/Error.h"
24
25namespace llvm::cas {
26
27/// Sink for data. Stores variable length data with 8-byte alignment. Does not
28/// track size of data, which is assumed to known from context, or embedded.
29/// Uses 0-padding but does not guarantee 0-termination.
31public:
33
34 /// A pointer to data stored on disk.
35 class OnDiskPtr {
36 public:
37 FileOffset getOffset() const { return Offset; }
38 explicit operator bool() const { return bool(getOffset()); }
39 const ValueProxy &operator*() const {
40 assert(Offset && "Null dereference");
41 return Value;
42 }
43 const ValueProxy *operator->() const {
44 assert(Offset && "Null dereference");
45 return &Value;
46 }
47
48 OnDiskPtr() = default;
49
50 private:
51 friend class OnDiskDataAllocator;
52 OnDiskPtr(FileOffset Offset, ValueProxy Value)
53 : Offset(Offset), Value(Value) {}
56 };
57
58 /// Get the data of \p Size stored at the given \p Offset. Note the allocator
59 /// doesn't keep track of the allocation size, thus \p Size doesn't need to
60 /// match the size of allocation but needs to be smaller.
62 size_t Size) const;
63
64 /// Allocate at least \p Size with 8-byte alignment.
66
67 /// \returns the buffer that was allocated at \p create time, with size
68 /// \p UserHeaderSize.
70
71 LLVM_ABI_FOR_TEST size_t size() const;
72 LLVM_ABI_FOR_TEST size_t capacity() const;
73
75 create(const Twine &Path, const Twine &TableName, uint64_t MaxFileSize,
76 std::optional<uint64_t> NewFileInitialSize,
77 uint32_t UserHeaderSize = 0,
78 std::shared_ptr<ondisk::OnDiskCASLogger> Logger = nullptr,
79 function_ref<void(void *)> UserHeaderInit = nullptr);
80
83
84 // No copy. Just call \a create() again.
87
89
90private:
91 struct ImplType;
92 explicit OnDiskDataAllocator(std::unique_ptr<ImplType> Impl);
93 std::unique_ptr<ImplType> Impl;
94};
95
96} // namespace llvm::cas
97
98#endif // LLVM_CAS_ONDISKDATAALLOCATOR_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define LLVM_ABI_FOR_TEST
Definition Compiler.h:218
This file declares interface for FileOffset that represent stored data at an offset from the beginnin...
This file declares interface for OnDiskCASLogger, an interface that can be used to log CAS events to ...
Value * RHS
Tagged union holding either a T or a Error.
Definition Error.h:485
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...
Definition ArrayRef.h:298
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
LLVM Value Representation.
Definition Value.h:75
FileOffset is a wrapper around uint64_t to represent the offset of data from the beginning of the fil...
Definition FileOffset.h:24
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.
OnDiskDataAllocator & operator=(const OnDiskDataAllocator &)=delete
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
MutableArrayRef< char > ValueProxy
LLVM_ABI_FOR_TEST OnDiskDataAllocator & operator=(OnDiskDataAllocator &&RHS)
LLVM_ABI_FOR_TEST OnDiskDataAllocator(OnDiskDataAllocator &&RHS)
OnDiskDataAllocator(const OnDiskDataAllocator &)=delete
LLVM_ABI_FOR_TEST size_t capacity() const
An efficient, type-erasing, non-owning reference to a callable.
@ Offset
Definition DWP.cpp:532