CACAO
LinearScanAllocatorPass.hpp
Go to the documentation of this file.
1 /* src/vm/jit/compiler2/LinearScanAllocatorPass.hpp - LinearScanAllocatorPass
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_LINEARSCANALLOCATORPASS
26 #define _JIT_COMPILER2_LINEARSCANALLOCATORPASS
27 
30 
34 
35 MM_MAKE_NAME(LinearScanAllocatorPass)
36 
37 namespace cacao {
38 namespace jit {
39 namespace compiler2 {
40 
41 class MachineInstructionSchedule;
42 class MachineInstruction;
43 class Backend;
44 
45 struct Move {
49  bool scheduled;
50  Move(MachineOperand *from, MachineOperand *to) : from(from), to(to), dep(NULL), scheduled(false) {}
51  bool is_scheduled() const { return scheduled; }
52 };
53 struct Edge {
56  Edge(MachineBasicBlock *predecessor, MachineBasicBlock *successor) :
57  predecessor(predecessor), successor(successor) {}
58 };
59 
60 inline bool operator<(const Edge &lhs, const Edge &rhs) {
61  if (lhs.predecessor < rhs.predecessor) return true;
62  if (lhs.predecessor > rhs.predecessor) return false;
63  return lhs.successor < rhs.successor;
64 }
65 
69 
70 
71 /**
72  * Linear Scan Allocator
73  *
74  * It supports interval splitting, register hints and fixed intervals
75  * and makes use of livetime holes.
76  *
77  * Based on the approach from "Optimized Interval Splitting in a Linear Scan
78  * Register Allocator" by Wimmer and Moessenboeck @cite Wimmer2005 with
79  * the adoptions from "Linear scan register allocation on SSA form"
80  * by Wimmer and Franz @cite Wimmer2010.
81  * See also Wimmer's Masters Thesis @cite WimmerMScThesis.
82  */
83 class LinearScanAllocatorPass : public Pass, public memory::ManagerMixin<LinearScanAllocatorPass> {
84 public:
85  struct StartComparator {
86  bool operator()(const LivetimeInterval &lhs, const LivetimeInterval &rhs);
87  };
88 
90  //typedef alloc::map<std::pair<BeginInst*,BeginInst*>,MoveListTy>::type MoveMapTy;
95 private:
96 
101 
106 
107  bool try_allocate_free(LivetimeInterval& current, UseDef pos);
108  bool allocate_blocked(LivetimeInterval& current);
109  bool allocate_unhandled();
110  bool resolve();
111  bool reg_alloc_resolve_block(MIIterator first, MIIterator last);
112  bool order_and_insert_move(EdgeMoveMapTy::value_type &entry, BBtoLTI_Map &bb2lti_map);
113  //bool order_and_insert_move(MachineBasicBlock *predecessor, MachineBasicBlock *successor,
114  // MoveMapTy &move_map);
115 public:
116  static char ID;
118  virtual void initialize();
119  virtual bool run(JITData &JD);
120  virtual PassUsage& get_PassUsage(PassUsage &PA) const;
121  virtual bool verify() const;
122 };
123 
124 } // end namespace compiler2
125 } // end namespace jit
126 } // end namespace cacao
127 
128 #endif /* _JIT_COMPILER2_LINEARSCANALLOCATORPASS */
129 
130 
131 /*
132  * These are local overrides for various environment variables in Emacs.
133  * Please do not remove this and leave it at the end of the file, where
134  * Emacs will automagically detect them.
135  * ---------------------------------------------------------------------
136  * Local variables:
137  * mode: c++
138  * indent-tabs-mode: t
139  * c-basic-offset: 4
140  * tab-width: 4
141  * End:
142  * vim:noexpandtab:sw=4:ts=4:
143  */
Pass superclass All compiler passes should inheritate this class.
Definition: Pass.hpp:48
Edge(MachineBasicBlock *predecessor, MachineBasicBlock *successor)
Move(MachineOperand *from, MachineOperand *to)
argument_type from
alloc::map< Edge, MoveMapTy >::type EdgeMoveMapTy
alloc::priority_queue< LivetimeInterval, alloc::deque< LivetimeInterval >::type, StartComparator >::type UnhandledSetTy
Custom new/delete handler mixin.
Definition: Manager.hpp:43
A basic block of (scheduled) machine instructions.
#define MM_MAKE_NAME(x)
Definition: memstats.hpp:127
bool operator<(const NativeMethod &first, const NativeMethod &second)
Definition: native.cpp:212
alloc::map< MachineBasicBlock *, alloc::list< LivetimeInterval >::type >::type BBtoLTI_Map
alloc::list< MachineInstruction * >::type MoveListTy
MachineBasicBlock * current
std::list< T, Allocator< T > > type
Definition: list.hpp:38
alloc::list< LivetimeInterval >::type ActiveSetTy
alloc::list< Move >::type MoveMapTy
Stores the interdependencies of a pass.
Definition: PassUsage.hpp:55
alloc::list< LivetimeInterval >::type InactiveSetTy
MIIterator pos
Operands that can be directly used by the machine (register, memory, stackslot)
alloc::list< LivetimeInterval >::type HandledSetTy
alloc::set< Instruction * >::type & scheduled