1 /* src/vm/jit/allocator/lsra.c - linear scan register allocator
3 Copyright (C) 2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 Contact: cacao@cacaojvm.org
27 Authors: Christian Ullrich
31 $Id: lsra.c 6286 2007-01-10 10:03:38Z twisti $
48 #include "mm/memory.h"
49 #include "toolbox/logging.h"
50 #include "vm/builtin.h"
51 #include "vm/exceptions.h"
52 #include "vm/resolve.h"
53 #include "vm/options.h"
54 #include "vm/statistics.h"
55 #include "vm/stringlocal.h"
56 #include "vm/jit/abi.h"
57 #include "vm/jit/reg.h"
58 #include "vm/jit/allocator/liveness.h"
59 #include "vm/jit/allocator/lsra.h"
62 extern char **prof_m_names;
63 extern u4 **prof_bb_freq;
67 /* function prototypes */
68 void lsra_init(jitdata *);
69 void lsra_setup(jitdata *);
70 void lsra_main(jitdata *);
72 void lsra_reg_setup(jitdata *, struct lsra_register *, struct lsra_register * );
73 void lsra_calc_lifetime_length(jitdata *);
74 void _lsra_main( jitdata *, int *, int, struct lsra_register *, int *);
75 void lsra_expire_old_intervalls(jitdata *, struct lifetime *,
76 struct lsra_register *);
77 void spill_at_intervall(jitdata *, struct lifetime *);
78 void lsra_add_active(struct lifetime *, struct lifetime **, int *);
79 void _lsra_expire_old_intervalls(jitdata *, struct lifetime *,
80 struct lsra_register *, struct lifetime **,
82 void _spill_at_intervall(struct lifetime *, struct lifetime **, int *);
84 void lsra_alloc(jitdata *, int *, int, int *);
85 int lsra_getmem(struct lifetime *, struct freemem *, int *);
86 struct freemem *lsra_getnewmem(int *);
87 void lsra_setflags(int *, int);
89 #ifdef LSRA_DEBUG_VERBOSE
90 void lsra_dump_stack(stackptr );
91 void print_lifetimes(jitdata *, int *, int);
95 void lsra_scan_registers_canditates(jitdata *, int);
96 void lsra_join_lifetimes(jitdata *, int);
98 void _lsra_new_stack( lsradata *, stackptr , int , int, int);
99 void _lsra_from_stack(lsradata *, stackptr , int , int, int);
100 void lsra_add_ss(struct lifetime *, stackptr );
101 void lsra_usage_local(lsradata *, s4 , int , int , int , int );
106 bool lsra(jitdata *jd)
108 #if defined(ENABLE_STATISTICS)
113 #if defined(LSRA_DEBUG_CHECK)
120 #if defined(LSRA_DEBUG_CHECK)
123 while (b_index < m->basicblockcount ) {
125 if (m->basicblocks[b_index].flags >= BBREACHED) {
127 in=m->basicblocks[b_index].instack;
128 ind=m->basicblocks[b_index].indepth;
129 for (;ind != 0;in=in->prev, ind--) {
130 /* ARGVAR or LOCALVAR in instack is ok*/
132 if (in->varkind == ARGVAR) printf("ARGVAR in instack: \n");
133 if (in->varkind == LOCALVAR) printf("LOCALVAR in instack\n");
136 out=m->basicblocks[b_index].outstack;
137 outd=m->basicblocks[b_index].outdepth;
138 for (;outd != 0;out=out->prev, outd--) {
139 if (out->varkind == ARGVAR)
140 { log_text("ARGVAR in outstack\n"); assert(0); }
141 if (out->varkind == LOCALVAR)
142 { log_text("LOCALVAR in outstack\n"); assert(0); }
149 jd->ls = DNEW(lsradata);
153 #if defined(ENABLE_STATISTICS)
154 /* find conflicts between locals for statistics */
157 /* local Variable Lifetimes are at the end of the lifetime array and */
158 /* have v_index >= 0 */
159 for (locals_start = ls->lifetimecount-1; (locals_start >=0) &&
160 (ls->lifetime[ls->lt_used[locals_start]].v_index >= 0);
162 for (i=locals_start + 1; i < ls->lifetimecount; i++)
163 for (j=i+1; j < ls->lifetimecount; j++)
164 if ( !((ls->lifetime[ls->lt_used[i]].i_end
165 < ls->lifetime[ls->lt_used[j]].i_start)
166 || (ls->lifetime[ls->lt_used[j]].i_end <
167 ls->lifetime[ls->lt_used[i]].i_start)) )
168 count_locals_conflicts += 2;
174 /* everything's ok */
179 /* sort Basic Blocks using Depth First Search in reverse post order in */
181 void lsra_DFS(jitdata *jd) {
195 stack = DMNEW( int, m->basicblockcount + 1);
196 visited = (int *)DMNEW( int, m->basicblockcount + 1);
197 for (i = 0; i <= m->basicblockcount; i++) {
200 ls->sorted_rev[i]=-1;
203 stack[0] = 0; /* start with Block 0 */
205 visited[0] = ls->num_pred[0]; /* Start Block is handled right and can be */
209 while (not_finished) {
210 while (stack_top != 0) {
212 i = stack[stack_top];
215 for (succ = ls->succ[i]; succ != NULL; succ = succ->next) {
216 visited[succ->value]++;
217 if (visited[succ->value] == ls->num_pred[succ->value]) {
218 /* push the node on the stack, only if all ancestors have */
220 stack[stack_top] = succ->value;
225 not_finished = false;
226 for (i=1; i <= m->basicblockcount; i++) {
227 /* search for visited blocks, which have not reached the num_pred */
228 /* and put them on the stack -> happens with backedges */
229 if ((visited[i] != 0) && (visited[i] < ls->num_pred[i])) {
230 stack[stack_top] = i;
232 visited[i] = ls->num_pred[i];
240 void lsra_get_backedges_(lsradata *ls, int basicblockcount) {
243 struct _backedge *_backedges;
249 /* now look for backedges */
250 ls->backedge_count = 0;
251 for(i=0; i < basicblockcount; i++) {
252 if (ls->sorted[i] != -1)
253 for(s=ls->succ[ls->sorted[i]]; s != NULL; s=s->next) {
254 if (i >= ls->sorted_rev[s->value]) {
255 n=DNEW(struct _backedge);
256 n->start = max(i, ls->sorted_rev[s->value]);
257 n->end = min(i, ls->sorted_rev[s->value]);
258 n->next = _backedges;
260 ls->backedge_count++;
264 /* put _backedges in ls->backedge array */
265 ls->backedge = DMNEW(struct _backedge *, ls->backedge_count);
266 for (n=_backedges, i=0; n != NULL; n=n->next, i++) {
268 ls->backedge[i]->nesting = 1;
272 void lsra_get_nesting(jitdata *jd) {
281 for (i=0; i <= m->basicblockcount; i++)
282 if (ls->sorted[i] != -1)
283 ls->sorted_rev[ls->sorted[i]]=i;
285 lsra_get_backedges_(ls, m->basicblockcount + 1);
286 /* - sort backedge by increasing end: */
287 for (i=0; i < ls->backedge_count; i++)
288 for (j=i+1; j < ls->backedge_count; j++)
289 if ((ls->backedge[i]->end > ls->backedge[j]->end) || /* -> swap */
290 ((ls->backedge[i]->end == ls->backedge[j]->end) &&
291 (ls->backedge[i]->start > ls->backedge[j]->start) )) {
293 ls->backedge[i]=ls->backedge[j];
297 /* create ls->nesting */
298 /* look for nesting depth (overlapping backedges*/
299 for (i=0; i < ls->backedge_count - 1; i++) {
300 for (j = i + 1; (j < ls->backedge_count) &&
301 (ls->backedge[i]->start >= ls->backedge[j]->end); j++)
302 ls->backedge[j]->nesting += ls->backedge[i]->nesting;
307 while ( (i < m->basicblockcount + 1) ) {
308 if (j < ls->backedge_count) {
309 while ( i < ls->backedge[j]->end ) {
313 if ( (j+1) < ls->backedge_count)
314 end = min(ls->backedge[j]->start, ls->backedge[j+1]->end - 1);
316 end = ls->backedge[j]->start;
318 ls->nesting[i] = ls->backedge[j]->nesting;
328 #ifdef LSRA_DEBUG_VERBOSE
329 if (compileverbose) {
330 printf("sorted: \n");
331 for (i=0; i < ls->backedge_count; i++)
332 printf("Backedge: %i - %i, %i - %i\n", ls->sorted[ls->backedge[i]->start], ls->sorted[ls->backedge[i]->end], ls->backedge[i]->start, ls->backedge[i]->end);
333 printf("Nesting Level \n");
334 for (i=0; i<m->basicblockcount; i++) printf(" %3li", ls->nesting[i]);
338 for (i=0; i <= m->basicblockcount; i++) {
339 ls->sorted_rev[i] = -1;
340 ls->nesting[i] = 1+ls->nesting[i]*ls->nesting[i]*10;
344 void lsra_get_backedges(jitdata *jd) {
355 /* first remove artificial end basicblock from ls->sorted, succ and pred */
357 for (i=0; i < m->basicblockcount; i++) {
358 for (next=&(ls->succ[i]); *next != NULL; next=&((*next)->next)) {
359 if ( (*next)->value == m->basicblockcount ) {
360 /* artificial end bb found */
361 *next = (*next)->next;
362 if (*next == NULL) break;
365 for (next=&(ls->pred[i]); *next != NULL; next=&((*next)->next)) {
366 if ( (*next)->value == m->basicblockcount ) {
367 /* artificial end bb found */
368 *next = (*next)->next;
369 if (*next == NULL) break;
373 if (ls->sorted[i] == m->basicblockcount) j=i;
376 /* if an artificial end block was removed -> change ls->sorted accordingly*/
378 for (i=j+1; i <= m->basicblockcount; i++) {
379 ls->sorted[i-1] = ls->sorted[i];
380 ls->nesting[i-1] = ls->nesting[i];
383 for (i=0; i < m->basicblockcount; i++)
384 if (ls->sorted[i] != -1)
385 ls->sorted_rev[ls->sorted[i]]=i;
387 lsra_get_backedges_(ls, m->basicblockcount);
389 /* - sort backedge by increasing start */
390 for (i=0; i < ls->backedge_count; i++)
391 for (j=i+1; j < ls->backedge_count; j++)
392 if (ls->backedge[i]->start > ls->backedge[j]->start) {
395 ls->backedge[i] = ls->backedge[j];
399 #ifdef LSRA_DEBUG_VERBOSE
400 if (compileverbose) {
401 printf("sorted: \n");
402 for (i=0; i < ls->backedge_count; i++)
403 printf("Backedge: %i - %i, %i - %i\n",
404 ls->sorted[ls->backedge[i]->start],
405 ls->sorted[ls->backedge[i]->end], ls->backedge[i]->start,
406 ls->backedge[i]->end);
407 printf("Nesting Level \n");
408 for (i=0; i<m->basicblockcount; i++) printf(" %3li", ls->nesting[i]);
414 /* - merge overlapping backedges */
417 for (i=0; i < ls->backedge_count-1; i++) {
418 if (ls->backedge[i] != NULL) {
419 for (j = i + 1; (j < ls->backedge_count) && (ls->backedge[j] == NULL); j++ );
420 if (j != ls->backedge_count) {
421 if (ls->backedge[i]->start >= ls->backedge[j]->end) {
423 /* overlapping -> merge */
424 ls->backedge[j]->end = min (ls->backedge[j]->end,
425 ls->backedge[i]->end);
426 ls->backedge[i] = NULL;
432 #ifdef LSRA_DEBUG_VERBOSE
433 if (compileverbose) {
434 printf("merged: \n");
435 for (i = 0; i < ls->backedge_count; i++)
436 if (ls->backedge[i] != NULL)
437 printf("Backedge: %i - %i, %i - %i\n",
438 ls->sorted[ls->backedge[i]->start],
439 ls->sorted[ls->backedge[i]->end],
440 ls->backedge[i]->start, ls->backedge[i]->end);
443 /* - remove backedge[] == NULL from array */
445 for (j = ls->backedge_count - 1; ((j>=0) && (ls->backedge[j] == NULL));
449 if (ls->backedge[i] == NULL) { /* swap backedge[i] and backedge[j]*/
451 ls->backedge[j] = ls->backedge[i];
455 ls->backedge_count--;
458 #ifdef LSRA_DEBUG_VERBOSE
459 if (compileverbose) {
461 for (i=0; i < ls->backedge_count; i++)
462 printf("Backedge: %i - %i, %i - %i\n",
463 ls->sorted[ls->backedge[i]->start],
464 ls->sorted[ls->backedge[i]->end],ls->backedge[i]->start,
465 ls->backedge[i]->end);
470 void lsra_add_cfg(jitdata *jd, int from, int to) {
478 /* ignore Empty, Deleted,... Basic Blocks as target */
479 /* TODO: Setup BasicBlock array before to avoid this */
480 /* best together with using the basicblock list, so lsra works */
481 /* with opt_loops, too */
482 for (;(to < m->basicblockcount) && (m->basicblocks[to].flags < BBREACHED); to++);
484 for (n=ls->succ[from]; (n!= NULL) && (n->value != to); n=n->next);
485 if (n != NULL) return; /* edge from->to already existing */
487 n=DNEW(struct _list);
490 n->next=ls->succ[from];
493 n=DNEW(struct _list);
495 n->next=ls->pred[to];
500 /* add Edges from guarded Areas to Exception handlers in the CFG */
501 void lsra_add_exceptions(jitdata *jd) {
511 ex = jd->exceptiontable;
513 /* add cfg edges from all bb of a try block to the start of the according */
514 /* exception handler to ensure the right order after depthfirst search */
516 #ifdef LSRA_DEBUG_VERBOSE
518 printf("ExTable(%i): ", jd->exceptiontablelength);
521 for (; ex != NULL; ex = ex->down) {
523 #ifdef LSRA_DEBUG_VERBOSE
524 if (compileverbose) {
525 printf("[%i-%i]->%i ",ex->start->nr, ex->end->nr,
527 if (ex->handler->nr >= m->basicblockcount) {
528 log_text("Exceptionhandler Basicblocknummer invalid\n");
531 if (m->basicblocks[ex->handler->nr].flags < BBREACHED) {
532 log_text("Exceptionhandler Basicblocknummer not reachable\n");
535 if (ex->start->nr > ex->end->nr) {
536 log_text("Guarded Area starts after its end\n");
541 /* loop all valid Basic Blocks of the guarded area and add CFG edges */
542 /* to the appropriate handler */
543 for (i=ex->start->nr; (i <= ex->end->nr) &&
544 (i < m->basicblockcount); i++)
545 if (m->basicblocks[i].flags >= BBREACHED)
546 lsra_add_cfg(jd, i, ex->handler->nr);
548 #ifdef LSRA_DEBUG_VERBOSE
549 if (compileverbose) {
555 void lsra_add_jsr(jitdata *jd, int from, int to) {
558 struct _sbr *sbr, *n;
564 /* ignore Empty, Deleted,... Basic Blocks as target */
565 /* TODO: Setup BasicBlock array before to avoid this */
566 /* best together with using the basicblock list, so lsra works */
567 /* with opt_loops, too */
568 for (; (to < m->basicblockcount) && (m->basicblocks[to].flags < BBREACHED);
570 #ifdef LSRA_DEBUG_CHECK
571 if (to == m->basicblockcount)
572 { log_text("Invalid subroutine start index\n"); assert(0); }
575 lsra_add_cfg(jd, from, to);
577 /* from + 1 ist the return Basic Block Index */
578 for (from++; (from < m->basicblockcount) &&
579 (m->basicblocks[from].flags < BBREACHED); from++);
580 #ifdef LSRA_DEBUG_CHECK
581 if (from == m->basicblockcount)
582 { log_text("Invalid return basic block index for jsr\n"); assert(0); }
585 /* add subroutine info in ls->sbr.next */
587 /* search for right place to insert */
588 for (sbr = &(ls->sbr); (sbr->next != NULL) && (sbr->next->header < to); sbr=sbr->next);
590 if ((sbr->next!= NULL) && (sbr->next->header == to)) {
591 /* Entry for this sub already exist */
594 /* make new Entry and insert it in ls->sbr.next */
595 n = DNEW( struct _sbr );
605 /* now insert return adress in sbr->ret */
606 ret = DNEW( struct _list);
608 ret->next = sbr->ret;
612 void lsra_add_sub( jitdata *jd, int b_index, struct _list *ret,
624 /* break at virtual End Block */
625 if (b_index != m->basicblockcount) {
626 visited[b_index] = true;
629 if (m->basicblocks[b_index].flags < BBREACHED)
631 if (!next_block && !(m->basicblocks[b_index].icount))
635 ip = m->basicblocks[b_index].iinstr
636 + m->basicblocks[b_index].icount -1;
638 if (ip->opc == ICMD_JSR) /* nested Subroutines */
643 if (ip->opc == ICMD_RET) {
644 /* subroutine return found -> add return adresses to CFG */
645 for (l = ret; l != NULL; l = l->next)
646 lsra_add_cfg(jd, b_index, l->value);
647 } else { /* follow CFG */
648 for ( l = ls->succ[b_index]; l != NULL; l = l->next)
649 if (!visited[l->value])
650 lsra_add_sub(jd, l->value, ret, visited);
652 } else { /* fall through to next block */
653 if (!visited[b_index + 1])
654 lsra_add_sub(jd, b_index + 1, ret, visited);
659 /* Add subroutines from ls->sbr list to CFG */
660 void lsra_add_subs(jitdata *jd) {
666 #ifdef LSRA_DEBUG_VERBOSE
673 visited = (bool *)DMNEW(int, m->basicblockcount + 1);
674 for (i=0; i <= m->basicblockcount; i++) visited[i] = false;
675 for (sbr = ls->sbr.next; sbr != NULL; sbr=sbr->next) {
677 #ifdef LSRA_DEBUG_VERBOSE
678 if (compileverbose) {
679 printf("Subroutine Header: %3i Return Adresses:",sbr->header);
680 for (ret = sbr->ret; ret != NULL; ret = ret->next)
681 printf(" %3i", ret->value);
685 lsra_add_sub(jd, sbr->header, sbr->ret, visited );
689 /* Generate the Control Flow Graph */
690 /* ( pred,succ,num_pred of lsradata structure) */
692 void lsra_make_cfg(jitdata *jd) {
697 int high, low, count;
704 while (b_index < m->basicblockcount ) {
705 if ((m->basicblocks[b_index].flags >= BBREACHED) &&
706 (len = m->basicblocks[b_index].icount)) {
707 /* block is valid and contains instructions */
709 /* set ip to last instruction */
710 ip = m->basicblocks[b_index].iinstr +
711 m->basicblocks[b_index].icount -1;
712 while ((len>0) && (ip->opc == ICMD_NOP)) {
716 switch (ip->opc) { /* check type of last instruction */
724 lsra_add_cfg(jd, b_index, m->basicblockcount);
725 break; /* function returns -> end of graph */
754 case ICMD_IF_ACMPNE: /* branch -> add next block */
755 lsra_add_cfg(jd, b_index, b_index+1);
756 /* fall throu -> add branch target */
759 lsra_add_cfg(jd, b_index, m->basicblockindex[ip->op1]);
760 break; /* visit branch (goto) target */
762 case ICMD_TABLESWITCH: /* switch statement */
765 lsra_add_cfg(jd, b_index, m->basicblockindex[*s4ptr]);
772 count = (high-low+1);
774 while (--count >= 0) {
776 lsra_add_cfg(jd, b_index,
777 m->basicblockindex[*s4ptr]);
781 case ICMD_LOOKUPSWITCH: /* switch statement */
784 lsra_add_cfg(jd, b_index, m->basicblockindex[*s4ptr]);
789 while (--count >= 0) {
790 lsra_add_cfg(jd, b_index,
791 m->basicblockindex[s4ptr[1]]);
797 lsra_add_jsr(jd, b_index, m->basicblockindex[ip->op1]);
804 lsra_add_cfg(jd, b_index, b_index + 1 );
806 } /* switch (ip->opc)*/
807 } /* if ((m->basicblocks[blockIndex].icount)&& */
808 /* (m->basicblocks[b_index].flags >= BBREACHED)) */
810 } /* while (b_index < m->basicblockcount ) */
813 void lsra_init(jitdata *jd) {
821 /* Init LSRA Data Structures */
822 /* allocate lifetimes for all Basicblocks */
823 /* + 1 for an artificial exit node */
824 /* which is needed as "start" point for the reverse postorder sorting */
825 ls->pred = DMNEW(struct _list *, m->basicblockcount+1);
826 ls->succ = DMNEW(struct _list *, m->basicblockcount+1);
827 ls->sorted = DMNEW(int , m->basicblockcount+1);
828 ls->sorted_rev = DMNEW(int , m->basicblockcount+1);
829 ls->num_pred = DMNEW(int , m->basicblockcount+1);
830 ls->nesting = DMNEW(long , m->basicblockcount+1);
831 for (i=0; i<m->basicblockcount; i++) {
835 ls->sorted_rev[i]=-1;
839 ls->pred[m->basicblockcount]=NULL;
840 ls->succ[m->basicblockcount]=NULL;
841 ls->sorted[m->basicblockcount]=-1;
842 ls->sorted_rev[m->basicblockcount]=-1;
843 ls->num_pred[m->basicblockcount]=0;
850 void lsra_setup(jitdata *jd) {
855 #ifdef LSRA_DEBUG_VERBOSE
872 #if defined(ENABLE_LOOP)
873 /* Loop optimization "destroys" the basicblock array */
874 /* TODO: work with the basicblock list */
876 log_text("lsra not possible with loop optimization\n");
879 #endif /* defined(ENABLE_LOOP) */
881 /* Setup LSRA Data structures */
883 /* Generate the Control Flow Graph */
885 /* gather nesting before adding of Exceptions and Subroutines!!! */
889 lsra_get_nesting(jd);
892 #ifdef LSRA_DEBUG_VERBOSE
893 if (compileverbose) {
894 printf("Successors:\n");
895 for (i=0; i < m->basicblockcount; i++) {
897 for (nl=ls->succ[i]; nl!= NULL; nl=nl->next)
898 printf("%3i ",nl->value);
901 printf("Predecessors:\n");
902 for (i=0; i < m->basicblockcount; i++) {
904 for (nl=ls->pred[i]; nl!= NULL; nl=nl->next)
905 printf("%3i ",nl->value);
909 for (i=0; i < m->basicblockcount; i++) printf("%3i ", ls->sorted[i]);
911 printf("Sorted_rev: ");
912 for (i=0; i < m->basicblockcount; i++) printf("%3i ", ls->sorted_rev[i]);
917 /* add subroutines before exceptions! They "destroy" the CFG */
919 lsra_add_exceptions(jd);
921 /* generate reverse post order sort */
924 /* setup backedge and nested data structures*/
925 lsra_get_backedges(jd);
929 ls->lifetimecount = ls->maxlifetimes + jd->maxlocals * (TYPE_ADR+1);
930 ls->lifetime = DMNEW(struct lifetime, ls->lifetimecount);
931 ls->lt_used = DMNEW(int, ls->lifetimecount);
932 ls->lt_int = DMNEW(int, ls->lifetimecount);
933 ls->lt_int_count = 0;
934 ls->lt_flt = DMNEW(int, ls->lifetimecount);
935 ls->lt_flt_count = 0;
936 ls->lt_mem = DMNEW(int, ls->lifetimecount);
937 ls->lt_mem_count = 0;
939 for (i=0; i < ls->lifetimecount; i++) ls->lifetime[i].type = -1;
941 #ifdef LSRA_DEBUG_VERBOSE
942 if (compileverbose) {
943 printf("Successors:\n");
944 for (i=0; i < m->basicblockcount; i++) {
946 for (nl=ls->succ[i]; nl!= NULL; nl=nl->next)
947 printf("%3i ",nl->value);
950 printf("Predecessors:\n");
951 for (i=0; i < m->basicblockcount; i++) {
953 for (nl=ls->pred[i]; nl!= NULL; nl=nl->next)
954 printf("%3i ",nl->value);
958 for (i=0; i < m->basicblockcount; i++) printf("%3i ", ls->sorted[i]);
960 printf("Sorted_rev: ");
961 for (i=0; i < m->basicblockcount; i++) printf("%3i ", ls->sorted_rev[i]);
967 #ifdef LSRA_DEBUG_CHECK
968 /* compare m->basicblocks[] with the list basicblocks->next */
970 bptr = m->basicblocks;
971 while (bptr != NULL) {
972 if (i > m->basicblockcount){
973 { log_text("linked bb list does not correspond with bb array(1)\n");
976 if (bptr != &(m->basicblocks[i])){
977 { log_text("linked bb list does not correspond with bb array(2)\n");
984 if (i<m->basicblockcount){
985 { log_text("linked bb list does not correspond with bb array(3)\n");
998 methoddesc *md = m->parseddesc;
1000 /* Create Stack Slot lifetimes over all basic blocks */
1001 for (i=m->basicblockcount-1; i >= 0; i--) {
1002 if (ls->sorted[i] != -1) {
1003 lsra_scan_registers_canditates(jd, ls->sorted[i]);
1004 lsra_join_lifetimes(jd, ls->sorted[i]);
1008 /* Parameter initialisiation for locals [0 .. paramcount[ */
1009 /* -> add local var write access at (bb=0,iindex=-1) */
1010 /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
1011 /* this needs a special treatment, wenn lifetimes get extended */
1012 /* over backedges, since this parameter initialisation happens */
1013 /* outside of Basic Block 0 !!!! */
1014 /* this could have been avoided by marking the read access with -1,0 */
1016 for (p = 0, i = 0; p < md->paramcount; p++) {
1017 t = md->paramtypes[p].type;
1019 if (rd->locals[i][t].type >= 0)
1020 /* Param to Local init happens before normal Code */
1021 lsra_usage_local(ls, i, t, 0, -1, LSRA_STORE);
1023 /* increment local counter a second time */
1024 /* for 2 word types */
1025 if (IS_2_WORD_TYPE(t))
1031 lsra_calc_lifetime_length(jd);
1033 #ifdef LSRA_DEBUG_VERBOSE
1035 printf("Basicblockcount: %4i\n",m->basicblockcount);
1040 void lsra_reg_setup(jitdata *jd, struct lsra_register *int_reg,
1041 struct lsra_register *flt_reg ) {
1042 int i, j, iarg, farg;
1045 bool *fltarg_used, *intarg_used;
1054 int_reg->nregdesc = nregdescint;
1055 flt_reg->nregdesc = nregdescfloat;
1056 if (jd->isleafmethod) {
1057 /* Temp and Argumentregister can be used as saved registers */
1059 int_reg->sav_top = INT_ARG_CNT + INT_TMP_CNT + INT_SAV_CNT;
1060 int_reg->sav_reg = DMNEW(int, int_reg->sav_top);
1061 int_reg->tmp_reg = NULL;
1062 int_reg->tmp_top = -1;
1063 flt_reg->sav_top = FLT_ARG_CNT + FLT_TMP_CNT + FLT_SAV_CNT;
1064 flt_reg->sav_reg = DMNEW(int, flt_reg->sav_top);
1065 flt_reg->tmp_reg = NULL;
1066 flt_reg->tmp_top = -1;
1068 /* additionaly precolour registers for Local Variables acting as */
1074 intarg_used = DMNEW(bool, INT_ARG_CNT);
1075 for (i=0; i < INT_ARG_CNT; i++)
1076 intarg_used[i]=false;
1078 fltarg_used = DMNEW(bool, FLT_ARG_CNT);
1079 for (i=0; i < FLT_ARG_CNT; i++)
1080 fltarg_used[i]=false;
1082 int_sav_top=int_reg->sav_top;
1083 flt_sav_top=flt_reg->sav_top;
1085 for (i=0; (i < md->paramcount); i++) {
1086 if (!md->params[i].inmemory) {
1087 if (IS_INT_LNG_TYPE(md->paramtypes[i].type)) {
1088 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1089 if (IS_2_WORD_TYPE(md->paramtypes[i].type)) {
1090 int_reg->sav_reg[--int_sav_top] =
1091 rd->argintregs[GET_HIGH_REG(md->params[i].regoff)];
1092 intarg_used[GET_HIGH_REG(md->params[i].regoff)]=true;
1093 /*used -> don't copy later on */
1094 int_reg->sav_reg[--int_sav_top] =
1095 rd->argintregs[GET_LOW_REG(md->params[i].regoff)];
1096 intarg_used[GET_LOW_REG(md->params[i].regoff)]=true;
1097 /*used -> don't copy later on */
1100 { /* !IS_2_WORD_TYPE(md->paramtypes[i].type */
1101 int_reg->sav_reg[--int_sav_top] =
1102 rd->argintregs[md->params[i].regoff];
1103 intarg_used[md->params[i].regoff]=true;
1104 /*used -> don't copy later on */
1107 #if !defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
1108 /* do not precolour float arguments if they are passed in */
1109 /* integer registers. But these integer argument registers */
1110 /* still be used in the method! */
1111 else { /* IS_FLT_DBL_TYPE(md->paramtypes[i].type */
1112 flt_reg->sav_reg[--flt_sav_top] =
1113 rd->argfltregs[md->params[i].regoff];
1114 fltarg_used[md->params[i].regoff]=true;
1121 /* copy rest of argument registers to flt_reg->sav_reg and */
1122 /* int_reg->sav_reg; */
1123 for (i=0; i < INT_ARG_CNT; i++)
1124 if (!intarg_used[i])
1125 int_reg->sav_reg[--int_sav_top]=rd->argintregs[i];
1126 for (i=0; i < FLT_ARG_CNT; i++)
1127 if (!fltarg_used[i])
1128 flt_reg->sav_reg[--flt_sav_top]=rd->argfltregs[i];
1130 /* copy temp registers to flt_reg->sav_reg and int_reg->sav_reg */
1131 for (i=0; i < INT_TMP_CNT; i++)
1132 int_reg->sav_reg[--int_sav_top]=rd->tmpintregs[i];
1133 for (i=0; i < FLT_TMP_CNT; i++)
1134 flt_reg->sav_reg[--flt_sav_top]=rd->tmpfltregs[i];
1137 /* non leaf method -> use Argument Registers [arg[int|flt]reguse */
1138 /* ... [INT|FLT]_ARG_CNT[ as temp reg */
1139 /* divide temp and saved registers */
1140 int argintreguse, argfltreguse;
1142 /* with Locals as non SAVEDVAR, the used arg[int|flt] as in params */
1143 /* of the method itself have to be regarded, or mismatch before */
1144 /* block 0 with parameter copy could happen! */
1145 argintreguse = max(rd->argintreguse, md->argintreguse);
1146 argfltreguse = max(rd->argfltreguse, md->argfltreguse);
1148 argintreguse = rd->argintreguse;
1149 argfltreguse = rd->argfltreguse;
1151 int_sav_top = int_reg->sav_top = INT_SAV_CNT;
1152 int_reg->sav_reg = DMNEW(int, int_reg->sav_top);
1153 int_reg->tmp_top = INT_TMP_CNT +
1154 max(0, (INT_ARG_CNT - argintreguse));
1155 int_reg->tmp_reg = DMNEW(int, int_reg->tmp_top);
1157 flt_sav_top =flt_reg->sav_top = FLT_SAV_CNT;
1158 flt_reg->sav_reg = DMNEW(int, flt_reg->sav_top);
1159 flt_reg->tmp_top = FLT_TMP_CNT +
1160 max(0 , (FLT_ARG_CNT - argfltreguse));
1161 flt_reg->tmp_reg = DMNEW(int, flt_reg->tmp_top);
1163 /* copy temp and unused argument registers to flt_reg->tmp_reg and */
1164 /* int_reg->tmp_reg */
1165 for (i=0; i < INT_TMP_CNT; i++)
1166 int_reg->tmp_reg[i]=rd->tmpintregs[i];
1167 for (j=argintreguse; j < INT_ARG_CNT; j++, i++)
1168 int_reg->tmp_reg[i]=rd->argintregs[j];
1169 for (i=0; i < FLT_TMP_CNT; i++)
1170 flt_reg->tmp_reg[i]=rd->tmpfltregs[i];
1171 for (j=argfltreguse; j < FLT_ARG_CNT; j++, i++)
1172 flt_reg->tmp_reg[i]=rd->argfltregs[j];
1175 /* now copy saved registers to flt_reg->sav_reg and int_reg->sav_reg */
1176 for (i = INT_SAV_CNT-1; i >= 0; i--)
1177 int_reg->sav_reg[--int_sav_top]=rd->savintregs[i];
1178 for (i = FLT_SAV_CNT-1; i >= 0; i--)
1179 flt_reg->sav_reg[--flt_sav_top]=rd->savfltregs[i];
1183 void lsra_insertion_sort( struct lsradata *ls, int *a, int lo, int hi) {
1186 for (i=lo+1; i<=hi; i++) {
1188 t=ls->lifetime[a[j]].i_start;
1190 while ((j>lo) && (ls->lifetime[a[j-1]].i_start > t)) {
1198 void lsra_qsort( struct lsradata *ls, int *a, int lo, int hi) {
1204 x = ls->lifetime[a[(lo+hi)/2]].i_start;
1207 while (ls->lifetime[a[i]].i_start < x) i++;
1208 while (ls->lifetime[a[j]].i_start > x) j--;
1210 /* exchange a[i], a[j] */
1220 if (lo < j) lsra_qsort( ls, a, lo, j);
1221 if (i < hi) lsra_qsort( ls, a, i, hi);
1223 lsra_insertion_sort(ls, a, lo, hi);
1227 void lsra_param_sort(struct lsradata *ls, int *lifetime, int lifetime_count) {
1232 /* count number of parameters ( .i_start == -1) */
1233 for (param_count=0; (param_count < lifetime_count) &&
1234 (ls->lifetime[lifetime[param_count]].i_start == -1); param_count++);
1236 if (param_count > 0) {
1237 /* now sort the parameters by v_index */
1238 for (i=0; i < param_count -1; i++)
1239 for (j=i+1; j < param_count; j++)
1240 if ( ls->lifetime[lifetime[i]].v_index >
1241 ls->lifetime[lifetime[j]].v_index) {
1244 lifetime[i]=lifetime[j];
1250 void lsra_main(jitdata *jd) {
1251 #ifdef LSRA_DEBUG_VERBOSE
1256 struct lsra_register flt_reg, int_reg;
1259 #if defined(__I386__)
1267 /* sort lifetimes by increasing start */
1268 lsra_qsort( ls, ls->lt_mem, 0, ls->lt_mem_count - 1);
1269 lsra_qsort( ls, ls->lt_int, 0, ls->lt_int_count - 1);
1270 lsra_qsort( ls, ls->lt_flt, 0, ls->lt_flt_count - 1);
1271 /* sort local vars used as parameter */
1272 lsra_param_sort( ls, ls->lt_int, ls->lt_int_count);
1273 lsra_param_sort( ls, ls->lt_flt, ls->lt_flt_count);
1274 lsra_reg_setup(jd, &int_reg, &flt_reg);
1276 #ifdef LSRA_DEBUG_VERBOSE
1277 if (compileverbose) {
1278 printf("INTSAV REG: ");
1279 for (i=0; i<int_reg.sav_top; i++)
1280 printf("%2i ",int_reg.sav_reg[i]);
1281 printf("\nINTTMP REG: ");
1282 for (i=0; i<int_reg.tmp_top; i++)
1283 printf("%2i ",int_reg.tmp_reg[i]);
1284 printf("\nFLTSAV REG: ");
1285 for (i=0; i<flt_reg.sav_top; i++)
1286 printf("%2i ",flt_reg.sav_reg[i]);
1287 printf("\nFLTTMP REG: ");
1288 for (i=0; i<flt_reg.tmp_top; i++)
1289 printf("%2i ",flt_reg.tmp_reg[i]);
1293 ls->active_tmp = DMNEW( struct lifetime *, max(INT_REG_CNT, FLT_REG_CNT));
1294 ls->active_sav = DMNEW( struct lifetime *, max(INT_REG_CNT, FLT_REG_CNT));
1296 lsra_reg_use=INT_SAV_CNT; /* init to no saved reg used... */
1297 _lsra_main(jd, ls->lt_int, ls->lt_int_count, &int_reg, &lsra_reg_use);
1298 if (lsra_reg_use > INT_SAV_CNT)
1299 lsra_reg_use=INT_SAV_CNT;
1300 rd->savintreguse = lsra_reg_use;
1302 lsra_reg_use = FLT_SAV_CNT; /* no saved reg used... */
1303 _lsra_main(jd, ls->lt_flt, ls->lt_flt_count, &flt_reg, &lsra_reg_use);
1304 if (lsra_reg_use > FLT_SAV_CNT)
1305 lsra_reg_use=FLT_SAV_CNT;
1306 rd->savfltreguse=lsra_reg_use;
1308 /* rd->memuse was already set in stack.c to allocate stack space for */
1309 /* passing arguments to called methods */
1310 #if defined(__I386__)
1311 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
1312 /* reserve 0(%esp) for Monitorenter/exit Argument on i386 */
1318 lsra_mem_use = rd->memuse; /* Init with memuse from stack.c */
1320 lsra_alloc(jd, ls->lt_mem, ls->lt_mem_count, &lsra_mem_use);
1321 lsra_alloc(jd, ls->lt_int, ls->lt_int_count, &lsra_mem_use);
1322 lsra_alloc(jd, ls->lt_flt, ls->lt_flt_count, &lsra_mem_use);
1324 rd->memuse=lsra_mem_use;
1326 #ifdef LSRA_DEBUG_VERBOSE
1327 if (compileverbose) {
1328 printf("Int RA complete \n");
1329 printf("Lifetimes after splitting int: \n");
1330 print_lifetimes(jd, ls->lt_int, ls->lt_int_count);
1332 printf("Flt RA complete \n");
1333 printf("Lifetimes after splitting flt:\n");
1334 print_lifetimes(jd, ls->lt_flt, ls->lt_flt_count);
1336 printf("Rest RA complete \n");
1337 printf("Lifetimes after leftt:\n");
1338 print_lifetimes(jd, ls->lt_mem, ls->lt_mem_count);
1343 void lsra_alloc(jitdata *jd, int *lifet, int lifetimecount, int *mem_use)
1346 struct lifetime *lt;
1347 struct freemem *fmem;
1348 struct stackslot *n;
1350 #ifdef HAS_4BYTE_STACKSLOT
1351 struct freemem *fmem_2;
1359 fmem = DNEW(struct freemem);
1362 #ifdef HAS_4BYTE_STACKSLOT
1363 fmem_2=DNEW(struct freemem);
1365 fmem_2->next = NULL;
1368 for (lt_index = 0; lt_index < lifetimecount; lt_index ++) {
1369 lt = &(ls->lifetime[lifet[lt_index]]);
1373 if (lt->reg == -1) {
1375 #ifdef HAS_4BYTE_STACKSLOT
1376 if (IS_2_WORD_TYPE(lt->type))
1377 regoff = lsra_getmem(lt, fmem_2, mem_use);
1380 regoff = lsra_getmem(lt, fmem, mem_use);
1382 flags = lt->savedvar;
1386 if (lt->v_index < 0) {
1387 for (n = lt->local_ss; n != NULL; n = n->next) {
1388 lsra_setflags(&(n->s->flags), flags);
1389 n->s->regoff = regoff;
1391 } else { /* local var */
1392 if (rd->locals[lt->v_index][lt->type].type >= 0) {
1393 rd->locals[lt->v_index][lt->type].flags = flags;
1394 rd->locals[lt->v_index][lt->type].regoff = regoff;
1396 log_text("Type Data mismatch\n");
1404 void lsra_setflags(int *flags, int newflags)
1406 if ( newflags & INMEMORY)
1409 *flags &= ~INMEMORY;
1411 if (newflags & SAVEDVAR)
1415 int lsra_getmem(struct lifetime *lt, struct freemem *fmem, int *mem_use)
1417 struct freemem *fm, *p;
1419 /* no Memory Slot allocated till now or all are still live */
1420 if ((fmem->next == NULL) || (fmem->next->end > lt->i_start)) {
1421 #ifdef HAS_4BYTE_STACKSLOT
1422 if (IS_2_WORD_TYPE(lt->type))
1423 if ( (*mem_use)&1 ) /* align memory location for 2 Word Types */
1425 fm=lsra_getnewmem(mem_use);
1426 if (IS_2_WORD_TYPE(lt->type))
1427 /* allocate a second following Slot for 2 Word Types */
1430 fm=lsra_getnewmem(mem_use);
1433 /* Memoryslot free */
1435 fmem->next = fm->next;
1438 fm->end = lt->i_end;
1439 for (p = fmem; (p->next != NULL) && (p->next->end < fm->end); p = p->next);
1445 struct freemem *lsra_getnewmem(int *mem_use)
1449 fm = DNEW(struct freemem);
1456 void _lsra_main(jitdata *jd, int *lifet, int lifetimecount,
1457 struct lsra_register *reg, int *reg_use)
1459 struct lifetime *lt;
1463 bool temp; /* reg from temp registers (true) or saved registers (false) */
1470 #if !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1473 if ((reg->tmp_top+reg->sav_top) == 0) {
1475 /* no registers available */
1476 for (lt_index = 0; lt_index < lifetimecount; lt_index++)
1477 ls->lifetime[lifet[lt_index]].reg = -1;
1481 ls->active_tmp_top = 0;
1482 ls->active_sav_top = 0;
1484 for (lt_index = 0; lt_index < lifetimecount; lt_index++) {
1485 lt = &(ls->lifetime[lifet[lt_index]]);
1487 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1488 regsneeded = (lt->type == TYPE_LNG)?1:0;
1491 lsra_expire_old_intervalls(jd, lt, reg);
1494 if (lt->savedvar || jd->isleafmethod) {
1495 /* use Saved Reg (in case of leafmethod all regs are saved regs) */
1496 if (reg->sav_top > regsneeded) {
1497 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1499 reg_index = PACK_REGS(reg->sav_reg[--reg->sav_top],
1500 reg->sav_reg[--reg->sav_top]);
1504 reg_index = reg->sav_reg[--reg->sav_top];
1506 } else { /* use Temp Reg or if none is free a Saved Reg */
1507 if (reg->tmp_top > regsneeded) {
1509 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1511 reg_index = PACK_REGS(reg->tmp_reg[--reg->tmp_top],
1512 reg->tmp_reg[--reg->tmp_top]);
1515 reg_index = reg->tmp_reg[--reg->tmp_top];
1518 if (reg->sav_top > regsneeded) {
1520 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1522 reg_index = PACK_REGS(reg->sav_reg[--reg->sav_top],
1523 reg->sav_reg[--reg->sav_top]);
1526 reg_index = reg->sav_reg[--reg->sav_top];
1529 if (reg_index == -1) /* no reg is available anymore... -> spill */
1530 spill_at_intervall(jd, lt);
1532 lt->reg = reg_index;
1534 lsra_add_active(lt, ls->active_tmp, &(ls->active_tmp_top));
1536 if (reg->sav_top<*reg_use) *reg_use=reg->sav_top;
1537 lsra_add_active(lt, ls->active_sav, &(ls->active_sav_top));
1543 void lsra_add_active(struct lifetime *lt, struct lifetime **active,
1548 for(i = 0; (i < *active_top) && (active[i]->i_end < lt->i_end); i++);
1549 for(j = *active_top; j > i; j--) active[j] = active[j-1];
1554 void lsra_expire_old_intervalls(jitdata *jd, struct lifetime *lt,
1555 struct lsra_register *reg)
1557 _lsra_expire_old_intervalls(jd, lt, reg, jd->ls->active_tmp,
1558 &(jd->ls->active_tmp_top));
1559 _lsra_expire_old_intervalls(jd, lt, reg, jd->ls->active_sav,
1560 &(jd->ls->active_sav_top));
1563 void _lsra_expire_old_intervalls(jitdata *jd, struct lifetime *lt,
1564 struct lsra_register *reg,
1565 struct lifetime **active, int *active_top)
1569 for(i = 0; i < *active_top; i++) {
1570 if (active[i]->i_end > lt->i_start) break;
1572 /* make active[i]->reg available again */
1573 if (jd->isleafmethod) {
1574 /* leafmethod -> don't care about type -> put all again into */
1576 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1577 if (active[i]->type == TYPE_LNG) {
1578 reg->sav_reg[reg->sav_top++] = GET_LOW_REG(active[i]->reg);
1579 reg->sav_reg[reg->sav_top++] = GET_HIGH_REG(active[i]->reg);
1582 reg->sav_reg[reg->sav_top++] = active[i]->reg;
1584 /* no leafmethod -> distinguish between temp and saved register */
1585 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1586 if (active[i]->type == TYPE_LNG) {
1587 /* no temp and saved regs are packed together, so looking at */
1588 /* LOW_REG is sufficient */
1589 if ( reg->nregdesc[ GET_LOW_REG(active[i]->reg)] == REG_SAV) {
1590 reg->sav_reg[reg->sav_top++] = GET_LOW_REG(active[i]->reg);
1591 reg->sav_reg[reg->sav_top++] = GET_HIGH_REG(active[i]->reg);
1593 reg->tmp_reg[reg->tmp_top++] = GET_LOW_REG(active[i]->reg);
1594 reg->tmp_reg[reg->tmp_top++] = GET_HIGH_REG(active[i]->reg);
1598 if ( reg->nregdesc[active[i]->reg] == REG_SAV) {
1599 reg->sav_reg[reg->sav_top++] = active[i]->reg;
1601 reg->tmp_reg[reg->tmp_top++] = active[i]->reg;
1606 /* active[0..i[ is to be removed */
1607 /* -> move [i..*active_top[ to [0..*active_top-i[ */
1608 for(k = 0, j = i; (j < *active_top); k++,j++)
1609 active[k] = active[j];
1615 void spill_at_intervall(jitdata *jd, struct lifetime *lt )
1617 if (lt->savedvar || jd->isleafmethod) {
1618 _spill_at_intervall(lt, jd->ls->active_sav, &(jd->ls->active_sav_top));
1620 _spill_at_intervall(lt, jd->ls->active_tmp, &(jd->ls->active_tmp_top));
1621 if (lt->reg == -1) { /* no tmp free anymore */
1622 _spill_at_intervall(lt, jd->ls->active_sav,
1623 &(jd->ls->active_sav_top));
1628 void _spill_at_intervall(struct lifetime *lt, struct lifetime **active,
1632 #ifdef USAGE_COUNT_EXACT
1636 if (*active_top == 0) {
1641 i = *active_top - 1;
1642 #if defined(USAGE_COUNT_EXACT)
1643 /* find intervall which ends later or equal than than lt and has the lowest
1644 usagecount lower than lt */
1646 u_min = lt->usagecount;
1647 for (; (i >= 0) && (active[i]->i_end >= lt->i_end); i--) {
1648 if (active[i]->usagecount < u_min) {
1649 u_min = active[i]->usagecount;
1657 # if defined(USAGE_COUNT) && !defined(USAGE_COUNT_EXACT)
1658 if ((active[i]->i_end >= lt->i_end)
1659 && (active[i]->usagecount < lt->usagecount)) {
1660 # else /* "normal" LSRA heuristic */
1661 /* get last intervall from active */
1662 if (active[i]->i_end > lt->i_end) {
1665 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1666 /* Don't spill between one and two word int types */
1667 if ((active[i]->type == TYPE_LNG) != (lt->type == TYPE_LNG))
1670 lt->reg = active[i]->reg;
1674 for (j = i; j < *active_top; j++)
1675 active[j] = active[j + 1];
1677 lsra_add_active(lt, active, active_top);
1683 void lsra_calc_lifetime_length(jitdata *jd) {
1687 struct lifetime *lt;
1688 #if defined(LSRA_DEBUG_VERBOSE) || !defined(LV)
1693 int flags; /* 0 INMEMORY -> ls->lt_mem */
1694 /* 1 INTREG -> ls->lt_int */
1695 /* 2 FLTREG -> ls->lt_flt */
1702 #ifdef LSRA_DEBUG_VERBOSE
1703 if (compileverbose) {
1704 printf("icount_block: ");
1705 for (i=0; i < m->basicblockcount; i++)
1706 printf("(%3i-%3i) ",i, ls->icount_block[i]);
1711 /* extend lifetime over backedges (for the lsra version without exact
1713 now iterate through lifetimes and expand them */
1716 for(lt_index = 0 ;lt_index < ls->lifetimecount; lt_index++) {
1717 if ( ls->lifetime[lt_index].type != -1) { /* used lifetime */
1718 /* remember lt_index in lt_sorted */
1719 ls->lt_used[lifetimecount++] = lt_index;
1720 lt = &(ls->lifetime[lt_index]);
1721 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1722 /* prevent conflicts between lifetimes of type long by increasing
1723 the lifetime by one instruction
1726 with i==l and/or j==k
1727 to resolve this during codegeneration a temporary register
1729 if (lt->type == TYPE_LNG)
1733 /* distribute lifetimes to lt_int, lt_flt and lt_mem */
1739 #if defined(HAS_4BYTE_STACKSLOT) && !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1752 #if defined(__I386__)
1754 * for i386 put all floats in memory
1762 { log_text("Unknown Type\n"); assert(0); }
1766 case 0: /* lt_used[lt_used_index] -> lt_rest */
1767 ls->lt_mem[ ls->lt_mem_count++ ] = lt_index;
1769 case 1: /* l->lifetimes -> lt_int */
1770 ls->lt_int[ ls->lt_int_count++ ] = lt_index;
1772 case 2: /* l->lifetimes -> lt_flt */
1773 ls->lt_flt[ ls->lt_flt_count++ ] = lt_index;
1778 if (lt->i_first_def == INT_MAX) {
1779 #ifdef LSRA_DEBUG_VERBOSE
1780 printf("Warning: var not defined! vi: %i start: %i end: %i\n",
1781 lt->v_index, lt->i_start, lt->i_end);
1783 lt->bb_first_def = 0;
1784 lt->i_first_def = 0;
1787 lt->i_start = lt->i_first_def;
1789 if (lt->i_last_use == -2) {
1790 #ifdef LSRA_DEBUG_VERBOSE
1791 printf("Warning: Var not used! vi: %i start: %i end: %i\n",
1792 lt->v_index, lt->i_start, lt->i_end);
1794 lt->bb_last_use = lt->bb_first_def;
1795 lt->i_last_use = lt->i_first_def;
1798 lt->i_end = lt->i_last_use;
1800 #ifdef LSRA_DEBUG_VERBOSE
1801 if (lt->i_start > lt->i_end)
1802 printf("Warning: last use before first def! vi: %i start: %i end: %i\n", lt->v_index, lt->i_start, lt->i_end);
1806 if ((lt->bb_first_def != lt->bb_last_use) ||
1807 (lt->i_first_def == -1)) {
1808 /* Lifetime goes over more than one Basic Block -> */
1809 /* check for necessary extension over backedges */
1810 /* see lsra_get_backedges */
1811 /* Arguments are set "before" Block 0, so they have */
1812 /* a lifespan of more then one block, too */
1814 for (i=0; i < ls->backedge_count; i++) {
1815 if (!( (lt->bb_first_def > ls->backedge[i]->start) ||
1816 (lt->bb_last_use < ls->backedge[i]->end) )) {
1817 /* Live intervall intersects with a backedge */
1818 /* if (lt->bb_first_def <= ls->backedge[i]->start) */
1819 if (lt->bb_last_use <= ls->backedge[i]->start)
1821 ls->icount_block[ls->backedge[i]->start] +
1822 m->basicblocks[ls->sorted[ls->backedge[i]->start]].icount;
1826 #endif /* !defined(LV) */
1828 #ifdef USAGE_PER_INSTR
1829 lt->usagecount = lt->usagecount / ( lt->i_end - lt->i_start + 1);
1833 ls->lifetimecount = lifetimecount;
1836 #ifdef LSRA_DEBUG_VERBOSE
1837 void print_lifetimes(jitdata *jd, int *lt, int lifetimecount)
1841 int type,flags,regoff,varkind;
1849 for (lt_index = 0; lt_index < lifetimecount; lt_index++) {
1850 n = &(ls->lifetime[lt[lt_index]]);
1851 if (n->savedvar == SAVEDVAR)
1855 if (n->v_index < 0) { /* stackslot */
1856 type = n->local_ss->s->type;
1857 flags=n->local_ss->s->flags;
1858 regoff=n->local_ss->s->regoff;
1859 varkind=n->local_ss->s->varkind;
1860 } else { /* local var */
1861 if (rd->locals[n->v_index][n->type].type>=0) {
1862 type = rd->locals[n->v_index][n->type].type;
1863 flags=rd->locals[n->v_index][n->type].flags;
1864 regoff=rd->locals[n->v_index][n->type].regoff;
1867 { log_text("Type Data mismatch 3\n"); assert(0); }
1870 printf("i_Start: %3i(%3i,%3i) i_stop: %3i(%3i,%3i) reg: %3i VI: %3i type: %3i flags: %3i varkind: %3i usage: %3li ltflags: %xi \n",n->i_start, ls->sorted[n->bb_first_def], n->i_first_def,n->i_end, ls->sorted[n->bb_last_use], n->i_last_use,regoff,n->v_index,type,flags, varkind, n->usagecount, n->flags);
1872 printf("i_Start: %3i i_stop: %3i reg: %3i VI: %3i type: %3i flags: %3i varkind: %3i usage: %3li ltflags: %xi \n",n->i_start, n->i_end, regoff,n->v_index,type,flags, varkind, n->usagecount, n->flags);
1875 printf( "%3i Lifetimes printed \n",lt_index);
1881 /******************************************************************************
1882 Helpers for first LSRA Version without exact Liveness Analysis
1883 *****************************************************************************/
1886 bool lsra_join_ss( struct lsradata *ls, struct stackelement *in,
1887 struct stackelement *out, int join_flag) {
1888 struct lifetime *lt, *lto;
1889 struct stackslot *ss, *ss_last;
1892 if (in->varnum != out->varnum) {
1893 lt = &(ls->lifetime[-in->varnum - 1]);
1895 #ifdef LSRA_DEBUG_CHECK
1896 if (join_flag == JOIN_BB)
1897 if (lt->type == -1) {
1898 log_text("lsra_join_ss: lifetime for instack not found\n");
1903 if (out->varnum >= 0) { /* no lifetime for this slot till now */
1904 lsra_add_ss(lt, out);
1906 lto = &(ls->lifetime[-out->varnum - 1]);
1907 if ((join_flag == JOIN_DUP) || (join_flag == JOIN_OP))
1908 if ( (lt->flags & JOIN_BB) || (lto->flags & JOIN_BB)) {
1911 if (join_flag == JOIN_DUP)
1912 if ( (lt->flags & JOIN_OP) || (lto->flags & JOIN_OP)) {
1915 #ifdef LSRA_DEBUG_CHECK
1916 if (lto->type == -1) {
1917 log_text("lsra_join_ss: lifetime for outstack not found\n");
1921 #ifdef LSRA_DEBUG_CHECK
1922 if (lto->type != lt->type) {
1923 log_text("lsra_join_ss: in/out stack type mismatch\n");
1928 lt->flags |= JOINING;
1930 /* take Lifetime lto out of ls->lifetimes */
1933 /* merge lto into lt of in */
1935 ss_last = ss = lto->local_ss;
1936 while (ss != NULL) {
1938 ss->s->varnum = lt->v_index;
1941 if (ss_last != NULL) {
1942 ss_last->next = lt->local_ss;
1943 lt->local_ss = lto->local_ss;
1946 lt->savedvar |= lto->savedvar;
1947 lt->flags |= lto->flags | join_flag;
1948 lt->usagecount += lto->usagecount;
1950 /*join of i_first_def and i_last_use */
1951 if (lto->i_first_def < lt->i_first_def) {
1952 lt->i_first_def = lto->i_first_def;
1954 if (lto->i_last_use > lt->i_last_use) {
1955 lt->i_last_use = lto->i_last_use;
1962 /* join instack of Basic Block b_index with outstack of predecessors */
1963 void lsra_join_lifetimes(jitdata *jd,int b_index) {
1966 struct stackelement *in, *i, *out;
1972 /* do not join instack of Exception Handler */
1973 if (m->basicblocks[b_index].type == BBTYPE_EXH)
1975 in=m->basicblocks[b_index].instack;
1976 /* do not join first instack element of a subroutine header */
1977 if (m->basicblocks[b_index].type == BBTYPE_SBR)
1981 for (pred = ls->pred[b_index]; pred != NULL; pred = pred->next) {
1982 out = m->basicblocks[pred->value].outstack;
1983 for (i=in; (i != NULL); i = i->prev, out=out->prev) {
1984 lsra_join_ss(ls, i, out, JOIN_BB);
1990 struct stackslot *lsra_make_ss(stackptr s, int bb_index)
1992 struct stackslot *ss;
1994 ss = DNEW(struct stackslot);
2000 void lsra_add_ss(struct lifetime *lt, stackptr s) {
2001 struct stackslot *ss;
2003 /* Stackslot not in list? */
2004 if (s->varnum != lt->v_index) {
2005 ss = DNEW(struct stackslot);
2007 ss->s->varnum = lt->v_index;
2008 ss->next = lt->local_ss;
2011 lt->savedvar |= s->flags & SAVEDVAR;
2017 struct lifetime *get_ss_lifetime(lsradata *ls, stackptr s) {
2020 if (s->varnum >= 0) { /* new stackslot lifetime */
2021 #ifdef LSRA_DEBUG_CHECK_VERBOSE
2022 if (-ls->v_index - 1 >= ls->maxlifetimes) {
2023 printf("%i %i\n", -ls->v_index - 1, ls->maxlifetimes);
2026 _LSRA_ASSERT(-ls->v_index - 1 < ls->maxlifetimes);
2028 n = &(ls->lifetime[-ls->v_index - 1]);
2030 n->v_index = ls->v_index--;
2033 n->bb_last_use = -1;
2034 n->bb_first_def = -1;
2035 n->i_last_use = -2; /* At -1 param init happens, so -2 is below all
2036 possible instruction indices */
2037 n->i_first_def = INT_MAX;
2042 n = &(ls->lifetime[-s->varnum - 1]);
2048 #define IS_TEMP_VAR(s) (((s)->varkind != ARGVAR) && ((s)->varkind != LOCALVAR))
2050 #define lsra_join_3_stack(ls, dst, src1, src2, join_type) \
2051 if ( IS_TEMP_VAR(dst) ) { \
2053 if ( IS_TEMP_VAR(src1) && ((src1)->type == (dst)->type)) { \
2054 join_ret = lsra_join_ss(ls, dst, src1, join_type); \
2056 if ((!join_ret) && IS_TEMP_VAR(src2) && ((src2)->type == (dst)->type)) { \
2057 lsra_join_ss(ls, dst, src2, join_type); \
2061 #define lsra_join_2_stack(ls, dst, src, join_type) \
2062 if ( IS_TEMP_VAR(dst) ) { \
2063 if ( (IS_TEMP_VAR(src)) && ((src)->type == (dst)->type)) { \
2064 lsra_join_ss(ls, dst, src, join_type); \
2068 #define lsra_join_dup(ls, s1, s2, s3) { \
2069 if (IS_TEMP_VAR(s1)) { \
2071 if (IS_TEMP_VAR(s2)) \
2072 join_ret = lsra_join_ss(ls, s1, s2, JOIN); \
2073 /* undangerous join!*/\
2074 if (IS_TEMP_VAR(s3)) { \
2075 if (join_ret) /* first join succesfull -> second of type */ \
2077 lsra_join_ss(ls, s1, s3, JOIN_DUP); \
2079 lsra_join_ss(ls, s1, s3, JOIN); /* first join did not */ \
2080 /* happen -> second undangerous */ \
2083 if (IS_TEMP_VAR(s2) && IS_TEMP_VAR(s3)) \
2084 lsra_join_ss(ls, s2, s3, JOIN_DUP); \
2087 #define lsra_new_stack(ls, s, block, instr) \
2088 if ((s)->varkind != ARGVAR) _lsra_new_stack(ls, s, block, instr, LSRA_STORE)
2089 void _lsra_new_stack(lsradata *ls, stackptr s, int block, int instr, int store)
2093 if (s->varkind == LOCALVAR) {
2094 lsra_usage_local(ls, s->varnum, s->type, block, instr, LSRA_STORE);
2095 } else /* if (s->varkind != ARGVAR) */ {
2097 n=get_ss_lifetime(ls, s);
2099 if (store == LSRA_BB_IN)
2100 n->flags |= JOIN_BB;
2101 /* remember first def -> overwrite everytime */
2102 n->bb_first_def = ls->sorted_rev[block];
2103 n->i_first_def = ls->icount_block[ls->sorted_rev[block]] + instr;
2105 n->usagecount+=ls->nesting[ls->sorted_rev[block]];
2109 #define lsra_from_stack(ls, s, block, instr) \
2110 if ((s)->varkind != ARGVAR) _lsra_from_stack(ls, s, block, instr, LSRA_LOAD)
2111 #define lsra_pop_from_stack(ls, s, block, instr) \
2112 if ((s)->varkind != ARGVAR) _lsra_from_stack(ls, s, block, instr, LSRA_POP)
2113 void _lsra_from_stack(lsradata *ls, stackptr s, int block, int instr, int store)
2117 if (s->varkind == LOCALVAR) {
2118 lsra_usage_local(ls, s->varnum, s->type, block, instr, LSRA_LOAD);
2119 } else /* if (s->varkind != ARGVAR) */ {
2120 if (s->varkind == STACKVAR )
2121 /* No STACKVARS possible with lsra! */
2122 s->varkind = TEMPVAR;
2124 n=get_ss_lifetime(ls, s);
2126 if (store == LSRA_BB_OUT)
2127 n->flags |= JOIN_BB;
2128 if (n->flags & JOINING)
2129 n->flags &= ~JOINING;
2130 n->usagecount+=ls->nesting[ls->sorted_rev[block]];
2132 /* remember last USE, so only write, if USE Field is undefined (==-1) */
2133 if (n->bb_last_use == -1) {
2134 n->bb_last_use = ls->sorted_rev[block];
2135 n->i_last_use = ls->icount_block[ls->sorted_rev[block]] + instr;
2140 void lsra_usage_local(lsradata *ls, s4 v_index, int type, int block, int instr,
2145 n = &(ls->lifetime[ ls->maxlifetimes + v_index * (TYPE_ADR+1) + type]);
2147 if (n->type == -1) { /* new local lifetime */
2151 n->savedvar = SAVEDVAR;
2155 n->bb_last_use = -1;
2156 n->bb_first_def = -1;
2158 n->i_first_def = INT_MAX;
2160 n->usagecount+=ls->nesting[ls->sorted_rev[block]];
2161 /* add access at (block, instr) to instruction list */
2162 /* remember last USE, so only write, if USE Field is undefined (==-1) */
2163 /* count store as use, too -> defined and not used vars would overwrite */
2165 if (n->bb_last_use == -1) {
2166 n->bb_last_use = ls->sorted_rev[block];
2167 n->i_last_use = ls->icount_block[ls->sorted_rev[block]] + instr;
2169 if (store == LSRA_STORE) {
2170 /* store == LSRA_STORE, remember first def -> overwrite everytime */
2171 n->bb_first_def = ls->sorted_rev[block];
2172 n->i_first_def = ls->icount_block[ls->sorted_rev[block]] + instr;
2176 #ifdef LSRA_DEBUG_VERBOSE
2177 void lsra_dump_stack(stackptr s)
2180 printf("%p(R%3i N%3i K%3i T%3i F%3i) ",(void *)s,s->regoff, s->varnum,
2181 s->varkind, s->type, s->flags);
2189 void lsra_scan_registers_canditates(jitdata *jd, int b_index)
2191 /* methodinfo *lm; */
2192 builtintable_entry *bte;
2200 bool join_ret; /* for lsra_join* Macros */
2207 /* get instruction count for BB and remember the max instruction count */
2209 iindex = m->basicblocks[b_index].icount - 1;
2211 src = m->basicblocks[b_index].instack;
2212 if (m->basicblocks[b_index].type != BBTYPE_STD) {
2213 lsra_new_stack(ls, src, b_index, 0);
2216 for (;src != NULL; src=src->prev) {
2217 /*******************************************************************************
2218 Check this - ? For every incoming Stack Slot a lifetime has to be created ?
2219 *******************************************************************************/
2220 _lsra_new_stack(ls, src, b_index, 0, LSRA_BB_IN);
2222 src = m->basicblocks[b_index].outstack;
2223 for (;src != NULL; src=src->prev) {
2224 _lsra_from_stack(ls, src, b_index, iindex, LSRA_BB_OUT);
2227 /* set iptr to last instruction of BB */
2228 iptr = m->basicblocks[b_index].iinstr + iindex;
2230 for (;iindex >= 0; iindex--, iptr--) {
2232 /* get source and destination Stack for the current instruction */
2233 /* destination stack is available as iptr->dst */
2237 /* source stack is either the destination stack of the previos */
2238 /* instruction, or the basicblock instack for the first instruction */
2240 if (iindex) /* != 0 is > 0 here, since iindex ist always >= 0 */
2243 src=m->basicblocks[b_index].instack;
2251 /* local read (return adress) */
2252 lsra_usage_local(ls, iptr->op1, TYPE_ADR, b_index, iindex,
2256 /* case ICMD_ELSE_ICONST: */
2257 case ICMD_CHECKNULL:
2261 case ICMD_PUTSTATICCONST:
2262 case ICMD_INLINE_START:
2263 case ICMD_INLINE_END:
2264 case ICMD_INLINE_GOTO:
2268 /* local = local+<const> */
2269 lsra_usage_local(ls, iptr->op1, TYPE_INT, b_index, iindex,
2271 lsra_usage_local(ls, iptr->op1, TYPE_INT, b_index, iindex,
2275 /* pop 0 push 1 const: const->stack */
2281 /* new stack slot */
2282 lsra_new_stack(ls, dst, b_index, iindex);
2285 /* pop 0 push 1 load: local->stack */
2291 if (dst->varkind != LOCALVAR) {
2292 /* local->value on stack */
2293 lsra_usage_local(ls, iptr->op1, opcode - ICMD_ILOAD, b_index,
2295 lsra_new_stack(ls, dst, b_index, iindex); /* value->stack */
2296 } else /* if (dst->varnum != iptr->op1) */ {
2297 /* local -> local */
2298 lsra_usage_local(ls, iptr->op1, opcode - ICMD_ILOAD, b_index,
2299 iindex,LSRA_LOAD); /* local->value */
2300 lsra_usage_local(ls, dst->varnum, opcode - ICMD_ILOAD, b_index,
2301 iindex, LSRA_STORE); /* local->value */
2307 /* Stack(arrayref,index)->stack */
2318 lsra_from_stack(ls, src, b_index, iindex);
2319 /* stack->arrayref */
2320 lsra_from_stack(ls, src->prev, b_index, iindex);
2321 /* arrayref[index]->stack */
2322 lsra_new_stack(ls, dst, b_index, iindex);
2326 /* stack(arrayref,index,value)->arrayref[index]=value */
2337 lsra_from_stack(ls, src,b_index, iindex); /* stack -> value */
2338 lsra_from_stack(ls, src->prev, b_index, iindex); /* stack -> index*/
2339 /* stack -> arrayref */
2340 lsra_from_stack(ls, src->prev->prev, b_index, iindex);
2343 /* pop 1 push 0 store: stack -> local */
2349 if (src->varkind != LOCALVAR) {
2350 lsra_from_stack(ls, src, b_index, iindex); /* stack -> value */
2351 lsra_usage_local(ls, iptr->op1, opcode-ICMD_ISTORE, b_index,
2352 iindex, LSRA_STORE); /* local->value */
2353 } else /* if (src->varnum != iptr->op1) */ {
2354 lsra_usage_local(ls, iptr->op1, opcode-ICMD_ISTORE, b_index,
2355 iindex, LSRA_STORE); /* local->value */
2356 lsra_usage_local(ls, src->varnum, opcode-ICMD_ISTORE, b_index,
2357 iindex, LSRA_LOAD); /* local->value */
2362 case ICMD_POP: /* throw away a stackslot */
2363 /* TODO: check if used anyway (DUP...) and change codegen to */
2364 /* ignore this stackslot */
2365 lsra_pop_from_stack(ls, src, b_index, iindex);
2373 case ICMD_ARETURN: /* stack(value) -> [empty] */
2375 case ICMD_ATHROW: /* stack(objref) -> undefined */
2377 case ICMD_PUTSTATIC: /* stack(value) -> static_field */
2378 case ICMD_PUTFIELDCONST:
2380 /* pop 1 push 0 branch */
2381 case ICMD_IFNULL: /* stack(value) -> branch? */
2382 case ICMD_IFNONNULL:
2398 /* pop 1 push 0 table branch */
2399 case ICMD_TABLESWITCH:
2400 case ICMD_LOOKUPSWITCH:
2402 case ICMD_MONITORENTER:
2403 case ICMD_MONITOREXIT:
2404 lsra_from_stack(ls, src, b_index, iindex); /* stack -> value */
2408 case ICMD_POP2: /* throw away 2 stackslots */
2409 /* TODO: check if used anyway (DUP...) and change codegen to */
2410 /* ignore this stackslot */
2411 lsra_pop_from_stack(ls, src, b_index, iindex);
2412 lsra_pop_from_stack(ls, src->prev, b_index, iindex);
2415 /* pop 2 push 0 branch */
2417 case ICMD_IF_ICMPEQ: /* stack (v1,v2) -> branch(v1,v2) */
2418 case ICMD_IF_ICMPNE:
2419 case ICMD_IF_ICMPLT:
2420 case ICMD_IF_ICMPGE:
2421 case ICMD_IF_ICMPGT:
2422 case ICMD_IF_ICMPLE:
2424 case ICMD_IF_LCMPEQ:
2425 case ICMD_IF_LCMPNE:
2426 case ICMD_IF_LCMPLT:
2427 case ICMD_IF_LCMPGE:
2428 case ICMD_IF_LCMPGT:
2429 case ICMD_IF_LCMPLE:
2431 case ICMD_IF_ACMPEQ:
2432 case ICMD_IF_ACMPNE:
2435 case ICMD_PUTFIELD: /* stack(objref,value) -> objref = value */
2437 case ICMD_IASTORECONST:
2438 case ICMD_LASTORECONST:
2439 case ICMD_AASTORECONST:
2440 case ICMD_BASTORECONST:
2441 case ICMD_CASTORECONST:
2442 case ICMD_SASTORECONST:
2443 lsra_from_stack(ls, src, b_index, iindex); /* stack -> value*/
2444 lsra_from_stack(ls, src->prev, b_index, iindex);
2447 /* pop 0 push 1 dup */
2448 case ICMD_DUP: /* src == dst->prev, src -> dst */
2449 /* lsra_from_stack(ls, src,b_index,iindex);*/
2450 lsra_new_stack(ls, dst, b_index, iindex);
2452 #ifdef JOIN_DUP_STACK
2453 /* src is identical to dst->prev */
2454 lsra_join_2_stack(ls, src, dst, JOIN_DUP);
2458 /* pop 0 push 2 dup */
2460 /* lsra_from_stack(ls, src,b_index, iindex); */
2461 /* lsra_from_stack(ls, src->prev, b_index, iindex); */
2462 lsra_new_stack(ls, dst->prev, b_index, iindex);
2463 lsra_new_stack(ls, dst, b_index, iindex);
2465 #ifdef JOIN_DUP_STACK
2466 lsra_join_2_stack(ls, src, dst, JOIN_DUP);
2467 lsra_join_2_stack(ls, src->prev, dst->prev, JOIN_DUP);
2468 /* src is identical to dst->prev->prev */
2469 /* src->prev is identical to dst->prev->prev->prev */
2473 /* pop 2 push 3 dup */
2475 lsra_from_stack(ls, src, b_index, iindex+1);
2476 lsra_from_stack(ls, src->prev, b_index, iindex+1);
2477 lsra_new_stack(ls, dst->prev->prev, b_index, iindex);
2478 lsra_new_stack(ls, dst->prev, b_index, iindex);
2479 lsra_new_stack(ls, dst, b_index, iindex);
2480 #ifdef JOIN_DUP_STACK
2481 lsra_join_dup(ls, src, dst, dst->prev->prev);
2482 lsra_join_2_stack(ls, src->prev, dst->prev, JOIN);
2486 /* pop 3 push 4 dup */
2488 lsra_from_stack(ls, src,b_index, iindex+1);
2489 lsra_from_stack(ls, src->prev, b_index, iindex+1);
2490 lsra_from_stack(ls, src->prev->prev, b_index, iindex+1);
2491 lsra_new_stack(ls, dst->prev->prev->prev, b_index, iindex);
2492 lsra_new_stack(ls, dst->prev->prev, b_index, iindex);
2493 lsra_new_stack(ls, dst->prev, b_index, iindex);
2494 lsra_new_stack(ls, dst, b_index, iindex);
2496 #ifdef JOIN_DUP_STACK
2497 lsra_join_dup(ls, src, dst, dst->prev->prev->prev);
2498 lsra_join_2_stack(ls, src->prev, dst->prev, JOIN);
2499 lsra_join_2_stack(ls, src->prev->prev, dst->prev->prev, JOIN);
2503 /* pop 3 push 5 dup */
2505 lsra_from_stack(ls, src, b_index, iindex+1);
2506 lsra_from_stack(ls, src->prev, b_index, iindex+1);
2507 lsra_from_stack(ls, src->prev->prev, b_index, iindex+1);
2508 lsra_new_stack(ls, dst->prev->prev->prev->prev, b_index, iindex);
2509 lsra_new_stack(ls, dst->prev->prev->prev, b_index, iindex);
2510 lsra_new_stack(ls, dst->prev->prev, b_index, iindex);
2511 lsra_new_stack(ls, dst->prev, b_index, iindex);
2512 lsra_new_stack(ls, dst, b_index, iindex);
2514 #ifdef JOIN_DUP_STACK
2515 lsra_join_dup(ls, src, dst, dst->prev->prev->prev);
2516 lsra_join_dup(ls, src->prev, dst->prev,
2517 dst->prev->prev->prev->prev);
2518 lsra_join_2_stack(ls, src->prev->prev, dst->prev->prev, JOIN);
2522 /* pop 4 push 6 dup */
2524 lsra_from_stack(ls, src, b_index, iindex+1);
2525 lsra_from_stack(ls, src->prev, b_index, iindex+1);
2526 lsra_from_stack(ls, src->prev->prev, b_index, iindex+1);
2527 lsra_from_stack(ls, src->prev->prev->prev, b_index, iindex+1);
2528 lsra_new_stack(ls, dst->prev->prev->prev->prev->prev, b_index,
2530 lsra_new_stack(ls, dst->prev->prev->prev->prev, b_index, iindex);
2531 lsra_new_stack(ls, dst->prev->prev->prev, b_index, iindex);
2532 lsra_new_stack(ls, dst->prev->prev, b_index, iindex);
2533 lsra_new_stack(ls, dst->prev, b_index, iindex);
2534 lsra_new_stack(ls, dst, b_index, iindex);
2536 #ifdef JOIN_DUP_STACK
2537 lsra_join_dup(ls, src, dst, dst->prev->prev->prev->prev);
2538 lsra_join_dup(ls, src->prev, dst->prev,
2539 dst->prev->prev->prev->prev->prev);
2540 lsra_join_2_stack(ls, src->prev->prev, dst->prev->prev, JOIN);
2541 lsra_join_2_stack(ls, src->prev->prev->prev, dst->prev->prev->prev,
2546 /* pop 2 push 2 swap */
2548 lsra_from_stack(ls, src, b_index, iindex+1);
2549 lsra_from_stack(ls, src->prev, b_index, iindex+1);
2550 lsra_new_stack(ls, dst->prev, b_index, iindex);
2551 lsra_new_stack(ls, dst, b_index, iindex);
2553 lsra_join_2_stack(ls, src->prev, dst, JOIN);
2554 lsra_join_2_stack(ls, src, dst->prev, JOIN);
2592 lsra_from_stack(ls, src, b_index, iindex);
2593 lsra_from_stack(ls, src->prev, b_index, iindex);
2594 lsra_new_stack(ls, dst, b_index, iindex);
2595 #ifdef JOIN_DEST_STACK
2596 lsra_join_3_stack(ls, dst, src->prev, src, JOIN_OP);
2601 lsra_from_stack(ls, src, b_index, iindex);
2602 lsra_from_stack(ls, src->prev,b_index,iindex);
2603 lsra_new_stack(ls, dst, b_index, iindex);
2604 #ifdef JOIN_DEST_STACK
2605 lsra_join_2_stack(ls, src, dst, JOIN_OP);
2623 lsra_from_stack(ls, src, b_index, iindex);
2624 lsra_from_stack(ls, src->prev, b_index, iindex);
2625 lsra_new_stack(ls, dst, b_index, iindex);
2629 case ICMD_LADDCONST:
2630 case ICMD_LSUBCONST:
2631 case ICMD_LMULCONST:
2635 case ICMD_LANDCONST:
2637 case ICMD_LXORCONST:
2638 case ICMD_LSHLCONST:
2639 case ICMD_LSHRCONST:
2640 case ICMD_LUSHRCONST:
2642 case ICMD_IADDCONST:
2643 case ICMD_ISUBCONST:
2644 case ICMD_IMULCONST:
2648 case ICMD_IANDCONST:
2650 case ICMD_IXORCONST:
2651 case ICMD_ISHLCONST:
2652 case ICMD_ISHRCONST:
2653 case ICMD_IUSHRCONST:
2655 /* case ICMD_IFEQ_ICONST: */
2656 /* case ICMD_IFNE_ICONST: */
2657 /* case ICMD_IFLT_ICONST: */
2658 /* case ICMD_IFGE_ICONST: */
2659 /* case ICMD_IFGT_ICONST: */
2660 /* case ICMD_IFLE_ICONST: */
2665 case ICMD_INT2SHORT:
2683 case ICMD_CHECKCAST:
2684 lsra_from_stack(ls, src, b_index, iindex);
2685 lsra_new_stack(ls, dst, b_index, iindex);
2686 #ifdef JOIN_DEST_STACK
2687 lsra_join_2_stack(ls, src, dst, JOIN_OP);
2691 /* TODO: check if for these ICMDs JOIN_DEST_STACK works, too! */
2692 case ICMD_ARRAYLENGTH:
2693 case ICMD_INSTANCEOF:
2696 case ICMD_ANEWARRAY:
2699 lsra_from_stack(ls, src, b_index, iindex);
2700 lsra_new_stack(ls, dst, b_index, iindex);
2704 case ICMD_GETSTATIC:
2707 lsra_new_stack(ls, dst, b_index, iindex);
2710 /* pop many push any */
2712 case ICMD_INVOKESTATIC:
2713 case ICMD_INVOKESPECIAL:
2714 case ICMD_INVOKEVIRTUAL:
2715 case ICMD_INVOKEINTERFACE:
2716 INSTRUCTION_GET_METHODDESC(iptr,md);
2719 lsra_from_stack(ls, src, b_index, iindex);
2722 if (md->returntype.type != TYPE_VOID)
2723 lsra_new_stack(ls, dst, b_index, iindex);
2732 lsra_from_stack(ls, src, b_index, iindex);
2735 if (md->returntype.type != TYPE_VOID)
2736 lsra_new_stack(ls, dst, b_index, iindex);
2739 case ICMD_MULTIANEWARRAY:
2742 lsra_from_stack(ls, src, b_index, iindex);
2745 lsra_new_stack(ls, dst, b_index, iindex);
2749 exceptions_throw_internalerror("Unknown ICMD %d during register allocation",
2755 #endif /* defined(LV) */
2759 * These are local overrides for various environment variables in Emacs.
2760 * Please do not remove this and leave it at the end of the file, where
2761 * Emacs will automagically detect them.
2762 * ---------------------------------------------------------------------
2765 * indent-tabs-mode: t
2769 * vim:noexpandtab:sw=4:ts=4: