31 Expected<ObjectRef> storeImpl(ArrayRef<uint8_t> ComputedHash,
33 ArrayRef<char>
Data)
final;
35 Expected<std::optional<ObjectHandle>> loadIfExists(ObjectRef
Ref)
final;
37 CASID getID(ObjectRef
Ref)
const final;
39 std::optional<ObjectRef> getReference(
const CASID &ID)
const final;
41 Expected<bool> isMaterialized(ObjectRef
Ref)
const final;
43 ArrayRef<char> getDataConst(ObjectHandle Node)
const final;
45 Expected<ObjectRef> storeFromFile(StringRef Path)
final;
47 Error exportDataToFile(ObjectHandle Node, StringRef Path)
const final;
49 std::unique_ptr<MemoryBuffer>
50 getStandaloneMemoryBufferImpl(ObjectHandle Node, StringRef Name,
51 bool RequiresNullTerminator)
final;
53 void print(raw_ostream &OS)
const final;
56 static Expected<std::unique_ptr<OnDiskCAS>> open(StringRef Path);
58 OnDiskCAS(std::shared_ptr<ondisk::UnifiedOnDiskCache> UniDB)
59 : UnifiedDB(std::
move(UniDB)), DB(&UnifiedDB->getGraphDB()) {}
62 ObjectHandle convertHandle(ondisk::ObjectHandle Node)
const {
63 return makeObjectHandle(
Node.getOpaqueData());
66 ondisk::ObjectHandle convertHandle(ObjectHandle Node)
const {
67 return ondisk::ObjectHandle(
Node.getInternalRef(*
this));
70 ObjectRef convertRef(ondisk::ObjectID
Ref)
const {
71 return makeObjectRef(
Ref.getOpaqueData());
74 ondisk::ObjectID convertRef(ObjectRef
Ref)
const {
78 size_t getNumRefs(ObjectHandle Node)
const final {
79 auto RefsRange = DB->getObjectRefs(convertHandle(Node));
83 ObjectRef readRef(ObjectHandle Node,
size_t I)
const final {
84 auto RefsRange = DB->getObjectRefs(convertHandle(Node));
85 return convertRef(RefsRange.begin()[
I]);
88 Error forEachRef(ObjectHandle Node,
89 function_ref<
Error(ObjectRef)> Callback)
const final;
92 Expected<std::optional<uint64_t>> getStorageSize()
const final;
93 Error pruneStorageData() final;
95 OnDiskCAS(std::unique_ptr<ondisk::OnDiskGraphDB> GraphDB)
96 : OwnedDB(std::
move(GraphDB)), DB(OwnedDB.
get()) {}
98 std::unique_ptr<ondisk::OnDiskGraphDB> OwnedDB;
99 std::shared_ptr<ondisk::UnifiedOnDiskCache> UnifiedDB;
100 ondisk::OnDiskGraphDB *DB;
106Error OnDiskCAS::validate(
bool CheckHash)
const {
113CASID OnDiskCAS::getID(ObjectRef
Ref)
const {
114 ArrayRef<uint8_t> Hash = DB->
getDigest(convertRef(
Ref));
118std::optional<ObjectRef> OnDiskCAS::getReference(
const CASID &ID)
const {
119 std::optional<ondisk::ObjectID> ObjID =
123 return convertRef(*ObjID);
126Expected<bool> OnDiskCAS::isMaterialized(ObjectRef ExternalRef)
const {
130ArrayRef<char> OnDiskCAS::getDataConst(ObjectHandle Node)
const {
134Expected<std::optional<ObjectHandle>>
135OnDiskCAS::loadIfExists(ObjectRef ExternalRef) {
136 Expected<std::optional<ondisk::ObjectHandle>> ObjHnd =
137 DB->
load(convertRef(ExternalRef));
142 return convertHandle(**ObjHnd);
145Expected<ObjectRef> OnDiskCAS::storeImpl(ArrayRef<uint8_t> ComputedHash,
147 ArrayRef<char>
Data) {
150 for (ObjectRef
Ref : Refs) {
156 return StoredID.takeError();
159 return convertRef(*StoredID);
162Expected<ObjectRef> OnDiskCAS::storeFromFile(StringRef Path) {
165 return Hash.takeError();
168 return StoredID.takeError();
171 return convertRef(*StoredID);
174std::unique_ptr<MemoryBuffer>
175OnDiskCAS::getStandaloneMemoryBufferImpl(ObjectHandle Node, StringRef Name,
176 bool RequiresNullTerminator) {
178 RequiresNullTerminator);
181Error OnDiskCAS::exportDataToFile(ObjectHandle Node, StringRef Path)
const {
183 if (!FBData.FileInfo.has_value())
184 return BuiltinCAS::exportDataToFile(Node, Path);
187 assert(FBData.FileInfo.has_value());
191 ondisk::UniqueTempFile UniqueTmp;
193 FBData.FileInfo->FilePath);
195 return ExpectedPath.takeError();
196 StringRef TmpPath = *ExpectedPath;
198 if (FBData.FileInfo->IsFileNulTerminated) {
201 if (std::error_code EC =
218Error OnDiskCAS::forEachRef(ObjectHandle Node,
219 function_ref<
Error(ObjectRef)> Callback)
const {
221 for (ondisk::ObjectID
Ref : RefsRange) {
233Expected<std::optional<uint64_t>> OnDiskCAS::getStorageSize()
const {
234 return UnifiedDB->getStorageSize();
237Error OnDiskCAS::pruneStorageData() {
return UnifiedDB->collectGarbage(); }
239Expected<std::unique_ptr<OnDiskCAS>> OnDiskCAS::open(StringRef AbsPath) {
240 std::shared_ptr<ondisk::OnDiskCASLogger> Logger;
247 Expected<std::unique_ptr<ondisk::OnDiskGraphDB>> DB =
252 return DB.takeError();
253 return std::unique_ptr<OnDiskCAS>(
new OnDiskCAS(std::move(*DB)));
257#if LLVM_ENABLE_ONDISK_CAS
265#if LLVM_ENABLE_ONDISK_CAS
269 Path.toVector(AbsPath);
272 return OnDiskCAS::open(AbsPath);
278std::unique_ptr<ObjectStore>
280 std::shared_ptr<ondisk::UnifiedOnDiskCache> UniDB) {
281 return std::make_unique<OnDiskCAS>(std::move(UniDB));
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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 file declares interface for OnDiskCASLogger, an interface that can be used to log CAS events to ...
This declares OnDiskGraphDB, an ondisk CAS database with a fixed length hash.
Func getContext().diagnose(DiagnosticInfoUnsupported(Func
This file defines the scope_exit class, which executes user-defined cleanup logic at scope exit.
size_t size() const
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 Expected< HashT > hashFile(StringRef FilePath)
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)
static LLVM_ABI Expected< std::unique_ptr< OnDiskCASLogger > > openIfEnabled(const Twine &Path)
Create or append to a log file inside the given CAS directory Path if logging is enabled by the envir...
LLVM_ABI void print(raw_ostream &OS) const
LLVM_ABI Expected< std::optional< ObjectHandle > > load(ObjectID Ref)
LLVM_ABI std::unique_ptr< MemoryBuffer > getStandaloneMemoryBuffer(ObjectHandle Node, StringRef Name, bool RequiresNullTerminator) const
Get a MemoryBuffer for Node's data that stays valid after this database is destroyed.
LLVM_ABI Expected< bool > isMaterialized(ObjectID Ref)
Check whether the object associated with Ref is stored in the CAS.
LLVM_ABI Error validate(bool Deep, HashingFuncT Hasher) const
Validate the OnDiskGraphDB.
object_refs_range getObjectRefs(ObjectHandle Node) const
LLVM_ABI 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
LLVM_ABI FileBackedData getInternalFileBackedObjectData(ObjectHandle Node) const
Provides access to the underlying file path, that represents an object leaf node, when available.
LLVM_ABI Error storeFile(ObjectID ID, StringRef FilePath)
Associates the data of a file with a particular object ID.
static LLVM_ABI Expected< std::unique_ptr< OnDiskGraphDB > > open(StringRef Path, StringRef HashName, unsigned HashByteSize, OnDiskGraphDB *UpstreamDB=nullptr, std::shared_ptr< OnDiskCASLogger > Logger=nullptr, FaultInPolicy Policy=FaultInPolicy::FullTree)
Open the on-disk store from a directory.
LLVM_ABI Expected< ObjectID > getReference(ArrayRef< uint8_t > Hash)
Form a reference for the provided hash.
LLVM_ABI ArrayRef< char > getObjectData(ObjectHandle Node) const
LLVM_ABI std::optional< ObjectID > getExistingReference(ArrayRef< uint8_t > Digest, bool CheckUpstream=true)
Get an existing reference to the object Digest.
Error renameTo(StringRef RenameToPath)
Rename the new unique file to RenameToPath.
Expected< StringRef > createAndCopyFrom(StringRef ParentPath, StringRef CopyFromPath)
Create a new unique file path under ParentPath and copy the contents of CopyFromPath into it.
This class implements an extremely fast bulk output stream that can only output to a stream.
void validate(const Triple &TT, const FeatureBitset &FeatureBits)
std::unique_ptr< ObjectStore > createObjectStoreFromUnifiedOnDiskCache(std::shared_ptr< ondisk::UnifiedOnDiskCache > UniDB)
void hashingFunc(ArrayRef< ArrayRef< uint8_t > > Refs, ArrayRef< char > Data, SmallVectorImpl< uint8_t > &Result)
Convenience wrapper for BuiltinObjectHasher.
decltype(HasherT::hash(std::declval< ArrayRef< uint8_t > & >())) HashType
LLVM_ABI bool isOnDiskCASEnabled()
LLVM_ABI Expected< std::unique_ptr< ObjectStore > > createOnDiskCAS(const Twine &Path)
Create a persistent on-disk path at Path.
llvm::unique_function< void(llvm::Expected< T >)> Callback
A Callback<T> is a void function that accepts Expected<T>.
NodeAddr< NodeBase * > Node
LLVM_ABI std::error_code closeFile(file_t &F)
Close the file object.
@ CD_OpenExisting
CD_OpenExisting - When opening a file:
std::error_code openFileForWrite(const Twine &Name, int &ResultFD, CreationDisposition Disp=CD_CreateAlways, OpenFlags Flags=OF_None, unsigned Mode=0666)
Opens the file with the given name in a write-only or read-write mode, returning its open file descri...
LLVM_ABI std::error_code make_absolute(SmallVectorImpl< char > &path)
Make path an absolute path.
LLVM_ABI std::error_code resize_file(int FD, uint64_t Size)
Resize path to size.
LLVM_ABI file_t convertFDToNativeFile(int FD)
Converts from a Posix file descriptor number to a native file handle.
LLVM_ABI StringRef parent_path(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get parent path.
ScopedSetting scopedDisable()
This is an optimization pass for GlobalISel generic memory operations.
Error createFileError(const Twine &F, Error E)
Concatenate a source file path and/or name with an Error.
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.
scope_exit(Callable) -> scope_exit< Callable >
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.
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.