Deleted Added
full compact
IntervalIterator.h (208954) IntervalIterator.h (210299)
1//===- IntervalIterator.h - Interval Iterator Declaration -------*- 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//===----------------------------------------------------------------------===//

--- 22 unchanged lines hidden (view full) ---

31//===----------------------------------------------------------------------===//
32
33#ifndef LLVM_INTERVAL_ITERATOR_H
34#define LLVM_INTERVAL_ITERATOR_H
35
36#include "llvm/Analysis/IntervalPartition.h"
37#include "llvm/Function.h"
38#include "llvm/Support/CFG.h"
1//===- IntervalIterator.h - Interval Iterator Declaration -------*- 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//===----------------------------------------------------------------------===//

--- 22 unchanged lines hidden (view full) ---

31//===----------------------------------------------------------------------===//
32
33#ifndef LLVM_INTERVAL_ITERATOR_H
34#define LLVM_INTERVAL_ITERATOR_H
35
36#include "llvm/Analysis/IntervalPartition.h"
37#include "llvm/Function.h"
38#include "llvm/Support/CFG.h"
39#include <stack>
40#include <set>
41#include <algorithm>
39#include <algorithm>
40#include <set>
41#include <vector>
42
43namespace llvm {
44
45// getNodeHeader - Given a source graph node and the source graph, return the
46// BasicBlock that is the header node. This is the opposite of
47// getSourceGraphNode.
48//
49inline BasicBlock *getNodeHeader(BasicBlock *BB) { return BB; }

--- 33 unchanged lines hidden (view full) ---

83
84
85
86
87
88template<class NodeTy, class OrigContainer_t, class GT = GraphTraits<NodeTy*>,
89 class IGT = GraphTraits<Inverse<NodeTy*> > >
90class IntervalIterator {
42
43namespace llvm {
44
45// getNodeHeader - Given a source graph node and the source graph, return the
46// BasicBlock that is the header node. This is the opposite of
47// getSourceGraphNode.
48//
49inline BasicBlock *getNodeHeader(BasicBlock *BB) { return BB; }

--- 33 unchanged lines hidden (view full) ---

83
84
85
86
87
88template<class NodeTy, class OrigContainer_t, class GT = GraphTraits<NodeTy*>,
89 class IGT = GraphTraits<Inverse<NodeTy*> > >
90class IntervalIterator {
91 std::stack<std::pair<Interval*, typename Interval::succ_iterator> > IntStack;
91 std::vector<std::pair<Interval*, typename Interval::succ_iterator> > IntStack;
92 std::set<BasicBlock*> Visited;
93 OrigContainer_t *OrigContainer;
94 bool IOwnMem; // If True, delete intervals when done with them
95 // See file header for conditions of use
96public:
97 typedef IntervalIterator<NodeTy, OrigContainer_t> _Self;
98 typedef std::forward_iterator_tag iterator_category;
99

--- 11 unchanged lines hidden (view full) ---

111 assert(0 && "ProcessInterval should never fail for first interval!");
112 }
113 }
114
115 inline ~IntervalIterator() {
116 if (IOwnMem)
117 while (!IntStack.empty()) {
118 delete operator*();
92 std::set<BasicBlock*> Visited;
93 OrigContainer_t *OrigContainer;
94 bool IOwnMem; // If True, delete intervals when done with them
95 // See file header for conditions of use
96public:
97 typedef IntervalIterator<NodeTy, OrigContainer_t> _Self;
98 typedef std::forward_iterator_tag iterator_category;
99

--- 11 unchanged lines hidden (view full) ---

111 assert(0 && "ProcessInterval should never fail for first interval!");
112 }
113 }
114
115 inline ~IntervalIterator() {
116 if (IOwnMem)
117 while (!IntStack.empty()) {
118 delete operator*();
119 IntStack.pop();
119 IntStack.pop_back();
120 }
121 }
122
123 inline bool operator==(const _Self& x) const { return IntStack == x.IntStack;}
124 inline bool operator!=(const _Self& x) const { return !operator==(x); }
125
120 }
121 }
122
123 inline bool operator==(const _Self& x) const { return IntStack == x.IntStack;}
124 inline bool operator!=(const _Self& x) const { return !operator==(x); }
125
126 inline const Interval *operator*() const { return IntStack.top().first; }
127 inline Interval *operator*() { return IntStack.top().first; }
126 inline const Interval *operator*() const { return IntStack.back().first; }
127 inline Interval *operator*() { return IntStack.back().first; }
128 inline const Interval *operator->() const { return operator*(); }
129 inline Interval *operator->() { return operator*(); }
130
131 _Self& operator++() { // Preincrement
132 assert(!IntStack.empty() && "Attempting to use interval iterator at end!");
133 do {
134 // All of the intervals on the stack have been visited. Try visiting
135 // their successors now.
128 inline const Interval *operator->() const { return operator*(); }
129 inline Interval *operator->() { return operator*(); }
130
131 _Self& operator++() { // Preincrement
132 assert(!IntStack.empty() && "Attempting to use interval iterator at end!");
133 do {
134 // All of the intervals on the stack have been visited. Try visiting
135 // their successors now.
136 Interval::succ_iterator &SuccIt = IntStack.top().second,
137 EndIt = succ_end(IntStack.top().first);
136 Interval::succ_iterator &SuccIt = IntStack.back().second,
137 EndIt = succ_end(IntStack.back().first);
138 while (SuccIt != EndIt) { // Loop over all interval succs
139 bool Done = ProcessInterval(getSourceGraphNode(OrigContainer, *SuccIt));
140 ++SuccIt; // Increment iterator
141 if (Done) return *this; // Found a new interval! Use it!
142 }
143
144 // Free interval memory... if necessary
138 while (SuccIt != EndIt) { // Loop over all interval succs
139 bool Done = ProcessInterval(getSourceGraphNode(OrigContainer, *SuccIt));
140 ++SuccIt; // Increment iterator
141 if (Done) return *this; // Found a new interval! Use it!
142 }
143
144 // Free interval memory... if necessary
145 if (IOwnMem) delete IntStack.top().first;
145 if (IOwnMem) delete IntStack.back().first;
146
147 // We ran out of successors for this interval... pop off the stack
146
147 // We ran out of successors for this interval... pop off the stack
148 IntStack.pop();
148 IntStack.pop_back();
149 } while (!IntStack.empty());
150
151 return *this;
152 }
153 inline _Self operator++(int) { // Postincrement
154 _Self tmp = *this; ++*this; return tmp;
155 }
156

--- 13 unchanged lines hidden (view full) ---

170 Interval *Int = new Interval(Header);
171 Visited.insert(Header); // The header has now been visited!
172
173 // Check all of our successors to see if they are in the interval...
174 for (typename GT::ChildIteratorType I = GT::child_begin(Node),
175 E = GT::child_end(Node); I != E; ++I)
176 ProcessNode(Int, getSourceGraphNode(OrigContainer, *I));
177
149 } while (!IntStack.empty());
150
151 return *this;
152 }
153 inline _Self operator++(int) { // Postincrement
154 _Self tmp = *this; ++*this; return tmp;
155 }
156

--- 13 unchanged lines hidden (view full) ---

170 Interval *Int = new Interval(Header);
171 Visited.insert(Header); // The header has now been visited!
172
173 // Check all of our successors to see if they are in the interval...
174 for (typename GT::ChildIteratorType I = GT::child_begin(Node),
175 E = GT::child_end(Node); I != E; ++I)
176 ProcessNode(Int, getSourceGraphNode(OrigContainer, *I));
177
178 IntStack.push(std::make_pair(Int, succ_begin(Int)));
178 IntStack.push_back(std::make_pair(Int, succ_begin(Int)));
179 return true;
180 }
181
182 // ProcessNode - This method is called by ProcessInterval to add nodes to the
183 // interval being constructed, and it is also called recursively as it walks
184 // the source graph. A node is added to the current interval only if all of
185 // its predecessors are already in the graph. This also takes care of keeping
186 // the successor set of an interval up to date.

--- 73 unchanged lines hidden ---
179 return true;
180 }
181
182 // ProcessNode - This method is called by ProcessInterval to add nodes to the
183 // interval being constructed, and it is also called recursively as it walks
184 // the source graph. A node is added to the current interval only if all of
185 // its predecessors are already in the graph. This also takes care of keeping
186 // the successor set of an interval up to date.

--- 73 unchanged lines hidden ---