llvm.org GIT mirror llvm / 31dd38e
Add support for hashing attributes with DW_FORM_block. This required passing down an AsmPrinter instance so we could compute the size of the block which could be target specific. All of the test cases in the unittest don't have any target specific data so we can use a NULL AsmPrinter there. This also depends upon block data being added as integers. We can now hash the entire fission-cu.ll compile unit so turn the flag on there with the hash value. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@201752 91177308-0d34-0410-b5e6-96231b3b80d8 Eric Christopher 6 years ago
5 changed file(s) with 94 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
1616 #include "DIE.h"
1717 #include "llvm/ADT/ArrayRef.h"
1818 #include "llvm/ADT/StringRef.h"
19 #include "llvm/CodeGen/AsmPrinter.h"
1920 #include "llvm/Support/Debug.h"
2021 #include "llvm/Support/Dwarf.h"
2122 #include "llvm/Support/Endian.h"
268269 computeHash(Entry);
269270 }
270271
272 // Hash all of the values in a block like set of values. This assumes that
273 // all of the data is going to be added as integers.
274 void DIEHash::hashBlockData(const SmallVectorImpl &Values) {
275 for (SmallVectorImpl::const_iterator I = Values.begin(),
276 E = Values.end();
277 I != E; ++I)
278 Hash.update((uint64_t)cast(*I)->getValue());
279 }
280
271281 // Hash an individual attribute \param Attr based on the type of attribute and
272282 // the form.
273283 void DIEHash::hashAttribute(AttrEntry Attr, dwarf::Tag Tag) {
319329 addULEB128(Attribute);
320330 addULEB128(dwarf::DW_FORM_flag);
321331 addULEB128((int64_t)cast(Value)->getValue());
332 break;
333 case dwarf::DW_FORM_exprloc:
334 case dwarf::DW_FORM_block1:
335 case dwarf::DW_FORM_block2:
336 case dwarf::DW_FORM_block4:
337 case dwarf::DW_FORM_block:
338 addULEB128('A');
339 addULEB128(Attribute);
340 addULEB128(dwarf::DW_FORM_block);
341 if (isa(Value)) {
342 addULEB128(cast(Value)->ComputeSize(AP));
343 hashBlockData(cast(Value)->getValues());
344 } else {
345 addULEB128(cast(Value)->ComputeSize(AP));
346 hashBlockData(cast(Value)->getValues());
347 }
322348 break;
323349 default:
324350 llvm_unreachable("Add support for additional forms");
1616
1717 namespace llvm {
1818
19 class AsmPrinter;
1920 class CompileUnit;
2021
2122 /// \brief An object containing the capability of hashing and adding hash
8384 };
8485
8586 public:
87 DIEHash(AsmPrinter *A = NULL) : AP(A) {}
88
8689 /// \brief Computes the ODR signature.
8790 uint64_t computeDIEODRSignature(const DIE &Die);
8891
121124 /// \brief Hashes the attributes in \param Attrs in order.
122125 void hashAttributes(const DIEAttrs &Attrs, dwarf::Tag Tag);
123126
127 /// \brief Hashes the data in a block like DIEValue, e.g. DW_FORM_block or
128 /// DW_FORM_exprloc.
129 void hashBlockData(const SmallVectorImpl &Values);
130
124131 /// \brief Hashes an individual attribute.
125132 void hashAttribute(AttrEntry Attr, dwarf::Tag Tag);
126133
142149
143150 private:
144151 MD5 Hash;
152 AsmPrinter *AP;
145153 DenseMap Numbering;
146154 };
147155 }
10061006 // This should be a unique identifier when we want to build .dwp files.
10071007 uint64_t ID = 0;
10081008 if (GenerateCUHash) {
1009 DIEHash CUHash;
1009 DIEHash CUHash(Asm);
10101010 ID = CUHash.computeCUSignature(*TheU->getUnitDie());
10111011 }
10121012 TheU->addUInt(TheU->getUnitDie(), dwarf::DW_AT_GNU_dwo_id,
None ; RUN: llc -split-dwarf=Enable -O0 %s -mtriple=x86_64-unknown-linux-gnu -filetype=obj -o %t
0 ; RUN: llc -split-dwarf=Enable -generate-cu-hash -O0 %s -mtriple=x86_64-unknown-linux-gnu -filetype=obj -o %t
11 ; RUN: llvm-dwarfdump -debug-dump=all %t | FileCheck %s
22 ; RUN: llvm-readobj --relocations %t | FileCheck --check-prefix=OBJ %s
33
6060 ; CHECK: DW_AT_GNU_dwo_name [DW_FORM_strp] ( .debug_str[0x00000000] = "baz.dwo")
6161 ; CHECK: DW_AT_GNU_addr_base [DW_FORM_sec_offset] (0x00000000)
6262 ; CHECK: DW_AT_comp_dir [DW_FORM_strp] ( .debug_str[0x00000008] = "/usr/local/google/home/echristo/tmp")
63 ; CHECK: DW_AT_GNU_dwo_id [DW_FORM_data8] (0x0000000000000000)
63 ; CHECK: DW_AT_GNU_dwo_id [DW_FORM_data8] (0x1f1f859683d49324)
6464 ; CHECK: DW_AT_low_pc [DW_FORM_addr] (0x0000000000000000)
6565
6666 ; Check that the rest of the compile units have information.
7272 ; CHECK-NOT: DW_AT_low_pc
7373 ; CHECK-NOT: DW_AT_stmt_list
7474 ; CHECK-NOT: DW_AT_comp_dir
75 ; CHECK: DW_AT_GNU_dwo_id [DW_FORM_data8] (0x0000000000000000)
75 ; CHECK: DW_AT_GNU_dwo_id [DW_FORM_data8] (0x1f1f859683d49324)
7676 ; CHECK: DW_TAG_variable
7777 ; CHECK: DW_AT_name [DW_FORM_GNU_str_index] ( indexed (00000002) string = "a")
7878 ; CHECK: DW_AT_type [DW_FORM_ref4] (cu + 0x{{[0-9a-f]*}} => {[[TYPE:0x[0-9a-f]*]]})
593593 uint64_t MD5Res = DIEHash().computeTypeSignature(A);
594594 ASSERT_EQ(0x9a216000dd3788a7ULL, MD5Res);
595595 }
596 }
596
597 // Derived from:
598 // struct A {
599 // const static float PI = 3.14;
600 // };
601 // A a;
602 TEST(DIEHashTest, MemberBlock) {
603 DIE A(dwarf::DW_TAG_structure_type);
604 DIEInteger One(1);
605 DIEString AStr(&One, "A");
606 A.addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &AStr);
607 A.addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &One);
608 A.addValue(dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, &One);
609 A.addValue(dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, &One);
610
611 DIEInteger Four(4);
612 DIEString FStr(&One, "float");
613 DIE *FloatTyDIE = new DIE(dwarf::DW_TAG_base_type);
614 FloatTyDIE->addValue(dwarf::DW_AT_byte_size, dwarf::DW_FORM_data1, &Four);
615 FloatTyDIE->addValue(dwarf::DW_AT_encoding, dwarf::DW_FORM_data1, &Four);
616 FloatTyDIE->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &FStr);
617
618 DIEEntry FloatTy(FloatTyDIE);
619 DIE *PITyDIE = new DIE(dwarf::DW_TAG_const_type);
620 PITyDIE->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &FloatTy);
621
622 DIEEntry PITy(PITyDIE);
623 DIE *PI = new DIE(dwarf::DW_TAG_member);
624 DIEString PIStr(&One, "PI");
625 DIEInteger Two(2);
626 PI->addValue(dwarf::DW_AT_name, dwarf::DW_FORM_strp, &PIStr);
627 PI->addValue(dwarf::DW_AT_decl_file, dwarf::DW_FORM_data1, &One);
628 PI->addValue(dwarf::DW_AT_decl_line, dwarf::DW_FORM_data1, &Two);
629 PI->addValue(dwarf::DW_AT_type, dwarf::DW_FORM_ref4, &PITy);
630 PI->addValue(dwarf::DW_AT_external, dwarf::DW_FORM_flag_present, &One);
631 PI->addValue(dwarf::DW_AT_declaration, dwarf::DW_FORM_flag_present, &One);
632
633 DIEBlock *PIBlock = new DIEBlock();
634 DIEInteger Blk1(0xc3);
635 DIEInteger Blk2(0xf5);
636 DIEInteger Blk3(0x48);
637 DIEInteger Blk4(0x40);
638
639 PIBlock->addValue((dwarf::Attribute)0, dwarf::DW_FORM_data1, &Blk1);
640 PIBlock->addValue((dwarf::Attribute)0, dwarf::DW_FORM_data1, &Blk2);
641 PIBlock->addValue((dwarf::Attribute)0, dwarf::DW_FORM_data1, &Blk3);
642 PIBlock->addValue((dwarf::Attribute)0, dwarf::DW_FORM_data1, &Blk4);
643
644 PI->addValue(dwarf::DW_AT_const_value, dwarf::DW_FORM_block1, PIBlock);
645
646 A.addChild(PI);
647
648 uint64_t MD5Res = DIEHash().computeTypeSignature(A);
649 ASSERT_EQ(0x493af53ad3d3f651ULL, MD5Res);
650 }
651 }