annotate graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/LoweringPhase.java @ 13246:0909754d87f4

tightened assertion about lowering a floating node with unscheduled usages to cases where it really matters
author Doug Simon <doug.simon@oracle.com>
date Wed, 04 Dec 2013 16:03:21 +0100
parents 438ed35bed29
children 17c9afa0bfcb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
1 /*
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
4 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
8 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
13 * accompanied this code).
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
14 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
18 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
21 * questions.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
22 */
6526
ee651c726397 split phases out of graal.phases project into graal.phases.common project
Doug Simon <doug.simon@oracle.com>
parents: 6525
diff changeset
23 package com.oracle.graal.phases.common;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
24
9864
063a712fe8d8 converted remaining options in GraalOptions to new system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 9646
diff changeset
25 import static com.oracle.graal.phases.GraalOptions.*;
063a712fe8d8 converted remaining options in GraalOptions to new system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 9646
diff changeset
26
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 6285
diff changeset
27 import java.util.*;
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 6285
diff changeset
28
5510
426c605c9d3c Move cri.ci to api.code.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5507
diff changeset
29 import com.oracle.graal.api.code.*;
5507
dc71b06d09f8 Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5506
diff changeset
30 import com.oracle.graal.api.meta.*;
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
31 import com.oracle.graal.graph.*;
12686
ca8ab182026f abstracted a graph mark as a Mark object (hiding the node index)
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
32 import com.oracle.graal.graph.Graph.Mark;
6285
471b9eb7419d made LoweringPhase use a schedule so that floating and fixed nodes are lowered iteratively together
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
33 import com.oracle.graal.graph.iterators.*;
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
34 import com.oracle.graal.nodes.*;
11732
03c781923573 made snippet and substitution graphs lower themselves before being inlined
Doug Simon <doug.simon@oracle.com>
parents: 11705
diff changeset
35 import com.oracle.graal.nodes.StructuredGraph.GuardsStage;
5425
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5397
diff changeset
36 import com.oracle.graal.nodes.calc.*;
6529
2e96dc4eb8e2 renamed package: com.oracle.graal.lir.cfg -> com.oracle.graal.nodes.cfg
Doug Simon <doug.simon@oracle.com>
parents: 6526
diff changeset
37 import com.oracle.graal.nodes.cfg.*;
9646
183d33c76419 Removed ValueNode.dependencies
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 9376
diff changeset
38 import com.oracle.graal.nodes.extended.*;
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
39 import com.oracle.graal.nodes.spi.*;
11265
ef6915cf1e59 Add illegal stamp
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 10710
diff changeset
40 import com.oracle.graal.nodes.type.*;
6525
2c913b643422 rename packages in graal.phases to match project name
Doug Simon <doug.simon@oracle.com>
parents: 6522
diff changeset
41 import com.oracle.graal.phases.*;
2c913b643422 rename packages in graal.phases to match project name
Doug Simon <doug.simon@oracle.com>
parents: 6522
diff changeset
42 import com.oracle.graal.phases.schedule.*;
9267
950a385e059b Make LoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 9266
diff changeset
43 import com.oracle.graal.phases.tiers.*;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
44
5247
62bbfd78c703 removed mechanism for lowering ExceptionObjectNode via substitution; only LIR lowering by the runtime is now supported
Doug Simon <doug.simon@oracle.com>
parents: 5242
diff changeset
45 /**
62bbfd78c703 removed mechanism for lowering ExceptionObjectNode via substitution; only LIR lowering by the runtime is now supported
Doug Simon <doug.simon@oracle.com>
parents: 5242
diff changeset
46 * Processes all {@link Lowerable} nodes to do their lowering.
62bbfd78c703 removed mechanism for lowering ExceptionObjectNode via substitution; only LIR lowering by the runtime is now supported
Doug Simon <doug.simon@oracle.com>
parents: 5242
diff changeset
47 */
9267
950a385e059b Make LoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 9266
diff changeset
48 public class LoweringPhase extends BasePhase<PhaseContext> {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
49
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 6285
diff changeset
50 final class LoweringToolImpl implements LoweringTool {
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 6285
diff changeset
51
9267
950a385e059b Make LoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 9266
diff changeset
52 private final PhaseContext context;
7535
f057113c7a87 provide TargetDescription in LoweringTool
Lukas Stadler <lukas.stadler@jku.at>
parents: 7307
diff changeset
53 private final NodeBitMap activeGuards;
12702
44c0e08c4150 Lowering should handle the case where the current guard anchor gets lowered and does not exist anymore
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 12686
diff changeset
54 private GuardingNode guardAnchor;
7535
f057113c7a87 provide TargetDescription in LoweringTool
Lukas Stadler <lukas.stadler@jku.at>
parents: 7307
diff changeset
55 private FixedWithNextNode lastFixedNode;
f057113c7a87 provide TargetDescription in LoweringTool
Lukas Stadler <lukas.stadler@jku.at>
parents: 7307
diff changeset
56 private ControlFlowGraph cfg;
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 6285
diff changeset
57
11500
d2f31e6ddc35 LoweringTool: pass initial lastFixedNode to constructor
Bernhard Urban <bernhard.urban@jku.at>
parents: 11462
diff changeset
58 public LoweringToolImpl(PhaseContext context, GuardingNode guardAnchor, NodeBitMap activeGuards, FixedWithNextNode lastFixedNode, ControlFlowGraph cfg) {
9267
950a385e059b Make LoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 9266
diff changeset
59 this.context = context;
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 6285
diff changeset
60 this.guardAnchor = guardAnchor;
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 6285
diff changeset
61 this.activeGuards = activeGuards;
11500
d2f31e6ddc35 LoweringTool: pass initial lastFixedNode to constructor
Bernhard Urban <bernhard.urban@jku.at>
parents: 11462
diff changeset
62 this.lastFixedNode = lastFixedNode;
6653
2d5407ae1ac4 intermediate materialization is now removed during lowering of an InstanceOfNode that has a single usage which is an IfNode in the same block
Doug Simon <doug.simon@oracle.com>
parents: 6529
diff changeset
63 this.cfg = cfg;
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 6285
diff changeset
64 }
5425
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5397
diff changeset
65
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5397
diff changeset
66 @Override
12052
0afe7370260c refactored constantEquals(), lookupArrayLength() and readUnsafeConstant() out of MetaAccessProvider into ConstantReflectionProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 12045
diff changeset
67 public ConstantReflectionProvider getConstantReflection() {
0afe7370260c refactored constantEquals(), lookupArrayLength() and readUnsafeConstant() out of MetaAccessProvider into ConstantReflectionProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 12045
diff changeset
68 return context.getConstantReflection();
0afe7370260c refactored constantEquals(), lookupArrayLength() and readUnsafeConstant() out of MetaAccessProvider into ConstantReflectionProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 12045
diff changeset
69 }
0afe7370260c refactored constantEquals(), lookupArrayLength() and readUnsafeConstant() out of MetaAccessProvider into ConstantReflectionProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 12045
diff changeset
70
0afe7370260c refactored constantEquals(), lookupArrayLength() and readUnsafeConstant() out of MetaAccessProvider into ConstantReflectionProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 12045
diff changeset
71 @Override
11959
23ccaa863eda made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11804
diff changeset
72 public MetaAccessProvider getMetaAccess() {
23ccaa863eda made CodeCacheProvider independent of MetaAccessProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11804
diff changeset
73 return context.getMetaAccess();
5425
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5397
diff changeset
74 }
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5397
diff changeset
75
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5397
diff changeset
76 @Override
12045
0fc653a9e019 made GraalCodeCacheProvider independent of CodeCacheProvider and renamed the former to LoweringProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11959
diff changeset
77 public LoweringProvider getLowerer() {
0fc653a9e019 made GraalCodeCacheProvider independent of CodeCacheProvider and renamed the former to LoweringProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11959
diff changeset
78 return context.getLowerer();
0fc653a9e019 made GraalCodeCacheProvider independent of CodeCacheProvider and renamed the former to LoweringProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11959
diff changeset
79 }
0fc653a9e019 made GraalCodeCacheProvider independent of CodeCacheProvider and renamed the former to LoweringProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11959
diff changeset
80
0fc653a9e019 made GraalCodeCacheProvider independent of CodeCacheProvider and renamed the former to LoweringProvider (GRAAL-511)
Doug Simon <doug.simon@oracle.com>
parents: 11959
diff changeset
81 @Override
8638
8d6265614e13 added getReplacements() to LoweringTool
Doug Simon <doug.simon@oracle.com>
parents: 8298
diff changeset
82 public Replacements getReplacements() {
9267
950a385e059b Make LoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 9266
diff changeset
83 return context.getReplacements();
8638
8d6265614e13 added getReplacements() to LoweringTool
Doug Simon <doug.simon@oracle.com>
parents: 8298
diff changeset
84 }
8d6265614e13 added getReplacements() to LoweringTool
Doug Simon <doug.simon@oracle.com>
parents: 8298
diff changeset
85
8d6265614e13 added getReplacements() to LoweringTool
Doug Simon <doug.simon@oracle.com>
parents: 8298
diff changeset
86 @Override
12703
b6f66fb9f106 SnippetTemplate instantiation should replace snippet's start node with a valid anchor point not the caller's start node
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 12702
diff changeset
87 public GuardingNode getCurrentGuardAnchor() {
b6f66fb9f106 SnippetTemplate instantiation should replace snippet's start node with a valid anchor point not the caller's start node
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 12702
diff changeset
88 return guardAnchor;
b6f66fb9f106 SnippetTemplate instantiation should replace snippet's start node with a valid anchor point not the caller's start node
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 12702
diff changeset
89 }
b6f66fb9f106 SnippetTemplate instantiation should replace snippet's start node with a valid anchor point not the caller's start node
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 12702
diff changeset
90
b6f66fb9f106 SnippetTemplate instantiation should replace snippet's start node with a valid anchor point not the caller's start node
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 12702
diff changeset
91 @Override
9646
183d33c76419 Removed ValueNode.dependencies
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 9376
diff changeset
92 public GuardingNode createNullCheckGuard(GuardedNode guardedNode, ValueNode object) {
11265
ef6915cf1e59 Add illegal stamp
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 10710
diff changeset
93 if (ObjectStamp.isObjectNonNull(object)) {
9376
ee75b4f569ed Don't create null check guard if object is kown to be non-null.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9267
diff changeset
94 // Short cut creation of null check guard if the object is known to be non-null.
ee75b4f569ed Don't create null check guard if object is kown to be non-null.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9267
diff changeset
95 return null;
ee75b4f569ed Don't create null check guard if object is kown to be non-null.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9267
diff changeset
96 }
12655
2c4aa758ee18 made ConstantNodes external to a Graph (GRAAL-508)
Doug Simon <doug.simon@oracle.com>
parents: 12362
diff changeset
97 StructuredGraph graph = guardedNode.asNode().graph();
11732
03c781923573 made snippet and substitution graphs lower themselves before being inlined
Doug Simon <doug.simon@oracle.com>
parents: 11705
diff changeset
98 if (graph.getGuardsStage().ordinal() > GuardsStage.FLOATING_GUARDS.ordinal()) {
03c781923573 made snippet and substitution graphs lower themselves before being inlined
Doug Simon <doug.simon@oracle.com>
parents: 11705
diff changeset
99 NullCheckNode nullCheck = graph.add(new NullCheckNode(object));
03c781923573 made snippet and substitution graphs lower themselves before being inlined
Doug Simon <doug.simon@oracle.com>
parents: 11705
diff changeset
100 graph.addBeforeFixed((FixedNode) guardedNode, nullCheck);
03c781923573 made snippet and substitution graphs lower themselves before being inlined
Doug Simon <doug.simon@oracle.com>
parents: 11705
diff changeset
101 return nullCheck;
03c781923573 made snippet and substitution graphs lower themselves before being inlined
Doug Simon <doug.simon@oracle.com>
parents: 11705
diff changeset
102 } else {
03c781923573 made snippet and substitution graphs lower themselves before being inlined
Doug Simon <doug.simon@oracle.com>
parents: 11705
diff changeset
103 GuardingNode guard = createGuard(graph.unique(new IsNullNode(object)), DeoptimizationReason.NullCheckException, DeoptimizationAction.InvalidateReprofile, true);
03c781923573 made snippet and substitution graphs lower themselves before being inlined
Doug Simon <doug.simon@oracle.com>
parents: 11705
diff changeset
104 assert guardedNode.getGuard() == null;
03c781923573 made snippet and substitution graphs lower themselves before being inlined
Doug Simon <doug.simon@oracle.com>
parents: 11705
diff changeset
105 guardedNode.setGuard(guard);
03c781923573 made snippet and substitution graphs lower themselves before being inlined
Doug Simon <doug.simon@oracle.com>
parents: 11705
diff changeset
106 return guard;
03c781923573 made snippet and substitution graphs lower themselves before being inlined
Doug Simon <doug.simon@oracle.com>
parents: 11705
diff changeset
107 }
5425
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5397
diff changeset
108 }
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5397
diff changeset
109
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5397
diff changeset
110 @Override
9646
183d33c76419 Removed ValueNode.dependencies
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 9376
diff changeset
111 public GuardingNode createGuard(LogicNode condition, DeoptimizationReason deoptReason, DeoptimizationAction action) {
7660
0b646334c5f7 keep track of leafGraphIds only at the StructuredGraph level (see GRAAL-60)
Lukas Stadler <lukas.stadler@jku.at>
parents: 7539
diff changeset
112 return createGuard(condition, deoptReason, action, false);
5425
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5397
diff changeset
113 }
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5397
diff changeset
114
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5397
diff changeset
115 @Override
5547
b6617d13ea44 Dropping Ci* prefixes. Some additional renamings in the api.code interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5541
diff changeset
116 public Assumptions assumptions() {
9267
950a385e059b Make LoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 9266
diff changeset
117 return context.getAssumptions();
5425
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5397
diff changeset
118 }
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 6285
diff changeset
119
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 6285
diff changeset
120 @Override
9646
183d33c76419 Removed ValueNode.dependencies
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 9376
diff changeset
121 public GuardingNode createGuard(LogicNode condition, DeoptimizationReason deoptReason, DeoptimizationAction action, boolean negated) {
11705
23d91654c363 completed renaming GuardsPhase to GuardsStage
Doug Simon <doug.simon@oracle.com>
parents: 11626
diff changeset
122 if (condition.graph().getGuardsStage().ordinal() > StructuredGraph.GuardsStage.FLOATING_GUARDS.ordinal()) {
11579
ae619d70bf4b Rename LoweringType to GuardsPhase and make it an attribute of StructuredGraphs
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11500
diff changeset
123 throw new GraalInternalError("Cannot create guards after guard lowering");
9251
435bb9425124 added enum to Lowerable interface (before/after guard lowering)
Lukas Stadler <lukas.stadler@jku.at>
parents: 9049
diff changeset
124 }
9864
063a712fe8d8 converted remaining options in GraalOptions to new system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 9646
diff changeset
125 if (OptEliminateGuards.getValue()) {
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 6285
diff changeset
126 for (Node usage : condition.usages()) {
8298
1774e72a60b3 Guards with different anchors should be commoned out in the lowering phase
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 8273
diff changeset
127 if (!activeGuards.isNew(usage) && activeGuards.isMarked(usage) && ((GuardNode) usage).negated() == negated) {
8273
53683dc2815e Fix and enable deopt to guard conversion.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 8178
diff changeset
128 return (GuardNode) usage;
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 6285
diff changeset
129 }
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 6285
diff changeset
130 }
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 6285
diff changeset
131 }
9646
183d33c76419 Removed ValueNode.dependencies
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 9376
diff changeset
132 GuardNode newGuard = guardAnchor.asNode().graph().unique(new GuardNode(condition, guardAnchor, deoptReason, action, negated));
9864
063a712fe8d8 converted remaining options in GraalOptions to new system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 9646
diff changeset
133 if (OptEliminateGuards.getValue()) {
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 6285
diff changeset
134 activeGuards.grow();
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 6285
diff changeset
135 activeGuards.mark(newGuard);
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 6285
diff changeset
136 }
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 6285
diff changeset
137 return newGuard;
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 6285
diff changeset
138 }
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 6285
diff changeset
139
6653
2d5407ae1ac4 intermediate materialization is now removed during lowering of an InstanceOfNode that has a single usage which is an IfNode in the same block
Doug Simon <doug.simon@oracle.com>
parents: 6529
diff changeset
140 @Override
2d5407ae1ac4 intermediate materialization is now removed during lowering of an InstanceOfNode that has a single usage which is an IfNode in the same block
Doug Simon <doug.simon@oracle.com>
parents: 6529
diff changeset
141 public Block getBlockFor(Node node) {
2d5407ae1ac4 intermediate materialization is now removed during lowering of an InstanceOfNode that has a single usage which is an IfNode in the same block
Doug Simon <doug.simon@oracle.com>
parents: 6529
diff changeset
142 return cfg.blockFor(node);
2d5407ae1ac4 intermediate materialization is now removed during lowering of an InstanceOfNode that has a single usage which is an IfNode in the same block
Doug Simon <doug.simon@oracle.com>
parents: 6529
diff changeset
143 }
2d5407ae1ac4 intermediate materialization is now removed during lowering of an InstanceOfNode that has a single usage which is an IfNode in the same block
Doug Simon <doug.simon@oracle.com>
parents: 6529
diff changeset
144
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 6285
diff changeset
145 public FixedWithNextNode lastFixedNode() {
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 6285
diff changeset
146 return lastFixedNode;
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 6285
diff changeset
147 }
8178
67ee3325c285 added support for node lowering to set the fixed node for the next node to be lowered
Doug Simon <doug.simon@oracle.com>
parents: 7827
diff changeset
148
10422
a47dd157277e Simplified lowering phase. Removed "deferred" lowering. Removed custom setLastFixedNode method.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10029
diff changeset
149 private void setLastFixedNode(FixedWithNextNode n) {
11461
2da44804f720 LoweringPhase: move detection of first lastFixedNode out of the loop, add comment
Bernhard Urban <bernhard.urban@jku.at>
parents: 11449
diff changeset
150 assert n.isAlive() : n;
8178
67ee3325c285 added support for node lowering to set the fixed node for the next node to be lowered
Doug Simon <doug.simon@oracle.com>
parents: 7827
diff changeset
151 lastFixedNode = n;
67ee3325c285 added support for node lowering to set the fixed node for the next node to be lowered
Doug Simon <doug.simon@oracle.com>
parents: 7827
diff changeset
152 }
5425
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5397
diff changeset
153 }
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5397
diff changeset
154
11566
aa9ce8d56771 New methods for incremental canonicalization.
Roland Schatz <roland.schatz@oracle.com>
parents: 11500
diff changeset
155 private final CanonicalizerPhase canonicalizer;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
156
11584
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11576 11579
diff changeset
157 public LoweringPhase(CanonicalizerPhase canonicalizer) {
11566
aa9ce8d56771 New methods for incremental canonicalization.
Roland Schatz <roland.schatz@oracle.com>
parents: 11500
diff changeset
158 this.canonicalizer = canonicalizer;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
159 }
5425
0364a2a874b8 changes towards a canonical representation of comparisons:
Lukas Stadler <lukas.stadler@jku.at>
parents: 5397
diff changeset
160
11798
2fbb9fd55dde made lowering recursive instead of iterative
Doug Simon <doug.simon@oracle.com>
parents: 11732
diff changeset
161 /**
2fbb9fd55dde made lowering recursive instead of iterative
Doug Simon <doug.simon@oracle.com>
parents: 11732
diff changeset
162 * Checks that second lowering of a given graph did not introduce any new nodes.
2fbb9fd55dde made lowering recursive instead of iterative
Doug Simon <doug.simon@oracle.com>
parents: 11732
diff changeset
163 *
2fbb9fd55dde made lowering recursive instead of iterative
Doug Simon <doug.simon@oracle.com>
parents: 11732
diff changeset
164 * @param graph a graph that was just {@linkplain #lower lowered}
2fbb9fd55dde made lowering recursive instead of iterative
Doug Simon <doug.simon@oracle.com>
parents: 11732
diff changeset
165 * @throws AssertionError if the check fails
2fbb9fd55dde made lowering recursive instead of iterative
Doug Simon <doug.simon@oracle.com>
parents: 11732
diff changeset
166 */
2fbb9fd55dde made lowering recursive instead of iterative
Doug Simon <doug.simon@oracle.com>
parents: 11732
diff changeset
167 private boolean checkPostLowering(StructuredGraph graph, PhaseContext context) {
12686
ca8ab182026f abstracted a graph mark as a Mark object (hiding the node index)
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
168 Mark expectedMark = graph.getMark();
11798
2fbb9fd55dde made lowering recursive instead of iterative
Doug Simon <doug.simon@oracle.com>
parents: 11732
diff changeset
169 lower(graph, context, 1);
12686
ca8ab182026f abstracted a graph mark as a Mark object (hiding the node index)
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
170 Mark mark = graph.getMark();
13126
c07055d2c66e Fix assertion error message
Christian Wimmer <christian.wimmer@oracle.com>
parents: 12703
diff changeset
171 assert mark.equals(expectedMark) : graph + ": a second round in the current lowering phase introduced these new nodes: " + graph.getNewNodes(expectedMark).snapshot();
11798
2fbb9fd55dde made lowering recursive instead of iterative
Doug Simon <doug.simon@oracle.com>
parents: 11732
diff changeset
172 return true;
6285
471b9eb7419d made LoweringPhase use a schedule so that floating and fixed nodes are lowered iteratively together
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
173 }
471b9eb7419d made LoweringPhase use a schedule so that floating and fixed nodes are lowered iteratively together
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
174
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
175 @Override
9267
950a385e059b Make LoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 9266
diff changeset
176 protected void run(final StructuredGraph graph, PhaseContext context) {
11798
2fbb9fd55dde made lowering recursive instead of iterative
Doug Simon <doug.simon@oracle.com>
parents: 11732
diff changeset
177 lower(graph, context, 0);
2fbb9fd55dde made lowering recursive instead of iterative
Doug Simon <doug.simon@oracle.com>
parents: 11732
diff changeset
178 assert checkPostLowering(graph, context);
2fbb9fd55dde made lowering recursive instead of iterative
Doug Simon <doug.simon@oracle.com>
parents: 11732
diff changeset
179 }
2fbb9fd55dde made lowering recursive instead of iterative
Doug Simon <doug.simon@oracle.com>
parents: 11732
diff changeset
180
2fbb9fd55dde made lowering recursive instead of iterative
Doug Simon <doug.simon@oracle.com>
parents: 11732
diff changeset
181 private void lower(StructuredGraph graph, PhaseContext context, int i) {
2fbb9fd55dde made lowering recursive instead of iterative
Doug Simon <doug.simon@oracle.com>
parents: 11732
diff changeset
182 IncrementalCanonicalizerPhase<PhaseContext> incrementalCanonicalizer = new IncrementalCanonicalizerPhase<>(canonicalizer);
2fbb9fd55dde made lowering recursive instead of iterative
Doug Simon <doug.simon@oracle.com>
parents: 11732
diff changeset
183 incrementalCanonicalizer.appendPhase(new Round(i, context));
2fbb9fd55dde made lowering recursive instead of iterative
Doug Simon <doug.simon@oracle.com>
parents: 11732
diff changeset
184 incrementalCanonicalizer.apply(graph, context);
2fbb9fd55dde made lowering recursive instead of iterative
Doug Simon <doug.simon@oracle.com>
parents: 11732
diff changeset
185 assert graph.verify();
2fbb9fd55dde made lowering recursive instead of iterative
Doug Simon <doug.simon@oracle.com>
parents: 11732
diff changeset
186 }
6285
471b9eb7419d made LoweringPhase use a schedule so that floating and fixed nodes are lowered iteratively together
Doug Simon <doug.simon@oracle.com>
parents: 5720
diff changeset
187
11798
2fbb9fd55dde made lowering recursive instead of iterative
Doug Simon <doug.simon@oracle.com>
parents: 11732
diff changeset
188 /**
2fbb9fd55dde made lowering recursive instead of iterative
Doug Simon <doug.simon@oracle.com>
parents: 11732
diff changeset
189 * Checks that lowering of a given node did not introduce any new {@link Lowerable} nodes that
2fbb9fd55dde made lowering recursive instead of iterative
Doug Simon <doug.simon@oracle.com>
parents: 11732
diff changeset
190 * could be lowered in the current {@link LoweringPhase}. Such nodes must be recursively lowered
2fbb9fd55dde made lowering recursive instead of iterative
Doug Simon <doug.simon@oracle.com>
parents: 11732
diff changeset
191 * as part of lowering {@code node}.
2fbb9fd55dde made lowering recursive instead of iterative
Doug Simon <doug.simon@oracle.com>
parents: 11732
diff changeset
192 *
2fbb9fd55dde made lowering recursive instead of iterative
Doug Simon <doug.simon@oracle.com>
parents: 11732
diff changeset
193 * @param node a node that was just lowered
2fbb9fd55dde made lowering recursive instead of iterative
Doug Simon <doug.simon@oracle.com>
parents: 11732
diff changeset
194 * @param preLoweringMark the graph mark before {@code node} was lowered
13246
0909754d87f4 tightened assertion about lowering a floating node with unscheduled usages to cases where it really matters
Doug Simon <doug.simon@oracle.com>
parents: 13137
diff changeset
195 * @param unscheduledUsages set of {@code node}'s usages that were unscheduled before it was
0909754d87f4 tightened assertion about lowering a floating node with unscheduled usages to cases where it really matters
Doug Simon <doug.simon@oracle.com>
parents: 13137
diff changeset
196 * lowered
11798
2fbb9fd55dde made lowering recursive instead of iterative
Doug Simon <doug.simon@oracle.com>
parents: 11732
diff changeset
197 * @throws AssertionError if the check fails
2fbb9fd55dde made lowering recursive instead of iterative
Doug Simon <doug.simon@oracle.com>
parents: 11732
diff changeset
198 */
13246
0909754d87f4 tightened assertion about lowering a floating node with unscheduled usages to cases where it really matters
Doug Simon <doug.simon@oracle.com>
parents: 13137
diff changeset
199 private static boolean checkPostNodeLowering(Node node, LoweringToolImpl loweringTool, Mark preLoweringMark, Collection<Node> unscheduledUsages) {
11798
2fbb9fd55dde made lowering recursive instead of iterative
Doug Simon <doug.simon@oracle.com>
parents: 11732
diff changeset
200 StructuredGraph graph = (StructuredGraph) node.graph();
12686
ca8ab182026f abstracted a graph mark as a Mark object (hiding the node index)
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
201 Mark postLoweringMark = graph.getMark();
11798
2fbb9fd55dde made lowering recursive instead of iterative
Doug Simon <doug.simon@oracle.com>
parents: 11732
diff changeset
202 NodeIterable<Node> newNodesAfterLowering = graph.getNewNodes(preLoweringMark);
13246
0909754d87f4 tightened assertion about lowering a floating node with unscheduled usages to cases where it really matters
Doug Simon <doug.simon@oracle.com>
parents: 13137
diff changeset
203 if (node instanceof FloatingNode) {
0909754d87f4 tightened assertion about lowering a floating node with unscheduled usages to cases where it really matters
Doug Simon <doug.simon@oracle.com>
parents: 13137
diff changeset
204 if (!unscheduledUsages.isEmpty()) {
0909754d87f4 tightened assertion about lowering a floating node with unscheduled usages to cases where it really matters
Doug Simon <doug.simon@oracle.com>
parents: 13137
diff changeset
205 for (Node n : newNodesAfterLowering) {
0909754d87f4 tightened assertion about lowering a floating node with unscheduled usages to cases where it really matters
Doug Simon <doug.simon@oracle.com>
parents: 13137
diff changeset
206 assert !(n instanceof FixedNode) : node.graph() + ": cannot lower floatable node " + node + " as it introduces fixed node(s) but has the following unscheduled usages: " +
0909754d87f4 tightened assertion about lowering a floating node with unscheduled usages to cases where it really matters
Doug Simon <doug.simon@oracle.com>
parents: 13137
diff changeset
207 unscheduledUsages;
0909754d87f4 tightened assertion about lowering a floating node with unscheduled usages to cases where it really matters
Doug Simon <doug.simon@oracle.com>
parents: 13137
diff changeset
208 }
0909754d87f4 tightened assertion about lowering a floating node with unscheduled usages to cases where it really matters
Doug Simon <doug.simon@oracle.com>
parents: 13137
diff changeset
209 }
0909754d87f4 tightened assertion about lowering a floating node with unscheduled usages to cases where it really matters
Doug Simon <doug.simon@oracle.com>
parents: 13137
diff changeset
210 }
11798
2fbb9fd55dde made lowering recursive instead of iterative
Doug Simon <doug.simon@oracle.com>
parents: 11732
diff changeset
211 for (Node n : newNodesAfterLowering) {
2fbb9fd55dde made lowering recursive instead of iterative
Doug Simon <doug.simon@oracle.com>
parents: 11732
diff changeset
212 if (n instanceof Lowerable) {
2fbb9fd55dde made lowering recursive instead of iterative
Doug Simon <doug.simon@oracle.com>
parents: 11732
diff changeset
213 ((Lowerable) n).lower(loweringTool);
12686
ca8ab182026f abstracted a graph mark as a Mark object (hiding the node index)
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
214 Mark mark = graph.getMark();
ca8ab182026f abstracted a graph mark as a Mark object (hiding the node index)
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
215 assert postLoweringMark.equals(mark) : graph + ": lowering of " + node + " produced lowerable " + n + " that should have been recursively lowered as it introduces these new nodes: " +
11798
2fbb9fd55dde made lowering recursive instead of iterative
Doug Simon <doug.simon@oracle.com>
parents: 11732
diff changeset
216 graph.getNewNodes(postLoweringMark).snapshot();
5397
a3d6ea4241e5 made lowering repeat processing of fixed nodes until no new fixed nodes are added before lowering floating nodes
Doug Simon <doug.simon@oracle.com>
parents: 5379
diff changeset
217 }
a3d6ea4241e5 made lowering repeat processing of fixed nodes until no new fixed nodes are added before lowering floating nodes
Doug Simon <doug.simon@oracle.com>
parents: 5379
diff changeset
218 }
11798
2fbb9fd55dde made lowering recursive instead of iterative
Doug Simon <doug.simon@oracle.com>
parents: 11732
diff changeset
219 return true;
5397
a3d6ea4241e5 made lowering repeat processing of fixed nodes until no new fixed nodes are added before lowering floating nodes
Doug Simon <doug.simon@oracle.com>
parents: 5379
diff changeset
220 }
a3d6ea4241e5 made lowering repeat processing of fixed nodes until no new fixed nodes are added before lowering floating nodes
Doug Simon <doug.simon@oracle.com>
parents: 5379
diff changeset
221
9267
950a385e059b Make LoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 9266
diff changeset
222 private final class Round extends Phase {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
223
9267
950a385e059b Make LoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 9266
diff changeset
224 private final PhaseContext context;
950a385e059b Make LoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 9266
diff changeset
225 private final SchedulePhase schedule;
950a385e059b Make LoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 9266
diff changeset
226
10422
a47dd157277e Simplified lowering phase. Removed "deferred" lowering. Removed custom setLastFixedNode method.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10029
diff changeset
227 private Round(int iteration, PhaseContext context) {
11599
d9342daa5078 added timer for each phase; imposed regex pattern check on phase names
Doug Simon <doug.simon@oracle.com>
parents: 11584
diff changeset
228 super("LoweringIteration" + iteration);
9267
950a385e059b Make LoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 9266
diff changeset
229 this.context = context;
950a385e059b Make LoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 9266
diff changeset
230 this.schedule = new SchedulePhase();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
231 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
232
9267
950a385e059b Make LoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 9266
diff changeset
233 @Override
950a385e059b Make LoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 9266
diff changeset
234 public void run(StructuredGraph graph) {
950a385e059b Make LoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 9266
diff changeset
235 schedule.apply(graph, false);
950a385e059b Make LoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 9266
diff changeset
236 processBlock(schedule.getCFG().getStartBlock(), graph.createNodeBitMap(), null);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
237 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
238
9646
183d33c76419 Removed ValueNode.dependencies
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 9376
diff changeset
239 private void processBlock(Block block, NodeBitMap activeGuards, GuardingNode parentAnchor) {
9267
950a385e059b Make LoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 9266
diff changeset
240
9646
183d33c76419 Removed ValueNode.dependencies
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 9376
diff changeset
241 GuardingNode anchor = parentAnchor;
9267
950a385e059b Make LoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 9266
diff changeset
242 if (anchor == null) {
950a385e059b Make LoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 9266
diff changeset
243 anchor = block.getBeginNode();
950a385e059b Make LoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 9266
diff changeset
244 }
12702
44c0e08c4150 Lowering should handle the case where the current guard anchor gets lowered and does not exist anymore
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 12686
diff changeset
245 anchor = process(block, activeGuards, anchor);
9267
950a385e059b Make LoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 9266
diff changeset
246
950a385e059b Make LoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 9266
diff changeset
247 // Process always reached block first.
950a385e059b Make LoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 9266
diff changeset
248 Block alwaysReachedBlock = block.getPostdominator();
950a385e059b Make LoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 9266
diff changeset
249 if (alwaysReachedBlock != null && alwaysReachedBlock.getDominator() == block) {
950a385e059b Make LoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 9266
diff changeset
250 processBlock(alwaysReachedBlock, activeGuards, anchor);
950a385e059b Make LoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 9266
diff changeset
251 }
950a385e059b Make LoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 9266
diff changeset
252
950a385e059b Make LoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 9266
diff changeset
253 // Now go for the other dominators.
950a385e059b Make LoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 9266
diff changeset
254 for (Block dominated : block.getDominated()) {
950a385e059b Make LoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 9266
diff changeset
255 if (dominated != alwaysReachedBlock) {
950a385e059b Make LoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 9266
diff changeset
256 assert dominated.getDominator() == block;
950a385e059b Make LoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 9266
diff changeset
257 processBlock(dominated, activeGuards, null);
950a385e059b Make LoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 9266
diff changeset
258 }
950a385e059b Make LoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 9266
diff changeset
259 }
950a385e059b Make LoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 9266
diff changeset
260
9864
063a712fe8d8 converted remaining options in GraalOptions to new system (GRAAL-27)
Doug Simon <doug.simon@oracle.com>
parents: 9646
diff changeset
261 if (parentAnchor == null && OptEliminateGuards.getValue()) {
9646
183d33c76419 Removed ValueNode.dependencies
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 9376
diff changeset
262 for (GuardNode guard : anchor.asNode().usages().filter(GuardNode.class)) {
11732
03c781923573 made snippet and substitution graphs lower themselves before being inlined
Doug Simon <doug.simon@oracle.com>
parents: 11705
diff changeset
263 if (activeGuards.contains(guard)) {
03c781923573 made snippet and substitution graphs lower themselves before being inlined
Doug Simon <doug.simon@oracle.com>
parents: 11705
diff changeset
264 activeGuards.clear(guard);
03c781923573 made snippet and substitution graphs lower themselves before being inlined
Doug Simon <doug.simon@oracle.com>
parents: 11705
diff changeset
265 }
9267
950a385e059b Make LoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 9266
diff changeset
266 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
267 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
268 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
269
12702
44c0e08c4150 Lowering should handle the case where the current guard anchor gets lowered and does not exist anymore
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 12686
diff changeset
270 private GuardingNode process(final Block b, final NodeBitMap activeGuards, final GuardingNode startAnchor) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
271
12702
44c0e08c4150 Lowering should handle the case where the current guard anchor gets lowered and does not exist anymore
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 12686
diff changeset
272 final LoweringToolImpl loweringTool = new LoweringToolImpl(context, startAnchor, activeGuards, b.getBeginNode(), schedule.getCFG());
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
273
9267
950a385e059b Make LoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 9266
diff changeset
274 // Lower the instructions of this block.
950a385e059b Make LoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 9266
diff changeset
275 List<ScheduledNode> nodes = schedule.nodesFor(b);
950a385e059b Make LoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 9266
diff changeset
276 for (Node node : nodes) {
10422
a47dd157277e Simplified lowering phase. Removed "deferred" lowering. Removed custom setLastFixedNode method.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10029
diff changeset
277
a47dd157277e Simplified lowering phase. Removed "deferred" lowering. Removed custom setLastFixedNode method.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10029
diff changeset
278 if (node.isDeleted()) {
a47dd157277e Simplified lowering phase. Removed "deferred" lowering. Removed custom setLastFixedNode method.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10029
diff changeset
279 // This case can happen when previous lowerings deleted nodes.
a47dd157277e Simplified lowering phase. Removed "deferred" lowering. Removed custom setLastFixedNode method.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10029
diff changeset
280 continue;
9267
950a385e059b Make LoweringPhase reentrant.
Roland Schatz <roland.schatz@oracle.com>
parents: 9266
diff changeset
281 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
282
10422
a47dd157277e Simplified lowering phase. Removed "deferred" lowering. Removed custom setLastFixedNode method.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10029
diff changeset
283 // Cache the next node to be able to reconstruct the previous of the next node
a47dd157277e Simplified lowering phase. Removed "deferred" lowering. Removed custom setLastFixedNode method.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10029
diff changeset
284 // after lowering.
a47dd157277e Simplified lowering phase. Removed "deferred" lowering. Removed custom setLastFixedNode method.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10029
diff changeset
285 FixedNode nextNode = null;
a47dd157277e Simplified lowering phase. Removed "deferred" lowering. Removed custom setLastFixedNode method.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10029
diff changeset
286 if (node instanceof FixedWithNextNode) {
11461
2da44804f720 LoweringPhase: move detection of first lastFixedNode out of the loop, add comment
Bernhard Urban <bernhard.urban@jku.at>
parents: 11449
diff changeset
287 nextNode = ((FixedWithNextNode) node).next();
10422
a47dd157277e Simplified lowering phase. Removed "deferred" lowering. Removed custom setLastFixedNode method.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10029
diff changeset
288 } else {
a47dd157277e Simplified lowering phase. Removed "deferred" lowering. Removed custom setLastFixedNode method.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10029
diff changeset
289 nextNode = loweringTool.lastFixedNode().next();
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 6285
diff changeset
290 }
10422
a47dd157277e Simplified lowering phase. Removed "deferred" lowering. Removed custom setLastFixedNode method.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10029
diff changeset
291
a47dd157277e Simplified lowering phase. Removed "deferred" lowering. Removed custom setLastFixedNode method.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10029
diff changeset
292 if (node instanceof Lowerable) {
13246
0909754d87f4 tightened assertion about lowering a floating node with unscheduled usages to cases where it really matters
Doug Simon <doug.simon@oracle.com>
parents: 13137
diff changeset
293 Collection<Node> unscheduledUsages = null;
0909754d87f4 tightened assertion about lowering a floating node with unscheduled usages to cases where it really matters
Doug Simon <doug.simon@oracle.com>
parents: 13137
diff changeset
294 assert (unscheduledUsages = getUnscheduledUsages(node)) != null;
12686
ca8ab182026f abstracted a graph mark as a Mark object (hiding the node index)
Doug Simon <doug.simon@oracle.com>
parents: 12655
diff changeset
295 Mark preLoweringMark = node.graph().getMark();
11579
ae619d70bf4b Rename LoweringType to GuardsPhase and make it an attribute of StructuredGraphs
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11500
diff changeset
296 ((Lowerable) node).lower(loweringTool);
12702
44c0e08c4150 Lowering should handle the case where the current guard anchor gets lowered and does not exist anymore
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 12686
diff changeset
297 if (node == startAnchor && node.isDeleted()) {
44c0e08c4150 Lowering should handle the case where the current guard anchor gets lowered and does not exist anymore
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 12686
diff changeset
298 loweringTool.guardAnchor = BeginNode.prevBegin(nextNode);
44c0e08c4150 Lowering should handle the case where the current guard anchor gets lowered and does not exist anymore
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 12686
diff changeset
299 }
13246
0909754d87f4 tightened assertion about lowering a floating node with unscheduled usages to cases where it really matters
Doug Simon <doug.simon@oracle.com>
parents: 13137
diff changeset
300 assert checkPostNodeLowering(node, loweringTool, preLoweringMark, unscheduledUsages);
10422
a47dd157277e Simplified lowering phase. Removed "deferred" lowering. Removed custom setLastFixedNode method.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10029
diff changeset
301 }
a47dd157277e Simplified lowering phase. Removed "deferred" lowering. Removed custom setLastFixedNode method.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 10029
diff changeset
302
11412
7a775592258f Fix Lowering when the lowered node modifies its successor's predecessor to be somethign that is not a FixedWithNextNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11362
diff changeset
303 if (!nextNode.isAlive()) {
11798
2fbb9fd55dde made lowering recursive instead of iterative
Doug Simon <doug.simon@oracle.com>
parents: 11732
diff changeset
304 // can happen when the rest of the block is killed by lowering
2fbb9fd55dde made lowering recursive instead of iterative
Doug Simon <doug.simon@oracle.com>
parents: 11732
diff changeset
305 // (e.g. by an unconditional deopt)
11412
7a775592258f Fix Lowering when the lowered node modifies its successor's predecessor to be somethign that is not a FixedWithNextNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11362
diff changeset
306 break;
7a775592258f Fix Lowering when the lowered node modifies its successor's predecessor to be somethign that is not a FixedWithNextNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11362
diff changeset
307 } else {
7a775592258f Fix Lowering when the lowered node modifies its successor's predecessor to be somethign that is not a FixedWithNextNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11362
diff changeset
308 Node nextLastFixed = nextNode.predecessor();
11462
ff122ed4b9fd LoweringPhase: insert begin node to make lowering more robust, if the predecessor is not a FixedWithNextNode anymore
Bernhard Urban <bernhard.urban@jku.at>
parents: 11461
diff changeset
309 if (!(nextLastFixed instanceof FixedWithNextNode)) {
ff122ed4b9fd LoweringPhase: insert begin node to make lowering more robust, if the predecessor is not a FixedWithNextNode anymore
Bernhard Urban <bernhard.urban@jku.at>
parents: 11461
diff changeset
310 // insert begin node, to have a valid last fixed for next lowerable node.
11804
60f6d5939941 LoweringPhase: add comment
Bernhard Urban <bernhard.urban@jku.at>
parents: 11798
diff changeset
311 // This is about lowering a FixedWithNextNode to a control split while this
60f6d5939941 LoweringPhase: add comment
Bernhard Urban <bernhard.urban@jku.at>
parents: 11798
diff changeset
312 // FixedWithNextNode is followed by some kind of BeginNode.
60f6d5939941 LoweringPhase: add comment
Bernhard Urban <bernhard.urban@jku.at>
parents: 11798
diff changeset
313 // For example the when a FixedGuard followed by a loop exit is lowered to a
60f6d5939941 LoweringPhase: add comment
Bernhard Urban <bernhard.urban@jku.at>
parents: 11798
diff changeset
314 // control-split + deopt.
11462
ff122ed4b9fd LoweringPhase: insert begin node to make lowering more robust, if the predecessor is not a FixedWithNextNode anymore
Bernhard Urban <bernhard.urban@jku.at>
parents: 11461
diff changeset
315 BeginNode begin = node.graph().add(new BeginNode());
ff122ed4b9fd LoweringPhase: insert begin node to make lowering more robust, if the predecessor is not a FixedWithNextNode anymore
Bernhard Urban <bernhard.urban@jku.at>
parents: 11461
diff changeset
316 nextLastFixed.replaceFirstSuccessor(nextNode, begin);
ff122ed4b9fd LoweringPhase: insert begin node to make lowering more robust, if the predecessor is not a FixedWithNextNode anymore
Bernhard Urban <bernhard.urban@jku.at>
parents: 11461
diff changeset
317 begin.setNext(nextNode);
ff122ed4b9fd LoweringPhase: insert begin node to make lowering more robust, if the predecessor is not a FixedWithNextNode anymore
Bernhard Urban <bernhard.urban@jku.at>
parents: 11461
diff changeset
318 nextLastFixed = begin;
11412
7a775592258f Fix Lowering when the lowered node modifies its successor's predecessor to be somethign that is not a FixedWithNextNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11362
diff changeset
319 }
11462
ff122ed4b9fd LoweringPhase: insert begin node to make lowering more robust, if the predecessor is not a FixedWithNextNode anymore
Bernhard Urban <bernhard.urban@jku.at>
parents: 11461
diff changeset
320 loweringTool.setLastFixedNode((FixedWithNextNode) nextLastFixed);
11412
7a775592258f Fix Lowering when the lowered node modifies its successor's predecessor to be somethign that is not a FixedWithNextNode
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 11362
diff changeset
321 }
6302
5d7d9a6953bd added InstanceOfSnippets which passes InstanceOfTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents: 6285
diff changeset
322 }
12702
44c0e08c4150 Lowering should handle the case where the current guard anchor gets lowered and does not exist anymore
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 12686
diff changeset
323 return loweringTool.getCurrentGuardAnchor();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
324 }
10693
f8adf47cc05e checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents: 10660
diff changeset
325
f8adf47cc05e checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents: 10660
diff changeset
326 /**
13246
0909754d87f4 tightened assertion about lowering a floating node with unscheduled usages to cases where it really matters
Doug Simon <doug.simon@oracle.com>
parents: 13137
diff changeset
327 * Gets all usages of a floating, lowerable node that are unscheduled.
10693
f8adf47cc05e checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents: 10660
diff changeset
328 * <p>
f8adf47cc05e checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents: 10660
diff changeset
329 * Given that the lowering of such nodes may introduce fixed nodes, they must be lowered in
f8adf47cc05e checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents: 10660
diff changeset
330 * the context of a usage that dominates all other usages. The fixed nodes resulting from
f8adf47cc05e checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents: 10660
diff changeset
331 * lowering are attached to the fixed node context of the dominating usage. This ensures the
f8adf47cc05e checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents: 10660
diff changeset
332 * post-lowering graph still has a valid schedule.
f8adf47cc05e checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents: 10660
diff changeset
333 *
f8adf47cc05e checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents: 10660
diff changeset
334 * @param node a {@link Lowerable} node
f8adf47cc05e checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents: 10660
diff changeset
335 */
13246
0909754d87f4 tightened assertion about lowering a floating node with unscheduled usages to cases where it really matters
Doug Simon <doug.simon@oracle.com>
parents: 13137
diff changeset
336 private Collection<Node> getUnscheduledUsages(Node node) {
0909754d87f4 tightened assertion about lowering a floating node with unscheduled usages to cases where it really matters
Doug Simon <doug.simon@oracle.com>
parents: 13137
diff changeset
337 List<Node> unscheduledUsages = new ArrayList<>();
10693
f8adf47cc05e checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents: 10660
diff changeset
338 if (node instanceof FloatingNode) {
f8adf47cc05e checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents: 10660
diff changeset
339 for (Node usage : node.usages()) {
f8adf47cc05e checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents: 10660
diff changeset
340 if (usage instanceof ScheduledNode) {
f8adf47cc05e checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents: 10660
diff changeset
341 Block usageBlock = schedule.getCFG().blockFor(usage);
13246
0909754d87f4 tightened assertion about lowering a floating node with unscheduled usages to cases where it really matters
Doug Simon <doug.simon@oracle.com>
parents: 13137
diff changeset
342 if (usageBlock == null) {
0909754d87f4 tightened assertion about lowering a floating node with unscheduled usages to cases where it really matters
Doug Simon <doug.simon@oracle.com>
parents: 13137
diff changeset
343 unscheduledUsages.add(usage);
0909754d87f4 tightened assertion about lowering a floating node with unscheduled usages to cases where it really matters
Doug Simon <doug.simon@oracle.com>
parents: 13137
diff changeset
344 }
10693
f8adf47cc05e checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents: 10660
diff changeset
345 }
f8adf47cc05e checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents: 10660
diff changeset
346 }
f8adf47cc05e checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents: 10660
diff changeset
347 }
13246
0909754d87f4 tightened assertion about lowering a floating node with unscheduled usages to cases where it really matters
Doug Simon <doug.simon@oracle.com>
parents: 13137
diff changeset
348 return unscheduledUsages;
10693
f8adf47cc05e checkcast is lowered to instanceof (GRAAL-248)
Doug Simon <doug.simon@oracle.com>
parents: 10660
diff changeset
349 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
350 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
351 }