[llvm] 0cfd03a - [ProfileData] Use ArrayRef in PatchItem (NFC) (#97379)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 2 22:58:30 PDT 2024
Author: Kazu Hirata
Date: 2024-07-02T22:58:26-07:00
New Revision: 0cfd03ac0d3f9713090a581bda07584754c73a49
URL: https://github.com/llvm/llvm-project/commit/0cfd03ac0d3f9713090a581bda07584754c73a49
DIFF: https://github.com/llvm/llvm-project/commit/0cfd03ac0d3f9713090a581bda07584754c73a49.diff
LOG: [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().
Added:
Modified:
llvm/lib/ProfileData/InstrProfWriter.cpp
Removed:
################################################################################
diff --git a/llvm/lib/ProfileData/InstrProfWriter.cpp b/llvm/lib/ProfileData/InstrProfWriter.cpp
index 1ba229147c1f9..1a3721bf10350 100644
--- a/llvm/lib/ProfileData/InstrProfWriter.cpp
+++ b/llvm/lib/ProfileData/InstrProfWriter.cpp
@@ -39,9 +39,8 @@ using namespace llvm;
// A struct to define how the data stream should be patched. For Indexed
// profiling, only uint64_t data type is needed.
struct PatchItem {
- uint64_t Pos; // Where to patch.
- uint64_t *D; // Pointer to an array of source data.
- int N; // Number of elements in \c D array.
+ uint64_t Pos; // Where to patch.
+ ArrayRef<uint64_t> D; // An array of source data.
};
namespace llvm {
@@ -71,8 +70,8 @@ class ProfOStream {
const uint64_t LastPos = FDOStream.tell();
for (const auto &K : P) {
FDOStream.seek(K.Pos);
- for (int I = 0; I < K.N; I++)
- write(K.D[I]);
+ for (uint64_t Elem : K.D)
+ write(Elem);
}
// Reset the stream to the last position after patching so that users
// don't accidentally overwrite data. This makes it consistent with
@@ -82,7 +81,7 @@ class ProfOStream {
raw_string_ostream &SOStream = static_cast<raw_string_ostream &>(OS);
std::string &Data = SOStream.str(); // with flush
for (const auto &K : P) {
- for (int I = 0; I < K.N; I++) {
+ for (int I = 0, E = K.D.size(); I != E; I++) {
uint64_t Bytes =
endian::byte_swap<uint64_t, llvm::endianness::little>(K.D[I]);
Data.replace(K.Pos + I * sizeof(uint64_t), sizeof(uint64_t),
@@ -612,7 +611,7 @@ static Error writeMemProfV0(ProfOStream &OS,
uint64_t FrameTableOffset = writeMemProfFrames(OS, MemProfData.Frames);
uint64_t Header[] = {RecordTableOffset, FramePayloadOffset, FrameTableOffset};
- OS.patch({{HeaderUpdatePos, Header, std::size(Header)}});
+ OS.patch({{HeaderUpdatePos, Header}});
return Error::success();
}
@@ -647,7 +646,7 @@ static Error writeMemProfV1(ProfOStream &OS,
uint64_t FrameTableOffset = writeMemProfFrames(OS, MemProfData.Frames);
uint64_t Header[] = {RecordTableOffset, FramePayloadOffset, FrameTableOffset};
- OS.patch({{HeaderUpdatePos, Header, std::size(Header)}});
+ OS.patch({{HeaderUpdatePos, Header}});
return Error::success();
}
@@ -697,7 +696,7 @@ static Error writeMemProfV2(ProfOStream &OS,
RecordTableOffset, FramePayloadOffset, FrameTableOffset,
CallStackPayloadOffset, CallStackTableOffset,
};
- OS.patch({{HeaderUpdatePos, Header, std::size(Header)}});
+ OS.patch({{HeaderUpdatePos, Header}});
return Error::success();
}
@@ -751,7 +750,7 @@ static Error writeMemProfV3(ProfOStream &OS,
RecordPayloadOffset,
RecordTableOffset,
};
- OS.patch({{HeaderUpdatePos, Header, std::size(Header)}});
+ OS.patch({{HeaderUpdatePos, Header}});
return Error::success();
}
@@ -989,12 +988,14 @@ Error InstrProfWriter::writeImpl(ProfOStream &OS) {
PatchItem PatchItems[] = {
// Patch the Header fields
- {BackPatchStartOffset, HeaderOffsets.data(), (int)HeaderOffsets.size()},
+ {BackPatchStartOffset, HeaderOffsets},
// Patch the summary data.
- {SummaryOffset, reinterpret_cast<uint64_t *>(TheSummary.get()),
- (int)(SummarySize / sizeof(uint64_t))},
- {CSSummaryOffset, reinterpret_cast<uint64_t *>(TheCSSummary.get()),
- (int)CSSummarySize}};
+ {SummaryOffset,
+ ArrayRef<uint64_t>(reinterpret_cast<uint64_t *>(TheSummary.get()),
+ SummarySize / sizeof(uint64_t))},
+ {CSSummaryOffset,
+ ArrayRef<uint64_t>(reinterpret_cast<uint64_t *>(TheCSSummary.get()),
+ CSSummarySize)}};
OS.patch(PatchItems);
More information about the llvm-commits
mailing list