确定性函数的编译器优化

发布于 2024-11-09 20:00:56 字数 167 浏览 0 评论 0原文

我正在阅读有关确定性执行的内容,即对于相同的输入,您有相同的输出。我想知道是否有编译器编写者考虑过在运行时优化确定性函数。 例如,采用阶乘函数。如果在运行时,检测到连续使用相同的输入值调用它,编译器可以缓存输出值,并且可以直接使用该输出值,而不是执行阶乘函数。看起来是一个不错的研究课题。有关于这个主题的论文或工作吗?

I was reading about Deterministic Execution, which is that for the same input, you have the same output. I was wondering whether any compiler writer has thought about optimizing deterministic functions at runtime.
For example, take the factorial function. If at runtime, it is detected that it is continuously being called with the same input value, the compiler can cache the output value and instead of executing the factorial function, can directly use that output value. Seems like a nice research topic. Are there any papers or work on this topic?

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

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

发布评论

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

评论(4

孤独患者 2024-11-16 20:00:56

这通常称为记忆化,是函数式语言中相当常见的优化。

This is usually called memoization, and is a fairly common optimization in functional languages.

终陌 2024-11-16 20:00:56

这是可以做到的,但据我所知,编译器这样做并不常见。问题在于,用户可以按照自己喜欢的方式定义任意数量的类型和相等性,而使用堆分配和其他东西来证明这样的事情是非常非常困难的。基本上,这是可以完成的,但前提是您的函数涉及直接数值计算,这种情况很少见,因此通常价值不高。

It can be done but as far as I know, it's not common for compilers to do it. The trouble is that users can define as many types as they like and equality in any way that they like, and with heap allocation and stuff it's very, very difficult to prove such a thing. Basically, it could be done, but only if your function involves straight numerical computation, which is rare, and thus it's usually not of high value.

谜兔 2024-11-16 20:00:56

您正在谈论引用透明度。它是函数式编程的重要组成部分。

http://en.wikipedia.org/wiki/Referential_transparency_(computer_science)

You're talking about referential transparency. And it's a big part of functional programming.

http://en.wikipedia.org/wiki/Referential_transparency_(computer_science)

手心的温暖 2024-11-16 20:00:56

http://blogs.msdn.com/b/vcblog /archive/2008/11/12/pogo.aspx 讨论配置文件引导优化。

本身并没有回答您的问题,但一般讨论使用运行时行为来优化程序集

http://blogs.msdn.com/b/vcblog/archive/2008/11/12/pogo.aspx talks about profile guided optimization.

doesnot answer your questions per se but in general talks about using runtime behavior to optimize assembly

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