13219Smckusick /* Copyright (c) 1979 Regents of the University of California */ 23219Smckusick 3*10657Speter static char sccsid[] = "@(#)tmps.c 1.7 02/01/83"; 43219Smckusick 53219Smckusick #include "whoami.h" 63219Smckusick #include "0.h" 7*10657Speter #include "objfmt.h" 83280Smckusic #ifdef PC 93280Smckusic # include "pc.h" 103280Smckusic #endif PC 113219Smckusick 123219Smckusick /* 133280Smckusic * This routine defines the register allocation strategy 143280Smckusic * All temporaries are allocated here, and this routines decides 153280Smckusic * where they are to be put. 163280Smckusic */ 173281Smckusic #ifdef PC 18*10657Speter #ifdef vax 193280Smckusic # define MAXREGS 6 203839Speter # define MINREGSIZE 4 213839Speter # define MAXREGSIZE 4 223280Smckusic # define FIRSTREG 6 23*10657Speter #endif vax 24*10657Speter #ifdef pdp11 253280Smckusic # define MAXREGS 3 263839Speter # define MINREGSIZE 2 273839Speter # define MAXREGSIZE 2 283280Smckusic # define FIRSTREG 2 29*10657Speter #endif pdp11 30*10657Speter #if (!(vax || pdp11)) 313280Smckusic # define MAXREGS 0 323839Speter # define MINREGSIZE 0 333839Speter # define MAXREGSIZE 0 343280Smckusic # define FIRSTREG 0 35*10657Speter #endif 363281Smckusic #endif PC 373280Smckusic 383280Smckusic /* 393219Smckusick * allocate runtime temporary variables 403219Smckusick */ 413839Speter struct nl * 423280Smckusic tmpalloc(size, type, mode) 433219Smckusick long size; 443219Smckusick struct nl *type; 453280Smckusic int mode; 463219Smckusick { 473280Smckusic register struct om *op = &sizes[ cbn ]; 483280Smckusic register int offset; 493839Speter register struct nl *nlp; 503219Smckusick 513280Smckusic # ifdef PC 523839Speter if (mode == REGOK && size >= MINREGSIZE && size <= MAXREGSIZE && 533280Smckusic op->curtmps.reg_off < MAXREGS) { 543280Smckusic offset = op->curtmps.reg_off++; 553280Smckusic if ( offset > op->reg_max ) { 563280Smckusic op->reg_max = offset; 573280Smckusic } 583839Speter nlp = defnl( 0 , VAR , type , offset + FIRSTREG ); 593839Speter nlp -> extra_flags = NLOCAL | NREGVAR; 603839Speter return nlp; 613280Smckusic } 623280Smckusic # endif PC 634027Smckusic offset = op->curtmps.om_off = 644027Smckusic roundup((int)(op->curtmps.om_off - size), (long)align(type)); 653280Smckusic if ( offset < op->om_max ) { 663280Smckusic op->om_max = offset; 673219Smckusick } 683839Speter nlp = defnl( 0 , VAR , type , offset ); 693219Smckusick # ifdef PC 703839Speter nlp -> extra_flags = NLOCAL; 713219Smckusick putlbracket( ftnno , -offset ); 723219Smckusick # endif PC 733839Speter return nlp; 743219Smckusick } 753280Smckusic 763219Smckusick /* 773219Smckusick * deallocate runtime temporary variables 783219Smckusick */ 793219Smckusick tmpfree(restore) 803280Smckusic register struct tmps *restore; 813219Smckusick { 823280Smckusic register struct om *op = &sizes[ cbn ]; 833219Smckusick 843280Smckusic # ifdef PC 853280Smckusic if (restore->reg_off < op->curtmps.reg_off) { 863280Smckusic op->curtmps.reg_off = restore->reg_off; 873280Smckusic } 883280Smckusic # endif PC 893280Smckusic if (restore->om_off > op->curtmps.om_off) { 903280Smckusic op->curtmps.om_off = restore->om_off; 913219Smckusick # ifdef PC 923280Smckusic putlbracket( ftnno , -restore->om_off ); 933219Smckusick # endif PC 943219Smckusick } 953219Smckusick } 963280Smckusic 973281Smckusic #ifdef PC 98*10657Speter #ifdef vax 993280Smckusic /* 1003280Smckusic * create a save mask for registers which have been used 1013280Smckusic * in this level 1023280Smckusic */ 1033280Smckusic savmask() 1043280Smckusic { 1053839Speter int mask; 1063280Smckusic int i; 1073280Smckusic 1083280Smckusic mask = RSAVEMASK; 1093280Smckusic if (opt('t')) 1103280Smckusic mask |= RUNCHECK; 1113280Smckusic for (i = 0; i <= sizes[ cbn ].reg_max; i++) 1123280Smckusic mask |= 1 << (FIRSTREG + i); 1133280Smckusic return mask; 1143280Smckusic } 115*10657Speter #endif vax 1163281Smckusic #endif PC 117