Mercurial > hg > graal-compiler
comparison graal/GraalCompiler/src/com/sun/c1x/graph/package-info.java @ 2509:16b9a8b5ad39
Renamings Runtime=>GraalRuntime and Compiler=>GraalCompiler
author | Thomas Wuerthinger <thomas@wuerthinger.net> |
---|---|
date | Wed, 27 Apr 2011 11:50:44 +0200 |
parents | graal/Compiler/src/com/sun/c1x/graph/package-info.java@9ec15d6914ca |
children |
comparison
equal
deleted
inserted
replaced
2508:fea94949e0a2 | 2509:16b9a8b5ad39 |
---|---|
1 /* | |
2 * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
12 * version 2 for more details (a copy is included in the LICENSE file that | |
13 * accompanied this code). | |
14 * | |
15 * You should have received a copy of the GNU General Public License version | |
16 * 2 along with this work; if not, write to the Free Software Foundation, | |
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
18 * | |
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
20 * or visit www.oracle.com if you need additional information or have any | |
21 * questions. | |
22 */ | |
23 | |
24 /** | |
25 * <H2>IR Graph building</H2> | |
26 * | |
27 * The {@link com.sun.c1x.graph.IR} class drives the generation of the HIR graph for a method, making use of other | |
28 * utility classes in this package. | |
29 * | |
30 * The graph building is separated into a basic build phase ({@link com.sun.c1x.graph.IR#buildGraph} method)and | |
31 * (currently) two optimization phases ({@link com.sun.c1x.graph.IR#optimize1} and | |
32 * {@link com.sun.c1x.graph.IR#optimize2}) although the basic phase also does some (basic) optimizations. | |
33 * | |
34 * <H2>Basic Graph Build Phase</H2> | |
35 * | |
36 * {@code IR.buildGraph} creates an {@link com.sun.c1x.ir.IRScope topScope} object, | |
37 * that represents a context for inlining, and then invokes the constructor for the | |
38 * {@link com.sun.c1x.graph.GraphBuilder} class, passing the {@link com.sun.c1x.C1XCompilation}, and {@code IR} | |
39 * instances, which are cached. The following support objects are created in the constructor: | |
40 * | |
41 * <ul> | |
42 * <li>{@code memoryMap}: an instance of {@link com.sun.c1x.graph.MemoryMap} | |
43 * <li>{@code localValueMap}: an instance of {@link com.sun.c1x.opt.ValueMap} | |
44 * <li>{@code canonicalizer}: an instance of {@link com.sun.c1x.opt.Canonicalizer} | |
45 * </ul> | |
46 * | |
47 * Now the {@link com.sun.c1x.graph.GraphBuilder#build} is invoked with {@code topScope} as argument. | |
48 * | |
49 * <H3>{@code GraphBuilder.build}</H3> | |
50 * | |
51 * <ol> | |
52 * <li>The {@link com.sun.c1x.graph.IR#startBlock} field of the cached {@link com.sun.c1x.graph.IR} instance is set to a newly created | |
53 * {@link com.sun.c1x.ir.BlockBegin} node, with bytecode index 0 and then the {@link com.sun.c1x.graph.BlockMap} is | |
54 * constructed by calling {@link com.sun.c1x.C1XCompilation#getBlockMap}. This behaves slightly differently depending on | |
55 * whether this is an OSR compilation. If so, a new {@link com.sun.c1x.ir.BlockBegin} node is added to the map at the OSR bytecode | |
56 * index. The map is then built by the{@link com.sun.c1x.graph.BlockMap#build}, which takes a boolean argument that | |
57 * controls whether a second pass is made over the bytecodes to compute stores in loops. This always false for an OSR | |
58 * compilation (why?). Otherwise, it is only true if enabled by the {@link com.sun.c1x.C1XOptions#PhiLoopStores} | |
59 * compilation option. FInally some unneeded state from the map is removed by the {@link com.sun.c1x.graph.BlockMap#cleanup} method, and | |
60 * the statistics are updated. | |
61 * </li> | |
62 * | |
63 * <li>Next the {@link com.sun.c1x.graph.GraphBuilder#pushRootScope} method is called, with the passed-in {@link com.sun.c1x.ir.IRScope} | |
64 * object, the {@link com.sun.c1x.graph.BlockMap} returned by build and the {@code startBlock}. (Note: Unlike | |
65 * {@link com.sun.c1x.graph.GraphBuilder#pushScope}, this method does not propagate the | |
66 * {@link com.sun.c1x.graph.BlockMap#storesInLoops} field to the {@link com.sun.c1x.ir.IRScope} object, which means that | |
67 * {@link com.sun.c1x.ir.BlockBegin#insertLoopPhis} will always get null for this value. Is this a bug?). | |
68 * {@link com.sun.c1x.graph.GraphBuilder#pushRootScope} initializes the {@link com.sun.c1x.graph.GraphBuilder#scopeData} field with a | |
69 * {@link com.sun.c1x.graph.ScopeData} instance, with null parent. The | |
70 * {@link com.sun.c1x.graph.GraphBuilder#compilation} instance is called to get an {@link com.sun.cri.ri.RiConstantPool} | |
71 * , which is C1X's interface to constant pool information. The {@link com.sun.c1x.graph.GraphBuilder#curBlock} field is | |
72 * set to the {@code startBlock}. | |
73 * <p> | |
74 * | |
75 * Now a {@link com.sun.c1x.value.FrameState initialState} object is created by | |
76 * {@link com.sun.c1x.graph.GraphBuilder#stateAtEntry}. If the method is not static, then a {@link com.sun.c1x.ir.Local} | |
77 * instance is created at index 0. Since the receiver cannot be {@code null}, the | |
78 * {@link com.sun.c1x.ir.Value.Flag#NonNull} flag is set. Additional {@link com.sun.c1x.ir.Local} instances are created for the | |
79 * arguments to the method. The index is incremented by the number of slots occupied by the | |
80 * {@link com.sun.cri.ci.CiKind} corresponding to the argument type. All the {@link com.sun.c1x.ir.Local} instances are stored in the | |
81 * {@link com.sun.c1x.value.FrameState} using the {@link com.sun.c1x.value.FrameState#storeLocal} method. This {@link com.sun.c1x.value.FrameState} is then | |
82 * merged into the {@link com.sun.c1x.ir.BlockBegin#stateBefore} for the {@code startBlock}, which just results in a | |
83 * copy since {@code stateBefore} will be {@code null}. | |
84 * </li> | |
85 * <li> | |
86 * This step sets up three instance fields: {@link com.sun.c1x.graph.GraphBuilder#curBlock} and | |
87 * {@link com.sun.c1x.graph.GraphBuilder#lastInstr} to {@code startBlock} and | |
88 * {@link com.sun.c1x.graph.GraphBuilder#curState} to {@code initialState}. (N.B. the setting of {@code curBlock} is | |
89 * redundant as it is done in {@link com.sun.c1x.graph.GraphBuilder#pushRootScope}). | |
90 * </li> | |
91 * <li> | |
92 * Step 4 contains special handling for synchronized methods (TBD), otherwise it calls | |
93 * {@link com.sun.c1x.graph.GraphBuilder#finishStartBlock} which adds a {@link com.sun.c1x.ir.Base} block as the end of | |
94 * the {@code startBlock}. The {@link com.sun.c1x.ir.Base} block has one successor set to the (entry) block with flag | |
95 * {@link com.sun.c1x.ir.BlockBegin.BlockFlag#StandardEntry}, that was created by {@link com.sun.c1x.graph.BlockMap#build} (and possibly a | |
96 * successor to an OSREntry block). | |
97 * </li> | |
98 * <li> | |
99 * Then the {@link com.sun.c1x.ir.IRScope#lockStackSize} is computed. (TBD) | |
100 * </li> | |
101 * <li> | |
102 * Then the method is checked for being intrinsic, i.e., one that has a hard-wired implementation known to C1X. If so, | |
103 * and {@link com.sun.c1x.C1XOptions#OptIntrinsify} is set, an attempt is made to inline it (TBD). Otherwise, or if the | |
104 * intrinsification fails, normal processing continues by adding the entry block to the | |
105 * {@link com.sun.c1x.graph.ScopeData} work list (kept topologically sorted) and calling | |
106 * {@link com.sun.c1x.graph.GraphBuilder#iterateAllBlocks}. | |
107 * </li> | |
108 * <li> | |
109 * Finally there is some cleanup code for synchronized blocks and OSR compilations. | |
110 * </li> | |
111 * </ol> | |
112 * | |
113 * <H3>{@link com.sun.c1x.graph.GraphBuilder#iterateAllBlocks}</H3> | |
114 * {@link com.sun.c1x.graph#iterateAllBlocks} repeatedly removes a block from the work list and, if not already visited, marks it so, | |
115 * kills the current memory map, sets {@link com.sun.c1x.graph.GraphBuilder#curBlock}, {@link com.sun.c1x.graph.GraphBuilder#curState} and {@link com.sun.c1x.graph.GraphBuilder#lastInstr} and then calls | |
116 * {@link com.sun.c1x.graph.GraphBuilder#iterateBytecodesForBlock}. | |
117 * | |
118 * This process continues until all the blocks have been visited (processed) after which control returns to {@code | |
119 * build}. | |
120 * <p> | |
121 | |
122 * <H3>{@link com.sun.c1x.graph.GraphBuilder#iterateBytecodesForBlock}</H3> | |
123 * | |
124 * {@link com.sun.c1x.graph.GraphBuilder#iterateBytecodesForBlock} performs an abstract interpretation of the bytecodes in the block, appending new | |
125 * nodes as necessary, until the last added node is an instance of {@link com.sun.c1x.ir.BlockEnd}. (Note: It has an | |
126 * explicit check for finding a new {@link com.sun.c1x.ir.BlockBegin} before a {@link com.sun.c1x.ir.BlockEnd} but | |
127 * {@link com.sun.c1x.graph.BlockMap#moveSuccessorLists} has a similar check so this may be redundant). For example, | |
128 * consider the following bytecodes: | |
129 * | |
130 * <pre> | |
131 * <code> | |
132 * 0: iconst_0 | |
133 * 1: istore_2 | |
134 * 2: goto 22 | |
135 * </code> | |
136 * </pre> | |
137 * | |
138 * The {@code iconst_0} bytecode causes a {@link com.sun.c1x.ir.Constant} node representing zero to be pushed on the | |
139 * {@link com.sun.c1x.graph.GraphBuilder#curState} stack and the node to be appended to the {@link com.sun.c1x.ir.BlockBegin} (entry) node associated with index 0. | |
140 * The {@code istore_2} causes the node to be popped of the stack and stored in the local slot 2. No IR node is | |
141 * generated for the {@code istore_2}. The {@code goto} creates a {@link com.sun.c1x.ir.Goto} node which is a subclass | |
142 * of {@link com.sun.c1x.ir.BlockEnd}, so this terminates the iteration. As part of termination the {@link com.sun.c1x.ir.Goto} node is marked as the | |
143 * end node of the current block and the {@link com.sun.c1x.value.FrameState} is propagated to the successor node(s) by merging any | |
144 * existing {@link com.sun.c1x.value.FrameState} with the current state. If the target is a loop header node this involves inserting | |
145 * {@link com.sun.c1x.ir.Phi} nodes. Finally, the target node is added to the {@code scopeData} work list. | |
146 * <p> | |
147 * | |
148 * | |
149 * @author Ben Titzer | |
150 * @author Mick Jordan | |
151 * | |
152 */ | |
153 package com.sun.c1x.graph; |