@@ -273,7 +273,7 @@ void InstrProfWriter::addRecord(StringRef Name, uint64_t Hash,
273
273
274
274
void InstrProfWriter::addMemProfRecord (
275
275
const Function::GUID Id, const memprof::IndexedMemProfRecord &Record) {
276
- auto [Iter, Inserted] = MemProfRecordData .insert ({Id, Record});
276
+ auto [Iter, Inserted] = MemProfData. RecordData .insert ({Id, Record});
277
277
// If we inserted a new record then we are done.
278
278
if (Inserted) {
279
279
return ;
@@ -285,7 +285,7 @@ void InstrProfWriter::addMemProfRecord(
285
285
bool InstrProfWriter::addMemProfFrame (const memprof::FrameId Id,
286
286
const memprof::Frame &Frame,
287
287
function_ref<void (Error)> Warn) {
288
- auto [Iter, Inserted] = MemProfFrameData .insert ({Id, Frame});
288
+ auto [Iter, Inserted] = MemProfData. FrameData .insert ({Id, Frame});
289
289
// If a mapping already exists for the current frame id and it does not
290
290
// match the new mapping provided then reset the existing contents and bail
291
291
// out. We don't support the merging of memprof data whose Frame -> Id
@@ -302,7 +302,7 @@ bool InstrProfWriter::addMemProfCallStack(
302
302
const memprof::CallStackId CSId,
303
303
const llvm::SmallVector<memprof::FrameId> &CallStack,
304
304
function_ref<void (Error)> Warn) {
305
- auto [Iter, Inserted] = MemProfCallStackData .insert ({CSId, CallStack});
305
+ auto [Iter, Inserted] = MemProfData. CallStackData .insert ({CSId, CallStack});
306
306
// If a mapping already exists for the current call stack id and it does not
307
307
// match the new mapping provided then reset the existing contents and bail
308
308
// out. We don't support the merging of memprof data whose CallStack -> Id
@@ -389,22 +389,22 @@ void InstrProfWriter::mergeRecordsFromWriter(InstrProfWriter &&IPW,
389
389
addTemporalProfileTraces (IPW.TemporalProfTraces ,
390
390
IPW.TemporalProfTraceStreamSize );
391
391
392
- MemProfFrameData. reserve (IPW.MemProfFrameData .size ());
393
- for (auto &[FrameId, Frame] : IPW.MemProfFrameData ) {
392
+ MemProfData. FrameData . reserve (IPW.MemProfData . FrameData .size ());
393
+ for (auto &[FrameId, Frame] : IPW.MemProfData . FrameData ) {
394
394
// If we weren't able to add the frame mappings then it doesn't make sense
395
395
// to try to merge the records from this profile.
396
396
if (!addMemProfFrame (FrameId, Frame, Warn))
397
397
return ;
398
398
}
399
399
400
- MemProfCallStackData. reserve (IPW.MemProfCallStackData .size ());
401
- for (auto &[CSId, CallStack] : IPW.MemProfCallStackData ) {
400
+ MemProfData. CallStackData . reserve (IPW.MemProfData . CallStackData .size ());
401
+ for (auto &[CSId, CallStack] : IPW.MemProfData . CallStackData ) {
402
402
if (!addMemProfCallStack (CSId, CallStack, Warn))
403
403
return ;
404
404
}
405
405
406
- MemProfRecordData. reserve (IPW.MemProfRecordData .size ());
407
- for (auto &[GUID, Record] : IPW.MemProfRecordData ) {
406
+ MemProfData. RecordData . reserve (IPW.MemProfData . RecordData .size ());
407
+ for (auto &[GUID, Record] : IPW.MemProfData . RecordData ) {
408
408
addMemProfRecord (GUID, Record);
409
409
}
410
410
}
@@ -499,11 +499,8 @@ static uint64_t writeMemProfCallStacks(
499
499
return CallStackTableGenerator.Emit (OS.OS );
500
500
}
501
501
502
- static Error writeMemProfV0 (
503
- ProfOStream &OS,
504
- llvm::MapVector<GlobalValue::GUID, memprof::IndexedMemProfRecord>
505
- &MemProfRecordData,
506
- llvm::MapVector<memprof::FrameId, memprof::Frame> &MemProfFrameData) {
502
+ static Error writeMemProfV0 (ProfOStream &OS,
503
+ memprof::IndexedMemProfData &MemProfData) {
507
504
uint64_t HeaderUpdatePos = OS.tell ();
508
505
OS.write (0ULL ); // Reserve space for the memprof record table offset.
509
506
OS.write (0ULL ); // Reserve space for the memprof frame payload offset.
@@ -512,23 +509,20 @@ static Error writeMemProfV0(
512
509
auto Schema = memprof::getFullSchema ();
513
510
writeMemProfSchema (OS, Schema);
514
511
515
- uint64_t RecordTableOffset =
516
- writeMemProfRecords (OS, MemProfRecordData, &Schema, memprof::Version0);
512
+ uint64_t RecordTableOffset = writeMemProfRecords (OS, MemProfData. RecordData ,
513
+ &Schema, memprof::Version0);
517
514
518
515
uint64_t FramePayloadOffset = OS.tell ();
519
- uint64_t FrameTableOffset = writeMemProfFrames (OS, MemProfFrameData );
516
+ uint64_t FrameTableOffset = writeMemProfFrames (OS, MemProfData. FrameData );
520
517
521
518
uint64_t Header[] = {RecordTableOffset, FramePayloadOffset, FrameTableOffset};
522
519
OS.patch ({{HeaderUpdatePos, Header, std::size (Header)}});
523
520
524
521
return Error::success ();
525
522
}
526
523
527
- static Error writeMemProfV1 (
528
- ProfOStream &OS,
529
- llvm::MapVector<GlobalValue::GUID, memprof::IndexedMemProfRecord>
530
- &MemProfRecordData,
531
- llvm::MapVector<memprof::FrameId, memprof::Frame> &MemProfFrameData) {
524
+ static Error writeMemProfV1 (ProfOStream &OS,
525
+ memprof::IndexedMemProfData &MemProfData) {
532
526
OS.write (memprof::Version1);
533
527
uint64_t HeaderUpdatePos = OS.tell ();
534
528
OS.write (0ULL ); // Reserve space for the memprof record table offset.
@@ -538,26 +532,21 @@ static Error writeMemProfV1(
538
532
auto Schema = memprof::getFullSchema ();
539
533
writeMemProfSchema (OS, Schema);
540
534
541
- uint64_t RecordTableOffset =
542
- writeMemProfRecords (OS, MemProfRecordData, &Schema, memprof::Version1);
535
+ uint64_t RecordTableOffset = writeMemProfRecords (OS, MemProfData. RecordData ,
536
+ &Schema, memprof::Version1);
543
537
544
538
uint64_t FramePayloadOffset = OS.tell ();
545
- uint64_t FrameTableOffset = writeMemProfFrames (OS, MemProfFrameData );
539
+ uint64_t FrameTableOffset = writeMemProfFrames (OS, MemProfData. FrameData );
546
540
547
541
uint64_t Header[] = {RecordTableOffset, FramePayloadOffset, FrameTableOffset};
548
542
OS.patch ({{HeaderUpdatePos, Header, std::size (Header)}});
549
543
550
544
return Error::success ();
551
545
}
552
546
553
- static Error writeMemProfV2 (
554
- ProfOStream &OS,
555
- llvm::MapVector<GlobalValue::GUID, memprof::IndexedMemProfRecord>
556
- &MemProfRecordData,
557
- llvm::MapVector<memprof::FrameId, memprof::Frame> &MemProfFrameData,
558
- llvm::MapVector<memprof::CallStackId, llvm::SmallVector<memprof::FrameId>>
559
- &MemProfCallStackData,
560
- bool MemProfFullSchema) {
547
+ static Error writeMemProfV2 (ProfOStream &OS,
548
+ memprof::IndexedMemProfData &MemProfData,
549
+ bool MemProfFullSchema) {
561
550
OS.write (memprof::Version2);
562
551
uint64_t HeaderUpdatePos = OS.tell ();
563
552
OS.write (0ULL ); // Reserve space for the memprof record table offset.
@@ -571,15 +560,15 @@ static Error writeMemProfV2(
571
560
Schema = memprof::getFullSchema ();
572
561
writeMemProfSchema (OS, Schema);
573
562
574
- uint64_t RecordTableOffset =
575
- writeMemProfRecords (OS, MemProfRecordData, &Schema, memprof::Version2);
563
+ uint64_t RecordTableOffset = writeMemProfRecords (OS, MemProfData. RecordData ,
564
+ &Schema, memprof::Version2);
576
565
577
566
uint64_t FramePayloadOffset = OS.tell ();
578
- uint64_t FrameTableOffset = writeMemProfFrames (OS, MemProfFrameData );
567
+ uint64_t FrameTableOffset = writeMemProfFrames (OS, MemProfData. FrameData );
579
568
580
569
uint64_t CallStackPayloadOffset = OS.tell ();
581
570
uint64_t CallStackTableOffset =
582
- writeMemProfCallStacks (OS, MemProfCallStackData );
571
+ writeMemProfCallStacks (OS, MemProfData. CallStackData );
583
572
584
573
uint64_t Header[] = {
585
574
RecordTableOffset, FramePayloadOffset, FrameTableOffset,
@@ -603,23 +592,17 @@ static Error writeMemProfV2(
603
592
// uint64_t Schema entry N - 1
604
593
// OnDiskChainedHashTable MemProfRecordData
605
594
// OnDiskChainedHashTable MemProfFrameData
606
- static Error writeMemProf (
607
- ProfOStream &OS,
608
- llvm::MapVector<GlobalValue::GUID, memprof::IndexedMemProfRecord>
609
- &MemProfRecordData,
610
- llvm::MapVector<memprof::FrameId, memprof::Frame> &MemProfFrameData,
611
- llvm::MapVector<memprof::CallStackId, llvm::SmallVector<memprof::FrameId>>
612
- &MemProfCallStackData,
613
- memprof::IndexedVersion MemProfVersionRequested, bool MemProfFullSchema) {
614
-
595
+ static Error writeMemProf (ProfOStream &OS,
596
+ memprof::IndexedMemProfData &MemProfData,
597
+ memprof::IndexedVersion MemProfVersionRequested,
598
+ bool MemProfFullSchema) {
615
599
switch (MemProfVersionRequested) {
616
600
case memprof::Version0:
617
- return writeMemProfV0 (OS, MemProfRecordData, MemProfFrameData );
601
+ return writeMemProfV0 (OS, MemProfData );
618
602
case memprof::Version1:
619
- return writeMemProfV1 (OS, MemProfRecordData, MemProfFrameData );
603
+ return writeMemProfV1 (OS, MemProfData );
620
604
case memprof::Version2:
621
- return writeMemProfV2 (OS, MemProfRecordData, MemProfFrameData,
622
- MemProfCallStackData, MemProfFullSchema);
605
+ return writeMemProfV2 (OS, MemProfData, MemProfFullSchema);
623
606
}
624
607
625
608
return make_error<InstrProfError>(
@@ -737,8 +720,7 @@ Error InstrProfWriter::writeImpl(ProfOStream &OS) {
737
720
uint64_t MemProfSectionStart = 0 ;
738
721
if (static_cast <bool >(ProfileKind & InstrProfKind::MemProf)) {
739
722
MemProfSectionStart = OS.tell ();
740
- if (auto E = writeMemProf (OS, MemProfRecordData, MemProfFrameData,
741
- MemProfCallStackData, MemProfVersionRequested,
723
+ if (auto E = writeMemProf (OS, MemProfData, MemProfVersionRequested,
742
724
MemProfFullSchema))
743
725
return E;
744
726
}
0 commit comments