LLVM: lib/CAS/ObjectStore.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
15#include
16
17using namespace llvm;
19
20void CASContext::anchor() {}
21void ObjectStore::anchor() {}
22
27
29 std::string S;
31 return S;
32}
33
35 uint64_t InternalRef, std::optional ID) {
36 OS << Kind << "=" << InternalRef;
37 if (ID)
38 OS << "[" << *ID << "]";
39}
40
45
47 assert(this == &This);
48
49 std::optional ID;
50#if LLVM_ENABLE_ABI_BREAKING_CHECKS
51 if (CAS)
52 ID = CAS->getID(This);
53#endif
55}
56
58 std::optional Handle;
60 return std::move(E);
61 if (!Handle)
64 return *Handle;
65}
66
67std::unique_ptr
69 bool RequiresNullTerminator) {
72 RequiresNullTerminator);
73}
74
82
90
92 std::optional H;
94 return std::move(E);
95
97}
98
101 std::optional H;
103 return std::move(E);
104 if ()
105 return std::nullopt;
107}
108
110 return createStringError(std::make_error_code(std::errc::invalid_argument),
111 "unknown object '" + ID.toString() + "'");
112}
113
117 if ()
118 return Ref.takeError();
120}
121
124 std::optionalsys::fs::file\_status Status) {
125
126
129 if (!Buffer)
131
133}
134
139
140 while (!RefsToValidate.empty()) {
142 auto [I, Inserted] = ValidatedRefs.insert(Ref);
143 if (!Inserted)
144 continue;
146 return E;
148 if (!Obj)
149 return Obj.takeError();
153 }))
154 return E;
155 }
157}
158
161
162
163
164
165
166
167
168
169 if (this == &Upstream)
171
172
173
174 struct UpstreamCursor {
177 size_t RefsCount;
178 std::deque Refs;
179 };
181
182
184
186
189 std::deque Refs;
190 for (unsigned I = 0; I < NumRefs; ++I)
192
193 CursorStack.push_back({Ref, Node, NumRefs, std::move(Refs)});
194 };
195
196 auto UpstreamHandle = Upstream.load(Other);
197 if (!UpstreamHandle)
198 return UpstreamHandle.takeError();
199 enqueueNode(Other, *UpstreamHandle);
200
201 while (!CursorStack.empty()) {
202 UpstreamCursor &Cur = CursorStack.back();
203 if (Cur.Refs.empty()) {
204
205
206
207 assert(PrimaryRefStack.size() >= Cur.RefsCount);
208 auto Refs = ArrayRef(PrimaryRefStack)
209 .slice(PrimaryRefStack.size() - Cur.RefsCount);
210 auto NewNode = store(Refs, Upstream.getData(Cur.Node));
211 if (!NewNode)
212 return NewNode.takeError();
213
214
215 PrimaryRefStack.truncate(PrimaryRefStack.size() - Cur.RefsCount);
216
217
218 PrimaryRefStack.push_back(*NewNode);
219 CreatedObjects.try_emplace(Cur.Ref, *NewNode);
220
221
223 continue;
224 }
225
226
227 auto CurrentID = Cur.Refs.front();
228 Cur.Refs.pop_front();
229 auto Ref = CreatedObjects.find(CurrentID);
230 if (Ref != CreatedObjects.end()) {
231
233 continue;
234 }
235
236
237 auto PrimaryID = Upstream.load(CurrentID);
239 return PrimaryID.takeError();
240
241 enqueueNode(CurrentID, *PrimaryID);
242 }
243
245 return PrimaryRefStack.front();
246}
247
248std::unique_ptr
250 bool RequiresNullTerminator) const {
251 return CAS->getMemoryBuffer(H, Name, RequiresNullTerminator);
252}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
AMDGPU Mark last scratch load
#define LLVM_UNLIKELY(EXPR)
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
This file defines the DenseSet and SmallDenseSet classes.
static void printReferenceBase(raw_ostream &OS, StringRef Kind, uint64_t InternalRef, std::optional< CASID > ID)
Definition ObjectStore.cpp:34
This file contains the declaration of the ObjectStore class.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
iterator find(const_arg_type_t< KeyT > Val)
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&...Args)
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getOpenFile(sys::fs::file_t FD, const Twine &Filename, uint64_t FileSize, bool RequiresNullTerminator=true, bool IsVolatile=false, std::optional< Align > Alignment=std::nullopt)
Given an already-open file descriptor, read the file and return a MemoryBuffer.
static std::unique_ptr< MemoryBuffer > getMemBuffer(StringRef InputData, StringRef BufferName="", bool RequiresNullTerminator=true)
Open the specified memory range as a MemoryBuffer.
Implements a dense probed hash-table based set with some number of buckets stored inline.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void truncate(size_type N)
Like resize, but requires that N is less than size().
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
Unique identifier for a CAS object.
void dump() const
Definition ObjectStore.cpp:23
void print(raw_ostream &OS) const
Print CASID.
LLVM_ABI std::string toString() const
Return a printable string for CASID.
Definition ObjectStore.cpp:28
Handle to a loaded object in a ObjectStore instance.
void print(raw_ostream &OS) const
Print internal ref and/or CASID. Only suitable for debugging.
LLVM_DUMP_METHOD void dump() const
Definition ObjectStore.cpp:26
static ObjectProxy load(ObjectStore &CAS, ObjectRef Ref, ObjectHandle Node)
std::unique_ptr< MemoryBuffer > getMemoryBuffer(StringRef Name="", bool RequiresNullTerminator=true) const
Definition ObjectStore.cpp:249
Reference to an object in an ObjectStore instance.
void print(raw_ostream &OS) const
Print internal ref and/or CASID. Only suitable for debugging.
LLVM_DUMP_METHOD void dump() const
Definition ObjectStore.cpp:25
Expected< ObjectHandle > load(ObjectRef Ref)
Like loadIfExists but returns an error if the object is missing.
Definition ObjectStore.cpp:57
LLVM_ABI_FOR_TEST Expected< ObjectProxy > createProxy(ArrayRef< ObjectRef > Refs, StringRef Data)
Helper functions to store object and returns a ObjectProxy.
Definition ObjectStore.cpp:114
virtual void print(raw_ostream &) const
Print the ObjectStore internals for debugging purpose.
virtual Error validateObject(const CASID &ID)=0
Validate the underlying object referred by CASID.
Expected< ObjectRef > importObject(ObjectStore &Upstream, ObjectRef Other)
Import object from another CAS.
Definition ObjectStore.cpp:159
Expected< std::optional< ObjectProxy > > getProxyIfExists(ObjectRef Ref)
Definition ObjectStore.cpp:100
virtual Expected< ObjectRef > store(ArrayRef< ObjectRef > Refs, ArrayRef< char > Data)=0
Store object into ObjectStore.
virtual ArrayRef< char > getData(ObjectHandle Node, bool RequiresNullTerminator=false) const =0
virtual CASID getID(ObjectRef Ref) const =0
Get an ID for Ref.
static Error createUnknownObjectError(const CASID &ID)
Definition ObjectStore.cpp:109
virtual Expected< std::optional< ObjectHandle > > loadIfExists(ObjectRef Ref)=0
Load the object referenced by Ref.
Error validateTree(ObjectRef Ref)
Validate the whole node tree.
Definition ObjectStore.cpp:135
virtual ObjectRef readRef(ObjectHandle Node, size_t I) const =0
ObjectStore(const CASContext &Context)
virtual Expected< ObjectRef > storeFromOpenFileImpl(sys::fs::file_t FD, std::optional< sys::fs::file_status > Status)
Get ObjectRef from open file.
Definition ObjectStore.cpp:123
virtual void readRefs(ObjectHandle Node, SmallVectorImpl< ObjectRef > &Refs) const
Read all the refs from object in a SmallVector.
Definition ObjectStore.cpp:75
virtual size_t getNumRefs(ObjectHandle Node) const =0
std::unique_ptr< MemoryBuffer > getMemoryBuffer(ObjectHandle Node, StringRef Name="", bool RequiresNullTerminator=true)
Get a lifetime-extended MemoryBuffer pointing at Data.
Definition ObjectStore.cpp:68
virtual std::optional< ObjectRef > getReference(const CASID &ID) const =0
Get an existing reference to the object called ID.
void dump() const
Definition ObjectStore.cpp:24
LLVM_ABI Expected< ObjectProxy > getProxy(const CASID &ID)
Create ObjectProxy from CASID. If the object doesn't exist, get an error.
Definition ObjectStore.cpp:83
virtual Error forEachRef(ObjectHandle Node, function_ref< Error(ObjectRef)> Callback) const =0
Methods for handling objects.
void print(raw_ostream &OS, const ObjectHandle &This) const
Definition ObjectStore.cpp:41
std::pair< iterator, bool > insert(const ValueT &V)
This class implements an extremely fast bulk output stream that can only output to a stream.
A raw_ostream that writes to an std::string.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
This is an optimization pass for GlobalISel generic memory operations.
ArrayRef< CharT > arrayRefFromStringRef(StringRef Input)
Construct a string ref from an array ref of unsigned chars.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
@ Ref
The access may reference the value stored in memory.
FunctionAddr VTableAddr uintptr_t uintptr_t Data
ArrayRef(const T &OneElt) -> ArrayRef< T >
std::string toString(const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)
LLVM_ABI Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
void consumeError(Error Err)
Consume a Error without doing anything.
StringRef toStringRef(bool B)
Construct a string ref from a boolean.