寄存器和临时寄存器有什么区别?

发布于 2024-10-07 02:58:21 字数 356 浏览 0 评论 0原文

Valgrind 使用中间代码表示来让我们检测二进制代码,这样我们就不必处​​理编程语言级别的构造。在将二进制代码转换为 Valgrind 的中间表示 (IR) 代码的过程中,它显示了使用寄存器进行加法等操作。正在使用的寄存器有 1024 个。我没有得到的是另一种类型的寄存器,称为临时寄存器,表示为 tX,其中 X 是某个数字。因此,我可以看到:

t28 = Add32(t26,0xFFFFFFFC:I32)
t4 = LDle:I32(t28)

t 表示临时寄存器。据我所知,它们的行为似乎与常规寄存器非常相似,但无法弄清楚它们有何不同。有人可以告诉我什么是临时寄存器以及它与常规寄存器有何不同?

Valgrind uses an intermediate code representation to let us instrument binary code so that we don't have to deal with programming language level constructs. In the process of converting binary code into Valgrind's Intermediate Representation (IR) code, it shows the use of registers for operations like additions etc. There are 1024 of these that are being used. What I don't get is another type of registers called temporary registers represented as tX where X is some number. Thus, I can see this:

t28 = Add32(t26,0xFFFFFFFC:I32)
t4 = LDle:I32(t28)

t meaning a temporary register. As far as I can see, they seem to behave very similar to regular registers but am not able to figure out how they are different. Can someone tell me what a temporary register is and how it differs from a regular register?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蔚蓝源自深海 2024-10-14 02:58:21

在编译器构造课上,我被告知中间代码中的寄存器是虚拟寄存器。它们不一定与目标平台的可执行文件有任何关系。它们可以是真实的 CPU 寄存器,也可以是内存中的临时寄存器。这一切都取决于代码生成器和优化器。代码生成器决定临时变量应该分配到哪里。

生成IR的一个重要原因是为了最大化编译器的可移植性。您可以为所有平台使用一个编译器前端,然后将 IR 传递到特定于平台的代码生成器。 GCC 就是这样工作的,而且我确信大多数(如果不是全部)像样的编译器都是这样工作的。

另一个好处是,您可以在将 IR 代码发送到代码生成器之前对其执行某些优化。有些优化不是特定于平台的:例如,不受循环影响的代码可以从循环中取出。平台优化器通常在较低级别上进行优化,例如寄存器分配、分支等,这些内容实际上取决于 CPU 的属性。

In compiler construction class I was taught that registers in intermediate code are virtual registers. They don't necessarily have anything to do with the executable for the target platform. They could be real CPU registers, or they can be temporaries in memory. It all depends on the code generator and the optimizer. It is the code generator that decides where the temporaries should be allocated.

A big reason for generating IR is to maximize the portability of the compiler. You can use one compiler front end for all platforms, and then pass the IR to platform specific code generators. GCC works this way, and I'm sure most, if not all, decent compilers work this way.

Another benefit is that you can perform certain optimizations on the IR code, before it is sent to the code generator. Some optimizations are not platform specific: for instance, code that aren't affected by a loop, can be pulled out of the loop. The platform optimizer typically optimizes on a lower level such as register allocation, branching, etc, stuff that really depends on the properties of the CPU.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文