CACAO
md-abi.cpp
Go to the documentation of this file.
1 /* src/vm/jit/s390/md-abi.cpp - s390 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 #include "vm/types.hpp"
28 
29 #include "vm/jit/s390/md-abi.hpp"
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 #include "vm/jit/codegen-common.hpp" // for PACK_REGS
38 #include "vm/jit/stack.hpp"
39 
40 #include <assert.h>
41 
42 
43 /* register descripton array **************************************************/
44 
46  /*itmp3, itmp1, a0, a1, a2, a3, a4, s0, */
48  /* s1, s2, s3, s4, s5, pv, ra/itmp2, sp */
50  REG_END
51 };
52 
53 const char *abi_registers_integer_name[] = {
54  "r0", "r1", "r2", "r3",
55  "r4", "r5", "r6", "r7",
56  "r8", "r9", "r10", "r11",
57  "r12", "r13", "r14", "r15"
58 };
59 
61  2, /* r2/a0 */
62  3, /* r3/a1 */
63  4, /* r4/a2 */
64  5, /* r5/a3 */
65  6 /* r6/a4 */
66 };
67 
69  7, /* r7/s0 */
70  8, /* r8/s1 */
71  9, /* r9/s2 */
72  10, /* r10/s3 */
73  11, /* r11/s4 */
74  12 /* r12/s5 */
75 };
76 
78  -1 /* none */
79 };
80 
84  REG_END
85 };
86 
88  0, /* f0/fa0 */
89  2 /* f2/fa2 */
90 };
91 
93  -1 /* none */
94 };
95 
97  1, /* f1/ft0 */
98  3, /* f3/ft1 */
99  5, /* f5/ft2 */
100  7, /* f7/ft3 */
101  8, /* f8/ft4 */
102  9, /* f9/ft5 */
103  10, /* f10/ft6 */
104  11, /* f11/ft7 */
105  12, /* f12/ft8 */
106  13, /* f13/ft9 */
107  14, /* f14/ft10 */
108  15 /* f15/ft11 */
109 };
110 
111 /* md_param_alloc_intern *******************************************************
112 
113  Allocates parameters to registers or stackslots for both native and java
114  methods.
115 
116  --- in:
117  slot: size in bytes of a stack slot
118  slots1w: number of stack slots used by a 1 word type parameter
119  slots2w: number of stack slots used by a 2 word type parameter
120  stackoff: offset on stack frame where to start placing arguments
121 
122 *******************************************************************************/
123 
124 static void md_param_alloc_intern(methoddesc *md, s4 slot, s4 slots1w, s4 slots2w, s4 stackoff)
125 {
126  paramdesc *pd;
127  s4 i;
128  s4 iarg;
129  s4 farg;
130  s4 stacksize;
131 
132  /* set default values */
133 
134  iarg = 0;
135  farg = 0;
136  stacksize = 0;
137 
138  /* get params field of methoddesc */
139 
140  pd = md->params;
141 
142  for (i = 0; i < md->paramcount; i++, pd++) {
143  switch (md->paramtypes[i].type) {
144  case TYPE_INT:
145  case TYPE_ADR:
146  if (iarg < INT_ARG_CNT) {
147  pd->inmemory = false;
149  pd->index = iarg;
150  iarg++;
151  }
152  else {
153  pd->inmemory = true;
154  pd->regoff = (stacksize * slot) + stackoff;
155  pd->index = stacksize;
156  stacksize += slots1w;
157  }
158  break;
159 
160  case TYPE_LNG:
161  if (iarg < INT_ARG_CNT - 1) {
162  /* _ALIGN(iarg); */
163  pd->inmemory = false;
164  pd->regoff =
167  pd->index = PACK_REGS(iarg + 1, iarg);
168  iarg += 2;
169  }
170  else {
171  /* _ALIGN(stacksize); */
172  pd->inmemory = true;
173  pd->regoff = (stacksize * slot) + stackoff;
174  pd->index = stacksize;
175  iarg = INT_ARG_CNT;
176  stacksize += slots2w;
177  }
178  break;
179 
180  case TYPE_FLT:
181  if (farg < FLT_ARG_CNT) {
182  pd->inmemory = false;
184  pd->index = farg;
185  farg++;
186  }
187  else {
188  pd->inmemory = true;
189  pd->regoff = (stacksize * slot) + stackoff;
190  pd->index = stacksize;
191  stacksize += slots1w;
192  }
193  break;
194 
195  case TYPE_DBL:
196  if (farg < FLT_ARG_CNT) {
197  pd->inmemory = false;
199  pd->index = farg;
200  farg++;
201  }
202  else {
203  /* _ALIGN(stacksize); */
204  pd->inmemory = true;
205  pd->regoff = (stacksize * slot) + stackoff;
206  pd->index = stacksize;
207  stacksize += slots2w;
208  }
209  break;
210 
211  default:
212  assert(0);
213  }
214  }
215 
216  /* Since A0+A1/FA0 are used for passing return
217  values, this argument register usage has to be regarded,
218  too. */
219 
220  if (IS_INT_LNG_TYPE(md->returntype.type)) {
221  if (iarg < (IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1))
222  iarg = IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1;
223  }
224  else {
226  if (farg < 1)
227  farg = 1;
228  }
229 
230  /* fill register and stack usage */
231 
232  md->argintreguse = iarg;
233  md->argfltreguse = farg;
234  md->memuse = stacksize;
235 }
236 
238 {
239  md_param_alloc_intern(md, 8, 1, 1, 0);
240 }
241 
243 {
244  md_param_alloc_intern(md, 4, 1, 2, 96);
245 }
246 
247 
248 /* md_return_alloc *************************************************************
249 
250  Precolor the Java Stackelement containing the Return Value. Only
251  for float/ double types straight forward possible, since INT_LNG
252  types use "reserved" registers Float/Double values use a00 as
253  return register.
254 
255  --- in
256  jd: jitdata of the current method
257  stackslot: Java Stackslot to contain the Return Value
258 
259  --- out
260  if precoloring was possible:
261  VAR(stackslot->varnum)->flags = PREALLOC
262  ->vv.regoff = [REG_RESULT|REG_FRESULT]
263  rd->arg[flt|int]reguse set to a value according the register usage
264 
265  NOTE: Do not pass a LOCALVAR in stackslot->varnum.
266 
267 *******************************************************************************/
268 
270 {
271  methodinfo *m;
272  codeinfo *code;
273  registerdata *rd;
274  methoddesc *md;
275 
276  /* get required compiler data */
277 
278  m = jd->m;
279  code = jd->code;
280  rd = jd->rd;
281 
282  md = m->parseddesc;
283 
284  /* In Leafmethods Local Vars holding parameters are precolored to
285  their argument register -> so leafmethods with paramcount > 0
286  could already use R3 == a00! */
287 
288  if (!code_is_leafmethod(code) || (md->paramcount == 0)) {
289  /* Only precolor the stackslot, if it is not a SAVEDVAR <->
290  has not to survive method invokations. */
291 
292  if (!(stackslot->flags & SAVEDVAR)) {
293  VAR(stackslot->varnum)->flags = PREALLOC;
294 
295  if (IS_INT_LNG_TYPE(md->returntype.type)) {
296  if (!IS_2_WORD_TYPE(md->returntype.type)) {
297  if (rd->argintreguse < 1)
298  rd->argintreguse = 1;
299 
300  VAR(stackslot->varnum)->vv.regoff = REG_RESULT;
301  }
302  else {
303  if (rd->argintreguse < 2)
304  rd->argintreguse = 2;
305 
306  VAR(stackslot->varnum)->vv.regoff = REG_RESULT_PACKED;
307  }
308  }
309  else { /* float/double */
310  if (rd->argfltreguse < 1)
311  rd->argfltreguse = 1;
312 
313  VAR(stackslot->varnum)->vv.regoff = REG_FRESULT;
314  }
315  }
316  }
317 }
318 
319 
320 /*
321  * These are local overrides for various environment variables in Emacs.
322  * Please do not remove this and leave it at the end of the file, where
323  * Emacs will automagically detect them.
324  * ---------------------------------------------------------------------
325  * Local variables:
326  * mode: c
327  * indent-tabs-mode: t
328  * c-basic-offset: 4
329  * tab-width: 4
330  * End:
331  * vim:noexpandtab:sw=4:ts=4:
332  */
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
jlong jlong jlong jlong jint jmethodID jint slot
Definition: jvmti.h:497
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
static void md_param_alloc_intern(methoddesc *md, s4 slot, s4 slots1w, s4 slots2w, s4 stackoff)
Definition: md-abi.cpp:124
#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
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
#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 REG_RESULT_PACKED
Definition: md-abi.hpp:133