Skip to content

Commit 40ac8ff

Browse files
Address comments.
1 parent ff591bf commit 40ac8ff

File tree

3 files changed

+7
-13
lines changed

3 files changed

+7
-13
lines changed

llvm/include/llvm/ProfileData/MemProfReader.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,10 @@ class YAMLMemProfReader final : public MemProfReader {
214214
public:
215215
YAMLMemProfReader() = default;
216216

217-
// Return true if the \p DataBuffer starts "---" indicating it is a YAML file.
217+
// Return true if the \p DataBuffer starts with "---" indicating it is a YAML
218+
// file.
218219
static bool hasFormat(const MemoryBuffer &DataBuffer);
219-
// Return true if the file at \p Path starts with magic bytes indicating it is
220-
// a raw binary memprof profile.
220+
// Wrapper around hasFormat above, reading the file instead of the memory buffer.
221221
static bool hasFormat(const StringRef Path);
222222

223223
// Create a YAMLMemProfReader after sanity checking the contents of the file

llvm/lib/ProfileData/MemProfReader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ YAMLMemProfReader::create(const Twine &Path) {
767767

768768
Expected<std::unique_ptr<YAMLMemProfReader>>
769769
YAMLMemProfReader::create(std::unique_ptr<MemoryBuffer> Buffer) {
770-
std::unique_ptr<YAMLMemProfReader> Reader(new YAMLMemProfReader());
770+
auto Reader = std::make_unique<YAMLMemProfReader>();
771771
Reader->parse(Buffer->getBuffer());
772772
return std::move(Reader);
773773
}

llvm/tools/llvm-profdata/llvm-profdata.cpp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3271,22 +3271,16 @@ static int showMemProfProfile(ShowFormat SFormat, raw_fd_ostream &OS) {
32713271
if (SFormat == ShowFormat::Json)
32723272
exitWithError("JSON output is not supported for MemProf");
32733273

3274-
// Load the file to check the magic bytes.
3275-
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> BufferOrError =
3276-
llvm::MemoryBuffer::getFile(Filename);
3277-
if (auto EC = BufferOrError.getError())
3278-
exitWithError("Error opening profile file '" + Filename + "'");
3279-
auto Buffer = std::move(BufferOrError.get());
3280-
32813274
// Show the raw profile in YAML.
3282-
if (memprof::RawMemProfReader::hasFormat(*Buffer)) {
3275+
if (memprof::RawMemProfReader::hasFormat(Filename)) {
32833276
auto ReaderOr = llvm::memprof::RawMemProfReader::create(
32843277
Filename, ProfiledBinary, /*KeepNames=*/true);
3285-
if (Error E = ReaderOr.takeError())
3278+
if (Error E = ReaderOr.takeError()) {
32863279
// Since the error can be related to the profile or the binary we do not
32873280
// pass whence. Instead additional context is provided where necessary in
32883281
// the error message.
32893282
exitWithError(std::move(E), /*Whence*/ "");
3283+
}
32903284

32913285
std::unique_ptr<llvm::memprof::RawMemProfReader> Reader(
32923286
ReaderOr.get().release());

0 commit comments

Comments
 (0)