13219Smckusick /* Copyright (c) 1979 Regents of the University of California */ 23219Smckusick 3*4027Smckusic static char sccsid[] = "@(#)tmps.c 1.6 07/23/81"; 43219Smckusick 53219Smckusick #include "whoami.h" 63219Smckusick #include "0.h" 73280Smckusic #ifdef PC 83280Smckusic # include "pc.h" 93280Smckusic #endif PC 103219Smckusick 113219Smckusick /* 123280Smckusic * This routine defines the register allocation strategy 133280Smckusic * All temporaries are allocated here, and this routines decides 143280Smckusic * where they are to be put. 153280Smckusic */ 163281Smckusic #ifdef PC 173280Smckusic #ifdef VAX 183280Smckusic # define MAXREGS 6 193839Speter # define MINREGSIZE 4 203839Speter # define MAXREGSIZE 4 213280Smckusic # define FIRSTREG 6 223280Smckusic #else 233280Smckusic #ifdef PDP11 243280Smckusic # define MAXREGS 3 253839Speter # define MINREGSIZE 2 263839Speter # define MAXREGSIZE 2 273280Smckusic # define FIRSTREG 2 283280Smckusic #else 293280Smckusic # define MAXREGS 0 303839Speter # define MINREGSIZE 0 313839Speter # define MAXREGSIZE 0 323280Smckusic # define FIRSTREG 0 333280Smckusic #endif PDP11 343280Smckusic #endif VAX 353281Smckusic #endif PC 363280Smckusic 373280Smckusic /* 383219Smckusick * allocate runtime temporary variables 393219Smckusick */ 403839Speter struct nl * 413280Smckusic tmpalloc(size, type, mode) 423219Smckusick long size; 433219Smckusick struct nl *type; 443280Smckusic int mode; 453219Smckusick { 463280Smckusic register struct om *op = &sizes[ cbn ]; 473280Smckusic register int offset; 483839Speter register struct nl *nlp; 493219Smckusick 503280Smckusic # ifdef PC 513839Speter if (mode == REGOK && size >= MINREGSIZE && size <= MAXREGSIZE && 523280Smckusic op->curtmps.reg_off < MAXREGS) { 533280Smckusic offset = op->curtmps.reg_off++; 543280Smckusic if ( offset > op->reg_max ) { 553280Smckusic op->reg_max = offset; 563280Smckusic } 573839Speter nlp = defnl( 0 , VAR , type , offset + FIRSTREG ); 583839Speter nlp -> extra_flags = NLOCAL | NREGVAR; 593839Speter return nlp; 603280Smckusic } 613280Smckusic # endif PC 62*4027Smckusic offset = op->curtmps.om_off = 63*4027Smckusic roundup((int)(op->curtmps.om_off - size), (long)align(type)); 643280Smckusic if ( offset < op->om_max ) { 653280Smckusic op->om_max = offset; 663219Smckusick } 673839Speter nlp = defnl( 0 , VAR , type , offset ); 683219Smckusick # ifdef PC 693839Speter nlp -> extra_flags = NLOCAL; 703219Smckusick putlbracket( ftnno , -offset ); 713219Smckusick # endif PC 723839Speter return nlp; 733219Smckusick } 743280Smckusic 753219Smckusick /* 763219Smckusick * deallocate runtime temporary variables 773219Smckusick */ 783219Smckusick tmpfree(restore) 793280Smckusic register struct tmps *restore; 803219Smckusick { 813280Smckusic register struct om *op = &sizes[ cbn ]; 823219Smckusick 833280Smckusic # ifdef PC 843280Smckusic if (restore->reg_off < op->curtmps.reg_off) { 853280Smckusic op->curtmps.reg_off = restore->reg_off; 863280Smckusic } 873280Smckusic # endif PC 883280Smckusic if (restore->om_off > op->curtmps.om_off) { 893280Smckusic op->curtmps.om_off = restore->om_off; 903219Smckusick # ifdef PC 913280Smckusic putlbracket( ftnno , -restore->om_off ); 923219Smckusick # endif PC 933219Smckusick } 943219Smckusick } 953280Smckusic 963281Smckusic #ifdef PC 973280Smckusic #ifdef VAX 983280Smckusic /* 993280Smckusic * create a save mask for registers which have been used 1003280Smckusic * in this level 1013280Smckusic */ 1023280Smckusic savmask() 1033280Smckusic { 1043839Speter int mask; 1053280Smckusic int i; 1063280Smckusic 1073280Smckusic mask = RSAVEMASK; 1083280Smckusic if (opt('t')) 1093280Smckusic mask |= RUNCHECK; 1103280Smckusic for (i = 0; i <= sizes[ cbn ].reg_max; i++) 1113280Smckusic mask |= 1 << (FIRSTREG + i); 1123280Smckusic return mask; 1133280Smckusic } 1143280Smckusic #endif VAX 1153281Smckusic #endif PC 116