Add an atomic lowering pass
[oota-llvm.git] / include / llvm / ADT / ilist.h
1 //==-- llvm/ADT/ilist.h - Intrusive Linked List Template ---------*- C++ -*-==//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines classes to implement an intrusive doubly linked list class
11 // (i.e. each node of the list must contain a next and previous field for the
12 // list.
13 //
14 // The ilist_traits trait class is used to gain access to the next and previous
15 // fields of the node type that the list is instantiated with.  If it is not
16 // specialized, the list defaults to using the getPrev(), getNext() method calls
17 // to get the next and previous pointers.
18 //
19 // The ilist class itself, should be a plug in replacement for list, assuming
20 // that the nodes contain next/prev pointers.  This list replacement does not
21 // provide a constant time size() method, so be careful to use empty() when you
22 // really want to know if it's empty.
23 //
24 // The ilist class is implemented by allocating a 'tail' node when the list is
25 // created (using ilist_traits<>::createSentinel()).  This tail node is
26 // absolutely required because the user must be able to compute end()-1. Because
27 // of this, users of the direct next/prev links will see an extra link on the
28 // end of the list, which should be ignored.
29 //
30 // Requirements for a user of this list:
31 //
32 //   1. The user must provide {g|s}et{Next|Prev} methods, or specialize
33 //      ilist_traits to provide an alternate way of getting and setting next and
34 //      prev links.
35 //
36 //===----------------------------------------------------------------------===//
37
38 #ifndef LLVM_ADT_ILIST_H
39 #define LLVM_ADT_ILIST_H
40
41 #include <cassert>
42 #include <cstddef>
43 #include <iterator>
44
45 namespace llvm {
46
47 template<typename NodeTy, typename Traits> class iplist;
48 template<typename NodeTy> class ilist_iterator;
49
50 /// ilist_nextprev_traits - A fragment for template traits for intrusive list
51 /// that provides default next/prev implementations for common operations.
52 ///
53 template<typename NodeTy>
54 struct ilist_nextprev_traits {
55   static NodeTy *getPrev(NodeTy *N) { return N->getPrev(); }
56   static NodeTy *getNext(NodeTy *N) { return N->getNext(); }
57   static const NodeTy *getPrev(const NodeTy *N) { return N->getPrev(); }
58   static const NodeTy *getNext(const NodeTy *N) { return N->getNext(); }
59
60   static void setPrev(NodeTy *N, NodeTy *Prev) { N->setPrev(Prev); }
61   static void setNext(NodeTy *N, NodeTy *Next) { N->setNext(Next); }
62 };
63
64 template<typename NodeTy>
65 struct ilist_traits;
66
67 /// ilist_sentinel_traits - A fragment for template traits for intrusive list
68 /// that provides default sentinel implementations for common operations.
69 ///
70 /// ilist_sentinel_traits implements a lazy dynamic sentinel allocation
71 /// strategy. The sentinel is stored in the prev field of ilist's Head.
72 ///
73 template<typename NodeTy>
74 struct ilist_sentinel_traits {
75   /// createSentinel - create the dynamic sentinel
76   static NodeTy *createSentinel() { return new NodeTy(); }
77
78   /// destroySentinel - deallocate the dynamic sentinel
79   static void destroySentinel(NodeTy *N) { delete N; }
80
81   /// provideInitialHead - when constructing an ilist, provide a starting
82   /// value for its Head
83   /// @return null node to indicate that it needs to be allocated later
84   static NodeTy *provideInitialHead() { return 0; }
85
86   /// ensureHead - make sure that Head is either already
87   /// initialized or assigned a fresh sentinel
88   /// @return the sentinel
89   static NodeTy *ensureHead(NodeTy *&Head) {
90     if (!Head) {
91       Head = ilist_traits<NodeTy>::createSentinel();
92       ilist_traits<NodeTy>::noteHead(Head, Head);
93       ilist_traits<NodeTy>::setNext(Head, 0);
94       return Head;
95     }
96     return ilist_traits<NodeTy>::getPrev(Head);
97   }
98
99   /// noteHead - stash the sentinel into its default location
100   static void noteHead(NodeTy *NewHead, NodeTy *Sentinel) {
101     ilist_traits<NodeTy>::setPrev(NewHead, Sentinel);
102   }
103 };
104
105 /// ilist_node_traits - A fragment for template traits for intrusive list
106 /// that provides default node related operations.
107 ///
108 template<typename NodeTy>
109 struct ilist_node_traits {
110   static NodeTy *createNode(const NodeTy &V) { return new NodeTy(V); }
111   static void deleteNode(NodeTy *V) { delete V; }
112
113   void addNodeToList(NodeTy *) {}
114   void removeNodeFromList(NodeTy *) {}
115   void transferNodesFromList(ilist_node_traits &    /*SrcTraits*/,
116                              ilist_iterator<NodeTy> /*first*/,
117                              ilist_iterator<NodeTy> /*last*/) {}
118 };
119
120 /// ilist_default_traits - Default template traits for intrusive list.
121 /// By inheriting from this, you can easily use default implementations
122 /// for all common operations.
123 ///
124 template<typename NodeTy>
125 struct ilist_default_traits : public ilist_nextprev_traits<NodeTy>,
126                               public ilist_sentinel_traits<NodeTy>,
127                               public ilist_node_traits<NodeTy> {
128 };
129
130 // Template traits for intrusive list.  By specializing this template class, you
131 // can change what next/prev fields are used to store the links...
132 template<typename NodeTy>
133 struct ilist_traits : public ilist_default_traits<NodeTy> {};
134
135 // Const traits are the same as nonconst traits...
136 template<typename Ty>
137 struct ilist_traits<const Ty> : public ilist_traits<Ty> {};
138
139 //===----------------------------------------------------------------------===//
140 // ilist_iterator<Node> - Iterator for intrusive list.
141 //
142 template<typename NodeTy>
143 class ilist_iterator
144   : public std::iterator<std::bidirectional_iterator_tag, NodeTy, ptrdiff_t> {
145
146 public:
147   typedef ilist_traits<NodeTy> Traits;
148   typedef std::iterator<std::bidirectional_iterator_tag,
149                         NodeTy, ptrdiff_t> super;
150
151   typedef typename super::value_type value_type;
152   typedef typename super::difference_type difference_type;
153   typedef typename super::pointer pointer;
154   typedef typename super::reference reference;
155 private:
156   pointer NodePtr;
157
158   // ilist_iterator is not a random-access iterator, but it has an
159   // implicit conversion to pointer-type, which is. Declare (but
160   // don't define) these functions as private to help catch
161   // accidental misuse.
162   void operator[](difference_type) const;
163   void operator+(difference_type) const;
164   void operator-(difference_type) const;
165   void operator+=(difference_type) const;
166   void operator-=(difference_type) const;
167   template<class T> void operator<(T) const;
168   template<class T> void operator<=(T) const;
169   template<class T> void operator>(T) const;
170   template<class T> void operator>=(T) const;
171   template<class T> void operator-(T) const;
172 public:
173
174   ilist_iterator(pointer NP) : NodePtr(NP) {}
175   ilist_iterator(reference NR) : NodePtr(&NR) {}
176   ilist_iterator() : NodePtr(0) {}
177
178   // This is templated so that we can allow constructing a const iterator from
179   // a nonconst iterator...
180   template<class node_ty>
181   ilist_iterator(const ilist_iterator<node_ty> &RHS)
182     : NodePtr(RHS.getNodePtrUnchecked()) {}
183
184   // This is templated so that we can allow assigning to a const iterator from
185   // a nonconst iterator...
186   template<class node_ty>
187   const ilist_iterator &operator=(const ilist_iterator<node_ty> &RHS) {
188     NodePtr = RHS.getNodePtrUnchecked();
189     return *this;
190   }
191
192   // Accessors...
193   operator pointer() const {
194     return NodePtr;
195   }
196
197   reference operator*() const {
198     return *NodePtr;
199   }
200   pointer operator->() const { return &operator*(); }
201
202   // Comparison operators
203   bool operator==(const ilist_iterator &RHS) const {
204     return NodePtr == RHS.NodePtr;
205   }
206   bool operator!=(const ilist_iterator &RHS) const {
207     return NodePtr != RHS.NodePtr;
208   }
209
210   // Increment and decrement operators...
211   ilist_iterator &operator--() {      // predecrement - Back up
212     NodePtr = Traits::getPrev(NodePtr);
213     assert(NodePtr && "--'d off the beginning of an ilist!");
214     return *this;
215   }
216   ilist_iterator &operator++() {      // preincrement - Advance
217     NodePtr = Traits::getNext(NodePtr);
218     return *this;
219   }
220   ilist_iterator operator--(int) {    // postdecrement operators...
221     ilist_iterator tmp = *this;
222     --*this;
223     return tmp;
224   }
225   ilist_iterator operator++(int) {    // postincrement operators...
226     ilist_iterator tmp = *this;
227     ++*this;
228     return tmp;
229   }
230
231   // Internal interface, do not use...
232   pointer getNodePtrUnchecked() const { return NodePtr; }
233 };
234
235 // do not implement. this is to catch errors when people try to use
236 // them as random access iterators
237 template<typename T>
238 void operator-(int, ilist_iterator<T>);
239 template<typename T>
240 void operator-(ilist_iterator<T>,int);
241
242 template<typename T>
243 void operator+(int, ilist_iterator<T>);
244 template<typename T>
245 void operator+(ilist_iterator<T>,int);
246
247 // operator!=/operator== - Allow mixed comparisons without dereferencing
248 // the iterator, which could very likely be pointing to end().
249 template<typename T>
250 bool operator!=(const T* LHS, const ilist_iterator<const T> &RHS) {
251   return LHS != RHS.getNodePtrUnchecked();
252 }
253 template<typename T>
254 bool operator==(const T* LHS, const ilist_iterator<const T> &RHS) {
255   return LHS == RHS.getNodePtrUnchecked();
256 }
257 template<typename T>
258 bool operator!=(T* LHS, const ilist_iterator<T> &RHS) {
259   return LHS != RHS.getNodePtrUnchecked();
260 }
261 template<typename T>
262 bool operator==(T* LHS, const ilist_iterator<T> &RHS) {
263   return LHS == RHS.getNodePtrUnchecked();
264 }
265
266
267 // Allow ilist_iterators to convert into pointers to a node automatically when
268 // used by the dyn_cast, cast, isa mechanisms...
269
270 template<typename From> struct simplify_type;
271
272 template<typename NodeTy> struct simplify_type<ilist_iterator<NodeTy> > {
273   typedef NodeTy* SimpleType;
274
275   static SimpleType getSimplifiedValue(const ilist_iterator<NodeTy> &Node) {
276     return &*Node;
277   }
278 };
279 template<typename NodeTy> struct simplify_type<const ilist_iterator<NodeTy> > {
280   typedef NodeTy* SimpleType;
281
282   static SimpleType getSimplifiedValue(const ilist_iterator<NodeTy> &Node) {
283     return &*Node;
284   }
285 };
286
287
288 //===----------------------------------------------------------------------===//
289 //
290 /// iplist - The subset of list functionality that can safely be used on nodes
291 /// of polymorphic types, i.e. a heterogenous list with a common base class that
292 /// holds the next/prev pointers.  The only state of the list itself is a single
293 /// pointer to the head of the list.
294 ///
295 /// This list can be in one of three interesting states:
296 /// 1. The list may be completely unconstructed.  In this case, the head
297 ///    pointer is null.  When in this form, any query for an iterator (e.g.
298 ///    begin() or end()) causes the list to transparently change to state #2.
299 /// 2. The list may be empty, but contain a sentinel for the end iterator. This
300 ///    sentinel is created by the Traits::createSentinel method and is a link
301 ///    in the list.  When the list is empty, the pointer in the iplist points
302 ///    to the sentinel.  Once the sentinel is constructed, it
303 ///    is not destroyed until the list is.
304 /// 3. The list may contain actual objects in it, which are stored as a doubly
305 ///    linked list of nodes.  One invariant of the list is that the predecessor
306 ///    of the first node in the list always points to the last node in the list,
307 ///    and the successor pointer for the sentinel (which always stays at the
308 ///    end of the list) is always null.
309 ///
310 template<typename NodeTy, typename Traits=ilist_traits<NodeTy> >
311 class iplist : public Traits {
312   mutable NodeTy *Head;
313
314   // Use the prev node pointer of 'head' as the tail pointer.  This is really a
315   // circularly linked list where we snip the 'next' link from the sentinel node
316   // back to the first node in the list (to preserve assertions about going off
317   // the end of the list).
318   NodeTy *getTail() { return this->ensureHead(Head); }
319   const NodeTy *getTail() const { return this->ensureHead(Head); }
320   void setTail(NodeTy *N) const { this->noteHead(Head, N); }
321
322   /// CreateLazySentinel - This method verifies whether the sentinel for the
323   /// list has been created and lazily makes it if not.
324   void CreateLazySentinel() const {
325     this->ensureHead(Head);
326   }
327
328   static bool op_less(NodeTy &L, NodeTy &R) { return L < R; }
329   static bool op_equal(NodeTy &L, NodeTy &R) { return L == R; }
330
331   // No fundamental reason why iplist can't be copyable, but the default
332   // copy/copy-assign won't do.
333   iplist(const iplist &);         // do not implement
334   void operator=(const iplist &); // do not implement
335
336 public:
337   typedef NodeTy *pointer;
338   typedef const NodeTy *const_pointer;
339   typedef NodeTy &reference;
340   typedef const NodeTy &const_reference;
341   typedef NodeTy value_type;
342   typedef ilist_iterator<NodeTy> iterator;
343   typedef ilist_iterator<const NodeTy> const_iterator;
344   typedef size_t size_type;
345   typedef ptrdiff_t difference_type;
346   typedef std::reverse_iterator<const_iterator>  const_reverse_iterator;
347   typedef std::reverse_iterator<iterator>  reverse_iterator;
348
349   iplist() : Head(this->provideInitialHead()) {}
350   ~iplist() {
351     if (!Head) return;
352     clear();
353     Traits::destroySentinel(getTail());
354   }
355
356   // Iterator creation methods.
357   iterator begin() {
358     CreateLazySentinel();
359     return iterator(Head);
360   }
361   const_iterator begin() const {
362     CreateLazySentinel();
363     return const_iterator(Head);
364   }
365   iterator end() {
366     CreateLazySentinel();
367     return iterator(getTail());
368   }
369   const_iterator end() const {
370     CreateLazySentinel();
371     return const_iterator(getTail());
372   }
373
374   // reverse iterator creation methods.
375   reverse_iterator rbegin()            { return reverse_iterator(end()); }
376   const_reverse_iterator rbegin() const{ return const_reverse_iterator(end()); }
377   reverse_iterator rend()              { return reverse_iterator(begin()); }
378   const_reverse_iterator rend() const { return const_reverse_iterator(begin());}
379
380
381   // Miscellaneous inspection routines.
382   size_type max_size() const { return size_type(-1); }
383   bool empty() const { return Head == 0 || Head == getTail(); }
384
385   // Front and back accessor functions...
386   reference front() {
387     assert(!empty() && "Called front() on empty list!");
388     return *Head;
389   }
390   const_reference front() const {
391     assert(!empty() && "Called front() on empty list!");
392     return *Head;
393   }
394   reference back() {
395     assert(!empty() && "Called back() on empty list!");
396     return *this->getPrev(getTail());
397   }
398   const_reference back() const {
399     assert(!empty() && "Called back() on empty list!");
400     return *this->getPrev(getTail());
401   }
402
403   void swap(iplist &RHS) {
404     assert(0 && "Swap does not use list traits callback correctly yet!");
405     std::swap(Head, RHS.Head);
406   }
407
408   iterator insert(iterator where, NodeTy *New) {
409     NodeTy *CurNode = where.getNodePtrUnchecked();
410     NodeTy *PrevNode = this->getPrev(CurNode);
411     this->setNext(New, CurNode);
412     this->setPrev(New, PrevNode);
413
414     if (CurNode != Head)  // Is PrevNode off the beginning of the list?
415       this->setNext(PrevNode, New);
416     else
417       Head = New;
418     this->setPrev(CurNode, New);
419
420     this->addNodeToList(New);  // Notify traits that we added a node...
421     return New;
422   }
423
424   iterator insertAfter(iterator where, NodeTy *New) {
425     if (empty())
426       return insert(begin(), New);
427     else
428       return insert(++where, New);
429   }
430
431   NodeTy *remove(iterator &IT) {
432     assert(IT != end() && "Cannot remove end of list!");
433     NodeTy *Node = &*IT;
434     NodeTy *NextNode = this->getNext(Node);
435     NodeTy *PrevNode = this->getPrev(Node);
436
437     if (Node != Head)  // Is PrevNode off the beginning of the list?
438       this->setNext(PrevNode, NextNode);
439     else
440       Head = NextNode;
441     this->setPrev(NextNode, PrevNode);
442     IT = NextNode;
443     this->removeNodeFromList(Node);  // Notify traits that we removed a node...
444
445     // Set the next/prev pointers of the current node to null.  This isn't
446     // strictly required, but this catches errors where a node is removed from
447     // an ilist (and potentially deleted) with iterators still pointing at it.
448     // When those iterators are incremented or decremented, they will assert on
449     // the null next/prev pointer instead of "usually working".
450     this->setNext(Node, 0);
451     this->setPrev(Node, 0);
452     return Node;
453   }
454
455   NodeTy *remove(const iterator &IT) {
456     iterator MutIt = IT;
457     return remove(MutIt);
458   }
459
460   // erase - remove a node from the controlled sequence... and delete it.
461   iterator erase(iterator where) {
462     this->deleteNode(remove(where));
463     return where;
464   }
465
466
467 private:
468   // transfer - The heart of the splice function.  Move linked list nodes from
469   // [first, last) into position.
470   //
471   void transfer(iterator position, iplist &L2, iterator first, iterator last) {
472     assert(first != last && "Should be checked by callers");
473
474     if (position != last) {
475       // Note: we have to be careful about the case when we move the first node
476       // in the list.  This node is the list sentinel node and we can't move it.
477       NodeTy *ThisSentinel = getTail();
478       setTail(0);
479       NodeTy *L2Sentinel = L2.getTail();
480       L2.setTail(0);
481
482       // Remove [first, last) from its old position.
483       NodeTy *First = &*first, *Prev = this->getPrev(First);
484       NodeTy *Next = last.getNodePtrUnchecked(), *Last = this->getPrev(Next);
485       if (Prev)
486         this->setNext(Prev, Next);
487       else
488         L2.Head = Next;
489       this->setPrev(Next, Prev);
490
491       // Splice [first, last) into its new position.
492       NodeTy *PosNext = position.getNodePtrUnchecked();
493       NodeTy *PosPrev = this->getPrev(PosNext);
494
495       // Fix head of list...
496       if (PosPrev)
497         this->setNext(PosPrev, First);
498       else
499         Head = First;
500       this->setPrev(First, PosPrev);
501
502       // Fix end of list...
503       this->setNext(Last, PosNext);
504       this->setPrev(PosNext, Last);
505
506       this->transferNodesFromList(L2, First, PosNext);
507
508       // Now that everything is set, restore the pointers to the list sentinels.
509       L2.setTail(L2Sentinel);
510       setTail(ThisSentinel);
511     }
512   }
513
514 public:
515
516   //===----------------------------------------------------------------------===
517   // Functionality derived from other functions defined above...
518   //
519
520   size_type size() const {
521     if (Head == 0) return 0; // Don't require construction of sentinel if empty.
522     return std::distance(begin(), end());
523   }
524
525   iterator erase(iterator first, iterator last) {
526     while (first != last)
527       first = erase(first);
528     return last;
529   }
530
531   void clear() { if (Head) erase(begin(), end()); }
532
533   // Front and back inserters...
534   void push_front(NodeTy *val) { insert(begin(), val); }
535   void push_back(NodeTy *val) { insert(end(), val); }
536   void pop_front() {
537     assert(!empty() && "pop_front() on empty list!");
538     erase(begin());
539   }
540   void pop_back() {
541     assert(!empty() && "pop_back() on empty list!");
542     iterator t = end(); erase(--t);
543   }
544
545   // Special forms of insert...
546   template<class InIt> void insert(iterator where, InIt first, InIt last) {
547     for (; first != last; ++first) insert(where, *first);
548   }
549
550   // Splice members - defined in terms of transfer...
551   void splice(iterator where, iplist &L2) {
552     if (!L2.empty())
553       transfer(where, L2, L2.begin(), L2.end());
554   }
555   void splice(iterator where, iplist &L2, iterator first) {
556     iterator last = first; ++last;
557     if (where == first || where == last) return; // No change
558     transfer(where, L2, first, last);
559   }
560   void splice(iterator where, iplist &L2, iterator first, iterator last) {
561     if (first != last) transfer(where, L2, first, last);
562   }
563
564
565
566   //===----------------------------------------------------------------------===
567   // High-Level Functionality that shouldn't really be here, but is part of list
568   //
569
570   // These two functions are actually called remove/remove_if in list<>, but
571   // they actually do the job of erase, rename them accordingly.
572   //
573   void erase(const NodeTy &val) {
574     for (iterator I = begin(), E = end(); I != E; ) {
575       iterator next = I; ++next;
576       if (*I == val) erase(I);
577       I = next;
578     }
579   }
580   template<class Pr1> void erase_if(Pr1 pred) {
581     for (iterator I = begin(), E = end(); I != E; ) {
582       iterator next = I; ++next;
583       if (pred(*I)) erase(I);
584       I = next;
585     }
586   }
587
588   template<class Pr2> void unique(Pr2 pred) {
589     if (empty()) return;
590     for (iterator I = begin(), E = end(), Next = begin(); ++Next != E;) {
591       if (pred(*I))
592         erase(Next);
593       else
594         I = Next;
595       Next = I;
596     }
597   }
598   void unique() { unique(op_equal); }
599
600   template<class Pr3> void merge(iplist &right, Pr3 pred) {
601     iterator first1 = begin(), last1 = end();
602     iterator first2 = right.begin(), last2 = right.end();
603     while (first1 != last1 && first2 != last2)
604       if (pred(*first2, *first1)) {
605         iterator next = first2;
606         transfer(first1, right, first2, ++next);
607         first2 = next;
608       } else {
609         ++first1;
610       }
611     if (first2 != last2) transfer(last1, right, first2, last2);
612   }
613   void merge(iplist &right) { return merge(right, op_less); }
614
615   template<class Pr3> void sort(Pr3 pred);
616   void sort() { sort(op_less); }
617   void reverse();
618 };
619
620
621 template<typename NodeTy>
622 struct ilist : public iplist<NodeTy> {
623   typedef typename iplist<NodeTy>::size_type size_type;
624   typedef typename iplist<NodeTy>::iterator iterator;
625
626   ilist() {}
627   ilist(const ilist &right) {
628     insert(this->begin(), right.begin(), right.end());
629   }
630   explicit ilist(size_type count) {
631     insert(this->begin(), count, NodeTy());
632   }
633   ilist(size_type count, const NodeTy &val) {
634     insert(this->begin(), count, val);
635   }
636   template<class InIt> ilist(InIt first, InIt last) {
637     insert(this->begin(), first, last);
638   }
639
640   // bring hidden functions into scope
641   using iplist<NodeTy>::insert;
642   using iplist<NodeTy>::push_front;
643   using iplist<NodeTy>::push_back;
644
645   // Main implementation here - Insert for a node passed by value...
646   iterator insert(iterator where, const NodeTy &val) {
647     return insert(where, this->createNode(val));
648   }
649
650
651   // Front and back inserters...
652   void push_front(const NodeTy &val) { insert(this->begin(), val); }
653   void push_back(const NodeTy &val) { insert(this->end(), val); }
654
655   // Special forms of insert...
656   template<class InIt> void insert(iterator where, InIt first, InIt last) {
657     for (; first != last; ++first) insert(where, *first);
658   }
659   void insert(iterator where, size_type count, const NodeTy &val) {
660     for (; count != 0; --count) insert(where, val);
661   }
662
663   // Assign special forms...
664   void assign(size_type count, const NodeTy &val) {
665     iterator I = this->begin();
666     for (; I != this->end() && count != 0; ++I, --count)
667       *I = val;
668     if (count != 0)
669       insert(this->end(), val, val);
670     else
671       erase(I, this->end());
672   }
673   template<class InIt> void assign(InIt first1, InIt last1) {
674     iterator first2 = this->begin(), last2 = this->end();
675     for ( ; first1 != last1 && first2 != last2; ++first1, ++first2)
676       *first1 = *first2;
677     if (first2 == last2)
678       erase(first1, last1);
679     else
680       insert(last1, first2, last2);
681   }
682
683
684   // Resize members...
685   void resize(size_type newsize, NodeTy val) {
686     iterator i = this->begin();
687     size_type len = 0;
688     for ( ; i != this->end() && len < newsize; ++i, ++len) /* empty*/ ;
689
690     if (len == newsize)
691       erase(i, this->end());
692     else                                          // i == end()
693       insert(this->end(), newsize - len, val);
694   }
695   void resize(size_type newsize) { resize(newsize, NodeTy()); }
696 };
697
698 } // End llvm namespace
699
700 namespace std {
701   // Ensure that swap uses the fast list swap...
702   template<class Ty>
703   void swap(llvm::iplist<Ty> &Left, llvm::iplist<Ty> &Right) {
704     Left.swap(Right);
705   }
706 }  // End 'std' extensions...
707
708 #endif // LLVM_ADT_ILIST_H