summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Instrumentation
diff options
context:
space:
mode:
authorRong Xu <xur@google.com>2016-10-25 21:47:24 +0000
committerRong Xu <xur@google.com>2016-10-25 21:47:24 +0000
commit33308f92ebef0a0848997f912659c50ddf647383 (patch)
tree142670fd3c0522f394dd02b2a21fce001a94a85f /llvm/lib/Transforms/Instrumentation
parentfa2412b2e706d18c1afb7f70f34353baebb9c0ba (diff)
downloadbcm5719-llvm-33308f92ebef0a0848997f912659c50ddf647383.tar.gz
bcm5719-llvm-33308f92ebef0a0848997f912659c50ddf647383.zip
[PGO] Fix select instruction annotation
Summary: Select instruction annotation in IR PGO uses the edge count to infer the branch count. It's currently placed in setInstrumentedCounts() where no all the BB counts have been computed. This leads to wrong branch weights. Move the annotation after all BB counts are populated. Reviewers: davidxl Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D25961 llvm-svn: 285128
Diffstat (limited to 'llvm/lib/Transforms/Instrumentation')
-rw-r--r--llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp17
1 files changed, 13 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
index c2e42177661..833a8d8536f 100644
--- a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
+++ b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
@@ -642,7 +642,7 @@ public:
BranchProbabilityInfo *BPI = nullptr,
BlockFrequencyInfo *BFI = nullptr)
: F(Func), M(Modu), FuncInfo(Func, ComdatMembers, false, BPI, BFI),
- FreqAttr(FFA_Normal) {}
+ CountPosition(0), ProfileCountSize(0), FreqAttr(FFA_Normal) {}
// Read counts for the instrumented BB from profile.
bool readCounters(IndexedInstrProfReader *PGOReader);
@@ -682,6 +682,12 @@ private:
// compilation.
uint64_t ProgramMaxCount;
+ // Position of counter that remains to be read.
+ uint32_t CountPosition;
+
+ // Total size of the profile count for this function.
+ uint32_t ProfileCountSize;
+
// ProfileRecord for this function.
InstrProfRecord ProfileRecord;
@@ -750,9 +756,8 @@ void PGOUseFunc::setInstrumentedCounts(
NewEdge1.InMST = true;
getBBInfo(InstrBB).setBBInfoCount(CountValue);
}
- // Now annotate select instructions
- FuncInfo.SIVisitor.annotateSelects(F, this, &I);
- assert(I == CountFromProfile.size());
+ ProfileCountSize = CountFromProfile.size();
+ CountPosition = I;
}
// Set the count value for the unknown edge. There should be one and only one
@@ -892,6 +897,10 @@ void PGOUseFunc::populateCounters() {
FuncMaxCount = std::max(FuncMaxCount, getBBInfo(&BB).CountValue);
markFunctionAttributes(FuncEntryCount, FuncMaxCount);
+ // Now annotate select instructions
+ FuncInfo.SIVisitor.annotateSelects(F, this, &CountPosition);
+ assert(CountPosition == ProfileCountSize);
+
DEBUG(FuncInfo.dumpInfo("after reading profile."));
}
OpenPOWER on IntegriCloud