[llvm] r200571 - Add support for DW_FORM_flag and DW_FORM_flag_present to the DIE hashing

Eric Christopher echristo at gmail.com
Fri Jan 31 12:02:58 PST 2014


Author: echristo
Date: Fri Jan 31 14:02:58 2014
New Revision: 200571

URL: http://llvm.org/viewvc/llvm-project?rev=200571&view=rev
Log:
Add support for DW_FORM_flag and DW_FORM_flag_present to the DIE hashing
algorithm. Sink the 'A' + Attribute hash into each form so we don't
have to check valid forms before deciding whether or not we're going
to hash which will let the default be to return without doing anything.

Modified:
    llvm/trunk/lib/CodeGen/AsmPrinter/DIEHash.cpp
    llvm/trunk/unittests/CodeGen/DIEHashTest.cpp

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/DIEHash.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/DIEHash.cpp?rev=200571&r1=200570&r2=200571&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/DIEHash.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/DIEHash.cpp Fri Jan 31 14:02:58 2014
@@ -284,22 +284,20 @@ void DIEHash::hashAttribute(AttrEntry At
     return;
   }
 
-  // Other attribute values use the letter 'A' as the marker, ...
-  addULEB128('A');
-
-  addULEB128(Attribute);
-
-  // ... and the value consists of the form code (encoded as an unsigned LEB128
-  // value) followed by the encoding of the value according to the form code. To
-  // ensure reproducibility of the signature, the set of forms used in the
-  // signature computation is limited to the following: DW_FORM_sdata,
-  // DW_FORM_flag, DW_FORM_string, and DW_FORM_block.
+  // Other attribute values use the letter 'A' as the marker, and the value
+  // consists of the form code (encoded as an unsigned LEB128 value) followed by
+  // the encoding of the value according to the form code. To ensure
+  // reproducibility of the signature, the set of forms used in the signature
+  // computation is limited to the following: DW_FORM_sdata, DW_FORM_flag,
+  // DW_FORM_string, and DW_FORM_block.
   switch (Desc->getForm()) {
   case dwarf::DW_FORM_string:
     llvm_unreachable(
         "Add support for DW_FORM_string if we ever start emitting them again");
   case dwarf::DW_FORM_GNU_str_index:
   case dwarf::DW_FORM_strp:
+    addULEB128('A');
+    addULEB128(Attribute);
     addULEB128(dwarf::DW_FORM_string);
     addString(cast<DIEString>(Value)->getString());
     break;
@@ -308,9 +306,20 @@ void DIEHash::hashAttribute(AttrEntry At
   case dwarf::DW_FORM_data4:
   case dwarf::DW_FORM_data8:
   case dwarf::DW_FORM_udata:
+    addULEB128('A');
+    addULEB128(Attribute);
     addULEB128(dwarf::DW_FORM_sdata);
     addSLEB128((int64_t)cast<DIEInteger>(Value)->getValue());
     break;
+  // DW_FORM_flag_present is just flag with a value of one. We still give it a
+  // value so just use the value.
+  case dwarf::DW_FORM_flag_present:
+  case dwarf::DW_FORM_flag:
+    addULEB128('A');
+    addULEB128(Attribute);
+    addULEB128(dwarf::DW_FORM_flag);
+    addULEB128((int64_t)cast<DIEInteger>(Value)->getValue());
+    break;
   default:
     llvm_unreachable("Add support for additional forms");
   }

Modified: llvm/trunk/unittests/CodeGen/DIEHashTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/CodeGen/DIEHashTest.cpp?rev=200571&r1=200570&r2=200571&view=diff
==============================================================================
--- llvm/trunk/unittests/CodeGen/DIEHashTest.cpp (original)
+++ llvm/trunk/unittests/CodeGen/DIEHashTest.cpp Fri Jan 31 14:02:58 2014
@@ -514,4 +514,35 @@ TEST(DIEHashTest, MemberFunc) {
   // The exact same hash GCC produces for this DIE.
   ASSERT_EQ(0xd36a1b6dfb604ba0ULL, MD5Res);
 }
+
+// struct A {
+//   static void func();
+// };
+TEST(DIEHashTest, MemberFuncFlag) {
+  DIE A(dwarf::DW_TAG_structure_type);
+  DIEInteger One(1);
+  DIEString AStr(&One, "A");
+  A.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &AStr);
+  A.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &One);
+  A.addValue(dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, &One);
+  A.addValue(dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, &One);
+
+  DIE *Func = new DIE(dwarf::DW_TAG_subprogram);
+  DIEString FuncStr(&One, "func");
+  DIEString FuncLinkage(&One, "_ZN1A4funcEv");
+  DIEInteger Two(2);
+  Func->addValue(dwarf::DW_AT_external, dwarf::DW_FORM_flag_present, &One);
+  Func->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FuncStr);
+  Func->addValue(dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, &One);
+  Func->addValue(dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, &Two);
+  Func->addValue(dwarf::DW_AT_linkage_name, dwarf::DW_FORM_strp, &FuncLinkage);
+  Func->addValue(dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present, &One);
+
+  A.addChild(Func);
+
+  uint64_t MD5Res = DIEHash().computeTypeSignature(A);
+
+  // The exact same hash GCC produces for this DIE.
+  ASSERT_EQ(0x8f78211ddce3df10ULL, MD5Res);
+}
 }





More information about the llvm-commits mailing list