@@ -181,10 +181,12 @@ class InstrProfRecordWriterTrait {
181
181
182
182
InstrProfWriter::InstrProfWriter (bool Sparse,
183
183
uint64_t TemporalProfTraceReservoirSize,
184
- uint64_t MaxTemporalProfTraceLength)
184
+ uint64_t MaxTemporalProfTraceLength,
185
+ bool WritePrevVersion)
185
186
: Sparse(Sparse), MaxTemporalProfTraceLength(MaxTemporalProfTraceLength),
186
187
TemporalProfTraceReservoirSize(TemporalProfTraceReservoirSize),
187
- InfoObj(new InstrProfRecordWriterTrait()) {}
188
+ InfoObj(new InstrProfRecordWriterTrait()),
189
+ WritePrevVersion(WritePrevVersion) {}
188
190
189
191
InstrProfWriter::~InstrProfWriter () { delete InfoObj; }
190
192
@@ -432,7 +434,13 @@ Error InstrProfWriter::writeImpl(ProfOStream &OS) {
432
434
// Write the header.
433
435
IndexedInstrProf::Header Header;
434
436
Header.Magic = IndexedInstrProf::Magic;
435
- Header.Version = IndexedInstrProf::ProfVersion::CurrentVersion;
437
+ Header.Version = WritePrevVersion
438
+ ? IndexedInstrProf::ProfVersion::Version11
439
+ : IndexedInstrProf::ProfVersion::CurrentVersion;
440
+ // The WritePrevVersion handling will either need to be removed or updated
441
+ // if the version is advanced beyond 12.
442
+ assert (IndexedInstrProf::ProfVersion::CurrentVersion ==
443
+ IndexedInstrProf::ProfVersion::Version12);
436
444
if (static_cast <bool >(ProfileKind & InstrProfKind::IRInstrumentation))
437
445
Header.Version |= VARIANT_MASK_IR_PROF;
438
446
if (static_cast <bool >(ProfileKind & InstrProfKind::ContextSensitive))
@@ -484,7 +492,8 @@ Error InstrProfWriter::writeImpl(ProfOStream &OS) {
484
492
OS.write (0 );
485
493
486
494
uint64_t VTableNamesOffset = OS.tell ();
487
- OS.write (0 );
495
+ if (!WritePrevVersion)
496
+ OS.write (0 );
488
497
489
498
// Reserve space to write profile summary data.
490
499
uint32_t NumEntries = ProfileSummaryBuilder::DefaultCutoffs.size ();
@@ -608,27 +617,29 @@ Error InstrProfWriter::writeImpl(ProfOStream &OS) {
608
617
609
618
uint64_t VTableNamesSectionStart = OS.tell ();
610
619
611
- // Use a dummy (and uncompressed) string as compressed vtable names and get
612
- // the necessary profile format change in place for version 12.
613
- // TODO: Store the list of vtable names in InstrProfWriter and use the
614
- // real compressed name.
615
- std::string CompressedVTableNames = " VTableNames" ;
620
+ if (!WritePrevVersion) {
621
+ // Use a dummy (and uncompressed) string as compressed vtable names and get
622
+ // the necessary profile format change in place for version 12.
623
+ // TODO: Store the list of vtable names in InstrProfWriter and use the
624
+ // real compressed name.
625
+ std::string CompressedVTableNames = " VTableNames" ;
616
626
617
- uint64_t CompressedStringLen = CompressedVTableNames.length ();
627
+ uint64_t CompressedStringLen = CompressedVTableNames.length ();
618
628
619
- // Record the length of compressed string.
620
- OS.write (CompressedStringLen);
629
+ // Record the length of compressed string.
630
+ OS.write (CompressedStringLen);
621
631
622
- // Write the chars in compressed strings.
623
- for (auto &c : CompressedVTableNames)
624
- OS.writeByte (static_cast <uint8_t >(c));
632
+ // Write the chars in compressed strings.
633
+ for (auto &c : CompressedVTableNames)
634
+ OS.writeByte (static_cast <uint8_t >(c));
625
635
626
- // Pad up to a multiple of 8.
627
- // InstrProfReader would read bytes according to 'CompressedStringLen'.
628
- uint64_t PaddedLength = alignTo (CompressedStringLen, 8 );
636
+ // Pad up to a multiple of 8.
637
+ // InstrProfReader would read bytes according to 'CompressedStringLen'.
638
+ uint64_t PaddedLength = alignTo (CompressedStringLen, 8 );
629
639
630
- for (uint64_t K = CompressedStringLen; K < PaddedLength; K++) {
631
- OS.writeByte (0 );
640
+ for (uint64_t K = CompressedStringLen; K < PaddedLength; K++) {
641
+ OS.writeByte (0 );
642
+ }
632
643
}
633
644
634
645
uint64_t TemporalProfTracesSectionStart = 0 ;
@@ -662,26 +673,48 @@ Error InstrProfWriter::writeImpl(ProfOStream &OS) {
662
673
}
663
674
InfoObj->CSSummaryBuilder = nullptr ;
664
675
665
- // Now do the final patch:
666
- PatchItem PatchItems[] = {
667
- // Patch the Header.HashOffset field.
668
- {HashTableStartFieldOffset, &HashTableStart, 1 },
669
- // Patch the Header.MemProfOffset (=0 for profiles without MemProf
670
- // data).
671
- {MemProfSectionOffset, &MemProfSectionStart, 1 },
672
- // Patch the Header.BinaryIdSectionOffset.
673
- {BinaryIdSectionOffset, &BinaryIdSectionStart, 1 },
674
- // Patch the Header.TemporalProfTracesOffset (=0 for profiles without
675
- // traces).
676
- {TemporalProfTracesOffset, &TemporalProfTracesSectionStart, 1 },
677
- {VTableNamesOffset, &VTableNamesSectionStart, 1 },
678
- // Patch the summary data.
679
- {SummaryOffset, reinterpret_cast <uint64_t *>(TheSummary.get ()),
680
- (int )(SummarySize / sizeof (uint64_t ))},
681
- {CSSummaryOffset, reinterpret_cast <uint64_t *>(TheCSSummary.get ()),
682
- (int )CSSummarySize}};
683
-
684
- OS.patch (PatchItems, std::size (PatchItems));
676
+ if (!WritePrevVersion) {
677
+ // Now do the final patch:
678
+ PatchItem PatchItems[] = {
679
+ // Patch the Header.HashOffset field.
680
+ {HashTableStartFieldOffset, &HashTableStart, 1 },
681
+ // Patch the Header.MemProfOffset (=0 for profiles without MemProf
682
+ // data).
683
+ {MemProfSectionOffset, &MemProfSectionStart, 1 },
684
+ // Patch the Header.BinaryIdSectionOffset.
685
+ {BinaryIdSectionOffset, &BinaryIdSectionStart, 1 },
686
+ // Patch the Header.TemporalProfTracesOffset (=0 for profiles without
687
+ // traces).
688
+ {TemporalProfTracesOffset, &TemporalProfTracesSectionStart, 1 },
689
+ {VTableNamesOffset, &VTableNamesSectionStart, 1 },
690
+ // Patch the summary data.
691
+ {SummaryOffset, reinterpret_cast <uint64_t *>(TheSummary.get ()),
692
+ (int )(SummarySize / sizeof (uint64_t ))},
693
+ {CSSummaryOffset, reinterpret_cast <uint64_t *>(TheCSSummary.get ()),
694
+ (int )CSSummarySize}};
695
+
696
+ OS.patch (PatchItems, std::size (PatchItems));
697
+ } else {
698
+ // Now do the final patch:
699
+ PatchItem PatchItems[] = {
700
+ // Patch the Header.HashOffset field.
701
+ {HashTableStartFieldOffset, &HashTableStart, 1 },
702
+ // Patch the Header.MemProfOffset (=0 for profiles without MemProf
703
+ // data).
704
+ {MemProfSectionOffset, &MemProfSectionStart, 1 },
705
+ // Patch the Header.BinaryIdSectionOffset.
706
+ {BinaryIdSectionOffset, &BinaryIdSectionStart, 1 },
707
+ // Patch the Header.TemporalProfTracesOffset (=0 for profiles without
708
+ // traces).
709
+ {TemporalProfTracesOffset, &TemporalProfTracesSectionStart, 1 },
710
+ // Patch the summary data.
711
+ {SummaryOffset, reinterpret_cast <uint64_t *>(TheSummary.get ()),
712
+ (int )(SummarySize / sizeof (uint64_t ))},
713
+ {CSSummaryOffset, reinterpret_cast <uint64_t *>(TheCSSummary.get ()),
714
+ (int )CSSummarySize}};
715
+
716
+ OS.patch (PatchItems, std::size (PatchItems));
717
+ }
685
718
686
719
for (const auto &I : FunctionData)
687
720
for (const auto &F : I.getValue ())
0 commit comments