Golang IR

xuanbao · · 715 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I have been trying to find a specification for Golang IR but I&#39;m not able to find anything. I found this: <a href="https://golang.org/doc/asm" rel="nofollow">https://golang.org/doc/asm</a>, but it&#39;s just assembly. Does Golang have an IR? Is there a specification for it?</p> <hr/>**评论:**<br/><br/>albgr03: <pre><p>Golang IR is the assembly described on the page you found</p></pre>maaarcocr: <pre><p>Okay, thanks. While reading the page, I noticed that there are some platform specific instructions, does this means that there is no &#34;high-level&#34; IR that is equal for every platform or am I misunderstanding what I&#39;m reading?</p></pre>DenzelM: <pre><p>You are correct, there&#39;s no high-level IR. Go parses into an AST; lowers that into a syntax directed-acyclic-graph (DAG); lowers that into SSA form; and then finally generates platform-specific code from the SSA. At no point does Go generate what you and I would consider a high-level IR, like LLVM for example.</p></pre>maaarcocr: <pre><p>Thanks for the explanation! Just out of curiosity, how are optimisations applied? Are they applied on the SSA form? </p></pre>DenzelM: <pre><p>Good question: I don&#39;t know the full answer. There&#39;re definitely optimizations applied to SSA, and appears to be optimizations applied to the syntax DAG (such as constant folding), but I&#39;m not entirely sure if they do any AST optimizations. Haven&#39;t really gone that in-depth.</p> <p>If you want to have a look for yourself, the majority of the code can be found here in <a href="https://github.com/golang/go/tree/master/src/cmd/compile/internal/gc" rel="nofollow">gc</a> and <a href="https://github.com/golang/go/tree/master/src/cmd/compile/internal/ssa" rel="nofollow">ssa</a> (here&#39;s the <a href="https://github.com/golang/go/blob/master/src/cmd/compile/internal/gc/const.go" rel="nofollow">constant folding routines</a> for example).</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

715 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传