Skip to content

Latest commit

 

History

History
83 lines (64 loc) · 3.79 KB

compiler-ir.md

File metadata and controls

83 lines (64 loc) · 3.79 KB

Enso Compiler IR

Enso IR, currently implemented in Scala, with base class org.enso.compiler.core.IR, is created from the output of the native parser. The IR is an immutable annotated AST subjected to multiple passes. Every pass is a class implementing the org.enso.compiler.pass.IRPass interface.

See Runtime roadmap - static analysis for future goals.

Dumping IR

The IR can be visualized using the enso.compiler.dumpIr system property. The value of the property is a substring of a module name to dump. IRs are dumped into the IGV tool in a similar way to how GraalVM graphs are dumped, which is documented in enso4igv.

When using the enso.compiler.dumpIr property, one has to add --add-exports jdk.internal.vm.compiler/org.graalvm.graphio=org.enso.runtime.compiler.dump.igv to the JAVA_OPTS env var, because the IGV dumper uses an internal package of GraalVM JDK's module which is not exported by default.

Usage example:

$ env JAVA_OPTS='--add-exports jdk.internal.vm.compiler/org.graalvm.graphio=org.enso.runtime.compiler.dump.igv' ./built-distribution/*/bin/enso --vm.D enso.compiler.dumpIr=Vector --no-ir-caches --run tmp.enso

The IR graphs are dumped directly to IGV, if it is running, or to the ir-dumps directory in the BGV format.

Description of the graphs

For a module, multiple graphs are dumped. Names of the graphs correspond to the names of the Compiler passes, as can be seen on the screenshot: 1

Opening the first graph for the Vector module is overwhelming, since it has more than 3000 nodes: 2 However, nodes are structured in blocks. Blocks can be seen on the right side in the Control Flow tool window.

Zoom into a particular block:

  • Double-click on the block with id 1 in the Control Flow tool window.
  • Click on the Zoom to Selection button in the toolbar. 3

Below the tab, there are all the passes displayed as points (Phase toolbar). Hovering over a point shows the pass name: 4

Click-and-drag the mouse to select a region of passes. This will display the difference in the graph between those passes. In the following screenshot, we can see the difference between the very first pass, and MethodCalls pass: 5 Orange nodes represent those with changed properties.

Clicking on a single changed node, we can see that there is NEW_passData property: 6 In this case, we can see that AliasMetadata.ChildScope passData was added to that node between the selected passes.

In the following screenshot, we can see that the 8 Function$Lambda node was removed (displayed in red) between passes 15: AliasAnalysis and 18: SuspendedArguments: 7 Nodes that were added are displayed in green.

Clicking on a single node, the points representing passes in the Phase toolbar change colors:

  • White: No change
  • Orange: Property on the node changed.
  • Black: Node was removed
  • Green: Node was added 8