CACAO
Backend.hpp
Go to the documentation of this file.
1 /* src/vm/jit/compiler2/Backend.hpp - Backend
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_BACKEND
26 #define _JIT_COMPILER2_BACKEND
27 
32 
33 MM_MAKE_NAME(Backend)
34 
35 namespace cacao {
36 namespace jit {
37 namespace compiler2 {
38 
39 // forward declarations
40 class StackSlotManager;
41 class JITData;
42 class RegisterFile;
43 class MachineBasicBlock;
44 
45 class Backend : public memory::ManagerMixin<Backend> {
46 private:
48 protected:
49  Backend(JITData *JD) : JD(JD) {}
50 public:
51  static Backend* factory(JITData *JD);
52  JITData* get_JITData() const { return JD; };
53 
54  //virtual RegisterFile* get_RegisterFile(Type::TypeID type) const = 0;
55  virtual OperandFile& get_OperandFile(OperandFile& OF,MachineOperand *MO) const = 0;
56  virtual MachineInstruction* create_Move(MachineOperand *src,
57  MachineOperand* dst) const = 0;
58  virtual MachineInstruction* create_Jump(MachineBasicBlock *target) const = 0;
59  virtual void create_frame(CodeMemory* CM, StackSlotManager *SSM) const = 0;
60  virtual const char* get_name() const = 0;
61 };
62 /**
63  * Machine Backend
64  *
65  * This class containes all target dependent information.
66  */
67 template <typename Target>
68 class BackendBase : public Backend {
69 public:
70  BackendBase(JITData *JD) : Backend(JD) {}
71  //virtual RegisterFile* get_RegisterFile(Type::TypeID type) const;
72  virtual OperandFile& get_OperandFile(OperandFile& OF,MachineOperand *MO) const;
73  virtual MachineInstruction* create_Move(MachineOperand *src,
74  MachineOperand* dst) const;
75  virtual MachineInstruction* create_Jump(MachineBasicBlock *target) const;
76  virtual void create_frame(CodeMemory* CM, StackSlotManager *SSM) const;
77  virtual const char* get_name() const;
78 };
79 
81 protected:
84 private:
90 protected:
91  Backend* get_Backend() const {
92  return backend;
93  }
95  assert(BI);
96  MapTy::const_iterator it = map.find(BI);
97  assert_msg(it != map.end(), "MachineBasicBlock for BeginInst "<< *BI << " not found");
98  return it->second;
99  }
101  assert(I);
102  InstructionMapTy::const_iterator it = inst_map.find(I);
103  assert_msg(it != inst_map.end(), "operand for instruction " << *I << " not found");
104  return it->second;
105  }
107  assert(I);
108  assert(op);
109  inst_map[I] = op;
110  }
111 public:
114  : backend(backend), current(current), map(map), inst_map(inst_map),
115  schedule(schedule) {}
116 
117  virtual void visit_default(Instruction *I) {
118  ABORT_MSG("LoweringVisitor","Instruction " << BoldWhite
119  << *I << reset_color << " not yet handled by the Backend");
120  }
121  MachineBasicBlock* get_current() const { return current; }
122  void set_current(MachineBasicBlock* MBB) { current = MBB; }
123  MachineBasicBlock* new_block() const;
124  // make InstructionVisitors visit visible
125  using InstructionVisitor::visit;
126 
127  virtual void visit(BeginInst* I, bool copyOperands);
128  virtual void visit(GOTOInst* I, bool copyOperands);
129  virtual void visit(PHIInst* I, bool copyOperands);
130  virtual void visit(CONSTInst* I, bool copyOperands);
131 
132  /* RuleId enum cannot be used in interface, as including MatcherDefs.hpp
133  * requires Grammar.inc. Backend.hpp is included in several other files
134  * that are compiled without CXXFLAGS containing arch folder.
135  * Interface uses int, implicit conversion is done within method implementation.
136  */
137  virtual void lowerComplex(Instruction* I, int ruleId) = 0;
138 };
139 
140 
141 } // end namespace compiler2
142 } // end namespace jit
143 } // end namespace cacao
144 
145 #endif /* _JIT_COMPILER2_BACKEND */
146 
147 
148 /*
149  * These are local overrides for various environment variables in Emacs.
150  * Please do not remove this and leave it at the end of the file, where
151  * Emacs will automagically detect them.
152  * ---------------------------------------------------------------------
153  * Local variables:
154  * mode: c++
155  * indent-tabs-mode: t
156  * c-basic-offset: 4
157  * tab-width: 4
158  * End:
159  * vim:noexpandtab:sw=4:ts=4:
160  */
void set_op(Instruction *I, MachineOperand *op) const
Definition: Backend.hpp:106
alloc::map< Instruction *, MachineOperand * >::type InstructionMapTy
Definition: Backend.hpp:83
void set_current(MachineBasicBlock *MBB)
Definition: Backend.hpp:122
This Instruction mark the start of a basic block.
u2 op
Definition: disass.cpp:129
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
LoweringVisitorBase(Backend *backend, MachineBasicBlock *current, MapTy &map, InstructionMapTy &inst_map, MachineInstructionSchedule *schedule)
Definition: Backend.hpp:112
alloc::map< BeginInst *, MachineBasicBlock * >::type MapTy
Definition: Backend.hpp:82
MachineBasicBlock * current
Instruction super class.
Definition: Instruction.hpp:73
alloc::list< MachineOperand * >::type OperandFile
ResetColor reset_color
Definition: OStream.cpp:61
Proxy to encode explicit and implicit successors.
MachineBasicBlock * get_current() const
Definition: Backend.hpp:121
#define I(value)
Definition: codegen.c:279
jmethodID jint const void jint const jvmtiAddrLocationMap * map
Definition: jvmti.h:338
Operands that can be directly used by the machine (register, memory, stackslot)
virtual void visit_default(Instruction *I)
Definition: Backend.hpp:117
#define assert_msg(COND, EXPR)
Definition: logging.hpp:107
BeginInst * target
MachineOperand * get_op(Instruction *I) const
Definition: Backend.hpp:100
#define ABORT_MSG(EXPR_SHORT, EXPR_LONG)
Definition: logging.hpp:133
JITData * get_JITData() const
Definition: Backend.hpp:52
MachineInstructionSchedule * schedule
Definition: Backend.hpp:89