This patch is the third in the sequence of three patches related to the following diff (https://reviews.llvm.org/D73142). The first patch from the sequence that has introduced the structure for DOTFunction Information is found here - D76820. The second patch introduced similar functionality to the CFG - (D77161). This patch introduces the heat coloring of the CallPrinter which is based on the relative "hotness" of each function. All the functionality of this patch was developed and discussed in the preceding patches.
Details
Diff Detail
Event Timeline
Can you also provide the test_for_loop.ll (perhaps as a test case?) which correspond to the pdf file attached to the original patch?
llvm/lib/Analysis/CallPrinter.cpp | ||
---|---|---|
38 | callgraph-multigraph to be consistent with other option names | |
42 | to be consistent with naming convention in PGO, perhaps use 'callgraph-entry-count' |
Answering @davidxl 's comments:
- Renamed flags
Attaching the file test_heat.ll for which the .pdf from the original patch was created:
Where do you want me to put it?
Looked at the example .ll file for good_callgraph.pdf -- they don't seem to match. There is no callgraph edge from bar1 to bar2, but the pdf file shows there is one. Similarly for other edges between bar* functions.
- Changed the flag in the test
Indeed, sorry, wrong .ll test.
This one should be the one:
The call edges now look correct, but the resulting hotness does not look right. The caller 'foo' is marked as hot with red color, but hot callees like 'bar1' etc in the loop are not (Note that the branches in the loop are not highly biased).
- Fixed the functionality of heat coloring - now the coloring of CallGraph is done by analyzing how many times the given function was called. The more times it's being called - the hotter ("redder") it will be on the graph.
This Callgraph was generated from test_heat.ll
You can see, as foo is not being called by anyone, it is marked as the coldest block. Bar functions are ranked from the least number to the greatest by their hotness which makes sense - whenever function bar1 is called, it is calling all of the other bars that follow and so on. Thus, bar5 is the hottest function in the .ll file
thanks. The example graph looks great. Will take a look at the patch in details soon.
llvm/include/llvm/Analysis/HeatUtils.h | ||
---|---|---|
34 | Use CallBase instead of CallSite | |
llvm/lib/Analysis/CallPrinter.cpp | ||
34 | ShowEdgeWeight and callgraph-show-weights ? | |
71 | This is O(N^2) to the number of functions. For a C++ module, this can be quite large. | |
76 | why max but not sum? | |
113 | can directly use insert method and check its return value | |
217 | what is this check for? | |
llvm/lib/Analysis/HeatUtils.cpp | ||
46 | As I mentioned in one of the previous reviews, the blockfrequency is relative to the parent function (because of the final scaling step used in computing the integer frequency value which depends on the min and max value) and it will be meaningless to compare block frequency of callsites in different functions. | |
57 | where does the '5' come from? |
Addressed @davidxl 's comments:
- Added comments
- Brought for-loop iteration over functions in the module into the previous one
llvm/lib/Analysis/CallPrinter.cpp | ||
---|---|---|
80 | Is this loop needed? Can you just check the *iter, *F pair? -- the enclosing loop should cover all caller,callee pairs in the module. |
I have noticed that MaxEdgeCount is essentially count the same thing as MaxFreq, so I replaced its uses in all the cases.
Use CallBase instead of CallSite