1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02:00
llvm-mirror/tools/llvm-xray
Roman Lebedev 2e1aaf1aa5 [XRay] Account: recursion detection
Summary:
Recursion detection can be non-trivial. Currently, the state-of-the-art for LLVM,
as far as i'm concerned, is D72362 `[clang-tidy] misc-no-recursion: a new check`.
However, it is quite limited:
* It does very basic call-graph based analysis, in the sense it will report even dynamically-unreachable recursion.
* It is inherently limited to a single TU
* It is hard to gauge how problematic each recursion is in practice.

Some of that can be addressed by adding clang analyzer-based check,
then it would at least support multiple TU's.

However, we can approach this problem from another angle - dynamic run-time analysis.
We already have means to capture a run-time callgraph (XRay, duh),
and there are already means to reconstruct it within `llvm-xray` tool.

This proposes to add a `-recursive-calls-only` switch to the `account` tool.
When the switch is on, when re-constructing callgraph for latency reconstruction,
each time we enter/leave some function, we increment/decrement an entry for the function
in a "recursion depth" map. If, when we leave the function, said entry was at `1`,
then that means the function didn't call itself, however if it is at `2` or more,
then that means the function (possibly indirectly) called itself.

If the depth is 1, we don't account the time spent there,
unless within this call stack the function already recursed into itself.
Note that we don't pay for recursion depth tracking when `recursive-calls-only` is not on,
and the perf impact is insignificant (+0.3% regression)

The overhead of the option is actually negative, around -5.26% user time on a medium-sized (3.5G) XRay log.
As a practical example, that 3.5G log is a capture of the entire middle-end opt pipeline
at `-O3` for RawSpeed unity build. There are total of `5500` functions in the log,
however `-recursive-calls-only` says that `269`, or 5%, are recursive.

Having this functionality could be helpful for recursion eradication.

Reviewers: dberris, mboerger

Reviewed By: dberris

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D84582
2020-07-27 10:15:44 +03:00
..
CMakeLists.txt Break false dependencies on target libraries 2019-05-23 23:02:56 +00:00
func-id-helper.cpp [llvm-objdump] Add warning messages if disassembly + source for problematic inputs 2019-08-15 05:15:22 +00:00
func-id-helper.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
llvm-xray.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
trie-node.h Use std::foo_t rather than std::foo in LLVM. 2020-02-11 15:12:51 -08:00
xray-account.cpp [XRay] Account: recursion detection 2020-07-27 10:15:44 +03:00
xray-account.h [XRay] Account: recursion detection 2020-07-27 10:15:44 +03:00
xray-color-helper.cpp Make llvm::StringRef to std::string conversions explicit. 2020-01-28 23:25:25 +01:00
xray-color-helper.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
xray-converter.cpp [xray] Remove cl::sub from alias options 2020-01-09 22:05:14 -08:00
xray-converter.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
xray-extract.cpp [XRay] Change Sled.Function to PC-relative for sled version 2 and make llvm-xray support sled version 2 addresses 2020-04-24 14:41:56 -07:00
xray-fdr-dump.cpp Switch LLVM to use 64-bit offsets (2/5) 2019-08-06 10:49:40 +00:00
xray-graph-diff.cpp Make llvm::StringRef to std::string conversions explicit. 2020-01-28 23:25:25 +01:00
xray-graph-diff.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
xray-graph.cpp [XRay] Sanitize DOT labels in graph output 2020-03-09 12:05:57 +00:00
xray-graph.h [xray] Remove usage of procid_t 2019-06-26 15:42:42 +00:00
xray-registry.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
xray-registry.h Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
xray-stacks.cpp Make llvm::StringRef to std::string conversions explicit. 2020-01-28 23:25:25 +01:00