Skip to content

Commit 6e528b7

Browse files
committed
Address comments from Ellis #2
1 parent 93de548 commit 6e528b7

File tree

3 files changed

+25
-26
lines changed

3 files changed

+25
-26
lines changed

llvm/include/llvm/CodeGenData/CodeGenData.inc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
*
1313
\*===----------------------------------------------------------------------===*/
1414

15+
/* Helper macros. */
16+
#define CG_DATA_SIMPLE_QUOTE(x) #x
17+
#define CG_DATA_QUOTE(x) CG_DATA_SIMPLE_QUOTE(x)
18+
1519
#ifdef CG_DATA_SECT_ENTRY
1620
#define CG_DATA_DEFINED
1721
CG_DATA_SECT_ENTRY(CG_outline, CG_DATA_QUOTE(CG_DATA_OUTLINE_COMMON),
@@ -34,13 +38,9 @@ CG_DATA_SECT_ENTRY(CG_outline, CG_DATA_QUOTE(CG_DATA_OUTLINE_COMMON),
3438

3539
#else
3640
/* Runtime section names and name strings. */
37-
#define CG_DATA_SECT_NAME INSTR_PROF_QUOTE(CG_DATA_OUTLINE_COMMON)
41+
#define CG_DATA_SECT_NAME CG_DATA_QUOTE(CG_DATA_OUTLINE_COMMON)
3842

3943
#endif
4044

4145
/* Indexed codegen data format version (start from 1). */
4246
#define CG_DATA_INDEX_VERSION 1
43-
44-
/* Helper macros. */
45-
#define CG_DATA_SIMPLE_QUOTE(x) #x
46-
#define CG_DATA_QUOTE(x) CG_DATA_SIMPLE_QUOTE(x)

llvm/lib/CodeGenData/CodeGenData.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@ std::once_flag CodeGenData::OnceFlag;
130130

131131
CodeGenData &CodeGenData::getInstance() {
132132
std::call_once(CodeGenData::OnceFlag, []() {
133-
auto *CGD = new CodeGenData();
134-
Instance.reset(CGD);
133+
Instance = std::unique_ptr<CodeGenData>(new CodeGenData());
135134

136135
// TODO: Initialize writer or reader mode for the client optimization.
137136
});
@@ -187,7 +186,7 @@ void warn(Twine Message, std::string Whence, std::string Hint) {
187186
void warn(Error E, StringRef Whence) {
188187
if (E.isA<CGDataError>()) {
189188
handleAllErrors(std::move(E), [&](const CGDataError &IPE) {
190-
warn(IPE.message(), std::string(Whence), std::string(""));
189+
warn(IPE.message(), Whence.str(), "");
191190
});
192191
}
193192
}

llvm/lib/CodeGenData/CodeGenDataReader.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Error CodeGenDataReader::mergeFromObjectFile(
4747
auto *EndData = Data + ContentsOrErr->size();
4848

4949
if (*NameOrErr == CGOutLineName) {
50-
// In case dealing with an executable that has concatenaed cgdata,
50+
// In case dealing with an executable that has concatenated cgdata,
5151
// we want to merge them into a single cgdata.
5252
// Although it's not a typical workflow, we support this scenario.
5353
while (Data != EndData) {
@@ -74,10 +74,8 @@ Error IndexedCodeGenDataReader::read() {
7474
reinterpret_cast<const unsigned char *>(DataBuffer->getBufferStart());
7575
auto *End =
7676
reinterpret_cast<const unsigned char *>(DataBuffer->getBufferEnd());
77-
auto HeaderOr = IndexedCGData::Header::readFromBuffer(Start);
78-
if (!HeaderOr)
79-
return HeaderOr.takeError();
80-
Header = HeaderOr.get();
77+
if (auto E = IndexedCGData::Header::readFromBuffer(Start).moveInto(Header))
78+
return std::move(E);
8179

8280
if (hasOutlinedHashTree()) {
8381
const unsigned char *Ptr = Start + Header.OutlinedHashTreeOffset;
@@ -106,9 +104,9 @@ CodeGenDataReader::create(std::unique_ptr<MemoryBuffer> Buffer) {
106104
std::unique_ptr<CodeGenDataReader> Reader;
107105
// Create the reader.
108106
if (IndexedCodeGenDataReader::hasFormat(*Buffer))
109-
Reader.reset(new IndexedCodeGenDataReader(std::move(Buffer)));
107+
Reader = std::make_unique<IndexedCodeGenDataReader>(std::move(Buffer));
110108
else if (TextCodeGenDataReader::hasFormat(*Buffer))
111-
Reader.reset(new TextCodeGenDataReader(std::move(Buffer)));
109+
Reader = std::make_unique<TextCodeGenDataReader>(std::move(Buffer));
112110
else
113111
return make_error<CGDataError>(cgdata_error::malformed);
114112

@@ -132,31 +130,33 @@ bool IndexedCodeGenDataReader::hasFormat(const MemoryBuffer &DataBuffer) {
132130

133131
bool TextCodeGenDataReader::hasFormat(const MemoryBuffer &Buffer) {
134132
// Verify that this really looks like plain ASCII text by checking a
135-
// 'reasonable' number of characters (up to profile magic size).
136-
size_t count = std::min(Buffer.getBufferSize(), sizeof(uint64_t));
137-
StringRef buffer = Buffer.getBufferStart();
138-
return count == 0 ||
139-
std::all_of(buffer.begin(), buffer.begin() + count,
140-
[](char c) { return isPrint(c) || isSpace(c); });
133+
// 'reasonable' number of characters (up to the magic size).
134+
StringRef Prefix = Buffer.getBuffer().take_front(sizeof(uint64_t));
135+
return llvm::all_of(Prefix, [](char c) { return isPrint(c) || isSpace(c); });
141136
}
142137
Error TextCodeGenDataReader::read() {
143138
using namespace support;
144139

145140
// Parse the custom header line by line.
146-
while (Line->starts_with(":")) {
141+
for (; !Line.is_at_eof(); ++Line) {
142+
// Skip empty or whitespace-only lines
143+
if (Line->trim().empty())
144+
continue;
145+
146+
if (!Line->starts_with(":"))
147+
break;
147148
StringRef Str = Line->drop_front().rtrim();
148149
if (Str.equals_insensitive("outlined_hash_tree"))
149150
DataKind |= CGDataKind::FunctionOutlinedHashTree;
150151
else
151152
return error(cgdata_error::bad_header);
152-
++Line;
153153
}
154154

155155
// We treat an empty header (that is a comment # only) as a valid header.
156156
if (Line.is_at_eof()) {
157-
if (DataKind != CGDataKind::Unknown)
158-
return error(cgdata_error::bad_header);
159-
return Error::success();
157+
if (DataKind == CGDataKind::Unknown)
158+
return Error::success();
159+
return error(cgdata_error::bad_header);
160160
}
161161

162162
// The YAML docs follow after the header.

0 commit comments

Comments
 (0)