aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/IPO/SampleProfile.cpp
diff options
context:
space:
mode:
authorDehao Chen <dehao@google.com>2016-04-20 23:36:23 +0000
committerDehao Chen <dehao@google.com>2016-04-20 23:36:23 +0000
commita8bae8237321a37f2412a00a46ea8d005b82809b (patch)
tree89b853fdab12eb05d64d5fe5f136cf95fb38d381 /llvm/lib/Transforms/IPO/SampleProfile.cpp
parent848334704d3853dbb5a9984e3b8bd670f3325066 (diff)
downloadllvm-a8bae8237321a37f2412a00a46ea8d005b82809b.zip
llvm-a8bae8237321a37f2412a00a46ea8d005b82809b.tar.gz
llvm-a8bae8237321a37f2412a00a46ea8d005b82809b.tar.bz2
Refine instruction weight annotation algorithm for sample profiler.
Summary: This patch refined the instruction weight anootation algorithm: 1. Do not use dbg_value intrinsics for annotation. 2. Annotate cold calls if the call is inlined in profile, but not inlined before preparation. This indicates that the annotation preparation step found no sample for the inlined callsite, thus the call should be very cold. Reviewers: dnovillo, davidxl Subscribers: mgrang, llvm-commits Differential Revision: http://reviews.llvm.org/D19286 llvm-svn: 266936
Diffstat (limited to 'llvm/lib/Transforms/IPO/SampleProfile.cpp')
-rw-r--r--llvm/lib/Transforms/IPO/SampleProfile.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/IPO/SampleProfile.cpp b/llvm/lib/Transforms/IPO/SampleProfile.cpp
index 6591020..fb9ea88 100644
--- a/llvm/lib/Transforms/IPO/SampleProfile.cpp
+++ b/llvm/lib/Transforms/IPO/SampleProfile.cpp
@@ -34,6 +34,7 @@
#include "llvm/IR/Dominators.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/InstIterator.h"
+#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/MDBuilder.h"
@@ -452,6 +453,11 @@ SampleProfileLoader::getInstWeight(const Instruction &Inst) const {
if (!FS)
return std::error_code();
+ // Ignore all dbg_value intrinsics.
+ const IntrinsicInst *II = dyn_cast<IntrinsicInst>(&Inst);
+ if (II && II->getIntrinsicID() == Intrinsic::dbg_value)
+ return std::error_code();
+
const DILocation *DIL = DLoc;
unsigned Lineno = DLoc.getLine();
unsigned HeaderLineno = DIL->getScope()->getSubprogram()->getLine();
@@ -475,6 +481,13 @@ SampleProfileLoader::getInstWeight(const Instruction &Inst) const {
<< Inst << " (line offset: " << Lineno - HeaderLineno << "."
<< DIL->getDiscriminator() << " - weight: " << R.get()
<< ")\n");
+ } else {
+ // If a call instruction is inlined in profile, but not inlined here,
+ // it means that the inlined callsite has no sample, thus the call
+ // instruction should have 0 count.
+ const CallInst *CI = dyn_cast<CallInst>(&Inst);
+ if (CI && findCalleeFunctionSamples(*CI))
+ R = 0;
}
return R;
}