<p>I have been trying to find a specification for Golang IR but I'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'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 "high-level" IR that is equal for every platform or am I misunderstanding what I'm reading?</p></pre>DenzelM: <pre><p>You are correct, there'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't know the full answer. There're definitely optimizations applied to SSA, and appears to be optimizations applied to the syntax DAG (such as constant folding), but I'm not entirely sure if they do any AST optimizations. Haven'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'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>