CACAO
md-abi.cpp
Go to the documentation of this file.
1 /* src/vm/jit/powerpc/linux/md-abi.cpp - functions for PowerPC 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 #include <stdint.h>
30 
32 
33 #include "vm/descriptor.hpp"
34 #include "vm/global.hpp"
35 #include "vm/method.hpp"
36 
37 #include "vm/jit/abi.hpp"
38 #include "vm/jit/code.hpp"
39 #include "vm/jit/codegen-common.hpp" // for PACK_REGS
40 #include "vm/jit/stack.hpp"
41 
42 
43 /* register descripton arrays *************************************************/
44 
45 int nregdescint[] = {
46  /* zero, sp, NO(sys), a0/v0, a1/v1, a2, a3, a4, */
48 
49  /* a5, a6, a7, itmp1, itmp2, pv, s0, s1, */
51 
52  /*itmp3, t0, t1, t2, t3, t4, t5, t6, */
54 
55  /* s2, s3, s4, s5, s6, s7, s8, s9, */
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  14, /* s0 */
81  15, /* s1 */
82  24, /* s2 */
83  25, /* s3 */
84  26, /* s4 */
85  27, /* s5 */
86  28, /* s6 */
87  29, /* s7 */
88  30, /* s8 */
89  31, /* s9 */
90 };
91 
93  17, /* t0 */
94  18, /* t1 */
95  19, /* t2 */
96  20, /* t3 */
97  21, /* t4 */
98  22, /* t5 */
99  23, /* t6 */
100 };
101 
102 
103 int nregdescfloat[] = {
104  /*ftmp3, fa0/v0, fa1, fa2, fa3, fa4, fa5, fa6, */
106 
107  /* fa7, ft0, ft1, ft2, ft3, ft4, fs0, fs1, */
109 
110  /*ftmp1, ftmp2, ft5, ft6, ft7, ft8, ft9, ft10, */
112 
113  /* fs2, fs3, fs4, fs5, fs6, fs7, fs8, fs9 */
115 
116  REG_END
117 };
118 
119 
121  1, /* fa0 */
122  2, /* fa1 */
123  3, /* fa2 */
124  4, /* fa3 */
125  5, /* fa4 */
126  6, /* fa5 */
127  7, /* fa6 */
128  8, /* fa7 */
129 };
130 
132  14, /* fs0 */
133  15, /* fs1 */
134  24, /* fs2 */
135  25, /* fs3 */
136  26, /* fs4 */
137  27, /* fs5 */
138  28, /* fs6 */
139  29, /* fs7 */
140  30, /* fs8 */
141  31, /* fs9 */
142 };
143 
145  9, /* ft0 */
146  10, /* ft1 */
147  11, /* ft2 */
148  12, /* ft3 */
149  13, /* ft4 */
150  18, /* ft5 */
151  19, /* ft6 */
152  20, /* ft7 */
153  21, /* ft8 */
154  22, /* ft9 */
155  23, /* ft10 */
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  ALIGN_2(iarg);
215  pd->inmemory = false;
216  pd->index = PACK_REGS(iarg + 1, iarg);
217  pd->regoff =
220  iarg += 2;
221  }
222  else {
223  pd->inmemory = true;
224  pd->index = stacksize;
225  pd->regoff = stacksize * 8;
226  iarg = INT_ARG_CNT;
227  stacksize++;
228  }
229  break;
230 
231  case TYPE_FLT:
232  case TYPE_DBL:
233  if (farg < FLT_ARG_CNT) {
234  pd->inmemory = false;
235  pd->index = farg;
237  farg++;
238  }
239  else {
240  pd->inmemory = true;
241  pd->index = stacksize;
242  pd->regoff = stacksize * 8;
243  stacksize++;
244  }
245  break;
246 
247  default:
248  assert(false);
249  break;
250  }
251  }
252 
253  /* Since R3/R4, F1 (==A0/A1, A0) are used for passing return
254  values, this argument register usage has to be regarded,
255  too. */
256 
257  if (IS_INT_LNG_TYPE(md->returntype.type)) {
258  if (iarg < (IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1))
259  iarg = IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1;
260  }
261  else {
263  if (farg < 1)
264  farg = 1;
265  }
266 
267  /* fill register and stack usage */
268 
269  md->argintreguse = iarg;
270  md->argfltreguse = farg;
271  md->memuse = stacksize;
272 }
273 
274 
275 /* md_param_alloc_native *******************************************************
276 
277  Pre-allocate arguments according the native ABI.
278 
279 *******************************************************************************/
280 
282 {
283  paramdesc *pd;
284  int i;
285  int iarg;
286  int farg;
287  int stacksize;
288 
289  /* set default values */
290 
291  iarg = 0;
292  farg = 0;
293  stacksize = LA_SIZE_IN_POINTERS;
294 
295  /* get params field of methoddesc */
296 
297  pd = md->params;
298 
299  for (i = 0; i < md->paramcount; i++, pd++) {
300  switch (md->paramtypes[i].type) {
301  case TYPE_INT:
302  case TYPE_ADR:
303  if (iarg < INT_ARG_CNT) {
304  pd->inmemory = false;
306  iarg++;
307  }
308  else {
309  pd->inmemory = true;
310  pd->regoff = stacksize * 4;
311  stacksize++;
312  }
313  break;
314 
315  case TYPE_LNG:
316  if (iarg < INT_ARG_CNT - 1) {
317  ALIGN_2(iarg);
318  pd->inmemory = false;
319  pd->regoff =
322  iarg += 2;
323  }
324  else {
325  ALIGN_2(stacksize);
326  pd->inmemory = true;
327  pd->regoff = stacksize * 4;
328  iarg = INT_ARG_CNT;
329  stacksize += 2;
330  }
331  break;
332 
333  case TYPE_FLT:
334  if (farg < FLT_ARG_CNT) {
335  pd->inmemory = false;
337  farg++;
338  }
339  else {
340  pd->inmemory = true;
341  pd->regoff = stacksize * 4;
342  stacksize++;
343  }
344  break;
345 
346  case TYPE_DBL:
347  if (farg < FLT_ARG_CNT) {
348  pd->inmemory = false;
350  farg++;
351  }
352  else {
353  ALIGN_2(stacksize);
354  pd->inmemory = true;
355  pd->regoff = stacksize * 4;
356  stacksize += 2;
357  }
358  break;
359 
360  default:
361  assert(false);
362  break;
363  }
364  }
365 
366  /* Since R3/R4, F1 (==A0/A1, A0) are used for passing return
367  values, this argument register usage has to be regarded,
368  too. */
369 
370  if (IS_INT_LNG_TYPE(md->returntype.type)) {
371  if (iarg < (IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1))
372  iarg = IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1;
373  }
374  else {
376  if (farg < 1)
377  farg = 1;
378  }
379 
380  /* fill register and stack usage */
381 
382  md->argintreguse = iarg;
383  md->argfltreguse = farg;
384  md->memuse = stacksize;
385 }
386 
387 
388 /* md_return_alloc *************************************************************
389 
390  Precolor the Java Stackelement containing the Return Value, if
391  possible. (R3==a00 for int/adr, R4/R3 == a01/a00 for long, F1==a00
392  for float/double)
393 
394  --- in
395  jd: jitdata of the current method
396  stackslot: Java Stackslot to contain the Return Value
397 
398  --- out
399  if precoloring was possible:
400  VAR(stackslot->varnum)->flags = PREALLOC
401  ->regoff = [REG_RESULT|REG_FRESULT]
402  rd->arg[flt|int]reguse set to a value according the register usage
403 
404  NOTE: Do not pass a LOCALVAR in stackslot->varnum.
405 
406 *******************************************************************************/
407 
409 {
410  methodinfo *m;
411  codeinfo *code;
412  registerdata *rd;
413  methoddesc *md;
414  varinfo *v;
415 
416  /* get required compiler data */
417 
418  m = jd->m;
419  code = jd->code;
420  rd = jd->rd;
421 
422  md = m->parseddesc;
423 
424  /* In Leafmethods Local Vars holding parameters are precolored to
425  their argument register -> so leafmethods with paramcount > 0
426  could already use R3 == a00! */
427 
428  if (!code_is_leafmethod(code) || (md->paramcount == 0)) {
429  /* Only precolor the stackslot, if it is not a SAVEDVAR <->
430  has not to survive method invokations. */
431 
432  if (!(stackslot->flags & SAVEDVAR)) {
433  v = VAR(stackslot->varnum);
434  v->flags = PREALLOC;
435 
436  switch (md->returntype.type) {
437  case TYPE_INT:
438  case TYPE_ADR:
439  if (rd->argintreguse < 1)
440  rd->argintreguse = 1;
441 
442  v->vv.regoff = REG_RESULT;
443  break;
444 
445  case TYPE_LNG:
446  if (rd->argintreguse < 2)
447  rd->argintreguse = 2;
448 
450  break;
451 
452  case TYPE_FLT:
453  case TYPE_DBL:
454  if (rd->argfltreguse < 1)
455  rd->argfltreguse = 1;
456 
457  v->vv.regoff = REG_FRESULT;
458  break;
459 
460  default:
461  break;
462  }
463  }
464  }
465 }
466 
467 
468 /*
469  * These are local overrides for various environment variables in Emacs.
470  * Please do not remove this and leave it at the end of the file, where
471  * Emacs will automagically detect them.
472  * ---------------------------------------------------------------------
473  * Local variables:
474  * mode: c++
475  * indent-tabs-mode: t
476  * c-basic-offset: 4
477  * tab-width: 4
478  * End:
479  * vim:noexpandtab:sw=4:ts=4:
480  */
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
union varinfo::@19 vv
int argintreguse
Definition: reg.hpp:86
#define ALIGN_2(a)
Definition: global.hpp:72
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
Definition: reg.hpp:43
static int code_is_leafmethod(codeinfo *code)
Definition: code.hpp:151
s4 regoff
Definition: reg.hpp:47
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
s4 flags
Definition: reg.hpp:45
#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