Use LLVM's new ItaniumPartialDemangler in LLDB

Summary:
Replace the existing combination of FastDemangle and the fallback to llvm::itaniumDemangle() with LLVM's new ItaniumPartialDemangler. It slightly reduces complexity and slightly improves performance, but doesn't introduce conceptual changes. This patch is preparing for more fundamental improvements on LLDB's demangling approach.

Reviewers: friss, jingham, erik.pilkington, labath, clayborg, mgorny, davide, JDevlieghere

Reviewed By: JDevlieghere

Subscribers: teemperor, JDevlieghere, labath, clayborg, davide, lldb-commits, mgorny, erik.pilkington

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

llvm-svn: 337931
diff --git a/lldb/source/Core/Mangled.cpp b/lldb/source/Core/Mangled.cpp
index 3f64a3d..545ac51 100644
--- a/lldb/source/Core/Mangled.cpp
+++ b/lldb/source/Core/Mangled.cpp
@@ -16,34 +16,24 @@
 #pragma comment(lib, "dbghelp.lib")
 #endif
 
-#ifdef LLDB_USE_BUILTIN_DEMANGLER
-// Provide a fast-path demangler implemented in FastDemangle.cpp until it can
-// replace the existing C++ demangler with a complete implementation
-#include "lldb/Utility/FastDemangle.h"
-#include "llvm/Demangle/Demangle.h"
-#else
-// FreeBSD9-STABLE requires this to know about size_t in cxxabi.
-#include <cstddef>
-#include <cxxabi.h>
-#endif
-
 #include "lldb/Utility/ConstString.h"
 #include "lldb/Utility/Log.h"
 #include "lldb/Utility/Logging.h"
 #include "lldb/Utility/RegularExpression.h"
 #include "lldb/Utility/Stream.h"
 #include "lldb/Utility/Timer.h"
-#include "lldb/lldb-enumerations.h" // for LanguageType
+#include "lldb/lldb-enumerations.h"
 
 #include "Plugins/Language/CPlusPlus/CPlusPlusLanguage.h"
 #include "Plugins/Language/ObjC/ObjCLanguage.h"
 
-#include "llvm/ADT/StringRef.h"    // for StringRef
-#include "llvm/Support/Compiler.h" // for LLVM_PRETT...
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Demangle/Demangle.h"
+#include "llvm/Support/Compiler.h"
 
-#include <mutex>   // for mutex, loc...
-#include <string>  // for string
-#include <utility> // for pair
+#include <mutex>
+#include <string>
+#include <utility>
 
 #include <stdlib.h>
 #include <string.h>
@@ -295,18 +285,15 @@
         break;
       }
       case eManglingSchemeItanium: {
-#ifdef LLDB_USE_BUILTIN_DEMANGLER
-        if (log)
-          log->Printf("demangle itanium: %s", mangled_name);
-        // Try to use the fast-path demangler first for the performance win,
-        // falling back to the full demangler only when necessary
-        demangled_name = FastDemangle(mangled_name, m_mangled.GetLength());
-        if (!demangled_name)
-          demangled_name =
-              llvm::itaniumDemangle(mangled_name, NULL, NULL, NULL);
-#else
-        demangled_name = abi::__cxa_demangle(mangled_name, NULL, NULL, NULL);
-#endif
+        llvm::ItaniumPartialDemangler IPD;
+        bool demangle_err = IPD.partialDemangle(mangled_name);
+        if (!demangle_err) {
+          // Default buffer and size (realloc is used in case it's too small).
+          size_t demangled_size = 80;
+          demangled_name = static_cast<char *>(::malloc(demangled_size));
+          demangled_name = IPD.finishDemangle(demangled_name, &demangled_size);
+        }
+
         if (log) {
           if (demangled_name)
             log->Printf("demangled itanium: %s -> \"%s\"", mangled_name,