What is register scavenging?

Hi,

  I would like to know what register scavenging is, but reading
RegisterScavenging.h [1]
and googling don't help too much. Could someone explain it a little
bit (what it is and when
we need it), or point me to some nice link, I will be very appreciated. :slight_smile:

[1] http://llvm.org/docs/doxygen/html/RegisterScavenging_8h_source.html

Regards,
chenwj

Hi Chen,

  I would like to know what register scavenging is, but reading
RegisterScavenging.h [1] and googling don't help too much. Could someone explain it a little
bit (what it is and when we need it), or point me to some nice link, I will be very appreciated. :slight_smile:

It's a helper for passes that run after register allocation but still
need a new register they can use without breaking anything. It looks
around nearby instructions[*] to see if there's anything it can prove
is unused at the moment, and as a last ditch effort can spill
registers to the stack.

It's not commonly used (better to arrange to have a register allocated
for you if possible), but occasionally helpful in things like frame
lowering.

Cheers.

Tim.

[*] This is where the "scavenger" name comes from: hunting around for
discarded registers sort of like the animals.

It's a helper for passes that run after register allocation but still
need a new register they can use without breaking anything. It looks
around nearby instructions[*] to see if there's anything it can prove
is unused at the moment, and as a last ditch effort can spill
registers to the stack.

​I am reading TriCore document [1]​. It mention `eliminateFrameIndex`,
which is a pass after register allocation,
translates virtual stack slot reference to a register-offset pair. If the
offset is too large, additional instructions are
needed to compute the effective address, which need more register after the
register allocation. Now comes the
register scavenging.

Now I understand what it said after your help.

One last point, I am not native English speaker. By "as a last ditch
effort can spill registers to the stack.", you
mean if register scavenging cannot save us, then we have to do the spilling?

Thanks.

​[1]
https://wwwcip.informatik.uni-erlangen.de/~sicherha/foo/tricore-llvm.pdf​

Regards,
chenwj