Next: , Previous: Register Basics, Up: Registers


17.7.2 寄存器的分配顺序

寄存器按照顺序进行分配。

— Macro: REG_ALLOC_ORDER

如果定义,则为一个整数向量的初始化值,包含了硬件寄存器号, GCC将按该照顺序来使用它们(前面的优先)。

如果没有定义该宏,则寄存器按照低编号优先的方式使用。

该宏的一个用处是在一些机器上, 高编号的寄存器必须总是被保存并且save-multiple-registers指令 只支持连续序列的寄存器。在这些机器上, 可以定义REG_ALLOC_ORDER来初始化列表, 使得高编号寄存器优先分配。

— Macro: ADJUST_REG_ALLOC_ORDER

A C statement (sans semicolon) to choose the order in which to allocate hard registers for pseudo-registers local to a basic block.

Store the desired register order in the array reg_alloc_order. Element 0 should be the register to allocate first; element 1, the next register; and so on.

The macro body should not assume anything about the contents of reg_alloc_order before execution of the macro.

On most machines, it is not necessary to define this macro.

— Macro: HONOR_REG_ALLOC_ORDER

Normally, IRA tries to estimate the costs for saving a register in the prologue and restoring it in the epilogue. This discourages it from using call-saved registers. If a machine wants to ensure that IRA allocates registers in the order given by REG_ALLOC_ORDER even if some call-saved registers appear earlier than call-used ones, this macro should be defined.

— Macro: IRA_HARD_REGNO_ADD_COST_MULTIPLIER (regno)

In some case register allocation order is not enough for the Integrated Register Allocator (IRA) to generate a good code. If this macro is defined, it should return a floating point value based on regno. The cost of using regno for a pseudo will be increased by approximately the pseudo's usage frequency times the value returned by this macro. Not defining this macro is equivalent to having it always return 0.0.

在大多数机器上,不需要定义该宏。