Re: Compiler Terminology

"journeyman" <journeyman@compilerguru.com>
15 Jul 2002 23:48:28 -0400

          From comp.compilers

Related articles
Compiler Terminology pgupt@ece.arizona.edu (Pallav Gupta) (2002-07-04)
Re: Compiler Terminology peter_flass@yahoo.com (Peter Flass) (2002-07-15)
Re: Compiler Terminology journeyman@compilerguru.com (journeyman) (2002-07-15)
| List of all articles for this month |

From: "journeyman" <journeyman@compilerguru.com>
Newsgroups: comp.compilers
Date: 15 Jul 2002 23:48:28 -0400
Organization: Giganews.Com - Premium News Outsourcing
References: 02-07-029
Keywords: registers, practice
Posted-Date: 15 Jul 2002 23:48:28 EDT

On 4 Jul 2002 23:18:35 -0400, Pallav Gupta <pgupt@ece.arizona.edu> wrote:
>I see three terms that describe how registers are to be used:
>
>1. clobbered list


List of registers that are used, that overwrite their previous value.


>2. used list


List of registers that are used (written), irrespective of whether the
register already held any meaningful value.


>3. args list


List of registers used to pass parameters to a function.


>Furthermore the restriction is clobbered list must be a subset of used
>list while args list should be a subset of the clobbered list.


If you're clobbering a register, you must by definition be using it.


I'm not sure about the args list, though. You have to be using a
slightly different definition than given here.


>Now my understanding is that between a function call, the compiler
>should generally save/restore ALL registers that the callee function
>uses. Correct? (Ofcourse there can be some global registers that need
>not be saved/restored say for instance the stack pointer)


False in general. It depends on arbitrarily chosen conventions. The
rules can be defined by the designer of the chip, the designer of the
operating system, or the designer of the compiler. Typically, you
have some registers that are called "scratch" or "caller-save", and
some registers that are "non-volatile" or "callee-save". Non-volatile
means that if you use the register, you have to save the original
value in the function prologue and restore in the epilogue. Scratch
means you can use it, but if you call a function, assume that the
value has been overwritten by the called function. If you need the
value, you (the caller) have to save it before the call and restore
after the call.


Why is it done this way? Flexibility. If you have a leaf function
(i.e. a function that doesn't call anything else), you just use the
scratch registers and don't have to worry about saving and restoring
their values. OTOH, if you need the values kept live across a
function call, you use the nonvolatile registers and if you're lucky,
the called function doesn't use them.


Otherwise, it doesn't really matter if you save them in the prolog or
just before the function is called (unless you care about code size,
in which case you'd want them saved once in the prolog rather than at
every call site).


Also, you have argument registers for the first few parameters of
a function. I'm not aware of any instance where they aren't also
considered scratch registers, but I don't see any reason why they
couldn't also be nonvolatile registers (well, except for the fact
that in practice it doesn't really make a lot of sense to save the
parameters).


There's the register you use to return the result of the function.
On some architectures, it's also one of the parameter registers,
on others, it's a different register.


One of the main design issues for these conventions is the number of
registers available in the architecture.


>The args list specifies (I think) the registers to be used in giving
>the argumetns to the function. What's the purpose of the clobbered
>list? It seems like this list tells teh calle function which registers
>it can use as scratch registsers (for computation within the
>function).
....
>So then if r41-r54 aren't clobbered what will they likely contain?
>Constants? or possibily just one assignment and then will never be
>used again throughout the rest of the function?


Ah, I think "clobbered" means "scratch": has nothing to do with
whether the register is used or not. Just that *if* it is used,
the original value doesn't have to be saved and restored. The
non-clobered register is what I'm calling non-volatile.


>In other words, whats the reason for making the clobbered list a
>subset (and not the whole list itself) of the used list?


Engineering tradeoff, as described above.


HTH,


Morris


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.