CACAO
LoopList.hpp
Go to the documentation of this file.
1 /* src/vm/jit/loop/LoopList.hpp
2 
3  Copyright (C) 1996-2012
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 _LOOP_LIST_HPP
26 #define _LOOP_LIST_HPP
27 
28 #include "LoopContainer.hpp"
29 
30 #include <algorithm>
31 
32 namespace
33 {
34  bool depthGreaterThan(const LoopContainer* a, const LoopContainer* b)
35  {
36  return a->depth > b->depth;
37  }
38 }
39 
40 class LoopList
41 {
42  std::vector<LoopContainer*> _loops;
43 
44 public:
45 
46  typedef std::vector<LoopContainer*>::iterator iterator;
47 
48  iterator begin() { return _loops.begin(); }
49  iterator end() { return _loops.end(); }
50 
51  /**
52  * Inserts the specified loop if it is not already contained in this list.
53  */
54  void insert(LoopContainer* loop);
55 
56  /**
57  * Removes the specified loop from the list if the list contains it.
58  */
59  void erase(LoopContainer* loop);
60 
61  /**
62  * Sort the loops in this list according to their depth in the loop hierarchy.
63  * The first loop will have the highest depth.
64  */
65  void sort();
66 
67  /**
68  * Searches this list for the specified loop and returns an iterator to the found element.
69  */
70  iterator find(LoopContainer* loop) { return std::find(_loops.begin(), _loops.end(), loop); }
71 };
72 
74 {
75  iterator it = std::find(_loops.begin(), _loops.end(), loop);
76  if (it == _loops.end())
77  _loops.push_back(loop);
78 }
79 
81 {
82  iterator it = std::find(_loops.begin(), _loops.end(), loop);
83  if (it != _loops.end())
84  _loops.erase(it);
85 }
86 
87 inline void LoopList::sort()
88 {
89  std::sort(_loops.begin(), _loops.end(), depthGreaterThan);
90 }
91 
92 #endif
93 
94 /*
95  * These are local overrides for various environment variables in Emacs.
96  * Please do not remove this and leave it at the end of the file, where
97  * Emacs will automagically detect them.
98  * ---------------------------------------------------------------------
99  * Local variables:
100  * mode: c++
101  * indent-tabs-mode: t
102  * c-basic-offset: 4
103  * tab-width: 4
104  * End:
105  * vim:noexpandtab:sw=4:ts=4:
106  */
107 
iterator begin()
Definition: LoopList.hpp:48
void insert(LoopContainer *loop)
Inserts the specified loop if it is not already contained in this list.
Definition: LoopList.hpp:73
Represents a single loop.
void sort()
Sort the loops in this list according to their depth in the loop hierarchy.
Definition: LoopList.hpp:87
MachineLoop * loop
std::vector< LoopContainer * > _loops
Definition: LoopList.hpp:42
iterator end()
Definition: LoopList.hpp:49
void erase(LoopContainer *loop)
Removes the specified loop from the list if the list contains it.
Definition: LoopList.hpp:80
iterator find(LoopContainer *loop)
Searches this list for the specified loop and returns an iterator to the found element.
Definition: LoopList.hpp:70
std::vector< LoopContainer * >::iterator iterator
Definition: LoopList.hpp:46