Skip to content

Commit 41a0247

Browse files
resolve comments
1 parent 7fba316 commit 41a0247

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

llvm/include/llvm/ProfileData/SampleProfReader.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,10 @@ class SampleProfileReader {
589589
/// Whether the function profiles use FS discriminators.
590590
bool ProfileIsFS = false;
591591

592+
/// If true, the profile has vtable profiles and reader should decode them
593+
/// to parse profiles correctly.
594+
bool ReadVTableProf = false;
595+
592596
/// \brief The format of sample.
593597
SampleProfileFormat Format = SPF_None;
594598

@@ -735,10 +739,6 @@ class LLVM_ABI SampleProfileReaderBinary : public SampleProfileReader {
735739
/// to the start of MD5SampleContextTable.
736740
const uint64_t *MD5SampleContextStart = nullptr;
737741

738-
/// If true, the profile has vtable profiles and reader should decode them
739-
/// to parse profiles correctly.
740-
bool ReadVTableProf = false;
741-
742742
private:
743743
std::error_code readSummaryEntry(std::vector<ProfileSummaryEntry> &Entries);
744744
virtual std::error_code verifySPMagic(uint64_t Magic) = 0;

llvm/lib/ProfileData/SampleProf.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ sampleprof_error SampleRecord::merge(const SampleRecord &Other,
144144
for (const auto &I : Other.getCallTargets()) {
145145
mergeSampleProfErrors(Result, addCalledTarget(I.first, I.second, Weight));
146146
}
147-
148147
return Result;
149148
}
150149

llvm/lib/ProfileData/SampleProfReader.cpp

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -205,20 +205,25 @@ enum class LineType {
205205
static bool parseTypeCountMap(StringRef Input,
206206
DenseMap<StringRef, uint64_t> &TypeCountMap) {
207207
for (size_t Index = Input.find_first_not_of(' '); Index != StringRef::npos;) {
208-
size_t n1 = Input.find(':', Index);
209-
if (n1 == StringRef::npos)
208+
size_t ColonIndex = Input.find(':', Index);
209+
if (ColonIndex == StringRef::npos)
210210
return false; // No colon found, invalid format.
211-
StringRef TypeName = Input.substr(Index, n1 - Index);
212-
// n2 is the start index of count.
213-
size_t n2 = n1 + 1;
214-
// n3 is the start index after the 'target:count' pair.
215-
size_t n3 = Input.find_first_of(' ', n2);
211+
StringRef TypeName = Input.substr(Index, ColonIndex - Index);
212+
// CountIndex is the start index of count.
213+
size_t CountStartIndex = ColonIndex + 1;
214+
// NextIndex is the start index after the 'target:count' pair.
215+
size_t NextIndex = Input.find_first_of(' ', CountStartIndex);
216216
uint64_t Count;
217-
if (Input.substr(n2, n3 - n2).getAsInteger(10, Count))
217+
if (Input.substr(CountStartIndex, NextIndex - CountStartIndex)
218+
.getAsInteger(10, Count))
218219
return false; // Invalid count.
219-
TypeCountMap[TypeName] = Count;
220-
Index = (n3 == StringRef::npos) ? StringRef::npos
221-
: Input.find_first_not_of(' ', n3);
220+
// Error on duplicated type names in one line of input.
221+
auto [Iter, Inserted] = TypeCountMap.insert({TypeName, Count});
222+
if (!Inserted)
223+
return false;
224+
Index = (NextIndex == StringRef::npos)
225+
? StringRef::npos
226+
: Input.find_first_not_of(' ', NextIndex);
222227
}
223228
return true;
224229
}
@@ -409,6 +414,8 @@ std::error_code SampleProfileReaderText::readImpl() {
409414
uint64_t FunctionHash = 0;
410415
uint32_t Attributes = 0;
411416
bool IsFlat = false;
417+
// TODO: Update ParseLine to return an error code instead of a bool and
418+
// report it.
412419
if (!ParseLine(*LineIt, LineTy, Depth, NumSamples, LineOffset,
413420
Discriminator, FName, TargetCountMap, TypeCountMap,
414421
FunctionHash, Attributes, IsFlat)) {

0 commit comments

Comments
 (0)