[llvm-profgen] Pass iteration value by reference in for-range loops to avoid unnecess...
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Fri, 14 Jan 2022 14:16:18 +0000 (14:16 +0000)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Fri, 14 Jan 2022 14:49:57 +0000 (14:49 +0000)
llvm/tools/llvm-profgen/ProfileGenerator.cpp

index 4fd649d..1248e37 100644 (file)
@@ -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;