生存范围与达到定义

发布于 2024-07-15 22:51:04 字数 57 浏览 3 评论 0原文

在编译器数据流分析中,变量的生存范围和到达定义之间有什么区别? 两者似乎指的是同一件事......

In compiler data flow analysis, what is the difference between a live range of a variable and it's reaching definition? Both seem to refer to the same thing...

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

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

发布评论

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

评论(2

踏雪无痕 2024-07-22 22:51:04

到达定义是针对程序中的特定位置定义的。 例如,在第 10 行中,对于代码“a = b + c”,编译器了解“c”的到达定义是什么是有用的,或者换句话说,回答“变量 c 在哪个语句中获取 a”的问题。值可以达到第10行吗?”。

生存范围是根据变量定义的。 变量 c 的生存范围从变量 c 的定义开始,直到该变量的下一个定义(在该位置变量被杀死,或者定义为不同的变量,如果您使用 SSA),或者变量 c 的末尾。变量 c 存在的范围(块、函数或程序)。

这两个概念相似,但不是同一件事。

Reaching definitions are defined with respect to a particular place in a program. For example, in line 10, with code "a = b + c" it is useful for the compiler to know what the reaching definition of "c" is, or in other words answer the question "in what statement did variable c acquire a value that can reach line 10?".

Live range is defined with respect to a variable. The live range of variable c starts from a definition of variable c and goes until the next definition of the variable (in which place the variable gets killed, or defined as a different variable, if you are using SSA), or the end of the scope (block, function or program) that variable c exists.

The two concepts are similar, but they are not the same thing.

顾挽 2024-07-22 22:51:04

它们是非常不同的东西,我建议你回去重新阅读那些让你感到困惑的定义。 使用给定变量的点的变量的到达定义必须是该变量的定义。
变量的生命周期是程序中可以使用变量的部分,其中包括定义以外的内容,例如读取变量。

例如,参见 1986 年的《龙之书》,第 534 页(可能太笼统而没有帮助)和 610 页。

They’re very different things, and I suggest that you go back and reread whichever definitions confused you. A reaching definition of a variable for a point which uses the given variable must be, among other things, a definition of that variable.
The lifetime of a variable is the portion of the program in which it can be used, which includes things other than definitions, e.g., reading it.

See, for instance, the 1986 Dragon Book, pages 534 (perhaps too general to be helpful) and 610.

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