aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorRong Xu <xur@google.com>2016-01-19 18:29:54 +0000
committerRong Xu <xur@google.com>2016-01-19 18:29:54 +0000
commit294572f11699c4e8f5fca7f11c64540afa04c93d (patch)
treedb2d5f6e56b712230812e73bf867d494c74da1dd /llvm/lib/Transforms
parent1ec08ac7e46ce5f4aae562cb9f8b3173d650b597 (diff)
downloadllvm-294572f11699c4e8f5fca7f11c64540afa04c93d.zip
llvm-294572f11699c4e8f5fca7f11c64540afa04c93d.tar.gz
llvm-294572f11699c4e8f5fca7f11c64540afa04c93d.tar.bz2
[PGO] Create the profile data variable before the lowering
This patch creates the profile data variable before lowering the profile intrinsics. Reviewers: davidxl, silvas Differential Revision: http://reviews.llvm.org/D16015 llvm-svn: 258156
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
index 28483e7..8041816 100644
--- a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
+++ b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
@@ -137,11 +137,20 @@ bool InstrProfiling::runOnModule(Module &M) {
// We did not know how many value sites there would be inside
// the instrumented function. This is counting the number of instrumented
// target value sites to enter it as field in the profile data variable.
- for (Function &F : M)
+ for (Function &F : M) {
+ InstrProfIncrementInst *FirstProfIncInst = nullptr;
for (BasicBlock &BB : F)
- for (auto I = BB.begin(), E = BB.end(); I != E;)
- if (auto *Ind = dyn_cast<InstrProfValueProfileInst>(I++))
+ for (auto I = BB.begin(), E = BB.end(); I != E; I++)
+ if (auto *Ind = dyn_cast<InstrProfValueProfileInst>(I))
computeNumValueSiteCounts(Ind);
+ else if (FirstProfIncInst == nullptr)
+ FirstProfIncInst = dyn_cast<InstrProfIncrementInst>(I);
+
+ // Value profiling intrinsic lowering requires per-function profile data
+ // variable to be created first.
+ if (FirstProfIncInst != nullptr)
+ static_cast<void>(getOrCreateRegionCounters(FirstProfIncInst));
+ }
for (Function &F : M)
for (BasicBlock &BB : F)