LLVM: lib/CAS/OnDiskDataAllocator.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

15#include "llvm/Config/llvm-config.h"

16

17using namespace llvm;

20

21#if LLVM_ENABLE_ONDISK_CAS

22

23

24

25

26

27namespace {

28

29

30

31

32

33

34

35

36class DataAllocatorHandle {

37public:

39 TableHandle::TableKind::DataAllocator;

40

41 struct Header {

42 TableHandle::Header GenericHeader;

43 std::atomic<int64_t> AllocatorOffset;

44 const uint64_t UserHeaderSize;

45 };

46

47 operator TableHandle() const {

48 if (H)

49 return TableHandle();

50 return TableHandle(*Region, H->GenericHeader);

51 }

52

53 Expected<MutableArrayRef> allocate(MappedFileRegionArena &Alloc,

58 return Ptr.takeError();

60 }

61

62 explicit operator bool() const { return H; }

63 const Header &getHeader() const { return *H; }

65

66 MutableArrayRef<uint8_t> getUserHeader() {

68 H->UserHeaderSize);

69 }

70

71 static Expected

72 create(MappedFileRegionArena &Alloc, StringRef Name, uint32_t UserHeaderSize);

73

74 DataAllocatorHandle() = default;

77 DataAllocatorHandle(MappedFileRegion &Region, intptr_t HeaderOffset)

78 : DataAllocatorHandle(

79 Region, *reinterpret_cast<Header *>(Region.data() + HeaderOffset)) {

80 }

81

82private:

84 Header *H = nullptr;

85};

86

87}

88

90 DatabaseFile File;

91 DataAllocatorHandle Store;

92};

93

97

99 Alloc.allocateOffset(sizeof(Header) + UserHeaderSize + Name.size() + 1);

101 return Offset.takeError();

102

103

104 assert(Name.size() <= UINT16_MAX && "Expected smaller table name");

108 static_cast<int32_t>(sizeof(Header) + UserHeaderSize)},

109 {0},

110 UserHeaderSize};

111

112 char *UserHeader = reinterpret_cast<char *>(H + 1);

113 memset(UserHeader, 0, UserHeaderSize);

114

115 char *NameStorage = UserHeader + UserHeaderSize;

117 NameStorage[Name.size()] = 0;

118 return DataAllocatorHandle(Alloc.getRegion(), *H);

119}

120

122 const Twine &PathTwine, const Twine &TableNameTwine, uint64_t MaxFileSize,

123 std::optional<uint64_t> NewFileInitialSize, uint32_t UserHeaderSize,

125 assert(!UserHeaderSize || UserHeaderInit);

126 SmallString<128> PathStorage;

128 SmallString<128> TableNameStorage;

129 StringRef TableName = TableNameTwine.toStringRef(TableNameStorage);

130

131

132 auto NewDBConstructor = [&](DatabaseFile &DB) -> Error {

134 DataAllocatorHandle::create(DB.getAlloc(), TableName, UserHeaderSize);

136 return Store.takeError();

137

138 if (auto E = DB.addTable(*Store))

139 return E;

140

141 if (UserHeaderSize)

142 UserHeaderInit(Store->getUserHeader().data());

144 };

145

146

147 Expected File =

149 if (!File)

150 return File.takeError();

151

152

153 std::optional Table = File->findTable(TableName);

154 if (!Table)

156 TableName, "table not found");

157 if (Error E = checkTable("table kind", (size_t)DataAllocatorHandle::Kind,

158 (size_t)Table->getHeader().Kind, Path, TableName))

159 return std::move(E);

160 auto Store = Table->cast();

161 assert(Store && "Already checked the kind");

162

163

164 OnDiskDataAllocator::ImplType Impl{DatabaseFile(std::move(*File)), Store};

166}

167

168ExpectedOnDiskDataAllocator::OnDiskPtr

170 auto Data = Impl->Store.allocate(Impl->File.getAlloc(), Size);

172 return Data.takeError();

173

174 return OnDiskPtr(FileOffset(Data->data() - Impl->Store.getRegion().data()),

176}

177

179 size_t Size) const {

182 if (Offset.get() + Size >= Impl->File.getAlloc().size())

184 "requested size too large in allocator");

185 return ArrayRef{Impl->File.getRegion().data() + Offset.get(), Size};

186}

187

189 return Impl->Store.getUserHeader();

190}

191

194 return Impl->File.getRegion().size();

195}

196

198 : Impl(std::move(Impl)) {}

199

200#else

201

203

206 std::optional<uint64_t> NewFileInitialSize, uint32_t UserHeaderSize,

209 "OnDiskDataAllocator is not supported");

210}

211

215 "OnDiskDataAllocator is not supported");

216}

217

219 size_t Size) const {

221 "OnDiskDataAllocator is not supported");

222}

223

227

230

231#endif

232

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

AMDGPU Prepare AGPR Alloc

static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")

#define LLVM_UNLIKELY(EXPR)

This file declares the common interface for a DatabaseFile that is used to implement OnDiskCAS.

This file declares interface for OnDiskDataAllocator, a file backed data pool can be used to allocate...

static ErrorSuccess success()

Create a success value.

Tagged union holding either a T or a Error.

MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...

StringRef - Represent a constant reference to a string, i.e.

Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...

StringRef toStringRef(SmallVectorImpl< char > &Out) const

This returns the twine as a single StringRef if it can be represented as such.

FileOffset is a wrapper around uint64_t to represent the offset of data from the beginning of the fil...

Allocator for an owned mapped file region that supports thread-safe and process-safe bump pointer all...

A pointer to data stored on disk.

LLVM_ABI_FOR_TEST ~OnDiskDataAllocator()

MutableArrayRef< uint8_t > getUserHeader() const

Definition OnDiskDataAllocator.cpp:224

LLVM_ABI_FOR_TEST Expected< OnDiskPtr > allocate(size_t Size)

Allocate at least Size with 8-byte alignment.

Definition OnDiskDataAllocator.cpp:213

LLVM_ABI_FOR_TEST Expected< ArrayRef< char > > get(FileOffset Offset, size_t Size) const

Get the data of Size stored at the given Offset.

Definition OnDiskDataAllocator.cpp:218

static LLVM_ABI_FOR_TEST Expected< OnDiskDataAllocator > create(const Twine &Path, const Twine &TableName, uint64_t MaxFileSize, std::optional< uint64_t > NewFileInitialSize, uint32_t UserHeaderSize=0, function_ref< void(void *)> UserHeaderInit=nullptr)

Definition OnDiskDataAllocator.cpp:204

LLVM_ABI_FOR_TEST size_t size() const

Definition OnDiskDataAllocator.cpp:228

LLVM_ABI_FOR_TEST OnDiskDataAllocator & operator=(OnDiskDataAllocator &&RHS)

LLVM_ABI_FOR_TEST OnDiskDataAllocator(OnDiskDataAllocator &&RHS)

LLVM_ABI_FOR_TEST size_t capacity() const

Definition OnDiskDataAllocator.cpp:229

static Expected< DatabaseFile > create(const Twine &Path, uint64_t Capacity, function_ref< Error(DatabaseFile &)> NewDBConstructor)

Create the DatabaseFile at Path with Capacity.

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

Error createTableConfigError(std::errc ErrC, StringRef Path, StringRef TableName, const Twine &Msg)

MappedFileRegionArena::RegionT MappedFileRegion

Error checkTable(StringRef Label, size_t Expected, size_t Observed, StringRef Path, StringRef TrieName)

This is an optimization pass for GlobalISel generic memory operations.

std::error_code make_error_code(BitcodeError E)

FunctionAddr VTableAddr uintptr_t uintptr_t DataSize

Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)

Create formatted StringError object.

MutableArrayRef(T &OneElt) -> MutableArrayRef< T >

FunctionAddr VTableAddr uintptr_t uintptr_t Data

OutputIt copy(R &&Range, OutputIt Out)

OutputIt move(R &&Range, OutputIt Out)

Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.