[llvm-commits] [lld] r172495 - in /lld/trunk: include/lld/Core/DefinedAtom.h lib/Core/Resolver.cpp lib/Core/SymbolTable.cpp lib/ReaderWriter/YAML/ReaderWriterYAML.cpp test/constants-coalesce.objtxt test/cstring-coalesce.objtxt test/darwin/hello-world.objtxt test/fixups-unnamed.objtxt
Nick Kledzik
kledzik at apple.com
Mon Jan 14 16:17:57 PST 2013
Author: kledzik
Date: Mon Jan 14 18:17:57 2013
New Revision: 172495
URL: http://llvm.org/viewvc/llvm-project?rev=172495&view=rev
Log:
Add new merge-by-content Merge attribute for use by anonymous
constants and string literals which the linker should coalesce.
Added:
lld/trunk/test/constants-coalesce.objtxt
Modified:
lld/trunk/include/lld/Core/DefinedAtom.h
lld/trunk/lib/Core/Resolver.cpp
lld/trunk/lib/Core/SymbolTable.cpp
lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
lld/trunk/test/cstring-coalesce.objtxt
lld/trunk/test/darwin/hello-world.objtxt
lld/trunk/test/fixups-unnamed.objtxt
Modified: lld/trunk/include/lld/Core/DefinedAtom.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/DefinedAtom.h?rev=172495&r1=172494&r2=172495&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/DefinedAtom.h (original)
+++ lld/trunk/include/lld/Core/DefinedAtom.h Mon Jan 14 18:17:57 2013
@@ -101,8 +101,9 @@
mergeAsWeak, // is C++ inline definition that was not inlined,
// but address was not taken, so atom can be hidden
// by linker
- mergeAsWeakAndAddressUsed // is C++ definition inline definition whose
+ mergeAsWeakAndAddressUsed,// is C++ definition inline definition whose
// address was taken.
+ mergeByContent // merge with other constants with same content
};
enum ContentType {
Modified: lld/trunk/lib/Core/Resolver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/Resolver.cpp?rev=172495&r1=172494&r2=172495&view=diff
==============================================================================
--- lld/trunk/lib/Core/Resolver.cpp (original)
+++ lld/trunk/lib/Core/Resolver.cpp Mon Jan 14 18:17:57 2013
@@ -110,11 +110,8 @@
// add to list of known atoms
_atoms.push_back(&atom);
- // non-static atoms need extra handling
- if (atom.scope() != DefinedAtom::scopeTranslationUnit) {
- // tell symbol table about non-static atoms
- _symbolTable.add(atom);
- }
+ // tell symbol table
+ _symbolTable.add(atom);
if (_options.deadCodeStripping()) {
// add to set of dead-strip-roots, all symbols that
Modified: lld/trunk/lib/Core/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/SymbolTable.cpp?rev=172495&r1=172494&r2=172495&view=diff
==============================================================================
--- lld/trunk/lib/Core/SymbolTable.cpp (original)
+++ lld/trunk/lib/Core/SymbolTable.cpp Mon Jan 14 18:17:57 2013
@@ -46,11 +46,16 @@
}
void SymbolTable::add(const DefinedAtom &atom) {
- assert(atom.scope() != DefinedAtom::scopeTranslationUnit);
- if ( !atom.name().empty() ) {
+ if (!atom.name().empty() &&
+ (atom.scope() != DefinedAtom::scopeTranslationUnit)) {
+ // Named atoms cannot be merged by content.
+ assert(atom.merge() != DefinedAtom::mergeByContent);
+ // Track named atoms that are not scoped to file (static).
this->addByName(atom);
}
- else {
+ else if ( atom.merge() == DefinedAtom::mergeByContent ) {
+ // Named atoms cannot be merged by content.
+ assert(atom.name().empty());
this->addByContent(atom);
}
}
@@ -123,6 +128,7 @@
void SymbolTable::addByName(const Atom & newAtom) {
StringRef name = newAtom.name();
+ assert(!name.empty());
const Atom *existing = this->findByName(name);
if (existing == nullptr) {
// Name is not in symbol table yet, add it associate with this atom.
@@ -283,6 +289,8 @@
}
void SymbolTable::addByContent(const DefinedAtom & newAtom) {
+ // Currently only read-only constants can be merged.
+ assert(newAtom.permissions() == DefinedAtom::permR__);
AtomContentSet::iterator pos = _contentTable.find(&newAtom);
if ( pos == _contentTable.end() ) {
_contentTable.insert(&newAtom);
Modified: lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp?rev=172495&r1=172494&r2=172495&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp (original)
+++ lld/trunk/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp Mon Jan 14 18:17:57 2013
@@ -351,6 +351,7 @@
io.enumCase(value, "as-weak", lld::DefinedAtom::mergeAsWeak);
io.enumCase(value, "as-addressed-weak",
lld::DefinedAtom::mergeAsWeakAndAddressUsed);
+ io.enumCase(value, "by-content", lld::DefinedAtom::mergeByContent);
}
};
Added: lld/trunk/test/constants-coalesce.objtxt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/constants-coalesce.objtxt?rev=172495&view=auto
==============================================================================
--- lld/trunk/test/constants-coalesce.objtxt (added)
+++ lld/trunk/test/constants-coalesce.objtxt Mon Jan 14 18:17:57 2013
@@ -0,0 +1,60 @@
+# RUN: lld-core %s | FileCheck %s
+
+#
+# Test that duplicate merge-by-content anonymous constants are coalesced
+# and non-mergable duplicate constants are not coalesced.
+#
+
+---
+defined-atoms:
+ - ref-name: L4-byte
+ type: constant
+ merge: by-content
+ content: [ 01, 02, 03, 04 ]
+
+ - ref-name: L8-byte
+ type: constant
+ merge: by-content
+ content: [ 01, 23, 45, 67, 89, AB, CD, EF ]
+
+ - ref-name: L1
+ type: constant
+ content: [ 01, 02 ]
+---
+defined-atoms:
+ - ref-name: L1
+ type: constant
+ content: [ 01, 02 ]
+ - ref-name: L2
+ type: constant
+ merge: by-content
+ content: [ 01, 02, 03, 04 ]
+---
+defined-atoms:
+ - ref-name: L2
+ type: constant
+ merge: by-content
+ content: [ 01, 23, 45, 67, 89, AB, CD, EF ]
+ - ref-name: L3
+ type: constant
+ merge: by-content
+ content: [ 01, 02, 03 ]
+...
+
+# CHECK-NOT: name:
+# CHECK: type: constant
+# CHECK: content: [ 01, 02, 03, 04 ]
+# CHECK: merge: by-content
+# CHECK: type: constant
+# CHECK: content: [ 01, 23, 45, 67, 89, AB, CD, EF ]
+# CHECK: merge: by-content
+# CHECK: type: constant
+# CHECK: content: [ 01, 02 ]
+# CHECK: type: constant
+# CHECK: content: [ 01, 02 ]
+# CHECK: type: constant
+# CHECK: content: [ 01, 02, 03 ]
+# CHECK: merge: by-content
+# CHECK: ...
+
+
Modified: lld/trunk/test/cstring-coalesce.objtxt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/cstring-coalesce.objtxt?rev=172495&r1=172494&r2=172495&view=diff
==============================================================================
--- lld/trunk/test/cstring-coalesce.objtxt (original)
+++ lld/trunk/test/cstring-coalesce.objtxt Mon Jan 14 18:17:57 2013
@@ -7,31 +7,35 @@
---
defined-atoms:
- ref-name: L0
- scope: hidden
type: c-string
+ merge: by-content
content: [ 68, 65, 6c, 6c, 6f, 00 ]
- ref-name: L1
- scope: hidden
type: c-string
+ merge: by-content
content: [ 74, 68, 65, 72, 65, 00 ]
---
defined-atoms:
- ref-name: L2
- scope: hidden
type: c-string
+ merge: by-content
content: [ 68, 65, 6c, 6c, 6f, 00 ]
---
defined-atoms:
- ref-name: L2
- scope: hidden
type: c-string
+ merge: by-content
content: [ 74, 68, 65, 72, 65, 00 ]
...
+# CHECK-NOT: name:
# CHECK: type: c-string
# CHECK: content: [ 68, 65, 6C, 6C, 6F, 00 ]
+# CHECK: merge: by-content
# CHECK: type: c-string
# CHECK: content: [ 74, 68, 65, 72, 65, 00 ]
-# CHECK-NOT: name:
+# CHECK: merge: by-content
# CHECK: ...
+
+
Modified: lld/trunk/test/darwin/hello-world.objtxt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/darwin/hello-world.objtxt?rev=172495&r1=172494&r2=172495&view=diff
==============================================================================
--- lld/trunk/test/darwin/hello-world.objtxt (original)
+++ lld/trunk/test/darwin/hello-world.objtxt Mon Jan 14 18:17:57 2013
@@ -21,8 +21,8 @@
target: _printf
- ref-name: LC1
- scope: hidden
type: c-string
+ merge: by-content
content: [ 68, 65, 6C, 6C, 6F, 0A, 00 ]
shared-library-atoms:
Modified: lld/trunk/test/fixups-unnamed.objtxt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/fixups-unnamed.objtxt?rev=172495&r1=172494&r2=172495&view=diff
==============================================================================
--- lld/trunk/test/fixups-unnamed.objtxt (original)
+++ lld/trunk/test/fixups-unnamed.objtxt Mon Jan 14 18:17:57 2013
@@ -20,13 +20,13 @@
- ref-name: LC1
- scope: hidden
type: c-string
+ merge: by-content
content: [ 68, 65, 6c, 6c, 6f, 00 ]
- ref-name: LC2
- scope: hidden
type: c-string
+ merge: by-content
content: [ 74, 68, 65, 72, 65, 00 ]
More information about the llvm-commits
mailing list