[Lldb-commits] [PATCH] D102624: [lldb] Optimize expressions

Raphael Isemann via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon May 17 07:15:26 PDT 2021

teemperor created this revision.
teemperor added a reviewer: LLDB.
teemperor added a project: LLDB.
Herald added a subscriber: JDevlieghere.
teemperor requested review of this revision.

At the moment we codegen or interpret the IR in exactly the way as it is generated by Clang.
This patch runs the default O2 <https://reviews.llvm.org/owners/package/2/> optimizations over the generated LLVM module before we
interpret or JIT it.

The motivation for this patch is twofold. First, LLDB contains an LLVM IR interpreter that
supports a very limited subset of LLVM instructions for the sake of maintainability. The
IR interpreter is intended as a fast first path to run the code provided by the user (fast in
comparison to JITing and injecting the code). It also is the only way LLDB can evaluate
expressions for targets where we cant JIT&inject code. Because the LLVM IR interpreter
only supports a limited set of instructions, most non-trivial Clang expression can't be
interpreted which is really limiting the expression evaluator functionality when we can't
JIT code. By running running the default -O2 passes over the IR before interpreting it,
LLVM will give us usually a much more concise IR that the IR interpreter can more often
than not handle.

Second, sometimes users want to run expressions that are simple but might process quite
a bit of data. An example for that would be any algorithm that users can now invoke via
the `std` C++ module. Calling `std::count_if` with a relatively simple predicate on a large
vector currently takes far too long to be considered usable.

To give some stats on the first claim:

- Currently we run about 7700 expressions in a test suit run (the actual number of expressions is fluctuating a bit....)
- Around 5800 of these expressions are simple enough that the IR interpreter can interpret them right now (most of them just print simple variables)
- This leaves us with around 1900 expressions that we currently can't interpret in the test suite.
- After applying this patch the number of expressions we can't interpret drops to around 1300 (**-33%**).
- The average expression evaluation time when running on my local machine doesn't change with this patch (around 50ms before and after).



-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102624.345860.patch
Type: text/x-patch
Size: 14611 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20210517/fb1d6e95/attachment-0001.bin>

More information about the lldb-commits mailing list