[PATCH] D18918: [DebugInfo] Try to make class memory layout more efficient

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 12 18:16:58 PDT 2016


davide updated this revision to Diff 53505.

http://reviews.llvm.org/D18918

Files:
  include/llvm/IR/DebugInfoMetadata.h
  unittests/IR/MetadataTest.cpp

Index: unittests/IR/MetadataTest.cpp
===================================================================
--- unittests/IR/MetadataTest.cpp
+++ unittests/IR/MetadataTest.cpp
@@ -1413,7 +1413,7 @@
   bool IsDefinition = true;
   unsigned ScopeLine = 3;
   DITypeRef ContainingType = getCompositeType();
-  unsigned Virtuality = 4;
+  unsigned Virtuality = 2;
   unsigned VirtualIndex = 5;
   unsigned Flags = 6;
   bool IsOptimized = false;
Index: include/llvm/IR/DebugInfoMetadata.h
===================================================================
--- include/llvm/IR/DebugInfoMetadata.h
+++ include/llvm/IR/DebugInfoMetadata.h
@@ -1229,22 +1229,34 @@
 
   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,
                unsigned Flags, bool IsLocalToUnit, bool IsDefinition,
                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(log2(dwarf::DW_VIRTUALITY_max) < 4, "Virtuality out of range");
+    assert(Virtuality < 4 && "Virtuality out of range");
+  }
   ~DISubprogram() = default;
 
   static DISubprogram *


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18918.53505.patch
Type: text/x-patch
Size: 2282 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160413/829e8d5f/attachment.bin>


More information about the llvm-commits mailing list