annotate doc/design/graal_compiler.tex @ 2679:07aa0a31fffb

Rewrote frame state to be not-so-Java-specific. Clarified and reduced the usage of the term "node".
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Mon, 16 May 2011 14:29:12 +0200
parents b9b0a0aa7ee8
children c5739b99762a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2517
8c6e31c62fba added initial version of design docs, fixed .hgignore (regex, . -> \.)
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
1 \documentclass[twocolumn]{svjour3}
2678
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
2 \usepackage{listings}
2517
8c6e31c62fba added initial version of design docs, fixed .hgignore (regex, . -> \.)
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
3 \usepackage[pdftex]{graphicx}
8c6e31c62fba added initial version of design docs, fixed .hgignore (regex, . -> \.)
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
4 \usepackage{environ}
8c6e31c62fba added initial version of design docs, fixed .hgignore (regex, . -> \.)
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
5 \usepackage{amsmath}
8c6e31c62fba added initial version of design docs, fixed .hgignore (regex, . -> \.)
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
6 \usepackage{amsfonts}
8c6e31c62fba added initial version of design docs, fixed .hgignore (regex, . -> \.)
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
7 \usepackage[english]{babel}
8c6e31c62fba added initial version of design docs, fixed .hgignore (regex, . -> \.)
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
8 \usepackage[utf8]{inputenc}
8c6e31c62fba added initial version of design docs, fixed .hgignore (regex, . -> \.)
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
9 \usepackage{lmodern}
8c6e31c62fba added initial version of design docs, fixed .hgignore (regex, . -> \.)
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
10 \usepackage[T1]{fontenc}
8c6e31c62fba added initial version of design docs, fixed .hgignore (regex, . -> \.)
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
11 \usepackage{color}
8c6e31c62fba added initial version of design docs, fixed .hgignore (regex, . -> \.)
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
12
8c6e31c62fba added initial version of design docs, fixed .hgignore (regex, . -> \.)
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
13 \input{graphdrawing}
8c6e31c62fba added initial version of design docs, fixed .hgignore (regex, . -> \.)
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
14
8c6e31c62fba added initial version of design docs, fixed .hgignore (regex, . -> \.)
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
15 \renewcommand*\descriptionlabel[1]{\hspace\labelsep\normalfont\bf #1}
8c6e31c62fba added initial version of design docs, fixed .hgignore (regex, . -> \.)
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
16
8c6e31c62fba added initial version of design docs, fixed .hgignore (regex, . -> \.)
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
17 \newcommand{\Sa}{{\Large$^*$}}
8c6e31c62fba added initial version of design docs, fixed .hgignore (regex, . -> \.)
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
18 \newcommand{\Sb}{{\Large$^\dag$}}
8c6e31c62fba added initial version of design docs, fixed .hgignore (regex, . -> \.)
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
19 \newcommand{\Sc}{{\Large$^\S$}}
8c6e31c62fba added initial version of design docs, fixed .hgignore (regex, . -> \.)
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
20
2562
0023bd42eefe comments
christian.wimmer@oracle.com
parents: 2561
diff changeset
21
0023bd42eefe comments
christian.wimmer@oracle.com
parents: 2561
diff changeset
22 \newcommand{\mynote}[2]{
0023bd42eefe comments
christian.wimmer@oracle.com
parents: 2561
diff changeset
23 \textcolor{red}{\fbox{\bfseries\sffamily\scriptsize#1}
0023bd42eefe comments
christian.wimmer@oracle.com
parents: 2561
diff changeset
24 {\small\textsf{\emph{#2}}}
0023bd42eefe comments
christian.wimmer@oracle.com
parents: 2561
diff changeset
25 \fbox{\bfseries\sffamily\scriptsize }}}
0023bd42eefe comments
christian.wimmer@oracle.com
parents: 2561
diff changeset
26
0023bd42eefe comments
christian.wimmer@oracle.com
parents: 2561
diff changeset
27 \newcommand\TODO[1]{\mynote{TODO}{#1}}
0023bd42eefe comments
christian.wimmer@oracle.com
parents: 2561
diff changeset
28 \newcommand\cw[1]{\mynote{CW}{#1}}
2576
c59db1f02893 doc: expanded framestate section
Lukas Stadler <lukas.stadler@jku.at>
parents: 2569
diff changeset
29 \newcommand\ls[1]{\mynote{LS}{#1}}
2573
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
30 \newcommand\nodename[1]{\texttt{#1}}
2562
0023bd42eefe comments
christian.wimmer@oracle.com
parents: 2561
diff changeset
31
0023bd42eefe comments
christian.wimmer@oracle.com
parents: 2561
diff changeset
32
0023bd42eefe comments
christian.wimmer@oracle.com
parents: 2561
diff changeset
33
2517
8c6e31c62fba added initial version of design docs, fixed .hgignore (regex, . -> \.)
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
34 \smartqed % flush right qed marks, e.g. at end of proof
8c6e31c62fba added initial version of design docs, fixed .hgignore (regex, . -> \.)
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
35
8c6e31c62fba added initial version of design docs, fixed .hgignore (regex, . -> \.)
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
36 \journalname{Graal Compiler Design}
8c6e31c62fba added initial version of design docs, fixed .hgignore (regex, . -> \.)
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
37 \def\makeheadbox{{%
8c6e31c62fba added initial version of design docs, fixed .hgignore (regex, . -> \.)
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
38 \hbox to0pt{\vbox{\baselineskip=10dd\hrule\hbox
8c6e31c62fba added initial version of design docs, fixed .hgignore (regex, . -> \.)
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
39 to\hsize{\vrule\kern3pt\vbox{\kern3pt
8c6e31c62fba added initial version of design docs, fixed .hgignore (regex, . -> \.)
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
40 \hbox{\bfseries The Graal Compiler - Design and Strategy}
8c6e31c62fba added initial version of design docs, fixed .hgignore (regex, . -> \.)
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
41 \kern3pt}\hfil\kern3pt\vrule}\hrule}%
8c6e31c62fba added initial version of design docs, fixed .hgignore (regex, . -> \.)
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
42 \hss}}}
8c6e31c62fba added initial version of design docs, fixed .hgignore (regex, . -> \.)
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
43
8c6e31c62fba added initial version of design docs, fixed .hgignore (regex, . -> \.)
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
44 \begin{document}
8c6e31c62fba added initial version of design docs, fixed .hgignore (regex, . -> \.)
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
45
2561
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
46 \author{Thomas W\"{u}rthinger \Sa, Lukas Stadler \Sc, Gilles Duboscq \Sa}
2517
8c6e31c62fba added initial version of design docs, fixed .hgignore (regex, . -> \.)
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
47 \institute{\Sa Oracle, \Sc Johannes Kepler University, Linz}
8c6e31c62fba added initial version of design docs, fixed .hgignore (regex, . -> \.)
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
48
8c6e31c62fba added initial version of design docs, fixed .hgignore (regex, . -> \.)
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
49 \date{Created: \today}
8c6e31c62fba added initial version of design docs, fixed .hgignore (regex, . -> \.)
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
50
8c6e31c62fba added initial version of design docs, fixed .hgignore (regex, . -> \.)
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
51 \title{The Graal Compiler}
2604
c9b17ac5c06b Doc fixes.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2598
diff changeset
52 \subtitle{Design and Strategy \\ \textcolor{red}{work in progress (Oracle internal)}}
2517
8c6e31c62fba added initial version of design docs, fixed .hgignore (regex, . -> \.)
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
53
8c6e31c62fba added initial version of design docs, fixed .hgignore (regex, . -> \.)
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
54 \maketitle
8c6e31c62fba added initial version of design docs, fixed .hgignore (regex, . -> \.)
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
55
2561
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
56 \abstract{
2589
795df30f979d Refer to "Graal compiler" as "the compiler" in the design document.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2588
diff changeset
57 The Graal compiler (simply referred to as \emph{the compiler} in the rest of this document) aims at improving C1X, the Java port of the HotSpot client compiler, both in terms of modularity and peak performance.
2561
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
58 The compiler should work with the Maxine VM and the HotSpot VM.
2589
795df30f979d Refer to "Graal compiler" as "the compiler" in the design document.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2588
diff changeset
59 This document contains information about the proposed design and strategy for developing the compiler.}
2561
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
60
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
61 \section{Context}
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
62
2618
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
63 In 2009, the Maxine team started with creating C1X, a Java port of the HotSpot client compiler, and integrated it into the Maxine VM.
2604
c9b17ac5c06b Doc fixes.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2598
diff changeset
64 Part of this effort was the development of a clear and clean compiler-runtime interface that allows the separation of the compiler and the VM.
c9b17ac5c06b Doc fixes.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2598
diff changeset
65 This compiler-runtime interface enables the use of one compiler for multiple VMs.
2561
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
66 In June 2010, we started integrating C1X into the HotSpot VM and we called the resulting system Graal~VM.
2618
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
67 Currently, the Graal~VM is fully functional and runs benchmarks (SciMark, DaCapo) at a similar speed as the HotSpot client compiler.
2561
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
68
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
69 \section{Goals}
2589
795df30f979d Refer to "Graal compiler" as "the compiler" in the design document.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2588
diff changeset
70 The compiler effort aims at rewriting the high-level intermediate representation of C1X with two main goals:
2561
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
71 \begin{description}
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
72 \item[Modularity:] A modular design of the compiler should simplify the implementation of new languages, new back-ends, and new optimizations.
2618
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
73 \item[Peak Performance:] A more powerful intermediate representation should enable the implementation of aggressive optimizations that impact the peak performance of the resulting machine code.
2561
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
74 \end{description}
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
75
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
76 \section{Design}
2589
795df30f979d Refer to "Graal compiler" as "the compiler" in the design document.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2588
diff changeset
77 For the implementation of the compiler, we rely on the following design decisions:
2561
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
78 \begin{description}
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
79 \item[Graph Representation:]
2562
0023bd42eefe comments
christian.wimmer@oracle.com
parents: 2561
diff changeset
80 The compiler's intermediate representation is modeled as a graph with nodes that are connected with directed edges.
2561
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
81 There is only a single node base class and every node has an associated graph object that does not change during the node's lifetime.
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
82 Every node is serializable and has an id that is unique within its graph.
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
83 Every edge is classified as either a control flow edge (anti-dependency) or a data flow edge (dependency) and represented as a simple pointer from the source node to the target node.
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
84 It is possible to replace a node with another node without traversing the full graph.
2588
26ecba0ead6d Update on doc.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2578
diff changeset
85 The graph does not allow data flow edge cycles or control flow edge cycles.
26ecba0ead6d Update on doc.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2578
diff changeset
86 We achieve this by explicitely modelling loops (see Section~\ref{sec:loops}).
2561
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
87 \item[Extensibility:]
2618
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
88 The compiler is extensible by allowing developers to add new compiler phases and new node subclasses without modifying the compiler's sources.
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
89 A node has an abstract way of expressing its semantics and new compiler phases can ask compiler nodes for their properties and capabilities.
2588
26ecba0ead6d Update on doc.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2578
diff changeset
90 We use the ``everything is an extension'' concept.
26ecba0ead6d Update on doc.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2578
diff changeset
91 Even standard compiler optimizations are internally modeled as extensions, to show that the extension mechanism exposes all necessary functionality.
2561
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
92 \item[Detailing:]
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
93 The compilation starts with a graph that contains nodes that represent the operations of the source language (e.g., one node for an array store to an object array).
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
94 During the compilation, the nodes are replaced with more detailed nodes (e.g., the array store node is split into a null check, a bounds check, a store check, and a memory access).
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
95 Compiler phases can choose whether they want to work on the earlier versions of the graph (e.g., escape analysis) or on later versions (e.g., null check elimination).
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
96 \item[Generality:]
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
97 The compiler does not require Java as its input.
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
98 This is achieved by having a graph as the starting point of the compilation and not a Java bytecodes array.
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
99 Building the graph from the Java bytecodes must happen before giving a method to the compiler.
2618
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
100 This enables front-ends for different languages (e.g., Ruby or JavaScript) to provide their own graph.
2561
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
101 Also, there is no dependency on a specific back-end, but the output of the compiler is a graph that can then be converted to a different representation in a final compiler phase.
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
102 \end{description}
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
103
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
104 \section{Milestones}
2597
08cda6637103 More doc + conclusion.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2591
diff changeset
105 \label{sec:mile}
2589
795df30f979d Refer to "Graal compiler" as "the compiler" in the design document.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2588
diff changeset
106 The compiler is developed starting from the current C1X source code base.
2561
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
107 This helps us testing the compiler at every intermediate development step on a variety of Java benchmarks.
2618
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
108 We define the following development milestones and when they are considered to be achieved (see Section~\ref{sec:conclusions} for planned dates):
2561
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
109 \begin{description}
2589
795df30f979d Refer to "Graal compiler" as "the compiler" in the design document.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2588
diff changeset
110 \item[M1:] We have a fully working Graal~VM version with a stripped down C1X compiler that does not perform any optimizations.
795df30f979d Refer to "Graal compiler" as "the compiler" in the design document.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2588
diff changeset
111 \item[M2:] We modified the high-level intermediate representation to be based on the compiler graph data structure.
795df30f979d Refer to "Graal compiler" as "the compiler" in the design document.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2588
diff changeset
112 \item[M3:] We have reimplemented and reenabled compiler optimizations in the compiler that previously existed in C1X.
795df30f979d Refer to "Graal compiler" as "the compiler" in the design document.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2588
diff changeset
113 \item[M4:] We have reintegrated the new compiler into the Maxine VM and can use it as a Maxine VM bootstrapping compiler.
2561
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
114 \end{description}
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
115
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
116 After those four milestones, we see three different possible further development directions that can be followed in parallel:
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
117 \begin{itemize}
2589
795df30f979d Refer to "Graal compiler" as "the compiler" in the design document.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2588
diff changeset
118 \item Removal of the XIR template mechanism and replacement with a snippet mechanism that works with the compiler graph.
795df30f979d Refer to "Graal compiler" as "the compiler" in the design document.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2588
diff changeset
119 \item Improvements for peak performance (loop optimizations, escape analysis, bounds check elimination, processing additional interpreter runtime feedback).
2604
c9b17ac5c06b Doc fixes.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2598
diff changeset
120 \item Implementation of a prototype front-end for a different language, e.g., JavaScript.
2561
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
121 \end{itemize}
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
122
2678
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
123 \section{Project Source Structure}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
124 In order to support the goal of a modular compiler, the code will be divided into the following source code projects (as subprojects of \textbf{com.oracle.max.graal}).
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
125
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
126 \begin{description}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
127 \item[graph] contains the abstract node implementation, the graph implementation and all the associated tools and auxiliary classes.
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
128 \item[nodes] contains the implementation of known basic nodes (e.g., phi nodes, control flow nodes, \ldots).
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
129 Additional node classes should go into separate projects and be specializations of the known basic nodes.
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
130 \item[java] contains code for building graphs from Java bytecodes and Java-specific nodes.
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
131 \item[opt] contains optimizations such as global value numbering or conditional constant propagation.
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
132 \item[compiler] contains the compiler, including:
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
133 \begin{itemize}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
134 \item Scheduling of the compilation phases.
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
135 \item Implementation of the \emph{compiler interface} (CI).
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
136 \item Implementation of the final compilation phase that produces the low-level representation.
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
137 \item Machine code creation, including debug info.
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
138 \end{itemize}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
139 \end{description}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
140
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
141
2597
08cda6637103 More doc + conclusion.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2591
diff changeset
142 \section{Graph}
2589
795df30f979d Refer to "Graal compiler" as "the compiler" in the design document.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2588
diff changeset
143
2597
08cda6637103 More doc + conclusion.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2591
diff changeset
144 The \emph{intermediate representation}~(IR) of the compiler is designed as a directed graph.
2604
c9b17ac5c06b Doc fixes.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2598
diff changeset
145 The graph deals out ids for new nodes and can be queried for the node corresponding to a given id as well as for an unordered list of nodes of the graph.
2597
08cda6637103 More doc + conclusion.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2591
diff changeset
146 Graphs can manage side data structures, which will be automatically invalidated and lazily recomputed whenever the graph changes. Examples for side data structures are dominator trees and temporary schedules. These side data structures will usually be understood by more than one optimization.
2589
795df30f979d Refer to "Graal compiler" as "the compiler" in the design document.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2588
diff changeset
147
2597
08cda6637103 More doc + conclusion.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2591
diff changeset
148 The nodes of the graph have the following properties:
2589
795df30f979d Refer to "Graal compiler" as "the compiler" in the design document.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2588
diff changeset
149 \begin{itemize}
2597
08cda6637103 More doc + conclusion.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2591
diff changeset
150 \item Each node is always associated with a single graph and this association is immutable.
08cda6637103 More doc + conclusion.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2591
diff changeset
151 \item Each node has an immutable id that is unique within its associated graph.
2604
c9b17ac5c06b Doc fixes.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2598
diff changeset
152 \item Nodes can have a data dependency, which means that one node requires the result of another node as its input. The fact that the result of the first node needs to be computed before the second node can be executed introduces a partial order to the set of nodes.
2597
08cda6637103 More doc + conclusion.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2591
diff changeset
153 \item Nodes can have a control flow dependency, which means that the execution of one node will be followed by the execution of another node. This includes conditional execution, memory access serialization and other reasons, and again introduces a partial order to the set of nodes.
2589
795df30f979d Refer to "Graal compiler" as "the compiler" in the design document.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2588
diff changeset
154 \item Nodes can only have data and control dependencies to nodes which belong to the same graph.
2618
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
155 \item Control dependencies and data dependencies each represent a \emph{directed acyclic graph} (DAG) on the same set of nodes. This means that data dependencies always point upwards, and control dependencies always point downwards in a drawing of the graph. Situations that normally incur cycles (like loops) are represented by special nodes (see Section~\ref{sec:loops}).
2619
1586b1b56f0c Fixed typo.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2618
diff changeset
156 \item Ordering between nodes is specified only to the extent which is required to correctly express the semantics of a given program. This gives the compiler flexibility for the possible scheduling of a node and therefore wiggle room for optimizations. For algorithms that require a fixed ordering of nodes, a temporary schedule can always be generated.
2597
08cda6637103 More doc + conclusion.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2591
diff changeset
157 \item Both data and control dependencies can be traversed in both directions, so that each node can be traversed in four directions (see Figure~\ref{fig:directions}):
2589
795df30f979d Refer to "Graal compiler" as "the compiler" in the design document.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2588
diff changeset
158 \begin{itemize}
795df30f979d Refer to "Graal compiler" as "the compiler" in the design document.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2588
diff changeset
159 \item \emph{inputs} are all nodes that this node has data dependencies on.
2604
c9b17ac5c06b Doc fixes.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2598
diff changeset
160 \item \emph{usages} are all nodes whose inputs contain this node.
c9b17ac5c06b Doc fixes.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2598
diff changeset
161 \item \emph{successors} are all nodes that have to be after this node in control flow.
c9b17ac5c06b Doc fixes.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2598
diff changeset
162 \item \emph{predecessors} are all nodes whose successors contain this node.
2589
795df30f979d Refer to "Graal compiler" as "the compiler" in the design document.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2588
diff changeset
163 \end{itemize}
795df30f979d Refer to "Graal compiler" as "the compiler" in the design document.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2588
diff changeset
164 \item Only inputs and successors can be changed, and changes to them will update the usages and predecessors.
2597
08cda6637103 More doc + conclusion.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2591
diff changeset
165 \item Every node must be able to support cloning and serialization.
08cda6637103 More doc + conclusion.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2591
diff changeset
166 \item Inlining should always be performed as embedding one graph into another graph.
2590
d559fac49699 More work on doc.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2589
diff changeset
167 \item Nodes cannot be reassigned to another graph, they are cloned instead.
2597
08cda6637103 More doc + conclusion.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2591
diff changeset
168 \item The edges of a node also define \textit{happens-before} and \textit{happens-after} relationships as shown in Figure~\ref{fig:directions}.
2589
795df30f979d Refer to "Graal compiler" as "the compiler" in the design document.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2588
diff changeset
169 \end{itemize}
795df30f979d Refer to "Graal compiler" as "the compiler" in the design document.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2588
diff changeset
170
2597
08cda6637103 More doc + conclusion.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2591
diff changeset
171 \begin{figure}[h]
08cda6637103 More doc + conclusion.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2591
diff changeset
172 \centering
08cda6637103 More doc + conclusion.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2591
diff changeset
173 \begin{digraphenv}{scale=0.5}{graphdirections}
08cda6637103 More doc + conclusion.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2591
diff changeset
174 \node{node1}{Node}
08cda6637103 More doc + conclusion.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2591
diff changeset
175 \textnode{inputs}{inputs}
08cda6637103 More doc + conclusion.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2591
diff changeset
176 \textnode{usages}{usages}
08cda6637103 More doc + conclusion.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2591
diff changeset
177 \textnode{successors}{successors}
08cda6637103 More doc + conclusion.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2591
diff changeset
178 \textnode{predecessors}{predecessors}
08cda6637103 More doc + conclusion.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2591
diff changeset
179 \data{node1}{inputs}
08cda6637103 More doc + conclusion.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2591
diff changeset
180 \control{node1}{successors}
08cda6637103 More doc + conclusion.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2591
diff changeset
181 \data{usages}{node1}
08cda6637103 More doc + conclusion.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2591
diff changeset
182 \control{predecessors}{node1}
08cda6637103 More doc + conclusion.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2591
diff changeset
183 \node{node2}{Node}
2604
c9b17ac5c06b Doc fixes.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2598
diff changeset
184 \textnode{before}{happens-before}
c9b17ac5c06b Doc fixes.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2598
diff changeset
185 \textnode{after}{happens-after}
2597
08cda6637103 More doc + conclusion.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2591
diff changeset
186 \data{node2}{before}
08cda6637103 More doc + conclusion.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2591
diff changeset
187 \control{node2}{after}
08cda6637103 More doc + conclusion.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2591
diff changeset
188 \data{after}{node2}
08cda6637103 More doc + conclusion.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2591
diff changeset
189 \control{before}{node2}
08cda6637103 More doc + conclusion.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2591
diff changeset
190 \end{digraphenv}
08cda6637103 More doc + conclusion.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2591
diff changeset
191 \caption{A node and its edges.}
2604
c9b17ac5c06b Doc fixes.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2598
diff changeset
192 \label{fig:directions}
2597
08cda6637103 More doc + conclusion.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2591
diff changeset
193 \end{figure}
08cda6637103 More doc + conclusion.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2591
diff changeset
194
2678
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
195 \section{Control Flow}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
196
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
197 Control flow is managed in way where the predecessor node contains direct pointers to its successor nodes.
2679
07aa0a31fffb Rewrote frame state to be not-so-Java-specific. Clarified and reduced the usage of the term "node".
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2678
diff changeset
198 We reserve the term \textit{instruction} for nodes that are embedded in the control flow.
2678
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
199 This is opposite to the approach taken in the server compiler, where control flow and data flow edges point in the same direction.
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
200 The advantage that we see in our approach is that there is no need for projection nodes in case of control flow splits.
2679
07aa0a31fffb Rewrote frame state to be not-so-Java-specific. Clarified and reduced the usage of the term "node".
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2678
diff changeset
201 An \texttt{If} instruction can directly point to its true and false successors without any intermediate nodes.
2678
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
202 This makes the graph more compact and simplifies graph traversal.
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
203
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
204 Listing \ref{lst:cfg2} shows an example Java program with an if statement where both paths do not contain any instruction with side effects.
2679
07aa0a31fffb Rewrote frame state to be not-so-Java-specific. Clarified and reduced the usage of the term "node".
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2678
diff changeset
205 The \texttt{If} instruction can directly point its true and false successors to a \texttt{Merge} instruction.
07aa0a31fffb Rewrote frame state to be not-so-Java-specific. Clarified and reduced the usage of the term "node".
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2678
diff changeset
206 A \texttt{Phi} node that selects the appropriate value is appended to the \texttt{Merge} instruction.
2678
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
207 The \texttt{Return} instruction then has a data dependency on the \texttt{Phi} node.
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
208
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
209 \begin{lstlisting}[label=lst:cfg2, caption=Control flow in the graph, captionpos=b]
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
210 if (condition) { return 0; }
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
211 else { return 1; }
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
212 \end{lstlisting}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
213
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
214 \begin{figure}[h]
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
215 \centering
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
216 \begin{digraphenv}{scale=0.5}{cfg2}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
217 \textnode{entry}{Entry}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
218 \textnode{condition}{condition}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
219 \textnode{const0}{0}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
220 \textnode{const1}{1}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
221 \nodesplit{if}{If}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
222 \control{entry}{if}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
223 \controllabel{if:succ1}{merge}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
224 \controllabel{if:succ2}{merge}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
225 \data{if}{condition}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
226 \node{merge}{Merge}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
227 \node{return}{Return}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
228 \nodetri{phi}{Phi}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
229 \datalabel{phi:in1}{merge}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
230 \datalabel{phi:in2}{const0}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
231 \datalabel{phi:in3}{const1}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
232 \data{return}{phi}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
233 \control{merge}{return}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
234 \end{digraphenv}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
235 \caption{A simple loop with two exits.}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
236 \label{fig:exc1}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
237 \end{figure}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
238
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
239 \section{Exceptions}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
240 \label{sec:Exceptions}
2597
08cda6637103 More doc + conclusion.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2591
diff changeset
241
2678
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
242 We do not throw runtime exceptions (e.g., \texttt{IndexOutOf\-BoundsException}, \texttt{NullPointerException}, or \texttt{Out\-Of\-MemoryException}), but deoptimize instead.
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
243 This reduces the places in the compiled code where an exact bytecode location and debug information must be known.
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
244 Additionally, this greatly reduces the number of exception handler edges in the compiled code.
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
245 The main advantage of this technique is however, that we are free in moving around bounds checks, memory allocation, memory accesses with implicit null checks, etc.
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
246
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
247 There are only two kinds of instruction that need explicit exception edges, because they are the only instructions that can throw exceptions in compiled code: \texttt{Throw} instructions and \texttt{Invoke} instructions.
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
248 They are modelled as instructions with an additional control flow continuation that points to an \texttt{ExceptionDispatch} instruction.
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
249 The exception dispatch instruction decides based on the type of the exception object whether the control should flow to the catch handler or to another exception dispatch.
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
250 If there is no catch handler in the currently compiled method, then the control flows into the \texttt{Unwind} instruction that handles the exception by forwarding it to the caller.
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
251 Listing \ref{lst:exc1} shows an example Java program with nested try blocks and Figure \ref{fig:exc1} shows the corresponding compiler graph.
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
252
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
253 \begin{lstlisting}[label=lst:exc1, caption=Exception dispatch in the compiler graph, captionpos=b]
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
254 try { m1();
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
255 try { m2();
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
256 } catch(ExtendedException e) { ... }
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
257 m3();
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
258 throw exception;
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
259 } catch(Exception e) { ... }
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
260 \end{lstlisting}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
261
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
262 \begin{figure}[h]
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
263 \centering
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
264 \begin{digraphenv}{scale=0.5}{exc1}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
265 \textnode{entry}{Entry}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
266 \textnode{catch1}{catch1}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
267 \textnode{catch2}{catch2}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
268 \nodesplit{m1}{Invoke m1}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
269 \nodesplit{m2}{Invoke m2}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
270 \nodesplit{m3}{Invoke m3}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
271 \nodesplit{dispatch1}{ExceptionDispatch}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
272 \nodesplit{dispatch2}{ExceptionDispatch}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
273 \node{throw}{Throw}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
274 \node{unwind}{Unwind}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
275 \control{entry}{m1}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
276 \controllabel{m1:succ1}{m2}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
277 \controllabel{m1:succ2}{dispatch2}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
278 \controllabel{m2:succ1}{m3}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
279 \controllabel{m2:succ2}{dispatch1}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
280 \controllabel{m3:succ1}{throw}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
281 \controllabel{m3:succ2}{dispatch2}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
282 \control{throw}{dispatch2}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
283 \controllabel{dispatch1:succ2}{catch1}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
284 \controllabel{dispatch1:succ1}{dispatch2}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
285 \controllabel{dispatch2:succ2}{catch2}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
286 \controllabel{dispatch2:succ1}{unwind}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
287 \end{digraphenv}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
288 \caption{A simple loop with two exits.}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
289 \label{fig:exc1}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
290 \end{figure}
2597
08cda6637103 More doc + conclusion.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2591
diff changeset
291
08cda6637103 More doc + conclusion.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2591
diff changeset
292 \section{Loops}
2588
26ecba0ead6d Update on doc.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2578
diff changeset
293 \label{sec:loops}
2618
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
294 Loops form a first-class construct in the IR that is expressed by specialized IR nodes during all optimization phases.
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
295 We only compile methods with a control flow where every loop has a single entry point.
2679
07aa0a31fffb Rewrote frame state to be not-so-Java-specific. Clarified and reduced the usage of the term "node".
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2678
diff changeset
296 This entry point is a \nodename{LoopBegin} instruction.
07aa0a31fffb Rewrote frame state to be not-so-Java-specific. Clarified and reduced the usage of the term "node".
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2678
diff changeset
297 This instruction is connected to a \nodename{LoopEnd} instruction that merges all control flow paths that do not exit the loop.
2573
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
298 The edge between the \nodename{LoopBegin} and the \nodename{LoopEnd} is the backedge of the loop.
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
299 It goes from the beginning to the end in order to make the graph acyclic.
2618
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
300 An algorithm that traverses the control flow has to explicitely decide whether it wants to incorporate backedges (i.e., special case of the treatment of \nodename{LoopEnd}) or ignore them.
2573
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
301 Figure \ref{fig:loop1} shows a simple example with a loop with a single entry and two exits.
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
302
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
303 \begin{figure}[h]
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
304 \centering
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
305 \begin{digraphenv}{scale=0.5}{layout1}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
306 \textnode{BeforeLoop}{Loop entry}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
307 \textnode{Exit1}{First loop exit}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
308 \textnode{Exit2}{Second loop exit}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
309 \nodesplit{LoopBegin}{LoopBegin}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
310 \node{LoopEnd}{LoopEnd}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
311 \nodesplit{If1}{If}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
312 \nodesplit{If2}{If}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
313 \controllabel{LoopBegin:succ1}{LoopEnd}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
314 \controllabel{LoopBegin:succ2}{If1}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
315 \controllabel{If1:succ1}{If2}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
316 \controllabel{If2:succ1}{LoopEnd}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
317 \controllabel{BeforeLoop}{LoopBegin}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
318 \controllabel{If1:succ2}{Exit1}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
319 \controllabel{If2:succ2}{Exit2}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
320 \end{digraphenv}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
321 \caption{A simple loop with two exits.}
2604
c9b17ac5c06b Doc fixes.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2598
diff changeset
322 \label{fig:loop1}
2573
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
323 \end{figure}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
324
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
325 \subsection{Loop Phis}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
326 Data flow in loops is modelled with special phi nodes at the beginning and the end of the loop.
2679
07aa0a31fffb Rewrote frame state to be not-so-Java-specific. Clarified and reduced the usage of the term "node".
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2678
diff changeset
327 The \nodename{LoopEnd} instruction merges every value that flows into the next loop iteration in associated \nodename{LoopEndPhi} nodes.
2573
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
328 A corresponding \nodename{LoopBeginPhi} node that is associated with the loop header has a control flow dependency on the \nodename{LoopEndPhi} node.
2678
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
329 Listing \ref{lst:loop} shows a simple counting loop that is used as an example in the rest of this section.
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
330 Figure \ref{fig:loop2} shows how the loop is modelled immediately after building the graph.
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
331
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
332 \begin{lstlisting}[label=lst:loop, caption=Loop example, captionpos=b]
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
333 for(int i=0; i<n; ++i) { }
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
334 \end{lstlisting}
b9b0a0aa7ee8 Added addition sections on control flow and exceptions.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2619
diff changeset
335
2573
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
336 \begin{figure}[h]
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
337 \centering
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
338 \begin{digraphenv}{scale=0.5}{layout2}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
339 \textnode{BeforeLoop}{Loop entry}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
340 \textnode{Exit}{Loop exit}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
341 \textnode{n}{n}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
342 \textnode{Constant0}{0}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
343 \textnode{Constant1}{1}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
344 \nodesplit{LoopBegin}{LoopBegin}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
345 \node{LoopEnd}{LoopEnd}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
346 \nodesplit{If1}{If}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
347 \controllabel{LoopBegin:succ1}{LoopEnd}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
348 \controllabel{LoopBegin:succ2}{If1}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
349 \nodebi{Compare}{&lt;}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
350 \nodebi{LoopBeginPhi}{LoopBeginPhi}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
351 \nodebi{Add}{+}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
352 \datalabel{Add:in1}{LoopBeginPhi}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
353 \datalabel{Add:in2}{Constant1}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
354 \nodebi{LoopEndPhi}{LoopEndPhi}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
355 \control{LoopBeginPhi}{LoopEndPhi}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
356 \data{LoopEndPhi:in1}{LoopEnd}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
357 \data{LoopEndPhi:in2}{Add}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
358 \datalabel{LoopBeginPhi:in1}{LoopBegin}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
359 \datalabel{LoopBeginPhi:in2}{Constant0}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
360 \datalabel{Compare:in1}{LoopBeginPhi}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
361 \datalabel{Compare:in2}{n}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
362 \data{If1}{Compare}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
363 \controllabel{If1:succ1}{LoopEnd}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
364 \controllabel{BeforeLoop}{LoopBegin}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
365 \controllabel{If1:succ2}{Exit}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
366 \end{digraphenv}
2589
795df30f979d Refer to "Graal compiler" as "the compiler" in the design document.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2588
diff changeset
367 \caption{Graph for a loop counting from 0 to n-1.}
2604
c9b17ac5c06b Doc fixes.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2598
diff changeset
368 \label{fig:loop2}
2573
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
369 \end{figure}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
370
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
371 \subsection{Loop Counters}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
372 The compiler is capable of recognizing variables that are only increased within a loop.
2618
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
373 A potential overflow of such a variable is prohibited with a guard before the loop (this is not necessary in this example, because the loop variable cannot overflow).
2573
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
374 Figure \ref{fig:loop3} shows the compiler graph of the example loop after the loop counter transformation.
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
375
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
376
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
377 \begin{figure}[h]
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
378 \centering
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
379 \begin{digraphenv}{scale=0.5}{layout3}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
380 \textnode{BeforeLoop}{Loop entry}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
381 \textnode{Exit}{Loop exit}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
382 \textnode{n}{n}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
383 \textnode{Constant0}{0}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
384 \textnode{Constant1}{1}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
385 \nodesplit{LoopBegin}{LoopBegin}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
386 \node{LoopEnd}{LoopEnd}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
387 \nodesplit{If1}{If}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
388 \controllabel{LoopBegin:succ1}{LoopEnd}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
389 \controllabel{LoopBegin:succ2}{If1}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
390 \nodebi{Compare}{&lt;}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
391 \nodetri{LoopCounter}{LoopCounter}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
392 \datalabel{LoopCounter:in1}{LoopBegin}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
393 \datalabeltext{LoopCounter:in2}{Constant0}{init}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
394 \datalabeltext{LoopCounter:in3}{Constant1}{stride}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
395 \datalabel{Compare:in1}{LoopCounter}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
396 \datalabel{Compare:in2}{n}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
397 \data{If1}{Compare}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
398 \controllabel{If1:succ1}{LoopEnd}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
399 \controllabel{BeforeLoop}{LoopBegin}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
400 \controllabel{If1:succ2}{Exit}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
401 \end{digraphenv}
2589
795df30f979d Refer to "Graal compiler" as "the compiler" in the design document.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2588
diff changeset
402 \caption{Graph after loop counter transformation.}
2604
c9b17ac5c06b Doc fixes.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2598
diff changeset
403 \label{fig:loop3}
2573
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
404 \end{figure}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
405
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
406 \subsection{Bounded Loops}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
407
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
408 If the total maximum number of iterations of a loop is fixed, then the loop is converted into a bounded loop.
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
409 The total number of iterations always denotes the number of full iterations of the loop with the control flowing from the loop begin to the loop end.
2604
c9b17ac5c06b Doc fixes.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2598
diff changeset
410 If the total number of iterations is reached, the loop is exited directly from the loop header.
2573
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
411 In the example, we can infer from the loop exit with the comparison on the loop counter that the total number of iterations of the loop is limited to n.
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
412 Figure \ref{fig:loop4} shows the compiler graph of the example loop after the bounded loop transformation.
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
413
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
414 \begin{figure}[h]
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
415 \centering
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
416 \begin{digraphenv}{scale=0.5}{layout4}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
417 \textnode{BeforeLoop}{Loop entry}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
418 \textnode{Exit}{Loop exit}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
419 \textnode{n}{n}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
420 \textnode{Constant0}{0}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
421 \textnode{Constant1}{1}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
422 \nodesplittri{LoopBegin}{BoundedLoopBegin}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
423 \node{LoopEnd}{LoopEnd}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
424 \controllabel{LoopBegin:succ1}{LoopEnd}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
425 \controllabel{LoopBegin:succ2}{LoopEnd}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
426 \controllabel{LoopBegin:succ3}{Exit}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
427 \nodetri{LoopCounter}{LoopCounter}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
428 \datalabel{LoopCounter:in1}{LoopBegin}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
429 \datalabeltext{LoopCounter:in2}{Constant0}{init}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
430 \datalabeltext{LoopCounter:in3}{Constant1}{stride}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
431 \data{LoopBegin}{n}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
432 \controllabel{BeforeLoop}{LoopBegin}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
433 \end{digraphenv}
2589
795df30f979d Refer to "Graal compiler" as "the compiler" in the design document.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2588
diff changeset
434 \caption{Graph after bounded loop transformation.}
2604
c9b17ac5c06b Doc fixes.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2598
diff changeset
435 \label{fig:loop4}
2573
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
436 \end{figure}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
437
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
438 \subsection{Vectorization}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
439
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
440 If we have now a bounded loop with no additional loop exit and no associated phi nodes (only associated loop counters), we can vectorize the loop.
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
441 We replace the loop header with a normal instruction that produces a vector of values from 0 to the number of loop iterations minus 1.
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
442 The loop counters are replaced with \texttt{VectorAdd} and \texttt{VectorMul} nodes.
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
443 The vectorization is only possible if every node of the loop can be replaced with a corresponding vector node.
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
444 Figure \ref{fig:loop5} shows the compiler graph of the example loop after vectorization.
2604
c9b17ac5c06b Doc fixes.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2598
diff changeset
445 The vector nodes all work on an ordered list of integer values and are subject to canonicalization and global value numbering like any other node.
2573
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
446
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
447
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
448 \begin{figure}[h]
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
449 \centering
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
450 \begin{digraphenv}{scale=0.5}{layout5}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
451 \textnode{Entry}{Entry}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
452 \textnode{Exit}{Exit}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
453 \textnode{n}{n}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
454 \textnode{Constant0}{0}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
455 \textnode{Constant1}{1}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
456 \node{Vector}{Vector}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
457 \nodebi{VectorAdd}{VectorAdd}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
458 \nodebi{VectorMul}{VectorMul}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
459 \control{Entry}{Vector}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
460 \control{Vector}{Exit}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
461 \datalabel{VectorAdd:in1}{Vector}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
462 \datalabel{VectorAdd:in2}{Constant0}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
463 \datalabel{VectorMul:in1}{VectorAdd}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
464 \datalabel{VectorMul:in2}{Constant1}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
465 \data{Vector}{n}
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
466 \end{digraphenv}
2598
e4395464810e Made graphs smaller.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2597
diff changeset
467 \caption{Graph after vectorization.}
2604
c9b17ac5c06b Doc fixes.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2598
diff changeset
468 \label{fig:loop5}
2573
6d99b909696d Documentation: More content and graphs on loops and vectorization.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2572
diff changeset
469 \end{figure}
2561
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
470
2588
26ecba0ead6d Update on doc.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2578
diff changeset
471
2597
08cda6637103 More doc + conclusion.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2591
diff changeset
472 \section{Frame States}
2679
07aa0a31fffb Rewrote frame state to be not-so-Java-specific. Clarified and reduced the usage of the term "node".
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2678
diff changeset
473 A frame state captures the state of the program like it is seen in by an interpreter of the program.
07aa0a31fffb Rewrote frame state to be not-so-Java-specific. Clarified and reduced the usage of the term "node".
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2678
diff changeset
474 The frame state contains the information that is local to the current activation and will therefore disappear during SSA-form constructions or other compiler optimizations.
07aa0a31fffb Rewrote frame state to be not-so-Java-specific. Clarified and reduced the usage of the term "node".
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2678
diff changeset
475 For Java, the frame state is defined in terms of the Java bytecode specification (i.e., the values of the local variables, the operand stack, and the locked monitors).
07aa0a31fffb Rewrote frame state to be not-so-Java-specific. Clarified and reduced the usage of the term "node".
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2678
diff changeset
476 However, a frame state is not a concept specific to Java (e.g., the Crankshaft JavaScript engine uses frame states in their optimizing compiler to model the values of the AST interpreter).
07aa0a31fffb Rewrote frame state to be not-so-Java-specific. Clarified and reduced the usage of the term "node".
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2678
diff changeset
477
07aa0a31fffb Rewrote frame state to be not-so-Java-specific. Clarified and reduced the usage of the term "node".
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2678
diff changeset
478 Frame states are necessary to support the deoptimization of the program, which is the precondition for performing aggressive optimizations that use optimistic assumptions.
07aa0a31fffb Rewrote frame state to be not-so-Java-specific. Clarified and reduced the usage of the term "node".
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2678
diff changeset
479 Therefore every point in the optimizing compiler that may revert execution back to the interpreter needs a valid frame state.
07aa0a31fffb Rewrote frame state to be not-so-Java-specific. Clarified and reduced the usage of the term "node".
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2678
diff changeset
480 However, the point where the interpreter continues execution need not correspond exactly to the execution position of the compiled code, because many Java bytecode instructions can be safely reexecuted.
07aa0a31fffb Rewrote frame state to be not-so-Java-specific. Clarified and reduced the usage of the term "node".
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2678
diff changeset
481 Thus, frame states need only be generated for the states after instructions that cannot be reexecuted, because they modify the state of the program.
07aa0a31fffb Rewrote frame state to be not-so-Java-specific. Clarified and reduced the usage of the term "node".
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2678
diff changeset
482 Examples for such instructions are:
2561
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
483
2576
c59db1f02893 doc: expanded framestate section
Lukas Stadler <lukas.stadler@jku.at>
parents: 2569
diff changeset
484 \begin{itemize}
2679
07aa0a31fffb Rewrote frame state to be not-so-Java-specific. Clarified and reduced the usage of the term "node".
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2678
diff changeset
485 \item Array stores (in Java bytecodes {\tt IASTORE, LASTORE, FASTORE, \\DASTORE, AASTORE, BASTORE, CASTORE, SASTORE})
07aa0a31fffb Rewrote frame state to be not-so-Java-specific. Clarified and reduced the usage of the term "node".
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2678
diff changeset
486 \item Field stores (in Java bytecodes {\tt PUTSTATIC, PUTFIELD})
07aa0a31fffb Rewrote frame state to be not-so-Java-specific. Clarified and reduced the usage of the term "node".
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2678
diff changeset
487 \item Method calls (in Java bytecodes {\tt INVOKEVIRTUAL, INVOKESPECIAL, \\INVOKESTATIC, INVOKEINTERFACE})
07aa0a31fffb Rewrote frame state to be not-so-Java-specific. Clarified and reduced the usage of the term "node".
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2678
diff changeset
488 \item Synchronization (in Java bytecodes {\tt MONITORENTER, MONITOREXIT})
2576
c59db1f02893 doc: expanded framestate section
Lukas Stadler <lukas.stadler@jku.at>
parents: 2569
diff changeset
489 \end{itemize}
2561
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
490
2679
07aa0a31fffb Rewrote frame state to be not-so-Java-specific. Clarified and reduced the usage of the term "node".
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2678
diff changeset
491 Within the graph a frame state is represented as a node that is attached to the instruction that caused it to be generated using a control dependency (see Figure~\ref{fig:fs1}).
2598
e4395464810e Made graphs smaller.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2597
diff changeset
492 Frame states also have data dependencies on the contents of the state: the local variables and the expression stack.
2561
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
493
2604
c9b17ac5c06b Doc fixes.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2598
diff changeset
494 The frame state at the method beginning does not have to be explicitely in the graph, because it can always be reconstructed at a later stage.
2618
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
495 We save the frame state at control flow merges if there is at least one frame state on any control flow path after the immediate dominator.
2604
c9b17ac5c06b Doc fixes.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2598
diff changeset
496
2561
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
497
2578
Lukas Stadler <lukas.stadler@jku.at>
parents: 2577 2574
diff changeset
498 \begin{figure}[h]
Lukas Stadler <lukas.stadler@jku.at>
parents: 2577 2574
diff changeset
499 \centering
2576
c59db1f02893 doc: expanded framestate section
Lukas Stadler <lukas.stadler@jku.at>
parents: 2569
diff changeset
500 \begin{digraphenv}{scale=0.5}{fs1}
2577
ac2029d0898f doc: framestate and deopt changes
Lukas Stadler <lukas.stadler@jku.at>
parents: 2576
diff changeset
501 \nodetrisplit{store1}{ArrayStore}
ac2029d0898f doc: framestate and deopt changes
Lukas Stadler <lukas.stadler@jku.at>
parents: 2576
diff changeset
502 \nodebi{load1}{ArrayLoad}
2576
c59db1f02893 doc: expanded framestate section
Lukas Stadler <lukas.stadler@jku.at>
parents: 2569
diff changeset
503 \controllabel{store1:succ1}{load1}
2618
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
504 \nodetrisplit{store2}{FieldStore}
2576
c59db1f02893 doc: expanded framestate section
Lukas Stadler <lukas.stadler@jku.at>
parents: 2569
diff changeset
505 \control{load1}{store2}
c59db1f02893 doc: expanded framestate section
Lukas Stadler <lukas.stadler@jku.at>
parents: 2569
diff changeset
506 end [shape=plaintext, label="...", width="2.0"]
c59db1f02893 doc: expanded framestate section
Lukas Stadler <lukas.stadler@jku.at>
parents: 2569
diff changeset
507 store2:succ1:s -> end:n [color=red];
c59db1f02893 doc: expanded framestate section
Lukas Stadler <lukas.stadler@jku.at>
parents: 2569
diff changeset
508 %
c59db1f02893 doc: expanded framestate section
Lukas Stadler <lukas.stadler@jku.at>
parents: 2569
diff changeset
509 \nodeframestate{fs1}{FrameState}
c59db1f02893 doc: expanded framestate section
Lukas Stadler <lukas.stadler@jku.at>
parents: 2569
diff changeset
510 \controllabel{store1:succ2}{fs1}
c59db1f02893 doc: expanded framestate section
Lukas Stadler <lukas.stadler@jku.at>
parents: 2569
diff changeset
511 \nodeframestate{fs2}{FrameState}
c59db1f02893 doc: expanded framestate section
Lukas Stadler <lukas.stadler@jku.at>
parents: 2569
diff changeset
512 \controllabel{store2:succ2}{fs2}
c59db1f02893 doc: expanded framestate section
Lukas Stadler <lukas.stadler@jku.at>
parents: 2569
diff changeset
513 \end{digraphenv}
2578
Lukas Stadler <lukas.stadler@jku.at>
parents: 2577 2574
diff changeset
514 \caption{Simple example using two frame states.}
2604
c9b17ac5c06b Doc fixes.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2598
diff changeset
515 \label{fig:fs1}
2578
Lukas Stadler <lukas.stadler@jku.at>
parents: 2577 2574
diff changeset
516 \end{figure}
2576
c59db1f02893 doc: expanded framestate section
Lukas Stadler <lukas.stadler@jku.at>
parents: 2569
diff changeset
517
c59db1f02893 doc: expanded framestate section
Lukas Stadler <lukas.stadler@jku.at>
parents: 2569
diff changeset
518
2618
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
519 \subsection{Guards}
2679
07aa0a31fffb Rewrote frame state to be not-so-Java-specific. Clarified and reduced the usage of the term "node".
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2678
diff changeset
520 A guard is a node that deoptimizes based on a conditional expression.
07aa0a31fffb Rewrote frame state to be not-so-Java-specific. Clarified and reduced the usage of the term "node".
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2678
diff changeset
521 Guards are not attached to a certain frame state, they can move around freely and will always use the correct frame state when the nodes are scheduled (i.e., the last emitted frame state).
2618
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
522 The node that is guarded by the deoptimization has a data dependency on the guard, and the guard in turn has a data dependency on the condition and on the most distant node that is postdominated by the guarded node.
2561
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
523
2618
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
524 In the example of Figure~\ref{fig:guard1}, the second load is guarded by a guard, because its receiver might be null (the receiver of the first load is assumed to be non-null).
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
525 The guard is anchored to the control split, because as soon as this node is executed, the second load must be executed as well.
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
526 In the final schedule, the guard can be placed before or after the first load.
2598
e4395464810e Made graphs smaller.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2597
diff changeset
527
2578
Lukas Stadler <lukas.stadler@jku.at>
parents: 2577 2574
diff changeset
528 \begin{figure}[h]
Lukas Stadler <lukas.stadler@jku.at>
parents: 2577 2574
diff changeset
529 \centering
2618
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
530 \begin{digraphenv}{scale=0.5}{guard1}
2576
c59db1f02893 doc: expanded framestate section
Lukas Stadler <lukas.stadler@jku.at>
parents: 2569
diff changeset
531 \nodesplit{if}{If}
c59db1f02893 doc: expanded framestate section
Lukas Stadler <lukas.stadler@jku.at>
parents: 2569
diff changeset
532 nop [shape=plaintext, label="..."]
2618
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
533 \controllabel{if:succ1}{nop}
2576
c59db1f02893 doc: expanded framestate section
Lukas Stadler <lukas.stadler@jku.at>
parents: 2569
diff changeset
534 %
2618
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
535 \node{split2}{Anchor}
2576
c59db1f02893 doc: expanded framestate section
Lukas Stadler <lukas.stadler@jku.at>
parents: 2569
diff changeset
536 \controllabel{if:succ2}{split2}
2577
ac2029d0898f doc: framestate and deopt changes
Lukas Stadler <lukas.stadler@jku.at>
parents: 2576
diff changeset
537 \nodebi{load1}{MemLoad}
2576
c59db1f02893 doc: expanded framestate section
Lukas Stadler <lukas.stadler@jku.at>
parents: 2569
diff changeset
538 \control{split2}{load1}
2577
ac2029d0898f doc: framestate and deopt changes
Lukas Stadler <lukas.stadler@jku.at>
parents: 2576
diff changeset
539 \nodebi{load2}{MemLoad}
2576
c59db1f02893 doc: expanded framestate section
Lukas Stadler <lukas.stadler@jku.at>
parents: 2569
diff changeset
540 \control{load1}{load2}
c59db1f02893 doc: expanded framestate section
Lukas Stadler <lukas.stadler@jku.at>
parents: 2569
diff changeset
541 \control{load2}{merge}
c59db1f02893 doc: expanded framestate section
Lukas Stadler <lukas.stadler@jku.at>
parents: 2569
diff changeset
542 \node{merge}{Merge}
c59db1f02893 doc: expanded framestate section
Lukas Stadler <lukas.stadler@jku.at>
parents: 2569
diff changeset
543 \control{nop}{merge}
c59db1f02893 doc: expanded framestate section
Lukas Stadler <lukas.stadler@jku.at>
parents: 2569
diff changeset
544 %
c59db1f02893 doc: expanded framestate section
Lukas Stadler <lukas.stadler@jku.at>
parents: 2569
diff changeset
545 \nodeconst{o1}{obj1}
c59db1f02893 doc: expanded framestate section
Lukas Stadler <lukas.stadler@jku.at>
parents: 2569
diff changeset
546 \nodeconst{o2}{obj2}
c59db1f02893 doc: expanded framestate section
Lukas Stadler <lukas.stadler@jku.at>
parents: 2569
diff changeset
547 \datalabel{load1:in2}{o1}
c59db1f02893 doc: expanded framestate section
Lukas Stadler <lukas.stadler@jku.at>
parents: 2569
diff changeset
548 \datalabel{load2:in2}{o2}
2618
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
549 \nodeguard{guard}{Guard}
2576
c59db1f02893 doc: expanded framestate section
Lukas Stadler <lukas.stadler@jku.at>
parents: 2569
diff changeset
550 \node{cmpnull}{IsNull}
c59db1f02893 doc: expanded framestate section
Lukas Stadler <lukas.stadler@jku.at>
parents: 2569
diff changeset
551 \data{cmpnull}{o2}
2618
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
552 \datalabel{guard:in2}{cmpnull}
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
553 \datalabel{load2:in1}{guard}
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
554 \datalabel{guard:in1}{split2}
2576
c59db1f02893 doc: expanded framestate section
Lukas Stadler <lukas.stadler@jku.at>
parents: 2569
diff changeset
555 \end{digraphenv}
2618
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
556 \caption{A load guarded by a null check guard.}
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
557 \label{fig:guard1}
2578
Lukas Stadler <lukas.stadler@jku.at>
parents: 2577 2574
diff changeset
558 \end{figure}
2576
c59db1f02893 doc: expanded framestate section
Lukas Stadler <lukas.stadler@jku.at>
parents: 2569
diff changeset
559
2618
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
560 A guard can be used to remove branches that have a very low execution frequency and replace them with a conditional jump to deoptimization.
2576
c59db1f02893 doc: expanded framestate section
Lukas Stadler <lukas.stadler@jku.at>
parents: 2569
diff changeset
561
2679
07aa0a31fffb Rewrote frame state to be not-so-Java-specific. Clarified and reduced the usage of the term "node".
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2678
diff changeset
562 In the example of Figure~\ref{fig:guard2}, an \texttt{If} instruction was replaced by an anchor and a guard.
07aa0a31fffb Rewrote frame state to be not-so-Java-specific. Clarified and reduced the usage of the term "node".
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2678
diff changeset
563 The anchor takes the place of the \texttt{If} instruction in the control flow, and is connected to the guard.
07aa0a31fffb Rewrote frame state to be not-so-Java-specific. Clarified and reduced the usage of the term "node".
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2678
diff changeset
564 The guard is now anchored to the most distant node of which the \texttt{If} instruction was a postdominator.
2598
e4395464810e Made graphs smaller.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2597
diff changeset
565
2578
Lukas Stadler <lukas.stadler@jku.at>
parents: 2577 2574
diff changeset
566 \begin{figure}[h]
Lukas Stadler <lukas.stadler@jku.at>
parents: 2577 2574
diff changeset
567 \centering
2618
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
568 \begin{digraphenv}{scale=0.5}{guard2}
2576
c59db1f02893 doc: expanded framestate section
Lukas Stadler <lukas.stadler@jku.at>
parents: 2569
diff changeset
569 start [shape=plaintext, label="..."]
c59db1f02893 doc: expanded framestate section
Lukas Stadler <lukas.stadler@jku.at>
parents: 2569
diff changeset
570 start2 [shape=plaintext, label=""]
c59db1f02893 doc: expanded framestate section
Lukas Stadler <lukas.stadler@jku.at>
parents: 2569
diff changeset
571 start3 [shape=plaintext, label=""]
c59db1f02893 doc: expanded framestate section
Lukas Stadler <lukas.stadler@jku.at>
parents: 2569
diff changeset
572 \control{start}{guard}
2618
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
573 \node{anchor}{Anchor}
2577
ac2029d0898f doc: framestate and deopt changes
Lukas Stadler <lukas.stadler@jku.at>
parents: 2576
diff changeset
574 \nodebi{load1}{MemLoad}
2618
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
575 \control{anchor}{load1}
2577
ac2029d0898f doc: framestate and deopt changes
Lukas Stadler <lukas.stadler@jku.at>
parents: 2576
diff changeset
576 \control{load1}{nop}
2576
c59db1f02893 doc: expanded framestate section
Lukas Stadler <lukas.stadler@jku.at>
parents: 2569
diff changeset
577 nop [shape=plaintext, label="..."]
c59db1f02893 doc: expanded framestate section
Lukas Stadler <lukas.stadler@jku.at>
parents: 2569
diff changeset
578 %
2618
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
579 \nodeguard{guard}{Guard}
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
580 \datalabel{guard:in1}{start2}
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
581 \datalabel{guard:in2}{start3}
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
582 \data{anchor}{guard}
2576
c59db1f02893 doc: expanded framestate section
Lukas Stadler <lukas.stadler@jku.at>
parents: 2569
diff changeset
583 \end{digraphenv}
2618
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
584 \caption{A guard that is fixed to the control flow using an anchor instruction.}
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
585 \label{fig:guard2}
2578
Lukas Stadler <lukas.stadler@jku.at>
parents: 2577 2574
diff changeset
586 \end{figure}
2576
c59db1f02893 doc: expanded framestate section
Lukas Stadler <lukas.stadler@jku.at>
parents: 2569
diff changeset
587
2679
07aa0a31fffb Rewrote frame state to be not-so-Java-specific. Clarified and reduced the usage of the term "node".
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2678
diff changeset
588 At some point during the compilation, guards need to be fixed, which means that appropriate data and control dependencies will be inserted so that they cannot move outside the scope of the associated frame state.
2576
c59db1f02893 doc: expanded framestate section
Lukas Stadler <lukas.stadler@jku.at>
parents: 2569
diff changeset
589 This will generate deoptimization-free zones that can be targeted by the most aggressive optimizations.
2618
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
590 A simple algorithm for this removal of frame states would be to move all guards as far upwards as possible.
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
591 Multiple guards with the same condition and anchor can be merged (see Figure~\ref{fig:guard3}).
2577
ac2029d0898f doc: framestate and deopt changes
Lukas Stadler <lukas.stadler@jku.at>
parents: 2576
diff changeset
592
2578
Lukas Stadler <lukas.stadler@jku.at>
parents: 2577 2574
diff changeset
593 \begin{figure}[h]
Lukas Stadler <lukas.stadler@jku.at>
parents: 2577 2574
diff changeset
594 \centering
2618
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
595 \begin{digraphenv}{scale=0.5}{guard3}
2577
ac2029d0898f doc: framestate and deopt changes
Lukas Stadler <lukas.stadler@jku.at>
parents: 2576
diff changeset
596 \nodesplit{if}{If}
ac2029d0898f doc: framestate and deopt changes
Lukas Stadler <lukas.stadler@jku.at>
parents: 2576
diff changeset
597 nop [shape=plaintext, label="..."]
2618
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
598 \controllabel{if:succ1}{nop}
2577
ac2029d0898f doc: framestate and deopt changes
Lukas Stadler <lukas.stadler@jku.at>
parents: 2576
diff changeset
599 %
2618
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
600 \node{split2}{Anchor}
2577
ac2029d0898f doc: framestate and deopt changes
Lukas Stadler <lukas.stadler@jku.at>
parents: 2576
diff changeset
601 \controllabel{if:succ2}{split2}
ac2029d0898f doc: framestate and deopt changes
Lukas Stadler <lukas.stadler@jku.at>
parents: 2576
diff changeset
602 \nodebi{load1}{MemLoad}
ac2029d0898f doc: framestate and deopt changes
Lukas Stadler <lukas.stadler@jku.at>
parents: 2576
diff changeset
603 \control{split2}{load1}
ac2029d0898f doc: framestate and deopt changes
Lukas Stadler <lukas.stadler@jku.at>
parents: 2576
diff changeset
604 \nodebi{load2}{MemLoad}
ac2029d0898f doc: framestate and deopt changes
Lukas Stadler <lukas.stadler@jku.at>
parents: 2576
diff changeset
605 \control{load1}{load2}
ac2029d0898f doc: framestate and deopt changes
Lukas Stadler <lukas.stadler@jku.at>
parents: 2576
diff changeset
606 \control{load2}{merge}
ac2029d0898f doc: framestate and deopt changes
Lukas Stadler <lukas.stadler@jku.at>
parents: 2576
diff changeset
607 \node{merge}{Merge}
ac2029d0898f doc: framestate and deopt changes
Lukas Stadler <lukas.stadler@jku.at>
parents: 2576
diff changeset
608 \control{nop}{merge}
ac2029d0898f doc: framestate and deopt changes
Lukas Stadler <lukas.stadler@jku.at>
parents: 2576
diff changeset
609 %
ac2029d0898f doc: framestate and deopt changes
Lukas Stadler <lukas.stadler@jku.at>
parents: 2576
diff changeset
610 \nodeconst{o}{obj}
ac2029d0898f doc: framestate and deopt changes
Lukas Stadler <lukas.stadler@jku.at>
parents: 2576
diff changeset
611 \datalabel{load1:in2}{o}
ac2029d0898f doc: framestate and deopt changes
Lukas Stadler <lukas.stadler@jku.at>
parents: 2576
diff changeset
612 \datalabel{load2:in2}{o}
2618
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
613 \nodeguard{guard}{Guard}
2577
ac2029d0898f doc: framestate and deopt changes
Lukas Stadler <lukas.stadler@jku.at>
parents: 2576
diff changeset
614 \node{cmpnull}{IsNull}
ac2029d0898f doc: framestate and deopt changes
Lukas Stadler <lukas.stadler@jku.at>
parents: 2576
diff changeset
615 \data{cmpnull}{o}
2618
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
616 \datalabel{guard:in2}{cmpnull}
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
617 \datalabel{load2:in1}{guard}
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
618 \datalabel{load1:in1}{guard}
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
619 \datalabel{guard:in1}{split2}
2577
ac2029d0898f doc: framestate and deopt changes
Lukas Stadler <lukas.stadler@jku.at>
parents: 2576
diff changeset
620 \end{digraphenv}
2618
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
621 \caption{Two loads using the same guard.}
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
622 \label{fig:guard3}
2578
Lukas Stadler <lukas.stadler@jku.at>
parents: 2577 2574
diff changeset
623 \end{figure}
2577
ac2029d0898f doc: framestate and deopt changes
Lukas Stadler <lukas.stadler@jku.at>
parents: 2576
diff changeset
624
2679
07aa0a31fffb Rewrote frame state to be not-so-Java-specific. Clarified and reduced the usage of the term "node".
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2678
diff changeset
625 Also, if two guards that are anchored to the true and false branch of the same \texttt{If} instruction have the same condition, they can be merged, so that the resulting guard is anchored at the most distant node of which the \texttt{If} instruction is a postdominator.
2561
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
626
2597
08cda6637103 More doc + conclusion.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2591
diff changeset
627 \section{Conclusions}
2618
15774da89658 Incorporated comments from Peter. Renamings trap=>guard and guard/split=>anchor.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2604
diff changeset
628 \label{sec:conclusions}
2597
08cda6637103 More doc + conclusion.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2591
diff changeset
629 This document sketched the strategy for the Graph compiler.
08cda6637103 More doc + conclusion.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2591
diff changeset
630 We already reached M1 (as defined in Section~\ref{sec:mile}) and have the following plans for M2 to M4:
08cda6637103 More doc + conclusion.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2591
diff changeset
631 \begin{description}
08cda6637103 More doc + conclusion.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2591
diff changeset
632 \item[M2:] June 30th, 2011
08cda6637103 More doc + conclusion.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2591
diff changeset
633 \item[M3:] August 15th, 2011
08cda6637103 More doc + conclusion.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2591
diff changeset
634 \item[M4:] September 30th, 2011
08cda6637103 More doc + conclusion.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2591
diff changeset
635 \end{description}
08cda6637103 More doc + conclusion.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2591
diff changeset
636 After we reached M4, we want to create a new project road map that further improves the Graal compiler with respect to its two main goals: Modularity and peak performance.
2561
765dd54244a6 Updated doc. Added Texclipse project.
Thomas Wuerthinger <thomas@wuerthinger.net>
parents: 2517
diff changeset
637
2517
8c6e31c62fba added initial version of design docs, fixed .hgignore (regex, . -> \.)
Lukas Stadler <lukas.stadler@jku.at>
parents:
diff changeset
638 \end{document}