[llvm] r313884 - [DWARF] Shrink AttributeSpec from 24 to 16 bytes.

Benjamin Kramer via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 21 08:27:45 PDT 2017


Author: d0k
Date: Thu Sep 21 08:27:45 2017
New Revision: 313884

URL: http://llvm.org/viewvc/llvm-project?rev=313884&view=rev
Log:
[DWARF] Shrink AttributeSpec from 24 to 16 bytes.

This is a bit ugly because we can't put Optional into a union. Hide all
of that behind a set of accessors and make accesses safer using asserts.

Modified:
    llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h
    llvm/trunk/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp

Modified: llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h?rev=313884&r1=313883&r2=313884&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h Thu Sep 21 08:27:45 2017
@@ -28,31 +28,54 @@ class raw_ostream;
 class DWARFAbbreviationDeclaration {
 public:
   struct AttributeSpec {
-    AttributeSpec(dwarf::Attribute A, dwarf::Form F, Optional<int64_t> V)
-        : Attr(A), Form(F), ByteSizeOrValue(V) {}
+    AttributeSpec(dwarf::Attribute A, dwarf::Form F, int64_t Value)
+        : Attr(A), Form(F), Value(Value) {
+      assert(isImplicitConst());
+    }
+    AttributeSpec(dwarf::Attribute A, dwarf::Form F, Optional<uint8_t> ByteSize)
+        : Attr(A), Form(F) {
+      assert(!isImplicitConst());
+      this->ByteSize.HasByteSize = ByteSize.hasValue();
+      if (this->ByteSize.HasByteSize)
+        this->ByteSize.ByteSize = *ByteSize;
+    }
 
     dwarf::Attribute Attr;
     dwarf::Form Form;
 
+  private:
     /// The following field is used for ByteSize for non-implicit_const
     /// attributes and as value for implicit_const ones, indicated by
     /// Form == DW_FORM_implicit_const.
     /// The following cases are distinguished:
-    /// * Form != DW_FORM_implicit_const and ByteSizeOrValue has a value:
-    ///     ByteSizeOrValue contains the fixed size in bytes
-    ///     for the Form in this object.
-    /// * Form != DW_FORM_implicit_const and ByteSizeOrValue is None:
+    /// * Form != DW_FORM_implicit_const and HasByteSize is true:
+    ///     ByteSize contains the fixed size in bytes for the Form in this
+    ///     object.
+    /// * Form != DW_FORM_implicit_const and HasByteSize is false:
     ///     byte size of Form either varies according to the DWARFUnit
     ///     that it is contained in or the value size varies and must be
     ///     decoded from the debug information in order to determine its size.
     /// * Form == DW_FORM_implicit_const:
-    ///     ByteSizeOrValue contains value for the implicit_const attribute.
-    Optional<int64_t> ByteSizeOrValue;
+    ///     Value contains value for the implicit_const attribute.
+    struct ByteSizeStorage {
+      bool HasByteSize;
+      uint8_t ByteSize;
+    };
+    union {
+      ByteSizeStorage ByteSize;
+      int64_t Value;
+    };
 
+  public:
     bool isImplicitConst() const {
       return Form == dwarf::DW_FORM_implicit_const;
     }
 
+    int64_t getImplicitConstValue() const {
+      assert(isImplicitConst());
+      return Value;
+    }
+
     /// Get the fixed byte size of this Form if possible. This function might
     /// use the DWARFUnit to calculate the size of the Form, like for
     /// DW_AT_address and DW_AT_ref_addr, so this isn't just an accessor for

Modified: llvm/trunk/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp?rev=313884&r1=313883&r2=313884&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARF/DWARFAbbreviationDeclaration.cpp Thu Sep 21 08:27:45 2017
@@ -63,13 +63,13 @@ DWARFAbbreviationDeclaration::extract(Da
     auto A = static_cast<Attribute>(Data.getULEB128(OffsetPtr));
     auto F = static_cast<Form>(Data.getULEB128(OffsetPtr));
     if (A && F) {
-      Optional<int64_t> V;
       bool IsImplicitConst = (F == DW_FORM_implicit_const);
       if (IsImplicitConst) {
-        V = Data.getSLEB128(OffsetPtr);
+        int64_t V = Data.getSLEB128(OffsetPtr);
         AttributeSpecs.push_back(AttributeSpec(A, F, V));
         continue;
       }
+      Optional<uint8_t> ByteSize;
       // If this abbrevation still has a fixed byte size, then update the
       // FixedAttributeSize as needed.
       switch (F) {
@@ -96,11 +96,10 @@ DWARFAbbreviationDeclaration::extract(Da
       default:
         // The form has a byte size that doesn't depend on Params.
         // If it's a fixed size, keep track of it.
-        if (auto Size =
-                DWARFFormValue::getFixedByteSize(F, DWARFFormParams())) {
-          V = *Size;
+        if ((ByteSize =
+                 DWARFFormValue::getFixedByteSize(F, DWARFFormParams()))) {
           if (FixedAttributeSize)
-            FixedAttributeSize->NumBytes += *V;
+            FixedAttributeSize->NumBytes += *ByteSize;
           break;
         }
         // Indicate we no longer have a fixed byte size for this
@@ -110,7 +109,7 @@ DWARFAbbreviationDeclaration::extract(Da
         break;
       }
       // Record this attribute and its fixed size if it has one.
-      AttributeSpecs.push_back(AttributeSpec(A, F, V));
+      AttributeSpecs.push_back(AttributeSpec(A, F, ByteSize));
     } else if (A == 0 && F == 0) {
       // We successfully reached the end of this abbreviation declaration
       // since both attribute and form are zero.
@@ -149,7 +148,7 @@ void DWARFAbbreviationDeclaration::dump(
     else
       OS << format("DW_FORM_Unknown_%x", Spec.Form);
     if (Spec.isImplicitConst())
-      OS << '\t' << *Spec.ByteSizeOrValue;
+      OS << '\t' << Spec.getImplicitConstValue();
     OS << '\n';
   }
   OS << '\n';
@@ -182,7 +181,7 @@ Optional<DWARFFormValue> DWARFAbbreviati
       // We have arrived at the attribute to extract, extract if from Offset.
       DWARFFormValue FormValue(Spec.Form);
       if (Spec.isImplicitConst()) {
-        FormValue.setSValue(*Spec.ByteSizeOrValue);
+        FormValue.setSValue(Spec.getImplicitConstValue());
         return FormValue;
       }
       if (FormValue.extractValue(DebugInfoData, &Offset, &U))
@@ -215,8 +214,8 @@ Optional<int64_t> DWARFAbbreviationDecla
     const DWARFUnit &U) const {
   if (isImplicitConst())
     return 0;
-  if (ByteSizeOrValue)
-    return ByteSizeOrValue;
+  if (ByteSize.HasByteSize)
+    return ByteSize.ByteSize;
   Optional<int64_t> S;
   auto FixedByteSize =
       DWARFFormValue::getFixedByteSize(Form, U.getFormParams());




More information about the llvm-commits mailing list