LLVM: lib/CAS/OnDiskCAS.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
16
17using namespace llvm;
20
21namespace {
22
24public:
25 Expected storeImpl(ArrayRef<uint8_t> ComputedHash,
27 ArrayRef Data) final;
28
29 Expected<std::optional> loadIfExists(ObjectRef Ref) final;
30
31 CASID getID(ObjectRef Ref) const final;
32
33 std::optional getReference(const CASID &ID) const final;
34
35 Expected isMaterialized(ObjectRef Ref) const final;
36
37 ArrayRef getDataConst(ObjectHandle Node) const final;
38
39 void print(raw_ostream &OS) const final;
41
42 static Expected<std::unique_ptr> open(StringRef Path);
43
44 OnDiskCAS(std::shared_ptrondisk::UnifiedOnDiskCache UniDB)
45 : UnifiedDB(std::move(UniDB)), DB(&UnifiedDB->getGraphDB()) {}
46
47private:
48 ObjectHandle convertHandle(ondisk::ObjectHandle Node) const {
49 return makeObjectHandle(Node.getOpaqueData());
50 }
51
52 ondisk::ObjectHandle convertHandle(ObjectHandle Node) const {
53 return ondisk::ObjectHandle(Node.getInternalRef(*this));
54 }
55
56 ObjectRef convertRef(ondisk::ObjectID Ref) const {
57 return makeObjectRef(Ref.getOpaqueData());
58 }
59
60 ondisk::ObjectID convertRef(ObjectRef Ref) const {
62 }
63
64 size_t getNumRefs(ObjectHandle Node) const final {
65 auto RefsRange = DB->getObjectRefs(convertHandle(Node));
67 }
68
69 ObjectRef readRef(ObjectHandle Node, size_t I) const final {
70 auto RefsRange = DB->getObjectRefs(convertHandle(Node));
71 return convertRef(RefsRange.begin()[I]);
72 }
73
74 Error forEachRef(ObjectHandle Node,
75 function_ref<Error(ObjectRef)> Callback) const final;
76
77 Error setSizeLimit(std::optional<uint64_t> SizeLimit) final;
78 Expected<std::optional<uint64_t>> getStorageSize() const final;
79 Error pruneStorageData() final;
80
81 OnDiskCAS(std::unique_ptrondisk::OnDiskGraphDB GraphDB)
82 : OwnedDB(std::move(GraphDB)), DB(OwnedDB.get()) {}
83
84 std::unique_ptrondisk::OnDiskGraphDB OwnedDB;
85 std::shared_ptrondisk::UnifiedOnDiskCache UnifiedDB;
86 ondisk::OnDiskGraphDB *DB;
87};
88
89}
90
91void OnDiskCAS::print(raw_ostream &OS) const { DB->print(OS); }
92Error OnDiskCAS::validate(bool CheckHash) const {
94 SmallVectorImpl<uint8_t> &Result) {
97 Result.assign(Hash.begin(), Hash.end());
98 };
99
100 if (auto E = DB->validate(CheckHash, Hasher))
101 return E;
102
104}
105
106CASID OnDiskCAS::getID(ObjectRef Ref) const {
107 ArrayRef<uint8_t> Hash = DB->getDigest(convertRef(Ref));
109}
110
111std::optional OnDiskCAS::getReference(const CASID &ID) const {
112 std::optionalondisk::ObjectID ObjID =
114 if (!ObjID)
115 return std::nullopt;
116 return convertRef(*ObjID);
117}
118
119Expected OnDiskCAS::isMaterialized(ObjectRef ExternalRef) const {
121}
122
123ArrayRef OnDiskCAS::getDataConst(ObjectHandle Node) const {
125}
126
127Expected<std::optional>
128OnDiskCAS::loadIfExists(ObjectRef ExternalRef) {
129 Expected<std::optionalondisk::ObjectHandle> ObjHnd =
130 DB->load(convertRef(ExternalRef));
131 if (!ObjHnd)
133 if (!*ObjHnd)
134 return std::nullopt;
135 return convertHandle(**ObjHnd);
136}
137
138Expected OnDiskCAS::storeImpl(ArrayRef<uint8_t> ComputedHash,
140 ArrayRef Data) {
143 for (ObjectRef Ref : Refs) {
145 }
146
147 auto StoredID = DB->getReference(ComputedHash);
149 return StoredID.takeError();
151 return std::move(E);
152 return convertRef(*StoredID);
153}
154
155Error OnDiskCAS::forEachRef(ObjectHandle Node,
156 function_ref<Error(ObjectRef)> Callback) const {
157 auto RefsRange = DB->getObjectRefs(convertHandle(Node));
158 for (ondisk::ObjectID Ref : RefsRange) {
160 return E;
161 }
163}
164
165Error OnDiskCAS::setSizeLimit(std::optional<uint64_t> SizeLimit) {
166 UnifiedDB->setSizeLimit(SizeLimit);
168}
169
170Expected<std::optional<uint64_t>> OnDiskCAS::getStorageSize() const {
171 return UnifiedDB->getStorageSize();
172}
173
174Error OnDiskCAS::pruneStorageData() { return UnifiedDB->collectGarbage(); }
175
176Expected<std::unique_ptr> OnDiskCAS::open(StringRef AbsPath) {
177 Expected<std::unique_ptrondisk::OnDiskGraphDB> DB =
180 if (!DB)
181 return DB.takeError();
182 return std::unique_ptr(new OnDiskCAS(std::move(*DB)));
183}
184
186#if LLVM_ENABLE_ONDISK_CAS
187 return true;
188#else
189 return false;
190#endif
191}
192
194#if LLVM_ENABLE_ONDISK_CAS
195
196
198 Path.toVector(AbsPath);
200
201 return OnDiskCAS::open(AbsPath);
202#else
204#endif
205}
206
207std::unique_ptr
209 std::shared_ptrondisk::UnifiedOnDiskCache UniDB) {
210 return std::make_unique(std::move(UniDB));
211}
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_UNLIKELY(EXPR)
static cl::opt< unsigned > SizeLimit("eif-limit", cl::init(6), cl::Hidden, cl::desc("Size limit in Hexagon early if-conversion"))
This declares OnDiskGraphDB, an ondisk CAS database with a fixed length hash.
size_t size() const
size - Get the array size.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
void reserve(size_type N)
void push_back(const T &Elt)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static HashT hashObject(const ObjectStore &CAS, ArrayRef< ObjectRef > Refs, ArrayRef< char > Data)
static CASID create(const CASContext *Context, StringRef Hash)
Create CASID from CASContext and raw hash bytes.
static StringRef getHashName()
Get the name of the hash for any table identifiers.
Common base class for builtin CAS implementations using the same CASContext.
static ObjectID fromOpaqueData(uint64_t Opaque)
void print(raw_ostream &OS) const
LLVM_ABI_FOR_TEST Expected< std::optional< ObjectHandle > > load(ObjectID Ref)
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.
object_refs_range getObjectRefs(ObjectHandle Node) 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
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 Expected< ObjectID > getReference(ArrayRef< uint8_t > Hash)
Form a reference for the provided hash.
LLVM_ABI_FOR_TEST ArrayRef< char > getObjectData(ObjectHandle Node) const
This class implements an extremely fast bulk output stream that can only output to a stream.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
void validate(const Triple &TT, const FeatureBitset &FeatureBits)
std::unique_ptr< ObjectStore > createObjectStoreFromUnifiedOnDiskCache(std::shared_ptr< ondisk::UnifiedOnDiskCache > UniDB)
Definition OnDiskCAS.cpp:208
decltype(HasherT::hash(std::declval< ArrayRef< uint8_t > & >())) HashType
bool isOnDiskCASEnabled()
Definition OnDiskCAS.cpp:185
LLVM_ABI Expected< std::unique_ptr< ObjectStore > > createOnDiskCAS(const Twine &Path)
Create a persistent on-disk path at Path.
Definition OnDiskCAS.cpp:193
llvm::unique_function< void(llvm::Expected< T >)> Callback
A Callback is a void function that accepts Expected.
NodeAddr< NodeBase * > Node
Context & getContext() const
LLVM_ABI std::error_code make_absolute(SmallVectorImpl< char > &path)
Make path an absolute path.
This is an optimization pass for GlobalISel generic memory operations.
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr, unsigned DynamicVGPRBlockSize=0)
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
@ Ref
The access may reference the value stored in memory.
FunctionAddr VTableAddr uintptr_t uintptr_t Data
ArrayRef(const T &OneElt) -> ArrayRef< T >
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
StringRef toStringRef(bool B)
Construct a string ref from a boolean.