@@ -639,6 +639,27 @@ static Error writeMemProf(ProfOStream &OS,
639
639
memprof::MaximumSupportedVersion));
640
640
}
641
641
642
+ uint64_t InstrProfWriter::writeHeader (const IndexedInstrProf::Header &Header,
643
+ const bool WritePrevVersion,
644
+ ProfOStream &OS) {
645
+ // Only write out the first four fields.
646
+ for (int I = 0 ; I < 4 ; I++)
647
+ OS.write (reinterpret_cast <const uint64_t *>(&Header)[I]);
648
+
649
+ // Remember the offset of the remaining fields to allow back patching later.
650
+ auto BackPatchStartOffset = OS.tell ();
651
+
652
+ // Reserve the space for back patching later.
653
+ OS.write (0 ); // HashOffset
654
+ OS.write (0 ); // MemProfOffset
655
+ OS.write (0 ); // BinaryIdOffset
656
+ OS.write (0 ); // TemporalProfTracesOffset
657
+ if (!WritePrevVersion)
658
+ OS.write (0 ); // VTableNamesOffset
659
+
660
+ return BackPatchStartOffset;
661
+ }
662
+
642
663
Error InstrProfWriter::writeImpl (ProfOStream &OS) {
643
664
using namespace IndexedInstrProf ;
644
665
using namespace support ;
@@ -651,7 +672,7 @@ Error InstrProfWriter::writeImpl(ProfOStream &OS) {
651
672
InfoObj->CSSummaryBuilder = &CSISB;
652
673
653
674
// Populate the hash table generator.
654
- SmallVector<std::pair<StringRef, const ProfilingData *>, 0 > OrderedData;
675
+ SmallVector<std::pair<StringRef, const ProfilingData *>> OrderedData;
655
676
for (const auto &I : FunctionData)
656
677
if (shouldEncodeData (I.getValue ()))
657
678
OrderedData.emplace_back ((I.getKey ()), &I.getValue ());
@@ -693,35 +714,8 @@ Error InstrProfWriter::writeImpl(ProfOStream &OS) {
693
714
Header.TemporalProfTracesOffset = 0 ;
694
715
Header.VTableNamesOffset = 0 ;
695
716
696
- // Only write out the first four fields. We need to remember the offset of the
697
- // remaining fields to allow back patching later.
698
- for (int I = 0 ; I < 4 ; I++)
699
- OS.write (reinterpret_cast <uint64_t *>(&Header)[I]);
700
-
701
- // Save the location of Header.HashOffset field in \c OS.
702
- uint64_t HashTableStartFieldOffset = OS.tell ();
703
- // Reserve the space for HashOffset field.
704
- OS.write (0 );
705
-
706
- // Save the location of MemProf profile data. This is stored in two parts as
707
- // the schema and as a separate on-disk chained hashtable.
708
- uint64_t MemProfSectionOffset = OS.tell ();
709
- // Reserve space for the MemProf table field to be patched later if this
710
- // profile contains memory profile information.
711
- OS.write (0 );
712
-
713
- // Save the location of binary ids section.
714
- uint64_t BinaryIdSectionOffset = OS.tell ();
715
- // Reserve space for the BinaryIdOffset field to be patched later if this
716
- // profile contains binary ids.
717
- OS.write (0 );
718
-
719
- uint64_t TemporalProfTracesOffset = OS.tell ();
720
- OS.write (0 );
721
-
722
- uint64_t VTableNamesOffset = OS.tell ();
723
- if (!WritePrevVersion)
724
- OS.write (0 );
717
+ const uint64_t BackPatchStartOffset =
718
+ writeHeader (Header, WritePrevVersion, OS);
725
719
726
720
// Reserve space to write profile summary data.
727
721
uint32_t NumEntries = ProfileSummaryBuilder::DefaultCutoffs.size ();
@@ -850,16 +844,20 @@ Error InstrProfWriter::writeImpl(ProfOStream &OS) {
850
844
}
851
845
InfoObj->CSSummaryBuilder = nullptr ;
852
846
847
+ const size_t MemProfOffset = BackPatchStartOffset + sizeof (uint64_t );
848
+ const size_t BinaryIdOffset = MemProfOffset + sizeof (uint64_t );
849
+ const size_t TemporalProfTracesOffset = BinaryIdOffset + sizeof (uint64_t );
850
+ const size_t VTableNamesOffset = TemporalProfTracesOffset + sizeof (uint64_t );
853
851
if (!WritePrevVersion) {
854
852
// Now do the final patch:
855
853
PatchItem PatchItems[] = {
856
854
// Patch the Header.HashOffset field.
857
- {HashTableStartFieldOffset , &HashTableStart, 1 },
855
+ {BackPatchStartOffset , &HashTableStart, 1 },
858
856
// Patch the Header.MemProfOffset (=0 for profiles without MemProf
859
857
// data).
860
- {MemProfSectionOffset , &MemProfSectionStart, 1 },
858
+ {MemProfOffset , &MemProfSectionStart, 1 },
861
859
// Patch the Header.BinaryIdSectionOffset.
862
- {BinaryIdSectionOffset , &BinaryIdSectionStart, 1 },
860
+ {BinaryIdOffset , &BinaryIdSectionStart, 1 },
863
861
// Patch the Header.TemporalProfTracesOffset (=0 for profiles without
864
862
// traces).
865
863
{TemporalProfTracesOffset, &TemporalProfTracesSectionStart, 1 },
@@ -875,12 +873,12 @@ Error InstrProfWriter::writeImpl(ProfOStream &OS) {
875
873
// Now do the final patch:
876
874
PatchItem PatchItems[] = {
877
875
// Patch the Header.HashOffset field.
878
- {HashTableStartFieldOffset , &HashTableStart, 1 },
876
+ {BackPatchStartOffset , &HashTableStart, 1 },
879
877
// Patch the Header.MemProfOffset (=0 for profiles without MemProf
880
878
// data).
881
- {MemProfSectionOffset , &MemProfSectionStart, 1 },
879
+ {MemProfOffset , &MemProfSectionStart, 1 },
882
880
// Patch the Header.BinaryIdSectionOffset.
883
- {BinaryIdSectionOffset , &BinaryIdSectionStart, 1 },
881
+ {BinaryIdOffset , &BinaryIdSectionStart, 1 },
884
882
// Patch the Header.TemporalProfTracesOffset (=0 for profiles without
885
883
// traces).
886
884
{TemporalProfTracesOffset, &TemporalProfTracesSectionStart, 1 },
0 commit comments