Skip to content

Commit 0cfd03a

Browse files
[ProfileData] Use ArrayRef in PatchItem (NFC) (#97379)
Packaging an array and its size as ArrayRef in PatchItem allows us to get rid of things like std::size(Header) and HeaderOffsets.size().
1 parent c785eae commit 0cfd03a

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

llvm/lib/ProfileData/InstrProfWriter.cpp

+16-15
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ using namespace llvm;
3939
// A struct to define how the data stream should be patched. For Indexed
4040
// profiling, only uint64_t data type is needed.
4141
struct PatchItem {
42-
uint64_t Pos; // Where to patch.
43-
uint64_t *D; // Pointer to an array of source data.
44-
int N; // Number of elements in \c D array.
42+
uint64_t Pos; // Where to patch.
43+
ArrayRef<uint64_t> D; // An array of source data.
4544
};
4645

4746
namespace llvm {
@@ -71,8 +70,8 @@ class ProfOStream {
7170
const uint64_t LastPos = FDOStream.tell();
7271
for (const auto &K : P) {
7372
FDOStream.seek(K.Pos);
74-
for (int I = 0; I < K.N; I++)
75-
write(K.D[I]);
73+
for (uint64_t Elem : K.D)
74+
write(Elem);
7675
}
7776
// Reset the stream to the last position after patching so that users
7877
// don't accidentally overwrite data. This makes it consistent with
@@ -82,7 +81,7 @@ class ProfOStream {
8281
raw_string_ostream &SOStream = static_cast<raw_string_ostream &>(OS);
8382
std::string &Data = SOStream.str(); // with flush
8483
for (const auto &K : P) {
85-
for (int I = 0; I < K.N; I++) {
84+
for (int I = 0, E = K.D.size(); I != E; I++) {
8685
uint64_t Bytes =
8786
endian::byte_swap<uint64_t, llvm::endianness::little>(K.D[I]);
8887
Data.replace(K.Pos + I * sizeof(uint64_t), sizeof(uint64_t),
@@ -612,7 +611,7 @@ static Error writeMemProfV0(ProfOStream &OS,
612611
uint64_t FrameTableOffset = writeMemProfFrames(OS, MemProfData.Frames);
613612

614613
uint64_t Header[] = {RecordTableOffset, FramePayloadOffset, FrameTableOffset};
615-
OS.patch({{HeaderUpdatePos, Header, std::size(Header)}});
614+
OS.patch({{HeaderUpdatePos, Header}});
616615

617616
return Error::success();
618617
}
@@ -647,7 +646,7 @@ static Error writeMemProfV1(ProfOStream &OS,
647646
uint64_t FrameTableOffset = writeMemProfFrames(OS, MemProfData.Frames);
648647

649648
uint64_t Header[] = {RecordTableOffset, FramePayloadOffset, FrameTableOffset};
650-
OS.patch({{HeaderUpdatePos, Header, std::size(Header)}});
649+
OS.patch({{HeaderUpdatePos, Header}});
651650

652651
return Error::success();
653652
}
@@ -697,7 +696,7 @@ static Error writeMemProfV2(ProfOStream &OS,
697696
RecordTableOffset, FramePayloadOffset, FrameTableOffset,
698697
CallStackPayloadOffset, CallStackTableOffset,
699698
};
700-
OS.patch({{HeaderUpdatePos, Header, std::size(Header)}});
699+
OS.patch({{HeaderUpdatePos, Header}});
701700

702701
return Error::success();
703702
}
@@ -751,7 +750,7 @@ static Error writeMemProfV3(ProfOStream &OS,
751750
RecordPayloadOffset,
752751
RecordTableOffset,
753752
};
754-
OS.patch({{HeaderUpdatePos, Header, std::size(Header)}});
753+
OS.patch({{HeaderUpdatePos, Header}});
755754

756755
return Error::success();
757756
}
@@ -989,12 +988,14 @@ Error InstrProfWriter::writeImpl(ProfOStream &OS) {
989988

990989
PatchItem PatchItems[] = {
991990
// Patch the Header fields
992-
{BackPatchStartOffset, HeaderOffsets.data(), (int)HeaderOffsets.size()},
991+
{BackPatchStartOffset, HeaderOffsets},
993992
// Patch the summary data.
994-
{SummaryOffset, reinterpret_cast<uint64_t *>(TheSummary.get()),
995-
(int)(SummarySize / sizeof(uint64_t))},
996-
{CSSummaryOffset, reinterpret_cast<uint64_t *>(TheCSSummary.get()),
997-
(int)CSSummarySize}};
993+
{SummaryOffset,
994+
ArrayRef<uint64_t>(reinterpret_cast<uint64_t *>(TheSummary.get()),
995+
SummarySize / sizeof(uint64_t))},
996+
{CSSummaryOffset,
997+
ArrayRef<uint64_t>(reinterpret_cast<uint64_t *>(TheCSSummary.get()),
998+
CSSummarySize)}};
998999

9991000
OS.patch(PatchItems);
10001001

0 commit comments

Comments
 (0)