CACAO
md-abi.cpp
Go to the documentation of this file.
1 /* src/vm/jit/powerpc/darwin/md-abi.cpp - PowerPC Darwin 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 <stdint.h>
29 
31 
32 #include "vm/descriptor.hpp"
33 #include "vm/global.hpp"
34 #include "vm/method.hpp"
35 
36 #include "vm/jit/abi.hpp"
37 #include "vm/jit/code.hpp"
38 #include "vm/jit/codegen-common.hpp" // for PACK_REGS
39 #include "vm/jit/stack.hpp"
40 
41 
42 /* register descripton arrays *************************************************/
43 
44 int nregdescint[] = {
45  /* zero, sp, t0, a0/v0, a0/v1, a2, a3, a4, */
47 
48  /* a5, a6, a7, itmp1, itmp2, pv, s0, s1, */
50 
51  /*itmp3, t1, t2, t3, t4, t5, t6, t7, */
53 
54  /* s2, s3, s4, s5, s6, s7, s8, s9, */
56 
57  REG_END
58 };
59 
60 const char *abi_registers_integer_name[] = {
61  "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
62  "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
63  "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
64  "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
65 };
66 
68  3, /* a0 */
69  4, /* a1 */
70  5, /* a2 */
71  6, /* a3 */
72  7, /* a4 */
73  8, /* a5 */
74  9, /* a6 */
75  10, /* a7 */
76 };
77 
79  14, /* s0 */
80  15, /* s1 */
81  24, /* s2 */
82  25, /* s3 */
83  26, /* s4 */
84  27, /* s5 */
85  28, /* s6 */
86  29, /* s7 */
87  30, /* s8 */
88  31, /* s9 */
89 };
90 
92  2, /* t0 */
93  17, /* t1 */
94  18, /* t2 */
95  19, /* t3 */
96  20, /* t4 */
97  21, /* t5 */
98  22, /* t6 */
99  23, /* t7 */
100 };
101 
102 
103 int nregdescfloat[] = {
104  /*ftmp3, fa0/v0, fa1, fa2, fa3, fa4, fa5, fa6, */
106 
107  /* fa7, fa8, fa9, fa10, fa11, fa12, fs0, fs1, */
109 
110  /*ftmp1, ftmp2, ft0, ft1, ft2, ft3, ft4, ft5, */
112 
113  /* fs2, fs3, fs4, fs5, fs6, fs7, fs8, fs9 */
115 
116  REG_END
117 };
118 
120  1, /* fa0 */
121  2, /* fa1 */
122  3, /* fa2 */
123  4, /* fa3 */
124  5, /* fa4 */
125  6, /* fa5 */
126  7, /* fa6 */
127  8, /* fa7 */
128  9, /* fa8 */
129  10, /* fa9 */
130  11, /* fa10 */
131  12, /* fa11 */
132  13, /* fa12 */
133 };
134 
136  14, /* fs0 */
137  15, /* fs1 */
138  24, /* fs2 */
139  25, /* fs3 */
140  26, /* fs4 */
141  27, /* fs5 */
142  28, /* fs6 */
143  29, /* fs7 */
144  30, /* fs8 */
145  31, /* fs9 */
146 };
147 
149  17, /* ft5 */
150  18, /* ft6 */
151  19, /* ft7 */
152  20, /* ft8 */
153  21, /* ft9 */
154  22, /* ft10 */
155  23, /* ft11 */
156 };
157 
158 
159 /* md_param_alloc **************************************************************
160 
161  Allocate Arguments to Stackslots according the Calling Conventions
162 
163  --- in
164  md->paramcount: Number of arguments for this method
165  md->paramtypes[].type: Argument types
166 
167  --- out
168  md->params[].inmemory: Argument spilled on stack
169  md->params[].regoff: Stack offset or rd->arg[int|flt]regs index
170  md->memuse: Stackslots needed for argument spilling
171  md->argintreguse: max number of integer arguments used
172  md->argfltreguse: max number of float arguments used
173 
174 *******************************************************************************/
175 
177 {
178  paramdesc *pd;
179  int i;
180  int iarg;
181  int farg;
182  int stacksize;
183 
184  /* set default values */
185 
186  iarg = 0;
187  farg = 0;
188  stacksize = LA_SIZE_IN_POINTERS;
189 
190  /* get params field of methoddesc */
191 
192  pd = md->params;
193 
194  for (i = 0; i < md->paramcount; i++, pd++) {
195  switch (md->paramtypes[i].type) {
196  case TYPE_INT:
197  case TYPE_ADR:
198  if (iarg < INT_ARG_CNT) {
199  pd->inmemory = false;
200  pd->index = iarg;
202  iarg++;
203  }
204  else {
205  pd->inmemory = true;
206  pd->index = stacksize;
207  pd->regoff = stacksize * 8;
208  stacksize++;
209  }
210  break;
211 
212  case TYPE_LNG:
213  if (iarg < INT_ARG_CNT - 1) {
214  pd->inmemory = false;
215  pd->index = PACK_REGS(iarg + 1, iarg);
216  pd->regoff =
219  iarg += 2;
220  }
221  else {
222  pd->inmemory = true;
223  pd->index = stacksize;
224  pd->regoff = stacksize * 8;
225  iarg = INT_ARG_CNT;
226  stacksize++;
227  }
228  break;
229 
230  case TYPE_FLT:
231  case TYPE_DBL:
232  if (farg < FLT_ARG_CNT) {
233  pd->inmemory = false;
234  pd->index = farg;
236  farg++;
237  }
238  else {
239  pd->inmemory = true;
240  pd->index = stacksize;
241  pd->regoff = stacksize * 8;
242  stacksize++;
243  }
244  break;
245  }
246  }
247 
248 
249  /* Since R3/R4, F1 (==A0/A1, A0) are used for passing return values, this */
250  /* argument register usage has to be regarded, too */
251 
252  if (IS_INT_LNG_TYPE(md->returntype.type)) {
253  if (iarg < (IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1))
254  iarg = IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1;
255  }
256  else {
258  if (farg < 1)
259  farg = 1;
260  }
261 
262  /* fill register and stack usage */
263 
264  md->argintreguse = iarg;
265  md->argfltreguse = farg;
266  md->memuse = stacksize;
267 }
268 
269 
270 /* md_param_alloc_native *******************************************************
271 
272  Pre-allocate arguments according the native ABI.
273 
274 *******************************************************************************/
275 
277 {
278  paramdesc *pd;
279  int i;
280  int iarg;
281  int farg;
282  int stacksize;
283 
284  /* set default values */
285 
286  iarg = 0;
287  farg = 0;
288  stacksize = LA_SIZE_IN_POINTERS;
289 
290  /* get params field of methoddesc */
291 
292  pd = md->params;
293 
294  for (i = 0; i < md->paramcount; i++, pd++) {
295  switch (md->paramtypes[i].type) {
296  case TYPE_INT:
297  case TYPE_ADR:
298  if (iarg < INT_ARG_CNT) {
299  pd->inmemory = false;
301  iarg++;
302  }
303  else {
304  pd->inmemory = true;
305  pd->regoff = stacksize * 4;
306  }
307  stacksize++;
308  break;
309 
310  case TYPE_LNG:
311  if (iarg < INT_ARG_CNT - 1) {
312  pd->inmemory = false;
313  pd->regoff =
316  iarg += 2;
317  }
318  else {
319  pd->inmemory = true;
320  pd->regoff = stacksize * 4;
321  iarg = INT_ARG_CNT;
322  }
323  stacksize += 2;
324  break;
325 
326  case TYPE_FLT:
327  if (farg < FLT_ARG_CNT) {
328  pd->inmemory = false;
330  iarg++; /* skip 1 integer argument register */
331  farg++;
332  }
333  else {
334  pd->inmemory = true;
335  pd->regoff = stacksize * 4;
336  }
337  stacksize++;
338  break;
339 
340  case TYPE_DBL:
341  if (farg < FLT_ARG_CNT) {
342  pd->inmemory = false;
344  iarg += 2; /* skip 2 integer argument registers */
345  farg++;
346  }
347  else {
348  pd->inmemory = true;
349  pd->regoff = stacksize * 4;
350  }
351  stacksize += 2;
352  break;
353  }
354  }
355 
356 
357  /* Since R3/R4, F1 (==A0/A1, A0) are used for passing return values, this */
358  /* argument register usage has to be regarded, too */
359 
360  if (IS_INT_LNG_TYPE(md->returntype.type)) {
361  if (iarg < (IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1))
362  iarg = IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1;
363  }
364  else {
366  if (farg < 1)
367  farg = 1;
368  }
369 
370  /* fill register and stack usage */
371 
372  md->argintreguse = iarg;
373  md->argfltreguse = farg;
374  md->memuse = stacksize;
375 }
376 
377 
378 /* md_return_alloc *************************************************************
379 
380  Precolor the Java Stackelement containing the Return Value, if
381  possible. (R3==a00 for int/adr, R4/R3 == a01/a00 for long, F1==a00
382  for float/double)
383 
384  --- in
385  jd: jitdata of the current method
386  stackslot: Java Stackslot to contain the Return Value
387 
388  --- out
389  if precoloring was possible:
390  VAR(stackslot->varnum)->flags = PREALLOC
391  ->regoff = [REG_RESULT|REG_FRESULT]
392  rd->arg[flt|int]reguse set to a value according the register usage
393 
394  NOTE: Do not pass a LOCALVAR in stackslot->varnum.
395 
396 *******************************************************************************/
397 
399 {
400  methodinfo *m;
401  codeinfo *code;
402  registerdata *rd;
403  methoddesc *md;
404 
405  /* get required compiler data */
406 
407  m = jd->m;
408  code = jd->code;
409  rd = jd->rd;
410 
411  md = m->parseddesc;
412 
413  /* In Leafmethods Local Vars holding parameters are precolored to
414  their argument register -> so leafmethods with paramcount > 0
415  could already use R3 == a00! */
416 
417  if (!code_is_leafmethod(code) || (md->paramcount == 0)) {
418  /* Only precolor the stackslot, if it is not a SAVEDVAR <->
419  has not to survive method invokations. */
420 
421  if (!(stackslot->flags & SAVEDVAR)) {
422 
423  VAR(stackslot->varnum)->flags = PREALLOC;
424 
425  if (IS_INT_LNG_TYPE(md->returntype.type)) {
426  if (!IS_2_WORD_TYPE(md->returntype.type)) {
427  if (rd->argintreguse < 1)
428  rd->argintreguse = 1;
429 
430  VAR(stackslot->varnum)->vv.regoff = REG_RESULT;
431  }
432  else {
433  if (rd->argintreguse < 2)
434  rd->argintreguse = 2;
435 
436  VAR(stackslot->varnum)->vv.regoff = REG_RESULT_PACKED;
437  }
438  }
439  else {
440  if (rd->argfltreguse < 1)
441  rd->argfltreguse = 1;
442 
443  VAR(stackslot->varnum)->vv.regoff = REG_FRESULT;
444  }
445  }
446  }
447 }
448 
449 
450 /*
451  * These are local overrides for various environment variables in Emacs.
452  * Please do not remove this and leave it at the end of the file, where
453  * Emacs will automagically detect them.
454  * ---------------------------------------------------------------------
455  * Local variables:
456  * mode: c++
457  * indent-tabs-mode: t
458  * c-basic-offset: 4
459  * tab-width: 4
460  * End:
461  * vim:noexpandtab:sw=4:ts=4:
462  */
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 IS_2_WORD_TYPE(a)
Definition: global.hpp:132
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
int argfltreguse
Definition: reg.hpp:89
registerdata * rd
Definition: jit.hpp:130
void md_param_alloc(methoddesc *md)
Definition: md-abi.cpp:153
#define PACK_REGS(low, high)
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
#define REG_RESULT_PACKED
Definition: md-abi.hpp:133