1 /* src/vm/jit/allocator/lsra.c - linear scan register allocator
3 Copyright (C) 2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
40 #include "mm/memory.h"
41 #include "toolbox/logging.h"
42 #include "vm/builtin.h"
43 #include "vm/exceptions.h"
44 #include "vm/resolve.h"
45 #include "vm/options.h"
46 #include "vm/statistics.h"
47 #include "vm/stringlocal.h"
48 #include "vm/jit/abi.h"
49 #include "vm/jit/reg.h"
50 #include "vm/jit/allocator/liveness.h"
51 #include "vm/jit/allocator/lsra.h"
54 extern char **prof_m_names;
55 extern u4 **prof_bb_freq;
59 /* function prototypes */
60 void lsra_init(jitdata *);
61 void lsra_setup(jitdata *);
62 void lsra_main(jitdata *);
64 void lsra_reg_setup(jitdata *, struct lsra_register *, struct lsra_register * );
65 void lsra_calc_lifetime_length(jitdata *);
66 void _lsra_main( jitdata *, int *, int, struct lsra_register *, int *);
67 void lsra_expire_old_intervalls(jitdata *, struct lifetime *,
68 struct lsra_register *);
69 void spill_at_intervall(jitdata *, struct lifetime *);
70 void lsra_add_active(struct lifetime *, struct lifetime **, int *);
71 void _lsra_expire_old_intervalls(jitdata *, struct lifetime *,
72 struct lsra_register *, struct lifetime **,
74 void _spill_at_intervall(struct lifetime *, struct lifetime **, int *);
76 void lsra_alloc(jitdata *, int *, int, int *);
77 int lsra_getmem(struct lifetime *, struct freemem *, int *);
78 struct freemem *lsra_getnewmem(int *);
79 void lsra_setflags(int *, int);
81 #ifdef LSRA_DEBUG_VERBOSE
82 void lsra_dump_stack(stackptr );
83 void print_lifetimes(jitdata *, int *, int);
87 void lsra_scan_registers_canditates(jitdata *, int);
88 void lsra_join_lifetimes(jitdata *, int);
90 void _lsra_new_stack( lsradata *, stackptr , int , int, int);
91 void _lsra_from_stack(lsradata *, stackptr , int , int, int);
92 void lsra_add_ss(struct lifetime *, stackptr );
93 void lsra_usage_local(lsradata *, s4 , int , int , int , int );
98 bool lsra(jitdata *jd)
100 #if defined(ENABLE_STATISTICS)
105 #if defined(LSRA_DEBUG_CHECK)
112 #if defined(LSRA_DEBUG_CHECK)
115 while (b_index < m->basicblockcount ) {
117 if (m->basicblocks[b_index].flags >= BBREACHED) {
119 in=m->basicblocks[b_index].instack;
120 ind=m->basicblocks[b_index].indepth;
121 for (;ind != 0;in=in->prev, ind--) {
122 /* ARGVAR or LOCALVAR in instack is ok*/
124 if (in->varkind == ARGVAR) printf("ARGVAR in instack: \n");
125 if (in->varkind == LOCALVAR) printf("LOCALVAR in instack\n");
128 out=m->basicblocks[b_index].outstack;
129 outd=m->basicblocks[b_index].outdepth;
130 for (;outd != 0;out=out->prev, outd--) {
131 if (out->varkind == ARGVAR)
132 { log_text("ARGVAR in outstack\n"); assert(0); }
133 if (out->varkind == LOCALVAR)
134 { log_text("LOCALVAR in outstack\n"); assert(0); }
141 jd->ls = DNEW(lsradata);
145 #if defined(ENABLE_STATISTICS)
146 /* find conflicts between locals for statistics */
149 /* local Variable Lifetimes are at the end of the lifetime array and */
150 /* have v_index >= 0 */
151 for (locals_start = ls->lifetimecount-1; (locals_start >=0) &&
152 (ls->lifetime[ls->lt_used[locals_start]].v_index >= 0);
154 for (i=locals_start + 1; i < ls->lifetimecount; i++)
155 for (j=i+1; j < ls->lifetimecount; j++)
156 if ( !((ls->lifetime[ls->lt_used[i]].i_end
157 < ls->lifetime[ls->lt_used[j]].i_start)
158 || (ls->lifetime[ls->lt_used[j]].i_end <
159 ls->lifetime[ls->lt_used[i]].i_start)) )
160 count_locals_conflicts += 2;
166 /* everything's ok */
171 /* sort Basic Blocks using Depth First Search in reverse post order in */
173 void lsra_DFS(jitdata *jd) {
187 stack = DMNEW( int, m->basicblockcount + 1);
188 visited = (int *)DMNEW( int, m->basicblockcount + 1);
189 for (i = 0; i <= m->basicblockcount; i++) {
192 ls->sorted_rev[i]=-1;
195 stack[0] = 0; /* start with Block 0 */
197 visited[0] = ls->num_pred[0]; /* Start Block is handled right and can be */
201 while (not_finished) {
202 while (stack_top != 0) {
204 i = stack[stack_top];
207 for (succ = ls->succ[i]; succ != NULL; succ = succ->next) {
208 visited[succ->value]++;
209 if (visited[succ->value] == ls->num_pred[succ->value]) {
210 /* push the node on the stack, only if all ancestors have */
212 stack[stack_top] = succ->value;
217 not_finished = false;
218 for (i=1; i <= m->basicblockcount; i++) {
219 /* search for visited blocks, which have not reached the num_pred */
220 /* and put them on the stack -> happens with backedges */
221 if ((visited[i] != 0) && (visited[i] < ls->num_pred[i])) {
222 stack[stack_top] = i;
224 visited[i] = ls->num_pred[i];
232 void lsra_get_backedges_(lsradata *ls, int basicblockcount) {
235 struct _backedge *_backedges;
241 /* now look for backedges */
242 ls->backedge_count = 0;
243 for(i=0; i < basicblockcount; i++) {
244 if (ls->sorted[i] != -1)
245 for(s=ls->succ[ls->sorted[i]]; s != NULL; s=s->next) {
246 if (i >= ls->sorted_rev[s->value]) {
247 n=DNEW(struct _backedge);
248 n->start = max(i, ls->sorted_rev[s->value]);
249 n->end = min(i, ls->sorted_rev[s->value]);
250 n->next = _backedges;
252 ls->backedge_count++;
256 /* put _backedges in ls->backedge array */
257 ls->backedge = DMNEW(struct _backedge *, ls->backedge_count);
258 for (n=_backedges, i=0; n != NULL; n=n->next, i++) {
260 ls->backedge[i]->nesting = 1;
264 void lsra_get_nesting(jitdata *jd) {
273 for (i=0; i <= m->basicblockcount; i++)
274 if (ls->sorted[i] != -1)
275 ls->sorted_rev[ls->sorted[i]]=i;
277 lsra_get_backedges_(ls, m->basicblockcount + 1);
278 /* - sort backedge by increasing end: */
279 for (i=0; i < ls->backedge_count; i++)
280 for (j=i+1; j < ls->backedge_count; j++)
281 if ((ls->backedge[i]->end > ls->backedge[j]->end) || /* -> swap */
282 ((ls->backedge[i]->end == ls->backedge[j]->end) &&
283 (ls->backedge[i]->start > ls->backedge[j]->start) )) {
285 ls->backedge[i]=ls->backedge[j];
289 /* create ls->nesting */
290 /* look for nesting depth (overlapping backedges*/
291 for (i=0; i < ls->backedge_count - 1; i++) {
292 for (j = i + 1; (j < ls->backedge_count) &&
293 (ls->backedge[i]->start >= ls->backedge[j]->end); j++)
294 ls->backedge[j]->nesting += ls->backedge[i]->nesting;
299 while ( (i < m->basicblockcount + 1) ) {
300 if (j < ls->backedge_count) {
301 while ( i < ls->backedge[j]->end ) {
305 if ( (j+1) < ls->backedge_count)
306 end = min(ls->backedge[j]->start, ls->backedge[j+1]->end - 1);
308 end = ls->backedge[j]->start;
310 ls->nesting[i] = ls->backedge[j]->nesting;
320 #ifdef LSRA_DEBUG_VERBOSE
321 if (compileverbose) {
322 printf("sorted: \n");
323 for (i=0; i < ls->backedge_count; i++)
324 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);
325 printf("Nesting Level \n");
326 for (i=0; i<m->basicblockcount; i++) printf(" %3li", ls->nesting[i]);
330 for (i=0; i <= m->basicblockcount; i++) {
331 ls->sorted_rev[i] = -1;
332 ls->nesting[i] = 1+ls->nesting[i]*ls->nesting[i]*10;
336 void lsra_get_backedges(jitdata *jd) {
347 /* first remove artificial end basicblock from ls->sorted, succ and pred */
349 for (i=0; i < m->basicblockcount; i++) {
350 for (next=&(ls->succ[i]); *next != NULL; next=&((*next)->next)) {
351 if ( (*next)->value == m->basicblockcount ) {
352 /* artificial end bb found */
353 *next = (*next)->next;
354 if (*next == NULL) break;
357 for (next=&(ls->pred[i]); *next != NULL; next=&((*next)->next)) {
358 if ( (*next)->value == m->basicblockcount ) {
359 /* artificial end bb found */
360 *next = (*next)->next;
361 if (*next == NULL) break;
365 if (ls->sorted[i] == m->basicblockcount) j=i;
368 /* if an artificial end block was removed -> change ls->sorted accordingly*/
370 for (i=j+1; i <= m->basicblockcount; i++) {
371 ls->sorted[i-1] = ls->sorted[i];
372 ls->nesting[i-1] = ls->nesting[i];
375 for (i=0; i < m->basicblockcount; i++)
376 if (ls->sorted[i] != -1)
377 ls->sorted_rev[ls->sorted[i]]=i;
379 lsra_get_backedges_(ls, m->basicblockcount);
381 /* - sort backedge by increasing start */
382 for (i=0; i < ls->backedge_count; i++)
383 for (j=i+1; j < ls->backedge_count; j++)
384 if (ls->backedge[i]->start > ls->backedge[j]->start) {
387 ls->backedge[i] = ls->backedge[j];
391 #ifdef LSRA_DEBUG_VERBOSE
392 if (compileverbose) {
393 printf("sorted: \n");
394 for (i=0; i < ls->backedge_count; i++)
395 printf("Backedge: %i - %i, %i - %i\n",
396 ls->sorted[ls->backedge[i]->start],
397 ls->sorted[ls->backedge[i]->end], ls->backedge[i]->start,
398 ls->backedge[i]->end);
399 printf("Nesting Level \n");
400 for (i=0; i<m->basicblockcount; i++) printf(" %3li", ls->nesting[i]);
406 /* - merge overlapping backedges */
409 for (i=0; i < ls->backedge_count-1; i++) {
410 if (ls->backedge[i] != NULL) {
411 for (j = i + 1; (j < ls->backedge_count) && (ls->backedge[j] == NULL); j++ );
412 if (j != ls->backedge_count) {
413 if (ls->backedge[i]->start >= ls->backedge[j]->end) {
415 /* overlapping -> merge */
416 ls->backedge[j]->end = min (ls->backedge[j]->end,
417 ls->backedge[i]->end);
418 ls->backedge[i] = NULL;
424 #ifdef LSRA_DEBUG_VERBOSE
425 if (compileverbose) {
426 printf("merged: \n");
427 for (i = 0; i < ls->backedge_count; i++)
428 if (ls->backedge[i] != NULL)
429 printf("Backedge: %i - %i, %i - %i\n",
430 ls->sorted[ls->backedge[i]->start],
431 ls->sorted[ls->backedge[i]->end],
432 ls->backedge[i]->start, ls->backedge[i]->end);
435 /* - remove backedge[] == NULL from array */
437 for (j = ls->backedge_count - 1; ((j>=0) && (ls->backedge[j] == NULL));
441 if (ls->backedge[i] == NULL) { /* swap backedge[i] and backedge[j]*/
443 ls->backedge[j] = ls->backedge[i];
447 ls->backedge_count--;
450 #ifdef LSRA_DEBUG_VERBOSE
451 if (compileverbose) {
453 for (i=0; i < ls->backedge_count; i++)
454 printf("Backedge: %i - %i, %i - %i\n",
455 ls->sorted[ls->backedge[i]->start],
456 ls->sorted[ls->backedge[i]->end],ls->backedge[i]->start,
457 ls->backedge[i]->end);
462 void lsra_add_cfg(jitdata *jd, int from, int to) {
470 /* ignore Empty, Deleted,... Basic Blocks as target */
471 /* TODO: Setup BasicBlock array before to avoid this */
472 /* best together with using the basicblock list, so lsra works */
473 /* with opt_loops, too */
474 for (;(to < m->basicblockcount) && (m->basicblocks[to].flags < BBREACHED); to++);
476 for (n=ls->succ[from]; (n!= NULL) && (n->value != to); n=n->next);
477 if (n != NULL) return; /* edge from->to already existing */
479 n=DNEW(struct _list);
482 n->next=ls->succ[from];
485 n=DNEW(struct _list);
487 n->next=ls->pred[to];
492 /* add Edges from guarded Areas to Exception handlers in the CFG */
493 void lsra_add_exceptions(jitdata *jd) {
503 ex = jd->exceptiontable;
505 /* add cfg edges from all bb of a try block to the start of the according */
506 /* exception handler to ensure the right order after depthfirst search */
508 #ifdef LSRA_DEBUG_VERBOSE
510 printf("ExTable(%i): ", jd->exceptiontablelength);
513 for (; ex != NULL; ex = ex->down) {
515 #ifdef LSRA_DEBUG_VERBOSE
516 if (compileverbose) {
517 printf("[%i-%i]->%i ",ex->start->nr, ex->end->nr,
519 if (ex->handler->nr >= m->basicblockcount) {
520 log_text("Exceptionhandler Basicblocknummer invalid\n");
523 if (m->basicblocks[ex->handler->nr].flags < BBREACHED) {
524 log_text("Exceptionhandler Basicblocknummer not reachable\n");
527 if (ex->start->nr > ex->end->nr) {
528 log_text("Guarded Area starts after its end\n");
533 /* loop all valid Basic Blocks of the guarded area and add CFG edges */
534 /* to the appropriate handler */
535 for (i=ex->start->nr; (i <= ex->end->nr) &&
536 (i < m->basicblockcount); i++)
537 if (m->basicblocks[i].flags >= BBREACHED)
538 lsra_add_cfg(jd, i, ex->handler->nr);
540 #ifdef LSRA_DEBUG_VERBOSE
541 if (compileverbose) {
547 void lsra_add_jsr(jitdata *jd, int from, int to) {
550 struct _sbr *sbr, *n;
556 /* ignore Empty, Deleted,... Basic Blocks as target */
557 /* TODO: Setup BasicBlock array before to avoid this */
558 /* best together with using the basicblock list, so lsra works */
559 /* with opt_loops, too */
560 for (; (to < m->basicblockcount) && (m->basicblocks[to].flags < BBREACHED);
562 #ifdef LSRA_DEBUG_CHECK
563 if (to == m->basicblockcount)
564 { log_text("Invalid subroutine start index\n"); assert(0); }
567 lsra_add_cfg(jd, from, to);
569 /* from + 1 ist the return Basic Block Index */
570 for (from++; (from < m->basicblockcount) &&
571 (m->basicblocks[from].flags < BBREACHED); from++);
572 #ifdef LSRA_DEBUG_CHECK
573 if (from == m->basicblockcount)
574 { log_text("Invalid return basic block index for jsr\n"); assert(0); }
577 /* add subroutine info in ls->sbr.next */
579 /* search for right place to insert */
580 for (sbr = &(ls->sbr); (sbr->next != NULL) && (sbr->next->header < to); sbr=sbr->next);
582 if ((sbr->next!= NULL) && (sbr->next->header == to)) {
583 /* Entry for this sub already exist */
586 /* make new Entry and insert it in ls->sbr.next */
587 n = DNEW( struct _sbr );
597 /* now insert return adress in sbr->ret */
598 ret = DNEW( struct _list);
600 ret->next = sbr->ret;
604 void lsra_add_sub( jitdata *jd, int b_index, struct _list *ret,
616 /* break at virtual End Block */
617 if (b_index != m->basicblockcount) {
618 visited[b_index] = true;
621 if (m->basicblocks[b_index].flags < BBREACHED)
623 if (!next_block && !(m->basicblocks[b_index].icount))
627 ip = m->basicblocks[b_index].iinstr
628 + m->basicblocks[b_index].icount -1;
630 if (ip->opc == ICMD_JSR) /* nested Subroutines */
635 if (ip->opc == ICMD_RET) {
636 /* subroutine return found -> add return adresses to CFG */
637 for (l = ret; l != NULL; l = l->next)
638 lsra_add_cfg(jd, b_index, l->value);
639 } else { /* follow CFG */
640 for ( l = ls->succ[b_index]; l != NULL; l = l->next)
641 if (!visited[l->value])
642 lsra_add_sub(jd, l->value, ret, visited);
644 } else { /* fall through to next block */
645 if (!visited[b_index + 1])
646 lsra_add_sub(jd, b_index + 1, ret, visited);
651 /* Add subroutines from ls->sbr list to CFG */
652 void lsra_add_subs(jitdata *jd) {
658 #ifdef LSRA_DEBUG_VERBOSE
665 visited = (bool *)DMNEW(int, m->basicblockcount + 1);
666 for (i=0; i <= m->basicblockcount; i++) visited[i] = false;
667 for (sbr = ls->sbr.next; sbr != NULL; sbr=sbr->next) {
669 #ifdef LSRA_DEBUG_VERBOSE
670 if (compileverbose) {
671 printf("Subroutine Header: %3i Return Adresses:",sbr->header);
672 for (ret = sbr->ret; ret != NULL; ret = ret->next)
673 printf(" %3i", ret->value);
677 lsra_add_sub(jd, sbr->header, sbr->ret, visited );
681 /* Generate the Control Flow Graph */
682 /* ( pred,succ,num_pred of lsradata structure) */
684 void lsra_make_cfg(jitdata *jd) {
689 int high, low, count;
696 while (b_index < m->basicblockcount ) {
697 if ((m->basicblocks[b_index].flags >= BBREACHED) &&
698 (len = m->basicblocks[b_index].icount)) {
699 /* block is valid and contains instructions */
701 /* set ip to last instruction */
702 ip = m->basicblocks[b_index].iinstr +
703 m->basicblocks[b_index].icount -1;
704 while ((len>0) && (ip->opc == ICMD_NOP)) {
708 switch (ip->opc) { /* check type of last instruction */
716 lsra_add_cfg(jd, b_index, m->basicblockcount);
717 break; /* function returns -> end of graph */
746 case ICMD_IF_ACMPNE: /* branch -> add next block */
747 lsra_add_cfg(jd, b_index, b_index+1);
748 /* fall throu -> add branch target */
751 lsra_add_cfg(jd, b_index, m->basicblockindex[ip->op1]);
752 break; /* visit branch (goto) target */
754 case ICMD_TABLESWITCH: /* switch statement */
757 lsra_add_cfg(jd, b_index, m->basicblockindex[*s4ptr]);
764 count = (high-low+1);
766 while (--count >= 0) {
768 lsra_add_cfg(jd, b_index,
769 m->basicblockindex[*s4ptr]);
773 case ICMD_LOOKUPSWITCH: /* switch statement */
776 lsra_add_cfg(jd, b_index, m->basicblockindex[*s4ptr]);
781 while (--count >= 0) {
782 lsra_add_cfg(jd, b_index,
783 m->basicblockindex[s4ptr[1]]);
789 lsra_add_jsr(jd, b_index, m->basicblockindex[ip->op1]);
796 lsra_add_cfg(jd, b_index, b_index + 1 );
798 } /* switch (ip->opc)*/
799 } /* if ((m->basicblocks[blockIndex].icount)&& */
800 /* (m->basicblocks[b_index].flags >= BBREACHED)) */
802 } /* while (b_index < m->basicblockcount ) */
805 void lsra_init(jitdata *jd) {
813 /* Init LSRA Data Structures */
814 /* allocate lifetimes for all Basicblocks */
815 /* + 1 for an artificial exit node */
816 /* which is needed as "start" point for the reverse postorder sorting */
817 ls->pred = DMNEW(struct _list *, m->basicblockcount+1);
818 ls->succ = DMNEW(struct _list *, m->basicblockcount+1);
819 ls->sorted = DMNEW(int , m->basicblockcount+1);
820 ls->sorted_rev = DMNEW(int , m->basicblockcount+1);
821 ls->num_pred = DMNEW(int , m->basicblockcount+1);
822 ls->nesting = DMNEW(long , m->basicblockcount+1);
823 for (i=0; i<m->basicblockcount; i++) {
827 ls->sorted_rev[i]=-1;
831 ls->pred[m->basicblockcount]=NULL;
832 ls->succ[m->basicblockcount]=NULL;
833 ls->sorted[m->basicblockcount]=-1;
834 ls->sorted_rev[m->basicblockcount]=-1;
835 ls->num_pred[m->basicblockcount]=0;
842 void lsra_setup(jitdata *jd) {
847 #ifdef LSRA_DEBUG_VERBOSE
864 #if defined(ENABLE_LOOP)
865 /* Loop optimization "destroys" the basicblock array */
866 /* TODO: work with the basicblock list */
868 log_text("lsra not possible with loop optimization\n");
871 #endif /* defined(ENABLE_LOOP) */
873 /* Setup LSRA Data structures */
875 /* Generate the Control Flow Graph */
877 /* gather nesting before adding of Exceptions and Subroutines!!! */
881 lsra_get_nesting(jd);
884 #ifdef LSRA_DEBUG_VERBOSE
885 if (compileverbose) {
886 printf("Successors:\n");
887 for (i=0; i < m->basicblockcount; i++) {
889 for (nl=ls->succ[i]; nl!= NULL; nl=nl->next)
890 printf("%3i ",nl->value);
893 printf("Predecessors:\n");
894 for (i=0; i < m->basicblockcount; i++) {
896 for (nl=ls->pred[i]; nl!= NULL; nl=nl->next)
897 printf("%3i ",nl->value);
901 for (i=0; i < m->basicblockcount; i++) printf("%3i ", ls->sorted[i]);
903 printf("Sorted_rev: ");
904 for (i=0; i < m->basicblockcount; i++) printf("%3i ", ls->sorted_rev[i]);
909 /* add subroutines before exceptions! They "destroy" the CFG */
911 lsra_add_exceptions(jd);
913 /* generate reverse post order sort */
916 /* setup backedge and nested data structures*/
917 lsra_get_backedges(jd);
921 ls->lifetimecount = ls->maxlifetimes + jd->maxlocals * (TYPE_ADR+1);
922 ls->lifetime = DMNEW(struct lifetime, ls->lifetimecount);
923 ls->lt_used = DMNEW(int, ls->lifetimecount);
924 ls->lt_int = DMNEW(int, ls->lifetimecount);
925 ls->lt_int_count = 0;
926 ls->lt_flt = DMNEW(int, ls->lifetimecount);
927 ls->lt_flt_count = 0;
928 ls->lt_mem = DMNEW(int, ls->lifetimecount);
929 ls->lt_mem_count = 0;
931 for (i=0; i < ls->lifetimecount; i++) ls->lifetime[i].type = -1;
933 #ifdef LSRA_DEBUG_VERBOSE
934 if (compileverbose) {
935 printf("Successors:\n");
936 for (i=0; i < m->basicblockcount; i++) {
938 for (nl=ls->succ[i]; nl!= NULL; nl=nl->next)
939 printf("%3i ",nl->value);
942 printf("Predecessors:\n");
943 for (i=0; i < m->basicblockcount; i++) {
945 for (nl=ls->pred[i]; nl!= NULL; nl=nl->next)
946 printf("%3i ",nl->value);
950 for (i=0; i < m->basicblockcount; i++) printf("%3i ", ls->sorted[i]);
952 printf("Sorted_rev: ");
953 for (i=0; i < m->basicblockcount; i++) printf("%3i ", ls->sorted_rev[i]);
959 #ifdef LSRA_DEBUG_CHECK
960 /* compare m->basicblocks[] with the list basicblocks->next */
962 bptr = m->basicblocks;
963 while (bptr != NULL) {
964 if (i > m->basicblockcount){
965 { log_text("linked bb list does not correspond with bb array(1)\n");
968 if (bptr != &(m->basicblocks[i])){
969 { log_text("linked bb list does not correspond with bb array(2)\n");
976 if (i<m->basicblockcount){
977 { log_text("linked bb list does not correspond with bb array(3)\n");
990 methoddesc *md = m->parseddesc;
992 /* Create Stack Slot lifetimes over all basic blocks */
993 for (i=m->basicblockcount-1; i >= 0; i--) {
994 if (ls->sorted[i] != -1) {
995 lsra_scan_registers_canditates(jd, ls->sorted[i]);
996 lsra_join_lifetimes(jd, ls->sorted[i]);
1000 /* Parameter initialisiation for locals [0 .. paramcount[ */
1001 /* -> add local var write access at (bb=0,iindex=-1) */
1002 /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
1003 /* this needs a special treatment, wenn lifetimes get extended */
1004 /* over backedges, since this parameter initialisation happens */
1005 /* outside of Basic Block 0 !!!! */
1006 /* this could have been avoided by marking the read access with -1,0 */
1008 for (p = 0, i = 0; p < md->paramcount; p++) {
1009 t = md->paramtypes[p].type;
1011 if (rd->locals[i][t].type >= 0)
1012 /* Param to Local init happens before normal Code */
1013 lsra_usage_local(ls, i, t, 0, -1, LSRA_STORE);
1015 /* increment local counter a second time */
1016 /* for 2 word types */
1017 if (IS_2_WORD_TYPE(t))
1023 lsra_calc_lifetime_length(jd);
1025 #ifdef LSRA_DEBUG_VERBOSE
1027 printf("Basicblockcount: %4i\n",m->basicblockcount);
1032 void lsra_reg_setup(jitdata *jd, struct lsra_register *int_reg,
1033 struct lsra_register *flt_reg ) {
1034 int i, j, iarg, farg;
1037 bool *fltarg_used, *intarg_used;
1046 int_reg->nregdesc = nregdescint;
1047 flt_reg->nregdesc = nregdescfloat;
1048 if (code_is_leafmethod(code)) {
1049 /* Temp and Argumentregister can be used as saved registers */
1051 int_reg->sav_top = INT_ARG_CNT + INT_TMP_CNT + INT_SAV_CNT;
1052 int_reg->sav_reg = DMNEW(int, int_reg->sav_top);
1053 int_reg->tmp_reg = NULL;
1054 int_reg->tmp_top = -1;
1055 flt_reg->sav_top = FLT_ARG_CNT + FLT_TMP_CNT + FLT_SAV_CNT;
1056 flt_reg->sav_reg = DMNEW(int, flt_reg->sav_top);
1057 flt_reg->tmp_reg = NULL;
1058 flt_reg->tmp_top = -1;
1060 /* additionaly precolour registers for Local Variables acting as */
1066 intarg_used = DMNEW(bool, INT_ARG_CNT);
1067 for (i=0; i < INT_ARG_CNT; i++)
1068 intarg_used[i]=false;
1070 fltarg_used = DMNEW(bool, FLT_ARG_CNT);
1071 for (i=0; i < FLT_ARG_CNT; i++)
1072 fltarg_used[i]=false;
1074 int_sav_top=int_reg->sav_top;
1075 flt_sav_top=flt_reg->sav_top;
1077 for (i=0; (i < md->paramcount); i++) {
1078 if (!md->params[i].inmemory) {
1079 if (IS_INT_LNG_TYPE(md->paramtypes[i].type)) {
1080 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1081 if (IS_2_WORD_TYPE(md->paramtypes[i].type)) {
1082 int_reg->sav_reg[--int_sav_top] =
1083 rd->argintregs[GET_HIGH_REG(md->params[i].regoff)];
1084 intarg_used[GET_HIGH_REG(md->params[i].regoff)]=true;
1085 /*used -> don't copy later on */
1086 int_reg->sav_reg[--int_sav_top] =
1087 rd->argintregs[GET_LOW_REG(md->params[i].regoff)];
1088 intarg_used[GET_LOW_REG(md->params[i].regoff)]=true;
1089 /*used -> don't copy later on */
1092 { /* !IS_2_WORD_TYPE(md->paramtypes[i].type */
1093 int_reg->sav_reg[--int_sav_top] =
1094 rd->argintregs[md->params[i].regoff];
1095 intarg_used[md->params[i].regoff]=true;
1096 /*used -> don't copy later on */
1099 #if !defined(SUPPORT_PASS_FLOATARGS_IN_INTREGS)
1100 /* do not precolour float arguments if they are passed in */
1101 /* integer registers. But these integer argument registers */
1102 /* still be used in the method! */
1103 else { /* IS_FLT_DBL_TYPE(md->paramtypes[i].type */
1104 flt_reg->sav_reg[--flt_sav_top] =
1105 rd->argfltregs[md->params[i].regoff];
1106 fltarg_used[md->params[i].regoff]=true;
1113 /* copy rest of argument registers to flt_reg->sav_reg and */
1114 /* int_reg->sav_reg; */
1115 for (i=0; i < INT_ARG_CNT; i++)
1116 if (!intarg_used[i])
1117 int_reg->sav_reg[--int_sav_top]=rd->argintregs[i];
1118 for (i=0; i < FLT_ARG_CNT; i++)
1119 if (!fltarg_used[i])
1120 flt_reg->sav_reg[--flt_sav_top]=rd->argfltregs[i];
1122 /* copy temp registers to flt_reg->sav_reg and int_reg->sav_reg */
1123 for (i=0; i < INT_TMP_CNT; i++)
1124 int_reg->sav_reg[--int_sav_top]=rd->tmpintregs[i];
1125 for (i=0; i < FLT_TMP_CNT; i++)
1126 flt_reg->sav_reg[--flt_sav_top]=rd->tmpfltregs[i];
1129 /* non leaf method -> use Argument Registers [arg[int|flt]reguse */
1130 /* ... [INT|FLT]_ARG_CNT[ as temp reg */
1131 /* divide temp and saved registers */
1132 int argintreguse, argfltreguse;
1134 /* with Locals as non SAVEDVAR, the used arg[int|flt] as in params */
1135 /* of the method itself have to be regarded, or mismatch before */
1136 /* block 0 with parameter copy could happen! */
1137 argintreguse = max(rd->argintreguse, md->argintreguse);
1138 argfltreguse = max(rd->argfltreguse, md->argfltreguse);
1140 argintreguse = rd->argintreguse;
1141 argfltreguse = rd->argfltreguse;
1143 int_sav_top = int_reg->sav_top = INT_SAV_CNT;
1144 int_reg->sav_reg = DMNEW(int, int_reg->sav_top);
1145 int_reg->tmp_top = INT_TMP_CNT +
1146 max(0, (INT_ARG_CNT - argintreguse));
1147 int_reg->tmp_reg = DMNEW(int, int_reg->tmp_top);
1149 flt_sav_top =flt_reg->sav_top = FLT_SAV_CNT;
1150 flt_reg->sav_reg = DMNEW(int, flt_reg->sav_top);
1151 flt_reg->tmp_top = FLT_TMP_CNT +
1152 max(0 , (FLT_ARG_CNT - argfltreguse));
1153 flt_reg->tmp_reg = DMNEW(int, flt_reg->tmp_top);
1155 /* copy temp and unused argument registers to flt_reg->tmp_reg and */
1156 /* int_reg->tmp_reg */
1157 for (i=0; i < INT_TMP_CNT; i++)
1158 int_reg->tmp_reg[i]=rd->tmpintregs[i];
1159 for (j=argintreguse; j < INT_ARG_CNT; j++, i++)
1160 int_reg->tmp_reg[i]=rd->argintregs[j];
1161 for (i=0; i < FLT_TMP_CNT; i++)
1162 flt_reg->tmp_reg[i]=rd->tmpfltregs[i];
1163 for (j=argfltreguse; j < FLT_ARG_CNT; j++, i++)
1164 flt_reg->tmp_reg[i]=rd->argfltregs[j];
1167 /* now copy saved registers to flt_reg->sav_reg and int_reg->sav_reg */
1168 for (i = INT_SAV_CNT-1; i >= 0; i--)
1169 int_reg->sav_reg[--int_sav_top]=rd->savintregs[i];
1170 for (i = FLT_SAV_CNT-1; i >= 0; i--)
1171 flt_reg->sav_reg[--flt_sav_top]=rd->savfltregs[i];
1175 void lsra_insertion_sort( struct lsradata *ls, int *a, int lo, int hi) {
1178 for (i=lo+1; i<=hi; i++) {
1180 t=ls->lifetime[a[j]].i_start;
1182 while ((j>lo) && (ls->lifetime[a[j-1]].i_start > t)) {
1190 void lsra_qsort( struct lsradata *ls, int *a, int lo, int hi) {
1196 x = ls->lifetime[a[(lo+hi)/2]].i_start;
1199 while (ls->lifetime[a[i]].i_start < x) i++;
1200 while (ls->lifetime[a[j]].i_start > x) j--;
1202 /* exchange a[i], a[j] */
1212 if (lo < j) lsra_qsort( ls, a, lo, j);
1213 if (i < hi) lsra_qsort( ls, a, i, hi);
1215 lsra_insertion_sort(ls, a, lo, hi);
1219 void lsra_param_sort(struct lsradata *ls, int *lifetime, int lifetime_count) {
1224 /* count number of parameters ( .i_start == -1) */
1225 for (param_count=0; (param_count < lifetime_count) &&
1226 (ls->lifetime[lifetime[param_count]].i_start == -1); param_count++);
1228 if (param_count > 0) {
1229 /* now sort the parameters by v_index */
1230 for (i=0; i < param_count -1; i++)
1231 for (j=i+1; j < param_count; j++)
1232 if ( ls->lifetime[lifetime[i]].v_index >
1233 ls->lifetime[lifetime[j]].v_index) {
1236 lifetime[i]=lifetime[j];
1242 void lsra_main(jitdata *jd) {
1243 #ifdef LSRA_DEBUG_VERBOSE
1248 struct lsra_register flt_reg, int_reg;
1251 #if defined(__I386__)
1259 /* sort lifetimes by increasing start */
1260 lsra_qsort( ls, ls->lt_mem, 0, ls->lt_mem_count - 1);
1261 lsra_qsort( ls, ls->lt_int, 0, ls->lt_int_count - 1);
1262 lsra_qsort( ls, ls->lt_flt, 0, ls->lt_flt_count - 1);
1263 /* sort local vars used as parameter */
1264 lsra_param_sort( ls, ls->lt_int, ls->lt_int_count);
1265 lsra_param_sort( ls, ls->lt_flt, ls->lt_flt_count);
1266 lsra_reg_setup(jd, &int_reg, &flt_reg);
1268 #ifdef LSRA_DEBUG_VERBOSE
1269 if (compileverbose) {
1270 printf("INTSAV REG: ");
1271 for (i=0; i<int_reg.sav_top; i++)
1272 printf("%2i ",int_reg.sav_reg[i]);
1273 printf("\nINTTMP REG: ");
1274 for (i=0; i<int_reg.tmp_top; i++)
1275 printf("%2i ",int_reg.tmp_reg[i]);
1276 printf("\nFLTSAV REG: ");
1277 for (i=0; i<flt_reg.sav_top; i++)
1278 printf("%2i ",flt_reg.sav_reg[i]);
1279 printf("\nFLTTMP REG: ");
1280 for (i=0; i<flt_reg.tmp_top; i++)
1281 printf("%2i ",flt_reg.tmp_reg[i]);
1285 ls->active_tmp = DMNEW( struct lifetime *, max(INT_REG_CNT, FLT_REG_CNT));
1286 ls->active_sav = DMNEW( struct lifetime *, max(INT_REG_CNT, FLT_REG_CNT));
1288 lsra_reg_use=INT_SAV_CNT; /* init to no saved reg used... */
1289 _lsra_main(jd, ls->lt_int, ls->lt_int_count, &int_reg, &lsra_reg_use);
1290 if (lsra_reg_use > INT_SAV_CNT)
1291 lsra_reg_use=INT_SAV_CNT;
1292 rd->savintreguse = lsra_reg_use;
1294 lsra_reg_use = FLT_SAV_CNT; /* no saved reg used... */
1295 _lsra_main(jd, ls->lt_flt, ls->lt_flt_count, &flt_reg, &lsra_reg_use);
1296 if (lsra_reg_use > FLT_SAV_CNT)
1297 lsra_reg_use=FLT_SAV_CNT;
1298 rd->savfltreguse=lsra_reg_use;
1300 /* rd->memuse was already set in stack.c to allocate stack space for */
1301 /* passing arguments to called methods */
1302 #if defined(__I386__)
1303 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
1304 /* reserve 0(%esp) for Monitorenter/exit Argument on i386 */
1310 lsra_mem_use = rd->memuse; /* Init with memuse from stack.c */
1312 lsra_alloc(jd, ls->lt_mem, ls->lt_mem_count, &lsra_mem_use);
1313 lsra_alloc(jd, ls->lt_int, ls->lt_int_count, &lsra_mem_use);
1314 lsra_alloc(jd, ls->lt_flt, ls->lt_flt_count, &lsra_mem_use);
1316 rd->memuse=lsra_mem_use;
1318 #ifdef LSRA_DEBUG_VERBOSE
1319 if (compileverbose) {
1320 printf("Int RA complete \n");
1321 printf("Lifetimes after splitting int: \n");
1322 print_lifetimes(jd, ls->lt_int, ls->lt_int_count);
1324 printf("Flt RA complete \n");
1325 printf("Lifetimes after splitting flt:\n");
1326 print_lifetimes(jd, ls->lt_flt, ls->lt_flt_count);
1328 printf("Rest RA complete \n");
1329 printf("Lifetimes after leftt:\n");
1330 print_lifetimes(jd, ls->lt_mem, ls->lt_mem_count);
1335 void lsra_alloc(jitdata *jd, int *lifet, int lifetimecount, int *mem_use)
1338 struct lifetime *lt;
1339 struct freemem *fmem;
1340 struct stackslot *n;
1342 #ifdef HAS_4BYTE_STACKSLOT
1343 struct freemem *fmem_2;
1351 fmem = DNEW(struct freemem);
1354 #ifdef HAS_4BYTE_STACKSLOT
1355 fmem_2=DNEW(struct freemem);
1357 fmem_2->next = NULL;
1360 for (lt_index = 0; lt_index < lifetimecount; lt_index ++) {
1361 lt = &(ls->lifetime[lifet[lt_index]]);
1365 if (lt->reg == -1) {
1367 #ifdef HAS_4BYTE_STACKSLOT
1368 if (IS_2_WORD_TYPE(lt->type))
1369 regoff = lsra_getmem(lt, fmem_2, mem_use);
1372 regoff = lsra_getmem(lt, fmem, mem_use);
1374 flags = lt->savedvar;
1378 if (lt->v_index < 0) {
1379 for (n = lt->local_ss; n != NULL; n = n->next) {
1380 lsra_setflags(&(n->s->flags), flags);
1381 n->s->regoff = regoff;
1383 } else { /* local var */
1384 if (rd->locals[lt->v_index][lt->type].type >= 0) {
1385 rd->locals[lt->v_index][lt->type].flags = flags;
1386 rd->locals[lt->v_index][lt->type].regoff = regoff;
1388 log_text("Type Data mismatch\n");
1396 void lsra_setflags(int *flags, int newflags)
1398 if ( newflags & INMEMORY)
1401 *flags &= ~INMEMORY;
1403 if (newflags & SAVEDVAR)
1407 int lsra_getmem(struct lifetime *lt, struct freemem *fmem, int *mem_use)
1409 struct freemem *fm, *p;
1411 /* no Memory Slot allocated till now or all are still live */
1412 if ((fmem->next == NULL) || (fmem->next->end > lt->i_start)) {
1413 #ifdef HAS_4BYTE_STACKSLOT
1414 if (IS_2_WORD_TYPE(lt->type))
1415 if ( (*mem_use)&1 ) /* align memory location for 2 Word Types */
1417 fm=lsra_getnewmem(mem_use);
1418 if (IS_2_WORD_TYPE(lt->type))
1419 /* allocate a second following Slot for 2 Word Types */
1422 fm=lsra_getnewmem(mem_use);
1425 /* Memoryslot free */
1427 fmem->next = fm->next;
1430 fm->end = lt->i_end;
1431 for (p = fmem; (p->next != NULL) && (p->next->end < fm->end); p = p->next);
1437 struct freemem *lsra_getnewmem(int *mem_use)
1441 fm = DNEW(struct freemem);
1448 void _lsra_main(jitdata *jd, int *lifet, int lifetimecount,
1449 struct lsra_register *reg, int *reg_use)
1451 struct lifetime *lt;
1455 bool temp; /* reg from temp registers (true) or saved registers (false) */
1462 #if !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1465 if ((reg->tmp_top+reg->sav_top) == 0) {
1467 /* no registers available */
1468 for (lt_index = 0; lt_index < lifetimecount; lt_index++)
1469 ls->lifetime[lifet[lt_index]].reg = -1;
1473 ls->active_tmp_top = 0;
1474 ls->active_sav_top = 0;
1476 for (lt_index = 0; lt_index < lifetimecount; lt_index++) {
1477 lt = &(ls->lifetime[lifet[lt_index]]);
1479 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1480 regsneeded = (lt->type == TYPE_LNG)?1:0;
1483 lsra_expire_old_intervalls(jd, lt, reg);
1486 if (lt->savedvar || code_is_leafmethod(code)) {
1487 /* use Saved Reg (in case of leafmethod all regs are saved regs) */
1488 if (reg->sav_top > regsneeded) {
1489 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1491 reg_index = PACK_REGS(reg->sav_reg[--reg->sav_top],
1492 reg->sav_reg[--reg->sav_top]);
1496 reg_index = reg->sav_reg[--reg->sav_top];
1498 } else { /* use Temp Reg or if none is free a Saved Reg */
1499 if (reg->tmp_top > regsneeded) {
1501 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1503 reg_index = PACK_REGS(reg->tmp_reg[--reg->tmp_top],
1504 reg->tmp_reg[--reg->tmp_top]);
1507 reg_index = reg->tmp_reg[--reg->tmp_top];
1510 if (reg->sav_top > regsneeded) {
1512 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1514 reg_index = PACK_REGS(reg->sav_reg[--reg->sav_top],
1515 reg->sav_reg[--reg->sav_top]);
1518 reg_index = reg->sav_reg[--reg->sav_top];
1521 if (reg_index == -1) /* no reg is available anymore... -> spill */
1522 spill_at_intervall(jd, lt);
1524 lt->reg = reg_index;
1526 lsra_add_active(lt, ls->active_tmp, &(ls->active_tmp_top));
1528 if (reg->sav_top<*reg_use) *reg_use=reg->sav_top;
1529 lsra_add_active(lt, ls->active_sav, &(ls->active_sav_top));
1535 void lsra_add_active(struct lifetime *lt, struct lifetime **active,
1540 for(i = 0; (i < *active_top) && (active[i]->i_end < lt->i_end); i++);
1541 for(j = *active_top; j > i; j--) active[j] = active[j-1];
1546 void lsra_expire_old_intervalls(jitdata *jd, struct lifetime *lt,
1547 struct lsra_register *reg)
1549 _lsra_expire_old_intervalls(jd, lt, reg, jd->ls->active_tmp,
1550 &(jd->ls->active_tmp_top));
1551 _lsra_expire_old_intervalls(jd, lt, reg, jd->ls->active_sav,
1552 &(jd->ls->active_sav_top));
1555 void _lsra_expire_old_intervalls(jitdata *jd, struct lifetime *lt,
1556 struct lsra_register *reg,
1557 struct lifetime **active, int *active_top)
1561 for(i = 0; i < *active_top; i++) {
1562 if (active[i]->i_end > lt->i_start) break;
1564 /* make active[i]->reg available again */
1565 if (code_is_leafmethod(code)) {
1566 /* leafmethod -> don't care about type -> put all again into */
1568 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1569 if (active[i]->type == TYPE_LNG) {
1570 reg->sav_reg[reg->sav_top++] = GET_LOW_REG(active[i]->reg);
1571 reg->sav_reg[reg->sav_top++] = GET_HIGH_REG(active[i]->reg);
1574 reg->sav_reg[reg->sav_top++] = active[i]->reg;
1576 /* no leafmethod -> distinguish between temp and saved register */
1577 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1578 if (active[i]->type == TYPE_LNG) {
1579 /* no temp and saved regs are packed together, so looking at */
1580 /* LOW_REG is sufficient */
1581 if ( reg->nregdesc[ GET_LOW_REG(active[i]->reg)] == REG_SAV) {
1582 reg->sav_reg[reg->sav_top++] = GET_LOW_REG(active[i]->reg);
1583 reg->sav_reg[reg->sav_top++] = GET_HIGH_REG(active[i]->reg);
1585 reg->tmp_reg[reg->tmp_top++] = GET_LOW_REG(active[i]->reg);
1586 reg->tmp_reg[reg->tmp_top++] = GET_HIGH_REG(active[i]->reg);
1590 if ( reg->nregdesc[active[i]->reg] == REG_SAV) {
1591 reg->sav_reg[reg->sav_top++] = active[i]->reg;
1593 reg->tmp_reg[reg->tmp_top++] = active[i]->reg;
1598 /* active[0..i[ is to be removed */
1599 /* -> move [i..*active_top[ to [0..*active_top-i[ */
1600 for(k = 0, j = i; (j < *active_top); k++,j++)
1601 active[k] = active[j];
1607 void spill_at_intervall(jitdata *jd, struct lifetime *lt )
1609 if (lt->savedvar || code_is_leafmethod(code)) {
1610 _spill_at_intervall(lt, jd->ls->active_sav, &(jd->ls->active_sav_top));
1612 _spill_at_intervall(lt, jd->ls->active_tmp, &(jd->ls->active_tmp_top));
1613 if (lt->reg == -1) { /* no tmp free anymore */
1614 _spill_at_intervall(lt, jd->ls->active_sav,
1615 &(jd->ls->active_sav_top));
1620 void _spill_at_intervall(struct lifetime *lt, struct lifetime **active,
1624 #ifdef USAGE_COUNT_EXACT
1628 if (*active_top == 0) {
1633 i = *active_top - 1;
1634 #if defined(USAGE_COUNT_EXACT)
1635 /* find intervall which ends later or equal than than lt and has the lowest
1636 usagecount lower than lt */
1638 u_min = lt->usagecount;
1639 for (; (i >= 0) && (active[i]->i_end >= lt->i_end); i--) {
1640 if (active[i]->usagecount < u_min) {
1641 u_min = active[i]->usagecount;
1649 # if defined(USAGE_COUNT) && !defined(USAGE_COUNT_EXACT)
1650 if ((active[i]->i_end >= lt->i_end)
1651 && (active[i]->usagecount < lt->usagecount)) {
1652 # else /* "normal" LSRA heuristic */
1653 /* get last intervall from active */
1654 if (active[i]->i_end > lt->i_end) {
1657 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1658 /* Don't spill between one and two word int types */
1659 if ((active[i]->type == TYPE_LNG) != (lt->type == TYPE_LNG))
1662 lt->reg = active[i]->reg;
1666 for (j = i; j < *active_top; j++)
1667 active[j] = active[j + 1];
1669 lsra_add_active(lt, active, active_top);
1675 void lsra_calc_lifetime_length(jitdata *jd) {
1679 struct lifetime *lt;
1680 #if defined(LSRA_DEBUG_VERBOSE) || !defined(LV)
1685 int flags; /* 0 INMEMORY -> ls->lt_mem */
1686 /* 1 INTREG -> ls->lt_int */
1687 /* 2 FLTREG -> ls->lt_flt */
1694 #ifdef LSRA_DEBUG_VERBOSE
1695 if (compileverbose) {
1696 printf("icount_block: ");
1697 for (i=0; i < m->basicblockcount; i++)
1698 printf("(%3i-%3i) ",i, ls->icount_block[i]);
1703 /* extend lifetime over backedges (for the lsra version without exact
1705 now iterate through lifetimes and expand them */
1708 for(lt_index = 0 ;lt_index < ls->lifetimecount; lt_index++) {
1709 if ( ls->lifetime[lt_index].type != -1) { /* used lifetime */
1710 /* remember lt_index in lt_sorted */
1711 ls->lt_used[lifetimecount++] = lt_index;
1712 lt = &(ls->lifetime[lt_index]);
1713 #if defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1714 /* prevent conflicts between lifetimes of type long by increasing
1715 the lifetime by one instruction
1718 with i==l and/or j==k
1719 to resolve this during codegeneration a temporary register
1721 if (lt->type == TYPE_LNG)
1725 /* distribute lifetimes to lt_int, lt_flt and lt_mem */
1731 #if defined(HAS_4BYTE_STACKSLOT) && !defined(SUPPORT_COMBINE_INTEGER_REGISTERS)
1744 #if defined(__I386__)
1746 * for i386 put all floats in memory
1754 { log_text("Unknown Type\n"); assert(0); }
1758 case 0: /* lt_used[lt_used_index] -> lt_rest */
1759 ls->lt_mem[ ls->lt_mem_count++ ] = lt_index;
1761 case 1: /* l->lifetimes -> lt_int */
1762 ls->lt_int[ ls->lt_int_count++ ] = lt_index;
1764 case 2: /* l->lifetimes -> lt_flt */
1765 ls->lt_flt[ ls->lt_flt_count++ ] = lt_index;
1770 if (lt->i_first_def == INT_MAX) {
1771 #ifdef LSRA_DEBUG_VERBOSE
1772 printf("Warning: var not defined! vi: %i start: %i end: %i\n",
1773 lt->v_index, lt->i_start, lt->i_end);
1775 lt->bb_first_def = 0;
1776 lt->i_first_def = 0;
1779 lt->i_start = lt->i_first_def;
1781 if (lt->i_last_use == -2) {
1782 #ifdef LSRA_DEBUG_VERBOSE
1783 printf("Warning: Var not used! vi: %i start: %i end: %i\n",
1784 lt->v_index, lt->i_start, lt->i_end);
1786 lt->bb_last_use = lt->bb_first_def;
1787 lt->i_last_use = lt->i_first_def;
1790 lt->i_end = lt->i_last_use;
1792 #ifdef LSRA_DEBUG_VERBOSE
1793 if (lt->i_start > lt->i_end)
1794 printf("Warning: last use before first def! vi: %i start: %i end: %i\n", lt->v_index, lt->i_start, lt->i_end);
1798 if ((lt->bb_first_def != lt->bb_last_use) ||
1799 (lt->i_first_def == -1)) {
1800 /* Lifetime goes over more than one Basic Block -> */
1801 /* check for necessary extension over backedges */
1802 /* see lsra_get_backedges */
1803 /* Arguments are set "before" Block 0, so they have */
1804 /* a lifespan of more then one block, too */
1806 for (i=0; i < ls->backedge_count; i++) {
1807 if (!( (lt->bb_first_def > ls->backedge[i]->start) ||
1808 (lt->bb_last_use < ls->backedge[i]->end) )) {
1809 /* Live intervall intersects with a backedge */
1810 /* if (lt->bb_first_def <= ls->backedge[i]->start) */
1811 if (lt->bb_last_use <= ls->backedge[i]->start)
1813 ls->icount_block[ls->backedge[i]->start] +
1814 m->basicblocks[ls->sorted[ls->backedge[i]->start]].icount;
1818 #endif /* !defined(LV) */
1820 #ifdef USAGE_PER_INSTR
1821 lt->usagecount = lt->usagecount / ( lt->i_end - lt->i_start + 1);
1825 ls->lifetimecount = lifetimecount;
1828 #ifdef LSRA_DEBUG_VERBOSE
1829 void print_lifetimes(jitdata *jd, int *lt, int lifetimecount)
1833 int type,flags,regoff,varkind;
1841 for (lt_index = 0; lt_index < lifetimecount; lt_index++) {
1842 n = &(ls->lifetime[lt[lt_index]]);
1843 if (n->savedvar == SAVEDVAR)
1847 if (n->v_index < 0) { /* stackslot */
1848 type = n->local_ss->s->type;
1849 flags=n->local_ss->s->flags;
1850 regoff=n->local_ss->s->regoff;
1851 varkind=n->local_ss->s->varkind;
1852 } else { /* local var */
1853 if (rd->locals[n->v_index][n->type].type>=0) {
1854 type = rd->locals[n->v_index][n->type].type;
1855 flags=rd->locals[n->v_index][n->type].flags;
1856 regoff=rd->locals[n->v_index][n->type].regoff;
1859 { log_text("Type Data mismatch 3\n"); assert(0); }
1862 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);
1864 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);
1867 printf( "%3i Lifetimes printed \n",lt_index);
1873 /******************************************************************************
1874 Helpers for first LSRA Version without exact Liveness Analysis
1875 *****************************************************************************/
1878 bool lsra_join_ss( struct lsradata *ls, struct stackelement *in,
1879 struct stackelement *out, int join_flag) {
1880 struct lifetime *lt, *lto;
1881 struct stackslot *ss, *ss_last;
1884 if (in->varnum != out->varnum) {
1885 lt = &(ls->lifetime[-in->varnum - 1]);
1887 #ifdef LSRA_DEBUG_CHECK
1888 if (join_flag == JOIN_BB)
1889 if (lt->type == -1) {
1890 log_text("lsra_join_ss: lifetime for instack not found\n");
1895 if (out->varnum >= 0) { /* no lifetime for this slot till now */
1896 lsra_add_ss(lt, out);
1898 lto = &(ls->lifetime[-out->varnum - 1]);
1899 if ((join_flag == JOIN_DUP) || (join_flag == JOIN_OP))
1900 if ( (lt->flags & JOIN_BB) || (lto->flags & JOIN_BB)) {
1903 if (join_flag == JOIN_DUP)
1904 if ( (lt->flags & JOIN_OP) || (lto->flags & JOIN_OP)) {
1907 #ifdef LSRA_DEBUG_CHECK
1908 if (lto->type == -1) {
1909 log_text("lsra_join_ss: lifetime for outstack not found\n");
1913 #ifdef LSRA_DEBUG_CHECK
1914 if (lto->type != lt->type) {
1915 log_text("lsra_join_ss: in/out stack type mismatch\n");
1920 lt->flags |= JOINING;
1922 /* take Lifetime lto out of ls->lifetimes */
1925 /* merge lto into lt of in */
1927 ss_last = ss = lto->local_ss;
1928 while (ss != NULL) {
1930 ss->s->varnum = lt->v_index;
1933 if (ss_last != NULL) {
1934 ss_last->next = lt->local_ss;
1935 lt->local_ss = lto->local_ss;
1938 lt->savedvar |= lto->savedvar;
1939 lt->flags |= lto->flags | join_flag;
1940 lt->usagecount += lto->usagecount;
1942 /*join of i_first_def and i_last_use */
1943 if (lto->i_first_def < lt->i_first_def) {
1944 lt->i_first_def = lto->i_first_def;
1946 if (lto->i_last_use > lt->i_last_use) {
1947 lt->i_last_use = lto->i_last_use;
1954 /* join instack of Basic Block b_index with outstack of predecessors */
1955 void lsra_join_lifetimes(jitdata *jd,int b_index) {
1958 struct stackelement *in, *i, *out;
1964 /* do not join instack of Exception Handler */
1965 if (m->basicblocks[b_index].type == BBTYPE_EXH)
1967 in=m->basicblocks[b_index].instack;
1968 /* do not join first instack element of a subroutine header */
1969 if (m->basicblocks[b_index].type == BBTYPE_SBR)
1973 for (pred = ls->pred[b_index]; pred != NULL; pred = pred->next) {
1974 out = m->basicblocks[pred->value].outstack;
1975 for (i=in; (i != NULL); i = i->prev, out=out->prev) {
1976 lsra_join_ss(ls, i, out, JOIN_BB);
1982 struct stackslot *lsra_make_ss(stackptr s, int bb_index)
1984 struct stackslot *ss;
1986 ss = DNEW(struct stackslot);
1992 void lsra_add_ss(struct lifetime *lt, stackptr s) {
1993 struct stackslot *ss;
1995 /* Stackslot not in list? */
1996 if (s->varnum != lt->v_index) {
1997 ss = DNEW(struct stackslot);
1999 ss->s->varnum = lt->v_index;
2000 ss->next = lt->local_ss;
2003 lt->savedvar |= s->flags & SAVEDVAR;
2009 struct lifetime *get_ss_lifetime(lsradata *ls, stackptr s) {
2012 if (s->varnum >= 0) { /* new stackslot lifetime */
2013 #ifdef LSRA_DEBUG_CHECK_VERBOSE
2014 if (-ls->v_index - 1 >= ls->maxlifetimes) {
2015 printf("%i %i\n", -ls->v_index - 1, ls->maxlifetimes);
2018 _LSRA_ASSERT(-ls->v_index - 1 < ls->maxlifetimes);
2020 n = &(ls->lifetime[-ls->v_index - 1]);
2022 n->v_index = ls->v_index--;
2025 n->bb_last_use = -1;
2026 n->bb_first_def = -1;
2027 n->i_last_use = -2; /* At -1 param init happens, so -2 is below all
2028 possible instruction indices */
2029 n->i_first_def = INT_MAX;
2034 n = &(ls->lifetime[-s->varnum - 1]);
2040 #define IS_TEMP_VAR(s) (((s)->varkind != ARGVAR) && ((s)->varkind != LOCALVAR))
2042 #define lsra_join_3_stack(ls, dst, src1, src2, join_type) \
2043 if ( IS_TEMP_VAR(dst) ) { \
2045 if ( IS_TEMP_VAR(src1) && ((src1)->type == (dst)->type)) { \
2046 join_ret = lsra_join_ss(ls, dst, src1, join_type); \
2048 if ((!join_ret) && IS_TEMP_VAR(src2) && ((src2)->type == (dst)->type)) { \
2049 lsra_join_ss(ls, dst, src2, join_type); \
2053 #define lsra_join_2_stack(ls, dst, src, join_type) \
2054 if ( IS_TEMP_VAR(dst) ) { \
2055 if ( (IS_TEMP_VAR(src)) && ((src)->type == (dst)->type)) { \
2056 lsra_join_ss(ls, dst, src, join_type); \
2060 #define lsra_join_dup(ls, s1, s2, s3) { \
2061 if (IS_TEMP_VAR(s1)) { \
2063 if (IS_TEMP_VAR(s2)) \
2064 join_ret = lsra_join_ss(ls, s1, s2, JOIN); \
2065 /* undangerous join!*/\
2066 if (IS_TEMP_VAR(s3)) { \
2067 if (join_ret) /* first join succesfull -> second of type */ \
2069 lsra_join_ss(ls, s1, s3, JOIN_DUP); \
2071 lsra_join_ss(ls, s1, s3, JOIN); /* first join did not */ \
2072 /* happen -> second undangerous */ \
2075 if (IS_TEMP_VAR(s2) && IS_TEMP_VAR(s3)) \
2076 lsra_join_ss(ls, s2, s3, JOIN_DUP); \
2079 #define lsra_new_stack(ls, s, block, instr) \
2080 if ((s)->varkind != ARGVAR) _lsra_new_stack(ls, s, block, instr, LSRA_STORE)
2081 void _lsra_new_stack(lsradata *ls, stackptr s, int block, int instr, int store)
2085 if (s->varkind == LOCALVAR) {
2086 lsra_usage_local(ls, s->varnum, s->type, block, instr, LSRA_STORE);
2087 } else /* if (s->varkind != ARGVAR) */ {
2089 n=get_ss_lifetime(ls, s);
2091 if (store == LSRA_BB_IN)
2092 n->flags |= JOIN_BB;
2093 /* remember first def -> overwrite everytime */
2094 n->bb_first_def = ls->sorted_rev[block];
2095 n->i_first_def = ls->icount_block[ls->sorted_rev[block]] + instr;
2097 n->usagecount+=ls->nesting[ls->sorted_rev[block]];
2101 #define lsra_from_stack(ls, s, block, instr) \
2102 if ((s)->varkind != ARGVAR) _lsra_from_stack(ls, s, block, instr, LSRA_LOAD)
2103 #define lsra_pop_from_stack(ls, s, block, instr) \
2104 if ((s)->varkind != ARGVAR) _lsra_from_stack(ls, s, block, instr, LSRA_POP)
2105 void _lsra_from_stack(lsradata *ls, stackptr s, int block, int instr, int store)
2109 if (s->varkind == LOCALVAR) {
2110 lsra_usage_local(ls, s->varnum, s->type, block, instr, LSRA_LOAD);
2111 } else /* if (s->varkind != ARGVAR) */ {
2112 if (s->varkind == STACKVAR )
2113 /* No STACKVARS possible with lsra! */
2114 s->varkind = TEMPVAR;
2116 n=get_ss_lifetime(ls, s);
2118 if (store == LSRA_BB_OUT)
2119 n->flags |= JOIN_BB;
2120 if (n->flags & JOINING)
2121 n->flags &= ~JOINING;
2122 n->usagecount+=ls->nesting[ls->sorted_rev[block]];
2124 /* remember last USE, so only write, if USE Field is undefined (==-1) */
2125 if (n->bb_last_use == -1) {
2126 n->bb_last_use = ls->sorted_rev[block];
2127 n->i_last_use = ls->icount_block[ls->sorted_rev[block]] + instr;
2132 void lsra_usage_local(lsradata *ls, s4 v_index, int type, int block, int instr,
2137 n = &(ls->lifetime[ ls->maxlifetimes + v_index * (TYPE_ADR+1) + type]);
2139 if (n->type == -1) { /* new local lifetime */
2143 n->savedvar = SAVEDVAR;
2147 n->bb_last_use = -1;
2148 n->bb_first_def = -1;
2150 n->i_first_def = INT_MAX;
2152 n->usagecount+=ls->nesting[ls->sorted_rev[block]];
2153 /* add access at (block, instr) to instruction list */
2154 /* remember last USE, so only write, if USE Field is undefined (==-1) */
2155 /* count store as use, too -> defined and not used vars would overwrite */
2157 if (n->bb_last_use == -1) {
2158 n->bb_last_use = ls->sorted_rev[block];
2159 n->i_last_use = ls->icount_block[ls->sorted_rev[block]] + instr;
2161 if (store == LSRA_STORE) {
2162 /* store == LSRA_STORE, remember first def -> overwrite everytime */
2163 n->bb_first_def = ls->sorted_rev[block];
2164 n->i_first_def = ls->icount_block[ls->sorted_rev[block]] + instr;
2168 #ifdef LSRA_DEBUG_VERBOSE
2169 void lsra_dump_stack(stackptr s)
2172 printf("%p(R%3i N%3i K%3i T%3i F%3i) ",(void *)s,s->regoff, s->varnum,
2173 s->varkind, s->type, s->flags);
2181 void lsra_scan_registers_canditates(jitdata *jd, int b_index)
2183 /* methodinfo *lm; */
2184 builtintable_entry *bte;
2192 bool join_ret; /* for lsra_join* Macros */
2199 /* get instruction count for BB and remember the max instruction count */
2201 iindex = m->basicblocks[b_index].icount - 1;
2203 src = m->basicblocks[b_index].instack;
2204 if (m->basicblocks[b_index].type != BBTYPE_STD) {
2205 lsra_new_stack(ls, src, b_index, 0);
2208 for (;src != NULL; src=src->prev) {
2209 /*******************************************************************************
2210 Check this - ? For every incoming Stack Slot a lifetime has to be created ?
2211 *******************************************************************************/
2212 _lsra_new_stack(ls, src, b_index, 0, LSRA_BB_IN);
2214 src = m->basicblocks[b_index].outstack;
2215 for (;src != NULL; src=src->prev) {
2216 _lsra_from_stack(ls, src, b_index, iindex, LSRA_BB_OUT);
2219 /* set iptr to last instruction of BB */
2220 iptr = m->basicblocks[b_index].iinstr + iindex;
2222 for (;iindex >= 0; iindex--, iptr--) {
2224 /* get source and destination Stack for the current instruction */
2225 /* destination stack is available as iptr->dst */
2229 /* source stack is either the destination stack of the previos */
2230 /* instruction, or the basicblock instack for the first instruction */
2232 if (iindex) /* != 0 is > 0 here, since iindex ist always >= 0 */
2235 src=m->basicblocks[b_index].instack;
2243 /* local read (return adress) */
2244 lsra_usage_local(ls, iptr->op1, TYPE_ADR, b_index, iindex,
2248 /* case ICMD_ELSE_ICONST: */
2249 case ICMD_CHECKNULL:
2253 case ICMD_PUTSTATICCONST:
2254 case ICMD_INLINE_START:
2255 case ICMD_INLINE_END:
2256 case ICMD_INLINE_GOTO:
2260 /* local = local+<const> */
2261 lsra_usage_local(ls, iptr->op1, TYPE_INT, b_index, iindex,
2263 lsra_usage_local(ls, iptr->op1, TYPE_INT, b_index, iindex,
2267 /* pop 0 push 1 const: const->stack */
2273 /* new stack slot */
2274 lsra_new_stack(ls, dst, b_index, iindex);
2277 /* pop 0 push 1 load: local->stack */
2283 if (dst->varkind != LOCALVAR) {
2284 /* local->value on stack */
2285 lsra_usage_local(ls, iptr->op1, opcode - ICMD_ILOAD, b_index,
2287 lsra_new_stack(ls, dst, b_index, iindex); /* value->stack */
2288 } else /* if (dst->varnum != iptr->op1) */ {
2289 /* local -> local */
2290 lsra_usage_local(ls, iptr->op1, opcode - ICMD_ILOAD, b_index,
2291 iindex,LSRA_LOAD); /* local->value */
2292 lsra_usage_local(ls, dst->varnum, opcode - ICMD_ILOAD, b_index,
2293 iindex, LSRA_STORE); /* local->value */
2299 /* Stack(arrayref,index)->stack */
2310 lsra_from_stack(ls, src, b_index, iindex);
2311 /* stack->arrayref */
2312 lsra_from_stack(ls, src->prev, b_index, iindex);
2313 /* arrayref[index]->stack */
2314 lsra_new_stack(ls, dst, b_index, iindex);
2318 /* stack(arrayref,index,value)->arrayref[index]=value */
2329 lsra_from_stack(ls, src,b_index, iindex); /* stack -> value */
2330 lsra_from_stack(ls, src->prev, b_index, iindex); /* stack -> index*/
2331 /* stack -> arrayref */
2332 lsra_from_stack(ls, src->prev->prev, b_index, iindex);
2335 /* pop 1 push 0 store: stack -> local */
2341 if (src->varkind != LOCALVAR) {
2342 lsra_from_stack(ls, src, b_index, iindex); /* stack -> value */
2343 lsra_usage_local(ls, iptr->op1, opcode-ICMD_ISTORE, b_index,
2344 iindex, LSRA_STORE); /* local->value */
2345 } else /* if (src->varnum != iptr->op1) */ {
2346 lsra_usage_local(ls, iptr->op1, opcode-ICMD_ISTORE, b_index,
2347 iindex, LSRA_STORE); /* local->value */
2348 lsra_usage_local(ls, src->varnum, opcode-ICMD_ISTORE, b_index,
2349 iindex, LSRA_LOAD); /* local->value */
2354 case ICMD_POP: /* throw away a stackslot */
2355 /* TODO: check if used anyway (DUP...) and change codegen to */
2356 /* ignore this stackslot */
2357 lsra_pop_from_stack(ls, src, b_index, iindex);
2365 case ICMD_ARETURN: /* stack(value) -> [empty] */
2367 case ICMD_ATHROW: /* stack(objref) -> undefined */
2369 case ICMD_PUTSTATIC: /* stack(value) -> static_field */
2370 case ICMD_PUTFIELDCONST:
2372 /* pop 1 push 0 branch */
2373 case ICMD_IFNULL: /* stack(value) -> branch? */
2374 case ICMD_IFNONNULL:
2390 /* pop 1 push 0 table branch */
2391 case ICMD_TABLESWITCH:
2392 case ICMD_LOOKUPSWITCH:
2394 case ICMD_MONITORENTER:
2395 case ICMD_MONITOREXIT:
2396 lsra_from_stack(ls, src, b_index, iindex); /* stack -> value */
2400 case ICMD_POP2: /* throw away 2 stackslots */
2401 /* TODO: check if used anyway (DUP...) and change codegen to */
2402 /* ignore this stackslot */
2403 lsra_pop_from_stack(ls, src, b_index, iindex);
2404 lsra_pop_from_stack(ls, src->prev, b_index, iindex);
2407 /* pop 2 push 0 branch */
2409 case ICMD_IF_ICMPEQ: /* stack (v1,v2) -> branch(v1,v2) */
2410 case ICMD_IF_ICMPNE:
2411 case ICMD_IF_ICMPLT:
2412 case ICMD_IF_ICMPGE:
2413 case ICMD_IF_ICMPGT:
2414 case ICMD_IF_ICMPLE:
2416 case ICMD_IF_LCMPEQ:
2417 case ICMD_IF_LCMPNE:
2418 case ICMD_IF_LCMPLT:
2419 case ICMD_IF_LCMPGE:
2420 case ICMD_IF_LCMPGT:
2421 case ICMD_IF_LCMPLE:
2423 case ICMD_IF_ACMPEQ:
2424 case ICMD_IF_ACMPNE:
2427 case ICMD_PUTFIELD: /* stack(objref,value) -> objref = value */
2429 case ICMD_IASTORECONST:
2430 case ICMD_LASTORECONST:
2431 case ICMD_AASTORECONST:
2432 case ICMD_BASTORECONST:
2433 case ICMD_CASTORECONST:
2434 case ICMD_SASTORECONST:
2435 lsra_from_stack(ls, src, b_index, iindex); /* stack -> value*/
2436 lsra_from_stack(ls, src->prev, b_index, iindex);
2439 /* pop 0 push 1 dup */
2440 case ICMD_DUP: /* src == dst->prev, src -> dst */
2441 /* lsra_from_stack(ls, src,b_index,iindex);*/
2442 lsra_new_stack(ls, dst, b_index, iindex);
2444 #ifdef JOIN_DUP_STACK
2445 /* src is identical to dst->prev */
2446 lsra_join_2_stack(ls, src, dst, JOIN_DUP);
2450 /* pop 0 push 2 dup */
2452 /* lsra_from_stack(ls, src,b_index, iindex); */
2453 /* lsra_from_stack(ls, src->prev, b_index, iindex); */
2454 lsra_new_stack(ls, dst->prev, b_index, iindex);
2455 lsra_new_stack(ls, dst, b_index, iindex);
2457 #ifdef JOIN_DUP_STACK
2458 lsra_join_2_stack(ls, src, dst, JOIN_DUP);
2459 lsra_join_2_stack(ls, src->prev, dst->prev, JOIN_DUP);
2460 /* src is identical to dst->prev->prev */
2461 /* src->prev is identical to dst->prev->prev->prev */
2465 /* pop 2 push 3 dup */
2467 lsra_from_stack(ls, src, b_index, iindex+1);
2468 lsra_from_stack(ls, src->prev, b_index, iindex+1);
2469 lsra_new_stack(ls, dst->prev->prev, b_index, iindex);
2470 lsra_new_stack(ls, dst->prev, b_index, iindex);
2471 lsra_new_stack(ls, dst, b_index, iindex);
2472 #ifdef JOIN_DUP_STACK
2473 lsra_join_dup(ls, src, dst, dst->prev->prev);
2474 lsra_join_2_stack(ls, src->prev, dst->prev, JOIN);
2478 /* pop 3 push 4 dup */
2480 lsra_from_stack(ls, src,b_index, iindex+1);
2481 lsra_from_stack(ls, src->prev, b_index, iindex+1);
2482 lsra_from_stack(ls, src->prev->prev, b_index, iindex+1);
2483 lsra_new_stack(ls, dst->prev->prev->prev, b_index, iindex);
2484 lsra_new_stack(ls, dst->prev->prev, b_index, iindex);
2485 lsra_new_stack(ls, dst->prev, b_index, iindex);
2486 lsra_new_stack(ls, dst, b_index, iindex);
2488 #ifdef JOIN_DUP_STACK
2489 lsra_join_dup(ls, src, dst, dst->prev->prev->prev);
2490 lsra_join_2_stack(ls, src->prev, dst->prev, JOIN);
2491 lsra_join_2_stack(ls, src->prev->prev, dst->prev->prev, JOIN);
2495 /* pop 3 push 5 dup */
2497 lsra_from_stack(ls, src, b_index, iindex+1);
2498 lsra_from_stack(ls, src->prev, b_index, iindex+1);
2499 lsra_from_stack(ls, src->prev->prev, b_index, iindex+1);
2500 lsra_new_stack(ls, dst->prev->prev->prev->prev, b_index, iindex);
2501 lsra_new_stack(ls, dst->prev->prev->prev, b_index, iindex);
2502 lsra_new_stack(ls, dst->prev->prev, b_index, iindex);
2503 lsra_new_stack(ls, dst->prev, b_index, iindex);
2504 lsra_new_stack(ls, dst, b_index, iindex);
2506 #ifdef JOIN_DUP_STACK
2507 lsra_join_dup(ls, src, dst, dst->prev->prev->prev);
2508 lsra_join_dup(ls, src->prev, dst->prev,
2509 dst->prev->prev->prev->prev);
2510 lsra_join_2_stack(ls, src->prev->prev, dst->prev->prev, JOIN);
2514 /* pop 4 push 6 dup */
2516 lsra_from_stack(ls, src, b_index, iindex+1);
2517 lsra_from_stack(ls, src->prev, b_index, iindex+1);
2518 lsra_from_stack(ls, src->prev->prev, b_index, iindex+1);
2519 lsra_from_stack(ls, src->prev->prev->prev, b_index, iindex+1);
2520 lsra_new_stack(ls, dst->prev->prev->prev->prev->prev, b_index,
2522 lsra_new_stack(ls, dst->prev->prev->prev->prev, b_index, iindex);
2523 lsra_new_stack(ls, dst->prev->prev->prev, b_index, iindex);
2524 lsra_new_stack(ls, dst->prev->prev, b_index, iindex);
2525 lsra_new_stack(ls, dst->prev, b_index, iindex);
2526 lsra_new_stack(ls, dst, b_index, iindex);
2528 #ifdef JOIN_DUP_STACK
2529 lsra_join_dup(ls, src, dst, dst->prev->prev->prev->prev);
2530 lsra_join_dup(ls, src->prev, dst->prev,
2531 dst->prev->prev->prev->prev->prev);
2532 lsra_join_2_stack(ls, src->prev->prev, dst->prev->prev, JOIN);
2533 lsra_join_2_stack(ls, src->prev->prev->prev, dst->prev->prev->prev,
2538 /* pop 2 push 2 swap */
2540 lsra_from_stack(ls, src, b_index, iindex+1);
2541 lsra_from_stack(ls, src->prev, b_index, iindex+1);
2542 lsra_new_stack(ls, dst->prev, b_index, iindex);
2543 lsra_new_stack(ls, dst, b_index, iindex);
2545 lsra_join_2_stack(ls, src->prev, dst, JOIN);
2546 lsra_join_2_stack(ls, src, dst->prev, JOIN);
2584 lsra_from_stack(ls, src, b_index, iindex);
2585 lsra_from_stack(ls, src->prev, b_index, iindex);
2586 lsra_new_stack(ls, dst, b_index, iindex);
2587 #ifdef JOIN_DEST_STACK
2588 lsra_join_3_stack(ls, dst, src->prev, src, JOIN_OP);
2593 lsra_from_stack(ls, src, b_index, iindex);
2594 lsra_from_stack(ls, src->prev,b_index,iindex);
2595 lsra_new_stack(ls, dst, b_index, iindex);
2596 #ifdef JOIN_DEST_STACK
2597 lsra_join_2_stack(ls, src, dst, JOIN_OP);
2615 lsra_from_stack(ls, src, b_index, iindex);
2616 lsra_from_stack(ls, src->prev, b_index, iindex);
2617 lsra_new_stack(ls, dst, b_index, iindex);
2621 case ICMD_LADDCONST:
2622 case ICMD_LSUBCONST:
2623 case ICMD_LMULCONST:
2627 case ICMD_LANDCONST:
2629 case ICMD_LXORCONST:
2630 case ICMD_LSHLCONST:
2631 case ICMD_LSHRCONST:
2632 case ICMD_LUSHRCONST:
2634 case ICMD_IADDCONST:
2635 case ICMD_ISUBCONST:
2636 case ICMD_IMULCONST:
2640 case ICMD_IANDCONST:
2642 case ICMD_IXORCONST:
2643 case ICMD_ISHLCONST:
2644 case ICMD_ISHRCONST:
2645 case ICMD_IUSHRCONST:
2647 /* case ICMD_IFEQ_ICONST: */
2648 /* case ICMD_IFNE_ICONST: */
2649 /* case ICMD_IFLT_ICONST: */
2650 /* case ICMD_IFGE_ICONST: */
2651 /* case ICMD_IFGT_ICONST: */
2652 /* case ICMD_IFLE_ICONST: */
2657 case ICMD_INT2SHORT:
2675 case ICMD_CHECKCAST:
2676 lsra_from_stack(ls, src, b_index, iindex);
2677 lsra_new_stack(ls, dst, b_index, iindex);
2678 #ifdef JOIN_DEST_STACK
2679 lsra_join_2_stack(ls, src, dst, JOIN_OP);
2683 /* TODO: check if for these ICMDs JOIN_DEST_STACK works, too! */
2684 case ICMD_ARRAYLENGTH:
2685 case ICMD_INSTANCEOF:
2688 case ICMD_ANEWARRAY:
2691 lsra_from_stack(ls, src, b_index, iindex);
2692 lsra_new_stack(ls, dst, b_index, iindex);
2696 case ICMD_GETSTATIC:
2699 lsra_new_stack(ls, dst, b_index, iindex);
2702 /* pop many push any */
2704 case ICMD_INVOKESTATIC:
2705 case ICMD_INVOKESPECIAL:
2706 case ICMD_INVOKEVIRTUAL:
2707 case ICMD_INVOKEINTERFACE:
2708 INSTRUCTION_GET_METHODDESC(iptr,md);
2711 lsra_from_stack(ls, src, b_index, iindex);
2714 if (md->returntype.type != TYPE_VOID)
2715 lsra_new_stack(ls, dst, b_index, iindex);
2724 lsra_from_stack(ls, src, b_index, iindex);
2727 if (md->returntype.type != TYPE_VOID)
2728 lsra_new_stack(ls, dst, b_index, iindex);
2731 case ICMD_MULTIANEWARRAY:
2734 lsra_from_stack(ls, src, b_index, iindex);
2737 lsra_new_stack(ls, dst, b_index, iindex);
2741 exceptions_throw_internalerror("Unknown ICMD %d during register allocation",
2747 #endif /* defined(LV) */
2751 * These are local overrides for various environment variables in Emacs.
2752 * Please do not remove this and leave it at the end of the file, where
2753 * Emacs will automagically detect them.
2754 * ---------------------------------------------------------------------
2757 * indent-tabs-mode: t
2761 * vim:noexpandtab:sw=4:ts=4: