comparison graal/com.oracle.max.graal.doc.initial/graal_compiler.tex @ 2896:5d4aa5672d3d

Small fix to design document.
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Wed, 08 Jun 2011 14:50:07 +0200
parents 5005a5607506
children 4db4e8cb6bd6
comparison
equal deleted inserted replaced
2895:5fd2b31f50ee 2896:5d4aa5672d3d
27 \newcommand\TODO[1]{\mynote{TODO}{#1}} 27 \newcommand\TODO[1]{\mynote{TODO}{#1}}
28 \newcommand\cw[1]{\mynote{CW}{#1}} 28 \newcommand\cw[1]{\mynote{CW}{#1}}
29 \newcommand\ls[1]{\mynote{LS}{#1}} 29 \newcommand\ls[1]{\mynote{LS}{#1}}
30 \newcommand\nodename[1]{\texttt{#1}} 30 \newcommand\nodename[1]{\texttt{#1}}
31 31
32 \hyphenpenalty=0
33 \doublehyphendemerits=0
34 \finalhyphendemerits=0
35 \clubpenalty10000
36 \widowpenalty10000
32 37
33 38
34 \smartqed % flush right qed marks, e.g. at end of proof 39 \smartqed % flush right qed marks, e.g. at end of proof
35 40
36 \journalname{Graal Compiler Design} 41 \journalname{Graal Compiler Design}
164 \item Only inputs and successors can be changed, and changes to them will update the usages and predecessors. 169 \item Only inputs and successors can be changed, and changes to them will update the usages and predecessors.
165 \item Every node must be able to support cloning and serialization. 170 \item Every node must be able to support cloning and serialization.
166 \item The edges of a node also define \textit{happens-before} and \textit{happens-after} relationships as shown in Figure~\ref{fig:directions}. 171 \item The edges of a node also define \textit{happens-before} and \textit{happens-after} relationships as shown in Figure~\ref{fig:directions}.
167 \end{itemize} 172 \end{itemize}
168 173
169 \begin{figure}[h] 174 \begin{figure}[ht]
170 \centering 175 \centering
171 \begin{digraphenv}{scale=0.5}{graphdirections} 176 \begin{digraphenv}{scale=0.5}{graphdirections}
172 \node{node1}{Node} 177 \node{node1}{Node}
173 \textnode{inputs}{inputs} 178 \textnode{inputs}{inputs}
174 \textnode{usages}{usages} 179 \textnode{usages}{usages}
209 The advantage that we see in our approach is that there is no need for projection nodes in case of control flow splits. 214 The advantage that we see in our approach is that there is no need for projection nodes in case of control flow splits.
210 An \texttt{If} instruction can directly point to its true and false successors without any intermediate nodes. 215 An \texttt{If} instruction can directly point to its true and false successors without any intermediate nodes.
211 This makes the graph more compact and simplifies graph traversal. 216 This makes the graph more compact and simplifies graph traversal.
212 217
213 Listing~\ref{lst:cfg2} shows an example Java program with an if statement where both paths do not contain any instruction with side effects. 218 Listing~\ref{lst:cfg2} shows an example Java program with an if statement where both paths do not contain any instruction with side effects.
219 Figure~\ref{fig:loopexits} shows the corresponding compiler graph.
214 The \texttt{If} instruction can directly point its true and false successors to a \texttt{Merge} instruction. 220 The \texttt{If} instruction can directly point its true and false successors to a \texttt{Merge} instruction.
215 A \texttt{Phi} node that selects the appropriate value is appended to the \texttt{Merge} instruction. 221 A \texttt{Phi} node that selects the appropriate value is appended to the \texttt{Merge} instruction.
216 The \texttt{Return} instruction then has a data dependency on the \texttt{Phi} node. 222 The \texttt{Return} instruction then has a data dependency on the \texttt{Phi} node.
217 223
218 \begin{lstlisting}[label=lst:cfg2, caption=Control flow in the graph., captionpos=b] 224 \begin{lstlisting}[label=lst:cfg2, caption=Control flow in the graph., captionpos=b]
219 if (condition) { return 0; } 225 if (condition) { return 0; }
220 else { return 1; } 226 else { return 1; }
221 \end{lstlisting} 227 \end{lstlisting}
222 228
223 \begin{figure}[h] 229 \begin{figure}[ht]
224 \centering 230 \centering
225 \begin{digraphenv}{scale=0.5}{cfg2} 231 \begin{digraphenv}{scale=0.5}{cfg2}
226 \textnode{entry}{Entry} 232 \textnode{entry}{Entry}
227 \textnode{condition}{condition} 233 \textnode{condition}{condition}
228 \textnode{const0}{0} 234 \textnode{const0}{0}
240 \datalabel{phi:in3}{const1} 246 \datalabel{phi:in3}{const1}
241 \data{return}{phi} 247 \data{return}{phi}
242 \control{merge}{return} 248 \control{merge}{return}
243 \end{digraphenv} 249 \end{digraphenv}
244 \caption{A simple loop with two exits.} 250 \caption{A simple loop with two exits.}
245 \label{fig:exc1} 251 \label{fig:loopexits}
246 \end{figure} 252 \end{figure}
247 253
248 \section{Exceptions} 254 \section{Exceptions}
249 \label{sec:Exceptions} 255 \label{sec:Exceptions}
250 256
251 We do not throw runtime exceptions (e.g., \texttt{IndexOutOf\-BoundsException}, \texttt{NullPointerException}, or \texttt{Out\-Of\-MemoryException}), but deoptimize instead. 257 We do not throw runtime exceptions (e.g., \texttt{IndexOutOf\-BoundsException}, \texttt{Null\-Pointer\-Exception}, or \texttt{Out\-Of\-Memory\-Exception}), but deoptimize instead.
252 This reduces the places in the compiled code where an exact bytecode location and debug information must be known. 258 This reduces the places in the compiled code where an exact bytecode location and debug information must be known.
253 Additionally, this greatly reduces the number of exception handler edges in the compiled code. 259 Additionally, this greatly reduces the number of exception handler edges in the compiled code.
254 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. 260 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.
255 261
256 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. 262 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.
266 m3(); 272 m3();
267 throw exception; 273 throw exception;
268 } catch(Exception e) { ... } 274 } catch(Exception e) { ... }
269 \end{lstlisting} 275 \end{lstlisting}
270 276
271 \begin{figure}[h] 277 \begin{figure}[ht]
272 \centering 278 \centering
273 \begin{digraphenv}{scale=0.5}{exc1} 279 \begin{digraphenv}{scale=0.5}{exc1}
274 \textnode{entry}{Entry} 280 \textnode{entry}{Entry}
275 \textnode{catch1}{catch1} 281 \textnode{catch1}{catch1}
276 \textnode{catch2}{catch2} 282 \textnode{catch2}{catch2}
307 The edge between the \nodename{LoopBegin} and the \nodename{LoopEnd} is the backedge of the loop. 313 The edge between the \nodename{LoopBegin} and the \nodename{LoopEnd} is the backedge of the loop.
308 It goes from the beginning to the end in order to make the graph acyclic. 314 It goes from the beginning to the end in order to make the graph acyclic.
309 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. 315 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.
310 Figure \ref{fig:loop1} shows a simple example with a loop with a single entry and two exits. 316 Figure \ref{fig:loop1} shows a simple example with a loop with a single entry and two exits.
311 317
312 \begin{figure}[h] 318 \begin{figure}[ht]
313 \centering 319 \centering
314 \begin{digraphenv}{scale=0.5}{layout1} 320 \begin{digraphenv}{scale=0.5}{layout1}
315 \textnode{BeforeLoop}{Loop entry} 321 \textnode{BeforeLoop}{Loop entry}
316 \textnode{Exit1}{First loop exit} 322 \textnode{Exit1}{First loop exit}
317 \textnode{Exit2}{Second loop exit} 323 \textnode{Exit2}{Second loop exit}
340 346
341 \begin{lstlisting}[label=lst:loop, caption=Loop example that counts from 0 to n-1., captionpos=b] 347 \begin{lstlisting}[label=lst:loop, caption=Loop example that counts from 0 to n-1., captionpos=b]
342 for(int i=0; i<n; ++i) { } 348 for(int i=0; i<n; ++i) { }
343 \end{lstlisting} 349 \end{lstlisting}
344 350
345 \begin{figure}[h] 351 \begin{figure}[ht]
346 \centering 352 \centering
347 \begin{digraphenv}{scale=0.5}{layout2} 353 \begin{digraphenv}{scale=0.5}{layout2}
348 \textnode{BeforeLoop}{Loop entry} 354 \textnode{BeforeLoop}{Loop entry}
349 \textnode{Exit}{Loop exit} 355 \textnode{Exit}{Loop exit}
350 \textnode{n}{n} 356 \textnode{n}{n}
381 The compiler is capable of recognizing variables that are only increased within a loop. 387 The compiler is capable of recognizing variables that are only increased within a loop.
382 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). 388 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).
383 Figure \ref{fig:loop3} shows the compiler graph of the example loop after the loop counter transformation. 389 Figure \ref{fig:loop3} shows the compiler graph of the example loop after the loop counter transformation.
384 390
385 391
386 \begin{figure}[h] 392 \begin{figure}[ht]
387 \centering 393 \centering
388 \begin{digraphenv}{scale=0.5}{layout3} 394 \begin{digraphenv}{scale=0.5}{layout3}
389 \textnode{BeforeLoop}{Loop entry} 395 \textnode{BeforeLoop}{Loop entry}
390 \textnode{Exit}{Loop exit} 396 \textnode{Exit}{Loop exit}
391 \textnode{n}{n} 397 \textnode{n}{n}
418 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. 424 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.
419 If the total number of iterations is reached, the loop is exited directly from the loop header. 425 If the total number of iterations is reached, the loop is exited directly from the loop header.
420 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. 426 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.
421 Figure \ref{fig:loop4} shows the compiler graph of the example loop after the bounded loop transformation. 427 Figure \ref{fig:loop4} shows the compiler graph of the example loop after the bounded loop transformation.
422 428
423 \begin{figure}[h] 429 \begin{figure}[ht]
424 \centering 430 \centering
425 \begin{digraphenv}{scale=0.5}{layout4} 431 \begin{digraphenv}{scale=0.5}{layout4}
426 \textnode{BeforeLoop}{Loop entry} 432 \textnode{BeforeLoop}{Loop entry}
427 \textnode{Exit}{Loop exit} 433 \textnode{Exit}{Loop exit}
428 \textnode{n}{n} 434 \textnode{n}{n}
452 The vectorization is only possible if every node of the loop can be replaced with a corresponding vector node. 458 The vectorization is only possible if every node of the loop can be replaced with a corresponding vector node.
453 Figure \ref{fig:loop5} shows the compiler graph of the example loop after vectorization. 459 Figure \ref{fig:loop5} shows the compiler graph of the example loop after vectorization.
454 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. 460 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.
455 461
456 462
457 \begin{figure}[h] 463 \begin{figure}[ht]
458 \centering 464 \centering
459 \begin{digraphenv}{scale=0.5}{layout5} 465 \begin{digraphenv}{scale=0.5}{layout5}
460 \textnode{Entry}{Entry} 466 \textnode{Entry}{Entry}
461 \textnode{Exit}{Exit} 467 \textnode{Exit}{Exit}
462 \textnode{n}{n} 468 \textnode{n}{n}
502 508
503 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. 509 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.
504 We save the frame state at control flow merges if there is at least one frame state on any control flow path between a node and its immediate dominator. 510 We save the frame state at control flow merges if there is at least one frame state on any control flow path between a node and its immediate dominator.
505 511
506 512
507 \begin{figure}[h] 513 \begin{figure}[ht]
508 \centering 514 \centering
509 \begin{digraphenv}{scale=0.5}{fs1} 515 \begin{digraphenv}{scale=0.5}{fs1}
510 \nodetrisplit{store1}{ArrayStore} 516 \nodetrisplit{store1}{ArrayStore}
511 \nodebi{load1}{ArrayLoad} 517 \nodebi{load1}{ArrayLoad}
512 \controllabel{store1:succ1}{load1} 518 \controllabel{store1:succ1}{load1}
576 } 582 }
577 p.y = 0; 583 p.y = 0;
578 } 584 }
579 \end{lstlisting} 585 \end{lstlisting}
580 586
581 \begin{figure}[h] 587 \begin{figure}[ht]
582 \centering 588 \centering
583 \begin{digraphenv}{scale=0.5}{guard0} 589 \begin{digraphenv}{scale=0.5}{guard0}
584 \textnode{entry}{Entry} 590 \textnode{entry}{Entry}
585 \nodesplit{if}{If} 591 \nodesplit{if}{If}
586 \node{merge}{Merge} 592 \node{merge}{Merge}
613 619
614 Figure~\ref{fig:guard1} shows the example graph at a later compilation phase when the field store instructions are lowered to memory store instructions and explicitely modelled null check guards. 620 Figure~\ref{fig:guard1} shows the example graph at a later compilation phase when the field store instructions are lowered to memory store instructions and explicitely modelled null check guards.
615 The guards are attached to anchor instructions that delimit their possible schedule. 621 The guards are attached to anchor instructions that delimit their possible schedule.
616 The first guard must not be moved outside the \texttt{if} block; the second guard may be moved before the \texttt{If} instruction, because at this point it is already guaranteed that the second store is executed. 622 The first guard must not be moved outside the \texttt{if} block; the second guard may be moved before the \texttt{If} instruction, because at this point it is already guaranteed that the second store is executed.
617 623
618 \begin{figure}[h] 624 \begin{figure}[ht]
619 \centering 625 \centering
620 \begin{digraphenv}{scale=0.5}{guard1} 626 \begin{digraphenv}{scale=0.5}{guard1}
621 \textnode{entry}{Entry} 627 \textnode{entry}{Entry}
622 \node{anchor1}{Anchor} 628 \node{anchor1}{Anchor}
623 \node{anchor2}{Anchor} 629 \node{anchor2}{Anchor}
664 Therefore we can remove the guard and the anchor from the graph and this gives us the graph shown in Figure \ref{fig:guard2}. 670 Therefore we can remove the guard and the anchor from the graph and this gives us the graph shown in Figure \ref{fig:guard2}.
665 671
666 There is another optimization for guard instructions: 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. 672 There is another optimization for guard instructions: 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.
667 673
668 674
669 \begin{figure}[h] 675 \begin{figure}[ht]
670 \centering 676 \centering
671 \begin{digraphenv}{scale=0.5}{guard2} 677 \begin{digraphenv}{scale=0.5}{guard2}
672 \textnode{entry}{Entry} 678 \textnode{entry}{Entry}
673 \node{anchor1}{Anchor} 679 \node{anchor1}{Anchor}
674 \nodesplit{if}{If} 680 \nodesplit{if}{If}
708 The remaining guard can now be moved above the \texttt{If} condition and be used to eliminate the need for the \texttt{If} node. 714 The remaining guard can now be moved above the \texttt{If} condition and be used to eliminate the need for the \texttt{If} node.
709 From this point on, the guard can however no longer be moved below the first memory store. 715 From this point on, the guard can however no longer be moved below the first memory store.
710 We use a control dependency from the guard to the field store to express this condition. 716 We use a control dependency from the guard to the field store to express this condition.
711 The link between the second store and the guard and the control flow merge instruction is no longer necessary. 717 The link between the second store and the guard and the control flow merge instruction is no longer necessary.
712 718
713 \begin{figure}[h] 719 \begin{figure}[ht]
714 \centering 720 \centering
715 \begin{digraphenv}{scale=0.5}{guard3} 721 \begin{digraphenv}{scale=0.5}{guard3}
716 \textnode{entry}{Entry} 722 \textnode{entry}{Entry}
717 \node{anchor1}{Anchor} 723 \node{anchor1}{Anchor}
718 \node{return}{Return} 724 \node{return}{Return}
748 This will generate deoptimization-free zones that can be targeted by the most aggressive optimizations. 754 This will generate deoptimization-free zones that can be targeted by the most aggressive optimizations.
749 A simple algorithm for this removal of frame states would be to move all guards as far upwards as possible and then the guards are fixed using anchor nodes. 755 A simple algorithm for this removal of frame states would be to move all guards as far upwards as possible and then the guards are fixed using anchor nodes.
750 In our example, the guard is already fixed, so there is no deoptimization point that uses any of the memory store frame states. 756 In our example, the guard is already fixed, so there is no deoptimization point that uses any of the memory store frame states.
751 Therefore we can delete the frame states from the graph (see Figure \ref{fig:guard4}). 757 Therefore we can delete the frame states from the graph (see Figure \ref{fig:guard4}).
752 758
753 \begin{figure}[h] 759 \begin{figure}[ht]
754 \centering 760 \centering
755 \begin{digraphenv}{scale=0.5}{guard4} 761 \begin{digraphenv}{scale=0.5}{guard4}
756 \textnode{entry}{Entry} 762 \textnode{entry}{Entry}
757 \node{anchor1}{Anchor} 763 \node{anchor1}{Anchor}
758 \node{return}{Return} 764 \node{return}{Return}
783 Now we can use memory coalescing to combine the two stores without frame state to adjacent locations in the same object. 789 Now we can use memory coalescing to combine the two stores without frame state to adjacent locations in the same object.
784 This is only possible if the first store does not have a frame state. 790 This is only possible if the first store does not have a frame state.
785 Figure \ref{fig:guard5} shows the resulting graph. 791 Figure \ref{fig:guard5} shows the resulting graph.
786 792
787 793
788 \begin{figure}[h] 794 \begin{figure}[ht]
789 \centering 795 \centering
790 \begin{digraphenv}{scale=0.5}{guard5} 796 \begin{digraphenv}{scale=0.5}{guard5}
791 \textnode{entry}{Entry} 797 \textnode{entry}{Entry}
792 \node{anchor1}{Anchor} 798 \node{anchor1}{Anchor}
793 \node{return}{Return} 799 \node{return}{Return}
812 818
813 A memory store that immediately follows a null check guard instruction on the same object, can be combined into a store with an implicit null check (that deoptimizes instead of throwing the exception). 819 A memory store that immediately follows a null check guard instruction on the same object, can be combined into a store with an implicit null check (that deoptimizes instead of throwing the exception).
814 Therefore, we can remove the guard again and also the anchor is no longer necessary. 820 Therefore, we can remove the guard again and also the anchor is no longer necessary.
815 Figure~\ref{fig:guard6} shows now that fully optimized graph that is generated for Listing~\ref{lst:guard1}. 821 Figure~\ref{fig:guard6} shows now that fully optimized graph that is generated for Listing~\ref{lst:guard1}.
816 822
817 \begin{figure}[h] 823 \begin{figure}[ht]
818 \centering 824 \centering
819 \begin{digraphenv}{scale=0.5}{guard6} 825 \begin{digraphenv}{scale=0.5}{guard6}
820 \textnode{entry}{Entry} 826 \textnode{entry}{Entry}
821 \node{return}{Return} 827 \node{return}{Return}
822 \textnode{p}{p} 828 \textnode{p}{p}