summaryrefslogtreecommitdiffstats
path: root/llvm/lib/ProfileData
diff options
context:
space:
mode:
authorDiego Novillo <dnovillo@google.com>2015-10-15 16:36:21 +0000
committerDiego Novillo <dnovillo@google.com>2015-10-15 16:36:21 +0000
commit38be33302c443f7bca45cad26855fea535516436 (patch)
tree24ec2e74826a3fe8505cf7b58460646b08540d29 /llvm/lib/ProfileData
parent4f3589c779e342557fd28c8133b68f4d075b5d39 (diff)
downloadbcm5719-llvm-38be33302c443f7bca45cad26855fea535516436.tar.gz
bcm5719-llvm-38be33302c443f7bca45cad26855fea535516436.zip
Sample Profiles - Adjust integer types. Mostly NFC.
This adjusts all integers in the reader/writer to reflect the types stored on profile files. They should all be unsigned 32-bit or 64-bit values. Changed all associated internal types to be uint32_t or uint64_t. The only place that needed some adjustments is in the sample profile transformation. Altough the weight read from the profile are 64-bit values, the internal API for branch weights only accepts 32-bit values. The pass now saturates weights that overflow uint32_t. llvm-svn: 250427
Diffstat (limited to 'llvm/lib/ProfileData')
-rw-r--r--llvm/lib/ProfileData/SampleProfReader.cpp48
-rw-r--r--llvm/lib/ProfileData/SampleProfWriter.cpp2
2 files changed, 25 insertions, 25 deletions
diff --git a/llvm/lib/ProfileData/SampleProfReader.cpp b/llvm/lib/ProfileData/SampleProfReader.cpp
index 6149c6c3506..1ea7d2a0c4b 100644
--- a/llvm/lib/ProfileData/SampleProfReader.cpp
+++ b/llvm/lib/ProfileData/SampleProfReader.cpp
@@ -87,7 +87,7 @@ void SampleProfileReader::dump(raw_ostream &OS) {
///
/// \returns true if parsing is successful.
static bool ParseHead(const StringRef &Input, StringRef &FName,
- unsigned &NumSamples, unsigned &NumHeadSamples) {
+ uint64_t &NumSamples, uint64_t &NumHeadSamples) {
if (Input[0] == ' ')
return false;
size_t n2 = Input.rfind(':');
@@ -111,10 +111,10 @@ static bool ParseHead(const StringRef &Input, StringRef &FName,
/// \param TargetCountMap map from indirect call target to count.
///
/// returns true if parsing is successful.
-static bool ParseLine(const StringRef &Input, bool &IsCallsite, unsigned &Depth,
- unsigned &NumSamples, unsigned &LineOffset,
- unsigned &Discriminator, StringRef &CalleeName,
- DenseMap<StringRef, unsigned> &TargetCountMap) {
+static bool ParseLine(const StringRef &Input, bool &IsCallsite, uint32_t &Depth,
+ uint64_t &NumSamples, uint32_t &LineOffset,
+ uint32_t &Discriminator, StringRef &CalleeName,
+ DenseMap<StringRef, uint64_t> &TargetCountMap) {
for (Depth = 0; Input[Depth] == ' '; Depth++)
;
if (Depth == 0)
@@ -153,15 +153,15 @@ static bool ParseLine(const StringRef &Input, bool &IsCallsite, unsigned &Depth,
if (n3 != StringRef::npos) {
pair = Rest.substr(0, n3);
}
- int n4 = pair.find(':');
- unsigned count;
+ size_t n4 = pair.find(':');
+ uint64_t count;
if (pair.substr(n4 + 1).getAsInteger(10, count))
return false;
TargetCountMap[pair.substr(0, n4)] = count;
}
} else {
IsCallsite = true;
- int n3 = Rest.find_last_of(':');
+ size_t n3 = Rest.find_last_of(':');
CalleeName = Rest.substr(0, n3);
if (Rest.substr(n3 + 1).getAsInteger(10, NumSamples))
return false;
@@ -196,7 +196,7 @@ std::error_code SampleProfileReaderText::read() {
// The only requirement we place on the identifier, then, is that it
// should not begin with a number.
if ((*LineIt)[0] != ' ') {
- unsigned NumSamples, NumHeadSamples;
+ uint64_t NumSamples, NumHeadSamples;
StringRef FName;
if (!ParseHead(*LineIt, FName, NumSamples, NumHeadSamples)) {
reportError(LineIt.line_number(),
@@ -210,11 +210,11 @@ std::error_code SampleProfileReaderText::read() {
InlineStack.clear();
InlineStack.push_back(&FProfile);
} else {
- unsigned NumSamples;
+ uint64_t NumSamples;
StringRef FName;
- DenseMap<StringRef, unsigned> TargetCountMap;
+ DenseMap<StringRef, uint64_t> TargetCountMap;
bool IsCallsite;
- unsigned Depth, LineOffset, Discriminator;
+ uint32_t Depth, LineOffset, Discriminator;
if (!ParseLine(*LineIt, IsCallsite, Depth, NumSamples, LineOffset,
Discriminator, FName, TargetCountMap)) {
reportError(LineIt.line_number(),
@@ -283,7 +283,7 @@ ErrorOr<StringRef> SampleProfileReaderBinary::readString() {
ErrorOr<StringRef> SampleProfileReaderBinary::readStringFromTable() {
std::error_code EC;
- auto Idx = readNumber<unsigned>();
+ auto Idx = readNumber<uint32_t>();
if (std::error_code EC = Idx.getError())
return EC;
if (*Idx >= NameTable.size())
@@ -293,22 +293,22 @@ ErrorOr<StringRef> SampleProfileReaderBinary::readStringFromTable() {
std::error_code
SampleProfileReaderBinary::readProfile(FunctionSamples &FProfile) {
- auto Val = readNumber<unsigned>();
+ auto Val = readNumber<uint64_t>();
if (std::error_code EC = Val.getError())
return EC;
FProfile.addTotalSamples(*Val);
- Val = readNumber<unsigned>();
+ Val = readNumber<uint64_t>();
if (std::error_code EC = Val.getError())
return EC;
FProfile.addHeadSamples(*Val);
// Read the samples in the body.
- auto NumRecords = readNumber<unsigned>();
+ auto NumRecords = readNumber<uint32_t>();
if (std::error_code EC = NumRecords.getError())
return EC;
- for (unsigned I = 0; I < *NumRecords; ++I) {
+ for (uint32_t I = 0; I < *NumRecords; ++I) {
auto LineOffset = readNumber<uint64_t>();
if (std::error_code EC = LineOffset.getError())
return EC;
@@ -321,11 +321,11 @@ SampleProfileReaderBinary::readProfile(FunctionSamples &FProfile) {
if (std::error_code EC = NumSamples.getError())
return EC;
- auto NumCalls = readNumber<unsigned>();
+ auto NumCalls = readNumber<uint32_t>();
if (std::error_code EC = NumCalls.getError())
return EC;
- for (unsigned J = 0; J < *NumCalls; ++J) {
+ for (uint32_t J = 0; J < *NumCalls; ++J) {
auto CalledFunction(readStringFromTable());
if (std::error_code EC = CalledFunction.getError())
return EC;
@@ -342,11 +342,11 @@ SampleProfileReaderBinary::readProfile(FunctionSamples &FProfile) {
}
// Read all the samples for inlined function calls.
- auto NumCallsites = readNumber<unsigned>();
+ auto NumCallsites = readNumber<uint32_t>();
if (std::error_code EC = NumCallsites.getError())
return EC;
- for (unsigned J = 0; J < *NumCallsites; ++J) {
+ for (uint32_t J = 0; J < *NumCallsites; ++J) {
auto LineOffset = readNumber<uint64_t>();
if (std::error_code EC = LineOffset.getError())
return EC;
@@ -403,11 +403,11 @@ std::error_code SampleProfileReaderBinary::readHeader() {
return sampleprof_error::unsupported_version;
// Read the name table.
- auto Size = readNumber<size_t>();
+ auto Size = readNumber<uint32_t>();
if (std::error_code EC = Size.getError())
return EC;
NameTable.reserve(*Size);
- for (size_t I = 0; I < *Size; ++I) {
+ for (uint32_t I = 0; I < *Size; ++I) {
auto Name(readString());
if (std::error_code EC = Name.getError())
return EC;
@@ -678,7 +678,7 @@ setupMemoryBuffer(std::string Filename) {
auto Buffer = std::move(BufferOrErr.get());
// Sanity check the file.
- if (Buffer->getBufferSize() > std::numeric_limits<unsigned>::max())
+ if (Buffer->getBufferSize() > std::numeric_limits<uint32_t>::max())
return sampleprof_error::too_large;
return std::move(Buffer);
diff --git a/llvm/lib/ProfileData/SampleProfWriter.cpp b/llvm/lib/ProfileData/SampleProfWriter.cpp
index d3001aac3f6..daf3783aba6 100644
--- a/llvm/lib/ProfileData/SampleProfWriter.cpp
+++ b/llvm/lib/ProfileData/SampleProfWriter.cpp
@@ -144,7 +144,7 @@ std::error_code SampleProfileWriterBinary::write(StringRef FName,
encodeULEB128(Sample.getCallTargets().size(), OS);
for (const auto &J : Sample.getCallTargets()) {
StringRef Callee = J.first();
- unsigned CalleeSamples = J.second;
+ uint64_t CalleeSamples = J.second;
if (std::error_code EC = writeNameIdx(Callee))
return EC;
encodeULEB128(CalleeSamples, OS);
OpenPOWER on IntegriCloud