llvm-project/lldb/source
Stefan Granitz f1a98df6ee Use rich mangling information in Symtab::InitNameIndexes()
Summary:
I set up a new review, because not all the code I touched was marked as a change in old one anymore.

In preparation for this review, there were two earlier ones:
* https://reviews.llvm.org/D49612 introduced the ItaniumPartialDemangler to LLDB demangling without conceptual changes
* https://reviews.llvm.org/D49909 added a unit test that covers all relevant code paths in the InitNameIndexes() function

Primary goals for this patch are:
(1) Use ItaniumPartialDemangler's rich mangling info for building LLDB's name index.
(2) Provide a uniform interface.
(3) Improve indexing performance.

The central implementation in this patch is our new function for explicit demangling:
```
const RichManglingInfo *
Mangled::DemangleWithRichManglingInfo(RichManglingContext &, SkipMangledNameFn *)
```

It takes a context object and a filter function and provides read-only access to the rich mangling info on success, or otherwise returns null. The two new classes are:
* `RichManglingInfo` offers a uniform interface to query symbol properties like `getFunctionDeclContextName()` or `isCtorOrDtor()` that are forwarded to the respective provider internally (`llvm::ItaniumPartialDemangler` or `lldb_private::CPlusPlusLanguage::MethodName`).
* `RichManglingContext` works a bit like `LLVMContext`, it the actual `RichManglingInfo` returned from `DemangleWithRichManglingInfo()` and handles lifetime and configuration. It is likely stack-allocated and can be reused for multiple queries during batch processing.

The idea here is that `DemangleWithRichManglingInfo()` acts like a gate keeper. It only provides access to `RichManglingInfo` on success, which in turn avoids the need to handle a `NoInfo` state in every single one of its getters. Having it stored within the context, avoids extra heap allocations and aids (3). As instantiations of the IPD the are considered expensive, the context is the ideal place to store it too. An efficient filtering function `SkipMangledNameFn` is another piece in the performance puzzle and it helps to mimic the original behavior of `InitNameIndexes`.

Future potential:
* `DemangleWithRichManglingInfo()` is thread-safe, IFF using different contexts in different threads. This may be exploited in the future. (It's another thing that it has in common with `LLVMContext`.)
* The old implementation only parsed and indexed Itanium mangled names. The new `RichManglingInfo` can be extended for various mangling schemes and languages.

One problem with the implementation of RichManglingInfo is the inaccessibility of class `CPlusPlusLanguage::MethodName` (defined in source/Plugins/Language/..), from within any header in the Core components of LLDB. The rather hacky solution is to store a type erased reference and cast it to the correct type on access in the cpp - see `RichManglingInfo::get<ParserT>()`. At the moment there seems to be no better way to do it. IMHO `CPlusPlusLanguage::MethodName` should be a top-level class in order to enable forward delcarations (but that is a rather big change I guess).

First simple profiling shows a good speedup. `target create clang` now takes 0.64s on average. Before the change I observed runtimes between 0.76s an 1.01s. This is still no bulletproof data (I only ran it on one machine!), but it's a promising indicator I think.

Reviewers: labath, jingham, JDevlieghere, erik.pilkington

Subscribers: zturner, clayborg, mgorny, lldb-commits

Differential Revision: https://reviews.llvm.org/D50071

llvm-svn: 339291
2018-08-08 21:57:37 +00:00
..
API Add new API to SBTarget class 2018-08-07 20:23:57 +00:00
Breakpoint If a function starts with line number 0, don't try to check if a breakpoint crossed function boundaries. 2018-08-07 21:09:55 +00:00
Commands Check result after setting PC value. 2018-08-07 16:46:11 +00:00
Core Use rich mangling information in Symtab::InitNameIndexes() 2018-08-08 21:57:37 +00:00
DataFormatters Reflow paragraphs in comments. 2018-04-30 16:49:04 +00:00
Expression [IRMemoryMap] Shrink Allocation and make it move-only (NFC) 2018-08-08 21:26:49 +00:00
Host Move RegisterValue,Scalar,State from Core to Utility 2018-08-07 11:07:21 +00:00
Initialization Move pretty stack trace printer into driver. 2018-07-17 10:04:19 +00:00
Interpreter Move RegisterValue,Scalar,State from Core to Utility 2018-08-07 11:07:21 +00:00
Plugins Removed doxygen comment that doesn't fit to function signature 2018-08-07 23:47:05 +00:00
Symbol Use rich mangling information in Symtab::InitNameIndexes() 2018-08-08 21:57:37 +00:00
Target [StackFrame] Add more clarifying comments to StackFrameList (NFC) 2018-08-07 23:48:25 +00:00
Utility Move RegisterValue,Scalar,State from Core to Utility 2018-08-07 11:07:21 +00:00
CMakeLists.txt Remove Plugins/Process/POSIX from include_directories 2017-04-11 12:26:25 +00:00
lldb.cpp Run clang-format on lldb.cpp 2017-11-02 16:56:52 +00:00