CACAO
ssa_rename.cpp
Go to the documentation of this file.
1 /* src/vm/jit/optimizing/ssa.cpp - static single-assignment form
2 
3  Copyright (C) 2005-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., 59 Temple Place - Suite 330, Boston, MA
21  02111-1307, USA.
22 
23 */
24 
25 
26 #include "config.h"
27 
28 #include <stdio.h>
29 #include <stdlib.h>
30 
31 #include "mm/dumpmemory.hpp"
32 
33 #include "toolbox/bitvector.hpp"
34 #include "toolbox/worklist.hpp"
35 
36 #include "vm/descriptor.hpp"
37 #include "vm/jit/builtin.hpp"
38 
39 #include "vm/jit/code.hpp"
40 #include "vm/jit/jit.hpp" /* icmd_table */
41 
48 
49 #if defined(SSA_DEBUG_VERBOSE)
50 #include "vm/options.hpp" /* compileverbose */
51 #endif
52 
53 /* function prototypes */
54 void ssa_rename_(jitdata *jd, graphdata *gd, dominatordata *dd, int n);
55 int ssa_rename_def_(lsradata *ls, int a);
56 
57 /* ssa_rename ******************************************************************
58 
59 Rename the variables a (0 <= a < ls->ssavarcount) so that each new variable
60 has only one definition (SSA form).
61 
62 ls->def_count[0..ls->ssavarcount[ holds the number of definitions of each var.
63 ls->var_0[0..ls->ssavarcount[ will be set to the new index of the first
64  definition of each old var.
65 ls->varcount_with_indices will be se to the new maximum varcount of LOCAL
66  and IOVARS.
67 
68 All other vars (TEMPVAR and PREALLOC) will get a new unique index above
69 ls->varcount_with_indices.
70 
71 jd->var and jd->varcount will be set for this renamed vars.
72 
73 *******************************************************************************/
74 
76 {
77  int i, mi, l, j, p, t;
78  Type type;
79  int flags;
80  methoddesc *md = jd->m->parseddesc;
81 
82  varinfo *new_vars;
83  lsradata *ls;
84 
85  ls = jd->ls;
86 
87  ssa_rename_init(jd, gd);
88 
89  /* Consider definition of Local Vars initialized with Arguments */
90  /* in Block 0 */
91  /* init is regarded as use too-> ssa_rename_use ->bullshit!!*/
92 
93  for (p = 0, l= 0; p < md->paramcount; p++) {
94  t = md->paramtypes[p].type;
95  mi = l * 5 + t;
96  i = jd->local_map[mi];
97  l++;
98  if (IS_2_WORD_TYPE(t))
99  l++;
100  if (i == jitdata::UNUSED)
101  continue;
102 
103  /* !!!!! locals are now numbered as the parameters !!!! */
104  /* !!!!! no additional increment for 2 word types !!!!! */
105  /* this happens later on! here we still need the increment */
106  /* index of var can be in the range from 0 up to not including*/
107  /* jd->varcount */
108 
109 
110  i = ls->new_varindex[i];
111 
112  /* ignore return value, since first definition gives 0 -> */
113  /* no rename necessary */
114 
115  j = ssa_rename_def_(ls, i);
116  _SSA_ASSERT(j == 0);
117  jd->local_map[mi] = i;
118  }
119  ssa_rename_(jd, gd, dd, 0);
120 
121 #if 0
122  /* DO _NOT_ DO THIS! Look at java.util.stringtokenizer.counttokens! */
123  /* if there is no use of the defined Var itself by the phi function */
124  /* for a loop path, in which this var is not used, it will not be life*/
125  /* in this path and overwritten! */
126 
127  /* Invalidate all xij from xi0=phi(xi1,xi2,xi3,..,xin) with xij == xi0*/
128  /* this happens if the phi function is the first definition of x or in*/
129  /* a path with a backedge xi has no definition */
130  /* a phi(xij) = ...,xij,... with the only use and definition of xij by*/
131  /* this phi function would otherwise "deadlock" the dead code */
132  /* elemination (invalidate means set it to UNUSED) */
133  /* a phi function phi(xi0)=xi1,xi2,...xin wiht xij == xi0 for all j in*/
134  /* [1,n] can be removed */
135 
136  for(i = 0; i < ls->ssavarcount; i++) {
137  for(t = 0; t < ls->basicblockcount; t++) {
138  if (ls->phi[t][i] != 0) {
139  remove_phi = true;
140  for(p = 1; p <= graph_get_num_predecessor(gd, t); p++) {
141  if (ls->phi[t][i][0] == ls->phi[t][i][p])
142  ls->phi[t][i][p] = jitdata::UNUSED;
143  else
144  remove_phi = false;
145  }
146  }
147  if (remove_phi)
148  ls->phi[t][i] = NULL;
149  }
150  }
151 #endif
152 
153 #if defined(SSA_DEBUG_CHECK) || defined(SSA_DEBUG_VERBOSE)
154 # if defined(SSA_DEBUG_VERBOSE)
155  if (compileverbose) {
156  printf("%s %s ", jd->m->clazz->name.begin(), jd->m->name.begin());
157  if (code_is_leafmethod(jd->code))
158  printf("**Leafmethod**");
159  printf("\n");
160  }
161 # endif
162  if (strcmp(jd->m->clazz->name.begin(),"fp")==0)
163  if (strcmp(jd->m->name.begin(),"testfloat")==0)
164 # if defined(SSA_DEBUG_VERBOSE)
165  if (compileverbose)
166  printf("12-------------------12\n");
167 # else
168  { int dummy=1; dummy++; }
169 # endif
170 #endif
171 
172  /* recreate rd->locals[][] */
173  /* now only one (local_index/type) pair exists anymore */
174  /* all var[t][i] with var_to_index[var[t][i]] >= 0 are locals */
175  /* max local index after SSA indexing is in ls->local_0[ls->max_locals] */
176 
177  new_vars = DMNEW(varinfo, ls->vartop);
178  for(i = 0; i < ls->vartop ; i++)
179  new_vars[i].type = (Type) jitdata::UNUSED;
180  for(i = 0; i < jd->varcount; i++) {
181  p = ls->new_varindex[i];
182  if (p != jitdata::UNUSED) {
183  if (p < ls->ssavarcount)
184  p = ls->var_0[p];
185  new_vars[p].type = VAR(i)->type;
186  new_vars[p].flags = VAR(i)->flags;
187  ls->lifetime[p].v_index = p;
188  ls->lifetime[p].type = VAR(i)->type;
189  }
190  }
191 
192  /* take care of newly indexed local & in/out vars */
193 
194  for(i = 0; i < ls->ssavarcount; i++) {
195  j = ls->var_0[i];
196  type = new_vars[j].type;
197  flags = new_vars[j].flags;
198  j++;
199  for (; j < ls->var_0[i + 1]; j++) {
200  new_vars[j].type = type;
201  new_vars[j].flags = flags;
202  ls->lifetime[j].v_index = j;
203  ls->lifetime[j].type = type;
204  }
205  }
206 
207 #ifdef SSA_DEBUG_VERBOSE
208  if (compileverbose) {
209 
210  printf("ssa_rename: Vars: Orig:%3i SSAVar: %3i\n", jd->varcount,
211  ls->ssavarcount);
212  for(i = 0; i < jd->varcount; i++) {
213  printf("%3i(%3i,%3x) ",i,VAR(i)->type, VAR(i)->flags);
214  ssa_show_variable(jd, i, VAR(i),0);
215  j = ls->new_varindex[i];
216  if ((j != jitdata::UNUSED) && (j < ls->ssavarcount))
217  printf(" -> %3i ... %3i", ls->var_0[j], ls->var_0[j + 1] - 1);
218  else
219  printf(" -> %3i", j);
220  printf("\n");
221  }
222  }
223 #endif
224 
225  jd->var = new_vars;
226  jd->varcount = ls->vartop;
227  jd->vartop = ls->vartop;
228 
229 #ifdef SSA_DEBUG_VERBOSE
230  if (compileverbose) {
231  printf("ssa_rename: Vars: Orig:%3i SSAVar: %3i\n", jd->varcount,
232  ls->ssavarcount);
233  for(i = 0; i < jd->varcount; i++) {
234  printf("%3i(%3i,%3x) ",i,VAR(i)->type, VAR(i)->flags);
235  ssa_show_variable(jd, i, VAR(i),0);
236  printf("\n");
237  }
238  }
239 #endif
240 }
241 
242 /* ssa_rename_init *************************************************************
243 
244 Setup the data structure for ssa_rename
245 
246 ls->def_count[0..ls->ssavarcount[ holds the number of definitions of each var.
247 ls->var_0[0..ls->ssavarcount[ will be set to the new index of the first
248  definition of each old var.
249 ls->varcount_with_indices will be se to the new maximum varcount of LOCAL
250  and IOVARS.
251 
252 All other vars (TEMPVAR and PREALLOC) will get a new unique index above
253 ls->varcount_with_indices.
254 
255 jd->var and jd->varcount will be set for this renamed vars.
256 
257 *******************************************************************************/
258 
260 {
261  int a, i;
262 #if 0
263  int p;
264 #endif
265  lsradata *ls;
266 
267  ls = jd->ls;
268 
269  /* set up new locals */
270  /* ls->new_varindex[0..jd->varcount[ holds the new unique index */
271  /* for locals and iovars */
272 
273  /* ls->num_defs[index] gives the number of indizes which will be created */
274  /* from SSA */
275 
276  /* -> vars will be numbered in this sequence: L0(0)..L0(i) L1(0)..L1(j) ..*/
277  /* ls->var_0[X] will point to each LX(0) */
278  /* ls->var_0[ls->ssavarcount] will hold ls->varcount_with_indices */
279 
280  /* as first step cummulate the num_defs array for locals and iovars */
281  /* last element is the maximum var count */
282 
283  ls->var_0 = DMNEW(int, MAX(1, ls->ssavarcount + 1));
284  ls->var_0[0] = 0;
285  ls->varcount_with_indices = 0;
286  for(i = 0; i < ls->ssavarcount; i++) {
287  ls->varcount_with_indices += ls->num_defs[i];
288  ls->var_0[i+1] = ls->var_0[i] + ls->num_defs[i];
289  }
290 
291 #if 0
292  /* Change the var indices in phi from La to La(0) */
293 
294  for(i = 0; i < ls->basicblockcount; i++)
295  for (a = 0; a < ls->ssavarcount; a++)
296  if (ls->phi[i][a] != NULL)
297  for(p = 0; p < graph_get_num_predecessor(gd, i) + 1; p++)
298  ls->phi[i][a][p] = ls->var_0[a];
299 #endif
300 
301  /* Initialization */
302 
303  ls->count = DMNEW(int, MAX(1, ls->ssavarcount));
304  ls->stack = DMNEW(int *, MAX(1, ls->ssavarcount));
305  ls->stack_top = DMNEW(int, MAX(1, ls->ssavarcount));
306  for(a = 0; a < ls->ssavarcount; a++) {
307  ls->count[a] = 0;
308  ls->stack_top[a] = 0;
309 
310  /* stack a has to hold number of defs of a Elements + 1 */
311 
312  ls->stack[a] = DMNEW(int, ls->num_defs[a] + 1);
313  ls->stack[a][ls->stack_top[a]++] = 0;
314  }
315 
316  if (ls->ssavarcount > 0) {
317 
318  /* Create the num_var_use Array */
319 
320  ls->num_var_use = DMNEW(int *, ls->basicblockcount);
321  for(i = 0; i < ls->basicblockcount; i++) {
322  ls->num_var_use[i] =DMNEW(int, MAX(1, ls->varcount_with_indices));
323  for(a = 0; a < ls->varcount_with_indices; a++)
324  ls->num_var_use[i][a] = 0;
325  }
326 
327  /* Create the use_sites Array of Bitvectors*/
328  /* use max(1,..), to ensure that the array is created! */
329 
331  for(a = 0; a < ls->varcount_with_indices; a++)
332  ls->use_sites[a] = bv_new(ls->basicblockcount);
333  }
334 
335  /* init lifetimes */
336  /* count number of TEMPVARs */
337 
338  ls->lifetimecount = 0;
339  for(i = 0; i < jd->varcount; i++)
340  if ((i >= jd->localcount) || (!(jd->var[i].flags & (INOUT | PREALLOC))))
341  ls->lifetimecount++;
342 
344 
345  ls->lifetimecount = ls->varcount;
346  ls->lifetime = DMNEW(struct lifetime, ls->lifetimecount);
347  ls->lt_used = DMNEW(int, ls->lifetimecount);
348  ls->lt_int = DMNEW(int, ls->lifetimecount);
349  ls->lt_int_count = 0;
350  ls->lt_flt = DMNEW(int, ls->lifetimecount);
351  ls->lt_flt_count = 0;
352  ls->lt_mem = DMNEW(int, ls->lifetimecount);
353  ls->lt_mem_count = 0;
354  for (i=0; i < ls->lifetimecount; i++) {
356  ls->lifetime[i].savedvar = 0;
357  ls->lifetime[i].flags = 0;
358  ls->lifetime[i].usagecount = 0;
359  ls->lifetime[i].bb_last_use = -1;
360  ls->lifetime[i].bb_first_def = -1;
361  ls->lifetime[i].use = NULL;
362  ls->lifetime[i].def = NULL;
363  ls->lifetime[i].last_use = NULL;
364  }
365 
366  /* for giving TEMP and PREALLOC vars a new unique index */
367 
368  ls->vartop = ls->varcount_with_indices;
369 
370 #ifdef SSA_DEBUG_VERBOSE
371  if (compileverbose) {
372  printf("ssa_rename_init: Vars: Orig:%3i SSAVar: %3i\n", jd->varcount,
373  ls->ssavarcount);
374  for(i = 0; i < jd->varcount; i++) {
375  if ((i < jd->localcount) || ( VAR(i)->flags & INOUT)) {
376  printf("%3i(%3i,%3x) ",i,VAR(i)->type, VAR(i)->flags);
377  ssa_show_variable(jd, i, VAR(i),0);
378  if ((i < ls->ssavarcount) || (VAR(i)->flags & INOUT)) {
379  printf(" -> %3i", ls->new_varindex[i]);
380  }
381  printf("\n");
382  }
383  }
384  ssa_print_phi(ls, gd);
385  }
386 #endif
387 }
388 
389 int ssa_rename_def_(lsradata *ls, int a) {
390  int i;
391 
393  ls->count[a]++;
394  i = ls->count[a] - 1;
395  /* push i on stack[a] */
396  _SSA_CHECK_BOUNDS(ls->stack_top[a], 0, ls->num_defs[a] + 1);
397  ls->stack[a][ls->stack_top[a]++] = i;
398  return i;
399 }
400 
401 int ssa_rename_def(jitdata *jd, int *def_count, int a) {
402  int i, a1, ret;
403  lsradata *ls;
404 
405  ls = jd->ls;
406 
407  a1 = ls->new_varindex[a];
409  if ((a1 != jitdata::UNUSED) && (a1 < ls->ssavarcount)) {
410  /* local or inoutvar -> normal ssa renaming */
411  _SSA_ASSERT((a < jd->localcount) || (VAR(a)->flags & INOUT));
412  /* !IS_TEMPVAR && !IS_PREALLOC == (IS_LOCALVAR || IS_INOUT) */
413 
414  def_count[a1]++;
415  i = ssa_rename_def_(ls, a1);
416  ret = ls->var_0[a1] + i;
417  }
418  else {
419  /* TEMP or PREALLOC var */
420  if (a1 == jitdata::UNUSED) {
421  ls->new_varindex[a] = ls->vartop;
422  ret = ls->vartop;
423  ls->vartop++;
424  _SSA_ASSERT( ls->vartop < ls->varcount);
425  }
426  else
427  ret = a1;
428  }
429  return ret;
430 }
431 
432 void ssa_rename_use_(lsradata *ls, int n, int a) {
434  if (ls->ssavarcount > 0) {
435  bv_set_bit(ls->use_sites[a], n);
436  ls->num_var_use[n][a]++;
437  }
438 }
439 
440 int ssa_rename_use(lsradata *ls, int n, int a) {
441  int a1, i;
442  int ret;
443 
444  a1 = ls->new_varindex[a];
446  if ((a1 != jitdata::UNUSED) && (a1 < ls->ssavarcount)) {
447  /* local or inoutvar -> normal ssa renaming */
448  /* i <- top(stack[a]) */
449 
450  _SSA_CHECK_BOUNDS(ls->stack_top[a1]-1, 0, ls->num_defs[a1]+1);
451  i = ls->stack[a1][ls->stack_top[a1] - 1];
452  _SSA_CHECK_BOUNDS(i, 0, ls->num_defs[a1]);
453 
454  ret = ls->var_0[a1] + i;
455  }
456  else {
457  /* TEMP or PREALLOC var */
458  if (a1 == jitdata::UNUSED) {
459  ls->new_varindex[a] = ls->vartop;
460  ret = ls->vartop;
461  ls->vartop++;
462  _SSA_ASSERT( ls->vartop < ls->varcount);
463  }
464  else
465  ret = a1;
466  }
467 
468  return ret;
469 }
470 
471 #ifdef SSA_DEBUG_VERBOSE
472 void ssa_rename_print(instruction *iptr, char *op, int from, int to) {
473  if (compileverbose) {
474  printf("ssa_rename_: ");
475  if (iptr != NULL)
476  printf("%s ", bytecode[iptr->opc].mnemonic);
477  else
478  printf(" ");
479 
480  printf("%s: %3i->%3i\n", op, from, to);
481  }
482 }
483 #endif
484 
485 /* ssa_rename_ ****************************************************************
486 
487 Algorithm is based on "modern compiler implementation in C" from andrew
488 w. appel, edition 2004
489 
490 page 443 Algorithm 19.7. Renaming Variables
491 
492 *******************************************************************************/
493 
494 void ssa_rename_(jitdata *jd, graphdata *gd, dominatordata *dd, int n) {
495  int a, i, j, k, iindex, Y, v;
496  int in_d, out_d;
497  int *def_count;
498  /* [0..ls->varcount[ Number of Definitions of this var in this */
499  /* Basic Block. Used to remove the entries off the stack at the */
500  /* end of the function */
501  instruction *iptr;
502  s4 *in, *out, *argp;
503  graphiterator iter_succ, iter_pred;
504  struct lifetime *lt;
505 
506  methoddesc *md;
507  methodinfo *m;
508  builtintable_entry *bte;
509  lsradata *ls;
510 
511  ls = jd->ls;
512  m = jd->m;
513 
514 #ifdef SSA_DEBUG_VERBOSE
515  if (compileverbose)
516  printf("ssa_rename_: BB %i\n",n);
517 #endif
518 
520 
521  def_count = DMNEW(int, MAX(1, ls->ssavarcount));
522  for(i = 0; i < ls->ssavarcount; i++)
523  def_count[i] = 0;
524 
525  /* change Store of possible phi functions from a to ai*/
526 
527  for(a = 0; a < ls->ssavarcount; a++)
528  if (ls->phi[n][a] != NULL) {
529  def_count[a]++;
530 
531  /* do not mark this store as use - maybe this phi function */
532  /* can be removed for unused Vars*/
533 
534  j = ls->var_0[a] + ssa_rename_def_(ls, a);
535 #ifdef SSA_DEBUG_VERBOSE
536  ssa_rename_print( NULL, "phi-st", ls->phi[n][a][0], j);
537 #endif
538  ls->phi[n][a][0] = j;
539  }
540 
541  in = ls->basicblocks[n]->invars;
542  in_d = ls->basicblocks[n]->indepth - 1;
543 
544  /* change use of instack Interface stackslots except top SBR and EXH */
545  /* stackslots */
546 
547  if ((ls->basicblocks[n]->type == basicblock::TYPE_EXH) ||
548  (ls->basicblocks[n]->type == basicblock::TYPE_SBR)) {
549  in_d--;
550  }
551 /* out = ls->basicblocks[n]->outvars; */
552 /* out_d = ls->basicblocks[n]->outdepth - 1; */
553 
554 /* for(; out_d > in_d; out_d--); */
555 
556  for (; in_d >= 0; in_d--) {
557  /* Possible Use of ls->new_varindex[jd->var[in_d]] */
558  _SSA_ASSERT(ls->new_varindex[in[in_d]] != jitdata::UNUSED);
559 
560  a = ls->new_varindex[in[in_d]];
561  _SSA_CHECK_BOUNDS(a, 0, ls->ssavarcount);
562 
563  /* i <- top(stack[a]) */
564 
565  _SSA_CHECK_BOUNDS(ls->stack_top[a]-1, 0, ls->num_defs[a]+1);
566  i = ls->stack[a][ls->stack_top[a]-1];
567  _SSA_CHECK_BOUNDS(i, 0, ls->num_defs[a]);
568 
569  /* Replace use of x with xi */
570 
571 #ifdef SSA_DEBUG_VERBOSE
572  ssa_rename_print( NULL, "invar", in[in_d], ls->var_0[a]+i);
573 #endif
574  in[in_d] = ls->var_0[a] + i;
575  lt = ls->lifetime + in[in_d];
576 
577  lt->v_index = in[in_d];
578  lt->bb_last_use = -1;
579  }
580 
581  iptr = ls->basicblocks[n]->iinstr;
582 
583  for(iindex = 0; iindex < ls->basicblocks[n]->icount; iindex++, iptr++) {
584 
585  /* check for use (s1, s2, s3 or special (argp) ) */
586 
587  switch (icmd_table[iptr->opc].dataflow) {
588  case DF_3_TO_0:
589  case DF_3_TO_1: /* icmd has s1, s2 and s3 */
590  j = ssa_rename_use(ls, n, iptr->sx.s23.s3.varindex);
591 #ifdef SSA_DEBUG_VERBOSE
592  ssa_rename_print( iptr, "s3 ", iptr->sx.s23.s3.varindex, j);
593 #endif
594  iptr->sx.s23.s3.varindex = j;
595 
596  /* now "fall through" for handling of s2 and s1 */
597 
598  case DF_2_TO_0:
599  case DF_2_TO_1: /* icmd has s1 and s2 */
600  j = ssa_rename_use(ls, n, iptr->sx.s23.s2.varindex);
601 #ifdef SSA_DEBUG_VERBOSE
602  ssa_rename_print( iptr, "s2 ", iptr->sx.s23.s2.varindex, j);
603 #endif
604  iptr->sx.s23.s2.varindex = j;
605 
606  /* now "fall through" for handling of s1 */
607 
608  case DF_1_TO_0:
609  case DF_1_TO_1:
610  case DF_MOVE:
611  case DF_COPY:
612  j = ssa_rename_use(ls, n, iptr->s1.varindex);
613 #ifdef SSA_DEBUG_VERBOSE
614  ssa_rename_print( iptr, "s1 ", iptr->s1.varindex, j);
615 #endif
616  iptr->s1.varindex = j;
617  break;
618 
619  case DF_INVOKE:
620  case DF_BUILTIN:
621  case DF_N_TO_1:
622  /* do not use md->paramcount, pass-through stackslots have */
623  /* to be renamed, too */
624  i = iptr->s1.argcount;
625  argp = iptr->sx.s23.s2.args;
626  while (--i >= 0) {
627  j = ssa_rename_use(ls, n, *argp);
628 #ifdef SSA_DEBUG_VERBOSE
629  ssa_rename_print( iptr, "arg", *argp, j);
630 #endif
631  *argp = j;
632  argp++;
633  }
634  break;
635  }
636 
637 
638  /* Look for definitions (iptr->dst). INVOKE and BUILTIN have */
639  /* an optional dst - so they to be checked first */
640 
641  v = jitdata::UNUSED;
642  if (icmd_table[iptr->opc].dataflow == DF_INVOKE) {
644  if (md->returntype.type != TYPE_VOID)
645  v = iptr->dst.varindex;
646  }
647  else if (icmd_table[iptr->opc].dataflow == DF_BUILTIN) {
648  bte = iptr->sx.s23.s3.bte;
649  md = bte->md;
650  if (md->returntype.type != TYPE_VOID)
651  v = iptr->dst.varindex;
652  }
653  else if (icmd_table[iptr->opc].dataflow >= DF_DST_BASE) {
654  v = iptr->dst.varindex;
655  }
656 
657  if (v != jitdata::UNUSED) {
658  j = ssa_rename_def(jd, def_count, iptr->dst.varindex);
659 #ifdef SSA_DEBUG_VERBOSE
660  ssa_rename_print( iptr, "dst", iptr->dst.varindex, j);
661 #endif
662  iptr->dst.varindex = j;
663  }
664 
665  /* ?????????????????????????????????????????????????????????? */
666  /* Mark Def as use, too. Since param initialisation is in */
667  /* var_def and this would not remove this locals, if not used */
668  /* elsewhere */
669  /* ?????????????????????????????????????????????????????????? */
670 
671  }
672 
673  /* change outstack Interface stackslots */
674  out = ls->basicblocks[n]->outvars;
675  out_d = ls->basicblocks[n]->outdepth - 1;
676 
677  for (;out_d >= 0; out_d--) {
678  /* Possible Use of ls->new_varindex[jd->var[out_d]] */
679  _SSA_ASSERT(ls->new_varindex[out[out_d]] != jitdata::UNUSED);
680 
681  a = ls->new_varindex[out[out_d]];
682  _SSA_CHECK_BOUNDS(a, 0, ls->ssavarcount);
683 
684  /* i <- top(stack[a]) */
685 
686  _SSA_CHECK_BOUNDS(ls->stack_top[a]-1, 0, ls->num_defs[a]+1);
687  i = ls->stack[a][ls->stack_top[a]-1];
688  _SSA_CHECK_BOUNDS(i, 0, ls->num_defs[a]);
689 
690  /* Replace use of x with xi */
691 
692 #ifdef SSA_DEBUG_VERBOSE
693  ssa_rename_print( NULL, "outvar", out[out_d], ls->var_0[a]+i);
694 #endif
695  out[out_d] = ls->var_0[a] + i;
696  lt = ls->lifetime + out[out_d];
697 
698  lt->v_index = out[out_d];
699  lt->bb_last_use = -1;
700  }
701 
702  /* change use in phi Functions of Successors */
703 
704  Y = graph_get_first_successor(gd, n, &iter_succ);
705  for(; Y != -1; Y = graph_get_next(&iter_succ)) {
707  k = graph_get_first_predecessor(gd, Y, &iter_pred);
708  for (j = 0; (k != -1) && (k != n); j++)
709  k = graph_get_next(&iter_pred);
710  _SSA_ASSERT(k == n);
711 
712  /* n is jth Predecessor of Y */
713 
714  for(a = 0; a < ls->ssavarcount; a++)
715  if (ls->phi[Y][a] != NULL) {
716 
717  /* i <- top(stack[a]) */
718 
719  if (ls->stack_top[a] == 1) {
720  /* no definition till now in controll flow */
721 #ifdef SSA_DEBUG_VERBOSE
722  if (compileverbose) {
723  printf("Succ %3i Arg %3i \n", Y, j);
724  ssa_rename_print( NULL, "phi-use", ls->phi[Y][a][j+1], jitdata::UNUSED);
725  }
726 #endif
727  ls->phi[Y][a][j+1] = jitdata::UNUSED;
728  }
729  else {
730  _SSA_CHECK_BOUNDS(ls->stack_top[a]-1, 0, ls->num_defs[a]+1);
731  i = ls->stack[a][ls->stack_top[a]-1];
732  _SSA_CHECK_BOUNDS(i, 0, ls->num_defs[a]);
733 
734  /* change jth operand from a0 to ai */
735 
736  i = ls->var_0[a] + i;
737 #ifdef SSA_DEBUG_VERBOSE
738  if (compileverbose) {
739  printf("Succ %3i Arg %3i \n", Y, j);
740  ssa_rename_print( NULL, "phi-use", ls->phi[Y][a][j+1], i);
741  }
742 #endif
743  ls->phi[Y][a][j+1] = i;
744  _SSA_CHECK_BOUNDS(ls->phi[Y][a][j+1], 0,
746 
747  /* use by phi function has to be remembered, too */
748 
749  ssa_rename_use_(ls, n, ls->phi[Y][a][j+1]);
750  }
751 
752  /* ????????????????????????????????????????????? */
753  /* why was this only for local vars before ? */
754  /* ????????????????????????????????????????????? */
755 
756  }
757  }
758 
759  /* Call ssa_rename_ for all Childs of n of the Dominator Tree */
760  for(i = 0; i < ls->basicblockcount; i++)
761  if (dd->idom[i] == n)
762  ssa_rename_(jd, gd, dd, i);
763 
764  /* pop Stack[a] for each definition of a var a in the original S */
765  for(a = 0; a < ls->ssavarcount; a++) {
766  ls->stack_top[a] -= def_count[a];
767  _SSA_ASSERT(ls->stack_top[a] >= 0);
768  }
769 }
770 
771 /*
772  * These are local overrides for various environment variables in Emacs.
773  * Please do not remove this and leave it at the end of the file, where
774  * Emacs will automagically detect them.
775  * ---------------------------------------------------------------------
776  * Local variables:
777  * mode: c++
778  * indent-tabs-mode: t
779  * c-basic-offset: 4
780  * tab-width: 4
781  * End:
782  * vim:noexpandtab:sw=4:ts=4:
783  */
int ** num_var_use
Definition: lsra.hpp:157
#define _SSA_CHECK_BOUNDS(i, l, h)
Definition: ssa.hpp:43
Utf8String name
Definition: method.hpp:71
int savedvar
Definition: lsra.hpp:101
int graph_get_next(graphiterator *i)
Definition: graph.cpp:104
int * bitvector
Definition: bitvector.hpp:34
#define DF_1_TO_0
Definition: icmd.hpp:335
int ** stack
Definition: lsra.hpp:202
int * lt_int
Definition: lsra.hpp:171
int bb_last_use
Definition: lsra.hpp:105
Definition: jit.hpp:126
#define DF_2_TO_0
Definition: icmd.hpp:336
Definition: stack.hpp:46
#define DF_1_TO_1
Definition: icmd.hpp:342
methoddesc * md
Definition: builtin.hpp:71
int bb_first_def
Definition: lsra.hpp:106
#define _SSA_ASSERT(a)
Definition: ssa.hpp:44
int lt_flt_count
Definition: lsra.hpp:174
s4 localcount
Definition: jit.hpp:152
int lifetimecount
Definition: lsra.hpp:169
bitvector * use_sites
Definition: lsra.hpp:156
argument_type from
s4 * invars
Definition: jit.hpp:323
int basicblockcount
Definition: lsra.hpp:188
codeinfo * code
Definition: jit.hpp:128
int varcount_with_indices
Definition: lsra.hpp:122
s4 outdepth
Definition: jit.hpp:326
u2 op
Definition: disass.cpp:129
int32_t argcount
Definition: instruction.hpp:64
varinfo * var
Definition: jit.hpp:148
struct site * use
Definition: lsra.hpp:90
int varcount
Definition: lsra.hpp:114
int v_index
Definition: lsra.hpp:97
int32_t varindex
Definition: instruction.hpp:63
int * lt_flt
Definition: lsra.hpp:173
void ssa_print_phi(lsradata *, graphdata *)
Definition: ssa_phi.cpp:279
void ssa_show_variable(jitdata *jd, int index, varinfo *v, int stage)
Definition: ssa.cpp:1262
s4 vartop
Definition: jit.hpp:149
struct site * def
Definition: lsra.hpp:89
int graph_get_first_predecessor(graphdata *gd, int b_index, graphiterator *i)
Definition: graph.cpp:99
struct lifetime * lifetime
Definition: lsra.hpp:168
int * lt_mem
Definition: lsra.hpp:175
#define DF_3_TO_0
Definition: icmd.hpp:337
int * lt_used
Definition: lsra.hpp:170
void ssa_rename_print(instruction *iptr, char *op, int from, int to)
Definition: ssa_rename.cpp:472
Type type
Definition: reg.hpp:44
#define DF_3_TO_1
Definition: icmd.hpp:344
instruction * iinstr
Definition: jit.hpp:319
#define VAR(i)
Definition: jit.hpp:252
Definition: reg.hpp:43
s4 icount
Definition: jit.hpp:318
static int code_is_leafmethod(codeinfo *code)
Definition: code.hpp:151
int * stack_top
Definition: lsra.hpp:203
s4 varcount
Definition: jit.hpp:151
typedesc paramtypes[1]
Definition: descriptor.hpp:167
#define IS_2_WORD_TYPE(a)
Definition: global.hpp:132
const char * mnemonic
Definition: bytecode.hpp:39
static void ssa_rename(ssa_info *ssa)
Definition: ssa2.cpp:412
#define DF_N_TO_1
Definition: icmd.hpp:345
int ssa_rename_def(jitdata *jd, int *def_count, int a)
Definition: ssa_rename.cpp:401
int * new_varindex
Definition: lsra.hpp:123
int ssa_rename_def_(lsradata *ls, int a)
Definition: ssa_rename.cpp:389
int lt_int_count
Definition: lsra.hpp:172
dst_operand_t dst
bool compileverbose
Definition: options.cpp:82
classinfo * clazz
Definition: method.hpp:80
int32_t dataflow
Definition: icmd.hpp:395
#define a1
Definition: md-asm.hpp:33
int ssa_rename_use(lsradata *ls, int n, int a)
Definition: ssa_rename.cpp:440
int * var_0
Definition: lsra.hpp:126
Utf8String name
Definition: class.hpp:91
void ssa_rename_init(jitdata *jd, graphdata *gd)
Definition: ssa_rename.cpp:259
#define DF_COPY
Definition: icmd.hpp:350
int ssavarcount
Definition: lsra.hpp:115
Type
Types used internally by JITTED code.
Definition: global.hpp:117
struct site * last_use
Definition: lsra.hpp:91
s4 indepth
Definition: jit.hpp:325
int * count
Definition: lsra.hpp:201
s4 * local_map
Definition: jit.hpp:153
int flags
Definition: lsra.hpp:102
MIIterator i
typedesc returntype
Definition: descriptor.hpp:166
basicblock ** basicblocks
Definition: lsra.hpp:189
void ssa_rename_(jitdata *jd, graphdata *gd, dominatordata *dd, int n)
Definition: ssa_rename.cpp:494
int32_t s4
Definition: types.hpp:45
#define DF_MOVE
Definition: icmd.hpp:351
s4 * outvars
Definition: jit.hpp:324
union instruction::@12 sx
int type
Definition: lsra.hpp:98
int32_t varindex
icmdtable_entry_t icmd_table[256]
Definition: icmd.cpp:60
#define INSTRUCTION_GET_METHODDESC(iptr, md)
long usagecount
Definition: lsra.hpp:99
s1_operand_t s1
byte_iterator begin() const
Definition: utf8.hpp:106
methoddesc * parseddesc
Definition: method.hpp:78
void ssa_rename_use_(lsradata *ls, int n, int a)
Definition: ssa_rename.cpp:432
int graph_get_num_predecessor(graphdata *gd, int b_index)
Definition: graph.cpp:84
Definition: builtin.hpp:60
methodinfo * m
Definition: jit.hpp:127
s4 flags
Definition: reg.hpp:45
int lt_mem_count
Definition: lsra.hpp:177
#define DF_INVOKE
Definition: icmd.hpp:347
#define DMNEW(type, num)
Definition: dumpmemory.hpp:371
OStream & out()
Definition: OStream.cpp:39
struct instruction::@12::@13 s23
#define MAX(a, b)
Definition: global.hpp:99
int * num_defs
Definition: lsra.hpp:165
bitvector bv_new(int size)
Definition: bitvector.cpp:122
void bv_set_bit(bitvector bv, int bit)
Definition: bitvector.cpp:166
bytecode_t bytecode[256]
Definition: bytecode.cpp:33
int vartop
Definition: lsra.hpp:121
#define DF_BUILTIN
Definition: icmd.hpp:348
Type type
Definition: jit.hpp:315
#define DF_DST_BASE
Definition: icmd.hpp:339
#define printf(...)
Definition: ssa2.cpp:40
#define DF_2_TO_1
Definition: icmd.hpp:343
int *** phi
Definition: lsra.hpp:193
int graph_get_first_successor(graphdata *gd, int b_index, graphiterator *i)
Definition: graph.cpp:94