Author: sammccall
Date: Sat Dec 23 11:31:24 2017
New Revision: 321411

URL: http://llvm.org/viewvc/llvm-project?rev=321411&view=rev
Log:
[Index] Reduce size of SymbolInfo struct.

Summary:
This is currently 16 bytes, the patch reduces it to 4.
(Building with clang on linux x84, I guess others are similar)

The only subfield that might need a bigger type is SymbolPropertySet,
I've moved it to the end of the struct so if it grows, SymbolInfo will
only be 8 bytes.

With a full index of namespace-scope symbols from the LLVM project (200k)
loaded into clangd, this saves ~2MB of RAM.

Reviewers: akyrtzi

Subscribers: ilya-biryukov, cfe-commits

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

Modified:
    cfe/trunk/include/clang/Index/IndexSymbol.h
    cfe/trunk/lib/Index/IndexSymbol.cpp
    cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp

Modified: cfe/trunk/include/clang/Index/IndexSymbol.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Index/IndexSymbol.h?rev=321411&r1=321410&r2=321411&view=diff
==============================================================================
--- cfe/trunk/include/clang/Index/IndexSymbol.h (original)
+++ cfe/trunk/include/clang/Index/IndexSymbol.h Sat Dec 23 11:31:24 2017
@@ -56,7 +56,7 @@ enum class SymbolKind : uint8_t {
   Using,
 };
 
-enum class SymbolLanguage {
+enum class SymbolLanguage : uint8_t {
   C,
   ObjC,
   CXX,
@@ -64,7 +64,7 @@ enum class SymbolLanguage {
 };
 
 /// Language specific sub-kinds.
-enum class SymbolSubKind {
+enum class SymbolSubKind : uint8_t {
   None,
   CXXCopyConstructor,
   CXXMoveConstructor,
@@ -74,8 +74,9 @@ enum class SymbolSubKind {
   UsingValue,
 };
 
+typedef uint8_t SymbolPropertySet;
 /// Set of properties that provide additional info about a symbol.
-enum class SymbolProperty : uint8_t {
+enum class SymbolProperty : SymbolPropertySet {
   Generic                       = 1 << 0,
   TemplatePartialSpecialization = 1 << 1,
   TemplateSpecialization        = 1 << 2,
@@ -86,7 +87,6 @@ enum class SymbolProperty : uint8_t {
   Local                         = 1 << 7,
 };
 static const unsigned SymbolPropertyBitNum = 8;
-typedef unsigned SymbolPropertySet;
 
 /// Set of roles that are attributed to symbol occurrences.
 enum class SymbolRole : uint32_t {
@@ -127,8 +127,8 @@ struct SymbolRelation {
 struct SymbolInfo {
   SymbolKind Kind;
   SymbolSubKind SubKind;
-  SymbolPropertySet Properties;
   SymbolLanguage Lang;
+  SymbolPropertySet Properties;
 };
 
 SymbolInfo getSymbolInfo(const Decl *D);

Modified: cfe/trunk/lib/Index/IndexSymbol.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexSymbol.cpp?rev=321411&r1=321410&r2=321411&view=diff
==============================================================================
--- cfe/trunk/lib/Index/IndexSymbol.cpp (original)
+++ cfe/trunk/lib/Index/IndexSymbol.cpp Sat Dec 23 11:31:24 2017
@@ -42,10 +42,10 @@ static bool isUnitTest(const ObjCMethodD
 
 static void checkForIBOutlets(const Decl *D, SymbolPropertySet &PropSet) {
   if (D->hasAttr<IBOutletAttr>()) {
-    PropSet |= (unsigned)SymbolProperty::IBAnnotated;
+    PropSet |= (SymbolPropertySet)SymbolProperty::IBAnnotated;
   } else if (D->hasAttr<IBOutletCollectionAttr>()) {
-    PropSet |= (unsigned)SymbolProperty::IBAnnotated;
-    PropSet |= (unsigned)SymbolProperty::IBOutletCollection;
+    PropSet |= (SymbolPropertySet)SymbolProperty::IBAnnotated;
+    PropSet |= (SymbolPropertySet)SymbolProperty::IBOutletCollection;
   }
 }
 
@@ -93,7 +93,7 @@ SymbolInfo index::getSymbolInfo(const De
   Info.Lang = SymbolLanguage::C;
 
   if (isFunctionLocalSymbol(D)) {
-    Info.Properties |= (unsigned)SymbolProperty::Local;
+    Info.Properties |= (SymbolPropertySet)SymbolProperty::Local;
   }
 
   if (const TagDecl *TD = dyn_cast<TagDecl>(D)) {
@@ -118,17 +118,19 @@ SymbolInfo index::getSymbolInfo(const De
       if (!CXXRec->isCLike()) {
         Info.Lang = SymbolLanguage::CXX;
         if (CXXRec->getDescribedClassTemplate()) {
-          Info.Properties |= (unsigned)SymbolProperty::Generic;
+          Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic;
         }
       }
     }
 
     if (isa<ClassTemplatePartialSpecializationDecl>(D)) {
-      Info.Properties |= (unsigned)SymbolProperty::Generic;
-      Info.Properties |= 
(unsigned)SymbolProperty::TemplatePartialSpecialization;
+      Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic;
+      Info.Properties |=
+          (SymbolPropertySet)SymbolProperty::TemplatePartialSpecialization;
     } else if (isa<ClassTemplateSpecializationDecl>(D)) {
-      Info.Properties |= (unsigned)SymbolProperty::Generic;
-      Info.Properties |= (unsigned)SymbolProperty::TemplateSpecialization;
+      Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic;
+      Info.Properties |=
+          (SymbolPropertySet)SymbolProperty::TemplateSpecialization;
     }
 
   } else if (auto *VD = dyn_cast<VarDecl>(D)) {
@@ -142,15 +144,17 @@ SymbolInfo index::getSymbolInfo(const De
 
     if (isa<VarTemplatePartialSpecializationDecl>(D)) {
       Info.Lang = SymbolLanguage::CXX;
-      Info.Properties |= (unsigned)SymbolProperty::Generic;
-      Info.Properties |= 
(unsigned)SymbolProperty::TemplatePartialSpecialization;
+      Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic;
+      Info.Properties |=
+          (SymbolPropertySet)SymbolProperty::TemplatePartialSpecialization;
     } else if (isa<VarTemplateSpecializationDecl>(D)) {
       Info.Lang = SymbolLanguage::CXX;
-      Info.Properties |= (unsigned)SymbolProperty::Generic;
-      Info.Properties |= (unsigned)SymbolProperty::TemplateSpecialization;
+      Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic;
+      Info.Properties |=
+          (SymbolPropertySet)SymbolProperty::TemplateSpecialization;
     } else if (VD->getDescribedVarTemplate()) {
       Info.Lang = SymbolLanguage::CXX;
-      Info.Properties |= (unsigned)SymbolProperty::Generic;
+      Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic;
     }
 
   } else {
@@ -181,7 +185,7 @@ SymbolInfo index::getSymbolInfo(const De
       if (!ClsD)
         ClsD = cast<ObjCImplementationDecl>(D)->getClassInterface();
       if (isUnitTestCase(ClsD))
-        Info.Properties |= (unsigned)SymbolProperty::UnitTest;
+        Info.Properties |= (SymbolPropertySet)SymbolProperty::UnitTest;
       break;
     }
     case Decl::ObjCProtocol:
@@ -198,7 +202,7 @@ SymbolInfo index::getSymbolInfo(const De
       else
         ClsD = cast<ObjCCategoryImplDecl>(D)->getClassInterface();
       if (isUnitTestCase(ClsD))
-        Info.Properties |= (unsigned)SymbolProperty::UnitTest;
+        Info.Properties |= (SymbolPropertySet)SymbolProperty::UnitTest;
       break;
     }
     case Decl::ObjCMethod: {
@@ -212,9 +216,9 @@ SymbolInfo index::getSymbolInfo(const De
       }
       Info.Lang = SymbolLanguage::ObjC;
       if (isUnitTest(MD))
-        Info.Properties |= (unsigned)SymbolProperty::UnitTest;
+        Info.Properties |= (SymbolPropertySet)SymbolProperty::UnitTest;
       if (D->hasAttr<IBActionAttr>())
-        Info.Properties |= (unsigned)SymbolProperty::IBAnnotated;
+        Info.Properties |= (SymbolPropertySet)SymbolProperty::IBAnnotated;
       break;
     }
     case Decl::ObjCProperty:
@@ -223,7 +227,7 @@ SymbolInfo index::getSymbolInfo(const De
       checkForIBOutlets(D, Info.Properties);
       if (auto *Annot = D->getAttr<AnnotateAttr>()) {
         if (Annot->getAnnotation() == "gk_inspectable")
-          Info.Properties |= (unsigned)SymbolProperty::GKInspectable;
+          Info.Properties |= (SymbolPropertySet)SymbolProperty::GKInspectable;
       }
       break;
     case Decl::ObjCIvar:
@@ -268,12 +272,12 @@ SymbolInfo index::getSymbolInfo(const De
     }
     case Decl::ClassTemplate:
       Info.Kind = SymbolKind::Class;
-      Info.Properties |= (unsigned)SymbolProperty::Generic;
+      Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic;
       Info.Lang = SymbolLanguage::CXX;
       break;
     case Decl::FunctionTemplate:
       Info.Kind = SymbolKind::Function;
-      Info.Properties |= (unsigned)SymbolProperty::Generic;
+      Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic;
       Info.Lang = SymbolLanguage::CXX;
       if (const CXXMethodDecl *MD = dyn_cast_or_null<CXXMethodDecl>(
                            cast<FunctionTemplateDecl>(D)->getTemplatedDecl())) 
{
@@ -294,7 +298,7 @@ SymbolInfo index::getSymbolInfo(const De
     case Decl::TypeAliasTemplate:
       Info.Kind = SymbolKind::TypeAlias;
       Info.Lang = SymbolLanguage::CXX;
-      Info.Properties |= (unsigned)SymbolProperty::Generic;
+      Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic;
       break;
     case Decl::TypeAlias:
       Info.Kind = SymbolKind::TypeAlias;
@@ -304,13 +308,13 @@ SymbolInfo index::getSymbolInfo(const De
       Info.Kind = SymbolKind::Using;
       Info.SubKind = SymbolSubKind::UsingTypename;
       Info.Lang = SymbolLanguage::CXX;
-      Info.Properties |= (unsigned)SymbolProperty::Generic;
+      Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic;
       break;
     case Decl::UnresolvedUsingValue:
       Info.Kind = SymbolKind::Using;
       Info.SubKind = SymbolSubKind::UsingValue;
       Info.Lang = SymbolLanguage::CXX;
-      Info.Properties |= (unsigned)SymbolProperty::Generic;
+      Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic;
       break;
     case Decl::Binding:
       Info.Kind = SymbolKind::Variable;
@@ -327,12 +331,13 @@ SymbolInfo index::getSymbolInfo(const De
   if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
     if (FD->getTemplatedKind() ==
           FunctionDecl::TK_FunctionTemplateSpecialization) {
-      Info.Properties |= (unsigned)SymbolProperty::Generic;
-      Info.Properties |= (unsigned)SymbolProperty::TemplateSpecialization;
+      Info.Properties |= (SymbolPropertySet)SymbolProperty::Generic;
+      Info.Properties |=
+          (SymbolPropertySet)SymbolProperty::TemplateSpecialization;
     }
   }
 
-  if (Info.Properties & (unsigned)SymbolProperty::Generic)
+  if (Info.Properties & (SymbolPropertySet)SymbolProperty::Generic)
     Info.Lang = SymbolLanguage::CXX;
 
   if (auto *attr = D->getExternalSourceSymbolAttr()) {
@@ -490,9 +495,9 @@ StringRef index::getSymbolLanguageString
 
 void index::applyForEachSymbolProperty(SymbolPropertySet Props,
                                   llvm::function_ref<void(SymbolProperty)> Fn) 
{
-#define APPLY_FOR_PROPERTY(K) \
-  if (Props & (unsigned)SymbolProperty::K) \
-    Fn(SymbolProperty::K)
+#define APPLY_FOR_PROPERTY(K)                                                  
\
+  if (Props & (SymbolPropertySet)SymbolProperty::K)                            
\
+  Fn(SymbolProperty::K)
 
   APPLY_FOR_PROPERTY(Generic);
   APPLY_FOR_PROPERTY(TemplatePartialSpecialization);

Modified: cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp?rev=321411&r1=321410&r2=321411&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp (original)
+++ cfe/trunk/tools/libclang/CXIndexDataConsumer.cpp Sat Dec 23 11:31:24 2017
@@ -1304,11 +1304,11 @@ static CXIdxEntityKind getEntityKindFrom
 
 static CXIdxEntityCXXTemplateKind
 getEntityKindFromSymbolProperties(SymbolPropertySet K) {
-  if (K & (unsigned)SymbolProperty::TemplatePartialSpecialization)
+  if (K & (SymbolPropertySet)SymbolProperty::TemplatePartialSpecialization)
     return CXIdxEntity_TemplatePartialSpecialization;
-  if (K & (unsigned)SymbolProperty::TemplateSpecialization)
+  if (K & (SymbolPropertySet)SymbolProperty::TemplateSpecialization)
     return CXIdxEntity_TemplateSpecialization;
-  if (K & (unsigned)SymbolProperty::Generic)
+  if (K & (SymbolPropertySet)SymbolProperty::Generic)
     return CXIdxEntity_Template;
   return CXIdxEntity_NonTemplate;
 }


_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to