[llvm] r255482 - [llvm-dwp] Deduplicate type units
David Blaikie via llvm-commits
llvm-commits at lists.llvm.org
Sun Dec 13 23:42:00 PST 2015
Author: dblaikie
Date: Mon Dec 14 01:42:00 2015
New Revision: 255482
URL: http://llvm.org/viewvc/llvm-project?rev=255482&view=rev
Log:
[llvm-dwp] Deduplicate type units
It's O(N^2) because it does a simple walk through the existing types to
find duplicates, but that will be fixed in a follow-up commit to use a
mapping data structure of some kind.
Added:
llvm/trunk/test/tools/llvm-dwp/Inputs/type_dedup/
llvm/trunk/test/tools/llvm-dwp/Inputs/type_dedup/a.dwo
llvm/trunk/test/tools/llvm-dwp/Inputs/type_dedup/b.dwo
llvm/trunk/test/tools/llvm-dwp/X86/type_dedup.test
Modified:
llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp
Added: llvm/trunk/test/tools/llvm-dwp/Inputs/type_dedup/a.dwo
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwp/Inputs/type_dedup/a.dwo?rev=255482&view=auto
==============================================================================
Binary files llvm/trunk/test/tools/llvm-dwp/Inputs/type_dedup/a.dwo (added) and llvm/trunk/test/tools/llvm-dwp/Inputs/type_dedup/a.dwo Mon Dec 14 01:42:00 2015 differ
Added: llvm/trunk/test/tools/llvm-dwp/Inputs/type_dedup/b.dwo
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwp/Inputs/type_dedup/b.dwo?rev=255482&view=auto
==============================================================================
Binary files llvm/trunk/test/tools/llvm-dwp/Inputs/type_dedup/b.dwo (added) and llvm/trunk/test/tools/llvm-dwp/Inputs/type_dedup/b.dwo Mon Dec 14 01:42:00 2015 differ
Added: llvm/trunk/test/tools/llvm-dwp/X86/type_dedup.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-dwp/X86/type_dedup.test?rev=255482&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-dwp/X86/type_dedup.test (added)
+++ llvm/trunk/test/tools/llvm-dwp/X86/type_dedup.test Mon Dec 14 01:42:00 2015
@@ -0,0 +1,35 @@
+RUN: llvm-dwp %p/../Inputs/type_dedup/a.dwo %p/../Inputs/type_dedup/b.dwo -o %t
+RUN: llvm-dwarfdump %t | FileCheck %s
+
+a.cpp:
+ struct common { };
+ common a1;
+ struct adistinct { };
+ adistinct a2;
+
+b.cpp:
+ struct common { };
+ common b1;
+ struct bdistinct { };
+ bdistinct b2;
+
+CHECK-LABEL: .debug_types.dwo contents:
+CHECK: [[COMMONUOFF:0x[0-9a-f]*]]:
+CHECK-LABEL: Type Unit: length = 0x00000020 version = 0x0004 abbr_offset =
+CHECK: 0x0000 addr_size = 0x08 type_signature = [[COMMONSIG:0x[0-9a-f]*]] type_offset = 0x[[COMMONOFF:.*]] (next unit at [[AUOFF:.*]])
+CHECK: DW_TAG_type_unit
+CHECK: [[COMMONOFF]]: DW_TAG_structure_type
+CHECK: DW_AT_name {{.*}} "common"
+CHECK: [[AUOFF]]:
+CHECK-LABEL: Type Unit: length = 0x00000020 version = 0x0004 abbr_offset =
+CHECK: 0x0000 addr_size = 0x08 type_signature = [[ASIG:0x[0-9a-f]*]] type_offset = 0x[[AOFF:.*]] (next unit at [[BUOFF:.*]])
+CHECK: DW_TAG_type_unit
+CHECK: 0x00000042: DW_TAG_structure_type
+CHECK: DW_AT_name {{.*}} "adistinct"
+CHECK: [[BUOFF]]:
+CHECK-LABEL: Type Unit: length = 0x00000020 version = 0x0004 abbr_offset =
+CHECK: 0x{{.*}} addr_size = 0x08 type_signature = [[BSIG:0x[0-9a-f]*]] type_offset = 0x[[BOFF:.*]] (next unit at [[XUOFF:.*]])
+CHECK: DW_TAG_type_unit
+CHECK: 0x00000066: DW_TAG_structure_type
+CHECK: DW_AT_name {{.*}} "bdistinct"
+CHECK-NOT: Type Unit
Modified: llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp?rev=255482&r1=255481&r2=255482&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp (original)
+++ llvm/trunk/tools/llvm-dwp/llvm-dwp.cpp Mon Dec 14 01:42:00 2015
@@ -148,24 +148,30 @@ static void addAllTypes(MCStreamer &Out,
uint32_t Offset = 0;
DataExtractor Data(Types, true, 0);
while (Data.isValidOffset(Offset)) {
- TypeIndexEntries.push_back(CUEntry);
- auto &Entry = TypeIndexEntries.back();
+ UnitIndexEntry Entry = CUEntry;
// Zero out the debug_info contribution
Entry.Contributions[0] = {};
auto &C = Entry.Contributions[DW_SECT_TYPES - DW_SECT_INFO];
- C.Offset = TypesOffset + Offset;
+ C.Offset = TypesOffset;
auto PrevOffset = Offset;
// Length of the unit, including the 4 byte length field.
C.Length = Data.getU32(&Offset) + 4;
- Out.EmitBytes(Types.substr(Offset - 4, C.Length));
- TypesOffset += C.Length;
-
Data.getU16(&Offset); // Version
Data.getU32(&Offset); // Abbrev offset
Data.getU8(&Offset); // Address size
Entry.Signature = Data.getU64(&Offset);
Offset = PrevOffset + C.Length;
+
+ if (any_of(TypeIndexEntries, [&](const UnitIndexEntry &E) {
+ return E.Signature == Entry.Signature;
+ }))
+ continue;
+
+ Out.EmitBytes(Types.substr(PrevOffset, C.Length));
+ TypesOffset += C.Length;
+
+ TypeIndexEntries.push_back(Entry);
}
}
More information about the llvm-commits
mailing list