CACAO
md-abi.cpp
Go to the documentation of this file.
1 /* src/vm/jit/alpha/md-abi.cpp - functions for Alpha ABI
2 
3  Copyright (C) 1996-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 
26 #include "config.h"
27 #include "vm/types.hpp"
28 
30 
31 #include "vm/descriptor.hpp"
32 #include "vm/global.hpp"
33 #include "vm/method.hpp"
34 
35 #include "vm/jit/abi.hpp"
36 #include "vm/jit/code.hpp"
37 
38 
39 /* register descripton array **************************************************/
40 
42  /* a0, a1, a2, a3, a4, a5, a6, a7, */
44 
45  /* r0, itmp1, itmp2, itmp3, t0, t1, t2, t3, */
47 
48  /* t4, t5, pv, s0, s1, s2, s3, s4, */
50 
51  /* s5, s6, s7, s8, s9, fp, lr, sp/zero, */
53 
54  REG_END
55 };
56 
57 const char *abi_registers_integer_name[] = {
58  "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
59  "r0", "it1", "it2", "it3", "t0", "t1", "t2", "t3",
60  "t4", "t5", "pv", "s0", "s1", "s2", "s3", "s4",
61  "s5", "s6", "s7", "s8", "s9", "fp", "lr", "sp"
62 };
63 
65  0, /* a0 */
66  1, /* a1 */
67  2, /* a2 */
68  3, /* a3 */
69  4, /* a4 */
70  5, /* a5 */
71  6, /* a6 */
72  7, /* a7 */
73 };
74 
76  19, /* s0 */
77  20, /* s1 */
78  21, /* s2 */
79  22, /* s3 */
80  23, /* s4 */
81  24, /* s5 */
82  25, /* s6 */
83  26, /* s7 */
84  27, /* s8 */
85  28, /* s9 */
86 };
87 
89  12, /* t0 */
90  13, /* t1 */
91  14, /* t2 */
92  15, /* t3 */
93  16, /* t4 */
94  17, /* t5 */
95 };
96 
97 
103  REG_END
104 };
105 
106 
108  0, /* fa0 */
109  1, /* fa1 */
110  2, /* fa2 */
111  3, /* fa3 */
112  4, /* fa4 */
113  5, /* fa5 */
114  6, /* fa6 */
115  7, /* fa7 */
116 };
117 
119  8, /* fs0 */
120  9, /* fs1 */
121  10, /* fs2 */
122  11, /* fs3 */
123  12, /* fs4 */
124  13, /* fs5 */
125  14, /* fs6 */
126  15, /* fs7 */
127 };
128 
130  19, /* ft0 */
131  20, /* ft1 */
132  21, /* ft2 */
133  22, /* ft3 */
134  23, /* ft4 */
135  24, /* ft5 */
136  25, /* ft6 */
137  26, /* ft7 */
138  27, /* ft8 */
139  28, /* ft9 */
140  29, /* ft10 */
141  30, /* ft11 */
142  31, /* ft12 */
143 };
144 
145 
146 /* md_param_alloc **************************************************************
147 
148  Allocate the parameters of the given method descriptor according to the
149  calling convention of the platform.
150 
151 *******************************************************************************/
152 
154 {
155  paramdesc *pd;
156  s4 i;
157  s4 reguse, freguse;
158  s4 stacksize;
159 
160  /* set default values */
161 
162  reguse = 0;
163  freguse = 0;
164  stacksize = 0;
165 
166  /* get params field of methoddesc */
167 
168  pd = md->params;
169 
170  for (i = 0; i < md->paramcount; i++, pd++) {
171  switch (md->paramtypes[i].type) {
172  case TYPE_INT:
173  case TYPE_ADR:
174  case TYPE_LNG:
175  if (reguse < INT_ARG_CNT) {
176  pd->inmemory = false;
177  pd->index = reguse;
179  reguse++;
180  md->argintreguse = reguse;
181  }
182  else {
183  pd->inmemory = true;
184  pd->index = stacksize;
185  pd->regoff = stacksize * 8;
186  stacksize++;
187  }
188  break;
189 
190  case TYPE_FLT:
191  case TYPE_DBL:
192  if (freguse < FLT_ARG_CNT) {
193  pd->inmemory = false;
194  pd->index = freguse;
195  pd->regoff = abi_registers_float_argument[freguse];
196  freguse++;
197  md->argfltreguse = freguse;
198  }
199  else {
200  pd->inmemory = true;
201  pd->index = stacksize;
202  pd->regoff = stacksize * 8;
203  stacksize++;
204  }
205  break;
206  default:
207  assert(false);
208  break;
209  }
210  }
211 
212  /* fill register and stack usage */
213 
214  md->memuse = stacksize;
215 }
216 
217 
218 /* md_param_alloc_native *******************************************************
219 
220  Pre-allocate arguments according to the native ABI.
221 
222 *******************************************************************************/
223 
225 {
226  /* On Alpha we use the same ABI for JIT method calls as for native
227  method calls. */
228 
229  md_param_alloc(md);
230 }
231 
232 
233 /* md_return_alloc *************************************************************
234 
235  Precolor the Java Stackelement containing the Return Value, if possible.
236 
237  --- in
238  jd: jitdata of the current method
239  stackslot: Java Stackslot to contain the Return Value
240 
241  --- out
242  if precoloring was possible:
243  VAR(stackslot->varnum)->flags = PREALLOC
244  ->vv.regoff = [REG_RESULT|REG_FRESULT]
245  rd->arg[flt|int]reguse set to a value according the register usage
246 
247  NOTE: Do not pass a LOCALVAR in stackslot->varnum.
248 *******************************************************************************/
249 
251 {
252  methodinfo *m;
253  codeinfo *code;
254  registerdata *rd;
255  methoddesc *md;
256 
257  /* get required compiler data */
258  m = jd->m;
259  code = jd->code;
260  rd = jd->rd;
261 
262  md = m->parseddesc;
263 
264  /* In Leafmethods Local Vars holding parameters are precolored to
265  their argument register -> so leafmethods with paramcount > 0
266  could already use R0 == a00! */
267 
268  if (!code_is_leafmethod(code) || (md->paramcount == 0)) {
269  /* Only precolor the stackslot, if it is not a SAVEDVAR <-> has
270  not to survive method invokations. */
271 
272  if (!(stackslot->flags & SAVEDVAR)) {
273 
274  VAR(stackslot->varnum)->flags = PREALLOC;
275 
276  if (IS_INT_LNG_TYPE(md->returntype.type)) {
277  if (rd->argintreguse < 1)
278  rd->argintreguse = 1;
279  VAR(stackslot->varnum)->vv.regoff = REG_RESULT;
280  } else {
281  if (rd->argfltreguse < 1)
282  rd->argfltreguse = 1;
283  VAR(stackslot->varnum)->vv.regoff = REG_FRESULT;
284  }
285  }
286  }
287 }
288 
289 
290 /*
291  * These are local overrides for various environment variables in Emacs.
292  * Please do not remove this and leave it at the end of the file, where
293  * Emacs will automagically detect them.
294  * ---------------------------------------------------------------------
295  * Local variables:
296  * mode: c++
297  * indent-tabs-mode: t
298  * c-basic-offset: 4
299  * tab-width: 4
300  * End:
301  * vim:noexpandtab:sw=4:ts=4:
302  */
const s4 abi_registers_float_argument[]
Definition: md-abi.cpp:107
void md_return_alloc(jitdata *jd, stackelement_t *stackslot)
Definition: md-abi.cpp:250
int argintreguse
Definition: reg.hpp:86
Definition: jit.hpp:126
paramdesc * params
Definition: descriptor.hpp:164
#define REG_SAV
Definition: jit.hpp:442
#define IS_INT_LNG_TYPE(a)
Definition: global.hpp:130
const s4 abi_registers_integer_argument[]
Definition: md-abi.cpp:64
codeinfo * code
Definition: jit.hpp:128
s4 nregdescint[]
Definition: md-abi.cpp:41
#define REG_FRESULT
Definition: md-abi.hpp:59
#define REG_END
Definition: jit.hpp:446
int32_t flags
Definition: stack.hpp:67
#define REG_RES
Definition: jit.hpp:439
const s4 abi_registers_integer_saved[]
Definition: md-abi.cpp:75
uint32_t index
Definition: descriptor.hpp:152
const s4 abi_registers_float_temporary[]
Definition: md-abi.cpp:129
#define VAR(i)
Definition: jit.hpp:252
static int code_is_leafmethod(codeinfo *code)
Definition: code.hpp:151
typedesc paramtypes[1]
Definition: descriptor.hpp:167
#define REG_RET
Definition: jit.hpp:440
const s4 abi_registers_float_saved[]
Definition: md-abi.cpp:118
#define INT_ARG_CNT
Definition: md-abi.hpp:74
const s4 abi_registers_integer_temporary[]
Definition: md-abi.cpp:88
MIIterator i
typedesc returntype
Definition: descriptor.hpp:166
int32_t s4
Definition: types.hpp:45
int argfltreguse
Definition: reg.hpp:89
registerdata * rd
Definition: jit.hpp:130
void md_param_alloc(methoddesc *md)
Definition: md-abi.cpp:153
bool inmemory
Definition: descriptor.hpp:151
const char * abi_registers_integer_name[]
Definition: md-abi.cpp:57
void md_param_alloc_native(methoddesc *md)
Definition: md-abi.cpp:224
methoddesc * parseddesc
Definition: method.hpp:78
methodinfo * m
Definition: jit.hpp:127
#define FLT_ARG_CNT
Definition: md-abi.hpp:81
#define REG_ARG
Definition: jit.hpp:444
#define REG_TMP
Definition: jit.hpp:443
s4 nregdescfloat[]
Definition: md-abi.cpp:98
int32_t varnum
Definition: stack.hpp:69
uint32_t regoff
Definition: descriptor.hpp:153
#define REG_RESULT
Definition: md-abi.hpp:33