CACAO
md-abi.cpp
Go to the documentation of this file.
1 /* src/vm/jit/powerpc64/linux/md-abi.cpp - functions for PowerPC64 Linux 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 
28 #include <cassert>
29 
30 #include "vm/types.hpp"
31 
33 
34 #include "vm/descriptor.hpp"
35 #include "vm/global.hpp"
36 #include "vm/method.hpp"
37 
38 #include "vm/jit/abi.hpp"
39 #include "vm/jit/code.hpp"
40 #include "vm/jit/stack.hpp"
41 
42 
43 /* register descripton array **************************************************/
44 
46  /* zero, sp, TOC, a0/v0, a1/v1, a2, a3, a4, */
48 
49  /* a5, a6, a7, itmp1, itmp2, NO(SYS), pv, s0, */
51 
52  /*itmp3, t0, t1, t2, t3, t4, t5, t6, */
54 
55  /* s1, s2, s3, s4, s5, s6, s7, s8, */
57 
58  REG_END
59 };
60 
61 const char *abi_registers_integer_name[] = {
62  "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
63  "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
64  "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
65  "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
66 };
67 
69  3, /* a0 */
70  4, /* a1 */
71  5, /* a2 */
72  6, /* a3 */
73  7, /* a4 */
74  8, /* a5 */
75  9, /* a6 */
76  10, /* a7 */
77 };
78 
80  15, /* s0 */
81  24, /* s1 */
82  25, /* s2 */
83  26, /* s3 */
84  27, /* s4 */
85  28, /* s5 */
86  29, /* s6 */
87  30, /* s7 */
88  31, /* s8 */
89 };
90 
92  17, /* t0 */
93  18, /* t1 */
94  19, /* t2 */
95  20, /* t3 */
96  21, /* t4 */
97  22, /* t5 */
98  23, /* t6 */
99 };
100 
101 
103  /*ftmp3, fa0/v0, fa1, fa2, fa3, fa4, fa5, fa6, */
105 
106  /* fa7, fa8, fa9, fa10, fa11, fa12, fs0, fs1, */
108 
109  /* ftmp1, ftmp2, fs2, fs3, fs4, fs5, fs6, fs7 */
111 
112  /* fs8, fs9, fs10, fs11, fs12, fs13, fs14, fs15 */
114 
115  REG_END
116 };
117 
119  1, /* fa0 */
120  2, /* fa1 */
121  3, /* fa2 */
122  4, /* fa3 */
123  5, /* fa4 */
124  6, /* fa5 */
125  7, /* fa6 */
126  8, /* fa7 */
127  9, /* fa8 */
128  10, /* fa9 */
129  11, /* fa10 */
130  12, /* fa11 */
131  13, /* fa12 */
132 };
133 
135  14, /* fs0 */
136  15, /* fs1 */
137  18, /* fs2 */
138  19, /* fs3 */
139  20, /* fs4 */
140  21, /* fs5 */
141  22, /* fs6 */
142  23, /* fs7 */
143  24, /* fs8 */
144  25, /* fs9 */
145  26, /* fs10 */
146  27, /* fs11 */
147  28, /* fs12 */
148  29, /* fs13 */
149  30, /* fs14 */
150  31, /* fs15 */
151 };
152 
154  -1,
155 };
156 
157 
158 /* md_param_alloc **************************************************************
159 
160  Allocate Arguments to Stackslots according the Calling Conventions
161 
162  --- in
163  md->paramcount: Number of arguments for this method
164  md->paramtypes[].type: Argument types
165 
166  --- out
167  md->params[].inmemory: Argument spilled on stack
168  md->params[].regoff: Stack offset or rd->arg[int|flt]regs index
169  md->memuse: Stackslots needed for argument spilling
170  md->argintreguse: max number of integer arguments used
171  md->argfltreguse: max number of float arguments used
172 
173 *******************************************************************************/
174 
176 {
177  paramdesc *pd;
178  s4 i;
179  s4 iarg;
180  s4 farg;
181  s4 arg;
182  s4 stacksize, stackcount;
183 
184 
185  /* set default values */
186 
187  iarg = 0;
188  farg = 0;
189  arg = 0;
190  stacksize = LA_SIZE_IN_POINTERS;
191  stackcount = 0;
192 
193  /* get params field of methoddesc */
194 
195  pd = md->params;
196 
197  for (i = 0; i < md->paramcount; i++, pd++) {
198  switch (md->paramtypes[i].type) {
199  case TYPE_LNG:
200  case TYPE_INT:
201  case TYPE_ADR:
202  if (iarg < INT_ARG_CNT) {
203  pd->inmemory = false;
204  pd->index = iarg;
206  iarg++;
207  }
208  else {
209  pd->inmemory = true;
210  pd->index = stacksize + stackcount;
211  pd->regoff = (stacksize + stackcount) * 8;
212  }
213  break;
214  case TYPE_FLT:
215  case TYPE_DBL:
216  if (farg < FLT_ARG_CNT) {
217  pd->inmemory = false;
218  pd->index = farg;
220  farg++;
221  if (arg < INT_ARG_CNT) {
222  iarg++; /* yes, that is true, floating arguments take int register slots away */
223  }
224  }
225  else {
226  pd->inmemory = true;
227  pd->index = stacksize + stackcount;
228  pd->regoff = (stacksize + stackcount) * 8;
229  }
230  break;
231  default:
232  assert(0);
233  }
234  arg++;
235  stackcount++;
236  }
237 
238  /* Since R3, F1 (==A0, A0) are used for passing return values, this */
239  /* argument register usage has to be regarded, too */
240  if (IS_INT_LNG_TYPE(md->returntype.type)) {
241  if (iarg < 1)
242  iarg = 1;
243  }
244  else if (IS_FLT_DBL_TYPE(md->returntype.type)) {
245  if (farg < 1)
246  farg = 1;
247  }
248 
249  /* fill register and stack usage, parameter areas is at least PA_SIZE_IN_POINTERS */
250 
251  md->argintreguse = iarg;
252  md->argfltreguse = farg;
253  md->memuse = stacksize + (stackcount<PA_SIZE_IN_POINTERS? PA_SIZE_IN_POINTERS: stackcount);
254 }
255 
256 
257 /* md_param_alloc_native *******************************************************
258 
259  Pre-allocate arguments according the native ABI.
260 
261 *******************************************************************************/
262 
264 {
265  /* On PowerPC64 we use the same ABI for JIT method calls as for
266  native method calls. */
267 
268  md_param_alloc(md);
269 }
270 
271 
272 /* md_return_alloc *************************************************************
273 
274  Precolor the Java Stackelement containing the Return Value, if
275  possible. (R3==a00 for int/adr, R4/R3 == a01/a00 for long, F1==a00
276  for float/double)
277 
278  --- in
279  jd: jitdata of the current method
280  stackslot: Java Stackslot to contain the Return Value
281 
282  --- out
283  if precoloring was possible:
284  VAR(stackslot->varnum)->flags = PREALLOC
285  VAR(stackslot->varnum)->vv.regoff = [REG_RESULT, REG_FRESULT]
286  rd->arg[flt|int]reguse set to a value according the register usage
287 
288 *******************************************************************************/
289 
291 {
292  methodinfo *m;
293  codeinfo *code;
294  registerdata *rd;
295  methoddesc *md;
296 
297  /* get required compiler data */
298 
299  m = jd->m;
300  code = jd->code;
301  rd = jd->rd;
302 
303  md = m->parseddesc;
304 
305  /* In Leafmethods Local Vars holding parameters are precolored to
306  their argument register -> so leafmethods with paramcount > 0
307  could already use R3 == a00! */
308 
309  if (!code_is_leafmethod(code) || (md->paramcount == 0)) {
310  /* Only precolor the stackslot, if it is not a SAVEDVAR <->
311  has not to survive method invokations. */
312 
313  if (!(stackslot->flags & SAVEDVAR)) {
314 
315  VAR(stackslot->varnum)->flags = PREALLOC;
316 
317  if (IS_INT_LNG_TYPE(md->returntype.type)) {
318  if (rd->argintreguse < 1)
319  rd->argintreguse = 1;
320 
321  VAR(stackslot->varnum)->vv.regoff = REG_RESULT;
322  } else { /* float/double */
323  if (rd->argfltreguse < 1)
324  rd->argfltreguse = 1;
325 
326  VAR(stackslot->varnum)->vv.regoff = REG_FRESULT;
327  }
328  }
329  }
330 }
331 
332 
333 /*
334  * These are local overrides for various environment variables in Emacs.
335  * Please do not remove this and leave it at the end of the file, where
336  * Emacs will automagically detect them.
337  * ---------------------------------------------------------------------
338  * Local variables:
339  * mode: c++
340  * indent-tabs-mode: t
341  * c-basic-offset: 4
342  * tab-width: 4
343  * End:
344  * vim:noexpandtab:sw=4:ts=4:
345  */
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
#define PA_SIZE_IN_POINTERS
Definition: md-abi.hpp:88
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
JNIEnv void * arg
Definition: jvmti.h:405
const s4 abi_registers_float_saved[]
Definition: md-abi.cpp:118
#define IS_FLT_DBL_TYPE(a)
Definition: global.hpp:131
#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
#define LA_SIZE_IN_POINTERS
Definition: md-abi.hpp:95