试图理解 gcc 选项 -fomit-frame-pointer [英] Trying to understand gcc option -fomit-frame-pointer

查看:34
本文介绍了试图理解 gcc 选项 -fomit-frame-pointer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要求 Google 给我 gcc 选项 -fomit-frame-pointer 的含义,它将我重定向到以下语句.

I asked Google to give me the meaning of the gcc option -fomit-frame-pointer, which redirects me to the below statement.

-fomit-frame-pointer

不要将帧指针保存在不需要的函数的寄存器中.这避免了保存、设置和恢复帧指针的指令;它还为许多功能提供了一个额外的寄存器.这也使得在某些机器上无法进行调试.

Don't keep the frame pointer in a register for functions that don't need one. This avoids the instructions to save, set up and restore frame pointers; it also makes an extra register available in many functions. It also makes debugging impossible on some machines.

根据我对每个函数的了解,会在进程内存的堆栈中创建一个激活记录,以保存所有局部变量和一些更多信息.我希望这个帧指针是一个函数的激活记录的地址.

As per my knowledge of each function, an activation record will be created in the stack of the process memory to keep all local variables and some more information. I hope this frame pointer means the address of the activation record of a function.

在这种情况下,哪些函数类型不需要将帧指针保存在寄存器中?如果我得到这些信息,我将尝试基于该信息(如果可能)设计新函数,因为如果帧指针未保存在寄存器中,则某些指令将以二进制形式省略.在功能众多的应用程序中,这确实会显着提高性能.

In this case, what are the type of functions, for which it doesn't need to keep the frame pointer in a register? If I get this information, I will try to design the new function based on that (if possible) because if the frame pointer is not kept in registers, some instructions will be omitted in binary. This will really improve the performance noticeably in an application where there are many functions.

推荐答案

大多数较小的函数不需要框架指针 - 较大的函数可能需要一个.

Most smaller functions don't need a frame pointer - larger functions MAY need one.

这实际上是关于编译器如何设法跟踪堆栈的使用方式以及堆栈中的内容(局部变量、传递给当前函数的参数以及为即将被调用的函数准备的参数).我认为描述需要或不需要帧指针的函数并不容易(从技术上讲,没有函数必须有帧指针——这更像是如果编译器认为有必要降低其他代码").

It's really about how well the compiler manages to track how the stack is used, and where things are on the stack (local variables, arguments passed to the current function and arguments being prepared for a function about to be called). I don't think it's easy to characterize the functions that need or don't need a frame pointer (technically, NO function HAS to have a frame pointer - it's more a case of "if the compiler deems it necessary to reduce the complexity of other code").

我不认为你应该尝试让函数没有帧指针"作为你编码策略的一部分——就像我说的,简单的函数不需要它们,所以使用 -fomit-frame-pointer,您将获得一个可用于寄存器分配器的寄存器,并在进入/退出函数时节省 1-3 条指令.如果您的函数需要帧指针,那是因为编译器认为这是比不使用帧指针更好的选择.拥有没有帧指针的函数并不是目标,目标是让代码既正确又快速地工作.

I don't think you should "attempt to make functions not have a frame pointer" as part of your strategy for coding - like I said, simple functions don't need them, so use -fomit-frame-pointer, and you'll get one more register available for the register allocator, and save 1-3 instructions on entry/exit to functions. If your function needs a frame pointer, it's because the compiler decides that's a better option than not using a frame pointer. It's not a goal to have functions without a frame pointer, it's a goal to have code that works both correctly and fast.

请注意,没有帧指针"应该会提供更好的性能,但这并不是带来巨大改进的灵丹妙药——尤其是在 x86-64 上,它已经有 16 个寄存器.在 32 位 x86 上,因为它只有 8 个寄存器,其中一个是堆栈指针,占用另一个作为帧指针意味着占用了 25% 的寄存器空间.将其更改为 12.5% 是一个相当大的改进.当然,为 64 位编译也会有很大帮助.

Note that "not having a frame pointer" should give better performance, but it's not some magic bullet that gives enormous improvements - particularly not on x86-64, which already has 16 registers to start with. On 32-bit x86, since it only has 8 registers, one of which is the stack pointer, and taking up another as the frame pointer means 25% of register-space is taken. To change that to 12.5% is quite an improvement. Of course, compiling for 64-bit will help quite a lot too.

这篇关于试图理解 gcc 选项 -fomit-frame-pointer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆