comparison graal/com.oracle.max.graal.compiler/src/com/oracle/max/graal/compiler/graph/package-info.java @ 2874:d90bf514d647

Renamed packages.
author Thomas Wuerthinger <thomas@wuerthinger.net>
date Wed, 08 Jun 2011 08:59:54 +0200
parents graal/com.oracle.max.graal.compiler/src/com/sun/c1x/graph/package-info.java@0341b6424579
children 7f584bf507ed
comparison
equal deleted inserted replaced
2873:810e2d253e00 2874:d90bf514d647
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.oracle.max.graal.compiler.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.oracle.max.graal.compiler.graph.IR#buildGraph} method)and
31 * (currently) two optimization phases ({@link com.oracle.max.graal.compiler.graph.IR#optimize1} and
32 * {@link com.oracle.max.graal.compiler.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.oracle.max.graal.compiler.ir.IRScope topScope} object,
37 * that represents a context for inlining, and then invokes the constructor for the
38 * {@link com.oracle.max.graal.compiler.graph.GraphBuilder} class, passing the {@link com.oracle.max.graal.compiler.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.oracle.max.graal.compiler.graph.MemoryMap}
43 * <li>{@code localValueMap}: an instance of {@link com.oracle.max.graal.compiler.opt.ValueMap}
44 * <li>{@code canonicalizer}: an instance of {@link com.oracle.max.graal.compiler.opt.Canonicalizer}
45 * </ul>
46 *
47 * Now the {@link com.oracle.max.graal.compiler.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.oracle.max.graal.compiler.graph.IR#startBlock} field of the cached {@link com.oracle.max.graal.compiler.graph.IR} instance is set to a newly created
53 * {@link com.oracle.max.graal.compiler.ir.BlockBegin} node, with bytecode index 0 and then the {@link com.oracle.max.graal.compiler.graph.BlockMap} is
54 * constructed by calling {@link com.oracle.max.graal.compiler.C1XCompilation#getBlockMap}. This behaves slightly differently depending on
55 * whether this is an OSR compilation. If so, a new {@link com.oracle.max.graal.compiler.ir.BlockBegin} node is added to the map at the OSR bytecode
56 * index. The map is then built by the{@link com.oracle.max.graal.compiler.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.oracle.max.graal.compiler.C1XOptions#PhiLoopStores}
59 * compilation option. FInally some unneeded state from the map is removed by the {@link com.oracle.max.graal.compiler.graph.BlockMap#cleanup} method, and
60 * the statistics are updated.
61 * </li>
62 *
63 * <li>Next the {@link com.oracle.max.graal.compiler.graph.GraphBuilder#pushRootScope} method is called, with the passed-in {@link com.oracle.max.graal.compiler.ir.IRScope}
64 * object, the {@link com.oracle.max.graal.compiler.graph.BlockMap} returned by build and the {@code startBlock}. (Note: Unlike
65 * {@link com.oracle.max.graal.compiler.graph.GraphBuilder#pushScope}, this method does not propagate the
66 * {@link com.oracle.max.graal.compiler.graph.BlockMap#storesInLoops} field to the {@link com.oracle.max.graal.compiler.ir.IRScope} object, which means that
67 * {@link com.oracle.max.graal.compiler.ir.BlockBegin#insertLoopPhis} will always get null for this value. Is this a bug?).
68 * {@link com.oracle.max.graal.compiler.graph.GraphBuilder#pushRootScope} initializes the {@link com.oracle.max.graal.compiler.graph.GraphBuilder#scopeData} field with a
69 * {@link com.oracle.max.graal.compiler.graph.ScopeData} instance, with null parent. The
70 * {@link com.oracle.max.graal.compiler.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.oracle.max.graal.compiler.graph.GraphBuilder#curBlock} field is
72 * set to the {@code startBlock}.
73 * <p>
74 *
75 * Now a {@link com.oracle.max.graal.compiler.value.FrameState initialState} object is created by
76 * {@link com.oracle.max.graal.compiler.graph.GraphBuilder#stateAtEntry}. If the method is not static, then a {@link com.oracle.max.graal.compiler.ir.Local}
77 * instance is created at index 0. Since the receiver cannot be {@code null}, the
78 * {@link com.oracle.max.graal.compiler.ir.Value.Flag#NonNull} flag is set. Additional {@link com.oracle.max.graal.compiler.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.oracle.max.graal.compiler.ir.Local} instances are stored in the
81 * {@link com.oracle.max.graal.compiler.value.FrameState} using the {@link com.oracle.max.graal.compiler.value.FrameState#storeLocal} method. This {@link com.oracle.max.graal.compiler.value.FrameState} is then
82 * merged into the {@link com.oracle.max.graal.compiler.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.oracle.max.graal.compiler.graph.GraphBuilder#curBlock} and
87 * {@link com.oracle.max.graal.compiler.graph.GraphBuilder#lastInstr} to {@code startBlock} and
88 * {@link com.oracle.max.graal.compiler.graph.GraphBuilder#curState} to {@code initialState}. (N.B. the setting of {@code curBlock} is
89 * redundant as it is done in {@link com.oracle.max.graal.compiler.graph.GraphBuilder#pushRootScope}).
90 * </li>
91 * <li>
92 * Step 4 contains special handling for synchronized methods (TBD), otherwise it calls
93 * {@link com.oracle.max.graal.compiler.graph.GraphBuilder#finishStartBlock} which adds a {@link com.oracle.max.graal.compiler.ir.Base} block as the end of
94 * the {@code startBlock}. The {@link com.oracle.max.graal.compiler.ir.Base} block has one successor set to the (entry) block with flag
95 * {@link com.oracle.max.graal.compiler.ir.BlockBegin.BlockFlag#StandardEntry}, that was created by {@link com.oracle.max.graal.compiler.graph.BlockMap#build} (and possibly a
96 * successor to an OSREntry block).
97 * </li>
98 * <li>
99 * Then the {@link com.oracle.max.graal.compiler.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.oracle.max.graal.compiler.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.oracle.max.graal.compiler.graph.ScopeData} work list (kept topologically sorted) and calling
106 * {@link com.oracle.max.graal.compiler.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.oracle.max.graal.compiler.graph.GraphBuilder#iterateAllBlocks}</H3>
114 * {@link com.oracle.max.graal.compiler.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.oracle.max.graal.compiler.graph.GraphBuilder#curBlock}, {@link com.oracle.max.graal.compiler.graph.GraphBuilder#curState}
116 * and {@link com.oracle.max.graal.compiler.graph.GraphBuilder#lastInstr} and then calls
117 * {@link com.oracle.max.graal.compiler.graph.GraphBuilder#iterateBytecodesForBlock}.
118 *
119 * This process continues until all the blocks have been visited (processed) after which control returns to {@code
120 * build}.
121 * <p>
122
123 * <H3>{@link com.oracle.max.graal.compiler.graph.GraphBuilder#iterateBytecodesForBlock}</H3>
124 *
125 * {@link com.oracle.max.graal.compiler.graph.GraphBuilder#iterateBytecodesForBlock} performs an abstract interpretation of the bytecodes in the block, appending new
126 * nodes as necessary, until the last added node is an instance of {@link com.oracle.max.graal.compiler.ir.BlockEnd}. (Note: It has an
127 * explicit check for finding a new {@link com.oracle.max.graal.compiler.ir.BlockBegin} before a {@link com.oracle.max.graal.compiler.ir.BlockEnd} but
128 * {@link com.oracle.max.graal.compiler.graph.BlockMap#moveSuccessorLists} has a similar check so this may be redundant). For example,
129 * consider the following bytecodes:
130 *
131 * <pre>
132 * <code>
133 * 0: iconst_0
134 * 1: istore_2
135 * 2: goto 22
136 * </code>
137 * </pre>
138 *
139 * The {@code iconst_0} bytecode causes a {@link com.oracle.max.graal.compiler.ir.Constant} node representing zero to be pushed on the
140 * {@link com.oracle.max.graal.compiler.graph.GraphBuilder#curState} stack and the node to be appended to the {@link com.oracle.max.graal.compiler.ir.BlockBegin} (entry) node associated with index 0.
141 * The {@code istore_2} causes the node to be popped of the stack and stored in the local slot 2. No IR node is
142 * generated for the {@code istore_2}. The {@code goto} creates a {@link com.oracle.max.graal.compiler.ir.Goto} node which is a subclass
143 * of {@link com.oracle.max.graal.compiler.ir.BlockEnd}, so this terminates the iteration. As part of termination the {@link com.oracle.max.graal.compiler.ir.Goto} node is marked as the
144 * end node of the current block and the {@link com.oracle.max.graal.compiler.value.FrameState} is propagated to the successor node(s) by merging any
145 * existing {@link com.oracle.max.graal.compiler.value.FrameState} with the current state. If the target is a loop header node this involves inserting
146 * {@link com.oracle.max.graal.compiler.ir.Phi} nodes. Finally, the target node is added to the {@code scopeData} work list.
147 * <p>
148 *
149 *
150 * @author Ben Titzer
151 * @author Mick Jordan
152 *
153 */
154 package com.oracle.max.graal.compiler.graph;