LLVM: lib/CAS/DatabaseFile.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#ifndef LLVM_LIB_CAS_DATABASEFILE_H
16#define LLVM_LIB_CAS_DATABASEFILE_H
17
21
23
25
26
27
28
29
30
31
33public:
43
44 explicit operator bool() const { return H; }
47
48 template static void check() {
49 static_assert(
50 std::is_same<decltype(T::Header::GenericHeader), Header>::value,
51 "T::GenericHeader should be of type TableHandle::Header");
52 static_assert(offsetof(typename T::Header, GenericHeader) == 0,
53 "T::GenericHeader must be the head of T::Header");
54 }
55 template bool is() const { return T::Kind == H->Kind; }
59 return T(*Region, *reinterpret_cast<typename T::Header *>(H));
60 return T();
61 }
65 }
66
68 auto *Begin = reinterpret_cast<const char *>(H) + H->NameRelOffset;
69 return StringRef(Begin, H->NameSize);
70 }
71
76 *reinterpret_cast<Header *>(Region.data() + HeaderOffset)) {
77 }
78
79private:
81 Header *H = nullptr;
82};
83
84
85
86
87
88
89
90
91
92
93
94
95class DatabaseFile {
96public:
104
108
109
110
112
113
115
116
120
121 size_t size() const { return Alloc.size(); }
122
123private:
125 get(std::unique_ptr Alloc) {
126 if (Error E = validate(Alloc->getRegion()))
127 return std::move(E);
129 }
130
132
135 DatabaseFile(std::unique_ptr Alloc)
136 : DatabaseFile(*Alloc) {
137 OwnedAlloc = std::move(Alloc);
138 }
139
140 Header *H = nullptr;
141 MappedFileRegionArena &Alloc;
142 std::unique_ptr OwnedAlloc;
143};
144
146 StringRef TableName, const Twine &Msg);
147
148Error checkTable(StringRef Label, size_t Expected, size_t Observed,
149 StringRef Path, StringRef TrieName);
150
151}
152
153#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
AMDGPU Prepare AGPR Alloc
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define offsetof(TYPE, MEMBER)
This file declares interface for MappedFileRegionArena, a bump pointer allocator, backed by a memory-...
Lightweight error class with error context and mandatory checking.
Tagged union holding either a T or a Error.
StringRef - Represent a constant reference to a string, i.e.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Allocator for an owned mapped file region that supports thread-safe and process-safe bump pointer all...
sys::fs::mapped_file_region RegionT
Encapsulate a database file, which:
Definition DatabaseFile.h:95
static Expected< DatabaseFile > create(const Twine &Path, uint64_t Capacity, function_ref< Error(DatabaseFile &)> NewDBConstructor)
Create the DatabaseFile at Path with Capacity.
std::optional< TableHandle > findTable(StringRef Name)
Find a table. May return null.
static constexpr uint32_t getVersion()
Definition DatabaseFile.h:98
MappedFileRegionArena & getAlloc()
Definition DatabaseFile.h:106
static constexpr uint32_t getMagic()
Definition DatabaseFile.h:97
size_t size() const
Definition DatabaseFile.h:121
MappedFileRegion & getRegion()
Definition DatabaseFile.h:107
const Header & getHeader()
Definition DatabaseFile.h:105
Error addTable(TableHandle Table)
Add a table.
Generic handle for a table.
Definition DatabaseFile.h:32
static void check()
Definition DatabaseFile.h:48
TableHandle(MappedFileRegion &Region, Header &H)
Definition DatabaseFile.h:73
T cast() const
Definition DatabaseFile.h:62
const Header & getHeader() const
Definition DatabaseFile.h:45
TableKind
Definition DatabaseFile.h:34
@ DataAllocator
Definition DatabaseFile.h:36
@ TrieRawHashMap
Definition DatabaseFile.h:35
StringRef getName() const
Definition DatabaseFile.h:67
MappedFileRegion & getRegion() const
Definition DatabaseFile.h:46
TableHandle(MappedFileRegion &Region, intptr_t HeaderOffset)
Definition DatabaseFile.h:74
T dyn_cast() const
Definition DatabaseFile.h:56
bool is() const
Definition DatabaseFile.h:55
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
Definition DatabaseFile.h:24
Error checkTable(StringRef Label, size_t Expected, size_t Observed, StringRef Path, StringRef TrieName)
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
Definition DatabaseFile.h:38
int32_t NameRelOffset
Relative to Header.
Definition DatabaseFile.h:41
TableKind Kind
Definition DatabaseFile.h:39
uint16_t NameSize
Definition DatabaseFile.h:40