CACAO
MethodC2.cpp
Go to the documentation of this file.
1 /* src/vm/jit/compiler2/Method.cpp - Method
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 
29 
30 #include "vm/method.hpp"
31 #include "vm/class.hpp"
32 #include "vm/descriptor.hpp"
33 #include "vm/jit/jit.hpp"
34 
35 #include <cassert>
36 #include <algorithm>
37 
38 namespace cacao {
39 namespace jit {
40 namespace compiler2 {
41 
42 Method::Method(methodinfo *m) : class_name_utf8(m->clazz->name),
43  method_name_utf8(m->name), method_desc_utf8(m->descriptor) {
44  assert(m);
45  methoddesc *md = m->parseddesc;
46  assert(md);
47  assert(md->paramtypes);
50 
51 
52  for (int i = 0, slot = 0; i < md->paramcount; ++i) {
53  int type = md->paramtypes[i].type;
54  MD[i] = convert_var_type(type);
55  /*
56  int varindex = jd->local_map[slot * 5 + type];
57  assert(varindex != UNUSED);
58  */
59 
60  switch (type) {
61  case TYPE_LNG:
62  case TYPE_DBL:
63  slot +=2;
64  break;
65  default:
66  ++slot;
67  }
68  }
69 }
70 
72  delete method_desc;
73  #if 0
74  for(InstructionListTy::iterator i = inst_list.begin(),
75  e = inst_list.end(); i != e ; ++i) {
76  Instruction *I = *i;
77  delete I;
78  }
79  #endif
80 }
81 
83  assert(I);
84  I->set_Method(this);
85  assert(std::find(inst_list.begin(), inst_list.end(),I) == inst_list.end());
86  inst_list.push_back(I);
87 }
88 
90  inst_list.remove(I);
91  #if 0
92  std::replace(inst_list.begin(), inst_list.end(),I,(Instruction*)0);
93  #endif
94  delete I;
95 }
96 
98  add_Instruction(bi);
99  bb_list.push_back(bi);
100 }
101 
103  bb_list.remove(bi);
104  remove_Instruction(bi);
105 }
106 
108  // clear schedule
109  for (InstructionListTy::const_iterator i = begin(),
110  e = end() ; i != e ; ++i) {
111  if ((*i)->is_floating()) {
112  (*i)->set_BeginInst(NULL);
113  }
114  }
115 }
116 
118  assert(pred);
119  assert(succ);
120  int pred_idx = succ->get_predecessor_index(pred);
121  int succ_idx = pred->get_successor_index(succ);
122  assert(pred_idx != -1);
123  assert(succ_idx != -1);
124  // setpu new block
125  BeginInst* BI = new BeginInst();
126  EndInst* EI = new GOTOInst(BI);
127  EI->succ_list.push_back(BeginInstRef(succ));
128  BI->pred_list.push_back(pred);
129  // insert new block
130  succ->set_predecessor(pred_idx,BI);
131  pred->set_successor(succ_idx,BI);
132  // add to method
133  add_bb(BI);
134  add_Instruction(EI);
135 
136  return BI;
137 }
138 
140  return OS << M.get_class_name_utf8() << '#' << M.get_name_utf8() << M.get_desc_utf8();
141 }
142 
143 } // end namespace cacao
144 } // end namespace jit
145 } // end namespace compiler2
146 
147 /*
148  * These are local overrides for various environment variables in Emacs.
149  * Please do not remove this and leave it at the end of the file, where
150  * Emacs will automagically detect them.
151  * ---------------------------------------------------------------------
152  * Local variables:
153  * mode: c++
154  * indent-tabs-mode: t
155  * c-basic-offset: 4
156  * tab-width: 4
157  * End:
158  * vim:noexpandtab:sw=4:ts=4:
159  */
160 
const Utf8String & get_name_utf8() const
Definition: MethodC2.hpp:85
jlong jlong jlong jlong jint jmethodID jint slot
Definition: jvmti.h:497
BeginInst * get_edge_block(BeginInst *pred, BeginInst *succ)
Get a BeginInst representing an edge.
Definition: MethodC2.cpp:117
This Instruction mark the start of a basic block.
This Instruction mark the end of a basic block.
void set_successor(int index, BeginInst *BI)
void remove_Instruction(Instruction *I)
Remove an Instruction for a Method.
Definition: MethodC2.cpp:89
int get_successor_index(const BeginInst *BI) const
JNIEnv jclass jobject const char * name
Definition: jvmti.h:312
const Utf8String & get_desc_utf8() const
Definition: MethodC2.hpp:87
typedesc paramtypes[1]
Definition: descriptor.hpp:167
this stores a reference to a begin instruction
int get_predecessor_index(const BeginInst *BI) const
MethodDescriptor * method_desc
Definition: MethodC2.hpp:77
void remove_bb(BeginInst *bi)
Remove BeginInst.
Definition: MethodC2.cpp:102
Simple stream class for formatted output.
Definition: OStream.hpp:141
Instruction super class.
Definition: Instruction.hpp:73
OStream & operator<<(OStream &OS, const Conditional::CondID &cond)
Definition: Conditional.cpp:34
void add_Instruction(Instruction *I)
Add instructions to a Method.
Definition: MethodC2.cpp:82
MIIterator i
const_iterator end() const
Definition: MethodC2.hpp:141
OStream & OS
MIIterator e
const Utf8String & get_class_name_utf8() const
Definition: MethodC2.hpp:86
Type::TypeID convert_var_type(int type)
Definition: Type.cpp:51
void set_predecessor(int index, BeginInst *BI)
methoddesc * parseddesc
Definition: method.hpp:78
#define I(value)
Definition: codegen.c:279
InstructionListTy inst_list
This is were the instructions live.
Definition: MethodC2.hpp:74
void add_bb(BeginInst *bi)
Add a BeginInst.
Definition: MethodC2.cpp:97
const Method & M
const_iterator begin() const
Definition: MethodC2.hpp:137
MethodDescriptor TODO: more info.