[llvm] r193560 - DWARF parser: Use ArrayRef to represent form sizes and simplify DWARFDIE::extractFast() interface. No functionality change.

Alexey Samsonov samsonov at google.com
Mon Oct 28 16:41:50 PDT 2013


Author: samsonov
Date: Mon Oct 28 18:41:49 2013
New Revision: 193560

URL: http://llvm.org/viewvc/llvm-project?rev=193560&view=rev
Log:
DWARF parser: Use ArrayRef to represent form sizes and simplify DWARFDIE::extractFast() interface. No functionality change.

Modified:
    llvm/trunk/include/llvm/DebugInfo/DWARFFormValue.h
    llvm/trunk/lib/DebugInfo/DWARFDebugInfoEntry.cpp
    llvm/trunk/lib/DebugInfo/DWARFDebugInfoEntry.h
    llvm/trunk/lib/DebugInfo/DWARFFormValue.cpp
    llvm/trunk/lib/DebugInfo/DWARFUnit.cpp
    llvm/trunk/unittests/DebugInfo/DWARFFormValueTest.cpp

Modified: llvm/trunk/include/llvm/DebugInfo/DWARFFormValue.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/DebugInfo/DWARFFormValue.h?rev=193560&r1=193559&r2=193560&view=diff
==============================================================================
--- llvm/trunk/include/llvm/DebugInfo/DWARFFormValue.h (original)
+++ llvm/trunk/include/llvm/DebugInfo/DWARFFormValue.h Mon Oct 28 18:41:49 2013
@@ -10,6 +10,7 @@
 #ifndef LLVM_DEBUGINFO_DWARFFORMVALUE_H
 #define LLVM_DEBUGINFO_DWARFFORMVALUE_H
 
+#include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/Support/DataExtractor.h"
 
@@ -75,7 +76,8 @@ public:
   static bool skipValue(uint16_t form, DataExtractor debug_info_data,
                         uint32_t *offset_ptr, const DWARFUnit *u);
 
-  static const uint8_t *getFixedFormSizes(uint8_t AddrSize, uint16_t Version);
+  static ArrayRef<uint8_t> getFixedFormSizes(uint8_t AddrSize,
+                                             uint16_t Version);
 };
 
 }

Modified: llvm/trunk/lib/DebugInfo/DWARFDebugInfoEntry.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARFDebugInfoEntry.cpp?rev=193560&r1=193559&r2=193560&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARFDebugInfoEntry.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARFDebugInfoEntry.cpp Mon Oct 28 18:41:49 2013
@@ -93,7 +93,6 @@ void DWARFDebugInfoEntryMinimal::dumpAtt
 }
 
 bool DWARFDebugInfoEntryMinimal::extractFast(const DWARFUnit *U,
-                                             const uint8_t *FixedFormSizes,
                                              uint32_t *OffsetPtr) {
   Offset = *OffsetPtr;
   DataExtractor DebugInfoData = U->getDebugInfoExtractor();
@@ -105,21 +104,19 @@ bool DWARFDebugInfoEntryMinimal::extract
   }
   AbbrevDecl = U->getAbbreviations()->getAbbreviationDeclaration(AbbrCode);
   assert(AbbrevDecl);
-  assert(FixedFormSizes); // For best performance this should be specified!
+  ArrayRef<uint8_t> FixedFormSizes = DWARFFormValue::getFixedFormSizes(
+      U->getAddressByteSize(), U->getVersion());
+  assert(FixedFormSizes.size() > 0);
 
   // Skip all data in the .debug_info for the attributes
   for (uint32_t i = 0, n = AbbrevDecl->getNumAttributes(); i < n; ++i) {
     uint16_t Form = AbbrevDecl->getFormByIndex(i);
 
-    // FIXME: Currently we're checking if this is less than the last
-    // entry in the fixed_form_sizes table, but this should be changed
-    // to use dynamic dispatch.
     uint8_t FixedFormSize =
-        (Form < DW_FORM_ref_sig8) ? FixedFormSizes[Form] : 0;
+        (Form < FixedFormSizes.size()) ? FixedFormSizes[Form] : 0;
     if (FixedFormSize)
       *OffsetPtr += FixedFormSize;
-    else if (!DWARFFormValue::skipValue(Form, DebugInfoData, OffsetPtr,
-                                        U)) {
+    else if (!DWARFFormValue::skipValue(Form, DebugInfoData, OffsetPtr, U)) {
       // Restore the original offset.
       *OffsetPtr = Offset;
       return false;

Modified: llvm/trunk/lib/DebugInfo/DWARFDebugInfoEntry.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARFDebugInfoEntry.h?rev=193560&r1=193559&r2=193560&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARFDebugInfoEntry.h (original)
+++ llvm/trunk/lib/DebugInfo/DWARFDebugInfoEntry.h Mon Oct 28 18:41:49 2013
@@ -45,11 +45,10 @@ public:
   void dumpAttribute(raw_ostream &OS, const DWARFUnit *u, uint32_t *offset_ptr,
                      uint16_t attr, uint16_t form, unsigned indent = 0) const;
 
-  /// Extracts a debug info entry, which is a child of a given compile unit,
+  /// Extracts a debug info entry, which is a child of a given unit,
   /// starting at a given offset. If DIE can't be extracted, returns false and
   /// doesn't change OffsetPtr.
-  bool extractFast(const DWARFUnit *U, const uint8_t *FixedFormSizes,
-                   uint32_t *OffsetPtr);
+  bool extractFast(const DWARFUnit *U, uint32_t *OffsetPtr);
 
   /// Extract a debug info entry for a given compile unit from the
   /// .debug_info and .debug_abbrev data starting at the given offset.

Modified: llvm/trunk/lib/DebugInfo/DWARFFormValue.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARFFormValue.cpp?rev=193560&r1=193559&r2=193560&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARFFormValue.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARFFormValue.cpp Mon Oct 28 18:41:49 2013
@@ -62,8 +62,8 @@ static uint8_t getRefAddrSize(uint8_t Ad
   return (Version == 2) ? AddrSize : 4;
 }
 
-const uint8_t *
-DWARFFormValue::getFixedFormSizes(uint8_t AddrSize, uint16_t Version) {
+ArrayRef<uint8_t> DWARFFormValue::getFixedFormSizes(uint8_t AddrSize,
+                                                    uint16_t Version) {
   uint8_t RefAddrSize = getRefAddrSize(AddrSize, Version);
   if (AddrSize == 4 && RefAddrSize == 4)
     return FixedFormSizes<4, 4>::sizes;
@@ -73,7 +73,7 @@ DWARFFormValue::getFixedFormSizes(uint8_
     return FixedFormSizes<8, 4>::sizes;
   if (AddrSize == 8 && RefAddrSize == 8)
     return FixedFormSizes<8, 8>::sizes;
-  return 0;
+  return None;
 }
 
 static const DWARFFormValue::FormClass DWARF4FormClasses[] = {

Modified: llvm/trunk/lib/DebugInfo/DWARFUnit.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARFUnit.cpp?rev=193560&r1=193559&r2=193560&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARFUnit.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARFUnit.cpp Mon Oct 28 18:41:49 2013
@@ -194,12 +194,9 @@ void DWARFUnit::extractDIEsToVector(
   uint32_t NextCUOffset = getNextUnitOffset();
   DWARFDebugInfoEntryMinimal DIE;
   uint32_t Depth = 0;
-  const uint8_t *FixedFormSizes =
-    DWARFFormValue::getFixedFormSizes(getAddressByteSize(), getVersion());
   bool IsCUDie = true;
 
-  while (Offset < NextCUOffset &&
-         DIE.extractFast(this, FixedFormSizes, &Offset)) {
+  while (Offset < NextCUOffset && DIE.extractFast(this, &Offset)) {
     if (IsCUDie) {
       if (AppendCUDie)
         Dies.push_back(DIE);

Modified: llvm/trunk/unittests/DebugInfo/DWARFFormValueTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/DebugInfo/DWARFFormValueTest.cpp?rev=193560&r1=193559&r2=193560&view=diff
==============================================================================
--- llvm/trunk/unittests/DebugInfo/DWARFFormValueTest.cpp (original)
+++ llvm/trunk/unittests/DebugInfo/DWARFFormValueTest.cpp Mon Oct 28 18:41:49 2013
@@ -18,14 +18,14 @@ namespace {
 TEST(DWARFFormValue, FixedFormSizes) {
   // Size of DW_FORM_addr and DW_FORM_ref_addr are equal in DWARF2,
   // DW_FORM_ref_addr is always 4 bytes in DWARF32 starting from DWARF3.
-  const uint8_t *sizes = DWARFFormValue::getFixedFormSizes(4, 2);
+  ArrayRef<uint8_t> sizes = DWARFFormValue::getFixedFormSizes(4, 2);
   EXPECT_EQ(sizes[DW_FORM_addr], sizes[DW_FORM_ref_addr]);
   sizes = DWARFFormValue::getFixedFormSizes(8, 2);
   EXPECT_EQ(sizes[DW_FORM_addr], sizes[DW_FORM_ref_addr]);
   sizes = DWARFFormValue::getFixedFormSizes(8, 3);
   EXPECT_EQ(4, sizes[DW_FORM_ref_addr]);
   // Check that we don't have fixed form sizes for weird address sizes.
-  EXPECT_EQ(0, DWARFFormValue::getFixedFormSizes(16, 2));
+  EXPECT_EQ(0U, DWARFFormValue::getFixedFormSizes(16, 2).size());
 }
 
 bool isFormClass(uint16_t Form, DWARFFormValue::FormClass FC) {





More information about the llvm-commits mailing list