[Lldb-commits] [lldb] b036f55 - [lldb] Remove some calls to GetASTContext

Raphael Isemann via lldb-commits lldb-commits at lists.llvm.org
Thu Dec 26 01:37:07 PST 2019


Author: Raphael Isemann
Date: 2019-12-26T10:36:36+01:00
New Revision: b036f557cee5b8eb87f0bffa7c305df6eda98437

URL: https://github.com/llvm/llvm-project/commit/b036f557cee5b8eb87f0bffa7c305df6eda98437
DIFF: https://github.com/llvm/llvm-project/commit/b036f557cee5b8eb87f0bffa7c305df6eda98437.diff

LOG: [lldb] Remove some calls to GetASTContext

GetASTContext is really expensive to call as it makes use of the global
mapping from ASTContext to ClangASTContext. This replaces all calls where
we already have the ClangASTContext around and don't need to call
GetASTContext again.

Added: 
    

Modified: 
    lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
    lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
    lldb/source/Symbol/ClangASTContext.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
index 60afa126ce90..ec1f3478df2a 100644
--- a/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
+++ b/lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionDeclMap.cpp
@@ -816,9 +816,8 @@ void ClangExpressionDeclMap::LookUpLldbClass(NameSearchContext &context,
 
     QualType class_qual_type(class_decl->getTypeForDecl(), 0);
 
-    TypeFromUser class_user_type(
-        class_qual_type.getAsOpaquePtr(),
-        ClangASTContext::GetASTContext(&class_decl->getASTContext()));
+    TypeFromUser class_user_type(class_qual_type.getAsOpaquePtr(),
+                                 function_decl_ctx.GetTypeSystem());
 
     LLDB_LOG(log, "  CEDM::FEVD[{0}] Adding type for $__lldb_class: {1}",
              current_id, class_qual_type.getAsString());
@@ -831,9 +830,8 @@ void ClangExpressionDeclMap::LookUpLldbClass(NameSearchContext &context,
       QualType class_pointer_type =
           method_decl->getASTContext().getPointerType(class_qual_type);
 
-      TypeFromUser self_user_type(
-          class_pointer_type.getAsOpaquePtr(),
-          ClangASTContext::GetASTContext(&method_decl->getASTContext()));
+      TypeFromUser self_user_type(class_pointer_type.getAsOpaquePtr(),
+                                  function_decl_ctx.GetTypeSystem());
 
       m_struct_vars->m_object_pointer_type = self_user_type;
     }
@@ -926,9 +924,8 @@ void ClangExpressionDeclMap::LookUpLldbObjCClass(NameSearchContext &context,
       return; // This is unlikely, but we have seen crashes where this
               // occurred
 
-    TypeFromUser class_user_type(
-        QualType(interface_type, 0).getAsOpaquePtr(),
-        ClangASTContext::GetASTContext(&method_decl->getASTContext()));
+    TypeFromUser class_user_type(QualType(interface_type, 0).getAsOpaquePtr(),
+                                 function_decl_ctx.GetTypeSystem());
 
     LLDB_LOG(log, "  FEVD[{0}] Adding type for $__lldb_objc_class: {1}",
              current_id, ClangUtil::ToString(interface_type));
@@ -942,18 +939,16 @@ void ClangExpressionDeclMap::LookUpLldbObjCClass(NameSearchContext &context,
           method_decl->getASTContext().getObjCObjectPointerType(
               QualType(interface_type, 0));
 
-      TypeFromUser self_user_type(
-          class_pointer_type.getAsOpaquePtr(),
-          ClangASTContext::GetASTContext(&method_decl->getASTContext()));
+      TypeFromUser self_user_type(class_pointer_type.getAsOpaquePtr(),
+                                  function_decl_ctx.GetTypeSystem());
 
       m_struct_vars->m_object_pointer_type = self_user_type;
     } else {
       // self is a Class pointer
       QualType class_type = method_decl->getASTContext().getObjCClassType();
 
-      TypeFromUser self_user_type(
-          class_type.getAsOpaquePtr(),
-          ClangASTContext::GetASTContext(&method_decl->getASTContext()));
+      TypeFromUser self_user_type(class_type.getAsOpaquePtr(),
+                                  function_decl_ctx.GetTypeSystem());
 
       m_struct_vars->m_object_pointer_type = self_user_type;
     }

diff  --git a/lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp b/lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
index f647abf7b5f0..6b2dbd9e1e5a 100644
--- a/lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
+++ b/lldb/source/Plugins/SymbolFile/PDB/PDBASTParser.cpp
@@ -118,31 +118,24 @@ GetBuiltinTypeForPDBEncodingAndBitSize(ClangASTContext &clang_ast,
     return clang_ast.GetBasicType(eBasicTypeBool);
   case PDB_BuiltinType::Long:
     if (width == ast.getTypeSize(ast.LongTy))
-      return CompilerType(ClangASTContext::GetASTContext(&ast),
-                          ast.LongTy.getAsOpaquePtr());
+      return CompilerType(&clang_ast, ast.LongTy.getAsOpaquePtr());
     if (width == ast.getTypeSize(ast.LongLongTy))
-      return CompilerType(ClangASTContext::GetASTContext(&ast),
-                          ast.LongLongTy.getAsOpaquePtr());
+      return CompilerType(&clang_ast, ast.LongLongTy.getAsOpaquePtr());
     break;
   case PDB_BuiltinType::ULong:
     if (width == ast.getTypeSize(ast.UnsignedLongTy))
-      return CompilerType(ClangASTContext::GetASTContext(&ast),
-                          ast.UnsignedLongTy.getAsOpaquePtr());
+      return CompilerType(&clang_ast, ast.UnsignedLongTy.getAsOpaquePtr());
     if (width == ast.getTypeSize(ast.UnsignedLongLongTy))
-      return CompilerType(ClangASTContext::GetASTContext(&ast),
-                          ast.UnsignedLongLongTy.getAsOpaquePtr());
+      return CompilerType(&clang_ast, ast.UnsignedLongLongTy.getAsOpaquePtr());
     break;
   case PDB_BuiltinType::WCharT:
     if (width == ast.getTypeSize(ast.WCharTy))
-      return CompilerType(ClangASTContext::GetASTContext(&ast),
-                          ast.WCharTy.getAsOpaquePtr());
+      return CompilerType(&clang_ast, ast.WCharTy.getAsOpaquePtr());
     break;
   case PDB_BuiltinType::Char16:
-    return CompilerType(ClangASTContext::GetASTContext(&ast),
-                        ast.Char16Ty.getAsOpaquePtr());
+    return CompilerType(&clang_ast, ast.Char16Ty.getAsOpaquePtr());
   case PDB_BuiltinType::Char32:
-    return CompilerType(ClangASTContext::GetASTContext(&ast),
-                        ast.Char32Ty.getAsOpaquePtr());
+    return CompilerType(&clang_ast, ast.Char32Ty.getAsOpaquePtr());
   case PDB_BuiltinType::Float:
     // Note: types `long double` and `double` have same bit size in MSVC and
     // there is no information in the PDB to distinguish them. So when falling

diff  --git a/lldb/source/Symbol/ClangASTContext.cpp b/lldb/source/Symbol/ClangASTContext.cpp
index dab210c15f4e..089d0177c8fc 100644
--- a/lldb/source/Symbol/ClangASTContext.cpp
+++ b/lldb/source/Symbol/ClangASTContext.cpp
@@ -902,7 +902,7 @@ CompilerType ClangASTContext::GetBasicType(lldb::BasicType basic_type) {
       GetOpaqueCompilerType(&ast, basic_type);
 
   if (clang_type)
-    return CompilerType(GetASTContext(&ast), clang_type);
+    return CompilerType(this, clang_type);
   return CompilerType();
 }
 
@@ -2736,9 +2736,7 @@ bool ClangASTContext::IsVectorType(lldb::opaque_compiler_type_t type,
 
 bool ClangASTContext::IsRuntimeGeneratedType(
     lldb::opaque_compiler_type_t type) {
-  clang::DeclContext *decl_ctx =
-      ClangASTContext::GetASTContext(&getASTContext())
-          ->GetDeclContextForType(GetQualType(type));
+  clang::DeclContext *decl_ctx = GetDeclContextForType(GetQualType(type));
   if (!decl_ctx)
     return false;
 
@@ -7757,9 +7755,8 @@ clang::ObjCMethodDecl *ClangASTContext::AddMethodToObjCObjectType(
       clang::SourceLocation(), // endLoc,
       method_selector, method_function_prototype->getReturnType(),
       nullptr, // TypeSourceInfo *ResultTInfo,
-      ClangASTContext::GetASTContext(&ast)->GetDeclContextForType(
-          ClangUtil::GetQualType(type)),
-      isInstance, isVariadic, isPropertyAccessor, isSynthesizedAccessorStub,
+      lldb_ast->GetDeclContextForType(ClangUtil::GetQualType(type)), isInstance,
+      isVariadic, isPropertyAccessor, isSynthesizedAccessorStub,
       isImplicitlyDeclared, isDefined, impControl, HasRelatedResultType);
 
   if (objc_method_decl == nullptr)


        


More information about the lldb-commits mailing list