CACAO
md-abi.cpp
Go to the documentation of this file.
1 /* src/vm/jit/powerpc/netbsd/md-abi.cpp - PowerPC NetBSD 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 #include "vm/jit/codegen-common.hpp" // for PACK_REGS
38 #include "vm/jit/stack.hpp"
39 
40 
41 #define _ALIGN(a) do { if ((a) & 1) (a)++; } while (0)
42 
43 
44 /* register descripton array **************************************************/
45 
47  /* zero, sp, NO(sys), a0/v0, a0/v1, a2, a3, a4, */
49 
50  /* a5, a6, a7, itmp1, itmp2, pv, s0, s1, */
52 
53  /*itmp3, t0, t1, t2, t3, t4, t5, t6, */
55 
56  /* s2, s3, s4, s5, s6, s7, s8, s9, */
58 
59  REG_END
60 };
61 
62 
64  /*ftmp3, fa0/v0, fa1, fa2, fa3, fa4, fa5, fa6, */
66 
67  /* fa7, ft0, ft1, ft2, ft3, ft4, fs0, fs1, */
69 
70  /*ftmp1, ftmp2, ft5, ft6, ft7, ft8, ft9, ft10, */
72 
73  /* fs2, fs3, fs4, fs5, fs6, fs7, fs8, fs9 */
75 
76  REG_END
77 };
78 
79 
80 /* md_param_alloc **************************************************************
81 
82  Allocate Arguments to Stackslots according the Calling Conventions
83 
84  --- in
85  md->paramcount: Number of arguments for this method
86  md->paramtypes[].type: Argument types
87 
88  --- out
89  md->params[].inmemory: Argument spilled on stack
90  md->params[].regoff: Stack offset or rd->arg[int|flt]regs index
91  md->memuse: Stackslots needed for argument spilling
92  md->argintreguse: max number of integer arguments used
93  md->argfltreguse: max number of float arguments used
94 
95 *******************************************************************************/
96 
98 {
99  paramdesc *pd;
100  s4 i;
101  s4 iarg;
102  s4 farg;
103  s4 stacksize;
104 
105  /* set default values */
106 
107  iarg = 0;
108  farg = 0;
109  stacksize = LA_WORD_SIZE;
110 
111  /* get params field of methoddesc */
112 
113  pd = md->params;
114 
115  for (i = 0; i < md->paramcount; i++, pd++) {
116  switch (md->paramtypes[i].type) {
117  case TYPE_INT:
118  case TYPE_ADR:
119  if (iarg < INT_ARG_CNT) {
120  pd->inmemory = false;
121  pd->regoff = iarg;
122  iarg++;
123  } else {
124  pd->inmemory = true;
125  pd->regoff = stacksize * 4;
126  stacksize++;
127  }
128  break;
129  case TYPE_LNG:
130  if (iarg < INT_ARG_CNT - 1) {
131  _ALIGN(iarg);
132  pd->inmemory = false;
133  /* rd->arg[int|flt]regs index !! */
134  pd->regoff = PACK_REGS(iarg + 1, iarg);
135  iarg += 2;
136  } else {
137  _ALIGN(stacksize);
138  pd->inmemory = true;
139  pd->regoff = stacksize * 4;
140  iarg = INT_ARG_CNT;
141  stacksize += 2;
142  }
143  break;
144  case TYPE_FLT:
145  if (farg < FLT_ARG_CNT) {
146  pd->inmemory = false;
147  pd->regoff = farg;
148  farg++;
149  } else {
150  pd->inmemory = true;
151  pd->regoff = stacksize * 4;
152  stacksize++;
153  }
154  break;
155  case TYPE_DBL:
156  if (farg < FLT_ARG_CNT) {
157  pd->inmemory = false;
158  pd->regoff = farg;
159  farg++;
160  } else {
161  _ALIGN(stacksize);
162  pd->inmemory = true;
163  pd->regoff = stacksize * 4;
164  stacksize += 2;
165  }
166  break;
167  }
168  }
169 
170  /* Since R3/R4, F1 (==A0/A1, A0) are used for passing return values, this */
171  /* argument register usage has to be regarded, too */
172  if (IS_INT_LNG_TYPE(md->returntype.type)) {
173  if (iarg < (IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1))
174  iarg = IS_2_WORD_TYPE(md->returntype.type) ? 2 : 1;
175  } else {
177  if (farg < 1)
178  farg = 1;
179  }
180 
181  /* fill register and stack usage */
182 
183  md->argintreguse = iarg;
184  md->argfltreguse = farg;
185  md->memuse = stacksize;
186 }
187 
188 
189 /* md_return_alloc *************************************************************
190 
191  Precolor the Java Stackelement containing the Return Value, if
192  possible. (R3==a00 for int/adr, R4/R3 == a01/a00 for long, F1==a00
193  for float/double)
194 
195  --- in
196  jd: jitdata of current method
197  stackslot: Java Stackslot to contain the Return Value
198 
199  --- out
200  if precoloring was possible:
201  VAR(stackslot->varnum)->flags = PREALLOC
202  VAR(stackslot->varnum)->vv.regoff = [REG_RESULT, (REG_RESULT2/REG_RESULT), REG_FRESULT]
203  rd->arg[flt|int]reguse set to a value according the register usage
204 
205 *******************************************************************************/
206 
208 {
209  methodinfo *m;
210  registerdata *rd;
211  methoddesc *md;
212 
213  /* get required compiler data */
214 
215  m = jd->m;
216  rd = jd->rd;
217 
218  md = m->parseddesc;
219 
220  /* In Leafmethods Local Vars holding parameters are precolored to
221  their argument register -> so leafmethods with paramcount > 0
222  could already use R3 == a00! */
223 
224  if (!m->isleafmethod || (md->paramcount == 0)) {
225  /* Only precolor the stackslot, if it is not a SAVEDVAR <->
226  has not to survive method invokations. */
227 
228  if (!(stackslot->flags & SAVEDVAR)) {
229 
230  VAR(stackslot->varnum)->flags = PREALLOC;
231 
232  if (IS_INT_LNG_TYPE(md->returntype.type)) {
233  if (!IS_2_WORD_TYPE(md->returntype.type)) {
234  if (rd->argintreguse < 1)
235  rd->argintreguse = 1;
236 
237  VAR(stackslot->varnum)->vv.regoff = REG_RESULT;
238 
239  } else {
240  if (rd->argintreguse < 2)
241  rd->argintreguse = 2;
242 
243  VAR(stackslot->varnum)->vv.regoff = PACK_REGS(REG_RESULT2, REG_RESULT);
244  }
245 
246  } else { /* float/double */
247  if (rd->argfltreguse < 1)
248  rd->argfltreguse = 1;
249 
250  VAR(stackslot->varnum)->vv.regoff = REG_FRESULT;
251  }
252  }
253  }
254 }
255 
256 
257 /*
258  * These are local overrides for various environment variables in Emacs.
259  * Please do not remove this and leave it at the end of the file, where
260  * Emacs will automagically detect them.
261  * ---------------------------------------------------------------------
262  * Local variables:
263  * mode: c++
264  * indent-tabs-mode: t
265  * c-basic-offset: 4
266  * tab-width: 4
267  * End:
268  * vim:noexpandtab:sw=4:ts=4:
269  */
void md_return_alloc(jitdata *jd, stackelement_t *stackslot)
Definition: md-abi.cpp:250
int argintreguse
Definition: reg.hpp:86
#define _ALIGN(a)
Definition: md-abi.cpp:41
Definition: jit.hpp:126
paramdesc * params
Definition: descriptor.hpp:164
#define REG_SAV
Definition: jit.hpp:449
#define IS_INT_LNG_TYPE(a)
Definition: global.hpp:130
s4 nregdescint[]
Definition: md-abi.cpp:41
#define REG_FRESULT
Definition: md-abi.hpp:61
#define REG_END
Definition: jit.hpp:453
int32_t flags
Definition: stack.hpp:67
#define REG_RES
Definition: jit.hpp:446
#define VAR(i)
Definition: jit.hpp:259
typedesc paramtypes[1]
Definition: descriptor.hpp:167
#define IS_2_WORD_TYPE(a)
Definition: global.hpp:132
#define LA_WORD_SIZE
Definition: md-abi.hpp:82
#define IS_FLT_DBL_TYPE(a)
Definition: global.hpp:131
#define INT_ARG_CNT
Definition: md-abi.hpp:76
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
methoddesc * parseddesc
Definition: method.hpp:78
methodinfo * m
Definition: jit.hpp:127
#define FLT_ARG_CNT
Definition: md-abi.hpp:83
#define REG_RESULT2
Definition: md-abi.hpp:37
#define REG_ARG
Definition: jit.hpp:451
#define REG_TMP
Definition: jit.hpp:450
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