[llvm] r266241 - [DebugInfo] Optimize memory layout of DISubprogram.

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 13 13:17:43 PDT 2016


Author: davide
Date: Wed Apr 13 15:17:42 2016
New Revision: 266241

URL: http://llvm.org/viewvc/llvm-project?rev=266241&view=rev
Log:
[DebugInfo] Optimize memory layout of DISubprogram.

A DISubprogram on x86_64 was 48 bytes. During an LTO build we
end up allocating *a lot* of these (see Duncan's numbers on
llvm-dev and/or my numbers in the review link).
This change reduces the size to 40 bytes, with a nice effect
on peak memory usage when LTO'ing clang.
There are more classes in the hierarchy which can be compacted
so more patches will come. DISubprogram was the biggest offender
in my profiling, anyway.

Differential Revision:  http://reviews.llvm.org/D18918

Modified:
    llvm/trunk/include/llvm/IR/DebugInfoMetadata.h
    llvm/trunk/unittests/IR/MetadataTest.cpp

Modified: llvm/trunk/include/llvm/IR/DebugInfoMetadata.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/DebugInfoMetadata.h?rev=266241&r1=266240&r2=266241&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/DebugInfoMetadata.h (original)
+++ llvm/trunk/include/llvm/IR/DebugInfoMetadata.h Wed Apr 13 15:17:42 2016
@@ -1229,12 +1229,21 @@ class DISubprogram : public DILocalScope
 
   unsigned Line;
   unsigned ScopeLine;
-  unsigned Virtuality;
   unsigned VirtualIndex;
-  unsigned Flags;
-  bool IsLocalToUnit;
-  bool IsDefinition;
-  bool IsOptimized;
+
+  // Virtuality can only assume three values, so we can pack
+  // in 2 bits (none/pure/pure_virtual).
+  unsigned Virtuality : 2;
+
+  unsigned Flags : 27;
+
+  // These are boolean flags so one bit is enough.
+  // MSVC starts a new container field every time the base
+  // type changes so we can't use 'bool' to ensure these bits
+  // are packed.
+  unsigned IsLocalToUnit : 1;
+  unsigned IsDefinition : 1;
+  unsigned IsOptimized : 1;
 
   DISubprogram(LLVMContext &C, StorageType Storage, unsigned Line,
                unsigned ScopeLine, unsigned Virtuality, unsigned VirtualIndex,
@@ -1242,9 +1251,13 @@ class DISubprogram : public DILocalScope
                bool IsOptimized, ArrayRef<Metadata *> Ops)
       : DILocalScope(C, DISubprogramKind, Storage, dwarf::DW_TAG_subprogram,
                      Ops),
-        Line(Line), ScopeLine(ScopeLine), Virtuality(Virtuality),
-        VirtualIndex(VirtualIndex), Flags(Flags), IsLocalToUnit(IsLocalToUnit),
-        IsDefinition(IsDefinition), IsOptimized(IsOptimized) {}
+        Line(Line), ScopeLine(ScopeLine), VirtualIndex(VirtualIndex),
+        Virtuality(Virtuality), Flags(Flags), IsLocalToUnit(IsLocalToUnit),
+        IsDefinition(IsDefinition), IsOptimized(IsOptimized) {
+    static_assert(dwarf::DW_VIRTUALITY_max < 4, "Virtuality out of range");
+    assert(Virtuality < 4 && "Virtuality out of range");
+    assert((Flags < (1 << 27)) && "Flags out of range");
+  }
   ~DISubprogram() = default;
 
   static DISubprogram *

Modified: llvm/trunk/unittests/IR/MetadataTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/IR/MetadataTest.cpp?rev=266241&r1=266240&r2=266241&view=diff
==============================================================================
--- llvm/trunk/unittests/IR/MetadataTest.cpp (original)
+++ llvm/trunk/unittests/IR/MetadataTest.cpp Wed Apr 13 15:17:42 2016
@@ -1413,9 +1413,10 @@ TEST_F(DISubprogramTest, get) {
   bool IsDefinition = true;
   unsigned ScopeLine = 3;
   DITypeRef ContainingType = getCompositeType();
-  unsigned Virtuality = 4;
+  unsigned Virtuality = 2;
   unsigned VirtualIndex = 5;
   unsigned Flags = 6;
+  unsigned NotFlags = (~Flags) & ((1 << 27) - 1);
   bool IsOptimized = false;
   MDTuple *TemplateParams = getTuple();
   DISubprogram *Declaration = getSubprogram();
@@ -1513,7 +1514,7 @@ TEST_F(DISubprogramTest, get) {
   EXPECT_NE(N, DISubprogram::get(Context, Scope, Name, LinkageName, File, Line,
                                  Type, IsLocalToUnit, IsDefinition, ScopeLine,
                                  ContainingType, Virtuality, VirtualIndex,
-                                 ~Flags, IsOptimized, TemplateParams,
+                                 NotFlags, IsOptimized, TemplateParams,
                                  Declaration, Variables));
   EXPECT_NE(N, DISubprogram::get(Context, Scope, Name, LinkageName, File, Line,
                                  Type, IsLocalToUnit, IsDefinition, ScopeLine,




More information about the llvm-commits mailing list