CACAO
Backend.cpp
Go to the documentation of this file.
1 /* src/vm/jit/compiler2/Backend.cpp - 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 
28 
29 # include "vm/jit/replace.hpp"
30 
31 #include "Target.hpp"
32 
33 namespace cacao {
34 namespace jit {
35 namespace compiler2 {
36 
38  return new BackendBase<Target>(JD);
39 }
40 
41 void LoweringVisitorBase::visit(BeginInst* I, bool copyOperands) {
42  assert(I);
43  MachineInstruction *label = new MachineLabelInst();
44  get_current()->push_back(label);
45  //set_op(I,label->get_result().op);
46 }
47 
48 void LoweringVisitorBase::visit(GOTOInst* I, bool copyOperands) {
49  assert(I);
50  MachineInstruction *jump = backend->create_Jump(get(I->get_target().get()));
51  get_current()->push_back(jump);
52  set_op(I,jump->get_result().op);
53 }
54 
55 void LoweringVisitorBase::visit(PHIInst* I, bool copyOperands) {
56  assert(I);
57  MachinePhiInst *phi = new MachinePhiInst(I->op_size(),I->get_type(),I);
58  //get_current()->push_back(phi);
59  get_current()->insert_phi(phi);
60  set_op(I,phi->get_result().op);
61 }
62 
63 void LoweringVisitorBase::visit(CONSTInst* I, bool copyOperands) {
64  assert(I);
65  VirtualRegister *reg = new VirtualRegister(I->get_type());
66  Immediate *imm = new Immediate(I);
67  MachineInstruction *move = backend->create_Move(imm,reg);
68  get_current()->push_back(move);
69  set_op(I,move->get_result().op);
70 }
71 
73  SourceStateInst *source_state) {
74  assert(MI);
75  assert(source_state);
76 
77  int op_index = 0;
78 
79  // lower javalocal dependencies
81  e = source_state->javalocal_end(); i != e; i++) {
83  Instruction *op = local.value->to_Instruction();
84  assert(op);
85  MachineOperand *mop = get_op(op);
86  MI->set_operand(op_index, mop);
87  MI->set_javalocal_index(op_index, local.index);
88  op_index++;
89  }
90 
91  // lower stackvar dependencies
93  e = source_state->stackvar_end(); i != e; i++) {
94  Instruction *op = (*i)->to_Instruction();
95  assert(op);
96  MachineOperand *mop = get_op(op);
97  MI->set_operand(op_index, mop);
98  MI->set_javalocal_index(op_index, RPLALLOC_STACK);
99  op_index++;
100  }
101 
102  // lower call-site parameter dependencies
103  for (SourceStateInst::const_param_iterator i = source_state->param_begin(),
104  e = source_state->param_end(); i != e; i++) {
105  Instruction *op = (*i)->to_Instruction();
106  assert(op);
107  MachineOperand *mop = get_op(op);
108  MI->set_operand(op_index, mop);
109  MI->set_javalocal_index(op_index, RPLALLOC_PARAM);
110  op_index++;
111  }
112 }
113 
115  SourceStateInst *source_state = I->get_source_state();
116 
117  if (source_state) {
118  MachineDeoptInst *deopt = new MachineDeoptInst(
119  source_state->get_source_location(), source_state->op_size());
120  lower_source_state_dependencies(deopt, source_state);
121  get_current()->push_back(deopt);
122  }
123 }
124 
125 void LoweringVisitorBase::visit(SourceStateInst* I, bool copyOperands) {
126  // A SouceStateInst is just an artificial instruction for holding metadata
127  // for ReplacementPointInsts. It has no direct pendant on LIR level and
128  // hence needs no lowering logic.
129 }
130 
132  SourceStateInst *source_state = I->get_source_state();
133  assert(source_state);
135  source_state->get_source_location(), source_state->op_size());
136  lower_source_state_dependencies(MI, source_state);
137  get_current()->push_back(MI);
138 }
139 
141  return *schedule->insert_after(get_current()->self_iterator(),MBBBuilder());
142 }
143 
144 
145 } // end namespace compiler2
146 } // end namespace jit
147 } // end namespace cacao
148 
149 
150 /*
151  * These are local overrides for various environment variables in Emacs.
152  * Please do not remove this and leave it at the end of the file, where
153  * Emacs will automagically detect them.
154  * ---------------------------------------------------------------------
155  * Local variables:
156  * mode: c++
157  * indent-tabs-mode: t
158  * c-basic-offset: 4
159  * tab-width: 4
160  * End:
161  * vim:noexpandtab:sw=4:ts=4:
162  */
void set_op(Instruction *I, MachineOperand *op) const
Definition: Backend.hpp:106
virtual MachineInstruction * create_Move(MachineOperand *src, MachineOperand *dst) const =0
virtual Instruction * to_Instruction()
Definition: Value.hpp:88
SourceStateInst * get_source_state() const
Get the SourceStateInst that corresponds to this Instruction.
void set_javalocal_index(std::size_t i, s4 javalocal_index)
Set the javalocal index of the i-th operand of this instruction.
Maps a HIR value to a baseline IR javalocal index.
const_javalocal_iterator javalocal_end() const
Type::TypeID get_type() const
get the value type of the instruction
Definition: Value.hpp:68
This Instruction marks the start of a basic block.
u2 op
Definition: disass.cpp:129
A basic block of (scheduled) machine instructions.
const_stackvar_iterator stackvar_begin() const
A point where the method can be entered through on-stack replacement.
Represents a point in the program, where it is possible to recover the source state to perform on-sta...
void set_operand(std::size_t i, MachineOperand *op)
virtual void visit(BeginInst *I, bool copyOperands)
Definition: Backend.cpp:41
const_param_iterator param_begin() const
const_param_iterator param_end() const
virtual MachineInstruction * create_Jump(MachineBasicBlock *target) const =0
const_javalocal_iterator javalocal_begin() const
Base type of instructions that can be mapped to a SourceStateInst.
SourceStateInst * get_source_state() const
Get the source state at this ReplacementEntryInst.
static Backend * factory(JITData *JD)
Definition: Backend.cpp:37
void push_back(MachineInstruction *value)
Appends the given element value to the end of the container.
StackvarListTy::const_iterator const_stackvar_iterator
JavalocalListTy::const_iterator const_javalocal_iterator
Provides a mapping from HIR values to baseline IR variables.
void insert_phi(MachinePhiInst *value)
Appends the given element value to the list of phis.
Instruction super class.
Definition: Instruction.hpp:75
const_stackvar_iterator stackvar_end() const
MIIterator i
MachineInstructionSchedule::iterator insert_after(iterator pos, const MBBBuilder &value)
inserts value after the element pointed to by pos
MIIterator e
Proxy to encode explicit and implicit successors.
MachineBasicBlock * get_current() const
Definition: Backend.hpp:121
#define I(value)
Definition: codegen.c:279
void lower_source_state_dependencies(MachineReplacementPointInst *MI, SourceStateInst *source_state)
Definition: Backend.cpp:72
ParamListTy::const_iterator const_param_iterator
Operands that can be directly used by the machine (register, memory, stackslot)
const MachineOperandDesc & get_result() const
MachineBasicBlock * new_block() const
Definition: Backend.cpp:140
MachineOperand * get_op(Instruction *I) const
Definition: Backend.hpp:100
std::size_t index
A baseline IR javalocal index.
void place_deoptimization_marker(SourceStateAwareInst *I)
Definition: Backend.cpp:114
Value * value
The value that is mapped to a baseline IR javalocal index.
MachineInstructionSchedule * schedule
Definition: Backend.hpp:89