CACAO
MachineInstructionSchedule.hpp
Go to the documentation of this file.
1 /* src/vm/jit/compiler2/MachineInstructionSchedule.hpp - MachineInstructionSchedule
2 
3  Copyright (C) 2013
4  CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5 
6  This file is part of CACAO.
7 
8  This program is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2, or (at
11  your option) any later version.
12 
13  This program is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  02110-1301, USA.
22 
23 */
24 
25 #ifndef _JIT_COMPILER2_MACHINEINSTRUCTIONSCHEDULE
26 #define _JIT_COMPILER2_MACHINEINSTRUCTIONSCHEDULE
27 
32 #include <cassert>
33 
34 namespace cacao {
35 namespace jit {
36 namespace compiler2 {
37 
38 // forward declarations
39 class MachineBasicBlock;
40 class MachineInstructionSchedule;
41 class MIIterator;
42 
43 class MBBIterator {
47  /// empty constructor
49 public:
52  typedef iterator::iterator_category iterator_category;
53  typedef iterator::value_type value_type;
54  typedef iterator::difference_type difference_type;
55 
57  : parent(parent), it(it) {}
58  MBBIterator(const MBBIterator& other) : parent(other.parent), it(other.it) {}
60  ++it;
61  return *this;
62  }
65  MBBIterator tmp(*this);
66  operator++();
67  return tmp;
68  }
70  --it;
71  return *this;
72  }
74  MBBIterator tmp(*this);
75  operator--();
76  return tmp;
77  }
78  bool operator==(const MBBIterator& rhs) const {
79  assert(parent == rhs.parent);
80  return it == rhs.it;
81  }
82  bool operator<( const MBBIterator& rhs) const {
83  assert(parent == rhs.parent);
84  return it < rhs.it;
85  }
86  bool operator!=(const MBBIterator& rhs) const { return !(*this == rhs); }
87  bool operator>( const MBBIterator& rhs) const { return rhs < *this; }
88  reference operator*() { return *it; }
89  const reference operator*() const { return *it; }
90  pointer operator->() { return &*it; }
91  const pointer operator->() const { return &*it; }
92 
94  friend class MachineBasicBlock;
95  friend class const_MBBIterator;
96 };
97 
102  /// empty constructor
104 public:
107  typedef const_iterator::iterator_category iterator_category;
108  typedef const_iterator::value_type value_type;
109  typedef const_iterator::difference_type difference_type;
110 
112  const const_iterator &it) : parent(parent), it(it) {}
114  it(other.it) {}
115  const_MBBIterator(const MBBIterator& other) : parent(other.parent),
116  it(other.it) {}
118  ++it;
119  return *this;
120  }
121  const MachineInstructionSchedule* get_parent() const { return parent; }
123  const_MBBIterator tmp(*this);
124  operator++();
125  return tmp;
126  }
128  --it;
129  return *this;
130  }
132  const_MBBIterator tmp(*this);
133  operator--();
134  return tmp;
135  }
136  bool operator==(const const_MBBIterator& rhs) const {
137  assert(parent == rhs.parent);
138  return it == rhs.it;
139  }
140  bool operator<( const const_MBBIterator& rhs) const {
141  assert(parent == rhs.parent);
142  return it < rhs.it;
143  }
144  bool operator!=(const const_MBBIterator& rhs) const { return !(*this == rhs); }
145  bool operator>( const const_MBBIterator& rhs) const { return rhs < *this; }
146  reference operator*() { return *it; }
147  const reference operator*() const { return *it; }
148  pointer operator->() { return &*it; }
149  const pointer operator->() const { return &*it; }
150 
152  friend class MachineBasicBlock;
153 };
154 
155 class MBBBuilder {
156 private:
158 public:
159  MBBBuilder();
161 };
162 
164 public:
167  typedef std::reverse_iterator<iterator> reverse_iterator;
168  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
170  /// construct an empty MachineInstructionSchedule
172  /// checks if the schedule has no elements.
173  bool empty() const;
174  /// returns the number of elements
175  std::size_t size() const;
176  /// Appends the given element value to the end of the container.
178  /// inserts value to the beginning
180  /// inserts value before the element pointed to by pos
182  /// inserts value after the element pointed to by pos
184  /// returns an iterator to the beginning
185  iterator begin();
186  /// returns an iterator to the end
187  iterator end();
188  /// returns an const iterator to the beginning
189  const_iterator begin() const;
190  /// returns an const iterator to the end
191  const_iterator end() const;
192 
193  /// returns an reverse_iterator to the beginning
195  /// returns an reverse_iterator to the end
197  /// returns an const reverse_iterator to the beginning
199  /// returns an const reverse_iterator to the end
201  /// access the first element
202  reference front();
203  /// access the last element
204  reference back();
205 
206  /// returns an const MIIterator to the beginning
208  /// returns an const MIIterator to the end
209  MIIterator mi_end();
210 private:
212 };
213 
215  return list.empty();
216 }
217 inline std::size_t MachineInstructionSchedule::size() const {
218  return list.size();
219 }
221  return insert_before(++pos,value);
222 }
225  return iterator(this,list.begin());
226 }
229  return iterator(this,list.end());
230 }
232  return list.front();
233 }
235  return list.back();
236 }
239  return const_iterator(this,list.begin());
240 }
243  return const_iterator(this,list.end());
244 }
245 
248  return reverse_iterator(iterator(this,list.end()));
249 }
252  return reverse_iterator(iterator(this,list.begin()));
253 }
256  return const_reverse_iterator(const_iterator(this,list.end()));
257 }
260  return const_reverse_iterator(const_iterator(this,list.begin()));
261 }
262 
263 } // end namespace compiler2
264 } // end namespace jit
265 } // end namespace cacao
266 
267 #endif /* _JIT_COMPILER2_MACHINEINSTRUCTIONSCHEDULE */
268 
269 
270 /*
271  * These are local overrides for various environment variables in Emacs.
272  * Please do not remove this and leave it at the end of the file, where
273  * Emacs will automagically detect them.
274  * ---------------------------------------------------------------------
275  * Local variables:
276  * mode: c++
277  * indent-tabs-mode: t
278  * c-basic-offset: 4
279  * tab-width: 4
280  * End:
281  * vim:noexpandtab:sw=4:ts=4:
282  */
alloc::ordered_list< MachineBasicBlock * >::type list
MIIterator mi_end()
returns an const MIIterator to the end
bool operator<(const const_MBBIterator &rhs) const
ordered const_iterator
const MachineInstructionSchedule * get_parent() const
reverse_iterator rbegin()
returns an reverse_iterator to the beginning
std::reverse_iterator< const_iterator > const_reverse_iterator
reverse_iterator rend()
returns an reverse_iterator to the end
bool operator>(const MBBIterator &rhs) const
MachineInstructionSchedule * get_parent() const
MachineInstructionSchedule::iterator insert_before(iterator pos, const MBBBuilder &value)
inserts value before the element pointed to by pos
std::iterator< std::bidirectional_iterator_tag, const T >::reference reference
A basic block of (scheduled) machine instructions.
const_iterator::iterator_category iterator_category
bool operator==(const MBBIterator &rhs) const
MBBIterator(MachineInstructionSchedule *parent, const iterator &it)
bool empty() const
checks if the schedule has no elements.
ordered iterator
bool operator>(const const_MBBIterator &rhs) const
std::iterator< std::bidirectional_iterator_tag, T >::pointer pointer
MachineInstructionSchedule()
construct an empty MachineInstructionSchedule
const_MBBIterator(const MachineInstructionSchedule *parent, const const_iterator &it)
std::iterator< std::bidirectional_iterator_tag, const T >::pointer pointer
iterator begin()
returns an iterator to the beginning
bool operator==(const const_MBBIterator &rhs) const
alloc::ordered_list< MachineBasicBlock * >::type::const_iterator const_iterator
Instruction::InstID tmp[]
Definition: Matcher.cpp:55
alloc::ordered_list< MachineBasicBlock * >::type::iterator iterator
std::size_t size() const
returns the number of elements
MachineInstructionSchedule::iterator insert_after(iterator pos, const MBBBuilder &value)
inserts value after the element pointed to by pos
MIIterator pos
bool operator<(const MBBIterator &rhs) const
bool operator!=(const const_MBBIterator &rhs) const
MIIterator mi_begin()
returns an const MIIterator to the beginning
MachineInstructionSchedule::iterator push_front(const MBBBuilder &value)
inserts value to the beginning
std::iterator< std::bidirectional_iterator_tag, T >::reference reference
MachineInstructionSchedule::iterator push_back(const MBBBuilder &value)
Appends the given element value to the end of the container.
bool operator!=(const MBBIterator &rhs) const
An ordered_list is an indexed sequence container.