diff options
| author | Easwaran Raman <eraman@google.com> | 2018-01-25 22:02:29 +0000 |
|---|---|---|
| committer | Easwaran Raman <eraman@google.com> | 2018-01-25 22:02:29 +0000 |
| commit | 8410c3746548f63c8471a34c696543fb51e22afb (patch) | |
| tree | 62e95f2e18042fc992d13c7fd72c5cd555b33605 /llvm/lib/Transforms/IPO | |
| parent | 0715092c65baa4005f8ec6bdd2a5f52ff8861da1 (diff) | |
| download | bcm5719-llvm-8410c3746548f63c8471a34c696543fb51e22afb.tar.gz bcm5719-llvm-8410c3746548f63c8471a34c696543fb51e22afb.zip | |
[SyntheticCounts] Rewrite the code using only graph traits.
Summary:
The intent of this is to allow the code to be used with ThinLTO. In
Thinlink phase, a traditional Callgraph can not be computed even though
all the necessary information (nodes and edges of a call graph) is
available. This is due to the fact that CallGraph class is closely tied
to the IR. This patch first extends GraphTraits to add a CallGraphTraits
graph. This is then used to implement a version of counts propagation
on a generic callgraph.
Reviewers: davidxl
Subscribers: mehdi_amini, tejohnson, llvm-commits
Differential Revision: https://reviews.llvm.org/D42311
llvm-svn: 323475
Diffstat (limited to 'llvm/lib/Transforms/IPO')
| -rw-r--r-- | llvm/lib/Transforms/IPO/SyntheticCountsPropagation.cpp | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/llvm/lib/Transforms/IPO/SyntheticCountsPropagation.cpp b/llvm/lib/Transforms/IPO/SyntheticCountsPropagation.cpp index f599adfe779..3c5ad37bced 100644 --- a/llvm/lib/Transforms/IPO/SyntheticCountsPropagation.cpp +++ b/llvm/lib/Transforms/IPO/SyntheticCountsPropagation.cpp @@ -102,23 +102,34 @@ PreservedAnalyses SyntheticCountsPropagation::run(Module &M, // Set initial entry counts. initializeCounts(M, [&](Function *F, uint64_t Count) { Counts[F] = Count; }); - // Compute the relative block frequency for a callsite. Use scaled numbers + // Compute the relative block frequency for a call edge. Use scaled numbers // and not integers since the relative block frequency could be less than 1. - auto GetCallSiteRelFreq = [&](CallSite CS) { + auto GetCallSiteRelFreq = [&](const CallGraphNode::CallRecord &Edge) { + Optional<Scaled64> Res = None; + if (!Edge.first) + return Res; + assert(isa<Instruction>(Edge.first)); + CallSite CS(cast<Instruction>(Edge.first)); Function *Caller = CS.getCaller(); auto &BFI = FAM.getResult<BlockFrequencyAnalysis>(*Caller); BasicBlock *CSBB = CS.getInstruction()->getParent(); Scaled64 EntryFreq(BFI.getEntryFreq(), 0); Scaled64 BBFreq(BFI.getBlockFreq(CSBB).getFrequency(), 0); BBFreq /= EntryFreq; - return BBFreq; + return Optional<Scaled64>(BBFreq); }; CallGraph CG(M); // Propgate the entry counts on the callgraph. - propagateSyntheticCounts( - CG, GetCallSiteRelFreq, [&](Function *F) { return Counts[F]; }, - [&](Function *F, uint64_t New) { Counts[F] += New; }); + SyntheticCountsUtils<const CallGraph *>::propagate( + &CG, GetCallSiteRelFreq, + [&](const CallGraphNode *N) { return Counts[N->getFunction()]; }, + [&](const CallGraphNode *N, uint64_t New) { + auto F = N->getFunction(); + if (!F || F->isDeclaration()) + return; + Counts[F] += New; + }); // Set the counts as metadata. for (auto Entry : Counts) |

