summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2016-08-12 16:19:34 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2016-08-12 16:19:34 +0000
commit4a1e87d9c6c62a3c08982193ccec0540487b0156 (patch)
tree4ae657b0ca995b668236eed12683084afe454992
parent87e4038a9154cb4b79a3dc19fe096bd8bdc8801e (diff)
downloadbcm5719-llvm-4a1e87d9c6c62a3c08982193ccec0540487b0156.tar.gz
bcm5719-llvm-4a1e87d9c6c62a3c08982193ccec0540487b0156.zip
Core: Use ilist_full_embedded_sentinel_traits for SimpleReference
Avoid custom code for sentinel traits in SimpleReference (the ilist node for references to a SimpleDefinedAtom), since they'll soon/eventually disappear from ilist entirely. Rather than using a BumpPtrAllocator, this drops the lazy sentinel characteristics and stores the sentinel directly in the ilist. This unconditionally allocates the sentinel. At first glance, this looks like it might increase memory usage slightly, since an unreferenced SimpleDefinedAtom pays for a 6-pointer-sized sentinel even when its list of references is empty. In practice, the sentinel was being lazily allocated at the first call to DefinedAtom::begin/end anyway. I don't expect any real memory effects here. Moreover, this is an intermediate state. The ilist_*sentinel_traits are being phased out. As a preview of the final state: in lieu of a NodeTy sentinel, the ilist will have a single, untemplated list_node_base that has next/prev pointers. This base node will serve both as a sentinel and as a pointer to the head of the list (the same memory layout as ilist_half_embedded_sentinel_traits, but without the UB). llvm-svn: 278521
-rw-r--r--lld/include/lld/Core/Simple.h48
1 files changed, 7 insertions, 41 deletions
diff --git a/lld/include/lld/Core/Simple.h b/lld/include/lld/Core/Simple.h
index eaad6425b84..a6e10612c51 100644
--- a/lld/include/lld/Core/Simple.h
+++ b/lld/include/lld/Core/Simple.h
@@ -143,46 +143,14 @@ private:
} // end namespace lld
-// ilist will lazily create a sentinal (so end() can return a node past the
-// end of the list). We need this trait so that the sentinal is allocated
-// via the BumpPtrAllocator.
+// ilist will lazily create a sentinal (so end() can return a node past the end
+// of the list). This trait embeds the sentinel in the ilist to avoid the lazy
+// logic.
namespace llvm {
-template<>
-struct ilist_sentinel_traits<lld::SimpleReference> {
-
- ilist_sentinel_traits() : _allocator(nullptr) { }
-
- void setAllocator(llvm::BumpPtrAllocator *alloc) {
- _allocator = alloc;
- }
-
- lld::SimpleReference *createSentinel() const {
- return new (*_allocator) lld::SimpleReference();
- }
-
- static void destroySentinel(lld::SimpleReference*) {}
-
- static lld::SimpleReference *provideInitialHead() { return nullptr; }
-
- lld::SimpleReference *ensureHead(lld::SimpleReference *&head) const {
- if (!head) {
- head = createSentinel();
- noteHead(head, head);
- ilist_traits<lld::SimpleReference>::setNext(head, nullptr);
- return head;
- }
- return ilist_traits<lld::SimpleReference>::getPrev(head);
- }
-
- void noteHead(lld::SimpleReference *newHead,
- lld::SimpleReference *sentinel) const {
- ilist_traits<lld::SimpleReference>::setPrev(newHead, sentinel);
- }
-
-private:
- mutable llvm::BumpPtrAllocator *_allocator;
-};
+template <>
+struct ilist_sentinel_traits<lld::SimpleReference>
+ : public ilist_full_embedded_sentinel_traits<lld::SimpleReference> {};
} // end namespace llvm
@@ -191,9 +159,7 @@ namespace lld {
class SimpleDefinedAtom : public DefinedAtom {
public:
explicit SimpleDefinedAtom(const File &f)
- : _file(f), _ordinal(f.getNextAtomOrdinalAndIncrement()) {
- _references.setAllocator(&f.allocator());
- }
+ : _file(f), _ordinal(f.getNextAtomOrdinalAndIncrement()) {}
~SimpleDefinedAtom() override {
_references.clearAndLeakNodesUnsafely();
OpenPOWER on IntegriCloud