[llvm] [memprof] Refactor getMemProfRecord (NFC) (PR #93138)
Snehasish Kumar via llvm-commits
llvm-commits at lists.llvm.org
Thu May 23 09:29:38 PDT 2024
================
@@ -1502,41 +1550,22 @@ IndexedMemProfReader::getMemProfRecord(const uint64_t FuncNameHash) const {
instrprof_error::unknown_function,
"memprof record not found for function hash " + Twine(FuncNameHash));
- // Setup a callback to convert from frame ids to frame using the on-disk
- // FrameData hash table.
- memprof::FrameIdConverter<MemProfFrameHashTable> FrameIdConv(
- *MemProfFrameTable.get());
-
const memprof::IndexedMemProfRecord IndexedRecord = *Iter;
- memprof::MemProfRecord Record;
- if (MemProfCallStackTable) {
- // Setup a callback to convert call stack ids to call stacks using the
- // on-disk hash table.
- memprof::CallStackIdConverter<MemProfCallStackHashTable> CSIdConv(
- *MemProfCallStackTable.get(), FrameIdConv);
-
- Record = IndexedRecord.toMemProfRecord(CSIdConv);
-
- // Check that all call stack ids were successfully converted to call stacks.
- if (CSIdConv.LastUnmappedId) {
- return make_error<InstrProfError>(
- instrprof_error::hash_mismatch,
- "memprof call stack not found for call stack id " +
- Twine(*CSIdConv.LastUnmappedId));
- }
- } else {
- Record = memprof::MemProfRecord(IndexedRecord, FrameIdConv);
+ switch (Version) {
+ case memprof::Version0:
+ case memprof::Version1:
+ assert(MemProfFrameTable && "MemProfFrameTable must be available");
+ assert(!MemProfCallStackTable &&
+ "MemProfCallStackTable must not be available");
+ return getMemProfRecordV0(IndexedRecord, *MemProfFrameTable.get());
+ case memprof::Version2:
+ assert(MemProfFrameTable && "MemProfFrameTable must be available");
+ assert(MemProfCallStackTable && "MemProfCallStackTable must be available");
+ return getMemProfRecordV2(IndexedRecord, *MemProfFrameTable.get(),
+ *MemProfCallStackTable.get());
}
- // Check that all frame ids were successfully converted to frames.
- if (FrameIdConv.LastUnmappedId) {
- return make_error<InstrProfError>(
- instrprof_error::hash_mismatch,
- "memprof frame not found for frame id " +
- Twine(*FrameIdConv.LastUnmappedId));
- }
-
- return Record;
+ llvm_unreachable("unknown version");
----------------
snehasish wrote:
Since this function can return an error we should do that instead. `instrprof_error::unsupported_version` should be appropriate here.
https://github.com/llvm/llvm-project/pull/93138
More information about the llvm-commits
mailing list