CACAO
GraphHelper.cpp
Go to the documentation of this file.
1 /* src/vm/jit/compiler2/GraphHelper.cpp - GraphHelper
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 
30 
31 #include <cassert>
32 
33 #define DEBUG_NAME "compiler2/GraphHelper"
34 
35 namespace cacao {
36 namespace jit {
37 namespace compiler2 {
38 
39 // specialization for BeginInst
40 template <>
42  EndInst *ve = v->get_EndInst();
43  assert(ve);
44  if (ve->to_IFInst()) {
45  // the first successor is usually the jump target, the second the fall-through block
46  assert(ve->succ_size() == 2);
47  for (EndInst::SuccessorListTy::const_reverse_iterator i = ve->succ_rbegin(),
48  e = ve->succ_rend(); i != e; ++i) {
49  list.insert(i->get());
50  }
51  } else {
52  for (EndInst::SuccessorListTy::const_iterator i = ve->succ_begin(),
53  e = ve->succ_end(); i != e; ++i) {
54  list.insert(i->get());
55  }
56  }
57  return list;
58 }
59 
60 template <>
62  assert(v->get_Method());
63  return v->get_Method()->bb_size();
64 }
65 
66 // specialization for MachineBasicBlock
67 template <>
69  MachineInstruction *last = v->back();
70  std::copy(last->successor_begin(),last->successor_end(),std::inserter(list,list.begin()));
71  return list;
72 }
73 
74 template <>
76  return v->get_parent()->size();
77 }
78 
79 } // end namespace compiler2
80 } // end namespace jit
81 } // end namespace cacao
82 
83 
84 /*
85  * These are local overrides for various environment variables in Emacs.
86  * Please do not remove this and leave it at the end of the file, where
87  * Emacs will automagically detect them.
88  * ---------------------------------------------------------------------
89  * Local variables:
90  * mode: c++
91  * indent-tabs-mode: t
92  * c-basic-offset: 4
93  * tab-width: 4
94  * End:
95  * vim:noexpandtab:sw=4:ts=4:
96  */
This Instruction mark the start of a basic block.
A basic block of (scheduled) machine instructions.
This Instruction mark the end of a basic block.
SuccessorListTy::const_reverse_iterator succ_rbegin() const
const_reference back() const
access the last element
SuccessorListTy::const_reverse_iterator succ_rend() const
SuccessorListTy::const_iterator succ_end() const
std::size_t size() const
returns the number of elements
MIIterator i
MachineInstructionSchedule * get_parent() const
get parent
SuccessorListTy::const_iterator succ_begin() const
alloc::set< _NodeTy * >::type NodeListTy
Definition: GraphHelper.hpp:58
MIIterator e
Proxy to encode explicit and implicit successors.
NodeListTy & successor(_NodeTy *v, NodeListTy &list)
int num_nodes(_NodeTy *v) const