[llvm] 92ba979 - [llvm-profgen] Pass iteration value by reference in for-range loops to avoid unnecessary copies
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 14 06:51:42 PST 2022
Author: Simon Pilgrim
Date: 2022-01-14T14:49:57Z
New Revision: 92ba979c28357ec6db1ad4990d341bd862d38a9f
URL: https://github.com/llvm/llvm-project/commit/92ba979c28357ec6db1ad4990d341bd862d38a9f
DIFF: https://github.com/llvm/llvm-project/commit/92ba979c28357ec6db1ad4990d341bd862d38a9f.diff
LOG: [llvm-profgen] Pass iteration value by reference in for-range loops to avoid unnecessary copies
Added:
Modified:
llvm/tools/llvm-profgen/ProfileGenerator.cpp
Removed:
################################################################################
diff --git a/llvm/tools/llvm-profgen/ProfileGenerator.cpp b/llvm/tools/llvm-profgen/ProfileGenerator.cpp
index 4fd649df17b1..1248e37dc506 100644
--- a/llvm/tools/llvm-profgen/ProfileGenerator.cpp
+++ b/llvm/tools/llvm-profgen/ProfileGenerator.cpp
@@ -286,7 +286,7 @@ void ProfileGeneratorBase::findDisjointRanges(RangeSample &DisjointRanges,
*/
std::map<uint64_t, BoundaryPoint> Boundaries;
- for (auto Item : Ranges) {
+ for (const auto &Item : Ranges) {
assert(Item.first.first <= Item.first.second &&
"Invalid instruction range");
auto &BeginPoint = Boundaries[Item.first.first];
@@ -306,9 +306,9 @@ void ProfileGeneratorBase::findDisjointRanges(RangeSample &DisjointRanges,
uint64_t BeginAddress = UINT64_MAX;
int ZeroRangeDepth = 0;
uint64_t Count = 0;
- for (auto Item : Boundaries) {
+ for (const auto &Item : Boundaries) {
uint64_t Address = Item.first;
- BoundaryPoint &Point = Item.second;
+ const BoundaryPoint &Point = Item.second;
if (Point.BeginCount != UINT64_MAX) {
if (BeginAddress != UINT64_MAX)
DisjointRanges[{BeginAddress, Address - 1}] = Count;
@@ -466,7 +466,7 @@ ProfileGenerator::preprocessRangeCounter(const RangeSample &RangeCounter) {
// and initialize it with zero count, so it remains zero if doesn't hit any
// samples. This is to be consistent with compiler that interpret zero count
// as unexecuted(cold).
- for (auto I : RangeCounter) {
+ for (const auto &I : RangeCounter) {
uint64_t StartOffset = I.first.first;
for (const auto &Range : Binary->getRangesForOffset(StartOffset))
Ranges[{Range.first, Range.second - 1}] += 0;
@@ -479,7 +479,7 @@ ProfileGenerator::preprocessRangeCounter(const RangeSample &RangeCounter) {
void ProfileGenerator::populateBodySamplesForAllFunctions(
const RangeSample &RangeCounter) {
- for (auto Range : preprocessRangeCounter(RangeCounter)) {
+ for (const auto &Range : preprocessRangeCounter(RangeCounter)) {
uint64_t RangeBegin = Binary->offsetToVirtualAddr(Range.first.first);
uint64_t RangeEnd = Binary->offsetToVirtualAddr(Range.first.second);
uint64_t Count = Range.second;
@@ -523,7 +523,7 @@ StringRef ProfileGeneratorBase::getCalleeNameForOffset(uint64_t TargetOffset) {
void ProfileGenerator::populateBoundarySamplesForAllFunctions(
const BranchSample &BranchCounters) {
- for (auto Entry : BranchCounters) {
+ for (const auto &Entry : BranchCounters) {
uint64_t SourceOffset = Entry.first.first;
uint64_t TargetOffset = Entry.first.second;
uint64_t Count = Entry.second;
@@ -595,7 +595,7 @@ void CSProfileGenerator::computeSizeForProfiledFunctions() {
// Go through all the ranges in the CS counters, use the start of the range to
// look up the function it belongs and record the function range.
for (const auto &CI : SampleCounters) {
- for (auto Item : CI.second.RangeCounter) {
+ for (const auto &Item : CI.second.RangeCounter) {
// FIXME: Filter the bogus crossing function range.
uint64_t StartOffset = Item.first.first;
// Note that a function can be spilt into multiple ranges, so get all
@@ -605,7 +605,7 @@ void CSProfileGenerator::computeSizeForProfiledFunctions() {
}
}
- for (auto I : AggregatedRanges) {
+ for (const auto &I : AggregatedRanges) {
uint64_t StartOffset = I.first;
uint64_t EndOffset = I.second;
Binary->computeInlinedContextSizeForRange(StartOffset, EndOffset);
@@ -641,7 +641,7 @@ void CSProfileGenerator::populateBodySamplesForFunction(
// for calculating count for each location.
RangeSample Ranges;
findDisjointRanges(Ranges, RangeCounter);
- for (auto Range : Ranges) {
+ for (const auto &Range : Ranges) {
uint64_t RangeBegin = Binary->offsetToVirtualAddr(Range.first.first);
uint64_t RangeEnd = Binary->offsetToVirtualAddr(Range.first.second);
uint64_t Count = Range.second;
@@ -673,7 +673,7 @@ void CSProfileGenerator::populateBoundarySamplesForFunction(
SampleContextFrames ContextId, FunctionSamples &FunctionProfile,
const BranchSample &BranchCounters) {
- for (auto Entry : BranchCounters) {
+ for (const auto &Entry : BranchCounters) {
uint64_t SourceOffset = Entry.first.first;
uint64_t TargetOffset = Entry.first.second;
uint64_t Count = Entry.second;
@@ -876,7 +876,7 @@ void CSProfileGenerator::populateBodySamplesWithProbes(
std::unordered_map<MCDecodedPseudoProbeInlineTree *,
std::unordered_set<FunctionSamples *>>
FrameSamples;
- for (auto PI : ProbeCounter) {
+ for (const auto &PI : ProbeCounter) {
const MCDecodedPseudoProbe *Probe = PI.first;
uint64_t Count = PI.second;
FunctionSamples &FunctionProfile =
@@ -928,7 +928,7 @@ void CSProfileGenerator::populateBodySamplesWithProbes(
void CSProfileGenerator::populateBoundarySamplesWithProbes(
const BranchSample &BranchCounter, SampleContextFrames ContextStack) {
- for (auto BI : BranchCounter) {
+ for (const auto &BI : BranchCounter) {
uint64_t SourceOffset = BI.first.first;
uint64_t TargetOffset = BI.first.second;
uint64_t Count = BI.second;
More information about the llvm-commits
mailing list