LLVM: include/llvm/CAS/ObjectStore.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14#ifndef LLVM_CAS_OBJECTSTORE_H

15#define LLVM_CAS_OBJECTSTORE_H

16

22#include

23

24namespace llvm {

25

28

29namespace cas {

30

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

92 void anchor();

93

94public:

95

96

97

98

99

100

102

103

106

108

109

110

111

113

114

115

117

118

120

121

123

124protected:

125

126

127

128

130

131

133

134

136

137

138

144 bool RequiresNullTerminator = false) const = 0;

145

146

149 std::optionalsys::fs::file\_status Status);

150

151

152

153

154

158

159

160

161

162

163 std::unique_ptr

165 bool RequiresNullTerminator = true);

166

167

170

171

172#define MAKE_CAS_HANDLE_CONSTRUCTOR(HandleKind) \

173 HandleKind make##HandleKind(uint64_t InternalRef) const { \

174 return HandleKind(*this, InternalRef); \

175 }

178#undef MAKE_CAS_HANDLE_CONSTRUCTOR

179

180public:

181

183 StringRef Data);

184

185

190

191

192

193

194

195

196

197

198

199

202 std::optionalsys::fs::file\_status Status = std::nullopt) {

204 }

205

207

208

210

211

213

214

216

217

219 uint64_t MaxBytes = -1ULL) const {

224 return Data.size();

225 }

226

227

228

229

230

234

235

236

237

238

240 return std::nullopt;

241 }

242

243

244

245

246

248

249

251

252

253

255

256

258 void dump() const;

259

260

262

264

265protected:

267

268private:

270};

271

272

273

274

276public:

282

286 assert(ID && "Expected reference to be first-class object");

287 return *ID;

288 }

289

290

291

293 return CAS->forEachRef(H, Callback);

294 }

295

296 std::unique_ptr

298 bool RequiresNullTerminator = true) const;

299

300

302

304 return Proxy.getRef() == Ref;

305 }

307 return Proxy.getRef() == Ref;

308 }

310 return !(Proxy.getRef() == Ref);

311 }

313 return !(Proxy.getRef() == Ref);

314 }

315

316public:

318

322

323private:

325 : CAS(&CAS), Ref(Ref), H(H) {}

326

327 ObjectStore *CAS;

328 ObjectRef Ref;

329 ObjectHandle H;

330};

331

332

334

335

337

338

339LLVM_ABI Expected<std::unique_ptr>

341

342}

343}

344

345#endif

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

AMDGPU Mark last scratch load

#define LLVM_ABI_FOR_TEST

static cl::opt< unsigned > SizeLimit("eif-limit", cl::init(6), cl::Hidden, cl::desc("Size limit in Hexagon early if-conversion"))

#define MAKE_CAS_HANDLE_CONSTRUCTOR(HandleKind)

Allow ObjectStore implementations to create internal handles.

Definition ObjectStore.h:172

ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...

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.

This interface provides simple read-only access to a block of memory, and provides simple methods for...

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.

Context for CAS identifiers.

Unique identifier for a CAS object.

Handle to a loaded object in a ObjectStore instance.

Reference to an abstract hierarchical node, with data and references.

Definition ObjectStore.h:275

static ObjectProxy load(ObjectStore &CAS, ObjectRef Ref, ObjectHandle Node)

Definition ObjectStore.h:319

friend bool operator==(ObjectRef Ref, const ObjectProxy &Proxy)

Definition ObjectStore.h:306

std::unique_ptr< MemoryBuffer > getMemoryBuffer(StringRef Name="", bool RequiresNullTerminator=true) const

size_t getNumReferences() const

Definition ObjectStore.h:280

friend bool operator!=(const ObjectProxy &Proxy, ObjectRef Ref)

Definition ObjectStore.h:309

CASID getID() const

Definition ObjectStore.h:278

friend bool operator==(const ObjectProxy &Proxy, ObjectRef Ref)

Definition ObjectStore.h:303

Error forEachReference(function_ref< Error(ObjectRef)> Callback) const

Visit each reference in order, returning an error from Callback to stop early.

Definition ObjectStore.h:292

StringRef getData() const

Get the content of the node. Valid as long as the CAS is valid.

Definition ObjectStore.h:301

friend bool operator!=(ObjectRef Ref, const ObjectProxy &Proxy)

Definition ObjectStore.h:312

CASID getReferenceID(size_t I) const

Definition ObjectStore.h:284

ObjectStore & getCAS() const

Definition ObjectStore.h:277

ObjectRef getRef() const

Definition ObjectStore.h:279

ObjectRef getReference(size_t I) const

Definition ObjectStore.h:281

Reference to an object in an ObjectStore instance.

Content-addressable storage for objects.

Definition ObjectStore.h:90

LLVM_ABI_FOR_TEST Expected< ObjectProxy > createProxy(ArrayRef< ObjectRef > Refs, StringRef Data)

Helper functions to store object and returns a ObjectProxy.

virtual void print(raw_ostream &) const

Print the ObjectStore internals for debugging purpose.

Definition ObjectStore.h:257

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.

virtual Expected< std::optional< uint64_t > > getStorageSize() const

Definition ObjectStore.h:239

Expected< ObjectRef > storeFromOpenFile(sys::fs::file_t FD, std::optional< sys::fs::file_status > Status=std::nullopt)

Default implementation reads FD and calls storeNode().

Definition ObjectStore.h:201

Expected< std::optional< ObjectProxy > > getProxyIfExists(ObjectRef Ref)

virtual Expected< bool > isMaterialized(ObjectRef Ref) const =0

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)

virtual Expected< std::optional< ObjectHandle > > loadIfExists(ObjectRef Ref)=0

Load the object referenced by Ref.

const CASContext & getContext() const

Get CASContext.

Definition ObjectStore.h:261

virtual Error setSizeLimit(std::optional< uint64_t > SizeLimit)

Set the size for limiting growth of on-disk storage.

Definition ObjectStore.h:231

virtual ~ObjectStore()=default

Error validateTree(ObjectRef Ref)

Validate the whole node tree.

Expected< ObjectRef > storeFromString(ArrayRef< ObjectRef > Refs, StringRef String)

Store object from StringRef.

Definition ObjectStore.h:186

virtual Error pruneStorageData()

Prune local storage to reduce its size according to the desired size limit.

Definition ObjectStore.h:247

uint64_t readData(ObjectHandle Node, raw_ostream &OS, uint64_t Offset=0, uint64_t MaxBytes=-1ULL) const

Read the data from Data into OS.

Definition ObjectStore.h:218

virtual ObjectRef readRef(ObjectHandle Node, size_t I) const =0

ObjectStore(const CASContext &Context)

Definition ObjectStore.h:266

virtual Expected< CASID > parseID(StringRef ID)=0

Get a CASID from a ID, which should have been generated by CASID::print().

virtual uint64_t getDataSize(ObjectHandle Node) const =0

Get the size of some data.

virtual Expected< ObjectRef > storeFromOpenFileImpl(sys::fs::file_t FD, std::optional< sys::fs::file_status > Status)

Get ObjectRef from open file.

StringRef getDataString(ObjectHandle Node)

Get a lifetime-extended StringRef pointing at Data.

Definition ObjectStore.h:155

virtual Error validate(bool CheckHash) const =0

Validate the entire ObjectStore.

virtual void readRefs(ObjectHandle Node, SmallVectorImpl< ObjectRef > &Refs) const

Read all the refs from object in a SmallVector.

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.

virtual std::optional< ObjectRef > getReference(const CASID &ID) const =0

Get an existing reference to the object called ID.

LLVM_ABI Expected< ObjectProxy > getProxy(const CASID &ID)

Create ObjectProxy from CASID. If the object doesn't exist, get an error.

friend class ObjectProxy

Definition ObjectStore.h:91

virtual Error forEachRef(ObjectHandle Node, function_ref< Error(ObjectRef)> Callback) const =0

Methods for handling objects.

An efficient, type-erasing, non-owning reference to a callable.

This class implements an extremely fast bulk output stream that can only output to a stream.

unique_function is a type-erasing functor similar to std::function.

unsigned ID

LLVM IR allows to use arbitrary numbers as calling convention identifiers.

bool isOnDiskCASEnabled()

LLVM_ABI std::unique_ptr< ObjectStore > createInMemoryCAS()

Create an in memory CAS.

LLVM_ABI Expected< std::unique_ptr< ObjectStore > > createOnDiskCAS(const Twine &Path)

Create a persistent on-disk path at Path.

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.

@ Ref

The access may reference the value stored in memory.

FunctionAddr VTableAddr uintptr_t uintptr_t Data

ArrayRef(const T &OneElt) -> ArrayRef< T >

StringRef toStringRef(bool B)

Construct a string ref from a boolean.