Next: , Previous: Frame Registers, Up: Stack and Calling


17.10.5 消除帧指针和参数指针

这些是关于消除帧指针和参数指针的。

— Target Hook: bool TARGET_FRAME_POINTER_REQUIRED (void)

This target hook should return true if a function must have and use a frame pointer. This target hook is called in the reload pass. If its return value is true the function will have a frame pointer.

This target hook can in principle examine the current function and decide according to the facts, but on most machines the constant false or the constant true suffices. Use false when the machine allows code to be generated with no frame pointer, and doing so saves some time or space. Use true when there is no possible advantage to avoiding a frame pointer.

In certain cases, the compiler does not know how to produce valid code without a frame pointer. The compiler recognizes those cases and automatically gives the function a frame pointer regardless of what TARGET_FRAME_POINTER_REQUIRED returns. You don't need to worry about them.

In a function that does not require a frame pointer, the frame pointer register can be allocated for ordinary usage, unless you mark it as a fixed register. See FIXED_REGISTERS for more information.

Default return value is false.

— Macro: INITIAL_FRAME_POINTER_OFFSET (depth-var)

一条C语句,用来紧接着函数序言之后, 将帧指针和栈指针值的差存储在depth-var中。 该值应该通过像get_frame_size ()这样的结果信息以及寄存器表 regs_ever_livecall_used_regs中被计算。

如果ELIMINABLE_REGS被定义,则该宏将不被使用并不需要被定义。 否则,其必须被定义,即使FRAME_POINTER_REQUIRED被定义为总是为真; 这这种情况下,你可以设置depth-var为任何值。

— Macro: ELIMINABLE_REGS

如果被定义,则该宏指定了一个寄存器双对的表,用于消除不需要的指向栈帧的寄存器。 如果没有被定义,则编译器唯一尝试去做的消除是将对帧指针的引用替换为对栈指针的引用。

该宏的定义为一个结构体初始化列表,每个指定了最初的和替换后的寄存器。

在一些机器上,参数指针的位置直到编译结束时才知道。这种情况下, 一个单独的硬件寄存器必须用于参数指针。 该寄存器可以通过替换为帧指针或者参数指针来消除,这取决于帧指针是否已经被消除。

这种情况下,你可能会指定:

          #define ELIMINABLE_REGS  \
          {{ARG_POINTER_REGNUM, STACK_POINTER_REGNUM}, \
           {ARG_POINTER_REGNUM, FRAME_POINTER_REGNUM}, \
           {FRAME_POINTER_REGNUM, STACK_POINTER_REGNUM}}

注意首先指定的是使用栈指针来消除参数指针,因为这是首选的消除方式。

— Target Hook: bool TARGET_CAN_ELIMINATE (const int from_reg, const int to_reg)

This target hook should returns true if the compiler is allowed to try to replace register number from_reg with register number to_reg. This target hook need only be defined if ELIMINABLE_REGS is defined, and will usually be true, since most of the cases preventing register elimination are things that the compiler already knows about.

Default return value is true.

— Macro: INITIAL_ELIMINATION_OFFSET (from-reg, to-reg, offset-var)

该宏类似于INITIAL_FRAME_POINTER_OFFSET。 其指定了被指定的寄存器双对的初始差。该宏必须被定义, 如果ELIMINABLE_REGS被定义。