Skip to content

Commit 13e6da8

Browse files
Address comments.
1 parent d8a8da6 commit 13e6da8

File tree

4 files changed

+23
-31
lines changed

4 files changed

+23
-31
lines changed

llvm/include/llvm/ProfileData/InstrProfReader.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -717,8 +717,8 @@ class IndexedMemProfReader {
717717
DenseMap<uint64_t, SmallVector<memprof::CallEdgeTy, 0>>
718718
getMemProfCallerCalleePairs() const;
719719

720-
// Return a vector of all GUIDs that we have corresponding MemProfRecords for.
721-
SmallVector<uint64_t, 0> getMemProfRecordKeys() const;
720+
// Return the entire MemProf profile.
721+
memprof::AllMemProfData getAllMemProfData() const;
722722
};
723723

724724
/// Reader for the indexed binary instrprof format.
@@ -826,8 +826,8 @@ class IndexedInstrProfReader : public InstrProfReader {
826826
return MemProfReader.getMemProfCallerCalleePairs();
827827
}
828828

829-
SmallVector<uint64_t, 0> getMemProfRecordKeys() {
830-
return MemProfReader.getMemProfRecordKeys();
829+
memprof::AllMemProfData getAllMemProfData() const {
830+
return MemProfReader.getAllMemProfData();
831831
}
832832

833833
/// Fill Counts with the profile data for the given function name.

llvm/include/llvm/ProfileData/MemProfReader.h

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

217-
// Return true if the \p DataBuffer starts with magic bytes indicating it is
218-
// a raw binary memprof profile.
217+
// Return true if the \p DataBuffer starts "---" indicating it is a YAML file.
219218
static bool hasFormat(const MemoryBuffer &DataBuffer);
220219
// Return true if the file at \p Path starts with magic bytes indicating it is
221220
// a raw binary memprof profile.
222221
static bool hasFormat(const StringRef Path);
223222

224-
// Create a RawMemProfReader after sanity checking the contents of the file at
225-
// \p Path or the \p Buffer. The binary from which the profile has been
226-
// collected is specified via a path in \p ProfiledBinary.
223+
// Create a YAMLMemProfReader after sanity checking the contents of the file at
224+
// \p Path or the \p Buffer.
227225
static Expected<std::unique_ptr<YAMLMemProfReader>> create(const Twine &Path);
228226
static Expected<std::unique_ptr<YAMLMemProfReader>>
229227
create(std::unique_ptr<MemoryBuffer> Buffer);

llvm/lib/ProfileData/InstrProfReader.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1664,12 +1664,19 @@ IndexedMemProfReader::getMemProfCallerCalleePairs() const {
16641664
return Pairs;
16651665
}
16661666

1667-
SmallVector<uint64_t, 0> IndexedMemProfReader::getMemProfRecordKeys() const {
1668-
SmallVector<uint64_t, 0> Keys;
1669-
Keys.reserve(MemProfRecordTable->getNumEntries());
1670-
for (uint64_t Key : MemProfRecordTable->keys())
1671-
Keys.push_back(Key);
1672-
return Keys;
1667+
memprof::AllMemProfData IndexedMemProfReader::getAllMemProfData() const {
1668+
memprof::AllMemProfData AllMemProfData;
1669+
AllMemProfData.HeapProfileRecords.reserve(MemProfRecordTable->getNumEntries());
1670+
for (uint64_t Key : MemProfRecordTable->keys()) {
1671+
auto Record = getMemProfRecord(Key);
1672+
if (Record.takeError())
1673+
continue;
1674+
memprof::GUIDMemProfRecordPair Pair;
1675+
Pair.GUID = Key;
1676+
Pair.Record = std::move(*Record);
1677+
AllMemProfData.HeapProfileRecords.push_back(std::move(Pair));
1678+
}
1679+
return AllMemProfData;
16731680
}
16741681

16751682
Error IndexedInstrProfReader::getFunctionCounts(StringRef FuncName,

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

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -726,17 +726,16 @@ loadInput(const WeightedFile &Input, SymbolRemapper *Remapper,
726726
using ::llvm::memprof::YAMLMemProfReader;
727727
if (YAMLMemProfReader::hasFormat(Input.Filename)) {
728728
auto ReaderOrErr = YAMLMemProfReader::create(Input.Filename);
729-
if (!ReaderOrErr) {
729+
if (!ReaderOrErr)
730730
exitWithError(ReaderOrErr.takeError(), Input.Filename);
731-
}
732731
std::unique_ptr<YAMLMemProfReader> Reader = std::move(ReaderOrErr.get());
733732
// Check if the profile types can be merged, e.g. clang frontend profiles
734733
// should not be merged with memprof profiles.
735734
if (Error E = WC->Writer.mergeProfileKind(Reader->getProfileKind())) {
736735
consumeError(std::move(E));
737736
WC->Errors.emplace_back(
738737
make_error<StringError>(
739-
"Cannot merge MemProf profile with Clang generated profile.",
738+
"Cannot merge MemProf profile with incompatible profile.",
740739
std::error_code()),
741740
Filename);
742741
return;
@@ -3303,19 +3302,7 @@ static int showMemProfProfile(ShowFormat SFormat, raw_fd_ostream &OS) {
33033302
exitWithError(std::move(E), Filename);
33043303

33053304
auto Reader = std::move(ReaderOrErr.get());
3306-
3307-
// Build pairs of GUID and MemProfRecord.
3308-
memprof::AllMemProfData Data;
3309-
for (const uint64_t Key : Reader->getMemProfRecordKeys()) {
3310-
auto Record = Reader->getMemProfRecord(Key);
3311-
if (Record.takeError())
3312-
continue;
3313-
memprof::GUIDMemProfRecordPair Pair;
3314-
Pair.GUID = Key;
3315-
Pair.Record = std::move(*Record);
3316-
Data.HeapProfileRecords.push_back(std::move(Pair));
3317-
}
3318-
3305+
memprof::AllMemProfData Data = Reader->getAllMemProfData();
33193306
yaml::Output Yout(OS);
33203307
Yout << Data;
33213308

0 commit comments

Comments
 (0)