Skip to content

Commit 4b3b74d

Browse files
[memprof] Use InstrProfWriter::addMemProfData in a unit test (NFC) (#116921)
This patch uses InstrProfWriter::addMemProfData to add the complete MemProf profile to the writer context.
1 parent 4acba06 commit 4b3b74d

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

llvm/unittests/Transforms/Instrumentation/MemProfUseTest.cpp

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -434,31 +434,30 @@ attributes #1 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "t
434434
ASSERT_THAT_ERROR(Writer.mergeProfileKind(InstrProfKind::MemProf),
435435
Succeeded());
436436

437-
const std::pair<memprof::FrameId, memprof::Frame> Frames[] = {
438-
// The call sites within foo.
439-
{0, {GUIDFoo, 1, 8, false}},
440-
{1, {GUIDFoo, 2, 3, false}},
441-
{2, {GUIDFoo, 3, 3, false}},
442-
// Line/column numbers below don't matter.
443-
{3, {GUIDBar, 9, 9, false}},
444-
{4, {GUIDZzz, 9, 9, false}},
445-
{5, {GUIDBaz, 9, 9, false}}};
446-
for (const auto &[FrameId, Frame] : Frames)
447-
Writer.addMemProfFrame(FrameId, Frame, Err);
448-
449-
const std::pair<memprof::CallStackId, SmallVector<memprof::FrameId>>
450-
CallStacks[] = {
451-
{0x111, {3, 0}}, // bar called by foo
452-
{0x222, {4, 1}}, // zzz called by foo
453-
{0x333, {5, 2}} // baz called by foo
454-
};
455-
for (const auto &[CSId, CallStack] : CallStacks)
456-
Writer.addMemProfCallStack(CSId, CallStack, Err);
457-
458437
const IndexedMemProfRecord IndexedMR = makeRecordV2(
459438
/*AllocFrames=*/{0x111, 0x222, 0x333},
460439
/*CallSiteFrames=*/{}, MIB, memprof::getHotColdSchema());
461-
Writer.addMemProfRecord(/*Id=*/0x9999, IndexedMR);
440+
441+
memprof::IndexedMemProfData MemProfData;
442+
// The call sites within foo.
443+
MemProfData.Frames.try_emplace(0, GUIDFoo, 1, 8, false);
444+
MemProfData.Frames.try_emplace(1, GUIDFoo, 2, 3, false);
445+
MemProfData.Frames.try_emplace(2, GUIDFoo, 3, 3, false);
446+
// Line/column numbers below don't matter.
447+
MemProfData.Frames.try_emplace(3, GUIDBar, 9, 9, false);
448+
MemProfData.Frames.try_emplace(4, GUIDZzz, 9, 9, false);
449+
MemProfData.Frames.try_emplace(5, GUIDBaz, 9, 9, false);
450+
MemProfData.CallStacks.try_emplace(
451+
0x111,
452+
std::initializer_list<memprof::FrameId>{3, 0}); // bar called by foo
453+
MemProfData.CallStacks.try_emplace(
454+
0x222,
455+
std::initializer_list<memprof::FrameId>{4, 1}); // zzz called by foo
456+
MemProfData.CallStacks.try_emplace(
457+
0x333,
458+
std::initializer_list<memprof::FrameId>{5, 2}); // baz called by foo
459+
MemProfData.Records.try_emplace(0x9999, IndexedMR);
460+
Writer.addMemProfData(MemProfData, Err);
462461

463462
auto Profile = Writer.writeBuffer();
464463

0 commit comments

Comments
 (0)