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"
39 #include "toolbox/logging.h"
40 #include "vm/builtin.h"
41 #include "vm/exceptions.h"
42 #include "vm/resolve.h"
43 #include "vm/options.h"
44 #include "vm/statistics.h"
45 #include "vm/stringlocal.h"
46 #include "vm/jit/abi.h"
47 #include "vm/jit/reg.h"
48 #include "vm/jit/allocator/liveness.h"
49 #include "vm/jit/allocator/lsra.h"
52 extern char **prof_m_names;
53 extern u4 **prof_bb_freq;
57 /* function prototypes */
58 void lsra_init(jitdata *);
59 void lsra_setup(jitdata *);
60 void lsra_main(jitdata *);
62 void lsra_reg_setup(jitdata *, struct lsra_register *, struct lsra_register * );
63 void lsra_calc_lifetime_length(jitdata *);
64 void _lsra_main( jitdata *, int *, int, struct lsra_register *, int *);
65 void lsra_expire_old_intervalls(jitdata *, struct lifetime *,
66 struct lsra_register *);
67 void spill_at_intervall(jitdata *, struct lifetime *);
68 void lsra_add_active(struct lifetime *, struct lifetime **, int *);
69 void _lsra_expire_old_intervalls(jitdata *, struct lifetime *,
70 struct lsra_register *, struct lifetime **,
72 void _spill_at_intervall(struct lifetime *, struct lifetime **, int *);
74 void lsra_alloc(jitdata *, int *, int, int *);
75 int lsra_getmem(struct lifetime *, struct freemem *, int *);
76 struct freemem *lsra_getnewmem(int *);
77 void lsra_setflags(int *, int);
79 #ifdef LSRA_DEBUG_VERBOSE
80 void lsra_dump_stack(stackelement_t* );
81 void print_lifetimes(jitdata *, int *, int);
85 void lsra_scan_registers_canditates(jitdata *, int);
86 void lsra_join_lifetimes(jitdata *, int);
88 void _lsra_new_stack( lsradata *, stackelement_t* , int , int, int);
89 void _lsra_from_stack(lsradata *, stackelement_t* , int , int, int);
90 void lsra_add_ss(struct lifetime *, stackelement_t* );
91 void lsra_usage_local(lsradata *, s4 , int , int , int , int );
96 bool lsra(jitdata *jd)
98 #if defined(ENABLE_STATISTICS)
103 #if defined(LSRA_DEBUG_CHECK)
106 stackelement_t* in,out;
110 #if defined(LSRA_DEBUG_CHECK)
113 while (b_index < m->basicblockcount ) {
115 if (m->basicblocks[b_index].flags >= BBREACHED) {
117 in=m->basicblocks[b_index].instack;
118 ind=m->basicblocks[b_index].indepth;
119 for (;ind != 0;in=in->prev, ind--) {
120 /* ARGVAR or LOCALVAR in instack is ok*/
122 if (in->varkind == ARGVAR) printf("ARGVAR in instack: \n");
123 if (in->varkind == LOCALVAR) printf("LOCALVAR in instack\n");
126 out=m->basicblocks[b_index].outstack;
127 outd=m->basicblocks[b_index].outdepth;
128 for (;outd != 0;out=out->prev, outd--) {
129 if (out->varkind == ARGVAR)
130 { log_text("ARGVAR in outstack\n"); assert(0); }
131 if (out->varkind == LOCALVAR)
132 { log_text("LOCALVAR in outstack\n"); assert(0); }
139 jd->ls = DNEW(lsradata);
143 #if defined(ENABLE_STATISTICS)
144 /* find conflicts between locals for statistics */
147 /* local Variable Lifetimes are at the end of the lifetime array and */
148 /* have v_index >= 0 */
149 for (locals_start = ls->lifetimecount-1; (locals_start >=0) &&
150 (ls->lifetime[ls->lt_used[locals_start]].v_index >= 0);
152 for (i=locals_start + 1; i < ls->lifetimecount; i++)
153 for (j=i+1; j < ls->lifetimecount; j++)
154 if ( !((ls->lifetime[ls->lt_used[i]].i_end
155 < ls->lifetime[ls->lt_used[j]].i_start)
156 || (ls->lifetime[ls->lt_used[j]].i_end <
157 ls->lifetime[ls->lt_used[i]].i_start)) )
158 count_locals_conflicts += 2;
164 /* everything's ok */
169 /* sort Basic Blocks using Depth First Search in reverse post order in */
171 void lsra_DFS(jitdata *jd) {
185 stack = DMNEW( int, m->basicblockcount + 1);
186 visited = (int *)DMNEW( int, m->basicblockcount + 1);
187 for (i = 0; i <= m->basicblockcount; i++) {
190 ls->sorted_rev[i]=-1;
193 stack[0] = 0; /* start with Block 0 */
195 visited[0] = ls->num_pred[0]; /* Start Block is handled right and can be */
199 while (not_finished) {
200 while (stack_top != 0) {
202 i = stack[stack_top];
205 for (succ = ls->succ[i]; succ != NULL; succ = succ->next) {
206 visited[succ->value]++;
207 if (visited[succ->value] == ls->num_pred[succ->value]) {
208 /* push the node on the stack, only if all ancestors have */
210 stack[stack_top] = succ->value;
215 not_finished = false;
216 for (i=1; i <= m->basicblockcount; i++) {
217 /* search for visited blocks, which have not reached the num_pred */
218 /* and put them on the stack -> happens with backedges */
219 if ((visited[i] != 0) && (visited[i] < ls->num_pred[i])) {
220 stack[stack_top] = i;
222 visited[i] = ls->num_pred[i];
230 void lsra_get_backedges_(lsradata *ls, int basicblockcount) {
233 struct _backedge *_backedges;
239 /* now look for backedges */
240 ls->backedge_count = 0;
241 for(i=0; i < basicblockcount; i++) {
242 if (ls->sorted[i] != -1)
243 for(s=ls->succ[ls->sorted[i]]; s != NULL; s=s->next) {
244 if (i >= ls->sorted_rev[s->value]) {
245 n=DNEW(struct _backedge);
246 n->start = max(i, ls->sorted_rev[s->value]);
247 n->end = min(i, ls->sorted_rev[s->value]);
248 n->next = _backedges;
250 ls->backedge_count++;
254 /* put _backedges in ls->backedge array */
255 ls->backedge = DMNEW(struct _backedge *, ls->backedge_count);
256 for (n=_backedges, i=0; n != NULL; n=n->next, i++) {
258 ls->backedge[i]->nesting = 1;
262 void lsra_get_nesting(jitdata *jd) {
271 for (i=0; i <= m->basicblockcount; i++)
272 if (ls->sorted[i] != -1)
273 ls->sorted_rev[ls->sorted[i]]=i;
275 lsra_get_backedges_(ls, m->basicblockcount + 1);
276 /* - sort backedge by increasing end: */
277 for (i=0; i < ls->backedge_count; i++)
278 for (j=i+1; j < ls->backedge_count; j++)
279 if ((ls->backedge[i]->end > ls->backedge[j]->end) || /* -> swap */
280 ((ls->backedge[i]->end == ls->backedge[j]->end) &&
281 (ls->backedge[i]->start > ls->backedge[j]->start) )) {
283 ls->backedge[i]=ls->backedge[j];
287 /* create ls->nesting */
288 /* look for nesting depth (overlapping backedges*/
289 for (i=0; i < ls->backedge_count - 1; i++) {
290 for (j = i + 1; (j < ls->backedge_count) &&
291 (ls->backedge[i]->start >= ls->backedge[j]->end); j++)
292 ls->backedge[j]->nesting += ls->backedge[i]->nesting;
297 while ( (i < m->basicblockcount + 1) ) {
298 if (j < ls->backedge_count) {
299 while ( i < ls->backedge[j]->end ) {
303 if ( (j+1) < ls->backedge_count)
304 end = min(ls->backedge[j]->start, ls->backedge[j+1]->end - 1);
306 end = ls->backedge[j]->start;
308 ls->nesting[i] = ls->backedge[j]->nesting;
318 #ifdef LSRA_DEBUG_VERBOSE
319 if (compileverbose) {
320 printf("sorted: \n");
321 for (i=0; i < ls->backedge_count; i++)
322 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);
323 printf("Nesting Level \n");
324 for (i=0; i<m->basicblockcount; i++) printf(" %3li", ls->nesting[i]);
328 for (i=0; i <= m->basicblockcount; i++) {
329 ls->sorted_rev[i] = -1;
330 ls->nesting[i] = 1+ls->nesting[i]*ls->nesting[i]*10;
334 void lsra_get_backedges(jitdata *jd) {
345 /* first remove artificial end basicblock from ls->sorted, succ and pred */
347 for (i=0; i < m->basicblockcount; i++) {
348 for (next=&(ls->succ[i]); *next != NULL; next=&((*next)->next)) {
349 if ( (*next)->value == m->basicblockcount ) {
350 /* artificial end bb found */
351 *next = (*next)->next;
352 if (*next == NULL) break;
355 for (next=&(ls->pred[i]); *next != NULL; next=&((*next)->next)) {
356 if ( (*next)->value == m->basicblockcount ) {
357 /* artificial end bb found */
358 *next = (*next)->next;
359 if (*next == NULL) break;
363 if (ls->sorted[i] == m->basicblockcount) j=i;
366 /* if an artificial end block was removed -> change ls->sorted accordingly*/
368 for (i=j+1; i <= m->basicblockcount; i++) {
369 ls->sorted[i-1] = ls->sorted[i];
370 ls->nesting[i-1] = ls->nesting[i];
373 for (i=0; i < m->basicblockcount; i++)
374 if (ls->sorted[i] != -1)
375 ls->sorted_rev[ls->sorted[i]]=i;
377 lsra_get_backedges_(ls, m->basicblockcount);
379 /* - sort backedge by increasing start */
380 for (i=0; i < ls->backedge_count; i++)
381 for (j=i+1; j < ls->backedge_count; j++)
382 if (ls->backedge[i]->start > ls->backedge[j]->start) {
385 ls->backedge[i] = ls->backedge[j];
389 #ifdef LSRA_DEBUG_VERBOSE
390 if (compileverbose) {
391 printf("sorted: \n");
392 for (i=0; i < ls->backedge_count; i++)
393 printf("Backedge: %i - %i, %i - %i\n",
394 ls->sorted[ls->backedge[i]->start],
395 ls->sorted[ls->backedge[i]->end], ls->backedge[i]->start,
396 ls->backedge[i]->end);
397 printf("Nesting Level \n");
398 for (i=0; i<m->basicblockcount; i++) printf(" %3li", ls->nesting[i]);
404 /* - merge overlapping backedges */
407 for (i=0; i < ls->backedge_count-1; i++) {
408 if (ls->backedge[i] != NULL) {
409 for (j = i + 1; (j < ls->backedge_count) && (ls->backedge[j] == NULL); j++ );
410 if (j != ls->backedge_count) {
411 if (ls->backedge[i]->start >= ls->backedge[j]->end) {
413 /* overlapping -> merge */
414 ls->backedge[j]->end = min (ls->backedge[j]->end,
415 ls->backedge[i]->end);
416 ls->backedge[i] = NULL;
422 #ifdef LSRA_DEBUG_VERBOSE
423 if (compileverbose) {
424 printf("merged: \n");
425 for (i = 0; i < ls->backedge_count; i++)
426 if (ls->backedge[i] != NULL)
427 printf("Backedge: %i - %i, %i - %i\n",
428 ls->sorted[ls->backedge[i]->start],
429 ls->sorted[ls->backedge[i]->end],
430 ls->backedge[i]->start, ls->backedge[i]->end);
433 /* - remove backedge[] == NULL from array */
435 for (j = ls->backedge_count - 1; ((j>=0) && (ls->backedge[j] == NULL));
439 if (ls->backedge[i] == NULL) { /* swap backedge[i] and backedge[j]*/
441 ls->backedge[j] = ls->backedge[i];
445 ls->backedge_count--;
448 #ifdef LSRA_DEBUG_VERBOSE
449 if (compileverbose) {
451 for (i=0; i < ls->backedge_count; i++)
452 printf("Backedge: %i - %i, %i - %i\n",
453 ls->sorted[ls->backedge[i]->start],
454 ls->sorted[ls->backedge[i]->end],ls->backedge[i]->start,
455 ls->backedge[i]->end);
460 void lsra_add_cfg(jitdata *jd, int from, int to) {
468 /* ignore Empty, Deleted,... Basic Blocks as target */
469 /* TODO: Setup BasicBlock array before to avoid this */
470 /* best together with using the basicblock list, so lsra works */
471 /* with opt_loops, too */
472 for (;(to < m->basicblockcount) && (m->basicblocks[to].flags < BBREACHED); to++);
474 for (n=ls->succ[from]; (n!= NULL) && (n->value != to); n=n->next);
475 if (n != NULL) return; /* edge from->to already existing */
477 n=DNEW(struct _list);
480 n->next=ls->succ[from];
483 n=DNEW(struct _list);
485 n->next=ls->pred[to];
490 /* add Edges from guarded Areas to Exception handlers in the CFG */
491 void lsra_add_exceptions(jitdata *jd) {
501 ex = jd->exceptiontable;
503 /* add cfg edges from all bb of a try block to the start of the according */
504 /* exception handler to ensure the right order after depthfirst search */
506 #ifdef LSRA_DEBUG_VERBOSE
508 printf("ExTable(%i): ", jd->exceptiontablelength);
511 for (; ex != NULL; ex = ex->down) {
513 #ifdef LSRA_DEBUG_VERBOSE
514 if (compileverbose) {
515 printf("[%i-%i]->%i ",ex->start->nr, ex->end->nr,
517 if (ex->handler->nr >= m->basicblockcount) {
518 log_text("Exceptionhandler Basicblocknummer invalid\n");
521 if (m->basicblocks[ex->handler->nr].flags < BBREACHED) {
522 log_text("Exceptionhandler Basicblocknummer not reachable\n");
525 if (ex->start->nr > ex->end->nr) {
526 log_text("Guarded Area starts after its end\n");
531 /* loop all valid Basic Blocks of the guarded area and add CFG edges */
532 /* to the appropriate handler */
533 for (i=ex->start->nr; (i <= ex->end->nr) &&
534 (i < m->basicblockcount); i++)
535 if (m->basicblocks[i].flags >= BBREACHED)
536 lsra_add_cfg(jd, i, ex->handler->nr);
538 #ifdef LSRA_DEBUG_VERBOSE
539 if (compileverbose) {
545 void lsra_add_jsr(jitdata *jd, int from, int to) {
548 struct _sbr *sbr, *n;
554 /* ignore Empty, Deleted,... Basic Blocks as target */
555 /* TODO: Setup BasicBlock array before to avoid this */
556 /* best together with using the basicblock list, so lsra works */
557 /* with opt_loops, too */
558 for (; (to < m->basicblockcount) && (m->basicblocks[to].flags < BBREACHED);
560 #ifdef LSRA_DEBUG_CHECK
561 if (to == m->basicblockcount)
562 { log_text("Invalid subroutine start index\n"); assert(0); }
565 lsra_add_cfg(jd, from, to);
567 /* from + 1 ist the return Basic Block Index */
568 for (from++; (from < m->basicblockcount) &&
569 (m->basicblocks[from].flags < BBREACHED); from++);
570 #ifdef LSRA_DEBUG_CHECK
571 if (from == m->basicblockcount)
572 { log_text("Invalid return basic block index for jsr\n"); assert(0); }
575 /* add subroutine info in ls->sbr.next */
577 /* search for right place to insert */
578 for (sbr = &(ls->sbr); (sbr->next != NULL) && (sbr->next->header < to); sbr=sbr->next);
580 if ((sbr->next!= NULL) && (sbr->next->header == to)) {
581 /* Entry for this sub already exist */
584 /* make new Entry and insert it in ls->sbr.next */
585 n = DNEW( struct _sbr );
595 /* now insert return adress in sbr->ret */
596 ret = DNEW( struct _list);
598 ret->next = sbr->ret;
602 void lsra_add_sub( jitdata *jd, int b_index, struct _list *ret,
614 /* break at virtual End Block */
615 if (b_index != m->basicblockcount) {
616 visited[b_index] = true;
619 if (m->basicblocks[b_index].flags < BBREACHED)
621 if (!next_block && !(m->basicblocks[b_index].icount))
625 ip = m->basicblocks[b_index].iinstr
626 + m->basicblocks[b_index].icount -1;
628 if (ip->opc == ICMD_JSR) /* nested Subroutines */
633 if (ip->opc == ICMD_RET) {
634 /* subroutine return found -> add return adresses to CFG */
635 for (l = ret; l != NULL; l = l->next)
636 lsra_add_cfg(jd, b_index, l->value);
637 } else { /* follow CFG */
638 for ( l = ls->succ[b_index]; l != NULL; l = l->next)
639 if (!visited[l->value])
640 lsra_add_sub(jd, l->value, ret, visited);
642 } else { /* fall through to next block */
643 if (!visited[b_index + 1])
644 lsra_add_sub(jd, b_index + 1, ret, visited);
649 /* Add subroutines from ls->sbr list to CFG */
650 void lsra_add_subs(jitdata *jd) {
656 #ifdef LSRA_DEBUG_VERBOSE
663 visited = (bool *)DMNEW(int, m->basicblockcount + 1);
664 for (i=0; i <= m->basicblockcount; i++) visited[i] = false;
665 for (sbr = ls->sbr.next; sbr != NULL; sbr=sbr->next) {
667 #ifdef LSRA_DEBUG_VERBOSE
668 if (compileverbose) {
669 printf("Subroutine Header: %3i Return Adresses:",sbr->header);
670 for (ret = sbr->ret; ret != NULL; ret = ret->next)
671 printf(" %3i", ret->value);
675 lsra_add_sub(jd, sbr->header, sbr->ret, visited );
679 /* Generate the Control Flow Graph */
680 /* ( pred,succ,num_pred of lsradata structure) */
682 void lsra_make_cfg(jitdata *jd) {
687 int high, low, count;
694 while (b_index < m->basicblockcount ) {
695 if ((m->basicblocks[b_index].flags >= BBREACHED) &&
696 (len = m->basicblocks[b_index].icount)) {
697 /* block is valid and contains instructions */
699 /* set ip to last instruction */
700 ip = m->basicblocks[b_index].iinstr +
701 m->basicblocks[b_index].icount -1;
702 while ((len>0) && (ip->opc == ICMD_NOP)) {
706 switch (ip->opc) { /* check type of last instruction */
714 lsra_add_cfg(jd, b_index, m->basicblockcount);
715 break; /* function returns -> end of graph */
744 case ICMD_IF_ACMPNE: /* branch -> add next block */
745 lsra_add_cfg(jd, b_index, b_index+1);
746 /* fall throu -> add branch target */
749 lsra_add_cfg(jd, b_index, m->basicblockindex[ip->op1]);
750 break; /* visit branch (goto) target */
752 case ICMD_TABLESWITCH: /* switch statement */
755 lsra_add_cfg(jd, b_index, m->basicblockindex[*s4ptr]);
762 count = (high-low+1);
764 while (--count >= 0) {
766 lsra_add_cfg(jd, b_index,
767 m->basicblockindex[*s4ptr]);
771 case ICMD_LOOKUPSWITCH: /* switch statement */
774 lsra_add_cfg(jd, b_index, m->basicblockindex[*s4ptr]);
779 while (--count >= 0) {
780 lsra_add_cfg(jd, b_index,
781 m->basicblockindex[s4ptr[1]]);
787 lsra_add_jsr(jd, b_index, m->basicblockindex[ip->op1]);
794 lsra_add_cfg(jd, b_index, b_index + 1 );
796 } /* switch (ip->opc)*/
797 } /* if ((m->basicblocks[blockIndex].icount)&& */
798 /* (m->basicblocks[b_index].flags >= BBREACHED)) */
800 } /* while (b_index < m->basicblockcount ) */
803 void lsra_init(jitdata *jd) {
811 /* Init LSRA Data Structures */
812 /* allocate lifetimes for all Basicblocks */
813 /* + 1 for an artificial exit node */
814 /* which is needed as "start" point for the reverse postorder sorting */
815 ls->pred = DMNEW(struct _list *, m->basicblockcount+1);
816 ls->succ = DMNEW(struct _list *, m->basicblockcount+1);
817 ls->sorted = DMNEW(int , m->basicblockcount+1);
818 ls->sorted_rev = DMNEW(int , m->basicblockcount+1);
819 ls->num_pred = DMNEW(int , m->basicblockcount+1);
820 ls->nesting = DMNEW(long , m->basicblockcount+1);
821 for (i=0; i<m->basicblockcount; i++) {
825 ls->sorted_rev[i]=-1;
829 ls->pred[m->basicblockcount]=NULL;
830 ls->succ[m->basicblockcount]=NULL;
831 ls->sorted[m->basicblockcount]=-1;
832 ls->sorted_rev[m->basicblockcount]=-1;
833 ls->num_pred[m->basicblockcount]=0;
840 void lsra_setup(jitdata *jd) {
845 #ifdef LSRA_DEBUG_VERBOSE
862 #if defined(ENABLE_LOOP)
863 /* Loop optimization "destroys" the basicblock array */
864 /* TODO: work with the basicblock list */
866 log_text("lsra not possible with loop optimization\n");
869 #endif /* defined(ENABLE_LOOP) */
871 /* Setup LSRA Data structures */
873 /* Generate the Control Flow Graph */
875 /* gather nesting before adding of Exceptions and Subroutines!!! */
879 lsra_get_nesting(jd);
882 #ifdef LSRA_DEBUG_VERBOSE
883 if (compileverbose) {
884 printf("Successors:\n");
885 for (i=0; i < m->basicblockcount; i++) {
887 for (nl=ls->succ[i]; nl!= NULL; nl=nl->next)
888 printf("%3i ",nl->value);
891 printf("Predecessors:\n");
892 for (i=0; i < m->basicblockcount; i++) {
894 for (nl=ls->pred[i]; nl!= NULL; nl=nl->next)
895 printf("%3i ",nl->value);
899 for (i=0; i < m->basicblockcount; i++) printf("%3i ", ls->sorted[i]);
901 printf("Sorted_rev: ");
902 for (i=0; i < m->basicblockcount; i++) printf("%3i ", ls->sorted_rev[i]);
907 /* add subroutines before exceptions! They "destroy" the CFG */
909 lsra_add_exceptions(jd);
911 /* generate reverse post order sort */
914 /* setup backedge and nested data structures*/
915 lsra_get_backedges(jd);
919 ls->lifetimecount = ls->maxlifetimes + jd->maxlocals * (TYPE_ADR+1);
920 ls->lifetime = DMNEW(struct lifetime, ls->lifetimecount);
921 ls->lt_used = DMNEW(int, ls->lifetimecount);
922 ls->lt_int = DMNEW(int, ls->lifetimecount);
923 ls->lt_int_count = 0;
924 ls->lt_flt = DMNEW(int, ls->lifetimecount);
925 ls->lt_flt_count = 0;
926 ls->lt_mem = DMNEW(int, ls->lifetimecount);
927 ls->lt_mem_count = 0;
929 for (i=0; i < ls->lifetimecount; i++) ls->lifetime[i].type = -1;
931 #ifdef LSRA_DEBUG_VERBOSE
932 if (compileverbose) {
933 printf("Successors:\n");
934 for (i=0; i < m->basicblockcount; i++) {
936 for (nl=ls->succ[i]; nl!= NULL; nl=nl->next)
937 printf("%3i ",nl->value);
940 printf("Predecessors:\n");
941 for (i=0; i < m->basicblockcount; i++) {
943 for (nl=ls->pred[i]; nl!= NULL; nl=nl->next)
944 printf("%3i ",nl->value);
948 for (i=0; i < m->basicblockcount; i++) printf("%3i ", ls->sorted[i]);
950 printf("Sorted_rev: ");
951 for (i=0; i < m->basicblockcount; i++) printf("%3i ", ls->sorted_rev[i]);
957 #ifdef LSRA_DEBUG_CHECK
958 /* compare m->basicblocks[] with the list basicblocks->next */
960 bptr = m->basicblocks;
961 while (bptr != NULL) {
962 if (i > m->basicblockcount){
963 { log_text("linked bb list does not correspond with bb array(1)\n");
966 if (bptr != &(m->basicblocks[i])){
967 { log_text("linked bb list does not correspond with bb array(2)\n");
974 if (i<m->basicblockcount){
975 { log_text("linked bb list does not correspond with bb array(3)\n");
988 methoddesc *md = m->parseddesc;
990 /* Create Stack Slot lifetimes over all basic blocks */
991 for (i=m->basicblockcount-1; i >= 0; i--) {
992 if (ls->sorted[i] != -1) {
993 lsra_scan_registers_canditates(jd, ls->sorted[i]);
994 lsra_join_lifetimes(jd, ls->sorted[i]);
998 /* Parameter initialisiation for locals [0 .. paramcount[ */
999 /* -> add local var write access at (bb=0,iindex=-1) */
1000 /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
1001 /* this needs a special treatment, wenn lifetimes get extended */
1002 /* over backedges, since this parameter initialisation happens */
1003 /* outside of Basic Block 0 !!!! */
1004 /* this could have been avoided by marking the read access with -1,0 */
1006 for (p = 0, i = 0; p < md->paramcount; p++) {
1007 t = md->paramtypes[p].type;
1009 if (rd->locals[i][t].type >= 0)
1010 /* Param to Local init happens before normal Code */
1011 lsra_usage_local(ls, i, t, 0, -1, LSRA_STORE);
1013 /* increment local counter a second time */
1014 /* for 2 word types */
1015 if (IS_2_WORD_TYPE(t))
1021 lsra_calc_lifetime_length(jd);
1023 #ifdef LSRA_DEBUG_VERBOSE
1025 printf("Basicblockcount: %4i\n",m->basicblockcount);
1030 void lsra_reg_setup(jitdata *jd, struct lsra_register *int_reg,
1031 struct lsra_register *flt_reg ) {
1032 int i, j, iarg, farg;
1035 bool *fltarg_used, *intarg_used;
1044 int_reg->nregdesc = nregdescint;
1045 flt_reg->nregdesc = nregdescfloat;
1046 if (code_is_leafmethod(code)) {
1047 /* Temp and Argumentregister can be used as saved registers */
1049 int_reg->sav_top = INT_ARG_CNT + INT_TMP_CNT + INT_SAV_CNT;
1050 int_reg->sav_reg = DMNEW(int, int_reg->sav_top);
1051 int_reg->tmp_reg = NULL;
1052 int_reg->tmp_top = -1;
1053 flt_reg->sav_top = FLT_ARG_CNT + FLT_TMP_CNT + FLT_SAV_CNT;
1054 flt_reg->sav_reg = DMNEW(int, flt_reg->sav_top);
1055 flt_reg->tmp_reg = NULL;
1056 flt_reg->tmp_top = -1;
1058 /* additionaly precolour registers for Local Variables acting as */
1064 intarg_used = DMNEW(bool, INT_ARG_CNT);
1065 for (i=0; i < INT_ARG_CNT; i++)
1066 intarg_used[i]=false;
1068 fltarg_used = DMNEW(bool, FLT_ARG_CNT);
1069 for (i=0; i < FLT_ARG_CNT; i++)
1070 fltarg_used[i]=false;
1072 int_sav_top=int_reg->sav_top;
1073 flt_sav_top=flt_reg->sav_top;
1075 for (i=0; (i < md->paramcount); i++) {
1076 if (!md->params[i].inmemory) {
1077 if (IS_INT_LNG_TYPE(md->paramtypes[i].type)) {
1078 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1079 if (IS_2_WORD_TYPE(md->paramtypes[i].type)) {
1080 int_reg->sav_reg[--int_sav_top] =
1081 rd->argintregs[GET_HIGH_REG(md->params[i].regoff)];
1082 intarg_used[GET_HIGH_REG(md->params[i].regoff)]=true;
1083 /*used -> don't copy later on */
1084 int_reg->sav_reg[--int_sav_top] =
1085 rd->argintregs[GET_LOW_REG(md->params[i].regoff)];
1086 intarg_used[GET_LOW_REG(md->params[i].regoff)]=true;
1087 /*used -> don't copy later on */
1090 { /* !IS_2_WORD_TYPE(md->paramtypes[i].type */
1091 int_reg->sav_reg[--int_sav_top] =
1092 rd->argintregs[md->params[i].regoff];
1093 intarg_used[md->params[i].regoff]=true;
1094 /*used -> don't copy later on */
1097 #if !defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
1098 /* do not precolour float arguments if they are passed in */
1099 /* integer registers. But these integer argument registers */
1100 /* still be used in the method! */
1101 else { /* IS_FLT_DBL_TYPE(md->paramtypes[i].type */
1102 flt_reg->sav_reg[--flt_sav_top] =
1103 rd->argfltregs[md->params[i].regoff];
1104 fltarg_used[md->params[i].regoff]=true;
1111 /* copy rest of argument registers to flt_reg->sav_reg and */
1112 /* int_reg->sav_reg; */
1113 for (i=0; i < INT_ARG_CNT; i++)
1114 if (!intarg_used[i])
1115 int_reg->sav_reg[--int_sav_top]=rd->argintregs[i];
1116 for (i=0; i < FLT_ARG_CNT; i++)
1117 if (!fltarg_used[i])
1118 flt_reg->sav_reg[--flt_sav_top]=rd->argfltregs[i];
1120 /* copy temp registers to flt_reg->sav_reg and int_reg->sav_reg */
1121 for (i=0; i < INT_TMP_CNT; i++)
1122 int_reg->sav_reg[--int_sav_top]=rd->tmpintregs[i];
1123 for (i=0; i < FLT_TMP_CNT; i++)
1124 flt_reg->sav_reg[--flt_sav_top]=rd->tmpfltregs[i];
1127 /* non leaf method -> use Argument Registers [arg[int|flt]reguse */
1128 /* ... [INT|FLT]_ARG_CNT[ as temp reg */
1129 /* divide temp and saved registers */
1130 int argintreguse, argfltreguse;
1132 /* with Locals as non SAVEDVAR, the used arg[int|flt] as in params */
1133 /* of the method itself have to be regarded, or mismatch before */
1134 /* block 0 with parameter copy could happen! */
1135 argintreguse = max(rd->argintreguse, md->argintreguse);
1136 argfltreguse = max(rd->argfltreguse, md->argfltreguse);
1138 argintreguse = rd->argintreguse;
1139 argfltreguse = rd->argfltreguse;
1141 int_sav_top = int_reg->sav_top = INT_SAV_CNT;
1142 int_reg->sav_reg = DMNEW(int, int_reg->sav_top);
1143 int_reg->tmp_top = INT_TMP_CNT +
1144 max(0, (INT_ARG_CNT - argintreguse));
1145 int_reg->tmp_reg = DMNEW(int, int_reg->tmp_top);
1147 flt_sav_top =flt_reg->sav_top = FLT_SAV_CNT;
1148 flt_reg->sav_reg = DMNEW(int, flt_reg->sav_top);
1149 flt_reg->tmp_top = FLT_TMP_CNT +
1150 max(0 , (FLT_ARG_CNT - argfltreguse));
1151 flt_reg->tmp_reg = DMNEW(int, flt_reg->tmp_top);
1153 /* copy temp and unused argument registers to flt_reg->tmp_reg and */
1154 /* int_reg->tmp_reg */
1155 for (i=0; i < INT_TMP_CNT; i++)
1156 int_reg->tmp_reg[i]=rd->tmpintregs[i];
1157 for (j=argintreguse; j < INT_ARG_CNT; j++, i++)
1158 int_reg->tmp_reg[i]=rd->argintregs[j];
1159 for (i=0; i < FLT_TMP_CNT; i++)
1160 flt_reg->tmp_reg[i]=rd->tmpfltregs[i];
1161 for (j=argfltreguse; j < FLT_ARG_CNT; j++, i++)
1162 flt_reg->tmp_reg[i]=rd->argfltregs[j];
1165 /* now copy saved registers to flt_reg->sav_reg and int_reg->sav_reg */
1166 for (i = INT_SAV_CNT-1; i >= 0; i--)
1167 int_reg->sav_reg[--int_sav_top]=rd->savintregs[i];
1168 for (i = FLT_SAV_CNT-1; i >= 0; i--)
1169 flt_reg->sav_reg[--flt_sav_top]=rd->savfltregs[i];
1173 void lsra_insertion_sort( struct lsradata *ls, int *a, int lo, int hi) {
1176 for (i=lo+1; i<=hi; i++) {
1178 t=ls->lifetime[a[j]].i_start;
1180 while ((j>lo) && (ls->lifetime[a[j-1]].i_start > t)) {
1188 void lsra_qsort( struct lsradata *ls, int *a, int lo, int hi) {
1194 x = ls->lifetime[a[(lo+hi)/2]].i_start;
1197 while (ls->lifetime[a[i]].i_start < x) i++;
1198 while (ls->lifetime[a[j]].i_start > x) j--;
1200 /* exchange a[i], a[j] */
1210 if (lo < j) lsra_qsort( ls, a, lo, j);
1211 if (i < hi) lsra_qsort( ls, a, i, hi);
1213 lsra_insertion_sort(ls, a, lo, hi);
1217 void lsra_param_sort(struct lsradata *ls, int *lifetime, int lifetime_count) {
1222 /* count number of parameters ( .i_start == -1) */
1223 for (param_count=0; (param_count < lifetime_count) &&
1224 (ls->lifetime[lifetime[param_count]].i_start == -1); param_count++);
1226 if (param_count > 0) {
1227 /* now sort the parameters by v_index */
1228 for (i=0; i < param_count -1; i++)
1229 for (j=i+1; j < param_count; j++)
1230 if ( ls->lifetime[lifetime[i]].v_index >
1231 ls->lifetime[lifetime[j]].v_index) {
1234 lifetime[i]=lifetime[j];
1240 void lsra_main(jitdata *jd) {
1241 #ifdef LSRA_DEBUG_VERBOSE
1246 struct lsra_register flt_reg, int_reg;
1249 #if defined(__I386__)
1257 /* sort lifetimes by increasing start */
1258 lsra_qsort( ls, ls->lt_mem, 0, ls->lt_mem_count - 1);
1259 lsra_qsort( ls, ls->lt_int, 0, ls->lt_int_count - 1);
1260 lsra_qsort( ls, ls->lt_flt, 0, ls->lt_flt_count - 1);
1261 /* sort local vars used as parameter */
1262 lsra_param_sort( ls, ls->lt_int, ls->lt_int_count);
1263 lsra_param_sort( ls, ls->lt_flt, ls->lt_flt_count);
1264 lsra_reg_setup(jd, &int_reg, &flt_reg);
1266 #ifdef LSRA_DEBUG_VERBOSE
1267 if (compileverbose) {
1268 printf("INTSAV REG: ");
1269 for (i=0; i<int_reg.sav_top; i++)
1270 printf("%2i ",int_reg.sav_reg[i]);
1271 printf("\nINTTMP REG: ");
1272 for (i=0; i<int_reg.tmp_top; i++)
1273 printf("%2i ",int_reg.tmp_reg[i]);
1274 printf("\nFLTSAV REG: ");
1275 for (i=0; i<flt_reg.sav_top; i++)
1276 printf("%2i ",flt_reg.sav_reg[i]);
1277 printf("\nFLTTMP REG: ");
1278 for (i=0; i<flt_reg.tmp_top; i++)
1279 printf("%2i ",flt_reg.tmp_reg[i]);
1283 ls->active_tmp = DMNEW( struct lifetime *, max(INT_REG_CNT, FLT_REG_CNT));
1284 ls->active_sav = DMNEW( struct lifetime *, max(INT_REG_CNT, FLT_REG_CNT));
1286 lsra_reg_use=INT_SAV_CNT; /* init to no saved reg used... */
1287 _lsra_main(jd, ls->lt_int, ls->lt_int_count, &int_reg, &lsra_reg_use);
1288 if (lsra_reg_use > INT_SAV_CNT)
1289 lsra_reg_use=INT_SAV_CNT;
1290 rd->savintreguse = lsra_reg_use;
1292 lsra_reg_use = FLT_SAV_CNT; /* no saved reg used... */
1293 _lsra_main(jd, ls->lt_flt, ls->lt_flt_count, &flt_reg, &lsra_reg_use);
1294 if (lsra_reg_use > FLT_SAV_CNT)
1295 lsra_reg_use=FLT_SAV_CNT;
1296 rd->savfltreguse=lsra_reg_use;
1298 /* rd->memuse was already set in stack.c to allocate stack space for */
1299 /* passing arguments to called methods */
1300 #if defined(__I386__)
1301 if (checksync && code_is_synchronized(code)) {
1302 /* reserve 0(%esp) for Monitorenter/exit Argument on i386 */
1308 lsra_mem_use = rd->memuse; /* Init with memuse from stack.c */
1310 lsra_alloc(jd, ls->lt_mem, ls->lt_mem_count, &lsra_mem_use);
1311 lsra_alloc(jd, ls->lt_int, ls->lt_int_count, &lsra_mem_use);
1312 lsra_alloc(jd, ls->lt_flt, ls->lt_flt_count, &lsra_mem_use);
1314 rd->memuse=lsra_mem_use;
1316 #ifdef LSRA_DEBUG_VERBOSE
1317 if (compileverbose) {
1318 printf("Int RA complete \n");
1319 printf("Lifetimes after splitting int: \n");
1320 print_lifetimes(jd, ls->lt_int, ls->lt_int_count);
1322 printf("Flt RA complete \n");
1323 printf("Lifetimes after splitting flt:\n");
1324 print_lifetimes(jd, ls->lt_flt, ls->lt_flt_count);
1326 printf("Rest RA complete \n");
1327 printf("Lifetimes after leftt:\n");
1328 print_lifetimes(jd, ls->lt_mem, ls->lt_mem_count);
1333 void lsra_alloc(jitdata *jd, int *lifet, int lifetimecount, int *mem_use)
1336 struct lifetime *lt;
1337 struct freemem *fmem;
1338 struct stackslot *n;
1340 #ifdef HAS_4BYTE_STACKSLOT
1341 struct freemem *fmem_2;
1349 fmem = DNEW(struct freemem);
1352 #ifdef HAS_4BYTE_STACKSLOT
1353 fmem_2=DNEW(struct freemem);
1355 fmem_2->next = NULL;
1358 for (lt_index = 0; lt_index < lifetimecount; lt_index ++) {
1359 lt = &(ls->lifetime[lifet[lt_index]]);
1363 if (lt->reg == -1) {
1365 #ifdef HAS_4BYTE_STACKSLOT
1366 if (IS_2_WORD_TYPE(lt->type))
1367 regoff = lsra_getmem(lt, fmem_2, mem_use);
1370 regoff = lsra_getmem(lt, fmem, mem_use);
1372 flags = lt->savedvar;
1376 if (lt->v_index < 0) {
1377 for (n = lt->local_ss; n != NULL; n = n->next) {
1378 lsra_setflags(&(n->s->flags), flags);
1379 n->s->regoff = regoff;
1381 } else { /* local var */
1382 if (rd->locals[lt->v_index][lt->type].type >= 0) {
1383 rd->locals[lt->v_index][lt->type].flags = flags;
1384 rd->locals[lt->v_index][lt->type].regoff = regoff;
1386 log_text("Type Data mismatch\n");
1394 void lsra_setflags(int *flags, int newflags)
1396 if ( newflags & INMEMORY)
1399 *flags &= ~INMEMORY;
1401 if (newflags & SAVEDVAR)
1405 int lsra_getmem(struct lifetime *lt, struct freemem *fmem, int *mem_use)
1407 struct freemem *fm, *p;
1409 /* no Memory Slot allocated till now or all are still live */
1410 if ((fmem->next == NULL) || (fmem->next->end > lt->i_start)) {
1411 #ifdef HAS_4BYTE_STACKSLOT
1412 if (IS_2_WORD_TYPE(lt->type))
1413 if ( (*mem_use)&1 ) /* align memory location for 2 Word Types */
1415 fm=lsra_getnewmem(mem_use);
1416 if (IS_2_WORD_TYPE(lt->type))
1417 /* allocate a second following Slot for 2 Word Types */
1420 fm=lsra_getnewmem(mem_use);
1423 /* Memoryslot free */
1425 fmem->next = fm->next;
1428 fm->end = lt->i_end;
1429 for (p = fmem; (p->next != NULL) && (p->next->end < fm->end); p = p->next);
1435 struct freemem *lsra_getnewmem(int *mem_use)
1439 fm = DNEW(struct freemem);
1446 void _lsra_main(jitdata *jd, int *lifet, int lifetimecount,
1447 struct lsra_register *reg, int *reg_use)
1449 struct lifetime *lt;
1453 bool temp; /* reg from temp registers (true) or saved registers (false) */
1460 #if !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1463 if ((reg->tmp_top+reg->sav_top) == 0) {
1465 /* no registers available */
1466 for (lt_index = 0; lt_index < lifetimecount; lt_index++)
1467 ls->lifetime[lifet[lt_index]].reg = -1;
1471 ls->active_tmp_top = 0;
1472 ls->active_sav_top = 0;
1474 for (lt_index = 0; lt_index < lifetimecount; lt_index++) {
1475 lt = &(ls->lifetime[lifet[lt_index]]);
1477 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1478 regsneeded = (lt->type == TYPE_LNG)?1:0;
1481 lsra_expire_old_intervalls(jd, lt, reg);
1484 if (lt->savedvar || code_is_leafmethod(code)) {
1485 /* use Saved Reg (in case of leafmethod all regs are saved regs) */
1486 if (reg->sav_top > regsneeded) {
1487 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1489 reg_index = PACK_REGS(reg->sav_reg[--reg->sav_top],
1490 reg->sav_reg[--reg->sav_top]);
1494 reg_index = reg->sav_reg[--reg->sav_top];
1496 } else { /* use Temp Reg or if none is free a Saved Reg */
1497 if (reg->tmp_top > regsneeded) {
1499 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1501 reg_index = PACK_REGS(reg->tmp_reg[--reg->tmp_top],
1502 reg->tmp_reg[--reg->tmp_top]);
1505 reg_index = reg->tmp_reg[--reg->tmp_top];
1508 if (reg->sav_top > regsneeded) {
1510 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1512 reg_index = PACK_REGS(reg->sav_reg[--reg->sav_top],
1513 reg->sav_reg[--reg->sav_top]);
1516 reg_index = reg->sav_reg[--reg->sav_top];
1519 if (reg_index == -1) /* no reg is available anymore... -> spill */
1520 spill_at_intervall(jd, lt);
1522 lt->reg = reg_index;
1524 lsra_add_active(lt, ls->active_tmp, &(ls->active_tmp_top));
1526 if (reg->sav_top<*reg_use) *reg_use=reg->sav_top;
1527 lsra_add_active(lt, ls->active_sav, &(ls->active_sav_top));
1533 void lsra_add_active(struct lifetime *lt, struct lifetime **active,
1538 for(i = 0; (i < *active_top) && (active[i]->i_end < lt->i_end); i++);
1539 for(j = *active_top; j > i; j--) active[j] = active[j-1];
1544 void lsra_expire_old_intervalls(jitdata *jd, struct lifetime *lt,
1545 struct lsra_register *reg)
1547 _lsra_expire_old_intervalls(jd, lt, reg, jd->ls->active_tmp,
1548 &(jd->ls->active_tmp_top));
1549 _lsra_expire_old_intervalls(jd, lt, reg, jd->ls->active_sav,
1550 &(jd->ls->active_sav_top));
1553 void _lsra_expire_old_intervalls(jitdata *jd, struct lifetime *lt,
1554 struct lsra_register *reg,
1555 struct lifetime **active, int *active_top)
1559 for(i = 0; i < *active_top; i++) {
1560 if (active[i]->i_end > lt->i_start) break;
1562 /* make active[i]->reg available again */
1563 if (code_is_leafmethod(code)) {
1564 /* leafmethod -> don't care about type -> put all again into */
1566 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1567 if (active[i]->type == TYPE_LNG) {
1568 reg->sav_reg[reg->sav_top++] = GET_LOW_REG(active[i]->reg);
1569 reg->sav_reg[reg->sav_top++] = GET_HIGH_REG(active[i]->reg);
1572 reg->sav_reg[reg->sav_top++] = active[i]->reg;
1574 /* no leafmethod -> distinguish between temp and saved register */
1575 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1576 if (active[i]->type == TYPE_LNG) {
1577 /* no temp and saved regs are packed together, so looking at */
1578 /* LOW_REG is sufficient */
1579 if ( reg->nregdesc[ GET_LOW_REG(active[i]->reg)] == REG_SAV) {
1580 reg->sav_reg[reg->sav_top++] = GET_LOW_REG(active[i]->reg);
1581 reg->sav_reg[reg->sav_top++] = GET_HIGH_REG(active[i]->reg);
1583 reg->tmp_reg[reg->tmp_top++] = GET_LOW_REG(active[i]->reg);
1584 reg->tmp_reg[reg->tmp_top++] = GET_HIGH_REG(active[i]->reg);
1588 if ( reg->nregdesc[active[i]->reg] == REG_SAV) {
1589 reg->sav_reg[reg->sav_top++] = active[i]->reg;
1591 reg->tmp_reg[reg->tmp_top++] = active[i]->reg;
1596 /* active[0..i[ is to be removed */
1597 /* -> move [i..*active_top[ to [0..*active_top-i[ */
1598 for(k = 0, j = i; (j < *active_top); k++,j++)
1599 active[k] = active[j];
1605 void spill_at_intervall(jitdata *jd, struct lifetime *lt )
1607 if (lt->savedvar || code_is_leafmethod(code)) {
1608 _spill_at_intervall(lt, jd->ls->active_sav, &(jd->ls->active_sav_top));
1610 _spill_at_intervall(lt, jd->ls->active_tmp, &(jd->ls->active_tmp_top));
1611 if (lt->reg == -1) { /* no tmp free anymore */
1612 _spill_at_intervall(lt, jd->ls->active_sav,
1613 &(jd->ls->active_sav_top));
1618 void _spill_at_intervall(struct lifetime *lt, struct lifetime **active,
1622 #ifdef USAGE_COUNT_EXACT
1626 if (*active_top == 0) {
1631 i = *active_top - 1;
1632 #if defined(USAGE_COUNT_EXACT)
1633 /* find intervall which ends later or equal than than lt and has the lowest
1634 usagecount lower than lt */
1636 u_min = lt->usagecount;
1637 for (; (i >= 0) && (active[i]->i_end >= lt->i_end); i--) {
1638 if (active[i]->usagecount < u_min) {
1639 u_min = active[i]->usagecount;
1647 # if defined(USAGE_COUNT) && !defined(USAGE_COUNT_EXACT)
1648 if ((active[i]->i_end >= lt->i_end)
1649 && (active[i]->usagecount < lt->usagecount)) {
1650 # else /* "normal" LSRA heuristic */
1651 /* get last intervall from active */
1652 if (active[i]->i_end > lt->i_end) {
1655 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1656 /* Don't spill between one and two word int types */
1657 if ((active[i]->type == TYPE_LNG) != (lt->type == TYPE_LNG))
1660 lt->reg = active[i]->reg;
1664 for (j = i; j < *active_top; j++)
1665 active[j] = active[j + 1];
1667 lsra_add_active(lt, active, active_top);
1673 void lsra_calc_lifetime_length(jitdata *jd) {
1677 struct lifetime *lt;
1678 #if defined(LSRA_DEBUG_VERBOSE) || !defined(LV)
1683 int flags; /* 0 INMEMORY -> ls->lt_mem */
1684 /* 1 INTREG -> ls->lt_int */
1685 /* 2 FLTREG -> ls->lt_flt */
1692 #ifdef LSRA_DEBUG_VERBOSE
1693 if (compileverbose) {
1694 printf("icount_block: ");
1695 for (i=0; i < m->basicblockcount; i++)
1696 printf("(%3i-%3i) ",i, ls->icount_block[i]);
1701 /* extend lifetime over backedges (for the lsra version without exact
1703 now iterate through lifetimes and expand them */
1706 for(lt_index = 0 ;lt_index < ls->lifetimecount; lt_index++) {
1707 if ( ls->lifetime[lt_index].type != -1) { /* used lifetime */
1708 /* remember lt_index in lt_sorted */
1709 ls->lt_used[lifetimecount++] = lt_index;
1710 lt = &(ls->lifetime[lt_index]);
1711 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1712 /* prevent conflicts between lifetimes of type long by increasing
1713 the lifetime by one instruction
1716 with i==l and/or j==k
1717 to resolve this during codegeneration a temporary register
1719 if (lt->type == TYPE_LNG)
1723 /* distribute lifetimes to lt_int, lt_flt and lt_mem */
1729 #if defined(HAS_4BYTE_STACKSLOT) && !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1742 #if defined(__I386__)
1744 * for i386 put all floats in memory
1752 { log_text("Unknown Type\n"); assert(0); }
1756 case 0: /* lt_used[lt_used_index] -> lt_rest */
1757 ls->lt_mem[ ls->lt_mem_count++ ] = lt_index;
1759 case 1: /* l->lifetimes -> lt_int */
1760 ls->lt_int[ ls->lt_int_count++ ] = lt_index;
1762 case 2: /* l->lifetimes -> lt_flt */
1763 ls->lt_flt[ ls->lt_flt_count++ ] = lt_index;
1768 if (lt->i_first_def == INT_MAX) {
1769 #ifdef LSRA_DEBUG_VERBOSE
1770 printf("Warning: var not defined! vi: %i start: %i end: %i\n",
1771 lt->v_index, lt->i_start, lt->i_end);
1773 lt->bb_first_def = 0;
1774 lt->i_first_def = 0;
1777 lt->i_start = lt->i_first_def;
1779 if (lt->i_last_use == -2) {
1780 #ifdef LSRA_DEBUG_VERBOSE
1781 printf("Warning: Var not used! vi: %i start: %i end: %i\n",
1782 lt->v_index, lt->i_start, lt->i_end);
1784 lt->bb_last_use = lt->bb_first_def;
1785 lt->i_last_use = lt->i_first_def;
1788 lt->i_end = lt->i_last_use;
1790 #ifdef LSRA_DEBUG_VERBOSE
1791 if (lt->i_start > lt->i_end)
1792 printf("Warning: last use before first def! vi: %i start: %i end: %i\n", lt->v_index, lt->i_start, lt->i_end);
1796 if ((lt->bb_first_def != lt->bb_last_use) ||
1797 (lt->i_first_def == -1)) {
1798 /* Lifetime goes over more than one Basic Block -> */
1799 /* check for necessary extension over backedges */
1800 /* see lsra_get_backedges */
1801 /* Arguments are set "before" Block 0, so they have */
1802 /* a lifespan of more then one block, too */
1804 for (i=0; i < ls->backedge_count; i++) {
1805 if (!( (lt->bb_first_def > ls->backedge[i]->start) ||
1806 (lt->bb_last_use < ls->backedge[i]->end) )) {
1807 /* Live intervall intersects with a backedge */
1808 /* if (lt->bb_first_def <= ls->backedge[i]->start) */
1809 if (lt->bb_last_use <= ls->backedge[i]->start)
1811 ls->icount_block[ls->backedge[i]->start] +
1812 m->basicblocks[ls->sorted[ls->backedge[i]->start]].icount;
1816 #endif /* !defined(LV) */
1818 #ifdef USAGE_PER_INSTR
1819 lt->usagecount = lt->usagecount / ( lt->i_end - lt->i_start + 1);
1823 ls->lifetimecount = lifetimecount;
1826 #ifdef LSRA_DEBUG_VERBOSE
1827 void print_lifetimes(jitdata *jd, int *lt, int lifetimecount)
1831 int type,flags,regoff,varkind;
1839 for (lt_index = 0; lt_index < lifetimecount; lt_index++) {
1840 n = &(ls->lifetime[lt[lt_index]]);
1841 if (n->savedvar == SAVEDVAR)
1845 if (n->v_index < 0) { /* stackslot */
1846 type = n->local_ss->s->type;
1847 flags=n->local_ss->s->flags;
1848 regoff=n->local_ss->s->regoff;
1849 varkind=n->local_ss->s->varkind;
1850 } else { /* local var */
1851 if (rd->locals[n->v_index][n->type].type>=0) {
1852 type = rd->locals[n->v_index][n->type].type;
1853 flags=rd->locals[n->v_index][n->type].flags;
1854 regoff=rd->locals[n->v_index][n->type].regoff;
1857 { log_text("Type Data mismatch 3\n"); assert(0); }
1860 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);
1862 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);
1865 printf( "%3i Lifetimes printed \n",lt_index);
1871 /******************************************************************************
1872 Helpers for first LSRA Version without exact Liveness Analysis
1873 *****************************************************************************/
1876 bool lsra_join_ss( struct lsradata *ls, struct stackelement *in,
1877 struct stackelement *out, int join_flag) {
1878 struct lifetime *lt, *lto;
1879 struct stackslot *ss, *ss_last;
1882 if (in->varnum != out->varnum) {
1883 lt = &(ls->lifetime[-in->varnum - 1]);
1885 #ifdef LSRA_DEBUG_CHECK
1886 if (join_flag == JOIN_BB)
1887 if (lt->type == -1) {
1888 log_text("lsra_join_ss: lifetime for instack not found\n");
1893 if (out->varnum >= 0) { /* no lifetime for this slot till now */
1894 lsra_add_ss(lt, out);
1896 lto = &(ls->lifetime[-out->varnum - 1]);
1897 if ((join_flag == JOIN_DUP) || (join_flag == JOIN_OP))
1898 if ( (lt->flags & JOIN_BB) || (lto->flags & JOIN_BB)) {
1901 if (join_flag == JOIN_DUP)
1902 if ( (lt->flags & JOIN_OP) || (lto->flags & JOIN_OP)) {
1905 #ifdef LSRA_DEBUG_CHECK
1906 if (lto->type == -1) {
1907 log_text("lsra_join_ss: lifetime for outstack not found\n");
1911 #ifdef LSRA_DEBUG_CHECK
1912 if (lto->type != lt->type) {
1913 log_text("lsra_join_ss: in/out stack type mismatch\n");
1918 lt->flags |= JOINING;
1920 /* take Lifetime lto out of ls->lifetimes */
1923 /* merge lto into lt of in */
1925 ss_last = ss = lto->local_ss;
1926 while (ss != NULL) {
1928 ss->s->varnum = lt->v_index;
1931 if (ss_last != NULL) {
1932 ss_last->next = lt->local_ss;
1933 lt->local_ss = lto->local_ss;
1936 lt->savedvar |= lto->savedvar;
1937 lt->flags |= lto->flags | join_flag;
1938 lt->usagecount += lto->usagecount;
1940 /*join of i_first_def and i_last_use */
1941 if (lto->i_first_def < lt->i_first_def) {
1942 lt->i_first_def = lto->i_first_def;
1944 if (lto->i_last_use > lt->i_last_use) {
1945 lt->i_last_use = lto->i_last_use;
1952 /* join instack of Basic Block b_index with outstack of predecessors */
1953 void lsra_join_lifetimes(jitdata *jd,int b_index) {
1956 struct stackelement *in, *i, *out;
1962 /* do not join instack of Exception Handler */
1963 if (m->basicblocks[b_index].type == BBTYPE_EXH)
1965 in=m->basicblocks[b_index].instack;
1966 /* do not join first instack element of a subroutine header */
1967 if (m->basicblocks[b_index].type == BBTYPE_SBR)
1971 for (pred = ls->pred[b_index]; pred != NULL; pred = pred->next) {
1972 out = m->basicblocks[pred->value].outstack;
1973 for (i=in; (i != NULL); i = i->prev, out=out->prev) {
1974 lsra_join_ss(ls, i, out, JOIN_BB);
1980 struct stackslot *lsra_make_ss(stackelement_t* s, int bb_index)
1982 struct stackslot *ss;
1984 ss = DNEW(struct stackslot);
1990 void lsra_add_ss(struct lifetime *lt, stackelement_t* s) {
1991 struct stackslot *ss;
1993 /* Stackslot not in list? */
1994 if (s->varnum != lt->v_index) {
1995 ss = DNEW(struct stackslot);
1997 ss->s->varnum = lt->v_index;
1998 ss->next = lt->local_ss;
2001 lt->savedvar |= s->flags & SAVEDVAR;
2007 struct lifetime *get_ss_lifetime(lsradata *ls, stackelement_t* s) {
2010 if (s->varnum >= 0) { /* new stackslot lifetime */
2011 #ifdef LSRA_DEBUG_CHECK_VERBOSE
2012 if (-ls->v_index - 1 >= ls->maxlifetimes) {
2013 printf("%i %i\n", -ls->v_index - 1, ls->maxlifetimes);
2016 _LSRA_ASSERT(-ls->v_index - 1 < ls->maxlifetimes);
2018 n = &(ls->lifetime[-ls->v_index - 1]);
2020 n->v_index = ls->v_index--;
2023 n->bb_last_use = -1;
2024 n->bb_first_def = -1;
2025 n->i_last_use = -2; /* At -1 param init happens, so -2 is below all
2026 possible instruction indices */
2027 n->i_first_def = INT_MAX;
2032 n = &(ls->lifetime[-s->varnum - 1]);
2038 #define IS_TEMP_VAR(s) (((s)->varkind != ARGVAR) && ((s)->varkind != LOCALVAR))
2040 #define lsra_join_3_stack(ls, dst, src1, src2, join_type) \
2041 if ( IS_TEMP_VAR(dst) ) { \
2043 if ( IS_TEMP_VAR(src1) && ((src1)->type == (dst)->type)) { \
2044 join_ret = lsra_join_ss(ls, dst, src1, join_type); \
2046 if ((!join_ret) && IS_TEMP_VAR(src2) && ((src2)->type == (dst)->type)) { \
2047 lsra_join_ss(ls, dst, src2, join_type); \
2051 #define lsra_join_2_stack(ls, dst, src, join_type) \
2052 if ( IS_TEMP_VAR(dst) ) { \
2053 if ( (IS_TEMP_VAR(src)) && ((src)->type == (dst)->type)) { \
2054 lsra_join_ss(ls, dst, src, join_type); \
2058 #define lsra_join_dup(ls, s1, s2, s3) { \
2059 if (IS_TEMP_VAR(s1)) { \
2061 if (IS_TEMP_VAR(s2)) \
2062 join_ret = lsra_join_ss(ls, s1, s2, JOIN); \
2063 /* undangerous join!*/\
2064 if (IS_TEMP_VAR(s3)) { \
2065 if (join_ret) /* first join succesfull -> second of type */ \
2067 lsra_join_ss(ls, s1, s3, JOIN_DUP); \
2069 lsra_join_ss(ls, s1, s3, JOIN); /* first join did not */ \
2070 /* happen -> second undangerous */ \
2073 if (IS_TEMP_VAR(s2) && IS_TEMP_VAR(s3)) \
2074 lsra_join_ss(ls, s2, s3, JOIN_DUP); \
2077 #define lsra_new_stack(ls, s, block, instr) \
2078 if ((s)->varkind != ARGVAR) _lsra_new_stack(ls, s, block, instr, LSRA_STORE)
2079 void _lsra_new_stack(lsradata *ls, stackelement_t* s, int block, int instr, int store)
2083 if (s->varkind == LOCALVAR) {
2084 lsra_usage_local(ls, s->varnum, s->type, block, instr, LSRA_STORE);
2085 } else /* if (s->varkind != ARGVAR) */ {
2087 n=get_ss_lifetime(ls, s);
2089 if (store == LSRA_BB_IN)
2090 n->flags |= JOIN_BB;
2091 /* remember first def -> overwrite everytime */
2092 n->bb_first_def = ls->sorted_rev[block];
2093 n->i_first_def = ls->icount_block[ls->sorted_rev[block]] + instr;
2095 n->usagecount+=ls->nesting[ls->sorted_rev[block]];
2099 #define lsra_from_stack(ls, s, block, instr) \
2100 if ((s)->varkind != ARGVAR) _lsra_from_stack(ls, s, block, instr, LSRA_LOAD)
2101 #define lsra_pop_from_stack(ls, s, block, instr) \
2102 if ((s)->varkind != ARGVAR) _lsra_from_stack(ls, s, block, instr, LSRA_POP)
2103 void _lsra_from_stack(lsradata *ls, stackelement_t* s, int block, int instr, int store)
2107 if (s->varkind == LOCALVAR) {
2108 lsra_usage_local(ls, s->varnum, s->type, block, instr, LSRA_LOAD);
2109 } else /* if (s->varkind != ARGVAR) */ {
2110 if (s->varkind == STACKVAR )
2111 /* No STACKVARS possible with lsra! */
2112 s->varkind = TEMPVAR;
2114 n=get_ss_lifetime(ls, s);
2116 if (store == LSRA_BB_OUT)
2117 n->flags |= JOIN_BB;
2118 if (n->flags & JOINING)
2119 n->flags &= ~JOINING;
2120 n->usagecount+=ls->nesting[ls->sorted_rev[block]];
2122 /* remember last USE, so only write, if USE Field is undefined (==-1) */
2123 if (n->bb_last_use == -1) {
2124 n->bb_last_use = ls->sorted_rev[block];
2125 n->i_last_use = ls->icount_block[ls->sorted_rev[block]] + instr;
2130 void lsra_usage_local(lsradata *ls, s4 v_index, int type, int block, int instr,
2135 n = &(ls->lifetime[ ls->maxlifetimes + v_index * (TYPE_ADR+1) + type]);
2137 if (n->type == -1) { /* new local lifetime */
2141 n->savedvar = SAVEDVAR;
2145 n->bb_last_use = -1;
2146 n->bb_first_def = -1;
2148 n->i_first_def = INT_MAX;
2150 n->usagecount+=ls->nesting[ls->sorted_rev[block]];
2151 /* add access at (block, instr) to instruction list */
2152 /* remember last USE, so only write, if USE Field is undefined (==-1) */
2153 /* count store as use, too -> defined and not used vars would overwrite */
2155 if (n->bb_last_use == -1) {
2156 n->bb_last_use = ls->sorted_rev[block];
2157 n->i_last_use = ls->icount_block[ls->sorted_rev[block]] + instr;
2159 if (store == LSRA_STORE) {
2160 /* store == LSRA_STORE, remember first def -> overwrite everytime */
2161 n->bb_first_def = ls->sorted_rev[block];
2162 n->i_first_def = ls->icount_block[ls->sorted_rev[block]] + instr;
2166 #ifdef LSRA_DEBUG_VERBOSE
2167 void lsra_dump_stack(stackelement_t* s)
2170 printf("%p(R%3i N%3i K%3i T%3i F%3i) ",(void *)s,s->regoff, s->varnum,
2171 s->varkind, s->type, s->flags);
2179 void lsra_scan_registers_canditates(jitdata *jd, int b_index)
2181 /* methodinfo *lm; */
2182 builtintable_entry *bte;
2187 stackelement_t* src;
2188 stackelement_t* dst;
2190 bool join_ret; /* for lsra_join* Macros */
2197 /* get instruction count for BB and remember the max instruction count */
2199 iindex = m->basicblocks[b_index].icount - 1;
2201 src = m->basicblocks[b_index].instack;
2202 if (m->basicblocks[b_index].type != BBTYPE_STD) {
2203 lsra_new_stack(ls, src, b_index, 0);
2206 for (;src != NULL; src=src->prev) {
2207 /*******************************************************************************
2208 Check this - ? For every incoming Stack Slot a lifetime has to be created ?
2209 *******************************************************************************/
2210 _lsra_new_stack(ls, src, b_index, 0, LSRA_BB_IN);
2212 src = m->basicblocks[b_index].outstack;
2213 for (;src != NULL; src=src->prev) {
2214 _lsra_from_stack(ls, src, b_index, iindex, LSRA_BB_OUT);
2217 /* set iptr to last instruction of BB */
2218 iptr = m->basicblocks[b_index].iinstr + iindex;
2220 for (;iindex >= 0; iindex--, iptr--) {
2222 /* get source and destination Stack for the current instruction */
2223 /* destination stack is available as iptr->dst */
2227 /* source stack is either the destination stack of the previos */
2228 /* instruction, or the basicblock instack for the first instruction */
2230 if (iindex) /* != 0 is > 0 here, since iindex ist always >= 0 */
2233 src=m->basicblocks[b_index].instack;
2241 /* local read (return adress) */
2242 lsra_usage_local(ls, iptr->op1, TYPE_ADR, b_index, iindex,
2246 /* case ICMD_ELSE_ICONST: */
2247 case ICMD_CHECKNULL:
2251 case ICMD_PUTSTATICCONST:
2252 case ICMD_INLINE_START:
2253 case ICMD_INLINE_END:
2254 case ICMD_INLINE_GOTO:
2258 /* local = local+<const> */
2259 lsra_usage_local(ls, iptr->op1, TYPE_INT, b_index, iindex,
2261 lsra_usage_local(ls, iptr->op1, TYPE_INT, b_index, iindex,
2265 /* pop 0 push 1 const: const->stack */
2271 /* new stack slot */
2272 lsra_new_stack(ls, dst, b_index, iindex);
2275 /* pop 0 push 1 load: local->stack */
2281 if (dst->varkind != LOCALVAR) {
2282 /* local->value on stack */
2283 lsra_usage_local(ls, iptr->op1, opcode - ICMD_ILOAD, b_index,
2285 lsra_new_stack(ls, dst, b_index, iindex); /* value->stack */
2286 } else /* if (dst->varnum != iptr->op1) */ {
2287 /* local -> local */
2288 lsra_usage_local(ls, iptr->op1, opcode - ICMD_ILOAD, b_index,
2289 iindex,LSRA_LOAD); /* local->value */
2290 lsra_usage_local(ls, dst->varnum, opcode - ICMD_ILOAD, b_index,
2291 iindex, LSRA_STORE); /* local->value */
2297 /* Stack(arrayref,index)->stack */
2308 lsra_from_stack(ls, src, b_index, iindex);
2309 /* stack->arrayref */
2310 lsra_from_stack(ls, src->prev, b_index, iindex);
2311 /* arrayref[index]->stack */
2312 lsra_new_stack(ls, dst, b_index, iindex);
2316 /* stack(arrayref,index,value)->arrayref[index]=value */
2327 lsra_from_stack(ls, src,b_index, iindex); /* stack -> value */
2328 lsra_from_stack(ls, src->prev, b_index, iindex); /* stack -> index*/
2329 /* stack -> arrayref */
2330 lsra_from_stack(ls, src->prev->prev, b_index, iindex);
2333 /* pop 1 push 0 store: stack -> local */
2339 if (src->varkind != LOCALVAR) {
2340 lsra_from_stack(ls, src, b_index, iindex); /* stack -> value */
2341 lsra_usage_local(ls, iptr->op1, opcode-ICMD_ISTORE, b_index,
2342 iindex, LSRA_STORE); /* local->value */
2343 } else /* if (src->varnum != iptr->op1) */ {
2344 lsra_usage_local(ls, iptr->op1, opcode-ICMD_ISTORE, b_index,
2345 iindex, LSRA_STORE); /* local->value */
2346 lsra_usage_local(ls, src->varnum, opcode-ICMD_ISTORE, b_index,
2347 iindex, LSRA_LOAD); /* local->value */
2352 case ICMD_POP: /* throw away a stackslot */
2353 /* TODO: check if used anyway (DUP...) and change codegen to */
2354 /* ignore this stackslot */
2355 lsra_pop_from_stack(ls, src, b_index, iindex);
2363 case ICMD_ARETURN: /* stack(value) -> [empty] */
2365 case ICMD_ATHROW: /* stack(objref) -> undefined */
2367 case ICMD_PUTSTATIC: /* stack(value) -> static_field */
2368 case ICMD_PUTFIELDCONST:
2370 /* pop 1 push 0 branch */
2371 case ICMD_IFNULL: /* stack(value) -> branch? */
2372 case ICMD_IFNONNULL:
2388 /* pop 1 push 0 table branch */
2389 case ICMD_TABLESWITCH:
2390 case ICMD_LOOKUPSWITCH:
2392 case ICMD_MONITORENTER:
2393 case ICMD_MONITOREXIT:
2394 lsra_from_stack(ls, src, b_index, iindex); /* stack -> value */
2398 case ICMD_POP2: /* throw away 2 stackslots */
2399 /* TODO: check if used anyway (DUP...) and change codegen to */
2400 /* ignore this stackslot */
2401 lsra_pop_from_stack(ls, src, b_index, iindex);
2402 lsra_pop_from_stack(ls, src->prev, b_index, iindex);
2405 /* pop 2 push 0 branch */
2407 case ICMD_IF_ICMPEQ: /* stack (v1,v2) -> branch(v1,v2) */
2408 case ICMD_IF_ICMPNE:
2409 case ICMD_IF_ICMPLT:
2410 case ICMD_IF_ICMPGE:
2411 case ICMD_IF_ICMPGT:
2412 case ICMD_IF_ICMPLE:
2414 case ICMD_IF_LCMPEQ:
2415 case ICMD_IF_LCMPNE:
2416 case ICMD_IF_LCMPLT:
2417 case ICMD_IF_LCMPGE:
2418 case ICMD_IF_LCMPGT:
2419 case ICMD_IF_LCMPLE:
2421 case ICMD_IF_ACMPEQ:
2422 case ICMD_IF_ACMPNE:
2425 case ICMD_PUTFIELD: /* stack(objref,value) -> objref = value */
2427 case ICMD_IASTORECONST:
2428 case ICMD_LASTORECONST:
2429 case ICMD_AASTORECONST:
2430 case ICMD_BASTORECONST:
2431 case ICMD_CASTORECONST:
2432 case ICMD_SASTORECONST:
2433 lsra_from_stack(ls, src, b_index, iindex); /* stack -> value*/
2434 lsra_from_stack(ls, src->prev, b_index, iindex);
2437 /* pop 0 push 1 dup */
2438 case ICMD_DUP: /* src == dst->prev, src -> dst */
2439 /* lsra_from_stack(ls, src,b_index,iindex);*/
2440 lsra_new_stack(ls, dst, b_index, iindex);
2442 #ifdef JOIN_DUP_STACK
2443 /* src is identical to dst->prev */
2444 lsra_join_2_stack(ls, src, dst, JOIN_DUP);
2448 /* pop 0 push 2 dup */
2450 /* lsra_from_stack(ls, src,b_index, iindex); */
2451 /* lsra_from_stack(ls, src->prev, b_index, iindex); */
2452 lsra_new_stack(ls, dst->prev, b_index, iindex);
2453 lsra_new_stack(ls, dst, b_index, iindex);
2455 #ifdef JOIN_DUP_STACK
2456 lsra_join_2_stack(ls, src, dst, JOIN_DUP);
2457 lsra_join_2_stack(ls, src->prev, dst->prev, JOIN_DUP);
2458 /* src is identical to dst->prev->prev */
2459 /* src->prev is identical to dst->prev->prev->prev */
2463 /* pop 2 push 3 dup */
2465 lsra_from_stack(ls, src, b_index, iindex+1);
2466 lsra_from_stack(ls, src->prev, b_index, iindex+1);
2467 lsra_new_stack(ls, dst->prev->prev, b_index, iindex);
2468 lsra_new_stack(ls, dst->prev, b_index, iindex);
2469 lsra_new_stack(ls, dst, b_index, iindex);
2470 #ifdef JOIN_DUP_STACK
2471 lsra_join_dup(ls, src, dst, dst->prev->prev);
2472 lsra_join_2_stack(ls, src->prev, dst->prev, JOIN);
2476 /* pop 3 push 4 dup */
2478 lsra_from_stack(ls, src,b_index, iindex+1);
2479 lsra_from_stack(ls, src->prev, b_index, iindex+1);
2480 lsra_from_stack(ls, src->prev->prev, b_index, iindex+1);
2481 lsra_new_stack(ls, dst->prev->prev->prev, b_index, iindex);
2482 lsra_new_stack(ls, dst->prev->prev, b_index, iindex);
2483 lsra_new_stack(ls, dst->prev, b_index, iindex);
2484 lsra_new_stack(ls, dst, b_index, iindex);
2486 #ifdef JOIN_DUP_STACK
2487 lsra_join_dup(ls, src, dst, dst->prev->prev->prev);
2488 lsra_join_2_stack(ls, src->prev, dst->prev, JOIN);
2489 lsra_join_2_stack(ls, src->prev->prev, dst->prev->prev, JOIN);
2493 /* pop 3 push 5 dup */
2495 lsra_from_stack(ls, src, b_index, iindex+1);
2496 lsra_from_stack(ls, src->prev, b_index, iindex+1);
2497 lsra_from_stack(ls, src->prev->prev, b_index, iindex+1);
2498 lsra_new_stack(ls, dst->prev->prev->prev->prev, b_index, iindex);
2499 lsra_new_stack(ls, dst->prev->prev->prev, b_index, iindex);
2500 lsra_new_stack(ls, dst->prev->prev, b_index, iindex);
2501 lsra_new_stack(ls, dst->prev, b_index, iindex);
2502 lsra_new_stack(ls, dst, b_index, iindex);
2504 #ifdef JOIN_DUP_STACK
2505 lsra_join_dup(ls, src, dst, dst->prev->prev->prev);
2506 lsra_join_dup(ls, src->prev, dst->prev,
2507 dst->prev->prev->prev->prev);
2508 lsra_join_2_stack(ls, src->prev->prev, dst->prev->prev, JOIN);
2512 /* pop 4 push 6 dup */
2514 lsra_from_stack(ls, src, b_index, iindex+1);
2515 lsra_from_stack(ls, src->prev, b_index, iindex+1);
2516 lsra_from_stack(ls, src->prev->prev, b_index, iindex+1);
2517 lsra_from_stack(ls, src->prev->prev->prev, b_index, iindex+1);
2518 lsra_new_stack(ls, dst->prev->prev->prev->prev->prev, b_index,
2520 lsra_new_stack(ls, dst->prev->prev->prev->prev, b_index, iindex);
2521 lsra_new_stack(ls, dst->prev->prev->prev, b_index, iindex);
2522 lsra_new_stack(ls, dst->prev->prev, b_index, iindex);
2523 lsra_new_stack(ls, dst->prev, b_index, iindex);
2524 lsra_new_stack(ls, dst, b_index, iindex);
2526 #ifdef JOIN_DUP_STACK
2527 lsra_join_dup(ls, src, dst, dst->prev->prev->prev->prev);
2528 lsra_join_dup(ls, src->prev, dst->prev,
2529 dst->prev->prev->prev->prev->prev);
2530 lsra_join_2_stack(ls, src->prev->prev, dst->prev->prev, JOIN);
2531 lsra_join_2_stack(ls, src->prev->prev->prev, dst->prev->prev->prev,
2536 /* pop 2 push 2 swap */
2538 lsra_from_stack(ls, src, b_index, iindex+1);
2539 lsra_from_stack(ls, src->prev, b_index, iindex+1);
2540 lsra_new_stack(ls, dst->prev, b_index, iindex);
2541 lsra_new_stack(ls, dst, b_index, iindex);
2543 lsra_join_2_stack(ls, src->prev, dst, JOIN);
2544 lsra_join_2_stack(ls, src, dst->prev, JOIN);
2582 lsra_from_stack(ls, src, b_index, iindex);
2583 lsra_from_stack(ls, src->prev, b_index, iindex);
2584 lsra_new_stack(ls, dst, b_index, iindex);
2585 #ifdef JOIN_DEST_STACK
2586 lsra_join_3_stack(ls, dst, src->prev, src, JOIN_OP);
2591 lsra_from_stack(ls, src, b_index, iindex);
2592 lsra_from_stack(ls, src->prev,b_index,iindex);
2593 lsra_new_stack(ls, dst, b_index, iindex);
2594 #ifdef JOIN_DEST_STACK
2595 lsra_join_2_stack(ls, src, dst, JOIN_OP);
2613 lsra_from_stack(ls, src, b_index, iindex);
2614 lsra_from_stack(ls, src->prev, b_index, iindex);
2615 lsra_new_stack(ls, dst, b_index, iindex);
2619 case ICMD_LADDCONST:
2620 case ICMD_LSUBCONST:
2621 case ICMD_LMULCONST:
2625 case ICMD_LANDCONST:
2627 case ICMD_LXORCONST:
2628 case ICMD_LSHLCONST:
2629 case ICMD_LSHRCONST:
2630 case ICMD_LUSHRCONST:
2632 case ICMD_IADDCONST:
2633 case ICMD_ISUBCONST:
2634 case ICMD_IMULCONST:
2638 case ICMD_IANDCONST:
2640 case ICMD_IXORCONST:
2641 case ICMD_ISHLCONST:
2642 case ICMD_ISHRCONST:
2643 case ICMD_IUSHRCONST:
2645 /* case ICMD_IFEQ_ICONST: */
2646 /* case ICMD_IFNE_ICONST: */
2647 /* case ICMD_IFLT_ICONST: */
2648 /* case ICMD_IFGE_ICONST: */
2649 /* case ICMD_IFGT_ICONST: */
2650 /* case ICMD_IFLE_ICONST: */
2655 case ICMD_INT2SHORT:
2673 case ICMD_CHECKCAST:
2674 lsra_from_stack(ls, src, b_index, iindex);
2675 lsra_new_stack(ls, dst, b_index, iindex);
2676 #ifdef JOIN_DEST_STACK
2677 lsra_join_2_stack(ls, src, dst, JOIN_OP);
2681 /* TODO: check if for these ICMDs JOIN_DEST_STACK works, too! */
2682 case ICMD_ARRAYLENGTH:
2683 case ICMD_INSTANCEOF:
2686 case ICMD_ANEWARRAY:
2689 lsra_from_stack(ls, src, b_index, iindex);
2690 lsra_new_stack(ls, dst, b_index, iindex);
2694 case ICMD_GETSTATIC:
2697 lsra_new_stack(ls, dst, b_index, iindex);
2700 /* pop many push any */
2702 case ICMD_INVOKESTATIC:
2703 case ICMD_INVOKESPECIAL:
2704 case ICMD_INVOKEVIRTUAL:
2705 case ICMD_INVOKEINTERFACE:
2706 INSTRUCTION_GET_METHODDESC(iptr,md);
2709 lsra_from_stack(ls, src, b_index, iindex);
2712 if (md->returntype.type != TYPE_VOID)
2713 lsra_new_stack(ls, dst, b_index, iindex);
2722 lsra_from_stack(ls, src, b_index, iindex);
2725 if (md->returntype.type != TYPE_VOID)
2726 lsra_new_stack(ls, dst, b_index, iindex);
2729 case ICMD_MULTIANEWARRAY:
2732 lsra_from_stack(ls, src, b_index, iindex);
2735 lsra_new_stack(ls, dst, b_index, iindex);
2739 exceptions_throw_internalerror("Unknown ICMD %d during register allocation",
2745 #endif /* defined(LV) */
2749 * These are local overrides for various environment variables in Emacs.
2750 * Please do not remove this and leave it at the end of the file, where
2751 * Emacs will automagically detect them.
2752 * ---------------------------------------------------------------------
2755 * indent-tabs-mode: t
2759 * vim:noexpandtab:sw=4:ts=4: