Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!think.com!paperboy!hsdndev!spdcc!iecc!compilers-sender From: mike@vlsivie.tuwien.ac.at (Michael K. Gschwind) Newsgroups: comp.compilers Subject: Re: Parameter Passing Via Registers Keywords: design, registers, Modula Message-ID: <1991May02.232454.1401@iecc.cambridge.ma.us> Date: 30 Apr 91 14:22:06 GMT References: <1991Apr30.022048.4539@iecc.cambridge.ma.us> Sender: compilers-sender@iecc.cambridge.ma.us Reply-To: mike@vlsivie.tuwien.ac.at (Michael K. Gschwind) Organization: Vienna University of Technology Lines: 94 Approved: compilers@iecc.cambridge.ma.us In-Reply-To: lins@apple.com's message of 29 Apr 91 17: 54:04 GMT In article <1991Apr30.022048.4539@iecc.cambridge.ma.us> lins@apple.com (Chuck Lins) writes: >Does anyone know how nested procedures affect the ability to pass parameters >via registers? ... Well, there is an easy solution: just generate a list of all variables used by nested procedures - then you can store these (AND ONLY THESE, they are bound to be very few) in well-known stack locations. All other variables can be kept in registers and pronounced dead. In this set-up, a variable is dead, if *) it is dead in the procedure *) and +) either no nested procedures are called +) or the varaible is dead upon entry in this procedure There are two possibilities to act, if you know a parameter is going to be referenced in nested procedures. Either push it on the stack upon function entry or only if you're calling a nested procedure which uses it (You will need the transitive closure, I guess) - the latter mey be preferable in some circumstances, but the fromer is easier to implement: Just search the nested functions and check if the parameter is ever used. If so, reserve a stack slot and push immediately. PROCEDURE x( a, b, c ,d : integer) ; PROCEDURE y ( e,f,g : real); BEGIN write (a+f); END BEGIN if (d = 0) y(a,b,c); else write (a); END You either do: _x: /* a into well-know location, no need to save b,c,d */ st rA, fp+_a test rD jne @L1 return @L1: return Or: _x: test rD jne @L1 /* a into well-know loc */ st rA, fp+_a return @L1: return [Can one reference a named parameter in an enclosing procedure? If so, I can imagine that would force them onto the stack. -John] I dunno, but I guess so. Shouldn't be any complication in any case. Maybe somebody could check out the relevant facts? Register allocation across all nested functions is *) impossible in Pascal (since nested procedures may be transmitted via PROCEDURE parameters to non-related functions) and *) (I guess) not worthwhile in Modula-2 (where only top-level functions may be assigned to procedure-type variables - thus you can have a fall-back strategy for all top-level functions and thus restrict register allocation to a top-level function and all its nested functions) except if used with a global register allocation algorithm. BTW, does anybody know about compilers trying to find 'optimal' register assignment for top-level Modula-2 functions and all nested functions? Register allocation could probably done quite easily for such a block of related functions, as the only entry point from without this block is the top-level function. Thus the compiler knows all the places where the nested functions are called. Michael K. Gschwind, Dept. of VLSI-Design, Vienna University of Technology mike@vlsivie.tuwien.ac.at || mike@vlsivie.uucp Voice: (++43).1.58801 8144 || Fax: (++43).1.569697 -- Send compilers articles to compilers@iecc.cambridge.ma.us or {ima | spdcc | world}!iecc!compilers. Meta-mail to compilers-request.