阅读 GHC 核心 [英] Reading GHC Core
问题描述
Core 是 GHC 的中间语言.Reading Core 可以帮助您更好地了解程序的性能.有人向我索要有关阅读 Core 的文档或教程,但我找不到太多.
哪些文档可用于阅读 GHC Core?
这是我目前发现的:
- 密切相关.GHC 所做的所有 ,托尔马赫,2001 年
- 定期出现在 GHC 核心输出中,当你已经将你的 Haskell 优化到 GHC 知道的基本指令.primop 集作为一组核心函数在 一个预处理文件.
Core is GHC's intermediate language. Reading Core can help you better understand the performance of your program. Someone asked me for documentation or tutorials on reading Core, but I couldn't find much.
What documentation is available for reading GHC Core?
Here's what I've found so far:
- Write Haskell as fast as C: exploiting strictness, laziness and recursion
- Haskell as fast as C: working at a high altitude for low level performance
- RWH: Chapter 25. Profiling and optimization
- High-Performance Haskell talk at CUFP (slide 65-80)
解决方案GHC Core is the System FC language into which all Haskell is translated. The (approximate) grammar for Core is given by:
Core is closely related to the simpler and better known System F. All transformations GHC does on the Core level are type-preserving refactorings of this Core representation, to improve performance. And, not so well known, you can write directly in Core to program GHC.
GHC Core fits in the compiler pipeline (as it was in 2002, sans-LLVM and CMM):
The primary documents to learn about GHC Core are:
- An External Representation for the GHC Core Language, Tolmach, 2001
- ghc/compiler/CoreSyn, the GHC definition itself
- Secrets of the Glasgow Haskell Compiler inliner, Peyton Jones and Marlow, 1999. Core is described in Section 2.3, including details on the occurrence analysis annotations.
- A transformation-based optimiser for Haskell, Peyton Jones and Santos, 1998. Core is described in S3, including a discussion of polymorphism and operational readings of Core.
Related material that can aid understanding:
- The GHC -fext-core output
- I spent a lot of time learning Core by reading GHC source. Some is described in my undergraduate thesis from 2002, from page 16.
- From using the ghc-core tool, to generate Core in a format I find pleasing.
Core in turn is translated into STG code, which looks something like:
The funny names in Core are encoded in the "Z-encoding":
GHC Core's types and kinds (from Tolmach's paper):
Finally, GHC's primops appear regularly in GHC Core output, when you have optimized your Haskell down to the basic instructions GHC knows about. The primop set is given as a set of Core functions in a pre-processed file.
这篇关于阅读 GHC 核心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!