LLVM: include/llvm/CAS/OnDiskGraphDB.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#ifndef LLVM_CAS_ONDISKGRAPHDB_H
17#define LLVM_CAS_ONDISKGRAPHDB_H
18
22
24
25
26class InternalRef {
27public:
30
33 return InternalRef(Offset.get());
34 }
35
37 return LHS.Data == RHS.Data;
38 }
39
40private:
44};
45
46
47class InternalRef4B {
48public:
51
52
55 if (Offset > UINT32_MAX)
56 return std::nullopt;
57 return InternalRef4B(Offset);
58 }
59
63
64private:
66 InternalRef4B(uint32_t Data) : Data(Data) {}
68};
69
70
72public:
73 size_t size() const { return Size; }
74 bool empty() const { return !Size; }
75
78 const InternalRef> {
79 public:
103 else
105 return *this;
106 }
110 else
112 return *this;
113 }
115
117
119
123 const InternalRef4B *>::getFromOpaqueValue((void *)
124 Opaque));
125 }
126
127 private:
131 : I(I) {}
133 };
134
138
141
142
144
147
149 if (is4B()) {
152 }
155 }
156
158
159
161 Begin = &PlaceHolder;
162 }
163
165 : Begin(Refs.begin()), Size(Refs.size()) {}
166
168 : Begin(Refs.begin()), Size(Refs.size()) {}
169
170private:
172 size_t Size = 0;
173};
174
175
176
177
178
179class ObjectID {
180public:
182
184
186 return LHS.Opaque == RHS.Opaque;
187 }
190 }
191
192private:
195};
196
197
199public:
202
205
207 return LHS.Opaque == RHS.Opaque;
208 }
211 }
212
213private:
215};
216
217
220 std::random_access_iterator_tag, ObjectID> {
221public:
228 return I - RHS.I;
229 }
231 I += N;
232 return *this;
233 }
235 I -= N;
236 return *this;
237 }
239
242
244
248
249private:
251};
252
254
255
256class OnDiskGraphDB {
257public:
258
259
260
261
264
265
267
268
273
274
275
277
278
279
280
283
284
285
287
288
289
293
294
296
297
302
303
304
305
306
308
309
310
311
313
315
316
319
320
321
322
323
324
325
327
328
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
356
358
359private:
360
361 struct IndexProxy;
362
363 enum class ObjectPresence {
364 Missing,
365 InPrimaryDB,
366 OnlyInUpstreamDB,
367 };
368
369
371 getObjectPresence(ObjectID Ref, bool CheckUpstream) const;
372
373
375 auto Presence = getObjectPresence(Ref, CheckUpstream);
376 if (!Presence) {
378 return false;
379 }
380 switch (*Presence) {
381 case ObjectPresence::Missing:
382 return false;
383 case ObjectPresence::InPrimaryDB:
384 return true;
385 case ObjectPresence::OnlyInUpstreamDB:
386 return true;
387 }
389 }
390
391
392
393 Expected<std::optional> faultInFromUpstream(ObjectID PrimaryID);
394
395
396 Error importFullTree(ObjectID PrimaryID, ObjectHandle UpstreamNode);
397
398 Error importSingleNode(ObjectID PrimaryID, ObjectHandle UpstreamNode);
399
400
401 Expected indexHash(ArrayRef<uint8_t> Hash);
402
403
404 void getStandalonePath(StringRef FileSuffix, const IndexProxy &I,
405 SmallVectorImpl &Path) const;
406
408
409
410
411 static InternalRef getInternalRef(ObjectID Ref) {
413 }
414
415 static ObjectID getExternalReference(InternalRef Ref) {
417 }
418
419 static ObjectID getExternalReference(const IndexProxy &I);
420
421 static InternalRef makeInternalRef(FileOffset IndexOffset);
422
425
427
428 Expected getIndexProxyFromRef(InternalRef Ref) const;
429
431 getIndexProxyFromPointer(OnDiskTrieRawHashMap::ConstOnDiskPtr P) const;
432
434 getInternalRefs(ObjectHandle Node) const;
435
436
437
438
439 std::atomic<uint64_t> &standaloneStorageSize() const;
440
441
442 void recordStandaloneSizeIncrease(size_t SizeIncrease);
443
444 uint64_t getStandaloneStorageSize() const;
445
446
447 OnDiskGraphDB(StringRef RootPath, OnDiskTrieRawHashMap Index,
448 OnDiskDataAllocator DataPool, OnDiskGraphDB *UpstreamDB,
450
451
452
453
454 OnDiskTrieRawHashMap Index;
455
456
457
458
459 OnDiskDataAllocator DataPool;
460
461
462 void *StandaloneData = nullptr;
463
464
465 std::string RootPath;
466
467
468 OnDiskGraphDB *UpstreamDB = nullptr;
469
470
472};
473
474}
475
476#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
AMDGPU Mark last scratch load
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ABI_FOR_TEST
This file declares interface for OnDiskDataAllocator, a file backed data pool can be used to allocate...
This file declares interface for OnDiskTrieRawHashMap, a thread-safe and (mostly) lock-free hash map ...
This file defines the PointerUnion class, which is a discriminated union of pointer types.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Lightweight error class with error context and mandatory checking.
Tagged union holding either a T or a Error.
A discriminated union of two or more pointer types, with the discriminator in the low bit of the poin...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
StringRef - Represent a constant reference to a string, i.e.
FileOffset is a wrapper around uint64_t to represent the offset of data from the beginning of the fil...
Compact 4 byte reference inside OnDiskGraphDB for smaller references.
Definition OnDiskGraphDB.h:47
FileOffset getFileOffset() const
Definition OnDiskGraphDB.h:49
friend class InternalRef
Definition OnDiskGraphDB.h:65
uint32_t getRawData() const
Definition OnDiskGraphDB.h:50
static std::optional< InternalRef4B > tryToShrink(InternalRef Ref)
Shrink to 4B reference.
Definition OnDiskGraphDB.h:53
Definition OnDiskGraphDB.h:78
ptrdiff_t operator-(const iterator &RHS) const
Definition OnDiskGraphDB.h:93
InternalRef operator[](ptrdiff_t N) const
Definition OnDiskGraphDB.h:114
InternalRef operator*() const
Definition OnDiskGraphDB.h:81
friend class InternalRefArrayRef
Definition OnDiskGraphDB.h:128
bool operator==(const iterator &RHS) const
Definition OnDiskGraphDB.h:80
iterator & operator+=(ptrdiff_t N)
Definition OnDiskGraphDB.h:100
uint64_t getOpaqueData() const
Definition OnDiskGraphDB.h:118
iterator & operator-=(ptrdiff_t N)
Definition OnDiskGraphDB.h:107
static iterator fromOpaqueData(uint64_t Opaque)
Definition OnDiskGraphDB.h:120
bool operator<(const iterator &RHS) const
Definition OnDiskGraphDB.h:86
Array of internal node references.
Definition OnDiskGraphDB.h:71
bool is8B() const
Definition OnDiskGraphDB.h:146
InternalRef operator[](ptrdiff_t N) const
Array accessor.
Definition OnDiskGraphDB.h:143
ArrayRef< uint8_t > getBuffer() const
Definition OnDiskGraphDB.h:148
size_t size() const
Definition OnDiskGraphDB.h:73
bool is4B() const
Definition OnDiskGraphDB.h:145
InternalRefArrayRef(std::nullopt_t=std::nullopt)
Definition OnDiskGraphDB.h:157
iterator begin() const
Definition OnDiskGraphDB.h:139
InternalRefArrayRef(ArrayRef< InternalRef4B > Refs)
Definition OnDiskGraphDB.h:167
bool empty() const
Definition OnDiskGraphDB.h:74
iterator end() const
Definition OnDiskGraphDB.h:140
bool operator==(const InternalRefArrayRef &RHS) const
Definition OnDiskGraphDB.h:135
InternalRefArrayRef(ArrayRef< InternalRef > Refs)
Definition OnDiskGraphDB.h:164
Standard 8 byte reference inside OnDiskGraphDB.
Definition OnDiskGraphDB.h:26
uint64_t getRawData() const
Definition OnDiskGraphDB.h:29
friend bool operator==(InternalRef LHS, InternalRef RHS)
Definition OnDiskGraphDB.h:36
FileOffset getFileOffset() const
Definition OnDiskGraphDB.h:28
static InternalRef getFromRawData(uint64_t Data)
Definition OnDiskGraphDB.h:31
static InternalRef getFromOffset(FileOffset Offset)
Definition OnDiskGraphDB.h:32
Handle for a loaded node object.
Definition OnDiskGraphDB.h:198
uint64_t getOpaqueData() const
Definition OnDiskGraphDB.h:201
static ObjectHandle fromFileOffset(FileOffset Offset)
static ObjectHandle fromMemory(uintptr_t Ptr)
ObjectHandle(uint64_t Opaque)
Definition OnDiskGraphDB.h:200
friend bool operator!=(const ObjectHandle &LHS, const ObjectHandle &RHS)
Definition OnDiskGraphDB.h:209
friend bool operator==(const ObjectHandle &LHS, const ObjectHandle &RHS)
Definition OnDiskGraphDB.h:206
Reference to a node.
Definition OnDiskGraphDB.h:179
friend bool operator!=(const ObjectID &LHS, const ObjectID &RHS)
Definition OnDiskGraphDB.h:188
uint64_t getOpaqueData() const
Definition OnDiskGraphDB.h:181
friend bool operator==(const ObjectID &LHS, const ObjectID &RHS)
Definition OnDiskGraphDB.h:185
static ObjectID fromOpaqueData(uint64_t Opaque)
Definition OnDiskGraphDB.h:183
On-disk CAS nodes database, independent of a particular hashing algorithm.
Definition OnDiskGraphDB.h:256
FaultInPolicy
How to fault-in nodes if an upstream database is used.
Definition OnDiskGraphDB.h:329
@ FullTree
Copy the the entire graph of a node.
Definition OnDiskGraphDB.h:333
@ SingleNode
Copy only the requested node.
Definition OnDiskGraphDB.h:331
void print(raw_ostream &OS) const
Expected< bool > isMaterialized(ObjectID Ref)
Check whether the object associated with Ref is stored in the CAS.
Error validate(bool Deep, HashingFuncT Hasher) const
Validate the OnDiskGraphDB.
bool containsObject(ObjectID Ref) const
Check whether the object associated with Ref is stored in the CAS.
Definition OnDiskGraphDB.h:290
object_refs_range getObjectRefs(ObjectHandle Node) const
Definition OnDiskGraphDB.h:298
unsigned getHardStorageLimitUtilization() const
LLVM_ABI_FOR_TEST Error store(ObjectID ID, ArrayRef< ObjectID > Refs, ArrayRef< char > Data)
Associate data & references with a particular object ID.
ArrayRef< uint8_t > getDigest(ObjectID Ref) const
Definition OnDiskGraphDB.h:269
static LLVM_ABI_FOR_TEST Expected< std::unique_ptr< OnDiskGraphDB > > open(StringRef Path, StringRef HashName, unsigned HashByteSize, OnDiskGraphDB *UpstreamDB=nullptr, FaultInPolicy Policy=FaultInPolicy::FullTree)
Open the on-disk store from a directory.
LLVM_ABI_FOR_TEST std::optional< ObjectID > getExistingReference(ArrayRef< uint8_t > Digest)
Get an existing reference to the object Digest.
LLVM_ABI_FOR_TEST size_t getStorageSize() const
LLVM_ABI_FOR_TEST ~OnDiskGraphDB()
LLVM_ABI_FOR_TEST Expected< ObjectID > getReference(ArrayRef< uint8_t > Hash)
Form a reference for the provided hash.
function_ref< void( ArrayRef< ArrayRef< uint8_t > >, ArrayRef< char >, SmallVectorImpl< uint8_t > &)> HashingFuncT
Hashing function type for validation.
Definition OnDiskGraphDB.h:317
LLVM_ABI_FOR_TEST ArrayRef< char > getObjectData(ObjectHandle Node) const
object_refs_iterator & operator-=(ptrdiff_t N)
Definition OnDiskGraphDB.h:234
bool operator<(const object_refs_iterator &RHS) const
Definition OnDiskGraphDB.h:226
object_refs_iterator & operator+=(ptrdiff_t N)
Definition OnDiskGraphDB.h:230
ptrdiff_t operator-(const object_refs_iterator &RHS) const
Definition OnDiskGraphDB.h:227
uint64_t getOpaqueData() const
Definition OnDiskGraphDB.h:243
bool operator==(const object_refs_iterator &RHS) const
Definition OnDiskGraphDB.h:222
ObjectID operator[](ptrdiff_t N) const
Definition OnDiskGraphDB.h:238
ObjectID operator*() const
Definition OnDiskGraphDB.h:223
object_refs_iterator()=default
static object_refs_iterator fromOpaqueData(uint64_t Opaque)
Definition OnDiskGraphDB.h:245
object_refs_iterator(InternalRefArrayRef::iterator I)
Definition OnDiskGraphDB.h:241
An efficient, type-erasing, non-owning reference to a callable.
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
iterator operator+(std::ptrdiff_t n) const
A range adaptor for a pair of iterators.
This class implements an extremely fast bulk output stream that can only output to a stream.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition OnDiskGraphDB.h:23
llvm::iterator_range< object_refs_iterator > object_refs_range
Definition OnDiskGraphDB.h:253
decltype(auto) dyn_cast(const From &Val)
dyn_cast - Return the argument parameter cast to the specified type.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
bool isa(const From &Val)
isa - Return true if the parameter to the template is an instance of one of the template type argu...
@ Ref
The access may reference the value stored in memory.
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
FunctionAddr VTableAddr uintptr_t uintptr_t Data
ArrayRef(const T &OneElt) -> ArrayRef< T >
decltype(auto) cast(const From &Val)
cast - Return the argument parameter cast to the specified type.
void consumeError(Error Err)
Consume a Error without doing anything.
Proxy for an on-disk index record.