annotate src/share/vm/opto/gcm.cpp @ 14412:e2722a66aba7

Merge
author kvn
date Thu, 05 Sep 2013 11:04:39 -0700
parents d2907f74462e adb9a7d94cb5
children 2b8e28fdf503
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
6842
b9a9ed0f8eeb 7197424: update copyright year to match last edit in jdk8 hotspot repository
mikael
parents: 4820
diff changeset
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 833
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 833
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 833
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1685
diff changeset
25 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1685
diff changeset
26 #include "libadt/vectset.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1685
diff changeset
27 #include "memory/allocation.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1685
diff changeset
28 #include "opto/block.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1685
diff changeset
29 #include "opto/c2compiler.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1685
diff changeset
30 #include "opto/callnode.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1685
diff changeset
31 #include "opto/cfgnode.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1685
diff changeset
32 #include "opto/machnode.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1685
diff changeset
33 #include "opto/opcodes.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1685
diff changeset
34 #include "opto/phaseX.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1685
diff changeset
35 #include "opto/rootnode.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1685
diff changeset
36 #include "opto/runtime.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1685
diff changeset
37 #include "runtime/deoptimization.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1685
diff changeset
38 #ifdef TARGET_ARCH_MODEL_x86_32
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1685
diff changeset
39 # include "adfiles/ad_x86_32.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1685
diff changeset
40 #endif
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1685
diff changeset
41 #ifdef TARGET_ARCH_MODEL_x86_64
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1685
diff changeset
42 # include "adfiles/ad_x86_64.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1685
diff changeset
43 #endif
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1685
diff changeset
44 #ifdef TARGET_ARCH_MODEL_sparc
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1685
diff changeset
45 # include "adfiles/ad_sparc.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1685
diff changeset
46 #endif
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1685
diff changeset
47 #ifdef TARGET_ARCH_MODEL_zero
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1685
diff changeset
48 # include "adfiles/ad_zero.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1685
diff changeset
49 #endif
2192
b92c45f2bc75 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 2008
diff changeset
50 #ifdef TARGET_ARCH_MODEL_arm
b92c45f2bc75 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 2008
diff changeset
51 # include "adfiles/ad_arm.hpp"
b92c45f2bc75 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 2008
diff changeset
52 #endif
14391
d2907f74462e 8016586: PPC64 (part 3): basic changes for PPC64
goetz
parents: 8691
diff changeset
53 #ifdef TARGET_ARCH_MODEL_ppc_32
d2907f74462e 8016586: PPC64 (part 3): basic changes for PPC64
goetz
parents: 8691
diff changeset
54 # include "adfiles/ad_ppc_32.hpp"
2192
b92c45f2bc75 7016023: Enable building ARM and PPC from src/closed repository
bobv
parents: 2008
diff changeset
55 #endif
14391
d2907f74462e 8016586: PPC64 (part 3): basic changes for PPC64
goetz
parents: 8691
diff changeset
56 #ifdef TARGET_ARCH_MODEL_ppc_64
d2907f74462e 8016586: PPC64 (part 3): basic changes for PPC64
goetz
parents: 8691
diff changeset
57 # include "adfiles/ad_ppc_64.hpp"
d2907f74462e 8016586: PPC64 (part 3): basic changes for PPC64
goetz
parents: 8691
diff changeset
58 #endif
d2907f74462e 8016586: PPC64 (part 3): basic changes for PPC64
goetz
parents: 8691
diff changeset
59
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1685
diff changeset
60
0
a61af66fc99e Initial load
duke
parents:
diff changeset
61 // Portions of code courtesy of Clifford Click
a61af66fc99e Initial load
duke
parents:
diff changeset
62
a61af66fc99e Initial load
duke
parents:
diff changeset
63 // Optimization - Graph Style
a61af66fc99e Initial load
duke
parents:
diff changeset
64
552
011517bbcd7b 6784930: server jvm fails with assert(!n->is_SpillCopy(),"")
kvn
parents: 418
diff changeset
65 // To avoid float value underflow
011517bbcd7b 6784930: server jvm fails with assert(!n->is_SpillCopy(),"")
kvn
parents: 418
diff changeset
66 #define MIN_BLOCK_FREQUENCY 1.e-35f
011517bbcd7b 6784930: server jvm fails with assert(!n->is_SpillCopy(),"")
kvn
parents: 418
diff changeset
67
0
a61af66fc99e Initial load
duke
parents:
diff changeset
68 //----------------------------schedule_node_into_block-------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
69 // Insert node n into block b. Look for projections of n and make sure they
a61af66fc99e Initial load
duke
parents:
diff changeset
70 // are in b also.
a61af66fc99e Initial load
duke
parents:
diff changeset
71 void PhaseCFG::schedule_node_into_block( Node *n, Block *b ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
72 // Set basic block of n, Add n to b,
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
73 map_node_to_block(n, b);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
74 b->add_inst(n);
a61af66fc99e Initial load
duke
parents:
diff changeset
75
a61af66fc99e Initial load
duke
parents:
diff changeset
76 // After Matching, nearly any old Node may have projections trailing it.
a61af66fc99e Initial load
duke
parents:
diff changeset
77 // These are usually machine-dependent flags. In any case, they might
a61af66fc99e Initial load
duke
parents:
diff changeset
78 // float to another block below this one. Move them up.
a61af66fc99e Initial load
duke
parents:
diff changeset
79 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
80 Node* use = n->fast_out(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
81 if (use->is_Proj()) {
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
82 Block* buse = get_block_for_node(use);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
83 if (buse != b) { // In wrong block?
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
84 if (buse != NULL) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
85 buse->find_remove(use); // Remove from wrong block
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
86 }
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
87 map_node_to_block(use, b);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
88 b->add_inst(use);
a61af66fc99e Initial load
duke
parents:
diff changeset
89 }
a61af66fc99e Initial load
duke
parents:
diff changeset
90 }
a61af66fc99e Initial load
duke
parents:
diff changeset
91 }
a61af66fc99e Initial load
duke
parents:
diff changeset
92 }
a61af66fc99e Initial load
duke
parents:
diff changeset
93
601
523ded093c31 6809798: SafePointScalarObject node placed into incorrect block during GCM
kvn
parents: 552
diff changeset
94 //----------------------------replace_block_proj_ctrl-------------------------
523ded093c31 6809798: SafePointScalarObject node placed into incorrect block during GCM
kvn
parents: 552
diff changeset
95 // Nodes that have is_block_proj() nodes as their control need to use
523ded093c31 6809798: SafePointScalarObject node placed into incorrect block during GCM
kvn
parents: 552
diff changeset
96 // the appropriate Region for their actual block as their control since
523ded093c31 6809798: SafePointScalarObject node placed into incorrect block during GCM
kvn
parents: 552
diff changeset
97 // the projection will be in a predecessor block.
523ded093c31 6809798: SafePointScalarObject node placed into incorrect block during GCM
kvn
parents: 552
diff changeset
98 void PhaseCFG::replace_block_proj_ctrl( Node *n ) {
523ded093c31 6809798: SafePointScalarObject node placed into incorrect block during GCM
kvn
parents: 552
diff changeset
99 const Node *in0 = n->in(0);
523ded093c31 6809798: SafePointScalarObject node placed into incorrect block during GCM
kvn
parents: 552
diff changeset
100 assert(in0 != NULL, "Only control-dependent");
523ded093c31 6809798: SafePointScalarObject node placed into incorrect block during GCM
kvn
parents: 552
diff changeset
101 const Node *p = in0->is_block_proj();
523ded093c31 6809798: SafePointScalarObject node placed into incorrect block during GCM
kvn
parents: 552
diff changeset
102 if (p != NULL && p != n) { // Control from a block projection?
4115
1bd45abaa507 6890673: Eliminate allocations immediately after EA
kvn
parents: 3842
diff changeset
103 assert(!n->pinned() || n->is_MachConstantBase(), "only pinned MachConstantBase node is expected here");
601
523ded093c31 6809798: SafePointScalarObject node placed into incorrect block during GCM
kvn
parents: 552
diff changeset
104 // Find trailing Region
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
105 Block *pb = get_block_for_node(in0); // Block-projection already has basic block
601
523ded093c31 6809798: SafePointScalarObject node placed into incorrect block during GCM
kvn
parents: 552
diff changeset
106 uint j = 0;
523ded093c31 6809798: SafePointScalarObject node placed into incorrect block during GCM
kvn
parents: 552
diff changeset
107 if (pb->_num_succs != 1) { // More then 1 successor?
523ded093c31 6809798: SafePointScalarObject node placed into incorrect block during GCM
kvn
parents: 552
diff changeset
108 // Search for successor
523ded093c31 6809798: SafePointScalarObject node placed into incorrect block during GCM
kvn
parents: 552
diff changeset
109 uint max = pb->_nodes.size();
523ded093c31 6809798: SafePointScalarObject node placed into incorrect block during GCM
kvn
parents: 552
diff changeset
110 assert( max > 1, "" );
523ded093c31 6809798: SafePointScalarObject node placed into incorrect block during GCM
kvn
parents: 552
diff changeset
111 uint start = max - pb->_num_succs;
523ded093c31 6809798: SafePointScalarObject node placed into incorrect block during GCM
kvn
parents: 552
diff changeset
112 // Find which output path belongs to projection
523ded093c31 6809798: SafePointScalarObject node placed into incorrect block during GCM
kvn
parents: 552
diff changeset
113 for (j = start; j < max; j++) {
523ded093c31 6809798: SafePointScalarObject node placed into incorrect block during GCM
kvn
parents: 552
diff changeset
114 if( pb->_nodes[j] == in0 )
523ded093c31 6809798: SafePointScalarObject node placed into incorrect block during GCM
kvn
parents: 552
diff changeset
115 break;
523ded093c31 6809798: SafePointScalarObject node placed into incorrect block during GCM
kvn
parents: 552
diff changeset
116 }
523ded093c31 6809798: SafePointScalarObject node placed into incorrect block during GCM
kvn
parents: 552
diff changeset
117 assert( j < max, "must find" );
523ded093c31 6809798: SafePointScalarObject node placed into incorrect block during GCM
kvn
parents: 552
diff changeset
118 // Change control to match head of successor basic block
523ded093c31 6809798: SafePointScalarObject node placed into incorrect block during GCM
kvn
parents: 552
diff changeset
119 j -= start;
523ded093c31 6809798: SafePointScalarObject node placed into incorrect block during GCM
kvn
parents: 552
diff changeset
120 }
523ded093c31 6809798: SafePointScalarObject node placed into incorrect block during GCM
kvn
parents: 552
diff changeset
121 n->set_req(0, pb->_succs[j]->head());
523ded093c31 6809798: SafePointScalarObject node placed into incorrect block during GCM
kvn
parents: 552
diff changeset
122 }
523ded093c31 6809798: SafePointScalarObject node placed into incorrect block during GCM
kvn
parents: 552
diff changeset
123 }
523ded093c31 6809798: SafePointScalarObject node placed into incorrect block during GCM
kvn
parents: 552
diff changeset
124
0
a61af66fc99e Initial load
duke
parents:
diff changeset
125
a61af66fc99e Initial load
duke
parents:
diff changeset
126 //------------------------------schedule_pinned_nodes--------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
127 // Set the basic block for Nodes pinned into blocks
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
128 void PhaseCFG::schedule_pinned_nodes(VectorSet &visited) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
129 // Allocate node stack of size C->unique()+8 to avoid frequent realloc
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
130 GrowableArray <Node *> spstack(C->unique() + 8);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
131 spstack.push(_root);
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
132 while (spstack.is_nonempty()) {
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
133 Node* node = spstack.pop();
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
134 if (!visited.test_set(node->_idx)) { // Test node and flag it as visited
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
135 if (node->pinned() && !has_block(node)) { // Pinned? Nail it down!
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
136 assert(node->in(0), "pinned Node must have Control");
601
523ded093c31 6809798: SafePointScalarObject node placed into incorrect block during GCM
kvn
parents: 552
diff changeset
137 // Before setting block replace block_proj control edge
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
138 replace_block_proj_ctrl(node);
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
139 Node* input = node->in(0);
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
140 while (!input->is_block_start()) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
141 input = input->in(0);
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
142 }
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
143 Block* block = get_block_for_node(input); // Basic block of controlling input
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
144 schedule_node_into_block(node, block);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
145 }
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
146
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
147 // process all inputs that are non NULL
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
148 for (int i = node->req() - 1; i >= 0; --i) {
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
149 if (node->in(i) != NULL) {
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
150 spstack.push(node->in(i));
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
151 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
152 }
a61af66fc99e Initial load
duke
parents:
diff changeset
153 }
a61af66fc99e Initial load
duke
parents:
diff changeset
154 }
a61af66fc99e Initial load
duke
parents:
diff changeset
155 }
a61af66fc99e Initial load
duke
parents:
diff changeset
156
a61af66fc99e Initial load
duke
parents:
diff changeset
157 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
158 // Assert that new input b2 is dominated by all previous inputs.
a61af66fc99e Initial load
duke
parents:
diff changeset
159 // Check this by by seeing that it is dominated by b1, the deepest
a61af66fc99e Initial load
duke
parents:
diff changeset
160 // input observed until b2.
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
161 static void assert_dom(Block* b1, Block* b2, Node* n, const PhaseCFG* cfg) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
162 if (b1 == NULL) return;
a61af66fc99e Initial load
duke
parents:
diff changeset
163 assert(b1->_dom_depth < b2->_dom_depth, "sanity");
a61af66fc99e Initial load
duke
parents:
diff changeset
164 Block* tmp = b2;
a61af66fc99e Initial load
duke
parents:
diff changeset
165 while (tmp != b1 && tmp != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
166 tmp = tmp->_idom;
a61af66fc99e Initial load
duke
parents:
diff changeset
167 }
a61af66fc99e Initial load
duke
parents:
diff changeset
168 if (tmp != b1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
169 // Detected an unschedulable graph. Print some nice stuff and die.
a61af66fc99e Initial load
duke
parents:
diff changeset
170 tty->print_cr("!!! Unschedulable graph !!!");
a61af66fc99e Initial load
duke
parents:
diff changeset
171 for (uint j=0; j<n->len(); j++) { // For all inputs
a61af66fc99e Initial load
duke
parents:
diff changeset
172 Node* inn = n->in(j); // Get input
a61af66fc99e Initial load
duke
parents:
diff changeset
173 if (inn == NULL) continue; // Ignore NULL, missing inputs
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
174 Block* inb = cfg->get_block_for_node(inn);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
175 tty->print("B%d idom=B%d depth=%2d ",inb->_pre_order,
a61af66fc99e Initial load
duke
parents:
diff changeset
176 inb->_idom ? inb->_idom->_pre_order : 0, inb->_dom_depth);
a61af66fc99e Initial load
duke
parents:
diff changeset
177 inn->dump();
a61af66fc99e Initial load
duke
parents:
diff changeset
178 }
a61af66fc99e Initial load
duke
parents:
diff changeset
179 tty->print("Failing node: ");
a61af66fc99e Initial load
duke
parents:
diff changeset
180 n->dump();
a61af66fc99e Initial load
duke
parents:
diff changeset
181 assert(false, "unscheduable graph");
a61af66fc99e Initial load
duke
parents:
diff changeset
182 }
a61af66fc99e Initial load
duke
parents:
diff changeset
183 }
a61af66fc99e Initial load
duke
parents:
diff changeset
184 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
185
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
186 static Block* find_deepest_input(Node* n, const PhaseCFG* cfg) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
187 // Find the last input dominated by all other inputs.
a61af66fc99e Initial load
duke
parents:
diff changeset
188 Block* deepb = NULL; // Deepest block so far
a61af66fc99e Initial load
duke
parents:
diff changeset
189 int deepb_dom_depth = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
190 for (uint k = 0; k < n->len(); k++) { // For all inputs
a61af66fc99e Initial load
duke
parents:
diff changeset
191 Node* inn = n->in(k); // Get input
a61af66fc99e Initial load
duke
parents:
diff changeset
192 if (inn == NULL) continue; // Ignore NULL, missing inputs
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
193 Block* inb = cfg->get_block_for_node(inn);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
194 assert(inb != NULL, "must already have scheduled this input");
a61af66fc99e Initial load
duke
parents:
diff changeset
195 if (deepb_dom_depth < (int) inb->_dom_depth) {
a61af66fc99e Initial load
duke
parents:
diff changeset
196 // The new inb must be dominated by the previous deepb.
a61af66fc99e Initial load
duke
parents:
diff changeset
197 // The various inputs must be linearly ordered in the dom
a61af66fc99e Initial load
duke
parents:
diff changeset
198 // tree, or else there will not be a unique deepest block.
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
199 DEBUG_ONLY(assert_dom(deepb, inb, n, cfg));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
200 deepb = inb; // Save deepest block
a61af66fc99e Initial load
duke
parents:
diff changeset
201 deepb_dom_depth = deepb->_dom_depth;
a61af66fc99e Initial load
duke
parents:
diff changeset
202 }
a61af66fc99e Initial load
duke
parents:
diff changeset
203 }
a61af66fc99e Initial load
duke
parents:
diff changeset
204 assert(deepb != NULL, "must be at least one input to n");
a61af66fc99e Initial load
duke
parents:
diff changeset
205 return deepb;
a61af66fc99e Initial load
duke
parents:
diff changeset
206 }
a61af66fc99e Initial load
duke
parents:
diff changeset
207
a61af66fc99e Initial load
duke
parents:
diff changeset
208
a61af66fc99e Initial load
duke
parents:
diff changeset
209 //------------------------------schedule_early---------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
210 // Find the earliest Block any instruction can be placed in. Some instructions
a61af66fc99e Initial load
duke
parents:
diff changeset
211 // are pinned into Blocks. Unpinned instructions can appear in last block in
a61af66fc99e Initial load
duke
parents:
diff changeset
212 // which all their inputs occur.
a61af66fc99e Initial load
duke
parents:
diff changeset
213 bool PhaseCFG::schedule_early(VectorSet &visited, Node_List &roots) {
a61af66fc99e Initial load
duke
parents:
diff changeset
214 // Allocate stack with enough space to avoid frequent realloc
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
215 Node_Stack nstack(roots.Size() + 8);
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
216 // _root will be processed among C->top() inputs
0
a61af66fc99e Initial load
duke
parents:
diff changeset
217 roots.push(C->top());
a61af66fc99e Initial load
duke
parents:
diff changeset
218 visited.set(C->top()->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
219
a61af66fc99e Initial load
duke
parents:
diff changeset
220 while (roots.size() != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
221 // Use local variables nstack_top_n & nstack_top_i to cache values
a61af66fc99e Initial load
duke
parents:
diff changeset
222 // on stack's top.
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
223 Node* parent_node = roots.pop();
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
224 uint input_index = 0;
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
225
0
a61af66fc99e Initial load
duke
parents:
diff changeset
226 while (true) {
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
227 if (input_index == 0) {
601
523ded093c31 6809798: SafePointScalarObject node placed into incorrect block during GCM
kvn
parents: 552
diff changeset
228 // Fixup some control. Constants without control get attached
523ded093c31 6809798: SafePointScalarObject node placed into incorrect block during GCM
kvn
parents: 552
diff changeset
229 // to root and nodes that use is_block_proj() nodes should be attached
523ded093c31 6809798: SafePointScalarObject node placed into incorrect block during GCM
kvn
parents: 552
diff changeset
230 // to the region that starts their block.
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
231 const Node* control_input = parent_node->in(0);
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
232 if (control_input != NULL) {
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
233 replace_block_proj_ctrl(parent_node);
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
234 } else {
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
235 // Is a constant with NO inputs?
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
236 if (parent_node->req() == 1) {
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
237 parent_node->set_req(0, _root);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
238 }
a61af66fc99e Initial load
duke
parents:
diff changeset
239 }
a61af66fc99e Initial load
duke
parents:
diff changeset
240 }
a61af66fc99e Initial load
duke
parents:
diff changeset
241
a61af66fc99e Initial load
duke
parents:
diff changeset
242 // First, visit all inputs and force them to get a block. If an
a61af66fc99e Initial load
duke
parents:
diff changeset
243 // input is already in a block we quit following inputs (to avoid
a61af66fc99e Initial load
duke
parents:
diff changeset
244 // cycles). Instead we put that Node on a worklist to be handled
a61af66fc99e Initial load
duke
parents:
diff changeset
245 // later (since IT'S inputs may not have a block yet).
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
246
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
247 // Assume all n's inputs will be processed
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
248 bool done = true;
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
249
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
250 while (input_index < parent_node->len()) {
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
251 Node* in = parent_node->in(input_index++);
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
252 if (in == NULL) {
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
253 continue;
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
254 }
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
255
0
a61af66fc99e Initial load
duke
parents:
diff changeset
256 int is_visited = visited.test_set(in->_idx);
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
257 if (!has_block(in)) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
258 if (is_visited) {
a61af66fc99e Initial load
duke
parents:
diff changeset
259 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
260 }
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
261 // Save parent node and next input's index.
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
262 nstack.push(parent_node, input_index);
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
263 // Process current input now.
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
264 parent_node = in;
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
265 input_index = 0;
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
266 // Not all n's inputs processed.
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
267 done = false;
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
268 break;
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
269 } else if (!is_visited) {
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
270 // Visit this guy later, using worklist
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
271 roots.push(in);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
272 }
a61af66fc99e Initial load
duke
parents:
diff changeset
273 }
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
274
0
a61af66fc99e Initial load
duke
parents:
diff changeset
275 if (done) {
a61af66fc99e Initial load
duke
parents:
diff changeset
276 // All of n's inputs have been processed, complete post-processing.
a61af66fc99e Initial load
duke
parents:
diff changeset
277
a61af66fc99e Initial load
duke
parents:
diff changeset
278 // Some instructions are pinned into a block. These include Region,
a61af66fc99e Initial load
duke
parents:
diff changeset
279 // Phi, Start, Return, and other control-dependent instructions and
a61af66fc99e Initial load
duke
parents:
diff changeset
280 // any projections which depend on them.
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
281 if (!parent_node->pinned()) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
282 // Set earliest legal block.
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
283 Block* earliest_block = find_deepest_input(parent_node, this);
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
284 map_node_to_block(parent_node, earliest_block);
601
523ded093c31 6809798: SafePointScalarObject node placed into incorrect block during GCM
kvn
parents: 552
diff changeset
285 } else {
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
286 assert(get_block_for_node(parent_node) == get_block_for_node(parent_node->in(0)), "Pinned Node should be at the same block as its control edge");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
287 }
a61af66fc99e Initial load
duke
parents:
diff changeset
288
a61af66fc99e Initial load
duke
parents:
diff changeset
289 if (nstack.is_empty()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
290 // Finished all nodes on stack.
a61af66fc99e Initial load
duke
parents:
diff changeset
291 // Process next node on the worklist 'roots'.
a61af66fc99e Initial load
duke
parents:
diff changeset
292 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
293 }
a61af66fc99e Initial load
duke
parents:
diff changeset
294 // Get saved parent node and next input's index.
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
295 parent_node = nstack.node();
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
296 input_index = nstack.index();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
297 nstack.pop();
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
298 }
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
299 }
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
300 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
301 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
302 }
a61af66fc99e Initial load
duke
parents:
diff changeset
303
a61af66fc99e Initial load
duke
parents:
diff changeset
304 //------------------------------dom_lca----------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
305 // Find least common ancestor in dominator tree
a61af66fc99e Initial load
duke
parents:
diff changeset
306 // LCA is a current notion of LCA, to be raised above 'this'.
a61af66fc99e Initial load
duke
parents:
diff changeset
307 // As a convenient boundary condition, return 'this' if LCA is NULL.
a61af66fc99e Initial load
duke
parents:
diff changeset
308 // Find the LCA of those two nodes.
a61af66fc99e Initial load
duke
parents:
diff changeset
309 Block* Block::dom_lca(Block* LCA) {
a61af66fc99e Initial load
duke
parents:
diff changeset
310 if (LCA == NULL || LCA == this) return this;
a61af66fc99e Initial load
duke
parents:
diff changeset
311
a61af66fc99e Initial load
duke
parents:
diff changeset
312 Block* anc = this;
a61af66fc99e Initial load
duke
parents:
diff changeset
313 while (anc->_dom_depth > LCA->_dom_depth)
a61af66fc99e Initial load
duke
parents:
diff changeset
314 anc = anc->_idom; // Walk up till anc is as high as LCA
a61af66fc99e Initial load
duke
parents:
diff changeset
315
a61af66fc99e Initial load
duke
parents:
diff changeset
316 while (LCA->_dom_depth > anc->_dom_depth)
a61af66fc99e Initial load
duke
parents:
diff changeset
317 LCA = LCA->_idom; // Walk up till LCA is as high as anc
a61af66fc99e Initial load
duke
parents:
diff changeset
318
a61af66fc99e Initial load
duke
parents:
diff changeset
319 while (LCA != anc) { // Walk both up till they are the same
a61af66fc99e Initial load
duke
parents:
diff changeset
320 LCA = LCA->_idom;
a61af66fc99e Initial load
duke
parents:
diff changeset
321 anc = anc->_idom;
a61af66fc99e Initial load
duke
parents:
diff changeset
322 }
a61af66fc99e Initial load
duke
parents:
diff changeset
323
a61af66fc99e Initial load
duke
parents:
diff changeset
324 return LCA;
a61af66fc99e Initial load
duke
parents:
diff changeset
325 }
a61af66fc99e Initial load
duke
parents:
diff changeset
326
a61af66fc99e Initial load
duke
parents:
diff changeset
327 //--------------------------raise_LCA_above_use--------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
328 // We are placing a definition, and have been given a def->use edge.
a61af66fc99e Initial load
duke
parents:
diff changeset
329 // The definition must dominate the use, so move the LCA upward in the
a61af66fc99e Initial load
duke
parents:
diff changeset
330 // dominator tree to dominate the use. If the use is a phi, adjust
a61af66fc99e Initial load
duke
parents:
diff changeset
331 // the LCA only with the phi input paths which actually use this def.
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
332 static Block* raise_LCA_above_use(Block* LCA, Node* use, Node* def, const PhaseCFG* cfg) {
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
333 Block* buse = cfg->get_block_for_node(use);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
334 if (buse == NULL) return LCA; // Unused killing Projs have no use block
a61af66fc99e Initial load
duke
parents:
diff changeset
335 if (!use->is_Phi()) return buse->dom_lca(LCA);
a61af66fc99e Initial load
duke
parents:
diff changeset
336 uint pmax = use->req(); // Number of Phi inputs
a61af66fc99e Initial load
duke
parents:
diff changeset
337 // Why does not this loop just break after finding the matching input to
a61af66fc99e Initial load
duke
parents:
diff changeset
338 // the Phi? Well...it's like this. I do not have true def-use/use-def
a61af66fc99e Initial load
duke
parents:
diff changeset
339 // chains. Means I cannot distinguish, from the def-use direction, which
a61af66fc99e Initial load
duke
parents:
diff changeset
340 // of many use-defs lead from the same use to the same def. That is, this
a61af66fc99e Initial load
duke
parents:
diff changeset
341 // Phi might have several uses of the same def. Each use appears in a
a61af66fc99e Initial load
duke
parents:
diff changeset
342 // different predecessor block. But when I enter here, I cannot distinguish
a61af66fc99e Initial load
duke
parents:
diff changeset
343 // which use-def edge I should find the predecessor block for. So I find
a61af66fc99e Initial load
duke
parents:
diff changeset
344 // them all. Means I do a little extra work if a Phi uses the same value
a61af66fc99e Initial load
duke
parents:
diff changeset
345 // more than once.
a61af66fc99e Initial load
duke
parents:
diff changeset
346 for (uint j=1; j<pmax; j++) { // For all inputs
a61af66fc99e Initial load
duke
parents:
diff changeset
347 if (use->in(j) == def) { // Found matching input?
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
348 Block* pred = cfg->get_block_for_node(buse->pred(j));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
349 LCA = pred->dom_lca(LCA);
a61af66fc99e Initial load
duke
parents:
diff changeset
350 }
a61af66fc99e Initial load
duke
parents:
diff changeset
351 }
a61af66fc99e Initial load
duke
parents:
diff changeset
352 return LCA;
a61af66fc99e Initial load
duke
parents:
diff changeset
353 }
a61af66fc99e Initial load
duke
parents:
diff changeset
354
a61af66fc99e Initial load
duke
parents:
diff changeset
355 //----------------------------raise_LCA_above_marks----------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
356 // Return a new LCA that dominates LCA and any of its marked predecessors.
a61af66fc99e Initial load
duke
parents:
diff changeset
357 // Search all my parents up to 'early' (exclusive), looking for predecessors
a61af66fc99e Initial load
duke
parents:
diff changeset
358 // which are marked with the given index. Return the LCA (in the dom tree)
a61af66fc99e Initial load
duke
parents:
diff changeset
359 // of all marked blocks. If there are none marked, return the original
a61af66fc99e Initial load
duke
parents:
diff changeset
360 // LCA.
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
361 static Block* raise_LCA_above_marks(Block* LCA, node_idx_t mark, Block* early, const PhaseCFG* cfg) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
362 Block_List worklist;
a61af66fc99e Initial load
duke
parents:
diff changeset
363 worklist.push(LCA);
a61af66fc99e Initial load
duke
parents:
diff changeset
364 while (worklist.size() > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
365 Block* mid = worklist.pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
366 if (mid == early) continue; // stop searching here
a61af66fc99e Initial load
duke
parents:
diff changeset
367
a61af66fc99e Initial load
duke
parents:
diff changeset
368 // Test and set the visited bit.
a61af66fc99e Initial load
duke
parents:
diff changeset
369 if (mid->raise_LCA_visited() == mark) continue; // already visited
a61af66fc99e Initial load
duke
parents:
diff changeset
370
a61af66fc99e Initial load
duke
parents:
diff changeset
371 // Don't process the current LCA, otherwise the search may terminate early
a61af66fc99e Initial load
duke
parents:
diff changeset
372 if (mid != LCA && mid->raise_LCA_mark() == mark) {
a61af66fc99e Initial load
duke
parents:
diff changeset
373 // Raise the LCA.
a61af66fc99e Initial load
duke
parents:
diff changeset
374 LCA = mid->dom_lca(LCA);
a61af66fc99e Initial load
duke
parents:
diff changeset
375 if (LCA == early) break; // stop searching everywhere
a61af66fc99e Initial load
duke
parents:
diff changeset
376 assert(early->dominates(LCA), "early is high enough");
a61af66fc99e Initial load
duke
parents:
diff changeset
377 // Resume searching at that point, skipping intermediate levels.
a61af66fc99e Initial load
duke
parents:
diff changeset
378 worklist.push(LCA);
215
273eaa04d9a1 6714694: assertion in 64bit server vm (store->find_edge(load) != -1,"missing precedence edge") with COOPs
kvn
parents: 31
diff changeset
379 if (LCA == mid)
273eaa04d9a1 6714694: assertion in 64bit server vm (store->find_edge(load) != -1,"missing precedence edge") with COOPs
kvn
parents: 31
diff changeset
380 continue; // Don't mark as visited to avoid early termination.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
381 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
382 // Keep searching through this block's predecessors.
a61af66fc99e Initial load
duke
parents:
diff changeset
383 for (uint j = 1, jmax = mid->num_preds(); j < jmax; j++) {
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
384 Block* mid_parent = cfg->get_block_for_node(mid->pred(j));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
385 worklist.push(mid_parent);
a61af66fc99e Initial load
duke
parents:
diff changeset
386 }
a61af66fc99e Initial load
duke
parents:
diff changeset
387 }
215
273eaa04d9a1 6714694: assertion in 64bit server vm (store->find_edge(load) != -1,"missing precedence edge") with COOPs
kvn
parents: 31
diff changeset
388 mid->set_raise_LCA_visited(mark);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
389 }
a61af66fc99e Initial load
duke
parents:
diff changeset
390 return LCA;
a61af66fc99e Initial load
duke
parents:
diff changeset
391 }
a61af66fc99e Initial load
duke
parents:
diff changeset
392
a61af66fc99e Initial load
duke
parents:
diff changeset
393 //--------------------------memory_early_block--------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
394 // This is a variation of find_deepest_input, the heart of schedule_early.
a61af66fc99e Initial load
duke
parents:
diff changeset
395 // Find the "early" block for a load, if we considered only memory and
a61af66fc99e Initial load
duke
parents:
diff changeset
396 // address inputs, that is, if other data inputs were ignored.
a61af66fc99e Initial load
duke
parents:
diff changeset
397 //
a61af66fc99e Initial load
duke
parents:
diff changeset
398 // Because a subset of edges are considered, the resulting block will
a61af66fc99e Initial load
duke
parents:
diff changeset
399 // be earlier (at a shallower dom_depth) than the true schedule_early
a61af66fc99e Initial load
duke
parents:
diff changeset
400 // point of the node. We compute this earlier block as a more permissive
a61af66fc99e Initial load
duke
parents:
diff changeset
401 // site for anti-dependency insertion, but only if subsume_loads is enabled.
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
402 static Block* memory_early_block(Node* load, Block* early, const PhaseCFG* cfg) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
403 Node* base;
a61af66fc99e Initial load
duke
parents:
diff changeset
404 Node* index;
a61af66fc99e Initial load
duke
parents:
diff changeset
405 Node* store = load->in(MemNode::Memory);
a61af66fc99e Initial load
duke
parents:
diff changeset
406 load->as_Mach()->memory_inputs(base, index);
a61af66fc99e Initial load
duke
parents:
diff changeset
407
a61af66fc99e Initial load
duke
parents:
diff changeset
408 assert(base != NodeSentinel && index != NodeSentinel,
a61af66fc99e Initial load
duke
parents:
diff changeset
409 "unexpected base/index inputs");
a61af66fc99e Initial load
duke
parents:
diff changeset
410
a61af66fc99e Initial load
duke
parents:
diff changeset
411 Node* mem_inputs[4];
a61af66fc99e Initial load
duke
parents:
diff changeset
412 int mem_inputs_length = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
413 if (base != NULL) mem_inputs[mem_inputs_length++] = base;
a61af66fc99e Initial load
duke
parents:
diff changeset
414 if (index != NULL) mem_inputs[mem_inputs_length++] = index;
a61af66fc99e Initial load
duke
parents:
diff changeset
415 if (store != NULL) mem_inputs[mem_inputs_length++] = store;
a61af66fc99e Initial load
duke
parents:
diff changeset
416
a61af66fc99e Initial load
duke
parents:
diff changeset
417 // In the comparision below, add one to account for the control input,
a61af66fc99e Initial load
duke
parents:
diff changeset
418 // which may be null, but always takes up a spot in the in array.
a61af66fc99e Initial load
duke
parents:
diff changeset
419 if (mem_inputs_length + 1 < (int) load->req()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
420 // This "load" has more inputs than just the memory, base and index inputs.
a61af66fc99e Initial load
duke
parents:
diff changeset
421 // For purposes of checking anti-dependences, we need to start
a61af66fc99e Initial load
duke
parents:
diff changeset
422 // from the early block of only the address portion of the instruction,
a61af66fc99e Initial load
duke
parents:
diff changeset
423 // and ignore other blocks that may have factored into the wider
a61af66fc99e Initial load
duke
parents:
diff changeset
424 // schedule_early calculation.
a61af66fc99e Initial load
duke
parents:
diff changeset
425 if (load->in(0) != NULL) mem_inputs[mem_inputs_length++] = load->in(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
426
a61af66fc99e Initial load
duke
parents:
diff changeset
427 Block* deepb = NULL; // Deepest block so far
a61af66fc99e Initial load
duke
parents:
diff changeset
428 int deepb_dom_depth = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
429 for (int i = 0; i < mem_inputs_length; i++) {
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
430 Block* inb = cfg->get_block_for_node(mem_inputs[i]);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
431 if (deepb_dom_depth < (int) inb->_dom_depth) {
a61af66fc99e Initial load
duke
parents:
diff changeset
432 // The new inb must be dominated by the previous deepb.
a61af66fc99e Initial load
duke
parents:
diff changeset
433 // The various inputs must be linearly ordered in the dom
a61af66fc99e Initial load
duke
parents:
diff changeset
434 // tree, or else there will not be a unique deepest block.
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
435 DEBUG_ONLY(assert_dom(deepb, inb, load, cfg));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
436 deepb = inb; // Save deepest block
a61af66fc99e Initial load
duke
parents:
diff changeset
437 deepb_dom_depth = deepb->_dom_depth;
a61af66fc99e Initial load
duke
parents:
diff changeset
438 }
a61af66fc99e Initial load
duke
parents:
diff changeset
439 }
a61af66fc99e Initial load
duke
parents:
diff changeset
440 early = deepb;
a61af66fc99e Initial load
duke
parents:
diff changeset
441 }
a61af66fc99e Initial load
duke
parents:
diff changeset
442
a61af66fc99e Initial load
duke
parents:
diff changeset
443 return early;
a61af66fc99e Initial load
duke
parents:
diff changeset
444 }
a61af66fc99e Initial load
duke
parents:
diff changeset
445
a61af66fc99e Initial load
duke
parents:
diff changeset
446 //--------------------------insert_anti_dependences---------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
447 // A load may need to witness memory that nearby stores can overwrite.
a61af66fc99e Initial load
duke
parents:
diff changeset
448 // For each nearby store, either insert an "anti-dependence" edge
a61af66fc99e Initial load
duke
parents:
diff changeset
449 // from the load to the store, or else move LCA upward to force the
a61af66fc99e Initial load
duke
parents:
diff changeset
450 // load to (eventually) be scheduled in a block above the store.
a61af66fc99e Initial load
duke
parents:
diff changeset
451 //
a61af66fc99e Initial load
duke
parents:
diff changeset
452 // Do not add edges to stores on distinct control-flow paths;
a61af66fc99e Initial load
duke
parents:
diff changeset
453 // only add edges to stores which might interfere.
a61af66fc99e Initial load
duke
parents:
diff changeset
454 //
a61af66fc99e Initial load
duke
parents:
diff changeset
455 // Return the (updated) LCA. There will not be any possibly interfering
a61af66fc99e Initial load
duke
parents:
diff changeset
456 // store between the load's "early block" and the updated LCA.
a61af66fc99e Initial load
duke
parents:
diff changeset
457 // Any stores in the updated LCA will have new precedence edges
a61af66fc99e Initial load
duke
parents:
diff changeset
458 // back to the load. The caller is expected to schedule the load
a61af66fc99e Initial load
duke
parents:
diff changeset
459 // in the LCA, in which case the precedence edges will make LCM
a61af66fc99e Initial load
duke
parents:
diff changeset
460 // preserve anti-dependences. The caller may also hoist the load
a61af66fc99e Initial load
duke
parents:
diff changeset
461 // above the LCA, if it is not the early block.
a61af66fc99e Initial load
duke
parents:
diff changeset
462 Block* PhaseCFG::insert_anti_dependences(Block* LCA, Node* load, bool verify) {
a61af66fc99e Initial load
duke
parents:
diff changeset
463 assert(load->needs_anti_dependence_check(), "must be a load of some sort");
a61af66fc99e Initial load
duke
parents:
diff changeset
464 assert(LCA != NULL, "");
a61af66fc99e Initial load
duke
parents:
diff changeset
465 DEBUG_ONLY(Block* LCA_orig = LCA);
a61af66fc99e Initial load
duke
parents:
diff changeset
466
a61af66fc99e Initial load
duke
parents:
diff changeset
467 // Compute the alias index. Loads and stores with different alias indices
a61af66fc99e Initial load
duke
parents:
diff changeset
468 // do not need anti-dependence edges.
a61af66fc99e Initial load
duke
parents:
diff changeset
469 uint load_alias_idx = C->get_alias_index(load->adr_type());
a61af66fc99e Initial load
duke
parents:
diff changeset
470 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
471 if (load_alias_idx == Compile::AliasIdxBot && C->AliasLevel() > 0 &&
a61af66fc99e Initial load
duke
parents:
diff changeset
472 (PrintOpto || VerifyAliases ||
a61af66fc99e Initial load
duke
parents:
diff changeset
473 PrintMiscellaneous && (WizardMode || Verbose))) {
a61af66fc99e Initial load
duke
parents:
diff changeset
474 // Load nodes should not consume all of memory.
a61af66fc99e Initial load
duke
parents:
diff changeset
475 // Reporting a bottom type indicates a bug in adlc.
a61af66fc99e Initial load
duke
parents:
diff changeset
476 // If some particular type of node validly consumes all of memory,
a61af66fc99e Initial load
duke
parents:
diff changeset
477 // sharpen the preceding "if" to exclude it, so we can catch bugs here.
a61af66fc99e Initial load
duke
parents:
diff changeset
478 tty->print_cr("*** Possible Anti-Dependence Bug: Load consumes all of memory.");
a61af66fc99e Initial load
duke
parents:
diff changeset
479 load->dump(2);
a61af66fc99e Initial load
duke
parents:
diff changeset
480 if (VerifyAliases) assert(load_alias_idx != Compile::AliasIdxBot, "");
a61af66fc99e Initial load
duke
parents:
diff changeset
481 }
a61af66fc99e Initial load
duke
parents:
diff changeset
482 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
483 assert(load_alias_idx || (load->is_Mach() && load->as_Mach()->ideal_Opcode() == Op_StrComp),
a61af66fc99e Initial load
duke
parents:
diff changeset
484 "String compare is only known 'load' that does not conflict with any stores");
681
fbde8ec322d0 6761600: Use sse 4.2 in intrinsics
cfang
parents: 673
diff changeset
485 assert(load_alias_idx || (load->is_Mach() && load->as_Mach()->ideal_Opcode() == Op_StrEquals),
fbde8ec322d0 6761600: Use sse 4.2 in intrinsics
cfang
parents: 673
diff changeset
486 "String equals is a 'load' that does not conflict with any stores");
fbde8ec322d0 6761600: Use sse 4.2 in intrinsics
cfang
parents: 673
diff changeset
487 assert(load_alias_idx || (load->is_Mach() && load->as_Mach()->ideal_Opcode() == Op_StrIndexOf),
fbde8ec322d0 6761600: Use sse 4.2 in intrinsics
cfang
parents: 673
diff changeset
488 "String indexOf is a 'load' that does not conflict with any stores");
fbde8ec322d0 6761600: Use sse 4.2 in intrinsics
cfang
parents: 673
diff changeset
489 assert(load_alias_idx || (load->is_Mach() && load->as_Mach()->ideal_Opcode() == Op_AryEq),
fbde8ec322d0 6761600: Use sse 4.2 in intrinsics
cfang
parents: 673
diff changeset
490 "Arrays equals is a 'load' that do not conflict with any stores");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
491
a61af66fc99e Initial load
duke
parents:
diff changeset
492 if (!C->alias_type(load_alias_idx)->is_rewritable()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
493 // It is impossible to spoil this load by putting stores before it,
a61af66fc99e Initial load
duke
parents:
diff changeset
494 // because we know that the stores will never update the value
a61af66fc99e Initial load
duke
parents:
diff changeset
495 // which 'load' must witness.
a61af66fc99e Initial load
duke
parents:
diff changeset
496 return LCA;
a61af66fc99e Initial load
duke
parents:
diff changeset
497 }
a61af66fc99e Initial load
duke
parents:
diff changeset
498
a61af66fc99e Initial load
duke
parents:
diff changeset
499 node_idx_t load_index = load->_idx;
a61af66fc99e Initial load
duke
parents:
diff changeset
500
a61af66fc99e Initial load
duke
parents:
diff changeset
501 // Note the earliest legal placement of 'load', as determined by
a61af66fc99e Initial load
duke
parents:
diff changeset
502 // by the unique point in the dom tree where all memory effects
a61af66fc99e Initial load
duke
parents:
diff changeset
503 // and other inputs are first available. (Computed by schedule_early.)
a61af66fc99e Initial load
duke
parents:
diff changeset
504 // For normal loads, 'early' is the shallowest place (dom graph wise)
a61af66fc99e Initial load
duke
parents:
diff changeset
505 // to look for anti-deps between this load and any store.
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
506 Block* early = get_block_for_node(load);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
507
a61af66fc99e Initial load
duke
parents:
diff changeset
508 // If we are subsuming loads, compute an "early" block that only considers
a61af66fc99e Initial load
duke
parents:
diff changeset
509 // memory or address inputs. This block may be different than the
a61af66fc99e Initial load
duke
parents:
diff changeset
510 // schedule_early block in that it could be at an even shallower depth in the
a61af66fc99e Initial load
duke
parents:
diff changeset
511 // dominator tree, and allow for a broader discovery of anti-dependences.
a61af66fc99e Initial load
duke
parents:
diff changeset
512 if (C->subsume_loads()) {
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
513 early = memory_early_block(load, early, this);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
514 }
a61af66fc99e Initial load
duke
parents:
diff changeset
515
a61af66fc99e Initial load
duke
parents:
diff changeset
516 ResourceArea *area = Thread::current()->resource_area();
a61af66fc99e Initial load
duke
parents:
diff changeset
517 Node_List worklist_mem(area); // prior memory state to store
a61af66fc99e Initial load
duke
parents:
diff changeset
518 Node_List worklist_store(area); // possible-def to explore
31
6152cbb08ce9 6590177: jck60019 test assert(!repeated,"do not walk merges twice")
kvn
parents: 0
diff changeset
519 Node_List worklist_visited(area); // visited mergemem nodes
0
a61af66fc99e Initial load
duke
parents:
diff changeset
520 Node_List non_early_stores(area); // all relevant stores outside of early
a61af66fc99e Initial load
duke
parents:
diff changeset
521 bool must_raise_LCA = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
522
a61af66fc99e Initial load
duke
parents:
diff changeset
523 #ifdef TRACK_PHI_INPUTS
a61af66fc99e Initial load
duke
parents:
diff changeset
524 // %%% This extra checking fails because MergeMem nodes are not GVNed.
a61af66fc99e Initial load
duke
parents:
diff changeset
525 // Provide "phi_inputs" to check if every input to a PhiNode is from the
a61af66fc99e Initial load
duke
parents:
diff changeset
526 // original memory state. This indicates a PhiNode for which should not
a61af66fc99e Initial load
duke
parents:
diff changeset
527 // prevent the load from sinking. For such a block, set_raise_LCA_mark
a61af66fc99e Initial load
duke
parents:
diff changeset
528 // may be overly conservative.
a61af66fc99e Initial load
duke
parents:
diff changeset
529 // Mechanism: count inputs seen for each Phi encountered in worklist_store.
a61af66fc99e Initial load
duke
parents:
diff changeset
530 DEBUG_ONLY(GrowableArray<uint> phi_inputs(area, C->unique(),0,0));
a61af66fc99e Initial load
duke
parents:
diff changeset
531 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
532
a61af66fc99e Initial load
duke
parents:
diff changeset
533 // 'load' uses some memory state; look for users of the same state.
a61af66fc99e Initial load
duke
parents:
diff changeset
534 // Recurse through MergeMem nodes to the stores that use them.
a61af66fc99e Initial load
duke
parents:
diff changeset
535
a61af66fc99e Initial load
duke
parents:
diff changeset
536 // Each of these stores is a possible definition of memory
a61af66fc99e Initial load
duke
parents:
diff changeset
537 // that 'load' needs to use. We need to force 'load'
a61af66fc99e Initial load
duke
parents:
diff changeset
538 // to occur before each such store. When the store is in
a61af66fc99e Initial load
duke
parents:
diff changeset
539 // the same block as 'load', we insert an anti-dependence
a61af66fc99e Initial load
duke
parents:
diff changeset
540 // edge load->store.
a61af66fc99e Initial load
duke
parents:
diff changeset
541
a61af66fc99e Initial load
duke
parents:
diff changeset
542 // The relevant stores "nearby" the load consist of a tree rooted
a61af66fc99e Initial load
duke
parents:
diff changeset
543 // at initial_mem, with internal nodes of type MergeMem.
a61af66fc99e Initial load
duke
parents:
diff changeset
544 // Therefore, the branches visited by the worklist are of this form:
a61af66fc99e Initial load
duke
parents:
diff changeset
545 // initial_mem -> (MergeMem ->)* store
a61af66fc99e Initial load
duke
parents:
diff changeset
546 // The anti-dependence constraints apply only to the fringe of this tree.
a61af66fc99e Initial load
duke
parents:
diff changeset
547
a61af66fc99e Initial load
duke
parents:
diff changeset
548 Node* initial_mem = load->in(MemNode::Memory);
a61af66fc99e Initial load
duke
parents:
diff changeset
549 worklist_store.push(initial_mem);
31
6152cbb08ce9 6590177: jck60019 test assert(!repeated,"do not walk merges twice")
kvn
parents: 0
diff changeset
550 worklist_visited.push(initial_mem);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
551 worklist_mem.push(NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
552 while (worklist_store.size() > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
553 // Examine a nearby store to see if it might interfere with our load.
a61af66fc99e Initial load
duke
parents:
diff changeset
554 Node* mem = worklist_mem.pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
555 Node* store = worklist_store.pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
556 uint op = store->Opcode();
a61af66fc99e Initial load
duke
parents:
diff changeset
557
a61af66fc99e Initial load
duke
parents:
diff changeset
558 // MergeMems do not directly have anti-deps.
a61af66fc99e Initial load
duke
parents:
diff changeset
559 // Treat them as internal nodes in a forward tree of memory states,
a61af66fc99e Initial load
duke
parents:
diff changeset
560 // the leaves of which are each a 'possible-def'.
a61af66fc99e Initial load
duke
parents:
diff changeset
561 if (store == initial_mem // root (exclusive) of tree we are searching
a61af66fc99e Initial load
duke
parents:
diff changeset
562 || op == Op_MergeMem // internal node of tree we are searching
a61af66fc99e Initial load
duke
parents:
diff changeset
563 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
564 mem = store; // It's not a possibly interfering store.
31
6152cbb08ce9 6590177: jck60019 test assert(!repeated,"do not walk merges twice")
kvn
parents: 0
diff changeset
565 if (store == initial_mem)
6152cbb08ce9 6590177: jck60019 test assert(!repeated,"do not walk merges twice")
kvn
parents: 0
diff changeset
566 initial_mem = NULL; // only process initial memory once
6152cbb08ce9 6590177: jck60019 test assert(!repeated,"do not walk merges twice")
kvn
parents: 0
diff changeset
567
0
a61af66fc99e Initial load
duke
parents:
diff changeset
568 for (DUIterator_Fast imax, i = mem->fast_outs(imax); i < imax; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
569 store = mem->fast_out(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
570 if (store->is_MergeMem()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
571 // Be sure we don't get into combinatorial problems.
a61af66fc99e Initial load
duke
parents:
diff changeset
572 // (Allow phis to be repeated; they can merge two relevant states.)
31
6152cbb08ce9 6590177: jck60019 test assert(!repeated,"do not walk merges twice")
kvn
parents: 0
diff changeset
573 uint j = worklist_visited.size();
6152cbb08ce9 6590177: jck60019 test assert(!repeated,"do not walk merges twice")
kvn
parents: 0
diff changeset
574 for (; j > 0; j--) {
6152cbb08ce9 6590177: jck60019 test assert(!repeated,"do not walk merges twice")
kvn
parents: 0
diff changeset
575 if (worklist_visited.at(j-1) == store) break;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
576 }
31
6152cbb08ce9 6590177: jck60019 test assert(!repeated,"do not walk merges twice")
kvn
parents: 0
diff changeset
577 if (j > 0) continue; // already on work list; do not repeat
6152cbb08ce9 6590177: jck60019 test assert(!repeated,"do not walk merges twice")
kvn
parents: 0
diff changeset
578 worklist_visited.push(store);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
579 }
a61af66fc99e Initial load
duke
parents:
diff changeset
580 worklist_mem.push(mem);
a61af66fc99e Initial load
duke
parents:
diff changeset
581 worklist_store.push(store);
a61af66fc99e Initial load
duke
parents:
diff changeset
582 }
a61af66fc99e Initial load
duke
parents:
diff changeset
583 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
584 }
a61af66fc99e Initial load
duke
parents:
diff changeset
585
a61af66fc99e Initial load
duke
parents:
diff changeset
586 if (op == Op_MachProj || op == Op_Catch) continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
587 if (store->needs_anti_dependence_check()) continue; // not really a store
a61af66fc99e Initial load
duke
parents:
diff changeset
588
a61af66fc99e Initial load
duke
parents:
diff changeset
589 // Compute the alias index. Loads and stores with different alias
a61af66fc99e Initial load
duke
parents:
diff changeset
590 // indices do not need anti-dependence edges. Wide MemBar's are
a61af66fc99e Initial load
duke
parents:
diff changeset
591 // anti-dependent on everything (except immutable memories).
a61af66fc99e Initial load
duke
parents:
diff changeset
592 const TypePtr* adr_type = store->adr_type();
a61af66fc99e Initial load
duke
parents:
diff changeset
593 if (!C->can_alias(adr_type, load_alias_idx)) continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
594
a61af66fc99e Initial load
duke
parents:
diff changeset
595 // Most slow-path runtime calls do NOT modify Java memory, but
a61af66fc99e Initial load
duke
parents:
diff changeset
596 // they can block and so write Raw memory.
a61af66fc99e Initial load
duke
parents:
diff changeset
597 if (store->is_Mach()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
598 MachNode* mstore = store->as_Mach();
a61af66fc99e Initial load
duke
parents:
diff changeset
599 if (load_alias_idx != Compile::AliasIdxRaw) {
a61af66fc99e Initial load
duke
parents:
diff changeset
600 // Check for call into the runtime using the Java calling
a61af66fc99e Initial load
duke
parents:
diff changeset
601 // convention (and from there into a wrapper); it has no
a61af66fc99e Initial load
duke
parents:
diff changeset
602 // _method. Can't do this optimization for Native calls because
a61af66fc99e Initial load
duke
parents:
diff changeset
603 // they CAN write to Java memory.
a61af66fc99e Initial load
duke
parents:
diff changeset
604 if (mstore->ideal_Opcode() == Op_CallStaticJava) {
a61af66fc99e Initial load
duke
parents:
diff changeset
605 assert(mstore->is_MachSafePoint(), "");
a61af66fc99e Initial load
duke
parents:
diff changeset
606 MachSafePointNode* ms = (MachSafePointNode*) mstore;
a61af66fc99e Initial load
duke
parents:
diff changeset
607 assert(ms->is_MachCallJava(), "");
a61af66fc99e Initial load
duke
parents:
diff changeset
608 MachCallJavaNode* mcj = (MachCallJavaNode*) ms;
a61af66fc99e Initial load
duke
parents:
diff changeset
609 if (mcj->_method == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
610 // These runtime calls do not write to Java visible memory
a61af66fc99e Initial load
duke
parents:
diff changeset
611 // (other than Raw) and so do not require anti-dependence edges.
a61af66fc99e Initial load
duke
parents:
diff changeset
612 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
613 }
a61af66fc99e Initial load
duke
parents:
diff changeset
614 }
a61af66fc99e Initial load
duke
parents:
diff changeset
615 // Same for SafePoints: they read/write Raw but only read otherwise.
a61af66fc99e Initial load
duke
parents:
diff changeset
616 // This is basically a workaround for SafePoints only defining control
a61af66fc99e Initial load
duke
parents:
diff changeset
617 // instead of control + memory.
a61af66fc99e Initial load
duke
parents:
diff changeset
618 if (mstore->ideal_Opcode() == Op_SafePoint)
a61af66fc99e Initial load
duke
parents:
diff changeset
619 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
620 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
621 // Some raw memory, such as the load of "top" at an allocation,
a61af66fc99e Initial load
duke
parents:
diff changeset
622 // can be control dependent on the previous safepoint. See
a61af66fc99e Initial load
duke
parents:
diff changeset
623 // comments in GraphKit::allocate_heap() about control input.
a61af66fc99e Initial load
duke
parents:
diff changeset
624 // Inserting an anti-dep between such a safepoint and a use
a61af66fc99e Initial load
duke
parents:
diff changeset
625 // creates a cycle, and will cause a subsequent failure in
a61af66fc99e Initial load
duke
parents:
diff changeset
626 // local scheduling. (BugId 4919904)
a61af66fc99e Initial load
duke
parents:
diff changeset
627 // (%%% How can a control input be a safepoint and not a projection??)
a61af66fc99e Initial load
duke
parents:
diff changeset
628 if (mstore->ideal_Opcode() == Op_SafePoint && load->in(0) == mstore)
a61af66fc99e Initial load
duke
parents:
diff changeset
629 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
630 }
a61af66fc99e Initial load
duke
parents:
diff changeset
631 }
a61af66fc99e Initial load
duke
parents:
diff changeset
632
a61af66fc99e Initial load
duke
parents:
diff changeset
633 // Identify a block that the current load must be above,
a61af66fc99e Initial load
duke
parents:
diff changeset
634 // or else observe that 'store' is all the way up in the
a61af66fc99e Initial load
duke
parents:
diff changeset
635 // earliest legal block for 'load'. In the latter case,
a61af66fc99e Initial load
duke
parents:
diff changeset
636 // immediately insert an anti-dependence edge.
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
637 Block* store_block = get_block_for_node(store);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
638 assert(store_block != NULL, "unused killing projections skipped above");
a61af66fc99e Initial load
duke
parents:
diff changeset
639
a61af66fc99e Initial load
duke
parents:
diff changeset
640 if (store->is_Phi()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
641 // 'load' uses memory which is one (or more) of the Phi's inputs.
a61af66fc99e Initial load
duke
parents:
diff changeset
642 // It must be scheduled not before the Phi, but rather before
a61af66fc99e Initial load
duke
parents:
diff changeset
643 // each of the relevant Phi inputs.
a61af66fc99e Initial load
duke
parents:
diff changeset
644 //
a61af66fc99e Initial load
duke
parents:
diff changeset
645 // Instead of finding the LCA of all inputs to a Phi that match 'mem',
a61af66fc99e Initial load
duke
parents:
diff changeset
646 // we mark each corresponding predecessor block and do a combined
a61af66fc99e Initial load
duke
parents:
diff changeset
647 // hoisting operation later (raise_LCA_above_marks).
a61af66fc99e Initial load
duke
parents:
diff changeset
648 //
a61af66fc99e Initial load
duke
parents:
diff changeset
649 // Do not assert(store_block != early, "Phi merging memory after access")
a61af66fc99e Initial load
duke
parents:
diff changeset
650 // PhiNode may be at start of block 'early' with backedge to 'early'
a61af66fc99e Initial load
duke
parents:
diff changeset
651 DEBUG_ONLY(bool found_match = false);
a61af66fc99e Initial load
duke
parents:
diff changeset
652 for (uint j = PhiNode::Input, jmax = store->req(); j < jmax; j++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
653 if (store->in(j) == mem) { // Found matching input?
a61af66fc99e Initial load
duke
parents:
diff changeset
654 DEBUG_ONLY(found_match = true);
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
655 Block* pred_block = get_block_for_node(store_block->pred(j));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
656 if (pred_block != early) {
a61af66fc99e Initial load
duke
parents:
diff changeset
657 // If any predecessor of the Phi matches the load's "early block",
a61af66fc99e Initial load
duke
parents:
diff changeset
658 // we do not need a precedence edge between the Phi and 'load'
605
98cb887364d3 6810672: Comment typos
twisti
parents: 601
diff changeset
659 // since the load will be forced into a block preceding the Phi.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
660 pred_block->set_raise_LCA_mark(load_index);
a61af66fc99e Initial load
duke
parents:
diff changeset
661 assert(!LCA_orig->dominates(pred_block) ||
a61af66fc99e Initial load
duke
parents:
diff changeset
662 early->dominates(pred_block), "early is high enough");
a61af66fc99e Initial load
duke
parents:
diff changeset
663 must_raise_LCA = true;
788
1851e1fb420e 6843752: missing code for an anti-dependent Phi in GCM
kvn
parents: 681
diff changeset
664 } else {
1851e1fb420e 6843752: missing code for an anti-dependent Phi in GCM
kvn
parents: 681
diff changeset
665 // anti-dependent upon PHI pinned below 'early', no edge needed
1851e1fb420e 6843752: missing code for an anti-dependent Phi in GCM
kvn
parents: 681
diff changeset
666 LCA = early; // but can not schedule below 'early'
0
a61af66fc99e Initial load
duke
parents:
diff changeset
667 }
a61af66fc99e Initial load
duke
parents:
diff changeset
668 }
a61af66fc99e Initial load
duke
parents:
diff changeset
669 }
a61af66fc99e Initial load
duke
parents:
diff changeset
670 assert(found_match, "no worklist bug");
a61af66fc99e Initial load
duke
parents:
diff changeset
671 #ifdef TRACK_PHI_INPUTS
a61af66fc99e Initial load
duke
parents:
diff changeset
672 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
673 // This assert asks about correct handling of PhiNodes, which may not
a61af66fc99e Initial load
duke
parents:
diff changeset
674 // have all input edges directly from 'mem'. See BugId 4621264
a61af66fc99e Initial load
duke
parents:
diff changeset
675 int num_mem_inputs = phi_inputs.at_grow(store->_idx,0) + 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
676 // Increment by exactly one even if there are multiple copies of 'mem'
a61af66fc99e Initial load
duke
parents:
diff changeset
677 // coming into the phi, because we will run this block several times
a61af66fc99e Initial load
duke
parents:
diff changeset
678 // if there are several copies of 'mem'. (That's how DU iterators work.)
a61af66fc99e Initial load
duke
parents:
diff changeset
679 phi_inputs.at_put(store->_idx, num_mem_inputs);
a61af66fc99e Initial load
duke
parents:
diff changeset
680 assert(PhiNode::Input + num_mem_inputs < store->req(),
a61af66fc99e Initial load
duke
parents:
diff changeset
681 "Expect at least one phi input will not be from original memory state");
a61af66fc99e Initial load
duke
parents:
diff changeset
682 #endif //ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
683 #endif //TRACK_PHI_INPUTS
a61af66fc99e Initial load
duke
parents:
diff changeset
684 } else if (store_block != early) {
a61af66fc99e Initial load
duke
parents:
diff changeset
685 // 'store' is between the current LCA and earliest possible block.
a61af66fc99e Initial load
duke
parents:
diff changeset
686 // Label its block, and decide later on how to raise the LCA
a61af66fc99e Initial load
duke
parents:
diff changeset
687 // to include the effect on LCA of this store.
a61af66fc99e Initial load
duke
parents:
diff changeset
688 // If this store's block gets chosen as the raised LCA, we
a61af66fc99e Initial load
duke
parents:
diff changeset
689 // will find him on the non_early_stores list and stick him
a61af66fc99e Initial load
duke
parents:
diff changeset
690 // with a precedence edge.
a61af66fc99e Initial load
duke
parents:
diff changeset
691 // (But, don't bother if LCA is already raised all the way.)
a61af66fc99e Initial load
duke
parents:
diff changeset
692 if (LCA != early) {
a61af66fc99e Initial load
duke
parents:
diff changeset
693 store_block->set_raise_LCA_mark(load_index);
a61af66fc99e Initial load
duke
parents:
diff changeset
694 must_raise_LCA = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
695 non_early_stores.push(store);
a61af66fc99e Initial load
duke
parents:
diff changeset
696 }
a61af66fc99e Initial load
duke
parents:
diff changeset
697 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
698 // Found a possibly-interfering store in the load's 'early' block.
a61af66fc99e Initial load
duke
parents:
diff changeset
699 // This means 'load' cannot sink at all in the dominator tree.
a61af66fc99e Initial load
duke
parents:
diff changeset
700 // Add an anti-dep edge, and squeeze 'load' into the highest block.
a61af66fc99e Initial load
duke
parents:
diff changeset
701 assert(store != load->in(0), "dependence cycle found");
a61af66fc99e Initial load
duke
parents:
diff changeset
702 if (verify) {
a61af66fc99e Initial load
duke
parents:
diff changeset
703 assert(store->find_edge(load) != -1, "missing precedence edge");
a61af66fc99e Initial load
duke
parents:
diff changeset
704 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
705 store->add_prec(load);
a61af66fc99e Initial load
duke
parents:
diff changeset
706 }
a61af66fc99e Initial load
duke
parents:
diff changeset
707 LCA = early;
a61af66fc99e Initial load
duke
parents:
diff changeset
708 // This turns off the process of gathering non_early_stores.
a61af66fc99e Initial load
duke
parents:
diff changeset
709 }
a61af66fc99e Initial load
duke
parents:
diff changeset
710 }
a61af66fc99e Initial load
duke
parents:
diff changeset
711 // (Worklist is now empty; all nearby stores have been visited.)
a61af66fc99e Initial load
duke
parents:
diff changeset
712
a61af66fc99e Initial load
duke
parents:
diff changeset
713 // Finished if 'load' must be scheduled in its 'early' block.
a61af66fc99e Initial load
duke
parents:
diff changeset
714 // If we found any stores there, they have already been given
a61af66fc99e Initial load
duke
parents:
diff changeset
715 // precedence edges.
a61af66fc99e Initial load
duke
parents:
diff changeset
716 if (LCA == early) return LCA;
a61af66fc99e Initial load
duke
parents:
diff changeset
717
a61af66fc99e Initial load
duke
parents:
diff changeset
718 // We get here only if there are no possibly-interfering stores
a61af66fc99e Initial load
duke
parents:
diff changeset
719 // in the load's 'early' block. Move LCA up above all predecessors
a61af66fc99e Initial load
duke
parents:
diff changeset
720 // which contain stores we have noted.
a61af66fc99e Initial load
duke
parents:
diff changeset
721 //
a61af66fc99e Initial load
duke
parents:
diff changeset
722 // The raised LCA block can be a home to such interfering stores,
a61af66fc99e Initial load
duke
parents:
diff changeset
723 // but its predecessors must not contain any such stores.
a61af66fc99e Initial load
duke
parents:
diff changeset
724 //
a61af66fc99e Initial load
duke
parents:
diff changeset
725 // The raised LCA will be a lower bound for placing the load,
a61af66fc99e Initial load
duke
parents:
diff changeset
726 // preventing the load from sinking past any block containing
a61af66fc99e Initial load
duke
parents:
diff changeset
727 // a store that may invalidate the memory state required by 'load'.
a61af66fc99e Initial load
duke
parents:
diff changeset
728 if (must_raise_LCA)
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
729 LCA = raise_LCA_above_marks(LCA, load->_idx, early, this);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
730 if (LCA == early) return LCA;
a61af66fc99e Initial load
duke
parents:
diff changeset
731
a61af66fc99e Initial load
duke
parents:
diff changeset
732 // Insert anti-dependence edges from 'load' to each store
a61af66fc99e Initial load
duke
parents:
diff changeset
733 // in the non-early LCA block.
a61af66fc99e Initial load
duke
parents:
diff changeset
734 // Mine the non_early_stores list for such stores.
a61af66fc99e Initial load
duke
parents:
diff changeset
735 if (LCA->raise_LCA_mark() == load_index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
736 while (non_early_stores.size() > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
737 Node* store = non_early_stores.pop();
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
738 Block* store_block = get_block_for_node(store);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
739 if (store_block == LCA) {
a61af66fc99e Initial load
duke
parents:
diff changeset
740 // add anti_dependence from store to load in its own block
a61af66fc99e Initial load
duke
parents:
diff changeset
741 assert(store != load->in(0), "dependence cycle found");
a61af66fc99e Initial load
duke
parents:
diff changeset
742 if (verify) {
a61af66fc99e Initial load
duke
parents:
diff changeset
743 assert(store->find_edge(load) != -1, "missing precedence edge");
a61af66fc99e Initial load
duke
parents:
diff changeset
744 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
745 store->add_prec(load);
a61af66fc99e Initial load
duke
parents:
diff changeset
746 }
a61af66fc99e Initial load
duke
parents:
diff changeset
747 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
748 assert(store_block->raise_LCA_mark() == load_index, "block was marked");
a61af66fc99e Initial load
duke
parents:
diff changeset
749 // Any other stores we found must be either inside the new LCA
a61af66fc99e Initial load
duke
parents:
diff changeset
750 // or else outside the original LCA. In the latter case, they
a61af66fc99e Initial load
duke
parents:
diff changeset
751 // did not interfere with any use of 'load'.
a61af66fc99e Initial load
duke
parents:
diff changeset
752 assert(LCA->dominates(store_block)
a61af66fc99e Initial load
duke
parents:
diff changeset
753 || !LCA_orig->dominates(store_block), "no stray stores");
a61af66fc99e Initial load
duke
parents:
diff changeset
754 }
a61af66fc99e Initial load
duke
parents:
diff changeset
755 }
a61af66fc99e Initial load
duke
parents:
diff changeset
756 }
a61af66fc99e Initial load
duke
parents:
diff changeset
757
a61af66fc99e Initial load
duke
parents:
diff changeset
758 // Return the highest block containing stores; any stores
a61af66fc99e Initial load
duke
parents:
diff changeset
759 // within that block have been given anti-dependence edges.
a61af66fc99e Initial load
duke
parents:
diff changeset
760 return LCA;
a61af66fc99e Initial load
duke
parents:
diff changeset
761 }
a61af66fc99e Initial load
duke
parents:
diff changeset
762
a61af66fc99e Initial load
duke
parents:
diff changeset
763 // This class is used to iterate backwards over the nodes in the graph.
a61af66fc99e Initial load
duke
parents:
diff changeset
764
a61af66fc99e Initial load
duke
parents:
diff changeset
765 class Node_Backward_Iterator {
a61af66fc99e Initial load
duke
parents:
diff changeset
766
a61af66fc99e Initial load
duke
parents:
diff changeset
767 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
768 Node_Backward_Iterator();
a61af66fc99e Initial load
duke
parents:
diff changeset
769
a61af66fc99e Initial load
duke
parents:
diff changeset
770 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
771 // Constructor for the iterator
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
772 Node_Backward_Iterator(Node *root, VectorSet &visited, Node_List &stack, PhaseCFG &cfg);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
773
a61af66fc99e Initial load
duke
parents:
diff changeset
774 // Postincrement operator to iterate over the nodes
a61af66fc99e Initial load
duke
parents:
diff changeset
775 Node *next();
a61af66fc99e Initial load
duke
parents:
diff changeset
776
a61af66fc99e Initial load
duke
parents:
diff changeset
777 private:
a61af66fc99e Initial load
duke
parents:
diff changeset
778 VectorSet &_visited;
a61af66fc99e Initial load
duke
parents:
diff changeset
779 Node_List &_stack;
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
780 PhaseCFG &_cfg;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
781 };
a61af66fc99e Initial load
duke
parents:
diff changeset
782
a61af66fc99e Initial load
duke
parents:
diff changeset
783 // Constructor for the Node_Backward_Iterator
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
784 Node_Backward_Iterator::Node_Backward_Iterator( Node *root, VectorSet &visited, Node_List &stack, PhaseCFG &cfg)
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
785 : _visited(visited), _stack(stack), _cfg(cfg) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
786 // The stack should contain exactly the root
a61af66fc99e Initial load
duke
parents:
diff changeset
787 stack.clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
788 stack.push(root);
a61af66fc99e Initial load
duke
parents:
diff changeset
789
a61af66fc99e Initial load
duke
parents:
diff changeset
790 // Clear the visited bits
a61af66fc99e Initial load
duke
parents:
diff changeset
791 visited.Clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
792 }
a61af66fc99e Initial load
duke
parents:
diff changeset
793
a61af66fc99e Initial load
duke
parents:
diff changeset
794 // Iterator for the Node_Backward_Iterator
a61af66fc99e Initial load
duke
parents:
diff changeset
795 Node *Node_Backward_Iterator::next() {
a61af66fc99e Initial load
duke
parents:
diff changeset
796
a61af66fc99e Initial load
duke
parents:
diff changeset
797 // If the _stack is empty, then just return NULL: finished.
a61af66fc99e Initial load
duke
parents:
diff changeset
798 if ( !_stack.size() )
a61af66fc99e Initial load
duke
parents:
diff changeset
799 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
800
a61af66fc99e Initial load
duke
parents:
diff changeset
801 // '_stack' is emulating a real _stack. The 'visit-all-users' loop has been
a61af66fc99e Initial load
duke
parents:
diff changeset
802 // made stateless, so I do not need to record the index 'i' on my _stack.
a61af66fc99e Initial load
duke
parents:
diff changeset
803 // Instead I visit all users each time, scanning for unvisited users.
a61af66fc99e Initial load
duke
parents:
diff changeset
804 // I visit unvisited not-anti-dependence users first, then anti-dependent
a61af66fc99e Initial load
duke
parents:
diff changeset
805 // children next.
a61af66fc99e Initial load
duke
parents:
diff changeset
806 Node *self = _stack.pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
807
a61af66fc99e Initial load
duke
parents:
diff changeset
808 // I cycle here when I am entering a deeper level of recursion.
a61af66fc99e Initial load
duke
parents:
diff changeset
809 // The key variable 'self' was set prior to jumping here.
a61af66fc99e Initial load
duke
parents:
diff changeset
810 while( 1 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
811
a61af66fc99e Initial load
duke
parents:
diff changeset
812 _visited.set(self->_idx);
a61af66fc99e Initial load
duke
parents:
diff changeset
813
a61af66fc99e Initial load
duke
parents:
diff changeset
814 // Now schedule all uses as late as possible.
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
815 const Node* src = self->is_Proj() ? self->in(0) : self;
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
816 uint src_rpo = _cfg.get_block_for_node(src)->_rpo;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
817
a61af66fc99e Initial load
duke
parents:
diff changeset
818 // Schedule all nodes in a post-order visit
a61af66fc99e Initial load
duke
parents:
diff changeset
819 Node *unvisited = NULL; // Unvisited anti-dependent Node, if any
a61af66fc99e Initial load
duke
parents:
diff changeset
820
a61af66fc99e Initial load
duke
parents:
diff changeset
821 // Scan for unvisited nodes
a61af66fc99e Initial load
duke
parents:
diff changeset
822 for (DUIterator_Fast imax, i = self->fast_outs(imax); i < imax; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
823 // For all uses, schedule late
a61af66fc99e Initial load
duke
parents:
diff changeset
824 Node* n = self->fast_out(i); // Use
a61af66fc99e Initial load
duke
parents:
diff changeset
825
a61af66fc99e Initial load
duke
parents:
diff changeset
826 // Skip already visited children
a61af66fc99e Initial load
duke
parents:
diff changeset
827 if ( _visited.test(n->_idx) )
a61af66fc99e Initial load
duke
parents:
diff changeset
828 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
829
a61af66fc99e Initial load
duke
parents:
diff changeset
830 // do not traverse backward control edges
a61af66fc99e Initial load
duke
parents:
diff changeset
831 Node *use = n->is_Proj() ? n->in(0) : n;
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
832 uint use_rpo = _cfg.get_block_for_node(use)->_rpo;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
833
a61af66fc99e Initial load
duke
parents:
diff changeset
834 if ( use_rpo < src_rpo )
a61af66fc99e Initial load
duke
parents:
diff changeset
835 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
836
a61af66fc99e Initial load
duke
parents:
diff changeset
837 // Phi nodes always precede uses in a basic block
a61af66fc99e Initial load
duke
parents:
diff changeset
838 if ( use_rpo == src_rpo && use->is_Phi() )
a61af66fc99e Initial load
duke
parents:
diff changeset
839 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
840
a61af66fc99e Initial load
duke
parents:
diff changeset
841 unvisited = n; // Found unvisited
a61af66fc99e Initial load
duke
parents:
diff changeset
842
a61af66fc99e Initial load
duke
parents:
diff changeset
843 // Check for possible-anti-dependent
a61af66fc99e Initial load
duke
parents:
diff changeset
844 if( !n->needs_anti_dependence_check() )
a61af66fc99e Initial load
duke
parents:
diff changeset
845 break; // Not visited, not anti-dep; schedule it NOW
a61af66fc99e Initial load
duke
parents:
diff changeset
846 }
a61af66fc99e Initial load
duke
parents:
diff changeset
847
a61af66fc99e Initial load
duke
parents:
diff changeset
848 // Did I find an unvisited not-anti-dependent Node?
a61af66fc99e Initial load
duke
parents:
diff changeset
849 if ( !unvisited )
a61af66fc99e Initial load
duke
parents:
diff changeset
850 break; // All done with children; post-visit 'self'
a61af66fc99e Initial load
duke
parents:
diff changeset
851
a61af66fc99e Initial load
duke
parents:
diff changeset
852 // Visit the unvisited Node. Contains the obvious push to
a61af66fc99e Initial load
duke
parents:
diff changeset
853 // indicate I'm entering a deeper level of recursion. I push the
a61af66fc99e Initial load
duke
parents:
diff changeset
854 // old state onto the _stack and set a new state and loop (recurse).
a61af66fc99e Initial load
duke
parents:
diff changeset
855 _stack.push(self);
a61af66fc99e Initial load
duke
parents:
diff changeset
856 self = unvisited;
a61af66fc99e Initial load
duke
parents:
diff changeset
857 } // End recursion loop
a61af66fc99e Initial load
duke
parents:
diff changeset
858
a61af66fc99e Initial load
duke
parents:
diff changeset
859 return self;
a61af66fc99e Initial load
duke
parents:
diff changeset
860 }
a61af66fc99e Initial load
duke
parents:
diff changeset
861
a61af66fc99e Initial load
duke
parents:
diff changeset
862 //------------------------------ComputeLatenciesBackwards----------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
863 // Compute the latency of all the instructions.
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
864 void PhaseCFG::compute_latencies_backwards(VectorSet &visited, Node_List &stack) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
865 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
866 if (trace_opto_pipelining())
a61af66fc99e Initial load
duke
parents:
diff changeset
867 tty->print("\n#---- ComputeLatenciesBackwards ----\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
868 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
869
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
870 Node_Backward_Iterator iter((Node *)_root, visited, stack, *this);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
871 Node *n;
a61af66fc99e Initial load
duke
parents:
diff changeset
872
a61af66fc99e Initial load
duke
parents:
diff changeset
873 // Walk over all the nodes from last to first
a61af66fc99e Initial load
duke
parents:
diff changeset
874 while (n = iter.next()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
875 // Set the latency for the definitions of this instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
876 partial_latency_of_defs(n);
a61af66fc99e Initial load
duke
parents:
diff changeset
877 }
a61af66fc99e Initial load
duke
parents:
diff changeset
878 } // end ComputeLatenciesBackwards
a61af66fc99e Initial load
duke
parents:
diff changeset
879
a61af66fc99e Initial load
duke
parents:
diff changeset
880 //------------------------------partial_latency_of_defs------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
881 // Compute the latency impact of this node on all defs. This computes
a61af66fc99e Initial load
duke
parents:
diff changeset
882 // a number that increases as we approach the beginning of the routine.
a61af66fc99e Initial load
duke
parents:
diff changeset
883 void PhaseCFG::partial_latency_of_defs(Node *n) {
a61af66fc99e Initial load
duke
parents:
diff changeset
884 // Set the latency for this instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
885 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
886 if (trace_opto_pipelining()) {
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
887 tty->print("# latency_to_inputs: node_latency[%d] = %d for node", n->_idx, get_latency_for_node(n));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
888 dump();
a61af66fc99e Initial load
duke
parents:
diff changeset
889 }
a61af66fc99e Initial load
duke
parents:
diff changeset
890 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
891
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
892 if (n->is_Proj()) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
893 n = n->in(0);
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
894 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
895
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
896 if (n->is_Root()) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
897 return;
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
898 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
899
a61af66fc99e Initial load
duke
parents:
diff changeset
900 uint nlen = n->len();
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
901 uint use_latency = get_latency_for_node(n);
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
902 uint use_pre_order = get_block_for_node(n)->_pre_order;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
903
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
904 for (uint j = 0; j < nlen; j++) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
905 Node *def = n->in(j);
a61af66fc99e Initial load
duke
parents:
diff changeset
906
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
907 if (!def || def == n) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
908 continue;
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
909 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
910
a61af66fc99e Initial load
duke
parents:
diff changeset
911 // Walk backwards thru projections
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
912 if (def->is_Proj()) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
913 def = def->in(0);
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
914 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
915
a61af66fc99e Initial load
duke
parents:
diff changeset
916 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
917 if (trace_opto_pipelining()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
918 tty->print("# in(%2d): ", j);
a61af66fc99e Initial load
duke
parents:
diff changeset
919 def->dump();
a61af66fc99e Initial load
duke
parents:
diff changeset
920 }
a61af66fc99e Initial load
duke
parents:
diff changeset
921 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
922
a61af66fc99e Initial load
duke
parents:
diff changeset
923 // If the defining block is not known, assume it is ok
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
924 Block *def_block = get_block_for_node(def);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
925 uint def_pre_order = def_block ? def_block->_pre_order : 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
926
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
927 if ((use_pre_order < def_pre_order) || (use_pre_order == def_pre_order && n->is_Phi())) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
928 continue;
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
929 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
930
a61af66fc99e Initial load
duke
parents:
diff changeset
931 uint delta_latency = n->latency(j);
a61af66fc99e Initial load
duke
parents:
diff changeset
932 uint current_latency = delta_latency + use_latency;
a61af66fc99e Initial load
duke
parents:
diff changeset
933
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
934 if (get_latency_for_node(def) < current_latency) {
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
935 set_latency_for_node(def, current_latency);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
936 }
a61af66fc99e Initial load
duke
parents:
diff changeset
937
a61af66fc99e Initial load
duke
parents:
diff changeset
938 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
939 if (trace_opto_pipelining()) {
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
940 tty->print_cr("# %d + edge_latency(%d) == %d -> %d, node_latency[%d] = %d", use_latency, j, delta_latency, current_latency, def->_idx, get_latency_for_node(def));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
941 }
a61af66fc99e Initial load
duke
parents:
diff changeset
942 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
943 }
a61af66fc99e Initial load
duke
parents:
diff changeset
944 }
a61af66fc99e Initial load
duke
parents:
diff changeset
945
a61af66fc99e Initial load
duke
parents:
diff changeset
946 //------------------------------latency_from_use-------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
947 // Compute the latency of a specific use
a61af66fc99e Initial load
duke
parents:
diff changeset
948 int PhaseCFG::latency_from_use(Node *n, const Node *def, Node *use) {
a61af66fc99e Initial load
duke
parents:
diff changeset
949 // If self-reference, return no latency
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
950 if (use == n || use->is_Root()) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
951 return 0;
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
952 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
953
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
954 uint def_pre_order = get_block_for_node(def)->_pre_order;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
955 uint latency = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
956
a61af66fc99e Initial load
duke
parents:
diff changeset
957 // If the use is not a projection, then it is simple...
a61af66fc99e Initial load
duke
parents:
diff changeset
958 if (!use->is_Proj()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
959 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
960 if (trace_opto_pipelining()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
961 tty->print("# out(): ");
a61af66fc99e Initial load
duke
parents:
diff changeset
962 use->dump();
a61af66fc99e Initial load
duke
parents:
diff changeset
963 }
a61af66fc99e Initial load
duke
parents:
diff changeset
964 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
965
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
966 uint use_pre_order = get_block_for_node(use)->_pre_order;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
967
a61af66fc99e Initial load
duke
parents:
diff changeset
968 if (use_pre_order < def_pre_order)
a61af66fc99e Initial load
duke
parents:
diff changeset
969 return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
970
a61af66fc99e Initial load
duke
parents:
diff changeset
971 if (use_pre_order == def_pre_order && use->is_Phi())
a61af66fc99e Initial load
duke
parents:
diff changeset
972 return 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
973
a61af66fc99e Initial load
duke
parents:
diff changeset
974 uint nlen = use->len();
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
975 uint nl = get_latency_for_node(use);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
976
a61af66fc99e Initial load
duke
parents:
diff changeset
977 for ( uint j=0; j<nlen; j++ ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
978 if (use->in(j) == n) {
a61af66fc99e Initial load
duke
parents:
diff changeset
979 // Change this if we want local latencies
a61af66fc99e Initial load
duke
parents:
diff changeset
980 uint ul = use->latency(j);
a61af66fc99e Initial load
duke
parents:
diff changeset
981 uint l = ul + nl;
a61af66fc99e Initial load
duke
parents:
diff changeset
982 if (latency < l) latency = l;
a61af66fc99e Initial load
duke
parents:
diff changeset
983 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
984 if (trace_opto_pipelining()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
985 tty->print_cr("# %d + edge_latency(%d) == %d -> %d, latency = %d",
a61af66fc99e Initial load
duke
parents:
diff changeset
986 nl, j, ul, l, latency);
a61af66fc99e Initial load
duke
parents:
diff changeset
987 }
a61af66fc99e Initial load
duke
parents:
diff changeset
988 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
989 }
a61af66fc99e Initial load
duke
parents:
diff changeset
990 }
a61af66fc99e Initial load
duke
parents:
diff changeset
991 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
992 // This is a projection, just grab the latency of the use(s)
a61af66fc99e Initial load
duke
parents:
diff changeset
993 for (DUIterator_Fast jmax, j = use->fast_outs(jmax); j < jmax; j++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
994 uint l = latency_from_use(use, def, use->fast_out(j));
a61af66fc99e Initial load
duke
parents:
diff changeset
995 if (latency < l) latency = l;
a61af66fc99e Initial load
duke
parents:
diff changeset
996 }
a61af66fc99e Initial load
duke
parents:
diff changeset
997 }
a61af66fc99e Initial load
duke
parents:
diff changeset
998
a61af66fc99e Initial load
duke
parents:
diff changeset
999 return latency;
a61af66fc99e Initial load
duke
parents:
diff changeset
1000 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1001
a61af66fc99e Initial load
duke
parents:
diff changeset
1002 //------------------------------latency_from_uses------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1003 // Compute the latency of this instruction relative to all of it's uses.
a61af66fc99e Initial load
duke
parents:
diff changeset
1004 // This computes a number that increases as we approach the beginning of the
a61af66fc99e Initial load
duke
parents:
diff changeset
1005 // routine.
a61af66fc99e Initial load
duke
parents:
diff changeset
1006 void PhaseCFG::latency_from_uses(Node *n) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1007 // Set the latency for this instruction
a61af66fc99e Initial load
duke
parents:
diff changeset
1008 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
1009 if (trace_opto_pipelining()) {
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1010 tty->print("# latency_from_outputs: node_latency[%d] = %d for node", n->_idx, get_latency_for_node(n));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1011 dump();
a61af66fc99e Initial load
duke
parents:
diff changeset
1012 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1013 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
1014 uint latency=0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1015 const Node *def = n->is_Proj() ? n->in(0): n;
a61af66fc99e Initial load
duke
parents:
diff changeset
1016
a61af66fc99e Initial load
duke
parents:
diff changeset
1017 for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1018 uint l = latency_from_use(n, def, n->fast_out(i));
a61af66fc99e Initial load
duke
parents:
diff changeset
1019
a61af66fc99e Initial load
duke
parents:
diff changeset
1020 if (latency < l) latency = l;
a61af66fc99e Initial load
duke
parents:
diff changeset
1021 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1022
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1023 set_latency_for_node(n, latency);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1024 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1025
a61af66fc99e Initial load
duke
parents:
diff changeset
1026 //------------------------------hoist_to_cheaper_block-------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1027 // Pick a block for node self, between early and LCA, that is a cheaper
a61af66fc99e Initial load
duke
parents:
diff changeset
1028 // alternative to LCA.
a61af66fc99e Initial load
duke
parents:
diff changeset
1029 Block* PhaseCFG::hoist_to_cheaper_block(Block* LCA, Block* early, Node* self) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1030 const double delta = 1+PROB_UNLIKELY_MAG(4);
a61af66fc99e Initial load
duke
parents:
diff changeset
1031 Block* least = LCA;
a61af66fc99e Initial load
duke
parents:
diff changeset
1032 double least_freq = least->_freq;
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1033 uint target = get_latency_for_node(self);
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1034 uint start_latency = get_latency_for_node(LCA->_nodes[0]);
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1035 uint end_latency = get_latency_for_node(LCA->_nodes[LCA->end_idx()]);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1036 bool in_latency = (target <= start_latency);
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
1037 const Block* root_block = get_block_for_node(_root);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1038
a61af66fc99e Initial load
duke
parents:
diff changeset
1039 // Turn off latency scheduling if scheduling is just plain off
a61af66fc99e Initial load
duke
parents:
diff changeset
1040 if (!C->do_scheduling())
a61af66fc99e Initial load
duke
parents:
diff changeset
1041 in_latency = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1042
a61af66fc99e Initial load
duke
parents:
diff changeset
1043 // Do not hoist (to cover latency) instructions which target a
a61af66fc99e Initial load
duke
parents:
diff changeset
1044 // single register. Hoisting stretches the live range of the
a61af66fc99e Initial load
duke
parents:
diff changeset
1045 // single register and may force spilling.
a61af66fc99e Initial load
duke
parents:
diff changeset
1046 MachNode* mach = self->is_Mach() ? self->as_Mach() : NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1047 if (mach && mach->out_RegMask().is_bound1() && mach->out_RegMask().is_NotEmpty())
a61af66fc99e Initial load
duke
parents:
diff changeset
1048 in_latency = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1049
a61af66fc99e Initial load
duke
parents:
diff changeset
1050 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
1051 if (trace_opto_pipelining()) {
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1052 tty->print("# Find cheaper block for latency %d: ", get_latency_for_node(self));
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1053 self->dump();
a61af66fc99e Initial load
duke
parents:
diff changeset
1054 tty->print_cr("# B%d: start latency for [%4d]=%d, end latency for [%4d]=%d, freq=%g",
a61af66fc99e Initial load
duke
parents:
diff changeset
1055 LCA->_pre_order,
a61af66fc99e Initial load
duke
parents:
diff changeset
1056 LCA->_nodes[0]->_idx,
a61af66fc99e Initial load
duke
parents:
diff changeset
1057 start_latency,
a61af66fc99e Initial load
duke
parents:
diff changeset
1058 LCA->_nodes[LCA->end_idx()]->_idx,
a61af66fc99e Initial load
duke
parents:
diff changeset
1059 end_latency,
a61af66fc99e Initial load
duke
parents:
diff changeset
1060 least_freq);
a61af66fc99e Initial load
duke
parents:
diff changeset
1061 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1062 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
1063
8691
571076d3c79d 8009120: Fuzz instruction scheduling in HotSpot compilers
shade
parents: 7196
diff changeset
1064 int cand_cnt = 0; // number of candidates tried
571076d3c79d 8009120: Fuzz instruction scheduling in HotSpot compilers
shade
parents: 7196
diff changeset
1065
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1066 // Walk up the dominator tree from LCA (Lowest common ancestor) to
a61af66fc99e Initial load
duke
parents:
diff changeset
1067 // the earliest legal location. Capture the least execution frequency.
a61af66fc99e Initial load
duke
parents:
diff changeset
1068 while (LCA != early) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1069 LCA = LCA->_idom; // Follow up the dominator tree
a61af66fc99e Initial load
duke
parents:
diff changeset
1070
a61af66fc99e Initial load
duke
parents:
diff changeset
1071 if (LCA == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1072 // Bailout without retry
a61af66fc99e Initial load
duke
parents:
diff changeset
1073 C->record_method_not_compilable("late schedule failed: LCA == NULL");
a61af66fc99e Initial load
duke
parents:
diff changeset
1074 return least;
a61af66fc99e Initial load
duke
parents:
diff changeset
1075 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1076
a61af66fc99e Initial load
duke
parents:
diff changeset
1077 // Don't hoist machine instructions to the root basic block
a61af66fc99e Initial load
duke
parents:
diff changeset
1078 if (mach && LCA == root_block)
a61af66fc99e Initial load
duke
parents:
diff changeset
1079 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1080
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1081 uint start_lat = get_latency_for_node(LCA->_nodes[0]);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1082 uint end_idx = LCA->end_idx();
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1083 uint end_lat = get_latency_for_node(LCA->_nodes[end_idx]);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1084 double LCA_freq = LCA->_freq;
a61af66fc99e Initial load
duke
parents:
diff changeset
1085 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
1086 if (trace_opto_pipelining()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1087 tty->print_cr("# B%d: start latency for [%4d]=%d, end latency for [%4d]=%d, freq=%g",
a61af66fc99e Initial load
duke
parents:
diff changeset
1088 LCA->_pre_order, LCA->_nodes[0]->_idx, start_lat, end_idx, end_lat, LCA_freq);
a61af66fc99e Initial load
duke
parents:
diff changeset
1089 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1090 #endif
8691
571076d3c79d 8009120: Fuzz instruction scheduling in HotSpot compilers
shade
parents: 7196
diff changeset
1091 cand_cnt++;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1092 if (LCA_freq < least_freq || // Better Frequency
8691
571076d3c79d 8009120: Fuzz instruction scheduling in HotSpot compilers
shade
parents: 7196
diff changeset
1093 (StressGCM && Compile::randomized_select(cand_cnt)) || // Should be randomly accepted in stress mode
571076d3c79d 8009120: Fuzz instruction scheduling in HotSpot compilers
shade
parents: 7196
diff changeset
1094 (!StressGCM && // Otherwise, choose with latency
571076d3c79d 8009120: Fuzz instruction scheduling in HotSpot compilers
shade
parents: 7196
diff changeset
1095 !in_latency && // No block containing latency
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1096 LCA_freq < least_freq * delta && // No worse frequency
a61af66fc99e Initial load
duke
parents:
diff changeset
1097 target >= end_lat && // within latency range
a61af66fc99e Initial load
duke
parents:
diff changeset
1098 !self->is_iteratively_computed() ) // But don't hoist IV increments
a61af66fc99e Initial load
duke
parents:
diff changeset
1099 // because they may end up above other uses of their phi forcing
a61af66fc99e Initial load
duke
parents:
diff changeset
1100 // their result register to be different from their input.
a61af66fc99e Initial load
duke
parents:
diff changeset
1101 ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1102 least = LCA; // Found cheaper block
a61af66fc99e Initial load
duke
parents:
diff changeset
1103 least_freq = LCA_freq;
a61af66fc99e Initial load
duke
parents:
diff changeset
1104 start_latency = start_lat;
a61af66fc99e Initial load
duke
parents:
diff changeset
1105 end_latency = end_lat;
a61af66fc99e Initial load
duke
parents:
diff changeset
1106 if (target <= start_lat)
a61af66fc99e Initial load
duke
parents:
diff changeset
1107 in_latency = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1108 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1109 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1110
a61af66fc99e Initial load
duke
parents:
diff changeset
1111 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
1112 if (trace_opto_pipelining()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1113 tty->print_cr("# Choose block B%d with start latency=%d and freq=%g",
a61af66fc99e Initial load
duke
parents:
diff changeset
1114 least->_pre_order, start_latency, least_freq);
a61af66fc99e Initial load
duke
parents:
diff changeset
1115 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1116 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
1117
a61af66fc99e Initial load
duke
parents:
diff changeset
1118 // See if the latency needs to be updated
a61af66fc99e Initial load
duke
parents:
diff changeset
1119 if (target < end_latency) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1120 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
1121 if (trace_opto_pipelining()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1122 tty->print_cr("# Change latency for [%4d] from %d to %d", self->_idx, target, end_latency);
a61af66fc99e Initial load
duke
parents:
diff changeset
1123 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1124 #endif
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1125 set_latency_for_node(self, end_latency);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1126 partial_latency_of_defs(self);
a61af66fc99e Initial load
duke
parents:
diff changeset
1127 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1128
a61af66fc99e Initial load
duke
parents:
diff changeset
1129 return least;
a61af66fc99e Initial load
duke
parents:
diff changeset
1130 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1131
a61af66fc99e Initial load
duke
parents:
diff changeset
1132
a61af66fc99e Initial load
duke
parents:
diff changeset
1133 //------------------------------schedule_late-----------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1134 // Now schedule all codes as LATE as possible. This is the LCA in the
a61af66fc99e Initial load
duke
parents:
diff changeset
1135 // dominator tree of all USES of a value. Pick the block with the least
a61af66fc99e Initial load
duke
parents:
diff changeset
1136 // loop nesting depth that is lowest in the dominator tree.
a61af66fc99e Initial load
duke
parents:
diff changeset
1137 extern const char must_clone[];
a61af66fc99e Initial load
duke
parents:
diff changeset
1138 void PhaseCFG::schedule_late(VectorSet &visited, Node_List &stack) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1139 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
1140 if (trace_opto_pipelining())
a61af66fc99e Initial load
duke
parents:
diff changeset
1141 tty->print("\n#---- schedule_late ----\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1142 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
1143
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
1144 Node_Backward_Iterator iter((Node *)_root, visited, stack, *this);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1145 Node *self;
a61af66fc99e Initial load
duke
parents:
diff changeset
1146
a61af66fc99e Initial load
duke
parents:
diff changeset
1147 // Walk over all the nodes from last to first
a61af66fc99e Initial load
duke
parents:
diff changeset
1148 while (self = iter.next()) {
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
1149 Block* early = get_block_for_node(self); // Earliest legal placement
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1150
a61af66fc99e Initial load
duke
parents:
diff changeset
1151 if (self->is_top()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1152 // Top node goes in bb #2 with other constants.
a61af66fc99e Initial load
duke
parents:
diff changeset
1153 // It must be special-cased, because it has no out edges.
a61af66fc99e Initial load
duke
parents:
diff changeset
1154 early->add_inst(self);
a61af66fc99e Initial load
duke
parents:
diff changeset
1155 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
1156 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1157
a61af66fc99e Initial load
duke
parents:
diff changeset
1158 // No uses, just terminate
a61af66fc99e Initial load
duke
parents:
diff changeset
1159 if (self->outcnt() == 0) {
3842
c7b60b601eb4 7069452: Cleanup NodeFlags
kvn
parents: 2426
diff changeset
1160 assert(self->is_MachProj(), "sanity");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1161 continue; // Must be a dead machine projection
a61af66fc99e Initial load
duke
parents:
diff changeset
1162 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1163
a61af66fc99e Initial load
duke
parents:
diff changeset
1164 // If node is pinned in the block, then no scheduling can be done.
a61af66fc99e Initial load
duke
parents:
diff changeset
1165 if( self->pinned() ) // Pinned in block?
a61af66fc99e Initial load
duke
parents:
diff changeset
1166 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
1167
a61af66fc99e Initial load
duke
parents:
diff changeset
1168 MachNode* mach = self->is_Mach() ? self->as_Mach() : NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1169 if (mach) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1170 switch (mach->ideal_Opcode()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1171 case Op_CreateEx:
a61af66fc99e Initial load
duke
parents:
diff changeset
1172 // Don't move exception creation
a61af66fc99e Initial load
duke
parents:
diff changeset
1173 early->add_inst(self);
a61af66fc99e Initial load
duke
parents:
diff changeset
1174 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
1175 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1176 case Op_CheckCastPP:
a61af66fc99e Initial load
duke
parents:
diff changeset
1177 // Don't move CheckCastPP nodes away from their input, if the input
a61af66fc99e Initial load
duke
parents:
diff changeset
1178 // is a rawptr (5071820).
a61af66fc99e Initial load
duke
parents:
diff changeset
1179 Node *def = self->in(1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1180 if (def != NULL && def->bottom_type()->base() == Type::RawPtr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1181 early->add_inst(self);
833
acba6af809c8 6840775: Multiple JVM crashes seen with 1.6.0_10 through 1.6.0_14
kvn
parents: 788
diff changeset
1182 #ifdef ASSERT
acba6af809c8 6840775: Multiple JVM crashes seen with 1.6.0_10 through 1.6.0_14
kvn
parents: 788
diff changeset
1183 _raw_oops.push(def);
acba6af809c8 6840775: Multiple JVM crashes seen with 1.6.0_10 through 1.6.0_14
kvn
parents: 788
diff changeset
1184 #endif
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1185 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
1186 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1187 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
1188 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1189 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1190
a61af66fc99e Initial load
duke
parents:
diff changeset
1191 // Gather LCA of all uses
a61af66fc99e Initial load
duke
parents:
diff changeset
1192 Block *LCA = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1193 {
a61af66fc99e Initial load
duke
parents:
diff changeset
1194 for (DUIterator_Fast imax, i = self->fast_outs(imax); i < imax; i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1195 // For all uses, find LCA
a61af66fc99e Initial load
duke
parents:
diff changeset
1196 Node* use = self->fast_out(i);
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
1197 LCA = raise_LCA_above_use(LCA, use, self, this);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1198 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1199 } // (Hide defs of imax, i from rest of block.)
a61af66fc99e Initial load
duke
parents:
diff changeset
1200
a61af66fc99e Initial load
duke
parents:
diff changeset
1201 // Place temps in the block of their use. This isn't a
a61af66fc99e Initial load
duke
parents:
diff changeset
1202 // requirement for correctness but it reduces useless
a61af66fc99e Initial load
duke
parents:
diff changeset
1203 // interference between temps and other nodes.
a61af66fc99e Initial load
duke
parents:
diff changeset
1204 if (mach != NULL && mach->is_MachTemp()) {
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
1205 map_node_to_block(self, LCA);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1206 LCA->add_inst(self);
a61af66fc99e Initial load
duke
parents:
diff changeset
1207 continue;
a61af66fc99e Initial load
duke
parents:
diff changeset
1208 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1209
a61af66fc99e Initial load
duke
parents:
diff changeset
1210 // Check if 'self' could be anti-dependent on memory
a61af66fc99e Initial load
duke
parents:
diff changeset
1211 if (self->needs_anti_dependence_check()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1212 // Hoist LCA above possible-defs and insert anti-dependences to
a61af66fc99e Initial load
duke
parents:
diff changeset
1213 // defs in new LCA block.
a61af66fc99e Initial load
duke
parents:
diff changeset
1214 LCA = insert_anti_dependences(LCA, self);
a61af66fc99e Initial load
duke
parents:
diff changeset
1215 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1216
a61af66fc99e Initial load
duke
parents:
diff changeset
1217 if (early->_dom_depth > LCA->_dom_depth) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1218 // Somehow the LCA has moved above the earliest legal point.
a61af66fc99e Initial load
duke
parents:
diff changeset
1219 // (One way this can happen is via memory_early_block.)
a61af66fc99e Initial load
duke
parents:
diff changeset
1220 if (C->subsume_loads() == true && !C->failing()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1221 // Retry with subsume_loads == false
a61af66fc99e Initial load
duke
parents:
diff changeset
1222 // If this is the first failure, the sentinel string will "stick"
a61af66fc99e Initial load
duke
parents:
diff changeset
1223 // to the Compile object, and the C2Compiler will see it and retry.
a61af66fc99e Initial load
duke
parents:
diff changeset
1224 C->record_failure(C2Compiler::retry_no_subsuming_loads());
a61af66fc99e Initial load
duke
parents:
diff changeset
1225 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1226 // Bailout without retry when (early->_dom_depth > LCA->_dom_depth)
a61af66fc99e Initial load
duke
parents:
diff changeset
1227 C->record_method_not_compilable("late schedule failed: incorrect graph");
a61af66fc99e Initial load
duke
parents:
diff changeset
1228 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1229 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1230 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1231
a61af66fc99e Initial load
duke
parents:
diff changeset
1232 // If there is no opportunity to hoist, then we're done.
8691
571076d3c79d 8009120: Fuzz instruction scheduling in HotSpot compilers
shade
parents: 7196
diff changeset
1233 // In stress mode, try to hoist even the single operations.
571076d3c79d 8009120: Fuzz instruction scheduling in HotSpot compilers
shade
parents: 7196
diff changeset
1234 bool try_to_hoist = StressGCM || (LCA != early);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1235
a61af66fc99e Initial load
duke
parents:
diff changeset
1236 // Must clone guys stay next to use; no hoisting allowed.
a61af66fc99e Initial load
duke
parents:
diff changeset
1237 // Also cannot hoist guys that alter memory or are otherwise not
a61af66fc99e Initial load
duke
parents:
diff changeset
1238 // allocatable (hoisting can make a value live longer, leading to
a61af66fc99e Initial load
duke
parents:
diff changeset
1239 // anti and output dependency problems which are normally resolved
a61af66fc99e Initial load
duke
parents:
diff changeset
1240 // by the register allocator giving everyone a different register).
a61af66fc99e Initial load
duke
parents:
diff changeset
1241 if (mach != NULL && must_clone[mach->ideal_Opcode()])
a61af66fc99e Initial load
duke
parents:
diff changeset
1242 try_to_hoist = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
1243
a61af66fc99e Initial load
duke
parents:
diff changeset
1244 Block* late = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
1245 if (try_to_hoist) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1246 // Now find the block with the least execution frequency.
a61af66fc99e Initial load
duke
parents:
diff changeset
1247 // Start at the latest schedule and work up to the earliest schedule
a61af66fc99e Initial load
duke
parents:
diff changeset
1248 // in the dominator tree. Thus the Node will dominate all its uses.
a61af66fc99e Initial load
duke
parents:
diff changeset
1249 late = hoist_to_cheaper_block(LCA, early, self);
a61af66fc99e Initial load
duke
parents:
diff changeset
1250 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1251 // Just use the LCA of the uses.
a61af66fc99e Initial load
duke
parents:
diff changeset
1252 late = LCA;
a61af66fc99e Initial load
duke
parents:
diff changeset
1253 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1254
a61af66fc99e Initial load
duke
parents:
diff changeset
1255 // Put the node into target block
a61af66fc99e Initial load
duke
parents:
diff changeset
1256 schedule_node_into_block(self, late);
a61af66fc99e Initial load
duke
parents:
diff changeset
1257
a61af66fc99e Initial load
duke
parents:
diff changeset
1258 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
1259 if (self->needs_anti_dependence_check()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1260 // since precedence edges are only inserted when we're sure they
a61af66fc99e Initial load
duke
parents:
diff changeset
1261 // are needed make sure that after placement in a block we don't
a61af66fc99e Initial load
duke
parents:
diff changeset
1262 // need any new precedence edges.
a61af66fc99e Initial load
duke
parents:
diff changeset
1263 verify_anti_dependences(late, self);
a61af66fc99e Initial load
duke
parents:
diff changeset
1264 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1265 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
1266 } // Loop until all nodes have been visited
a61af66fc99e Initial load
duke
parents:
diff changeset
1267
a61af66fc99e Initial load
duke
parents:
diff changeset
1268 } // end ScheduleLate
a61af66fc99e Initial load
duke
parents:
diff changeset
1269
a61af66fc99e Initial load
duke
parents:
diff changeset
1270 //------------------------------GlobalCodeMotion-------------------------------
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1271 void PhaseCFG::global_code_motion() {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1272 ResourceMark rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
1273
a61af66fc99e Initial load
duke
parents:
diff changeset
1274 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
1275 if (trace_opto_pipelining()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1276 tty->print("\n---- Start GlobalCodeMotion ----\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1277 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1278 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
1279
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
1280 // Initialize the node to block mapping for things on the proj_list
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1281 for (uint i = 0; i < _matcher.number_of_projections(); i++) {
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1282 unmap_node_from_block(_matcher.get_projection(i));
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
1283 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1284
a61af66fc99e Initial load
duke
parents:
diff changeset
1285 // Set the basic block for Nodes pinned into blocks
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1286 Arena* arena = Thread::current()->resource_area();
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1287 VectorSet visited(arena);
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1288 schedule_pinned_nodes(visited);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1289
a61af66fc99e Initial load
duke
parents:
diff changeset
1290 // Find the earliest Block any instruction can be placed in. Some
a61af66fc99e Initial load
duke
parents:
diff changeset
1291 // instructions are pinned into Blocks. Unpinned instructions can
a61af66fc99e Initial load
duke
parents:
diff changeset
1292 // appear in last block in which all their inputs occur.
a61af66fc99e Initial load
duke
parents:
diff changeset
1293 visited.Clear();
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1294 Node_List stack(arena);
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1295 // Pre-grow the list
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1296 stack.map((C->unique() >> 1) + 16, NULL);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1297 if (!schedule_early(visited, stack)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1298 // Bailout without retry
a61af66fc99e Initial load
duke
parents:
diff changeset
1299 C->record_method_not_compilable("early schedule failed");
a61af66fc99e Initial load
duke
parents:
diff changeset
1300 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1301 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1302
a61af66fc99e Initial load
duke
parents:
diff changeset
1303 // Build Def-Use edges.
a61af66fc99e Initial load
duke
parents:
diff changeset
1304 // Compute the latency information (via backwards walk) for all the
a61af66fc99e Initial load
duke
parents:
diff changeset
1305 // instructions in the graph
1685
0e35fa8ebccd 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 1552
diff changeset
1306 _node_latency = new GrowableArray<uint>(); // resource_area allocation
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1307
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1308 if (C->do_scheduling()) {
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1309 compute_latencies_backwards(visited, stack);
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1310 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1311
a61af66fc99e Initial load
duke
parents:
diff changeset
1312 // Now schedule all codes as LATE as possible. This is the LCA in the
a61af66fc99e Initial load
duke
parents:
diff changeset
1313 // dominator tree of all USES of a value. Pick the block with the least
a61af66fc99e Initial load
duke
parents:
diff changeset
1314 // loop nesting depth that is lowest in the dominator tree.
a61af66fc99e Initial load
duke
parents:
diff changeset
1315 // ( visited.Clear() called in schedule_late()->Node_Backward_Iterator() )
a61af66fc99e Initial load
duke
parents:
diff changeset
1316 schedule_late(visited, stack);
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1317 if (C->failing()) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1318 // schedule_late fails only when graph is incorrect.
a61af66fc99e Initial load
duke
parents:
diff changeset
1319 assert(!VerifyGraphEdges, "verification should have failed");
a61af66fc99e Initial load
duke
parents:
diff changeset
1320 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1321 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1322
a61af66fc99e Initial load
duke
parents:
diff changeset
1323 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
1324 if (trace_opto_pipelining()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1325 tty->print("\n---- Detect implicit null checks ----\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1326 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1327 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
1328
a61af66fc99e Initial load
duke
parents:
diff changeset
1329 // Detect implicit-null-check opportunities. Basically, find NULL checks
a61af66fc99e Initial load
duke
parents:
diff changeset
1330 // with suitable memory ops nearby. Use the memory op to do the NULL check.
a61af66fc99e Initial load
duke
parents:
diff changeset
1331 // I can generate a memory op if there is not one nearby.
a61af66fc99e Initial load
duke
parents:
diff changeset
1332 if (C->is_method_compilation()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1333 // Don't do it for natives, adapters, or runtime stubs
a61af66fc99e Initial load
duke
parents:
diff changeset
1334 int allowed_reasons = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1335 // ...and don't do it when there have been too many traps, globally.
a61af66fc99e Initial load
duke
parents:
diff changeset
1336 for (int reason = (int)Deoptimization::Reason_none+1;
a61af66fc99e Initial load
duke
parents:
diff changeset
1337 reason < Compile::trapHistLength; reason++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1338 assert(reason < BitsPerInt, "recode bit map");
a61af66fc99e Initial load
duke
parents:
diff changeset
1339 if (!C->too_many_traps((Deoptimization::DeoptReason) reason))
a61af66fc99e Initial load
duke
parents:
diff changeset
1340 allowed_reasons |= nth_bit(reason);
a61af66fc99e Initial load
duke
parents:
diff changeset
1341 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1342 // By reversing the loop direction we get a very minor gain on mpegaudio.
a61af66fc99e Initial load
duke
parents:
diff changeset
1343 // Feel free to revert to a forward loop for clarity.
a61af66fc99e Initial load
duke
parents:
diff changeset
1344 // for( int i=0; i < (int)matcher._null_check_tests.size(); i+=2 ) {
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1345 for (int i = _matcher._null_check_tests.size() - 2; i >= 0; i -= 2) {
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1346 Node* proj = _matcher._null_check_tests[i];
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1347 Node* val = _matcher._null_check_tests[i + 1];
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1348 Block* block = get_block_for_node(proj);
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1349 block->implicit_null_check(this, proj, val, allowed_reasons);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1350 // The implicit_null_check will only perform the transformation
a61af66fc99e Initial load
duke
parents:
diff changeset
1351 // if the null branch is truly uncommon, *and* it leads to an
a61af66fc99e Initial load
duke
parents:
diff changeset
1352 // uncommon trap. Combined with the too_many_traps guards
a61af66fc99e Initial load
duke
parents:
diff changeset
1353 // above, this prevents SEGV storms reported in 6366351,
a61af66fc99e Initial load
duke
parents:
diff changeset
1354 // by recompiling offending methods without this optimization.
a61af66fc99e Initial load
duke
parents:
diff changeset
1355 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1356 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1357
a61af66fc99e Initial load
duke
parents:
diff changeset
1358 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
1359 if (trace_opto_pipelining()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1360 tty->print("\n---- Start Local Scheduling ----\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
1361 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1362 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
1363
a61af66fc99e Initial load
duke
parents:
diff changeset
1364 // Schedule locally. Right now a simple topological sort.
a61af66fc99e Initial load
duke
parents:
diff changeset
1365 // Later, do a real latency aware scheduler.
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1366 GrowableArray<int> ready_cnt(C->unique(), C->unique(), -1);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1367 visited.Clear();
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1368 for (uint i = 0; i < number_of_blocks(); i++) {
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1369 Block* block = get_block(i);
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1370 if (!block->schedule_local(this, _matcher, ready_cnt, visited)) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1371 if (!C->failure_reason_is(C2Compiler::retry_no_subsuming_loads())) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1372 C->record_method_not_compilable("local schedule failed");
a61af66fc99e Initial load
duke
parents:
diff changeset
1373 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1374 return;
a61af66fc99e Initial load
duke
parents:
diff changeset
1375 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1376 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1377
a61af66fc99e Initial load
duke
parents:
diff changeset
1378 // If we inserted any instructions between a Call and his CatchNode,
a61af66fc99e Initial load
duke
parents:
diff changeset
1379 // clone the instructions on all paths below the Catch.
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1380 for (uint i = 0; i < number_of_blocks(); i++) {
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1381 Block* block = get_block(i);
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1382 block->call_catch_cleanup(this, C);
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
1383 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1384
a61af66fc99e Initial load
duke
parents:
diff changeset
1385 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
1386 if (trace_opto_pipelining()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1387 tty->print("\n---- After GlobalCodeMotion ----\n");
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1388 for (uint i = 0; i < number_of_blocks(); i++) {
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1389 Block* block = get_block(i);
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1390 block->dump();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1391 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1392 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1393 #endif
1685
0e35fa8ebccd 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 1552
diff changeset
1394 // Dead.
0e35fa8ebccd 6973963: SEGV in ciBlock::start_bci() with EA
kvn
parents: 1552
diff changeset
1395 _node_latency = (GrowableArray<uint> *)0xdeadbeef;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1396 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1397
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1398 bool PhaseCFG::do_global_code_motion() {
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1399
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1400 build_dominator_tree();
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1401 if (C->failing()) {
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1402 return false;
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1403 }
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1404
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1405 NOT_PRODUCT( C->verify_graph_edges(); )
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1406
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1407 estimate_block_frequency();
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1408
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1409 global_code_motion();
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1410
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1411 if (C->failing()) {
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1412 return false;
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1413 }
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1414
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1415 return true;
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1416 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1417
a61af66fc99e Initial load
duke
parents:
diff changeset
1418 //------------------------------Estimate_Block_Frequency-----------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1419 // Estimate block frequencies based on IfNode probabilities.
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1420 void PhaseCFG::estimate_block_frequency() {
418
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1421
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1422 // Force conditional branches leading to uncommon traps to be unlikely,
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1423 // not because we get to the uncommon_trap with less relative frequency,
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1424 // but because an uncommon_trap typically causes a deopt, so we only get
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1425 // there once.
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1426 if (C->do_freq_based_layout()) {
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1427 Block_List worklist;
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1428 Block* root_blk = get_block(0);
418
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1429 for (uint i = 1; i < root_blk->num_preds(); i++) {
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
1430 Block *pb = get_block_for_node(root_blk->pred(i));
418
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1431 if (pb->has_uncommon_code()) {
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1432 worklist.push(pb);
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1433 }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1434 }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1435 while (worklist.size() > 0) {
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1436 Block* uct = worklist.pop();
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1437 if (uct == get_root_block()) {
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1438 continue;
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1439 }
418
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1440 for (uint i = 1; i < uct->num_preds(); i++) {
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
1441 Block *pb = get_block_for_node(uct->pred(i));
418
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1442 if (pb->_num_succs == 1) {
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1443 worklist.push(pb);
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1444 } else if (pb->num_fall_throughs() == 2) {
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1445 pb->update_uncommon_branch(uct);
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1446 }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1447 }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1448 }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1449 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1450
a61af66fc99e Initial load
duke
parents:
diff changeset
1451 // Create the loop tree and calculate loop depth.
a61af66fc99e Initial load
duke
parents:
diff changeset
1452 _root_loop = create_loop_tree();
a61af66fc99e Initial load
duke
parents:
diff changeset
1453 _root_loop->compute_loop_depth(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
1454
a61af66fc99e Initial load
duke
parents:
diff changeset
1455 // Compute block frequency of each block, relative to a single loop entry.
a61af66fc99e Initial load
duke
parents:
diff changeset
1456 _root_loop->compute_freq();
a61af66fc99e Initial load
duke
parents:
diff changeset
1457
a61af66fc99e Initial load
duke
parents:
diff changeset
1458 // Adjust all frequencies to be relative to a single method entry
418
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1459 _root_loop->_freq = 1.0;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1460 _root_loop->scale_freq();
a61af66fc99e Initial load
duke
parents:
diff changeset
1461
673
fbc12e71c476 6810845: Performance regression in mpegaudio on x64
kvn
parents: 628
diff changeset
1462 // Save outmost loop frequency for LRG frequency threshold
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1463 _outer_loop_frequency = _root_loop->outer_loop_freq();
673
fbc12e71c476 6810845: Performance regression in mpegaudio on x64
kvn
parents: 628
diff changeset
1464
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1465 // force paths ending at uncommon traps to be infrequent
418
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1466 if (!C->do_freq_based_layout()) {
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1467 Block_List worklist;
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1468 Block* root_blk = get_block(0);
418
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1469 for (uint i = 1; i < root_blk->num_preds(); i++) {
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
1470 Block *pb = get_block_for_node(root_blk->pred(i));
418
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1471 if (pb->has_uncommon_code()) {
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1472 worklist.push(pb);
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1473 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1474 }
418
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1475 while (worklist.size() > 0) {
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1476 Block* uct = worklist.pop();
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1477 uct->_freq = PROB_MIN;
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1478 for (uint i = 1; i < uct->num_preds(); i++) {
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
1479 Block *pb = get_block_for_node(uct->pred(i));
418
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1480 if (pb->_num_succs == 1 && pb->_freq > PROB_MIN) {
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1481 worklist.push(pb);
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1482 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1483 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1484 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1485 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1486
552
011517bbcd7b 6784930: server jvm fails with assert(!n->is_SpillCopy(),"")
kvn
parents: 418
diff changeset
1487 #ifdef ASSERT
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1488 for (uint i = 0; i < number_of_blocks(); i++) {
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1489 Block* b = get_block(i);
605
98cb887364d3 6810672: Comment typos
twisti
parents: 601
diff changeset
1490 assert(b->_freq >= MIN_BLOCK_FREQUENCY, "Register Allocator requires meaningful block frequency");
552
011517bbcd7b 6784930: server jvm fails with assert(!n->is_SpillCopy(),"")
kvn
parents: 418
diff changeset
1491 }
011517bbcd7b 6784930: server jvm fails with assert(!n->is_SpillCopy(),"")
kvn
parents: 418
diff changeset
1492 #endif
011517bbcd7b 6784930: server jvm fails with assert(!n->is_SpillCopy(),"")
kvn
parents: 418
diff changeset
1493
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1494 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
1495 if (PrintCFGBlockFreq) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1496 tty->print_cr("CFG Block Frequencies");
a61af66fc99e Initial load
duke
parents:
diff changeset
1497 _root_loop->dump_tree();
a61af66fc99e Initial load
duke
parents:
diff changeset
1498 if (Verbose) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1499 tty->print_cr("PhaseCFG dump");
a61af66fc99e Initial load
duke
parents:
diff changeset
1500 dump();
a61af66fc99e Initial load
duke
parents:
diff changeset
1501 tty->print_cr("Node dump");
a61af66fc99e Initial load
duke
parents:
diff changeset
1502 _root->dump(99999);
a61af66fc99e Initial load
duke
parents:
diff changeset
1503 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1504 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1505 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
1506 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1507
a61af66fc99e Initial load
duke
parents:
diff changeset
1508 //----------------------------create_loop_tree--------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1509 // Create a loop tree from the CFG
a61af66fc99e Initial load
duke
parents:
diff changeset
1510 CFGLoop* PhaseCFG::create_loop_tree() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1511
a61af66fc99e Initial load
duke
parents:
diff changeset
1512 #ifdef ASSERT
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1513 assert(get_block(0) == get_root_block(), "first block should be root block");
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1514 for (uint i = 0; i < number_of_blocks(); i++) {
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1515 Block* block = get_block(i);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1516 // Check that _loop field are clear...we could clear them if not.
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1517 assert(block->_loop == NULL, "clear _loop expected");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1518 // Sanity check that the RPO numbering is reflected in the _blocks array.
a61af66fc99e Initial load
duke
parents:
diff changeset
1519 // It doesn't have to be for the loop tree to be built, but if it is not,
a61af66fc99e Initial load
duke
parents:
diff changeset
1520 // then the blocks have been reordered since dom graph building...which
a61af66fc99e Initial load
duke
parents:
diff changeset
1521 // may question the RPO numbering
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1522 assert(block->_rpo == i, "unexpected reverse post order number");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1523 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1524 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
1525
a61af66fc99e Initial load
duke
parents:
diff changeset
1526 int idct = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1527 CFGLoop* root_loop = new CFGLoop(idct++);
a61af66fc99e Initial load
duke
parents:
diff changeset
1528
a61af66fc99e Initial load
duke
parents:
diff changeset
1529 Block_List worklist;
a61af66fc99e Initial load
duke
parents:
diff changeset
1530
a61af66fc99e Initial load
duke
parents:
diff changeset
1531 // Assign blocks to loops
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1532 for(uint i = number_of_blocks() - 1; i > 0; i-- ) { // skip Root block
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1533 Block* block = get_block(i);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1534
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1535 if (block->head()->is_Loop()) {
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1536 Block* loop_head = block;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1537 assert(loop_head->num_preds() - 1 == 2, "loop must have 2 predecessors");
a61af66fc99e Initial load
duke
parents:
diff changeset
1538 Node* tail_n = loop_head->pred(LoopNode::LoopBackControl);
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
1539 Block* tail = get_block_for_node(tail_n);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1540
a61af66fc99e Initial load
duke
parents:
diff changeset
1541 // Defensively filter out Loop nodes for non-single-entry loops.
a61af66fc99e Initial load
duke
parents:
diff changeset
1542 // For all reasonable loops, the head occurs before the tail in RPO.
a61af66fc99e Initial load
duke
parents:
diff changeset
1543 if (i <= tail->_rpo) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1544
a61af66fc99e Initial load
duke
parents:
diff changeset
1545 // The tail and (recursive) predecessors of the tail
a61af66fc99e Initial load
duke
parents:
diff changeset
1546 // are made members of a new loop.
a61af66fc99e Initial load
duke
parents:
diff changeset
1547
a61af66fc99e Initial load
duke
parents:
diff changeset
1548 assert(worklist.size() == 0, "nonempty worklist");
a61af66fc99e Initial load
duke
parents:
diff changeset
1549 CFGLoop* nloop = new CFGLoop(idct++);
a61af66fc99e Initial load
duke
parents:
diff changeset
1550 assert(loop_head->_loop == NULL, "just checking");
a61af66fc99e Initial load
duke
parents:
diff changeset
1551 loop_head->_loop = nloop;
a61af66fc99e Initial load
duke
parents:
diff changeset
1552 // Add to nloop so push_pred() will skip over inner loops
a61af66fc99e Initial load
duke
parents:
diff changeset
1553 nloop->add_member(loop_head);
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
1554 nloop->push_pred(loop_head, LoopNode::LoopBackControl, worklist, this);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1555
a61af66fc99e Initial load
duke
parents:
diff changeset
1556 while (worklist.size() > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1557 Block* member = worklist.pop();
a61af66fc99e Initial load
duke
parents:
diff changeset
1558 if (member != loop_head) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1559 for (uint j = 1; j < member->num_preds(); j++) {
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
1560 nloop->push_pred(member, j, worklist, this);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1561 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1562 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1563 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1564 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1565 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1566 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1567
a61af66fc99e Initial load
duke
parents:
diff changeset
1568 // Create a member list for each loop consisting
a61af66fc99e Initial load
duke
parents:
diff changeset
1569 // of both blocks and (immediate child) loops.
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1570 for (uint i = 0; i < number_of_blocks(); i++) {
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1571 Block* block = get_block(i);
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1572 CFGLoop* lp = block->_loop;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1573 if (lp == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1574 // Not assigned to a loop. Add it to the method's pseudo loop.
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1575 block->_loop = root_loop;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1576 lp = root_loop;
a61af66fc99e Initial load
duke
parents:
diff changeset
1577 }
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1578 if (lp == root_loop || block != lp->head()) { // loop heads are already members
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1579 lp->add_member(block);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1580 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1581 if (lp != root_loop) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1582 if (lp->parent() == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1583 // Not a nested loop. Make it a child of the method's pseudo loop.
a61af66fc99e Initial load
duke
parents:
diff changeset
1584 root_loop->add_nested_loop(lp);
a61af66fc99e Initial load
duke
parents:
diff changeset
1585 }
12071
adb9a7d94cb5 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 12023
diff changeset
1586 if (block == lp->head()) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1587 // Add nested loop to member list of parent loop.
a61af66fc99e Initial load
duke
parents:
diff changeset
1588 lp->parent()->add_member(lp);
a61af66fc99e Initial load
duke
parents:
diff changeset
1589 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1590 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1591 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1592
a61af66fc99e Initial load
duke
parents:
diff changeset
1593 return root_loop;
a61af66fc99e Initial load
duke
parents:
diff changeset
1594 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1595
a61af66fc99e Initial load
duke
parents:
diff changeset
1596 //------------------------------push_pred--------------------------------------
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
1597 void CFGLoop::push_pred(Block* blk, int i, Block_List& worklist, PhaseCFG* cfg) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1598 Node* pred_n = blk->pred(i);
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
1599 Block* pred = cfg->get_block_for_node(pred_n);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1600 CFGLoop *pred_loop = pred->_loop;
a61af66fc99e Initial load
duke
parents:
diff changeset
1601 if (pred_loop == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1602 // Filter out blocks for non-single-entry loops.
a61af66fc99e Initial load
duke
parents:
diff changeset
1603 // For all reasonable loops, the head occurs before the tail in RPO.
a61af66fc99e Initial load
duke
parents:
diff changeset
1604 if (pred->_rpo > head()->_rpo) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1605 pred->_loop = this;
a61af66fc99e Initial load
duke
parents:
diff changeset
1606 worklist.push(pred);
a61af66fc99e Initial load
duke
parents:
diff changeset
1607 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1608 } else if (pred_loop != this) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1609 // Nested loop.
a61af66fc99e Initial load
duke
parents:
diff changeset
1610 while (pred_loop->_parent != NULL && pred_loop->_parent != this) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1611 pred_loop = pred_loop->_parent;
a61af66fc99e Initial load
duke
parents:
diff changeset
1612 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1613 // Make pred's loop be a child
a61af66fc99e Initial load
duke
parents:
diff changeset
1614 if (pred_loop->_parent == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1615 add_nested_loop(pred_loop);
a61af66fc99e Initial load
duke
parents:
diff changeset
1616 // Continue with loop entry predecessor.
a61af66fc99e Initial load
duke
parents:
diff changeset
1617 Block* pred_head = pred_loop->head();
a61af66fc99e Initial load
duke
parents:
diff changeset
1618 assert(pred_head->num_preds() - 1 == 2, "loop must have 2 predecessors");
a61af66fc99e Initial load
duke
parents:
diff changeset
1619 assert(pred_head != head(), "loop head in only one loop");
12023
d1034bd8cefc 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 8691
diff changeset
1620 push_pred(pred_head, LoopNode::EntryControl, worklist, cfg);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1621 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1622 assert(pred_loop->_parent == this && _parent == NULL, "just checking");
a61af66fc99e Initial load
duke
parents:
diff changeset
1623 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1624 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1625 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1626
a61af66fc99e Initial load
duke
parents:
diff changeset
1627 //------------------------------add_nested_loop--------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1628 // Make cl a child of the current loop in the loop tree.
a61af66fc99e Initial load
duke
parents:
diff changeset
1629 void CFGLoop::add_nested_loop(CFGLoop* cl) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1630 assert(_parent == NULL, "no parent yet");
a61af66fc99e Initial load
duke
parents:
diff changeset
1631 assert(cl != this, "not my own parent");
a61af66fc99e Initial load
duke
parents:
diff changeset
1632 cl->_parent = this;
a61af66fc99e Initial load
duke
parents:
diff changeset
1633 CFGLoop* ch = _child;
a61af66fc99e Initial load
duke
parents:
diff changeset
1634 if (ch == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1635 _child = cl;
a61af66fc99e Initial load
duke
parents:
diff changeset
1636 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1637 while (ch->_sibling != NULL) { ch = ch->_sibling; }
a61af66fc99e Initial load
duke
parents:
diff changeset
1638 ch->_sibling = cl;
a61af66fc99e Initial load
duke
parents:
diff changeset
1639 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1640 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1641
a61af66fc99e Initial load
duke
parents:
diff changeset
1642 //------------------------------compute_loop_depth-----------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1643 // Store the loop depth in each CFGLoop object.
a61af66fc99e Initial load
duke
parents:
diff changeset
1644 // Recursively walk the children to do the same for them.
a61af66fc99e Initial load
duke
parents:
diff changeset
1645 void CFGLoop::compute_loop_depth(int depth) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1646 _depth = depth;
a61af66fc99e Initial load
duke
parents:
diff changeset
1647 CFGLoop* ch = _child;
a61af66fc99e Initial load
duke
parents:
diff changeset
1648 while (ch != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1649 ch->compute_loop_depth(depth + 1);
a61af66fc99e Initial load
duke
parents:
diff changeset
1650 ch = ch->_sibling;
a61af66fc99e Initial load
duke
parents:
diff changeset
1651 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1652 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1653
a61af66fc99e Initial load
duke
parents:
diff changeset
1654 //------------------------------compute_freq-----------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1655 // Compute the frequency of each block and loop, relative to a single entry
a61af66fc99e Initial load
duke
parents:
diff changeset
1656 // into the dominating loop head.
a61af66fc99e Initial load
duke
parents:
diff changeset
1657 void CFGLoop::compute_freq() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1658 // Bottom up traversal of loop tree (visit inner loops first.)
a61af66fc99e Initial load
duke
parents:
diff changeset
1659 // Set loop head frequency to 1.0, then transitively
a61af66fc99e Initial load
duke
parents:
diff changeset
1660 // compute frequency for all successors in the loop,
a61af66fc99e Initial load
duke
parents:
diff changeset
1661 // as well as for each exit edge. Inner loops are
a61af66fc99e Initial load
duke
parents:
diff changeset
1662 // treated as single blocks with loop exit targets
a61af66fc99e Initial load
duke
parents:
diff changeset
1663 // as the successor blocks.
a61af66fc99e Initial load
duke
parents:
diff changeset
1664
a61af66fc99e Initial load
duke
parents:
diff changeset
1665 // Nested loops first
a61af66fc99e Initial load
duke
parents:
diff changeset
1666 CFGLoop* ch = _child;
a61af66fc99e Initial load
duke
parents:
diff changeset
1667 while (ch != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1668 ch->compute_freq();
a61af66fc99e Initial load
duke
parents:
diff changeset
1669 ch = ch->_sibling;
a61af66fc99e Initial load
duke
parents:
diff changeset
1670 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1671 assert (_members.length() > 0, "no empty loops");
a61af66fc99e Initial load
duke
parents:
diff changeset
1672 Block* hd = head();
a61af66fc99e Initial load
duke
parents:
diff changeset
1673 hd->_freq = 1.0f;
a61af66fc99e Initial load
duke
parents:
diff changeset
1674 for (int i = 0; i < _members.length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1675 CFGElement* s = _members.at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
1676 float freq = s->_freq;
a61af66fc99e Initial load
duke
parents:
diff changeset
1677 if (s->is_block()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1678 Block* b = s->as_Block();
a61af66fc99e Initial load
duke
parents:
diff changeset
1679 for (uint j = 0; j < b->_num_succs; j++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1680 Block* sb = b->_succs[j];
a61af66fc99e Initial load
duke
parents:
diff changeset
1681 update_succ_freq(sb, freq * b->succ_prob(j));
a61af66fc99e Initial load
duke
parents:
diff changeset
1682 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1683 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1684 CFGLoop* lp = s->as_CFGLoop();
a61af66fc99e Initial load
duke
parents:
diff changeset
1685 assert(lp->_parent == this, "immediate child");
a61af66fc99e Initial load
duke
parents:
diff changeset
1686 for (int k = 0; k < lp->_exits.length(); k++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1687 Block* eb = lp->_exits.at(k).get_target();
a61af66fc99e Initial load
duke
parents:
diff changeset
1688 float prob = lp->_exits.at(k).get_prob();
a61af66fc99e Initial load
duke
parents:
diff changeset
1689 update_succ_freq(eb, freq * prob);
a61af66fc99e Initial load
duke
parents:
diff changeset
1690 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1691 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1692 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1693
a61af66fc99e Initial load
duke
parents:
diff changeset
1694 // For all loops other than the outer, "method" loop,
a61af66fc99e Initial load
duke
parents:
diff changeset
1695 // sum and normalize the exit probability. The "method" loop
a61af66fc99e Initial load
duke
parents:
diff changeset
1696 // should keep the initial exit probability of 1, so that
a61af66fc99e Initial load
duke
parents:
diff changeset
1697 // inner blocks do not get erroneously scaled.
a61af66fc99e Initial load
duke
parents:
diff changeset
1698 if (_depth != 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1699 // Total the exit probabilities for this loop.
a61af66fc99e Initial load
duke
parents:
diff changeset
1700 float exits_sum = 0.0f;
a61af66fc99e Initial load
duke
parents:
diff changeset
1701 for (int i = 0; i < _exits.length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1702 exits_sum += _exits.at(i).get_prob();
a61af66fc99e Initial load
duke
parents:
diff changeset
1703 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1704
a61af66fc99e Initial load
duke
parents:
diff changeset
1705 // Normalize the exit probabilities. Until now, the
a61af66fc99e Initial load
duke
parents:
diff changeset
1706 // probabilities estimate the possibility of exit per
a61af66fc99e Initial load
duke
parents:
diff changeset
1707 // a single loop iteration; afterward, they estimate
a61af66fc99e Initial load
duke
parents:
diff changeset
1708 // the probability of exit per loop entry.
a61af66fc99e Initial load
duke
parents:
diff changeset
1709 for (int i = 0; i < _exits.length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1710 Block* et = _exits.at(i).get_target();
418
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1711 float new_prob = 0.0f;
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1712 if (_exits.at(i).get_prob() > 0.0f) {
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1713 new_prob = _exits.at(i).get_prob() / exits_sum;
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1714 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1715 BlockProbPair bpp(et, new_prob);
a61af66fc99e Initial load
duke
parents:
diff changeset
1716 _exits.at_put(i, bpp);
a61af66fc99e Initial load
duke
parents:
diff changeset
1717 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1718
418
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1719 // Save the total, but guard against unreasonable probability,
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1720 // as the value is used to estimate the loop trip count.
a61af66fc99e Initial load
duke
parents:
diff changeset
1721 // An infinite trip count would blur relative block
a61af66fc99e Initial load
duke
parents:
diff changeset
1722 // frequencies.
a61af66fc99e Initial load
duke
parents:
diff changeset
1723 if (exits_sum > 1.0f) exits_sum = 1.0;
a61af66fc99e Initial load
duke
parents:
diff changeset
1724 if (exits_sum < PROB_MIN) exits_sum = PROB_MIN;
a61af66fc99e Initial load
duke
parents:
diff changeset
1725 _exit_prob = exits_sum;
a61af66fc99e Initial load
duke
parents:
diff changeset
1726 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1727 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1728
a61af66fc99e Initial load
duke
parents:
diff changeset
1729 //------------------------------succ_prob-------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1730 // Determine the probability of reaching successor 'i' from the receiver block.
a61af66fc99e Initial load
duke
parents:
diff changeset
1731 float Block::succ_prob(uint i) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1732 int eidx = end_idx();
a61af66fc99e Initial load
duke
parents:
diff changeset
1733 Node *n = _nodes[eidx]; // Get ending Node
308
756b58154237 6611837: block frequency is zero
rasbold
parents: 235
diff changeset
1734
756b58154237 6611837: block frequency is zero
rasbold
parents: 235
diff changeset
1735 int op = n->Opcode();
756b58154237 6611837: block frequency is zero
rasbold
parents: 235
diff changeset
1736 if (n->is_Mach()) {
756b58154237 6611837: block frequency is zero
rasbold
parents: 235
diff changeset
1737 if (n->is_MachNullCheck()) {
756b58154237 6611837: block frequency is zero
rasbold
parents: 235
diff changeset
1738 // Can only reach here if called after lcm. The original Op_If is gone,
756b58154237 6611837: block frequency is zero
rasbold
parents: 235
diff changeset
1739 // so we attempt to infer the probability from one or both of the
756b58154237 6611837: block frequency is zero
rasbold
parents: 235
diff changeset
1740 // successor blocks.
756b58154237 6611837: block frequency is zero
rasbold
parents: 235
diff changeset
1741 assert(_num_succs == 2, "expecting 2 successors of a null check");
756b58154237 6611837: block frequency is zero
rasbold
parents: 235
diff changeset
1742 // If either successor has only one predecessor, then the
605
98cb887364d3 6810672: Comment typos
twisti
parents: 601
diff changeset
1743 // probability estimate can be derived using the
308
756b58154237 6611837: block frequency is zero
rasbold
parents: 235
diff changeset
1744 // relative frequency of the successor and this block.
756b58154237 6611837: block frequency is zero
rasbold
parents: 235
diff changeset
1745 if (_succs[i]->num_preds() == 2) {
756b58154237 6611837: block frequency is zero
rasbold
parents: 235
diff changeset
1746 return _succs[i]->_freq / _freq;
756b58154237 6611837: block frequency is zero
rasbold
parents: 235
diff changeset
1747 } else if (_succs[1-i]->num_preds() == 2) {
756b58154237 6611837: block frequency is zero
rasbold
parents: 235
diff changeset
1748 return 1 - (_succs[1-i]->_freq / _freq);
756b58154237 6611837: block frequency is zero
rasbold
parents: 235
diff changeset
1749 } else {
756b58154237 6611837: block frequency is zero
rasbold
parents: 235
diff changeset
1750 // Estimate using both successor frequencies
756b58154237 6611837: block frequency is zero
rasbold
parents: 235
diff changeset
1751 float freq = _succs[i]->_freq;
756b58154237 6611837: block frequency is zero
rasbold
parents: 235
diff changeset
1752 return freq / (freq + _succs[1-i]->_freq);
756b58154237 6611837: block frequency is zero
rasbold
parents: 235
diff changeset
1753 }
756b58154237 6611837: block frequency is zero
rasbold
parents: 235
diff changeset
1754 }
756b58154237 6611837: block frequency is zero
rasbold
parents: 235
diff changeset
1755 op = n->as_Mach()->ideal_Opcode();
756b58154237 6611837: block frequency is zero
rasbold
parents: 235
diff changeset
1756 }
756b58154237 6611837: block frequency is zero
rasbold
parents: 235
diff changeset
1757
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1758
a61af66fc99e Initial load
duke
parents:
diff changeset
1759 // Switch on branch type
a61af66fc99e Initial load
duke
parents:
diff changeset
1760 switch( op ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1761 case Op_CountedLoopEnd:
a61af66fc99e Initial load
duke
parents:
diff changeset
1762 case Op_If: {
a61af66fc99e Initial load
duke
parents:
diff changeset
1763 assert (i < 2, "just checking");
a61af66fc99e Initial load
duke
parents:
diff changeset
1764 // Conditionals pass on only part of their frequency
a61af66fc99e Initial load
duke
parents:
diff changeset
1765 float prob = n->as_MachIf()->_prob;
a61af66fc99e Initial load
duke
parents:
diff changeset
1766 assert(prob >= 0.0 && prob <= 1.0, "out of range probability");
a61af66fc99e Initial load
duke
parents:
diff changeset
1767 // If succ[i] is the FALSE branch, invert path info
a61af66fc99e Initial load
duke
parents:
diff changeset
1768 if( _nodes[i + eidx + 1]->Opcode() == Op_IfFalse ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1769 return 1.0f - prob; // not taken
a61af66fc99e Initial load
duke
parents:
diff changeset
1770 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1771 return prob; // taken
a61af66fc99e Initial load
duke
parents:
diff changeset
1772 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1773 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1774
a61af66fc99e Initial load
duke
parents:
diff changeset
1775 case Op_Jump:
a61af66fc99e Initial load
duke
parents:
diff changeset
1776 // Divide the frequency between all successors evenly
a61af66fc99e Initial load
duke
parents:
diff changeset
1777 return 1.0f/_num_succs;
a61af66fc99e Initial load
duke
parents:
diff changeset
1778
a61af66fc99e Initial load
duke
parents:
diff changeset
1779 case Op_Catch: {
a61af66fc99e Initial load
duke
parents:
diff changeset
1780 const CatchProjNode *ci = _nodes[i + eidx + 1]->as_CatchProj();
a61af66fc99e Initial load
duke
parents:
diff changeset
1781 if (ci->_con == CatchProjNode::fall_through_index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1782 // Fall-thru path gets the lion's share.
a61af66fc99e Initial load
duke
parents:
diff changeset
1783 return 1.0f - PROB_UNLIKELY_MAG(5)*_num_succs;
a61af66fc99e Initial load
duke
parents:
diff changeset
1784 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1785 // Presume exceptional paths are equally unlikely
a61af66fc99e Initial load
duke
parents:
diff changeset
1786 return PROB_UNLIKELY_MAG(5);
a61af66fc99e Initial load
duke
parents:
diff changeset
1787 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1788 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1789
a61af66fc99e Initial load
duke
parents:
diff changeset
1790 case Op_Root:
a61af66fc99e Initial load
duke
parents:
diff changeset
1791 case Op_Goto:
a61af66fc99e Initial load
duke
parents:
diff changeset
1792 // Pass frequency straight thru to target
a61af66fc99e Initial load
duke
parents:
diff changeset
1793 return 1.0f;
a61af66fc99e Initial load
duke
parents:
diff changeset
1794
a61af66fc99e Initial load
duke
parents:
diff changeset
1795 case Op_NeverBranch:
a61af66fc99e Initial load
duke
parents:
diff changeset
1796 return 0.0f;
a61af66fc99e Initial load
duke
parents:
diff changeset
1797
a61af66fc99e Initial load
duke
parents:
diff changeset
1798 case Op_TailCall:
a61af66fc99e Initial load
duke
parents:
diff changeset
1799 case Op_TailJump:
a61af66fc99e Initial load
duke
parents:
diff changeset
1800 case Op_Return:
a61af66fc99e Initial load
duke
parents:
diff changeset
1801 case Op_Halt:
a61af66fc99e Initial load
duke
parents:
diff changeset
1802 case Op_Rethrow:
a61af66fc99e Initial load
duke
parents:
diff changeset
1803 // Do not push out freq to root block
a61af66fc99e Initial load
duke
parents:
diff changeset
1804 return 0.0f;
a61af66fc99e Initial load
duke
parents:
diff changeset
1805
a61af66fc99e Initial load
duke
parents:
diff changeset
1806 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
1807 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
1808 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1809
a61af66fc99e Initial load
duke
parents:
diff changeset
1810 return 0.0f;
a61af66fc99e Initial load
duke
parents:
diff changeset
1811 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1812
418
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1813 //------------------------------num_fall_throughs-----------------------------
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1814 // Return the number of fall-through candidates for a block
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1815 int Block::num_fall_throughs() {
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1816 int eidx = end_idx();
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1817 Node *n = _nodes[eidx]; // Get ending Node
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1818
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1819 int op = n->Opcode();
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1820 if (n->is_Mach()) {
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1821 if (n->is_MachNullCheck()) {
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1822 // In theory, either side can fall-thru, for simplicity sake,
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1823 // let's say only the false branch can now.
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1824 return 1;
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1825 }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1826 op = n->as_Mach()->ideal_Opcode();
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1827 }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1828
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1829 // Switch on branch type
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1830 switch( op ) {
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1831 case Op_CountedLoopEnd:
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1832 case Op_If:
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1833 return 2;
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1834
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1835 case Op_Root:
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1836 case Op_Goto:
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1837 return 1;
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1838
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1839 case Op_Catch: {
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1840 for (uint i = 0; i < _num_succs; i++) {
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1841 const CatchProjNode *ci = _nodes[i + eidx + 1]->as_CatchProj();
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1842 if (ci->_con == CatchProjNode::fall_through_index) {
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1843 return 1;
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1844 }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1845 }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1846 return 0;
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1847 }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1848
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1849 case Op_Jump:
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1850 case Op_NeverBranch:
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1851 case Op_TailCall:
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1852 case Op_TailJump:
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1853 case Op_Return:
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1854 case Op_Halt:
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1855 case Op_Rethrow:
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1856 return 0;
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1857
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1858 default:
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1859 ShouldNotReachHere();
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1860 }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1861
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1862 return 0;
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1863 }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1864
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1865 //------------------------------succ_fall_through-----------------------------
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1866 // Return true if a specific successor could be fall-through target.
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1867 bool Block::succ_fall_through(uint i) {
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1868 int eidx = end_idx();
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1869 Node *n = _nodes[eidx]; // Get ending Node
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1870
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1871 int op = n->Opcode();
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1872 if (n->is_Mach()) {
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1873 if (n->is_MachNullCheck()) {
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1874 // In theory, either side can fall-thru, for simplicity sake,
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1875 // let's say only the false branch can now.
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1876 return _nodes[i + eidx + 1]->Opcode() == Op_IfFalse;
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1877 }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1878 op = n->as_Mach()->ideal_Opcode();
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1879 }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1880
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1881 // Switch on branch type
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1882 switch( op ) {
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1883 case Op_CountedLoopEnd:
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1884 case Op_If:
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1885 case Op_Root:
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1886 case Op_Goto:
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1887 return true;
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1888
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1889 case Op_Catch: {
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1890 const CatchProjNode *ci = _nodes[i + eidx + 1]->as_CatchProj();
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1891 return ci->_con == CatchProjNode::fall_through_index;
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1892 }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1893
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1894 case Op_Jump:
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1895 case Op_NeverBranch:
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1896 case Op_TailCall:
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1897 case Op_TailJump:
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1898 case Op_Return:
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1899 case Op_Halt:
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1900 case Op_Rethrow:
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1901 return false;
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1902
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1903 default:
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1904 ShouldNotReachHere();
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1905 }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1906
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1907 return false;
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1908 }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1909
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1910 //------------------------------update_uncommon_branch------------------------
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1911 // Update the probability of a two-branch to be uncommon
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1912 void Block::update_uncommon_branch(Block* ub) {
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1913 int eidx = end_idx();
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1914 Node *n = _nodes[eidx]; // Get ending Node
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1915
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1916 int op = n->as_Mach()->ideal_Opcode();
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1917
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1918 assert(op == Op_CountedLoopEnd || op == Op_If, "must be a If");
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1919 assert(num_fall_throughs() == 2, "must be a two way branch block");
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1920
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1921 // Which successor is ub?
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1922 uint s;
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1923 for (s = 0; s <_num_succs; s++) {
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1924 if (_succs[s] == ub) break;
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1925 }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1926 assert(s < 2, "uncommon successor must be found");
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1927
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1928 // If ub is the true path, make the proability small, else
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1929 // ub is the false path, and make the probability large
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1930 bool invert = (_nodes[s + eidx + 1]->Opcode() == Op_IfFalse);
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1931
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1932 // Get existing probability
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1933 float p = n->as_MachIf()->_prob;
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1934
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1935 if (invert) p = 1.0 - p;
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1936 if (p > PROB_MIN) {
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1937 p = PROB_MIN;
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1938 }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1939 if (invert) p = 1.0 - p;
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1940
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1941 n->as_MachIf()->_prob = p;
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1942 }
72c5366e5d86 6743900: frequency based block layout
rasbold
parents: 308
diff changeset
1943
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1944 //------------------------------update_succ_freq-------------------------------
605
98cb887364d3 6810672: Comment typos
twisti
parents: 601
diff changeset
1945 // Update the appropriate frequency associated with block 'b', a successor of
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1946 // a block in this loop.
a61af66fc99e Initial load
duke
parents:
diff changeset
1947 void CFGLoop::update_succ_freq(Block* b, float freq) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1948 if (b->_loop == this) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1949 if (b == head()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1950 // back branch within the loop
a61af66fc99e Initial load
duke
parents:
diff changeset
1951 // Do nothing now, the loop carried frequency will be
a61af66fc99e Initial load
duke
parents:
diff changeset
1952 // adjust later in scale_freq().
a61af66fc99e Initial load
duke
parents:
diff changeset
1953 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1954 // simple branch within the loop
a61af66fc99e Initial load
duke
parents:
diff changeset
1955 b->_freq += freq;
a61af66fc99e Initial load
duke
parents:
diff changeset
1956 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1957 } else if (!in_loop_nest(b)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1958 // branch is exit from this loop
a61af66fc99e Initial load
duke
parents:
diff changeset
1959 BlockProbPair bpp(b, freq);
a61af66fc99e Initial load
duke
parents:
diff changeset
1960 _exits.append(bpp);
a61af66fc99e Initial load
duke
parents:
diff changeset
1961 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
1962 // branch into nested loop
a61af66fc99e Initial load
duke
parents:
diff changeset
1963 CFGLoop* ch = b->_loop;
a61af66fc99e Initial load
duke
parents:
diff changeset
1964 ch->_freq += freq;
a61af66fc99e Initial load
duke
parents:
diff changeset
1965 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1966 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1967
a61af66fc99e Initial load
duke
parents:
diff changeset
1968 //------------------------------in_loop_nest-----------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1969 // Determine if block b is in the receiver's loop nest.
a61af66fc99e Initial load
duke
parents:
diff changeset
1970 bool CFGLoop::in_loop_nest(Block* b) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1971 int depth = _depth;
a61af66fc99e Initial load
duke
parents:
diff changeset
1972 CFGLoop* b_loop = b->_loop;
a61af66fc99e Initial load
duke
parents:
diff changeset
1973 int b_depth = b_loop->_depth;
a61af66fc99e Initial load
duke
parents:
diff changeset
1974 if (depth == b_depth) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1975 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
1976 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1977 while (b_depth > depth) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1978 b_loop = b_loop->_parent;
a61af66fc99e Initial load
duke
parents:
diff changeset
1979 b_depth = b_loop->_depth;
a61af66fc99e Initial load
duke
parents:
diff changeset
1980 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1981 return b_loop == this;
a61af66fc99e Initial load
duke
parents:
diff changeset
1982 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1983
a61af66fc99e Initial load
duke
parents:
diff changeset
1984 //------------------------------scale_freq-------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
1985 // Scale frequency of loops and blocks by trip counts from outer loops
a61af66fc99e Initial load
duke
parents:
diff changeset
1986 // Do a top down traversal of loop tree (visit outer loops first.)
a61af66fc99e Initial load
duke
parents:
diff changeset
1987 void CFGLoop::scale_freq() {
a61af66fc99e Initial load
duke
parents:
diff changeset
1988 float loop_freq = _freq * trip_count();
673
fbc12e71c476 6810845: Performance regression in mpegaudio on x64
kvn
parents: 628
diff changeset
1989 _freq = loop_freq;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1990 for (int i = 0; i < _members.length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1991 CFGElement* s = _members.at(i);
552
011517bbcd7b 6784930: server jvm fails with assert(!n->is_SpillCopy(),"")
kvn
parents: 418
diff changeset
1992 float block_freq = s->_freq * loop_freq;
621
19f25e603e7b 6812721: Block's frequency should not be NaN
kvn
parents: 605
diff changeset
1993 if (g_isnan(block_freq) || block_freq < MIN_BLOCK_FREQUENCY)
19f25e603e7b 6812721: Block's frequency should not be NaN
kvn
parents: 605
diff changeset
1994 block_freq = MIN_BLOCK_FREQUENCY;
552
011517bbcd7b 6784930: server jvm fails with assert(!n->is_SpillCopy(),"")
kvn
parents: 418
diff changeset
1995 s->_freq = block_freq;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1996 }
a61af66fc99e Initial load
duke
parents:
diff changeset
1997 CFGLoop* ch = _child;
a61af66fc99e Initial load
duke
parents:
diff changeset
1998 while (ch != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
1999 ch->scale_freq();
a61af66fc99e Initial load
duke
parents:
diff changeset
2000 ch = ch->_sibling;
a61af66fc99e Initial load
duke
parents:
diff changeset
2001 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2002 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2003
673
fbc12e71c476 6810845: Performance regression in mpegaudio on x64
kvn
parents: 628
diff changeset
2004 // Frequency of outer loop
fbc12e71c476 6810845: Performance regression in mpegaudio on x64
kvn
parents: 628
diff changeset
2005 float CFGLoop::outer_loop_freq() const {
fbc12e71c476 6810845: Performance regression in mpegaudio on x64
kvn
parents: 628
diff changeset
2006 if (_child != NULL) {
fbc12e71c476 6810845: Performance regression in mpegaudio on x64
kvn
parents: 628
diff changeset
2007 return _child->_freq;
fbc12e71c476 6810845: Performance regression in mpegaudio on x64
kvn
parents: 628
diff changeset
2008 }
fbc12e71c476 6810845: Performance regression in mpegaudio on x64
kvn
parents: 628
diff changeset
2009 return _freq;
fbc12e71c476 6810845: Performance regression in mpegaudio on x64
kvn
parents: 628
diff changeset
2010 }
fbc12e71c476 6810845: Performance regression in mpegaudio on x64
kvn
parents: 628
diff changeset
2011
0
a61af66fc99e Initial load
duke
parents:
diff changeset
2012 #ifndef PRODUCT
a61af66fc99e Initial load
duke
parents:
diff changeset
2013 //------------------------------dump_tree--------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
2014 void CFGLoop::dump_tree() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
2015 dump();
a61af66fc99e Initial load
duke
parents:
diff changeset
2016 if (_child != NULL) _child->dump_tree();
a61af66fc99e Initial load
duke
parents:
diff changeset
2017 if (_sibling != NULL) _sibling->dump_tree();
a61af66fc99e Initial load
duke
parents:
diff changeset
2018 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2019
a61af66fc99e Initial load
duke
parents:
diff changeset
2020 //------------------------------dump-------------------------------------------
a61af66fc99e Initial load
duke
parents:
diff changeset
2021 void CFGLoop::dump() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
2022 for (int i = 0; i < _depth; i++) tty->print(" ");
a61af66fc99e Initial load
duke
parents:
diff changeset
2023 tty->print("%s: %d trip_count: %6.0f freq: %6.0f\n",
a61af66fc99e Initial load
duke
parents:
diff changeset
2024 _depth == 0 ? "Method" : "Loop", _id, trip_count(), _freq);
a61af66fc99e Initial load
duke
parents:
diff changeset
2025 for (int i = 0; i < _depth; i++) tty->print(" ");
a61af66fc99e Initial load
duke
parents:
diff changeset
2026 tty->print(" members:", _id);
a61af66fc99e Initial load
duke
parents:
diff changeset
2027 int k = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
2028 for (int i = 0; i < _members.length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2029 if (k++ >= 6) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2030 tty->print("\n ");
a61af66fc99e Initial load
duke
parents:
diff changeset
2031 for (int j = 0; j < _depth+1; j++) tty->print(" ");
a61af66fc99e Initial load
duke
parents:
diff changeset
2032 k = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
2033 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2034 CFGElement *s = _members.at(i);
a61af66fc99e Initial load
duke
parents:
diff changeset
2035 if (s->is_block()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2036 Block *b = s->as_Block();
a61af66fc99e Initial load
duke
parents:
diff changeset
2037 tty->print(" B%d(%6.3f)", b->_pre_order, b->_freq);
a61af66fc99e Initial load
duke
parents:
diff changeset
2038 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
2039 CFGLoop* lp = s->as_CFGLoop();
a61af66fc99e Initial load
duke
parents:
diff changeset
2040 tty->print(" L%d(%6.3f)", lp->_id, lp->_freq);
a61af66fc99e Initial load
duke
parents:
diff changeset
2041 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2042 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2043 tty->print("\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2044 for (int i = 0; i < _depth; i++) tty->print(" ");
a61af66fc99e Initial load
duke
parents:
diff changeset
2045 tty->print(" exits: ");
a61af66fc99e Initial load
duke
parents:
diff changeset
2046 k = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
2047 for (int i = 0; i < _exits.length(); i++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2048 if (k++ >= 7) {
a61af66fc99e Initial load
duke
parents:
diff changeset
2049 tty->print("\n ");
a61af66fc99e Initial load
duke
parents:
diff changeset
2050 for (int j = 0; j < _depth+1; j++) tty->print(" ");
a61af66fc99e Initial load
duke
parents:
diff changeset
2051 k = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
2052 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2053 Block *blk = _exits.at(i).get_target();
a61af66fc99e Initial load
duke
parents:
diff changeset
2054 float prob = _exits.at(i).get_prob();
a61af66fc99e Initial load
duke
parents:
diff changeset
2055 tty->print(" ->%d@%d%%", blk->_pre_order, (int)(prob*100));
a61af66fc99e Initial load
duke
parents:
diff changeset
2056 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2057 tty->print("\n");
a61af66fc99e Initial load
duke
parents:
diff changeset
2058 }
a61af66fc99e Initial load
duke
parents:
diff changeset
2059 #endif