1 /* src/vm/jit/allocator/lsra.c - linear scan register allocator
3 Copyright (C) 2005, 2006, 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
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.
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.
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
38 #include "mm/memory.h"
40 #include "toolbox/logging.h"
42 #include "vm/jit/builtin.hpp"
43 #include "vm/exceptions.hpp"
44 #include "vm/resolve.h"
45 #include "vm/options.h"
46 #include "vm/statistics.h"
48 #include "vm/jit/abi.h"
49 #include "vm/jit/reg.h"
51 #include "vm/jit/allocator/liveness.h"
52 #include "vm/jit/allocator/lsra.h"
55 extern char **prof_m_names;
56 extern u4 **prof_bb_freq;
60 /* function prototypes */
61 void lsra_init(jitdata *);
62 void lsra_setup(jitdata *);
63 void lsra_main(jitdata *);
65 void lsra_reg_setup(jitdata *, struct lsra_register *, struct lsra_register * );
66 void lsra_calc_lifetime_length(jitdata *);
67 void _lsra_main( jitdata *, int *, int, struct lsra_register *, int *);
68 void lsra_expire_old_intervalls(jitdata *, struct lifetime *,
69 struct lsra_register *);
70 void spill_at_intervall(jitdata *, struct lifetime *);
71 void lsra_add_active(struct lifetime *, struct lifetime **, int *);
72 void _lsra_expire_old_intervalls(jitdata *, struct lifetime *,
73 struct lsra_register *, struct lifetime **,
75 void _spill_at_intervall(struct lifetime *, struct lifetime **, int *);
77 void lsra_alloc(jitdata *, int *, int, int *);
78 int lsra_getmem(struct lifetime *, struct freemem *, int *);
79 struct freemem *lsra_getnewmem(int *);
80 void lsra_setflags(int *, int);
82 #ifdef LSRA_DEBUG_VERBOSE
83 void lsra_dump_stack(stackelement_t* );
84 void print_lifetimes(jitdata *, int *, int);
88 void lsra_scan_registers_canditates(jitdata *, int);
89 void lsra_join_lifetimes(jitdata *, int);
91 void _lsra_new_stack( lsradata *, stackelement_t* , int , int, int);
92 void _lsra_from_stack(lsradata *, stackelement_t* , int , int, int);
93 void lsra_add_ss(struct lifetime *, stackelement_t* );
94 void lsra_usage_local(lsradata *, s4 , int , int , int , int );
99 bool lsra(jitdata *jd)
101 #if defined(ENABLE_STATISTICS)
106 #if defined(LSRA_DEBUG_CHECK)
109 stackelement_t* in,out;
113 #if defined(LSRA_DEBUG_CHECK)
116 while (b_index < m->basicblockcount ) {
118 if (m->basicblocks[b_index].flags >= BBREACHED) {
120 in=m->basicblocks[b_index].instack;
121 ind=m->basicblocks[b_index].indepth;
122 for (;ind != 0;in=in->prev, ind--) {
123 /* ARGVAR or LOCALVAR in instack is ok*/
125 if (in->varkind == ARGVAR) printf("ARGVAR in instack: \n");
126 if (in->varkind == LOCALVAR) printf("LOCALVAR in instack\n");
129 out=m->basicblocks[b_index].outstack;
130 outd=m->basicblocks[b_index].outdepth;
131 for (;outd != 0;out=out->prev, outd--) {
132 if (out->varkind == ARGVAR)
133 { log_text("ARGVAR in outstack\n"); assert(0); }
134 if (out->varkind == LOCALVAR)
135 { log_text("LOCALVAR in outstack\n"); assert(0); }
142 jd->ls = DNEW(lsradata);
146 #if defined(ENABLE_STATISTICS)
147 /* find conflicts between locals for statistics */
150 /* local Variable Lifetimes are at the end of the lifetime array and */
151 /* have v_index >= 0 */
152 for (locals_start = ls->lifetimecount-1; (locals_start >=0) &&
153 (ls->lifetime[ls->lt_used[locals_start]].v_index >= 0);
155 for (i=locals_start + 1; i < ls->lifetimecount; i++)
156 for (j=i+1; j < ls->lifetimecount; j++)
157 if ( !((ls->lifetime[ls->lt_used[i]].i_end
158 < ls->lifetime[ls->lt_used[j]].i_start)
159 || (ls->lifetime[ls->lt_used[j]].i_end <
160 ls->lifetime[ls->lt_used[i]].i_start)) )
161 count_locals_conflicts += 2;
167 /* everything's ok */
172 /* sort Basic Blocks using Depth First Search in reverse post order in */
174 void lsra_DFS(jitdata *jd) {
188 stack = DMNEW( int, m->basicblockcount + 1);
189 visited = (int *)DMNEW( int, m->basicblockcount + 1);
190 for (i = 0; i <= m->basicblockcount; i++) {
193 ls->sorted_rev[i]=-1;
196 stack[0] = 0; /* start with Block 0 */
198 visited[0] = ls->num_pred[0]; /* Start Block is handled right and can be */
202 while (not_finished) {
203 while (stack_top != 0) {
205 i = stack[stack_top];
208 for (succ = ls->succ[i]; succ != NULL; succ = succ->next) {
209 visited[succ->value]++;
210 if (visited[succ->value] == ls->num_pred[succ->value]) {
211 /* push the node on the stack, only if all ancestors have */
213 stack[stack_top] = succ->value;
218 not_finished = false;
219 for (i=1; i <= m->basicblockcount; i++) {
220 /* search for visited blocks, which have not reached the num_pred */
221 /* and put them on the stack -> happens with backedges */
222 if ((visited[i] != 0) && (visited[i] < ls->num_pred[i])) {
223 stack[stack_top] = i;
225 visited[i] = ls->num_pred[i];
233 void lsra_get_backedges_(lsradata *ls, int basicblockcount) {
236 struct _backedge *_backedges;
242 /* now look for backedges */
243 ls->backedge_count = 0;
244 for(i=0; i < basicblockcount; i++) {
245 if (ls->sorted[i] != -1)
246 for(s=ls->succ[ls->sorted[i]]; s != NULL; s=s->next) {
247 if (i >= ls->sorted_rev[s->value]) {
248 n=DNEW(struct _backedge);
249 n->start = max(i, ls->sorted_rev[s->value]);
250 n->end = min(i, ls->sorted_rev[s->value]);
251 n->next = _backedges;
253 ls->backedge_count++;
257 /* put _backedges in ls->backedge array */
258 ls->backedge = DMNEW(struct _backedge *, ls->backedge_count);
259 for (n=_backedges, i=0; n != NULL; n=n->next, i++) {
261 ls->backedge[i]->nesting = 1;
265 void lsra_get_nesting(jitdata *jd) {
274 for (i=0; i <= m->basicblockcount; i++)
275 if (ls->sorted[i] != -1)
276 ls->sorted_rev[ls->sorted[i]]=i;
278 lsra_get_backedges_(ls, m->basicblockcount + 1);
279 /* - sort backedge by increasing end: */
280 for (i=0; i < ls->backedge_count; i++)
281 for (j=i+1; j < ls->backedge_count; j++)
282 if ((ls->backedge[i]->end > ls->backedge[j]->end) || /* -> swap */
283 ((ls->backedge[i]->end == ls->backedge[j]->end) &&
284 (ls->backedge[i]->start > ls->backedge[j]->start) )) {
286 ls->backedge[i]=ls->backedge[j];
290 /* create ls->nesting */
291 /* look for nesting depth (overlapping backedges*/
292 for (i=0; i < ls->backedge_count - 1; i++) {
293 for (j = i + 1; (j < ls->backedge_count) &&
294 (ls->backedge[i]->start >= ls->backedge[j]->end); j++)
295 ls->backedge[j]->nesting += ls->backedge[i]->nesting;
300 while ( (i < m->basicblockcount + 1) ) {
301 if (j < ls->backedge_count) {
302 while ( i < ls->backedge[j]->end ) {
306 if ( (j+1) < ls->backedge_count)
307 end = min(ls->backedge[j]->start, ls->backedge[j+1]->end - 1);
309 end = ls->backedge[j]->start;
311 ls->nesting[i] = ls->backedge[j]->nesting;
321 #ifdef LSRA_DEBUG_VERBOSE
322 if (compileverbose) {
323 printf("sorted: \n");
324 for (i=0; i < ls->backedge_count; i++)
325 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);
326 printf("Nesting Level \n");
327 for (i=0; i<m->basicblockcount; i++) printf(" %3li", ls->nesting[i]);
331 for (i=0; i <= m->basicblockcount; i++) {
332 ls->sorted_rev[i] = -1;
333 ls->nesting[i] = 1+ls->nesting[i]*ls->nesting[i]*10;
337 void lsra_get_backedges(jitdata *jd) {
348 /* first remove artificial end basicblock from ls->sorted, succ and pred */
350 for (i=0; i < m->basicblockcount; i++) {
351 for (next=&(ls->succ[i]); *next != NULL; next=&((*next)->next)) {
352 if ( (*next)->value == m->basicblockcount ) {
353 /* artificial end bb found */
354 *next = (*next)->next;
355 if (*next == NULL) break;
358 for (next=&(ls->pred[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;
366 if (ls->sorted[i] == m->basicblockcount) j=i;
369 /* if an artificial end block was removed -> change ls->sorted accordingly*/
371 for (i=j+1; i <= m->basicblockcount; i++) {
372 ls->sorted[i-1] = ls->sorted[i];
373 ls->nesting[i-1] = ls->nesting[i];
376 for (i=0; i < m->basicblockcount; i++)
377 if (ls->sorted[i] != -1)
378 ls->sorted_rev[ls->sorted[i]]=i;
380 lsra_get_backedges_(ls, m->basicblockcount);
382 /* - sort backedge by increasing start */
383 for (i=0; i < ls->backedge_count; i++)
384 for (j=i+1; j < ls->backedge_count; j++)
385 if (ls->backedge[i]->start > ls->backedge[j]->start) {
388 ls->backedge[i] = ls->backedge[j];
392 #ifdef LSRA_DEBUG_VERBOSE
393 if (compileverbose) {
394 printf("sorted: \n");
395 for (i=0; i < ls->backedge_count; i++)
396 printf("Backedge: %i - %i, %i - %i\n",
397 ls->sorted[ls->backedge[i]->start],
398 ls->sorted[ls->backedge[i]->end], ls->backedge[i]->start,
399 ls->backedge[i]->end);
400 printf("Nesting Level \n");
401 for (i=0; i<m->basicblockcount; i++) printf(" %3li", ls->nesting[i]);
407 /* - merge overlapping backedges */
410 for (i=0; i < ls->backedge_count-1; i++) {
411 if (ls->backedge[i] != NULL) {
412 for (j = i + 1; (j < ls->backedge_count) && (ls->backedge[j] == NULL); j++ );
413 if (j != ls->backedge_count) {
414 if (ls->backedge[i]->start >= ls->backedge[j]->end) {
416 /* overlapping -> merge */
417 ls->backedge[j]->end = min (ls->backedge[j]->end,
418 ls->backedge[i]->end);
419 ls->backedge[i] = NULL;
425 #ifdef LSRA_DEBUG_VERBOSE
426 if (compileverbose) {
427 printf("merged: \n");
428 for (i = 0; i < ls->backedge_count; i++)
429 if (ls->backedge[i] != NULL)
430 printf("Backedge: %i - %i, %i - %i\n",
431 ls->sorted[ls->backedge[i]->start],
432 ls->sorted[ls->backedge[i]->end],
433 ls->backedge[i]->start, ls->backedge[i]->end);
436 /* - remove backedge[] == NULL from array */
438 for (j = ls->backedge_count - 1; ((j>=0) && (ls->backedge[j] == NULL));
442 if (ls->backedge[i] == NULL) { /* swap backedge[i] and backedge[j]*/
444 ls->backedge[j] = ls->backedge[i];
448 ls->backedge_count--;
451 #ifdef LSRA_DEBUG_VERBOSE
452 if (compileverbose) {
454 for (i=0; i < ls->backedge_count; i++)
455 printf("Backedge: %i - %i, %i - %i\n",
456 ls->sorted[ls->backedge[i]->start],
457 ls->sorted[ls->backedge[i]->end],ls->backedge[i]->start,
458 ls->backedge[i]->end);
463 void lsra_add_cfg(jitdata *jd, int from, int to) {
471 /* ignore Empty, Deleted,... Basic Blocks as target */
472 /* TODO: Setup BasicBlock array before to avoid this */
473 /* best together with using the basicblock list, so lsra works */
474 /* with opt_loops, too */
475 for (;(to < m->basicblockcount) && (m->basicblocks[to].flags < BBREACHED); to++);
477 for (n=ls->succ[from]; (n!= NULL) && (n->value != to); n=n->next);
478 if (n != NULL) return; /* edge from->to already existing */
480 n=DNEW(struct _list);
483 n->next=ls->succ[from];
486 n=DNEW(struct _list);
488 n->next=ls->pred[to];
493 /* add Edges from guarded Areas to Exception handlers in the CFG */
494 void lsra_add_exceptions(jitdata *jd) {
504 ex = jd->exceptiontable;
506 /* add cfg edges from all bb of a try block to the start of the according */
507 /* exception handler to ensure the right order after depthfirst search */
509 #ifdef LSRA_DEBUG_VERBOSE
511 printf("ExTable(%i): ", jd->exceptiontablelength);
514 for (; ex != NULL; ex = ex->down) {
516 #ifdef LSRA_DEBUG_VERBOSE
517 if (compileverbose) {
518 printf("[%i-%i]->%i ",ex->start->nr, ex->end->nr,
520 if (ex->handler->nr >= m->basicblockcount) {
521 log_text("Exceptionhandler Basicblocknummer invalid\n");
524 if (m->basicblocks[ex->handler->nr].flags < BBREACHED) {
525 log_text("Exceptionhandler Basicblocknummer not reachable\n");
528 if (ex->start->nr > ex->end->nr) {
529 log_text("Guarded Area starts after its end\n");
534 /* loop all valid Basic Blocks of the guarded area and add CFG edges */
535 /* to the appropriate handler */
536 for (i=ex->start->nr; (i <= ex->end->nr) &&
537 (i < m->basicblockcount); i++)
538 if (m->basicblocks[i].flags >= BBREACHED)
539 lsra_add_cfg(jd, i, ex->handler->nr);
541 #ifdef LSRA_DEBUG_VERBOSE
542 if (compileverbose) {
548 void lsra_add_jsr(jitdata *jd, int from, int to) {
551 struct _sbr *sbr, *n;
557 /* ignore Empty, Deleted,... Basic Blocks as target */
558 /* TODO: Setup BasicBlock array before to avoid this */
559 /* best together with using the basicblock list, so lsra works */
560 /* with opt_loops, too */
561 for (; (to < m->basicblockcount) && (m->basicblocks[to].flags < BBREACHED);
563 #ifdef LSRA_DEBUG_CHECK
564 if (to == m->basicblockcount)
565 { log_text("Invalid subroutine start index\n"); assert(0); }
568 lsra_add_cfg(jd, from, to);
570 /* from + 1 ist the return Basic Block Index */
571 for (from++; (from < m->basicblockcount) &&
572 (m->basicblocks[from].flags < BBREACHED); from++);
573 #ifdef LSRA_DEBUG_CHECK
574 if (from == m->basicblockcount)
575 { log_text("Invalid return basic block index for jsr\n"); assert(0); }
578 /* add subroutine info in ls->sbr.next */
580 /* search for right place to insert */
581 for (sbr = &(ls->sbr); (sbr->next != NULL) && (sbr->next->header < to); sbr=sbr->next);
583 if ((sbr->next!= NULL) && (sbr->next->header == to)) {
584 /* Entry for this sub already exist */
587 /* make new Entry and insert it in ls->sbr.next */
588 n = DNEW( struct _sbr );
598 /* now insert return adress in sbr->ret */
599 ret = DNEW( struct _list);
601 ret->next = sbr->ret;
605 void lsra_add_sub( jitdata *jd, int b_index, struct _list *ret,
617 /* break at virtual End Block */
618 if (b_index != m->basicblockcount) {
619 visited[b_index] = true;
622 if (m->basicblocks[b_index].flags < BBREACHED)
624 if (!next_block && !(m->basicblocks[b_index].icount))
628 ip = m->basicblocks[b_index].iinstr
629 + m->basicblocks[b_index].icount -1;
631 if (ip->opc == ICMD_JSR) /* nested Subroutines */
636 if (ip->opc == ICMD_RET) {
637 /* subroutine return found -> add return adresses to CFG */
638 for (l = ret; l != NULL; l = l->next)
639 lsra_add_cfg(jd, b_index, l->value);
640 } else { /* follow CFG */
641 for ( l = ls->succ[b_index]; l != NULL; l = l->next)
642 if (!visited[l->value])
643 lsra_add_sub(jd, l->value, ret, visited);
645 } else { /* fall through to next block */
646 if (!visited[b_index + 1])
647 lsra_add_sub(jd, b_index + 1, ret, visited);
652 /* Add subroutines from ls->sbr list to CFG */
653 void lsra_add_subs(jitdata *jd) {
659 #ifdef LSRA_DEBUG_VERBOSE
666 visited = (bool *)DMNEW(int, m->basicblockcount + 1);
667 for (i=0; i <= m->basicblockcount; i++) visited[i] = false;
668 for (sbr = ls->sbr.next; sbr != NULL; sbr=sbr->next) {
670 #ifdef LSRA_DEBUG_VERBOSE
671 if (compileverbose) {
672 printf("Subroutine Header: %3i Return Adresses:",sbr->header);
673 for (ret = sbr->ret; ret != NULL; ret = ret->next)
674 printf(" %3i", ret->value);
678 lsra_add_sub(jd, sbr->header, sbr->ret, visited );
682 /* Generate the Control Flow Graph */
683 /* ( pred,succ,num_pred of lsradata structure) */
685 void lsra_make_cfg(jitdata *jd) {
690 int high, low, count;
697 while (b_index < m->basicblockcount ) {
698 if ((m->basicblocks[b_index].flags >= BBREACHED) &&
699 (len = m->basicblocks[b_index].icount)) {
700 /* block is valid and contains instructions */
702 /* set ip to last instruction */
703 ip = m->basicblocks[b_index].iinstr +
704 m->basicblocks[b_index].icount -1;
705 while ((len>0) && (ip->opc == ICMD_NOP)) {
709 switch (ip->opc) { /* check type of last instruction */
717 lsra_add_cfg(jd, b_index, m->basicblockcount);
718 break; /* function returns -> end of graph */
747 case ICMD_IF_ACMPNE: /* branch -> add next block */
748 lsra_add_cfg(jd, b_index, b_index+1);
749 /* fall throu -> add branch target */
752 lsra_add_cfg(jd, b_index, m->basicblockindex[ip->op1]);
753 break; /* visit branch (goto) target */
755 case ICMD_TABLESWITCH: /* switch statement */
758 lsra_add_cfg(jd, b_index, m->basicblockindex[*s4ptr]);
765 count = (high-low+1);
767 while (--count >= 0) {
769 lsra_add_cfg(jd, b_index,
770 m->basicblockindex[*s4ptr]);
774 case ICMD_LOOKUPSWITCH: /* switch statement */
777 lsra_add_cfg(jd, b_index, m->basicblockindex[*s4ptr]);
782 while (--count >= 0) {
783 lsra_add_cfg(jd, b_index,
784 m->basicblockindex[s4ptr[1]]);
790 lsra_add_jsr(jd, b_index, m->basicblockindex[ip->op1]);
797 lsra_add_cfg(jd, b_index, b_index + 1 );
799 } /* switch (ip->opc)*/
800 } /* if ((m->basicblocks[blockIndex].icount)&& */
801 /* (m->basicblocks[b_index].flags >= BBREACHED)) */
803 } /* while (b_index < m->basicblockcount ) */
806 void lsra_init(jitdata *jd) {
814 /* Init LSRA Data Structures */
815 /* allocate lifetimes for all Basicblocks */
816 /* + 1 for an artificial exit node */
817 /* which is needed as "start" point for the reverse postorder sorting */
818 ls->pred = DMNEW(struct _list *, m->basicblockcount+1);
819 ls->succ = DMNEW(struct _list *, m->basicblockcount+1);
820 ls->sorted = DMNEW(int , m->basicblockcount+1);
821 ls->sorted_rev = DMNEW(int , m->basicblockcount+1);
822 ls->num_pred = DMNEW(int , m->basicblockcount+1);
823 ls->nesting = DMNEW(long , m->basicblockcount+1);
824 for (i=0; i<m->basicblockcount; i++) {
828 ls->sorted_rev[i]=-1;
832 ls->pred[m->basicblockcount]=NULL;
833 ls->succ[m->basicblockcount]=NULL;
834 ls->sorted[m->basicblockcount]=-1;
835 ls->sorted_rev[m->basicblockcount]=-1;
836 ls->num_pred[m->basicblockcount]=0;
843 void lsra_setup(jitdata *jd) {
848 #ifdef LSRA_DEBUG_VERBOSE
865 #if defined(ENABLE_LOOP)
866 /* Loop optimization "destroys" the basicblock array */
867 /* TODO: work with the basicblock list */
869 log_text("lsra not possible with loop optimization\n");
872 #endif /* defined(ENABLE_LOOP) */
874 /* Setup LSRA Data structures */
876 /* Generate the Control Flow Graph */
878 /* gather nesting before adding of Exceptions and Subroutines!!! */
882 lsra_get_nesting(jd);
885 #ifdef LSRA_DEBUG_VERBOSE
886 if (compileverbose) {
887 printf("Successors:\n");
888 for (i=0; i < m->basicblockcount; i++) {
890 for (nl=ls->succ[i]; nl!= NULL; nl=nl->next)
891 printf("%3i ",nl->value);
894 printf("Predecessors:\n");
895 for (i=0; i < m->basicblockcount; i++) {
897 for (nl=ls->pred[i]; nl!= NULL; nl=nl->next)
898 printf("%3i ",nl->value);
902 for (i=0; i < m->basicblockcount; i++) printf("%3i ", ls->sorted[i]);
904 printf("Sorted_rev: ");
905 for (i=0; i < m->basicblockcount; i++) printf("%3i ", ls->sorted_rev[i]);
910 /* add subroutines before exceptions! They "destroy" the CFG */
912 lsra_add_exceptions(jd);
914 /* generate reverse post order sort */
917 /* setup backedge and nested data structures*/
918 lsra_get_backedges(jd);
922 ls->lifetimecount = ls->maxlifetimes + jd->maxlocals * (TYPE_ADR+1);
923 ls->lifetime = DMNEW(struct lifetime, ls->lifetimecount);
924 ls->lt_used = DMNEW(int, ls->lifetimecount);
925 ls->lt_int = DMNEW(int, ls->lifetimecount);
926 ls->lt_int_count = 0;
927 ls->lt_flt = DMNEW(int, ls->lifetimecount);
928 ls->lt_flt_count = 0;
929 ls->lt_mem = DMNEW(int, ls->lifetimecount);
930 ls->lt_mem_count = 0;
932 for (i=0; i < ls->lifetimecount; i++) ls->lifetime[i].type = -1;
934 #ifdef LSRA_DEBUG_VERBOSE
935 if (compileverbose) {
936 printf("Successors:\n");
937 for (i=0; i < m->basicblockcount; i++) {
939 for (nl=ls->succ[i]; nl!= NULL; nl=nl->next)
940 printf("%3i ",nl->value);
943 printf("Predecessors:\n");
944 for (i=0; i < m->basicblockcount; i++) {
946 for (nl=ls->pred[i]; nl!= NULL; nl=nl->next)
947 printf("%3i ",nl->value);
951 for (i=0; i < m->basicblockcount; i++) printf("%3i ", ls->sorted[i]);
953 printf("Sorted_rev: ");
954 for (i=0; i < m->basicblockcount; i++) printf("%3i ", ls->sorted_rev[i]);
960 #ifdef LSRA_DEBUG_CHECK
961 /* compare m->basicblocks[] with the list basicblocks->next */
963 bptr = m->basicblocks;
964 while (bptr != NULL) {
965 if (i > m->basicblockcount){
966 { log_text("linked bb list does not correspond with bb array(1)\n");
969 if (bptr != &(m->basicblocks[i])){
970 { log_text("linked bb list does not correspond with bb array(2)\n");
977 if (i<m->basicblockcount){
978 { log_text("linked bb list does not correspond with bb array(3)\n");
991 methoddesc *md = m->parseddesc;
993 /* Create Stack Slot lifetimes over all basic blocks */
994 for (i=m->basicblockcount-1; i >= 0; i--) {
995 if (ls->sorted[i] != -1) {
996 lsra_scan_registers_canditates(jd, ls->sorted[i]);
997 lsra_join_lifetimes(jd, ls->sorted[i]);
1001 /* Parameter initialisiation for locals [0 .. paramcount[ */
1002 /* -> add local var write access at (bb=0,iindex=-1) */
1003 /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
1004 /* this needs a special treatment, wenn lifetimes get extended */
1005 /* over backedges, since this parameter initialisation happens */
1006 /* outside of Basic Block 0 !!!! */
1007 /* this could have been avoided by marking the read access with -1,0 */
1009 for (p = 0, i = 0; p < md->paramcount; p++) {
1010 t = md->paramtypes[p].type;
1012 if (rd->locals[i][t].type >= 0)
1013 /* Param to Local init happens before normal Code */
1014 lsra_usage_local(ls, i, t, 0, -1, LSRA_STORE);
1016 /* increment local counter a second time */
1017 /* for 2 word types */
1018 if (IS_2_WORD_TYPE(t))
1024 lsra_calc_lifetime_length(jd);
1026 #ifdef LSRA_DEBUG_VERBOSE
1028 printf("Basicblockcount: %4i\n",m->basicblockcount);
1033 void lsra_reg_setup(jitdata *jd, struct lsra_register *int_reg,
1034 struct lsra_register *flt_reg ) {
1035 int i, j, iarg, farg;
1038 bool *fltarg_used, *intarg_used;
1047 int_reg->nregdesc = nregdescint;
1048 flt_reg->nregdesc = nregdescfloat;
1049 if (code_is_leafmethod(code)) {
1050 /* Temp and Argumentregister can be used as saved registers */
1052 int_reg->sav_top = INT_ARG_CNT + INT_TMP_CNT + INT_SAV_CNT;
1053 int_reg->sav_reg = DMNEW(int, int_reg->sav_top);
1054 int_reg->tmp_reg = NULL;
1055 int_reg->tmp_top = -1;
1056 flt_reg->sav_top = FLT_ARG_CNT + FLT_TMP_CNT + FLT_SAV_CNT;
1057 flt_reg->sav_reg = DMNEW(int, flt_reg->sav_top);
1058 flt_reg->tmp_reg = NULL;
1059 flt_reg->tmp_top = -1;
1061 /* additionaly precolour registers for Local Variables acting as */
1067 intarg_used = DMNEW(bool, INT_ARG_CNT);
1068 for (i=0; i < INT_ARG_CNT; i++)
1069 intarg_used[i]=false;
1071 fltarg_used = DMNEW(bool, FLT_ARG_CNT);
1072 for (i=0; i < FLT_ARG_CNT; i++)
1073 fltarg_used[i]=false;
1075 int_sav_top=int_reg->sav_top;
1076 flt_sav_top=flt_reg->sav_top;
1078 for (i=0; (i < md->paramcount); i++) {
1079 if (!md->params[i].inmemory) {
1080 if (IS_INT_LNG_TYPE(md->paramtypes[i].type)) {
1081 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1082 if (IS_2_WORD_TYPE(md->paramtypes[i].type)) {
1083 int_reg->sav_reg[--int_sav_top] =
1084 rd->argintregs[GET_HIGH_REG(md->params[i].regoff)];
1085 intarg_used[GET_HIGH_REG(md->params[i].regoff)]=true;
1086 /*used -> don't copy later on */
1087 int_reg->sav_reg[--int_sav_top] =
1088 rd->argintregs[GET_LOW_REG(md->params[i].regoff)];
1089 intarg_used[GET_LOW_REG(md->params[i].regoff)]=true;
1090 /*used -> don't copy later on */
1093 { /* !IS_2_WORD_TYPE(md->paramtypes[i].type */
1094 int_reg->sav_reg[--int_sav_top] =
1095 rd->argintregs[md->params[i].regoff];
1096 intarg_used[md->params[i].regoff]=true;
1097 /*used -> don't copy later on */
1100 #if !defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
1101 /* do not precolour float arguments if they are passed in */
1102 /* integer registers. But these integer argument registers */
1103 /* still be used in the method! */
1104 else { /* IS_FLT_DBL_TYPE(md->paramtypes[i].type */
1105 flt_reg->sav_reg[--flt_sav_top] =
1106 rd->argfltregs[md->params[i].regoff];
1107 fltarg_used[md->params[i].regoff]=true;
1114 /* copy rest of argument registers to flt_reg->sav_reg and */
1115 /* int_reg->sav_reg; */
1116 for (i=0; i < INT_ARG_CNT; i++)
1117 if (!intarg_used[i])
1118 int_reg->sav_reg[--int_sav_top]=rd->argintregs[i];
1119 for (i=0; i < FLT_ARG_CNT; i++)
1120 if (!fltarg_used[i])
1121 flt_reg->sav_reg[--flt_sav_top]=rd->argfltregs[i];
1123 /* copy temp registers to flt_reg->sav_reg and int_reg->sav_reg */
1124 for (i=0; i < INT_TMP_CNT; i++)
1125 int_reg->sav_reg[--int_sav_top]=rd->tmpintregs[i];
1126 for (i=0; i < FLT_TMP_CNT; i++)
1127 flt_reg->sav_reg[--flt_sav_top]=rd->tmpfltregs[i];
1130 /* non leaf method -> use Argument Registers [arg[int|flt]reguse */
1131 /* ... [INT|FLT]_ARG_CNT[ as temp reg */
1132 /* divide temp and saved registers */
1133 int argintreguse, argfltreguse;
1135 /* with Locals as non SAVEDVAR, the used arg[int|flt] as in params */
1136 /* of the method itself have to be regarded, or mismatch before */
1137 /* block 0 with parameter copy could happen! */
1138 argintreguse = max(rd->argintreguse, md->argintreguse);
1139 argfltreguse = max(rd->argfltreguse, md->argfltreguse);
1141 argintreguse = rd->argintreguse;
1142 argfltreguse = rd->argfltreguse;
1144 int_sav_top = int_reg->sav_top = INT_SAV_CNT;
1145 int_reg->sav_reg = DMNEW(int, int_reg->sav_top);
1146 int_reg->tmp_top = INT_TMP_CNT +
1147 max(0, (INT_ARG_CNT - argintreguse));
1148 int_reg->tmp_reg = DMNEW(int, int_reg->tmp_top);
1150 flt_sav_top =flt_reg->sav_top = FLT_SAV_CNT;
1151 flt_reg->sav_reg = DMNEW(int, flt_reg->sav_top);
1152 flt_reg->tmp_top = FLT_TMP_CNT +
1153 max(0 , (FLT_ARG_CNT - argfltreguse));
1154 flt_reg->tmp_reg = DMNEW(int, flt_reg->tmp_top);
1156 /* copy temp and unused argument registers to flt_reg->tmp_reg and */
1157 /* int_reg->tmp_reg */
1158 for (i=0; i < INT_TMP_CNT; i++)
1159 int_reg->tmp_reg[i]=rd->tmpintregs[i];
1160 for (j=argintreguse; j < INT_ARG_CNT; j++, i++)
1161 int_reg->tmp_reg[i]=rd->argintregs[j];
1162 for (i=0; i < FLT_TMP_CNT; i++)
1163 flt_reg->tmp_reg[i]=rd->tmpfltregs[i];
1164 for (j=argfltreguse; j < FLT_ARG_CNT; j++, i++)
1165 flt_reg->tmp_reg[i]=rd->argfltregs[j];
1168 /* now copy saved registers to flt_reg->sav_reg and int_reg->sav_reg */
1169 for (i = INT_SAV_CNT-1; i >= 0; i--)
1170 int_reg->sav_reg[--int_sav_top]=rd->savintregs[i];
1171 for (i = FLT_SAV_CNT-1; i >= 0; i--)
1172 flt_reg->sav_reg[--flt_sav_top]=rd->savfltregs[i];
1176 void lsra_insertion_sort( struct lsradata *ls, int *a, int lo, int hi) {
1179 for (i=lo+1; i<=hi; i++) {
1181 t=ls->lifetime[a[j]].i_start;
1183 while ((j>lo) && (ls->lifetime[a[j-1]].i_start > t)) {
1191 void lsra_qsort( struct lsradata *ls, int *a, int lo, int hi) {
1197 x = ls->lifetime[a[(lo+hi)/2]].i_start;
1200 while (ls->lifetime[a[i]].i_start < x) i++;
1201 while (ls->lifetime[a[j]].i_start > x) j--;
1203 /* exchange a[i], a[j] */
1213 if (lo < j) lsra_qsort( ls, a, lo, j);
1214 if (i < hi) lsra_qsort( ls, a, i, hi);
1216 lsra_insertion_sort(ls, a, lo, hi);
1220 void lsra_param_sort(struct lsradata *ls, int *lifetime, int lifetime_count) {
1225 /* count number of parameters ( .i_start == -1) */
1226 for (param_count=0; (param_count < lifetime_count) &&
1227 (ls->lifetime[lifetime[param_count]].i_start == -1); param_count++);
1229 if (param_count > 0) {
1230 /* now sort the parameters by v_index */
1231 for (i=0; i < param_count -1; i++)
1232 for (j=i+1; j < param_count; j++)
1233 if ( ls->lifetime[lifetime[i]].v_index >
1234 ls->lifetime[lifetime[j]].v_index) {
1237 lifetime[i]=lifetime[j];
1243 void lsra_main(jitdata *jd) {
1244 #ifdef LSRA_DEBUG_VERBOSE
1249 struct lsra_register flt_reg, int_reg;
1252 #if defined(__I386__)
1260 /* sort lifetimes by increasing start */
1261 lsra_qsort( ls, ls->lt_mem, 0, ls->lt_mem_count - 1);
1262 lsra_qsort( ls, ls->lt_int, 0, ls->lt_int_count - 1);
1263 lsra_qsort( ls, ls->lt_flt, 0, ls->lt_flt_count - 1);
1264 /* sort local vars used as parameter */
1265 lsra_param_sort( ls, ls->lt_int, ls->lt_int_count);
1266 lsra_param_sort( ls, ls->lt_flt, ls->lt_flt_count);
1267 lsra_reg_setup(jd, &int_reg, &flt_reg);
1269 #ifdef LSRA_DEBUG_VERBOSE
1270 if (compileverbose) {
1271 printf("INTSAV REG: ");
1272 for (i=0; i<int_reg.sav_top; i++)
1273 printf("%2i ",int_reg.sav_reg[i]);
1274 printf("\nINTTMP REG: ");
1275 for (i=0; i<int_reg.tmp_top; i++)
1276 printf("%2i ",int_reg.tmp_reg[i]);
1277 printf("\nFLTSAV REG: ");
1278 for (i=0; i<flt_reg.sav_top; i++)
1279 printf("%2i ",flt_reg.sav_reg[i]);
1280 printf("\nFLTTMP REG: ");
1281 for (i=0; i<flt_reg.tmp_top; i++)
1282 printf("%2i ",flt_reg.tmp_reg[i]);
1286 ls->active_tmp = DMNEW( struct lifetime *, max(INT_REG_CNT, FLT_REG_CNT));
1287 ls->active_sav = DMNEW( struct lifetime *, max(INT_REG_CNT, FLT_REG_CNT));
1289 lsra_reg_use=INT_SAV_CNT; /* init to no saved reg used... */
1290 _lsra_main(jd, ls->lt_int, ls->lt_int_count, &int_reg, &lsra_reg_use);
1291 if (lsra_reg_use > INT_SAV_CNT)
1292 lsra_reg_use=INT_SAV_CNT;
1293 rd->savintreguse = lsra_reg_use;
1295 lsra_reg_use = FLT_SAV_CNT; /* no saved reg used... */
1296 _lsra_main(jd, ls->lt_flt, ls->lt_flt_count, &flt_reg, &lsra_reg_use);
1297 if (lsra_reg_use > FLT_SAV_CNT)
1298 lsra_reg_use=FLT_SAV_CNT;
1299 rd->savfltreguse=lsra_reg_use;
1301 /* rd->memuse was already set in stack.c to allocate stack space for */
1302 /* passing arguments to called methods */
1303 #if defined(__I386__)
1304 if (checksync && code_is_synchronized(code)) {
1305 /* reserve 0(%esp) for Monitorenter/exit Argument on i386 */
1311 lsra_mem_use = rd->memuse; /* Init with memuse from stack.c */
1313 lsra_alloc(jd, ls->lt_mem, ls->lt_mem_count, &lsra_mem_use);
1314 lsra_alloc(jd, ls->lt_int, ls->lt_int_count, &lsra_mem_use);
1315 lsra_alloc(jd, ls->lt_flt, ls->lt_flt_count, &lsra_mem_use);
1317 rd->memuse=lsra_mem_use;
1319 #ifdef LSRA_DEBUG_VERBOSE
1320 if (compileverbose) {
1321 printf("Int RA complete \n");
1322 printf("Lifetimes after splitting int: \n");
1323 print_lifetimes(jd, ls->lt_int, ls->lt_int_count);
1325 printf("Flt RA complete \n");
1326 printf("Lifetimes after splitting flt:\n");
1327 print_lifetimes(jd, ls->lt_flt, ls->lt_flt_count);
1329 printf("Rest RA complete \n");
1330 printf("Lifetimes after leftt:\n");
1331 print_lifetimes(jd, ls->lt_mem, ls->lt_mem_count);
1336 void lsra_alloc(jitdata *jd, int *lifet, int lifetimecount, int *mem_use)
1339 struct lifetime *lt;
1340 struct freemem *fmem;
1341 struct stackslot *n;
1343 #ifdef HAS_4BYTE_STACKSLOT
1344 struct freemem *fmem_2;
1352 fmem = DNEW(struct freemem);
1355 #ifdef HAS_4BYTE_STACKSLOT
1356 fmem_2=DNEW(struct freemem);
1358 fmem_2->next = NULL;
1361 for (lt_index = 0; lt_index < lifetimecount; lt_index ++) {
1362 lt = &(ls->lifetime[lifet[lt_index]]);
1366 if (lt->reg == -1) {
1368 #ifdef HAS_4BYTE_STACKSLOT
1369 if (IS_2_WORD_TYPE(lt->type))
1370 regoff = lsra_getmem(lt, fmem_2, mem_use);
1373 regoff = lsra_getmem(lt, fmem, mem_use);
1375 flags = lt->savedvar;
1379 if (lt->v_index < 0) {
1380 for (n = lt->local_ss; n != NULL; n = n->next) {
1381 lsra_setflags(&(n->s->flags), flags);
1382 n->s->regoff = regoff;
1384 } else { /* local var */
1385 if (rd->locals[lt->v_index][lt->type].type >= 0) {
1386 rd->locals[lt->v_index][lt->type].flags = flags;
1387 rd->locals[lt->v_index][lt->type].regoff = regoff;
1389 log_text("Type Data mismatch\n");
1397 void lsra_setflags(int *flags, int newflags)
1399 if ( newflags & INMEMORY)
1402 *flags &= ~INMEMORY;
1404 if (newflags & SAVEDVAR)
1408 int lsra_getmem(struct lifetime *lt, struct freemem *fmem, int *mem_use)
1410 struct freemem *fm, *p;
1412 /* no Memory Slot allocated till now or all are still live */
1413 if ((fmem->next == NULL) || (fmem->next->end > lt->i_start)) {
1414 #ifdef HAS_4BYTE_STACKSLOT
1415 if (IS_2_WORD_TYPE(lt->type))
1416 if ( (*mem_use)&1 ) /* align memory location for 2 Word Types */
1418 fm=lsra_getnewmem(mem_use);
1419 if (IS_2_WORD_TYPE(lt->type))
1420 /* allocate a second following Slot for 2 Word Types */
1423 fm=lsra_getnewmem(mem_use);
1426 /* Memoryslot free */
1428 fmem->next = fm->next;
1431 fm->end = lt->i_end;
1432 for (p = fmem; (p->next != NULL) && (p->next->end < fm->end); p = p->next);
1438 struct freemem *lsra_getnewmem(int *mem_use)
1442 fm = DNEW(struct freemem);
1449 void _lsra_main(jitdata *jd, int *lifet, int lifetimecount,
1450 struct lsra_register *reg, int *reg_use)
1452 struct lifetime *lt;
1456 bool temp; /* reg from temp registers (true) or saved registers (false) */
1463 #if !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1466 if ((reg->tmp_top+reg->sav_top) == 0) {
1468 /* no registers available */
1469 for (lt_index = 0; lt_index < lifetimecount; lt_index++)
1470 ls->lifetime[lifet[lt_index]].reg = -1;
1474 ls->active_tmp_top = 0;
1475 ls->active_sav_top = 0;
1477 for (lt_index = 0; lt_index < lifetimecount; lt_index++) {
1478 lt = &(ls->lifetime[lifet[lt_index]]);
1480 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1481 regsneeded = (lt->type == TYPE_LNG)?1:0;
1484 lsra_expire_old_intervalls(jd, lt, reg);
1487 if (lt->savedvar || code_is_leafmethod(code)) {
1488 /* use Saved Reg (in case of leafmethod all regs are saved regs) */
1489 if (reg->sav_top > regsneeded) {
1490 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1492 reg_index = PACK_REGS(reg->sav_reg[--reg->sav_top],
1493 reg->sav_reg[--reg->sav_top]);
1497 reg_index = reg->sav_reg[--reg->sav_top];
1499 } else { /* use Temp Reg or if none is free a Saved Reg */
1500 if (reg->tmp_top > regsneeded) {
1502 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1504 reg_index = PACK_REGS(reg->tmp_reg[--reg->tmp_top],
1505 reg->tmp_reg[--reg->tmp_top]);
1508 reg_index = reg->tmp_reg[--reg->tmp_top];
1511 if (reg->sav_top > regsneeded) {
1513 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1515 reg_index = PACK_REGS(reg->sav_reg[--reg->sav_top],
1516 reg->sav_reg[--reg->sav_top]);
1519 reg_index = reg->sav_reg[--reg->sav_top];
1522 if (reg_index == -1) /* no reg is available anymore... -> spill */
1523 spill_at_intervall(jd, lt);
1525 lt->reg = reg_index;
1527 lsra_add_active(lt, ls->active_tmp, &(ls->active_tmp_top));
1529 if (reg->sav_top<*reg_use) *reg_use=reg->sav_top;
1530 lsra_add_active(lt, ls->active_sav, &(ls->active_sav_top));
1536 void lsra_add_active(struct lifetime *lt, struct lifetime **active,
1541 for(i = 0; (i < *active_top) && (active[i]->i_end < lt->i_end); i++);
1542 for(j = *active_top; j > i; j--) active[j] = active[j-1];
1547 void lsra_expire_old_intervalls(jitdata *jd, struct lifetime *lt,
1548 struct lsra_register *reg)
1550 _lsra_expire_old_intervalls(jd, lt, reg, jd->ls->active_tmp,
1551 &(jd->ls->active_tmp_top));
1552 _lsra_expire_old_intervalls(jd, lt, reg, jd->ls->active_sav,
1553 &(jd->ls->active_sav_top));
1556 void _lsra_expire_old_intervalls(jitdata *jd, struct lifetime *lt,
1557 struct lsra_register *reg,
1558 struct lifetime **active, int *active_top)
1562 for(i = 0; i < *active_top; i++) {
1563 if (active[i]->i_end > lt->i_start) break;
1565 /* make active[i]->reg available again */
1566 if (code_is_leafmethod(code)) {
1567 /* leafmethod -> don't care about type -> put all again into */
1569 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1570 if (active[i]->type == TYPE_LNG) {
1571 reg->sav_reg[reg->sav_top++] = GET_LOW_REG(active[i]->reg);
1572 reg->sav_reg[reg->sav_top++] = GET_HIGH_REG(active[i]->reg);
1575 reg->sav_reg[reg->sav_top++] = active[i]->reg;
1577 /* no leafmethod -> distinguish between temp and saved register */
1578 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1579 if (active[i]->type == TYPE_LNG) {
1580 /* no temp and saved regs are packed together, so looking at */
1581 /* LOW_REG is sufficient */
1582 if ( reg->nregdesc[ GET_LOW_REG(active[i]->reg)] == REG_SAV) {
1583 reg->sav_reg[reg->sav_top++] = GET_LOW_REG(active[i]->reg);
1584 reg->sav_reg[reg->sav_top++] = GET_HIGH_REG(active[i]->reg);
1586 reg->tmp_reg[reg->tmp_top++] = GET_LOW_REG(active[i]->reg);
1587 reg->tmp_reg[reg->tmp_top++] = GET_HIGH_REG(active[i]->reg);
1591 if ( reg->nregdesc[active[i]->reg] == REG_SAV) {
1592 reg->sav_reg[reg->sav_top++] = active[i]->reg;
1594 reg->tmp_reg[reg->tmp_top++] = active[i]->reg;
1599 /* active[0..i[ is to be removed */
1600 /* -> move [i..*active_top[ to [0..*active_top-i[ */
1601 for(k = 0, j = i; (j < *active_top); k++,j++)
1602 active[k] = active[j];
1608 void spill_at_intervall(jitdata *jd, struct lifetime *lt )
1610 if (lt->savedvar || code_is_leafmethod(code)) {
1611 _spill_at_intervall(lt, jd->ls->active_sav, &(jd->ls->active_sav_top));
1613 _spill_at_intervall(lt, jd->ls->active_tmp, &(jd->ls->active_tmp_top));
1614 if (lt->reg == -1) { /* no tmp free anymore */
1615 _spill_at_intervall(lt, jd->ls->active_sav,
1616 &(jd->ls->active_sav_top));
1621 void _spill_at_intervall(struct lifetime *lt, struct lifetime **active,
1625 #ifdef USAGE_COUNT_EXACT
1629 if (*active_top == 0) {
1634 i = *active_top - 1;
1635 #if defined(USAGE_COUNT_EXACT)
1636 /* find intervall which ends later or equal than than lt and has the lowest
1637 usagecount lower than lt */
1639 u_min = lt->usagecount;
1640 for (; (i >= 0) && (active[i]->i_end >= lt->i_end); i--) {
1641 if (active[i]->usagecount < u_min) {
1642 u_min = active[i]->usagecount;
1650 # if defined(USAGE_COUNT) && !defined(USAGE_COUNT_EXACT)
1651 if ((active[i]->i_end >= lt->i_end)
1652 && (active[i]->usagecount < lt->usagecount)) {
1653 # else /* "normal" LSRA heuristic */
1654 /* get last intervall from active */
1655 if (active[i]->i_end > lt->i_end) {
1658 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1659 /* Don't spill between one and two word int types */
1660 if ((active[i]->type == TYPE_LNG) != (lt->type == TYPE_LNG))
1663 lt->reg = active[i]->reg;
1667 for (j = i; j < *active_top; j++)
1668 active[j] = active[j + 1];
1670 lsra_add_active(lt, active, active_top);
1676 void lsra_calc_lifetime_length(jitdata *jd) {
1680 struct lifetime *lt;
1681 #if defined(LSRA_DEBUG_VERBOSE) || !defined(LV)
1686 int flags; /* 0 INMEMORY -> ls->lt_mem */
1687 /* 1 INTREG -> ls->lt_int */
1688 /* 2 FLTREG -> ls->lt_flt */
1695 #ifdef LSRA_DEBUG_VERBOSE
1696 if (compileverbose) {
1697 printf("icount_block: ");
1698 for (i=0; i < m->basicblockcount; i++)
1699 printf("(%3i-%3i) ",i, ls->icount_block[i]);
1704 /* extend lifetime over backedges (for the lsra version without exact
1706 now iterate through lifetimes and expand them */
1709 for(lt_index = 0 ;lt_index < ls->lifetimecount; lt_index++) {
1710 if ( ls->lifetime[lt_index].type != -1) { /* used lifetime */
1711 /* remember lt_index in lt_sorted */
1712 ls->lt_used[lifetimecount++] = lt_index;
1713 lt = &(ls->lifetime[lt_index]);
1714 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1715 /* prevent conflicts between lifetimes of type long by increasing
1716 the lifetime by one instruction
1719 with i==l and/or j==k
1720 to resolve this during codegeneration a temporary register
1722 if (lt->type == TYPE_LNG)
1726 /* distribute lifetimes to lt_int, lt_flt and lt_mem */
1732 #if defined(HAS_4BYTE_STACKSLOT) && !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1745 #if defined(__I386__)
1747 * for i386 put all floats in memory
1755 { log_text("Unknown Type\n"); assert(0); }
1759 case 0: /* lt_used[lt_used_index] -> lt_rest */
1760 ls->lt_mem[ ls->lt_mem_count++ ] = lt_index;
1762 case 1: /* l->lifetimes -> lt_int */
1763 ls->lt_int[ ls->lt_int_count++ ] = lt_index;
1765 case 2: /* l->lifetimes -> lt_flt */
1766 ls->lt_flt[ ls->lt_flt_count++ ] = lt_index;
1771 if (lt->i_first_def == INT_MAX) {
1772 #ifdef LSRA_DEBUG_VERBOSE
1773 printf("Warning: var not defined! vi: %i start: %i end: %i\n",
1774 lt->v_index, lt->i_start, lt->i_end);
1776 lt->bb_first_def = 0;
1777 lt->i_first_def = 0;
1780 lt->i_start = lt->i_first_def;
1782 if (lt->i_last_use == -2) {
1783 #ifdef LSRA_DEBUG_VERBOSE
1784 printf("Warning: Var not used! vi: %i start: %i end: %i\n",
1785 lt->v_index, lt->i_start, lt->i_end);
1787 lt->bb_last_use = lt->bb_first_def;
1788 lt->i_last_use = lt->i_first_def;
1791 lt->i_end = lt->i_last_use;
1793 #ifdef LSRA_DEBUG_VERBOSE
1794 if (lt->i_start > lt->i_end)
1795 printf("Warning: last use before first def! vi: %i start: %i end: %i\n", lt->v_index, lt->i_start, lt->i_end);
1799 if ((lt->bb_first_def != lt->bb_last_use) ||
1800 (lt->i_first_def == -1)) {
1801 /* Lifetime goes over more than one Basic Block -> */
1802 /* check for necessary extension over backedges */
1803 /* see lsra_get_backedges */
1804 /* Arguments are set "before" Block 0, so they have */
1805 /* a lifespan of more then one block, too */
1807 for (i=0; i < ls->backedge_count; i++) {
1808 if (!( (lt->bb_first_def > ls->backedge[i]->start) ||
1809 (lt->bb_last_use < ls->backedge[i]->end) )) {
1810 /* Live intervall intersects with a backedge */
1811 /* if (lt->bb_first_def <= ls->backedge[i]->start) */
1812 if (lt->bb_last_use <= ls->backedge[i]->start)
1814 ls->icount_block[ls->backedge[i]->start] +
1815 m->basicblocks[ls->sorted[ls->backedge[i]->start]].icount;
1819 #endif /* !defined(LV) */
1821 #ifdef USAGE_PER_INSTR
1822 lt->usagecount = lt->usagecount / ( lt->i_end - lt->i_start + 1);
1826 ls->lifetimecount = lifetimecount;
1829 #ifdef LSRA_DEBUG_VERBOSE
1830 void print_lifetimes(jitdata *jd, int *lt, int lifetimecount)
1834 int type,flags,regoff,varkind;
1842 for (lt_index = 0; lt_index < lifetimecount; lt_index++) {
1843 n = &(ls->lifetime[lt[lt_index]]);
1844 if (n->savedvar == SAVEDVAR)
1848 if (n->v_index < 0) { /* stackslot */
1849 type = n->local_ss->s->type;
1850 flags=n->local_ss->s->flags;
1851 regoff=n->local_ss->s->regoff;
1852 varkind=n->local_ss->s->varkind;
1853 } else { /* local var */
1854 if (rd->locals[n->v_index][n->type].type>=0) {
1855 type = rd->locals[n->v_index][n->type].type;
1856 flags=rd->locals[n->v_index][n->type].flags;
1857 regoff=rd->locals[n->v_index][n->type].regoff;
1860 { log_text("Type Data mismatch 3\n"); assert(0); }
1863 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);
1865 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);
1868 printf( "%3i Lifetimes printed \n",lt_index);
1874 /******************************************************************************
1875 Helpers for first LSRA Version without exact Liveness Analysis
1876 *****************************************************************************/
1879 bool lsra_join_ss( struct lsradata *ls, struct stackelement *in,
1880 struct stackelement *out, int join_flag) {
1881 struct lifetime *lt, *lto;
1882 struct stackslot *ss, *ss_last;
1885 if (in->varnum != out->varnum) {
1886 lt = &(ls->lifetime[-in->varnum - 1]);
1888 #ifdef LSRA_DEBUG_CHECK
1889 if (join_flag == JOIN_BB)
1890 if (lt->type == -1) {
1891 log_text("lsra_join_ss: lifetime for instack not found\n");
1896 if (out->varnum >= 0) { /* no lifetime for this slot till now */
1897 lsra_add_ss(lt, out);
1899 lto = &(ls->lifetime[-out->varnum - 1]);
1900 if ((join_flag == JOIN_DUP) || (join_flag == JOIN_OP))
1901 if ( (lt->flags & JOIN_BB) || (lto->flags & JOIN_BB)) {
1904 if (join_flag == JOIN_DUP)
1905 if ( (lt->flags & JOIN_OP) || (lto->flags & JOIN_OP)) {
1908 #ifdef LSRA_DEBUG_CHECK
1909 if (lto->type == -1) {
1910 log_text("lsra_join_ss: lifetime for outstack not found\n");
1914 #ifdef LSRA_DEBUG_CHECK
1915 if (lto->type != lt->type) {
1916 log_text("lsra_join_ss: in/out stack type mismatch\n");
1921 lt->flags |= JOINING;
1923 /* take Lifetime lto out of ls->lifetimes */
1926 /* merge lto into lt of in */
1928 ss_last = ss = lto->local_ss;
1929 while (ss != NULL) {
1931 ss->s->varnum = lt->v_index;
1934 if (ss_last != NULL) {
1935 ss_last->next = lt->local_ss;
1936 lt->local_ss = lto->local_ss;
1939 lt->savedvar |= lto->savedvar;
1940 lt->flags |= lto->flags | join_flag;
1941 lt->usagecount += lto->usagecount;
1943 /*join of i_first_def and i_last_use */
1944 if (lto->i_first_def < lt->i_first_def) {
1945 lt->i_first_def = lto->i_first_def;
1947 if (lto->i_last_use > lt->i_last_use) {
1948 lt->i_last_use = lto->i_last_use;
1955 /* join instack of Basic Block b_index with outstack of predecessors */
1956 void lsra_join_lifetimes(jitdata *jd,int b_index) {
1959 struct stackelement *in, *i, *out;
1965 /* do not join instack of Exception Handler */
1966 if (m->basicblocks[b_index].type == BBTYPE_EXH)
1968 in=m->basicblocks[b_index].instack;
1969 /* do not join first instack element of a subroutine header */
1970 if (m->basicblocks[b_index].type == BBTYPE_SBR)
1974 for (pred = ls->pred[b_index]; pred != NULL; pred = pred->next) {
1975 out = m->basicblocks[pred->value].outstack;
1976 for (i=in; (i != NULL); i = i->prev, out=out->prev) {
1977 lsra_join_ss(ls, i, out, JOIN_BB);
1983 struct stackslot *lsra_make_ss(stackelement_t* s, int bb_index)
1985 struct stackslot *ss;
1987 ss = DNEW(struct stackslot);
1993 void lsra_add_ss(struct lifetime *lt, stackelement_t* s) {
1994 struct stackslot *ss;
1996 /* Stackslot not in list? */
1997 if (s->varnum != lt->v_index) {
1998 ss = DNEW(struct stackslot);
2000 ss->s->varnum = lt->v_index;
2001 ss->next = lt->local_ss;
2004 lt->savedvar |= s->flags & SAVEDVAR;
2010 struct lifetime *get_ss_lifetime(lsradata *ls, stackelement_t* s) {
2013 if (s->varnum >= 0) { /* new stackslot lifetime */
2014 #ifdef LSRA_DEBUG_CHECK_VERBOSE
2015 if (-ls->v_index - 1 >= ls->maxlifetimes) {
2016 printf("%i %i\n", -ls->v_index - 1, ls->maxlifetimes);
2019 _LSRA_ASSERT(-ls->v_index - 1 < ls->maxlifetimes);
2021 n = &(ls->lifetime[-ls->v_index - 1]);
2023 n->v_index = ls->v_index--;
2026 n->bb_last_use = -1;
2027 n->bb_first_def = -1;
2028 n->i_last_use = -2; /* At -1 param init happens, so -2 is below all
2029 possible instruction indices */
2030 n->i_first_def = INT_MAX;
2035 n = &(ls->lifetime[-s->varnum - 1]);
2041 #define IS_TEMP_VAR(s) (((s)->varkind != ARGVAR) && ((s)->varkind != LOCALVAR))
2043 #define lsra_join_3_stack(ls, dst, src1, src2, join_type) \
2044 if ( IS_TEMP_VAR(dst) ) { \
2046 if ( IS_TEMP_VAR(src1) && ((src1)->type == (dst)->type)) { \
2047 join_ret = lsra_join_ss(ls, dst, src1, join_type); \
2049 if ((!join_ret) && IS_TEMP_VAR(src2) && ((src2)->type == (dst)->type)) { \
2050 lsra_join_ss(ls, dst, src2, join_type); \
2054 #define lsra_join_2_stack(ls, dst, src, join_type) \
2055 if ( IS_TEMP_VAR(dst) ) { \
2056 if ( (IS_TEMP_VAR(src)) && ((src)->type == (dst)->type)) { \
2057 lsra_join_ss(ls, dst, src, join_type); \
2061 #define lsra_join_dup(ls, s1, s2, s3) { \
2062 if (IS_TEMP_VAR(s1)) { \
2064 if (IS_TEMP_VAR(s2)) \
2065 join_ret = lsra_join_ss(ls, s1, s2, JOIN); \
2066 /* undangerous join!*/\
2067 if (IS_TEMP_VAR(s3)) { \
2068 if (join_ret) /* first join succesfull -> second of type */ \
2070 lsra_join_ss(ls, s1, s3, JOIN_DUP); \
2072 lsra_join_ss(ls, s1, s3, JOIN); /* first join did not */ \
2073 /* happen -> second undangerous */ \
2076 if (IS_TEMP_VAR(s2) && IS_TEMP_VAR(s3)) \
2077 lsra_join_ss(ls, s2, s3, JOIN_DUP); \
2080 #define lsra_new_stack(ls, s, block, instr) \
2081 if ((s)->varkind != ARGVAR) _lsra_new_stack(ls, s, block, instr, LSRA_STORE)
2082 void _lsra_new_stack(lsradata *ls, stackelement_t* s, int block, int instr, int store)
2086 if (s->varkind == LOCALVAR) {
2087 lsra_usage_local(ls, s->varnum, s->type, block, instr, LSRA_STORE);
2088 } else /* if (s->varkind != ARGVAR) */ {
2090 n=get_ss_lifetime(ls, s);
2092 if (store == LSRA_BB_IN)
2093 n->flags |= JOIN_BB;
2094 /* remember first def -> overwrite everytime */
2095 n->bb_first_def = ls->sorted_rev[block];
2096 n->i_first_def = ls->icount_block[ls->sorted_rev[block]] + instr;
2098 n->usagecount+=ls->nesting[ls->sorted_rev[block]];
2102 #define lsra_from_stack(ls, s, block, instr) \
2103 if ((s)->varkind != ARGVAR) _lsra_from_stack(ls, s, block, instr, LSRA_LOAD)
2104 #define lsra_pop_from_stack(ls, s, block, instr) \
2105 if ((s)->varkind != ARGVAR) _lsra_from_stack(ls, s, block, instr, LSRA_POP)
2106 void _lsra_from_stack(lsradata *ls, stackelement_t* s, int block, int instr, int store)
2110 if (s->varkind == LOCALVAR) {
2111 lsra_usage_local(ls, s->varnum, s->type, block, instr, LSRA_LOAD);
2112 } else /* if (s->varkind != ARGVAR) */ {
2113 if (s->varkind == STACKVAR )
2114 /* No STACKVARS possible with lsra! */
2115 s->varkind = TEMPVAR;
2117 n=get_ss_lifetime(ls, s);
2119 if (store == LSRA_BB_OUT)
2120 n->flags |= JOIN_BB;
2121 if (n->flags & JOINING)
2122 n->flags &= ~JOINING;
2123 n->usagecount+=ls->nesting[ls->sorted_rev[block]];
2125 /* remember last USE, so only write, if USE Field is undefined (==-1) */
2126 if (n->bb_last_use == -1) {
2127 n->bb_last_use = ls->sorted_rev[block];
2128 n->i_last_use = ls->icount_block[ls->sorted_rev[block]] + instr;
2133 void lsra_usage_local(lsradata *ls, s4 v_index, int type, int block, int instr,
2138 n = &(ls->lifetime[ ls->maxlifetimes + v_index * (TYPE_ADR+1) + type]);
2140 if (n->type == -1) { /* new local lifetime */
2144 n->savedvar = SAVEDVAR;
2148 n->bb_last_use = -1;
2149 n->bb_first_def = -1;
2151 n->i_first_def = INT_MAX;
2153 n->usagecount+=ls->nesting[ls->sorted_rev[block]];
2154 /* add access at (block, instr) to instruction list */
2155 /* remember last USE, so only write, if USE Field is undefined (==-1) */
2156 /* count store as use, too -> defined and not used vars would overwrite */
2158 if (n->bb_last_use == -1) {
2159 n->bb_last_use = ls->sorted_rev[block];
2160 n->i_last_use = ls->icount_block[ls->sorted_rev[block]] + instr;
2162 if (store == LSRA_STORE) {
2163 /* store == LSRA_STORE, remember first def -> overwrite everytime */
2164 n->bb_first_def = ls->sorted_rev[block];
2165 n->i_first_def = ls->icount_block[ls->sorted_rev[block]] + instr;
2169 #ifdef LSRA_DEBUG_VERBOSE
2170 void lsra_dump_stack(stackelement_t* s)
2173 printf("%p(R%3i N%3i K%3i T%3i F%3i) ",(void *)s,s->regoff, s->varnum,
2174 s->varkind, s->type, s->flags);
2182 void lsra_scan_registers_canditates(jitdata *jd, int b_index)
2184 /* methodinfo *lm; */
2185 builtintable_entry *bte;
2190 stackelement_t* src;
2191 stackelement_t* dst;
2193 bool join_ret; /* for lsra_join* Macros */
2200 /* get instruction count for BB and remember the max instruction count */
2202 iindex = m->basicblocks[b_index].icount - 1;
2204 src = m->basicblocks[b_index].instack;
2205 if (m->basicblocks[b_index].type != BBTYPE_STD) {
2206 lsra_new_stack(ls, src, b_index, 0);
2209 for (;src != NULL; src=src->prev) {
2210 /*******************************************************************************
2211 Check this - ? For every incoming Stack Slot a lifetime has to be created ?
2212 *******************************************************************************/
2213 _lsra_new_stack(ls, src, b_index, 0, LSRA_BB_IN);
2215 src = m->basicblocks[b_index].outstack;
2216 for (;src != NULL; src=src->prev) {
2217 _lsra_from_stack(ls, src, b_index, iindex, LSRA_BB_OUT);
2220 /* set iptr to last instruction of BB */
2221 iptr = m->basicblocks[b_index].iinstr + iindex;
2223 for (;iindex >= 0; iindex--, iptr--) {
2225 /* get source and destination Stack for the current instruction */
2226 /* destination stack is available as iptr->dst */
2230 /* source stack is either the destination stack of the previos */
2231 /* instruction, or the basicblock instack for the first instruction */
2233 if (iindex) /* != 0 is > 0 here, since iindex ist always >= 0 */
2236 src=m->basicblocks[b_index].instack;
2244 /* local read (return adress) */
2245 lsra_usage_local(ls, iptr->op1, TYPE_ADR, b_index, iindex,
2249 /* case ICMD_ELSE_ICONST: */
2250 case ICMD_CHECKNULL:
2254 case ICMD_PUTSTATICCONST:
2255 case ICMD_INLINE_START:
2256 case ICMD_INLINE_END:
2257 case ICMD_INLINE_GOTO:
2261 /* local = local+<const> */
2262 lsra_usage_local(ls, iptr->op1, TYPE_INT, b_index, iindex,
2264 lsra_usage_local(ls, iptr->op1, TYPE_INT, b_index, iindex,
2268 /* pop 0 push 1 const: const->stack */
2274 /* new stack slot */
2275 lsra_new_stack(ls, dst, b_index, iindex);
2278 /* pop 0 push 1 load: local->stack */
2284 if (dst->varkind != LOCALVAR) {
2285 /* local->value on stack */
2286 lsra_usage_local(ls, iptr->op1, opcode - ICMD_ILOAD, b_index,
2288 lsra_new_stack(ls, dst, b_index, iindex); /* value->stack */
2289 } else /* if (dst->varnum != iptr->op1) */ {
2290 /* local -> local */
2291 lsra_usage_local(ls, iptr->op1, opcode - ICMD_ILOAD, b_index,
2292 iindex,LSRA_LOAD); /* local->value */
2293 lsra_usage_local(ls, dst->varnum, opcode - ICMD_ILOAD, b_index,
2294 iindex, LSRA_STORE); /* local->value */
2300 /* Stack(arrayref,index)->stack */
2311 lsra_from_stack(ls, src, b_index, iindex);
2312 /* stack->arrayref */
2313 lsra_from_stack(ls, src->prev, b_index, iindex);
2314 /* arrayref[index]->stack */
2315 lsra_new_stack(ls, dst, b_index, iindex);
2319 /* stack(arrayref,index,value)->arrayref[index]=value */
2330 lsra_from_stack(ls, src,b_index, iindex); /* stack -> value */
2331 lsra_from_stack(ls, src->prev, b_index, iindex); /* stack -> index*/
2332 /* stack -> arrayref */
2333 lsra_from_stack(ls, src->prev->prev, b_index, iindex);
2336 /* pop 1 push 0 store: stack -> local */
2342 if (src->varkind != LOCALVAR) {
2343 lsra_from_stack(ls, src, b_index, iindex); /* stack -> value */
2344 lsra_usage_local(ls, iptr->op1, opcode-ICMD_ISTORE, b_index,
2345 iindex, LSRA_STORE); /* local->value */
2346 } else /* if (src->varnum != iptr->op1) */ {
2347 lsra_usage_local(ls, iptr->op1, opcode-ICMD_ISTORE, b_index,
2348 iindex, LSRA_STORE); /* local->value */
2349 lsra_usage_local(ls, src->varnum, opcode-ICMD_ISTORE, b_index,
2350 iindex, LSRA_LOAD); /* local->value */
2355 case ICMD_POP: /* throw away a stackslot */
2356 /* TODO: check if used anyway (DUP...) and change codegen to */
2357 /* ignore this stackslot */
2358 lsra_pop_from_stack(ls, src, b_index, iindex);
2366 case ICMD_ARETURN: /* stack(value) -> [empty] */
2368 case ICMD_ATHROW: /* stack(objref) -> undefined */
2370 case ICMD_PUTSTATIC: /* stack(value) -> static_field */
2371 case ICMD_PUTFIELDCONST:
2373 /* pop 1 push 0 branch */
2374 case ICMD_IFNULL: /* stack(value) -> branch? */
2375 case ICMD_IFNONNULL:
2391 /* pop 1 push 0 table branch */
2392 case ICMD_TABLESWITCH:
2393 case ICMD_LOOKUPSWITCH:
2395 case ICMD_MONITORENTER:
2396 case ICMD_MONITOREXIT:
2397 lsra_from_stack(ls, src, b_index, iindex); /* stack -> value */
2401 case ICMD_POP2: /* throw away 2 stackslots */
2402 /* TODO: check if used anyway (DUP...) and change codegen to */
2403 /* ignore this stackslot */
2404 lsra_pop_from_stack(ls, src, b_index, iindex);
2405 lsra_pop_from_stack(ls, src->prev, b_index, iindex);
2408 /* pop 2 push 0 branch */
2410 case ICMD_IF_ICMPEQ: /* stack (v1,v2) -> branch(v1,v2) */
2411 case ICMD_IF_ICMPNE:
2412 case ICMD_IF_ICMPLT:
2413 case ICMD_IF_ICMPGE:
2414 case ICMD_IF_ICMPGT:
2415 case ICMD_IF_ICMPLE:
2417 case ICMD_IF_LCMPEQ:
2418 case ICMD_IF_LCMPNE:
2419 case ICMD_IF_LCMPLT:
2420 case ICMD_IF_LCMPGE:
2421 case ICMD_IF_LCMPGT:
2422 case ICMD_IF_LCMPLE:
2424 case ICMD_IF_ACMPEQ:
2425 case ICMD_IF_ACMPNE:
2428 case ICMD_PUTFIELD: /* stack(objref,value) -> objref = value */
2430 case ICMD_IASTORECONST:
2431 case ICMD_LASTORECONST:
2432 case ICMD_AASTORECONST:
2433 case ICMD_BASTORECONST:
2434 case ICMD_CASTORECONST:
2435 case ICMD_SASTORECONST:
2436 lsra_from_stack(ls, src, b_index, iindex); /* stack -> value*/
2437 lsra_from_stack(ls, src->prev, b_index, iindex);
2440 /* pop 0 push 1 dup */
2441 case ICMD_DUP: /* src == dst->prev, src -> dst */
2442 /* lsra_from_stack(ls, src,b_index,iindex);*/
2443 lsra_new_stack(ls, dst, b_index, iindex);
2445 #ifdef JOIN_DUP_STACK
2446 /* src is identical to dst->prev */
2447 lsra_join_2_stack(ls, src, dst, JOIN_DUP);
2451 /* pop 0 push 2 dup */
2453 /* lsra_from_stack(ls, src,b_index, iindex); */
2454 /* lsra_from_stack(ls, src->prev, b_index, iindex); */
2455 lsra_new_stack(ls, dst->prev, b_index, iindex);
2456 lsra_new_stack(ls, dst, b_index, iindex);
2458 #ifdef JOIN_DUP_STACK
2459 lsra_join_2_stack(ls, src, dst, JOIN_DUP);
2460 lsra_join_2_stack(ls, src->prev, dst->prev, JOIN_DUP);
2461 /* src is identical to dst->prev->prev */
2462 /* src->prev is identical to dst->prev->prev->prev */
2466 /* pop 2 push 3 dup */
2468 lsra_from_stack(ls, src, b_index, iindex+1);
2469 lsra_from_stack(ls, src->prev, b_index, iindex+1);
2470 lsra_new_stack(ls, dst->prev->prev, b_index, iindex);
2471 lsra_new_stack(ls, dst->prev, b_index, iindex);
2472 lsra_new_stack(ls, dst, b_index, iindex);
2473 #ifdef JOIN_DUP_STACK
2474 lsra_join_dup(ls, src, dst, dst->prev->prev);
2475 lsra_join_2_stack(ls, src->prev, dst->prev, JOIN);
2479 /* pop 3 push 4 dup */
2481 lsra_from_stack(ls, src,b_index, iindex+1);
2482 lsra_from_stack(ls, src->prev, b_index, iindex+1);
2483 lsra_from_stack(ls, src->prev->prev, b_index, iindex+1);
2484 lsra_new_stack(ls, dst->prev->prev->prev, b_index, iindex);
2485 lsra_new_stack(ls, dst->prev->prev, b_index, iindex);
2486 lsra_new_stack(ls, dst->prev, b_index, iindex);
2487 lsra_new_stack(ls, dst, b_index, iindex);
2489 #ifdef JOIN_DUP_STACK
2490 lsra_join_dup(ls, src, dst, dst->prev->prev->prev);
2491 lsra_join_2_stack(ls, src->prev, dst->prev, JOIN);
2492 lsra_join_2_stack(ls, src->prev->prev, dst->prev->prev, JOIN);
2496 /* pop 3 push 5 dup */
2498 lsra_from_stack(ls, src, b_index, iindex+1);
2499 lsra_from_stack(ls, src->prev, b_index, iindex+1);
2500 lsra_from_stack(ls, src->prev->prev, b_index, iindex+1);
2501 lsra_new_stack(ls, dst->prev->prev->prev->prev, b_index, iindex);
2502 lsra_new_stack(ls, dst->prev->prev->prev, b_index, iindex);
2503 lsra_new_stack(ls, dst->prev->prev, b_index, iindex);
2504 lsra_new_stack(ls, dst->prev, b_index, iindex);
2505 lsra_new_stack(ls, dst, b_index, iindex);
2507 #ifdef JOIN_DUP_STACK
2508 lsra_join_dup(ls, src, dst, dst->prev->prev->prev);
2509 lsra_join_dup(ls, src->prev, dst->prev,
2510 dst->prev->prev->prev->prev);
2511 lsra_join_2_stack(ls, src->prev->prev, dst->prev->prev, JOIN);
2515 /* pop 4 push 6 dup */
2517 lsra_from_stack(ls, src, b_index, iindex+1);
2518 lsra_from_stack(ls, src->prev, b_index, iindex+1);
2519 lsra_from_stack(ls, src->prev->prev, b_index, iindex+1);
2520 lsra_from_stack(ls, src->prev->prev->prev, b_index, iindex+1);
2521 lsra_new_stack(ls, dst->prev->prev->prev->prev->prev, b_index,
2523 lsra_new_stack(ls, dst->prev->prev->prev->prev, b_index, iindex);
2524 lsra_new_stack(ls, dst->prev->prev->prev, b_index, iindex);
2525 lsra_new_stack(ls, dst->prev->prev, b_index, iindex);
2526 lsra_new_stack(ls, dst->prev, b_index, iindex);
2527 lsra_new_stack(ls, dst, b_index, iindex);
2529 #ifdef JOIN_DUP_STACK
2530 lsra_join_dup(ls, src, dst, dst->prev->prev->prev->prev);
2531 lsra_join_dup(ls, src->prev, dst->prev,
2532 dst->prev->prev->prev->prev->prev);
2533 lsra_join_2_stack(ls, src->prev->prev, dst->prev->prev, JOIN);
2534 lsra_join_2_stack(ls, src->prev->prev->prev, dst->prev->prev->prev,
2539 /* pop 2 push 2 swap */
2541 lsra_from_stack(ls, src, b_index, iindex+1);
2542 lsra_from_stack(ls, src->prev, b_index, iindex+1);
2543 lsra_new_stack(ls, dst->prev, b_index, iindex);
2544 lsra_new_stack(ls, dst, b_index, iindex);
2546 lsra_join_2_stack(ls, src->prev, dst, JOIN);
2547 lsra_join_2_stack(ls, src, dst->prev, JOIN);
2585 lsra_from_stack(ls, src, b_index, iindex);
2586 lsra_from_stack(ls, src->prev, b_index, iindex);
2587 lsra_new_stack(ls, dst, b_index, iindex);
2588 #ifdef JOIN_DEST_STACK
2589 lsra_join_3_stack(ls, dst, src->prev, src, JOIN_OP);
2594 lsra_from_stack(ls, src, b_index, iindex);
2595 lsra_from_stack(ls, src->prev,b_index,iindex);
2596 lsra_new_stack(ls, dst, b_index, iindex);
2597 #ifdef JOIN_DEST_STACK
2598 lsra_join_2_stack(ls, src, dst, JOIN_OP);
2616 lsra_from_stack(ls, src, b_index, iindex);
2617 lsra_from_stack(ls, src->prev, b_index, iindex);
2618 lsra_new_stack(ls, dst, b_index, iindex);
2622 case ICMD_LADDCONST:
2623 case ICMD_LSUBCONST:
2624 case ICMD_LMULCONST:
2628 case ICMD_LANDCONST:
2630 case ICMD_LXORCONST:
2631 case ICMD_LSHLCONST:
2632 case ICMD_LSHRCONST:
2633 case ICMD_LUSHRCONST:
2635 case ICMD_IADDCONST:
2636 case ICMD_ISUBCONST:
2637 case ICMD_IMULCONST:
2641 case ICMD_IANDCONST:
2643 case ICMD_IXORCONST:
2644 case ICMD_ISHLCONST:
2645 case ICMD_ISHRCONST:
2646 case ICMD_IUSHRCONST:
2648 /* case ICMD_IFEQ_ICONST: */
2649 /* case ICMD_IFNE_ICONST: */
2650 /* case ICMD_IFLT_ICONST: */
2651 /* case ICMD_IFGE_ICONST: */
2652 /* case ICMD_IFGT_ICONST: */
2653 /* case ICMD_IFLE_ICONST: */
2658 case ICMD_INT2SHORT:
2676 case ICMD_CHECKCAST:
2677 lsra_from_stack(ls, src, b_index, iindex);
2678 lsra_new_stack(ls, dst, b_index, iindex);
2679 #ifdef JOIN_DEST_STACK
2680 lsra_join_2_stack(ls, src, dst, JOIN_OP);
2684 /* TODO: check if for these ICMDs JOIN_DEST_STACK works, too! */
2685 case ICMD_ARRAYLENGTH:
2686 case ICMD_INSTANCEOF:
2689 case ICMD_ANEWARRAY:
2692 lsra_from_stack(ls, src, b_index, iindex);
2693 lsra_new_stack(ls, dst, b_index, iindex);
2697 case ICMD_GETSTATIC:
2700 lsra_new_stack(ls, dst, b_index, iindex);
2703 /* pop many push any */
2705 case ICMD_INVOKESTATIC:
2706 case ICMD_INVOKESPECIAL:
2707 case ICMD_INVOKEVIRTUAL:
2708 case ICMD_INVOKEINTERFACE:
2709 INSTRUCTION_GET_METHODDESC(iptr,md);
2712 lsra_from_stack(ls, src, b_index, iindex);
2715 if (md->returntype.type != TYPE_VOID)
2716 lsra_new_stack(ls, dst, b_index, iindex);
2725 lsra_from_stack(ls, src, b_index, iindex);
2728 if (md->returntype.type != TYPE_VOID)
2729 lsra_new_stack(ls, dst, b_index, iindex);
2732 case ICMD_MULTIANEWARRAY:
2735 lsra_from_stack(ls, src, b_index, iindex);
2738 lsra_new_stack(ls, dst, b_index, iindex);
2742 exceptions_throw_internalerror("Unknown ICMD %d during register allocation",
2748 #endif /* defined(LV) */
2752 * These are local overrides for various environment variables in Emacs.
2753 * Please do not remove this and leave it at the end of the file, where
2754 * Emacs will automagically detect them.
2755 * ---------------------------------------------------------------------
2758 * indent-tabs-mode: t
2762 * vim:noexpandtab:sw=4:ts=4: