summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
diff options
context:
space:
mode:
authorPiotr Padlewski <piotr.padlewski@gmail.com>2016-08-30 00:46:26 +0000
committerPiotr Padlewski <piotr.padlewski@gmail.com>2016-08-30 00:46:26 +0000
commit442d38c0b4782c45499e142bb75fa16a202653ed (patch)
tree040c8e78ae650587a13ba3f844cbc3daf7b9a051 /llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
parent88c52e0f0a60dfbaf4a10067982b48881044bb1f (diff)
downloadbcm5719-llvm-442d38c0b4782c45499e142bb75fa16a202653ed.tar.gz
bcm5719-llvm-442d38c0b4782c45499e142bb75fa16a202653ed.zip
NFC: add early exit in ModuleSummaryAnalysis
Summary: Changed this code because it was not very readable. The one question that I got after changing it is, should we count calls to intrinsics? We don't add them to caller summary, so maybe we shouldn't also count them? Reviewers: tejohnson, eraman, mehdi_amini Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D23949 llvm-svn: 280036
Diffstat (limited to 'llvm/lib/Analysis/ModuleSummaryAnalysis.cpp')
-rw-r--r--llvm/lib/Analysis/ModuleSummaryAnalysis.cpp61
1 files changed, 32 insertions, 29 deletions
diff --git a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
index bf8381f303b..1a8872adeb8 100644
--- a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -81,37 +81,40 @@ static void computeFunctionSummary(ModuleSummaryIndex &Index, const Module &M,
SmallPtrSet<const User *, 8> Visited;
for (const BasicBlock &BB : F)
for (const Instruction &I : BB) {
- if (!isa<DbgInfoIntrinsic>(I))
- ++NumInsts;
+ if (isa<DbgInfoIntrinsic>(I))
+ continue;
+ ++NumInsts;
+ findRefEdges(&I, RefEdges, Visited);
+ auto CS = ImmutableCallSite(&I);
+ if (!CS)
+ continue;
+ auto *CalledFunction = CS.getCalledFunction();
+ // Check if this is a direct call to a known function.
+ if (CalledFunction) {
+ // Skip nameless and intrinsics.
+ if (!CalledFunction->hasName() || CalledFunction->isIntrinsic())
+ continue;
+ auto ScaledCount = BFI ? BFI->getBlockProfileCount(&BB) : None;
+ auto *CalleeId =
+ M.getValueSymbolTable().lookup(CalledFunction->getName());
+ CallGraphEdges[CalleeId] += (ScaledCount ? ScaledCount.getValue() : 0);
+ } else {
+ const auto *CI = dyn_cast<CallInst>(&I);
+ // Skip inline assembly calls.
+ if (CI && CI->isInlineAsm())
+ continue;
+ // Skip direct calls.
+ if (!CS.getCalledValue() || isa<Constant>(CS.getCalledValue()))
+ continue;
- if (auto CS = ImmutableCallSite(&I)) {
- auto *CalledFunction = CS.getCalledFunction();
- // Check if this is a direct call to a known function.
- if (CalledFunction) {
- if (CalledFunction->hasName() && !CalledFunction->isIntrinsic()) {
- auto ScaledCount = BFI ? BFI->getBlockProfileCount(&BB) : None;
- auto *CalleeId =
- M.getValueSymbolTable().lookup(CalledFunction->getName());
- CallGraphEdges[CalleeId] +=
- (ScaledCount ? ScaledCount.getValue() : 0);
- }
- } else {
- // Otherwise, check for an indirect call (call to a non-const value
- // that isn't an inline assembly call).
- const CallInst *CI = dyn_cast<CallInst>(&I);
- if (CS.getCalledValue() && !isa<Constant>(CS.getCalledValue()) &&
- !(CI && CI->isInlineAsm())) {
- uint32_t NumVals, NumCandidates;
- uint64_t TotalCount;
- auto CandidateProfileData =
- ICallAnalysis.getPromotionCandidatesForInstruction(
- &I, NumVals, TotalCount, NumCandidates);
- for (auto &Candidate : CandidateProfileData)
- IndirectCallEdges[Candidate.Value] += Candidate.Count;
- }
- }
+ uint32_t NumVals, NumCandidates;
+ uint64_t TotalCount;
+ auto CandidateProfileData =
+ ICallAnalysis.getPromotionCandidatesForInstruction(
+ &I, NumVals, TotalCount, NumCandidates);
+ for (auto &Candidate : CandidateProfileData)
+ IndirectCallEdges[Candidate.Value] += Candidate.Count;
}
- findRefEdges(&I, RefEdges, Visited);
}
GlobalValueSummary::GVFlags Flags(F);
OpenPOWER on IntegriCloud