LLVM: lib/CGData/CodeGenDataReader.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

18

19#define DEBUG_TYPE "cg-data-reader"

20

21using namespace llvm;

22

24 "indexed-codegen-data-read-function-map-names", cl::init(true), cl::Hidden,

25 cl::desc("Read function map names in indexed CodeGenData. Can be "

26 "disabled to save memory and time for final consumption of the "

27 "indexed CodeGenData in production."));

28

29namespace llvm {

30

34 "Lazily load indexed CodeGenData. Enable to save memory and time "

35 "for final consumption of the indexed CodeGenData in production."));

36

40 : FS.getBufferForFile(Filename);

41 if (std::error_code EC = BufferOrErr.getError())

43 return std::move(BufferOrErr.get());

44}

45

50 Triple TT = Obj->makeTriple();

51 auto CGOutlineName =

53 auto CGMergeName =

55

56 auto processSectionContents = [&](const StringRef &Name,

58 if (Name != CGOutlineName && Name != CGMergeName)

59 return;

60 if (CombinedHash)

62 auto *Data = reinterpret_cast<const unsigned char *>(Contents.data());

63 auto *EndData = Data + Contents.size();

64

65

66

67

68 if (Name == CGOutlineName) {

69 while (Data != EndData) {

72 GlobalOutlineRecord.merge(LocalOutlineRecord);

73 }

74 } else if (Name == CGMergeName) {

75 while (Data != EndData) {

78 GlobalFunctionMapRecord.merge(LocalFunctionMapRecord);

79 }

80 }

81 };

82

83 for (auto &Section : Obj->sections()) {

85 if (!NameOrErr)

88 if (!ContentsOrErr)

90 processSectionContents(*NameOrErr, *ContentsOrErr);

91 }

92

94}

95

98

99

100

101 const unsigned MinHeaderSize = 24;

102 if (DataBuffer->getBufferSize() < MinHeaderSize)

104

105 auto *Start =

106 reinterpret_cast<const unsigned char *>(DataBuffer->getBufferStart());

107 auto *End =

108 reinterpret_cast<const unsigned char *>(DataBuffer->getBufferEnd());

110 return E;

111

113 const unsigned char *Ptr = Start + Header.OutlinedHashTreeOffset;

114 if (Ptr >= End)

117 }

118

119

120 std::shared_ptr SharedDataBuffer = std::move(DataBuffer);

122 const unsigned char *Ptr = Start + Header.StableFunctionMapOffset;

123 if (Ptr >= End)

129 Header.StableFunctionMapOffset);

130 else

132 }

133

135}

136

139

141 if (Error E = BufferOrError.takeError())

142 return std::move(E);

144}

145

148 if (Buffer->getBufferSize() == 0)

150

151 std::unique_ptr Reader;

152

154 Reader = std::make_unique(std::move(Buffer));

156 Reader = std::make_unique(std::move(Buffer));

157 else

159

160

161 if (Error E = Reader->read())

162 return std::move(E);

163

164 return std::move(Reader);

165}

166

170 return false;

171

174

176}

177

186

187

188 for (; !Line.is_at_eof(); ++Line) {

189

190 if (Line->trim().empty())

191 continue;

192

193 if (!Line->starts_with(":"))

194 break;

196 if (Str.equals_insensitive("outlined_hash_tree"))

198 else if (Str.equals_insensitive("stable_function_map"))

200 else

202 }

203

204

205 if (Line.is_at_eof()) {

209 }

210

211

212 const char *Pos = Line->data();

213 size_t Size = reinterpret_cast<size_t>(DataBuffer->getBufferEnd()) -

214 reinterpret_cast<size_t>(Pos);

220

222}

223}

static cl::opt< bool > IndexedCodeGenDataReadFunctionMapNames("indexed-codegen-data-read-function-map-names", cl::init(true), cl::Hidden, cl::desc("Read function map names in indexed CodeGenData. Can be " "disabled to save memory and time for final consumption of the " "indexed CodeGenData in production."))

Error success()

Clear the current error and return a successful one.

OutlinedHashTreeRecord HashTreeRecord

The outlined hash tree that has been read.

static LLVM_ABI Expected< std::unique_ptr< CodeGenDataReader > > create(const Twine &Path, vfs::FileSystem &FS)

Factory method to create an appropriately typed reader for the given codegen data file path and file ...

Definition CodeGenDataReader.cpp:138

StableFunctionMapRecord FunctionMapRecord

The stable function map that has been read. When it's released by.

static LLVM_ABI Error mergeFromObjectFile(const object::ObjectFile *Obj, OutlinedHashTreeRecord &GlobalOutlineRecord, StableFunctionMapRecord &GlobalFunctionMapRecord, stable_hash *CombinedHash=nullptr)

Extract the cgdata embedded in sections from the given object file and merge them into the GlobalOutl...

Definition CodeGenDataReader.cpp:46

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.

Error takeError()

Take ownership of the stored error.

static bool hasFormat(const MemoryBuffer &Buffer)

Return true if the given buffer is in binary codegen data format.

Definition CodeGenDataReader.cpp:167

Error read() override

Read the contents including the header.

Definition CodeGenDataReader.cpp:96

bool hasStableFunctionMap() const override

Return true if the header indicates the data has a stable function map.

bool hasOutlinedHashTree() const override

Return true if the header indicates the data has an outlined hash tree.

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

StringRef getBuffer() const

static ErrorOr< std::unique_ptr< MemoryBuffer > > getSTDIN()

Read all of stdin into a file buffer, and return it.

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

StringRef drop_front(size_t N=1) const

Return a StringRef equal to 'this' but with the first N elements dropped.

StringRef rtrim(char Char) const

Return string with consecutive Char characters starting from the right removed.

StringRef take_front(size_t N=1) const

Return a StringRef equal to 'this' but with only the first N elements remaining.

static bool hasFormat(const MemoryBuffer &Buffer)

Return true if the given buffer is in text codegen data format.

Definition CodeGenDataReader.cpp:178

bool hasStableFunctionMap() const override

Return true if the header indicates the data has a stable function map.

bool hasOutlinedHashTree() const override

Return true if the header indicates the data has an outlined hash tree.

Error read() override

Read the contents including the header.

Definition CodeGenDataReader.cpp:184

Triple - Helper class for working with autoconf configuration names.

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

This class is the base class for all object file types.

The virtual file system interface.

The Input class is used to parse a yaml document into in-memory structs and vectors.

initializer< Ty > init(const Ty &Val)

value_type read(const void *memory, endianness endian)

Read a value of a particular endianness from memory.

This is an optimization pass for GlobalISel generic memory operations.

@ StableFunctionMergingMap

@ FunctionOutlinedHashTree

static Expected< std::unique_ptr< MemoryBuffer > > setupMemoryBuffer(const Twine &Filename, vfs::FileSystem &FS)

Definition CodeGenDataReader.cpp:38

bool all_of(R &&range, UnaryPredicate P)

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

LLVM_ABI uint64_t xxh3_64bits(ArrayRef< uint8_t > data)

cl::opt< bool > IndexedCodeGenDataLazyLoading("indexed-codegen-data-lazy-loading", cl::init(false), cl::Hidden, cl::desc("Lazily load indexed CodeGenData. Enable to save memory and time " "for final consumption of the indexed CodeGenData in production."))

uint64_t stable_hash

An opaque object representing a stable hash code.

Error make_error(ArgTs &&... Args)

Make a Error instance representing failure using the given error info type.

FunctionAddr VTableAddr uintptr_t uintptr_t Data

bool isPrint(char C)

Checks whether character C is printable.

bool isSpace(char C)

Checks whether character C is whitespace in the "C" locale.

LLVM_ABI Error errorCodeToError(std::error_code EC)

Helper for converting an std::error_code to a Error.

stable_hash stable_hash_combine(ArrayRef< stable_hash > Buffer)

LLVM_ABI std::string getCodeGenDataSectionName(CGDataSectKind CGSK, Triple::ObjectFormatType OF, bool AddSegmentInfo=true)

LLVM_ABI void deserialize(const unsigned char *&Ptr)

Deserialize the outlined hash tree from a raw_ostream.

void merge(const OutlinedHashTreeRecord &Other)

Merge the other outlined hash tree into this one.

The structure of the serialized stable function map is as follows:

void merge(const StableFunctionMapRecord &Other)

Merge the stable function map into this one.

LLVM_ABI void deserialize(const unsigned char *&Ptr)

Deserialize the stable function map from a raw_ostream.