-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[ProfileData] Use ArrayRef in PatchItem (NFC) #97379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ProfileData] Use ArrayRef in PatchItem (NFC) #97379
Conversation
Packaging an array and its size as ArrayRef in PatchItem allows us to get rid of things like std::size(Header) and HeaderOffsets.size().
@llvm/pr-subscribers-pgo Author: Kazu Hirata (kazutakahirata) ChangesPackaging an array and its size as ArrayRef in PatchItem allows us to Full diff: https://github.com/llvm/llvm-project/pull/97379.diff 1 Files Affected:
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);
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/159/builds/1307 Here is the relevant piece of the build log for the reference:
|
Packaging an array and its size as ArrayRef in PatchItem allows us to get rid of things like std::size(Header) and HeaderOffsets.size().
Packaging an array and its size as ArrayRef in PatchItem allows us to get rid of things like std::size(Header) and HeaderOffsets.size().
Packaging an array and its size as ArrayRef in PatchItem allows us to
get rid of things like std::size(Header) and HeaderOffsets.size().