Switch from using an ilist for uses to using a custom doubly linked list.

This list does not provide the ability to go backwards in the list (its
more of an unordered collection, stored in the shape of a list).

This change means that use iterators are now only forward iterators, not
bidirectional.

This improves the memory usage of use lists from '5 + 4*#use' per value to
'1 + 4*#use'.  While it would be better to reduce the multiplied factor,
I'm not smart enough to do so.  This list also has slightly more efficient
operators for manipulating list nodes (a few less loads/stores), due to not
needing to be able to iterate backwards through the list.

This change reduces the memory footprint required to hold 176.gcc from
66.025M -> 57.687M, a 14% reduction.  It also speeds up the compiler,
7.73% in the case of bytecode loading alone (release build loading 176.gcc).


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19956 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2005-02-01 01:22:06 +00:00
parent caa7c19fb4
commit a266197489
3 changed files with 83 additions and 122 deletions

View File

@@ -27,22 +27,22 @@ namespace llvm {
//===--------------------------------------------------------------------===//
template <class _Ptr, class _USE_iterator> // Predecessor Iterator
class PredIterator : public bidirectional_iterator<_Ptr, ptrdiff_t> {
typedef bidirectional_iterator<_Ptr, ptrdiff_t> super;
class PredIterator : public forward_iterator<_Ptr, ptrdiff_t> {
typedef forward_iterator<_Ptr, ptrdiff_t> super;
_Ptr *BB;
_USE_iterator It;
public:
typedef PredIterator<_Ptr,_USE_iterator> _Self;
typedef typename super::pointer pointer;
inline void advancePastConstants() {
inline void advancePastNonTerminators() {
// Loop to ignore non terminator uses (for example PHI nodes)...
while (It != BB->use_end() && !isa<TerminatorInst>(*It))
++It;
}
inline PredIterator(_Ptr *bb) : BB(bb), It(bb->use_begin()) {
advancePastConstants();
advancePastNonTerminators();
}
inline PredIterator(_Ptr *bb, bool) : BB(bb), It(bb->use_end()) {}
@@ -57,18 +57,13 @@ public:
inline _Self& operator++() { // Preincrement
assert(It != BB->use_end() && "pred_iterator out of range!");
++It; advancePastConstants();
++It; advancePastNonTerminators();
return *this;
}
inline _Self operator++(int) { // Postincrement
_Self tmp = *this; ++*this; return tmp;
}
inline _Self& operator--() { --It; return *this; } // Predecrement
inline _Self operator--(int) { // Postdecrement
_Self tmp = *this; --*this; return tmp;
}
};
typedef PredIterator<BasicBlock, Value::use_iterator> pred_iterator;