| File: | jdk/src/hotspot/share/opto/reg_split.cpp |
| Warning: | line 65, column 5 Access to field '_idx' results in a dereference of a null pointer (loaded from variable 'use') |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* | ||||
| 2 | * Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved. | ||||
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||||
| 4 | * | ||||
| 5 | * This code is free software; you can redistribute it and/or modify it | ||||
| 6 | * under the terms of the GNU General Public License version 2 only, as | ||||
| 7 | * published by the Free Software Foundation. | ||||
| 8 | * | ||||
| 9 | * This code is distributed in the hope that it will be useful, but WITHOUT | ||||
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||||
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||||
| 12 | * version 2 for more details (a copy is included in the LICENSE file that | ||||
| 13 | * accompanied this code). | ||||
| 14 | * | ||||
| 15 | * You should have received a copy of the GNU General Public License version | ||||
| 16 | * 2 along with this work; if not, write to the Free Software Foundation, | ||||
| 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||||
| 18 | * | ||||
| 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||||
| 20 | * or visit www.oracle.com if you need additional information or have any | ||||
| 21 | * questions. | ||||
| 22 | * | ||||
| 23 | */ | ||||
| 24 | |||||
| 25 | #include "precompiled.hpp" | ||||
| 26 | #include "libadt/vectset.hpp" | ||||
| 27 | #include "memory/allocation.inline.hpp" | ||||
| 28 | #include "memory/resourceArea.inline.hpp" | ||||
| 29 | #include "opto/addnode.hpp" | ||||
| 30 | #include "opto/c2compiler.hpp" | ||||
| 31 | #include "opto/callnode.hpp" | ||||
| 32 | #include "opto/cfgnode.hpp" | ||||
| 33 | #include "opto/chaitin.hpp" | ||||
| 34 | #include "opto/loopnode.hpp" | ||||
| 35 | #include "opto/machnode.hpp" | ||||
| 36 | |||||
| 37 | //------------------------------Split-------------------------------------- | ||||
| 38 | // Walk the graph in RPO and for each lrg which spills, propagate reaching | ||||
| 39 | // definitions. During propagation, split the live range around regions of | ||||
| 40 | // High Register Pressure (HRP). If a Def is in a region of Low Register | ||||
| 41 | // Pressure (LRP), it will not get spilled until we encounter a region of | ||||
| 42 | // HRP between it and one of its uses. We will spill at the transition | ||||
| 43 | // point between LRP and HRP. Uses in the HRP region will use the spilled | ||||
| 44 | // Def. The first Use outside the HRP region will generate a SpillCopy to | ||||
| 45 | // hoist the live range back up into a register, and all subsequent uses | ||||
| 46 | // will use that new Def until another HRP region is encountered. Defs in | ||||
| 47 | // HRP regions will get trailing SpillCopies to push the LRG down into the | ||||
| 48 | // stack immediately. | ||||
| 49 | // | ||||
| 50 | // As a side effect, unlink from (hence make dead) coalesced copies. | ||||
| 51 | // | ||||
| 52 | |||||
| 53 | static const char out_of_nodes[] = "out of nodes during split"; | ||||
| 54 | |||||
| 55 | //------------------------------get_spillcopy_wide----------------------------- | ||||
| 56 | // Get a SpillCopy node with wide-enough masks. Use the 'wide-mask', the | ||||
| 57 | // wide ideal-register spill-mask if possible. If the 'wide-mask' does | ||||
| 58 | // not cover the input (or output), use the input (or output) mask instead. | ||||
| 59 | Node *PhaseChaitin::get_spillcopy_wide(MachSpillCopyNode::SpillType spill_type, Node *def, Node *use, uint uidx) { | ||||
| 60 | // If ideal reg doesn't exist we've got a bad schedule happening | ||||
| 61 | // that is forcing us to spill something that isn't spillable. | ||||
| 62 | // Bail rather than abort | ||||
| 63 | uint ireg = def->ideal_reg(); | ||||
| 64 | if (ireg == 0 || ireg == Op_RegFlags) { | ||||
| 65 | assert(false, "attempted to spill a non-spillable item: %d: %s <- %d: %s, ireg = %u, spill_type: %s",do { if (!(false)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/reg_split.cpp" , 67, "assert(" "false" ") failed", "attempted to spill a non-spillable item: %d: %s <- %d: %s, ireg = %u, spill_type: %s" , def->_idx, def->Name(), use->_idx, use->Name(), ireg, MachSpillCopyNode::spill_type(spill_type)); ::breakpoint (); } } while (0) | ||||
| |||||
| 66 | def->_idx, def->Name(), use->_idx, use->Name(), ireg,do { if (!(false)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/reg_split.cpp" , 67, "assert(" "false" ") failed", "attempted to spill a non-spillable item: %d: %s <- %d: %s, ireg = %u, spill_type: %s" , def->_idx, def->Name(), use->_idx, use->Name(), ireg, MachSpillCopyNode::spill_type(spill_type)); ::breakpoint (); } } while (0) | ||||
| 67 | MachSpillCopyNode::spill_type(spill_type))do { if (!(false)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/reg_split.cpp" , 67, "assert(" "false" ") failed", "attempted to spill a non-spillable item: %d: %s <- %d: %s, ireg = %u, spill_type: %s" , def->_idx, def->Name(), use->_idx, use->Name(), ireg, MachSpillCopyNode::spill_type(spill_type)); ::breakpoint (); } } while (0); | ||||
| 68 | C->record_method_not_compilable("attempted to spill a non-spillable item"); | ||||
| 69 | return NULL__null; | ||||
| 70 | } | ||||
| 71 | if (C->check_node_count(NodeLimitFudgeFactor, out_of_nodes)) { | ||||
| 72 | return NULL__null; | ||||
| 73 | } | ||||
| 74 | const RegMask *i_mask = &def->out_RegMask(); | ||||
| 75 | const RegMask *w_mask = C->matcher()->idealreg2spillmask[ireg]; | ||||
| 76 | const RegMask *o_mask = use ? &use->in_RegMask(uidx) : w_mask; | ||||
| 77 | const RegMask *w_i_mask = w_mask->overlap( *i_mask ) ? w_mask : i_mask; | ||||
| 78 | const RegMask *w_o_mask; | ||||
| 79 | |||||
| 80 | int num_regs = RegMask::num_registers(ireg); | ||||
| 81 | bool is_vect = RegMask::is_vector(ireg); | ||||
| 82 | if( w_mask->overlap( *o_mask ) && // Overlap AND | ||||
| 83 | (num_regs == 1 // Single use or aligned | ||||
| 84 | || is_vect // or vector | ||||
| 85 | || (!is_vect && o_mask->is_aligned_pairs())) ) { | ||||
| 86 | assert(!is_vect || o_mask->is_aligned_sets(num_regs), "vectors are aligned")do { if (!(!is_vect || o_mask->is_aligned_sets(num_regs))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/reg_split.cpp" , 86, "assert(" "!is_vect || o_mask->is_aligned_sets(num_regs)" ") failed", "vectors are aligned"); ::breakpoint(); } } while (0); | ||||
| 87 | // Don't come here for mis-aligned doubles | ||||
| 88 | w_o_mask = w_mask; | ||||
| 89 | } else { // wide ideal mask does not overlap with o_mask | ||||
| 90 | // Mis-aligned doubles come here and XMM->FPR moves on x86. | ||||
| 91 | w_o_mask = o_mask; // Must target desired registers | ||||
| 92 | // Does the ideal-reg-mask overlap with o_mask? I.e., can I use | ||||
| 93 | // a reg-reg move or do I need a trip across register classes | ||||
| 94 | // (and thus through memory)? | ||||
| 95 | if( !C->matcher()->idealreg2regmask[ireg]->overlap( *o_mask) && o_mask->is_UP() ) | ||||
| 96 | // Here we assume a trip through memory is required. | ||||
| 97 | w_i_mask = &C->FIRST_STACK_mask(); | ||||
| 98 | } | ||||
| 99 | return new MachSpillCopyNode(spill_type, def, *w_i_mask, *w_o_mask ); | ||||
| 100 | } | ||||
| 101 | |||||
| 102 | //------------------------------insert_proj------------------------------------ | ||||
| 103 | // Insert the spill at chosen location. Skip over any intervening Proj's or | ||||
| 104 | // Phis. Skip over a CatchNode and projs, inserting in the fall-through block | ||||
| 105 | // instead. Update high-pressure indices. Create a new live range. | ||||
| 106 | void PhaseChaitin::insert_proj( Block *b, uint i, Node *spill, uint maxlrg ) { | ||||
| 107 | // Skip intervening ProjNodes. Do not insert between a ProjNode and | ||||
| 108 | // its definer. | ||||
| 109 | while( i < b->number_of_nodes() && | ||||
| 110 | (b->get_node(i)->is_Proj() || | ||||
| 111 | b->get_node(i)->is_Phi() ) ) | ||||
| 112 | i++; | ||||
| 113 | |||||
| 114 | // Do not insert between a call and his Catch | ||||
| 115 | if( b->get_node(i)->is_Catch() ) { | ||||
| 116 | // Put the instruction at the top of the fall-thru block. | ||||
| 117 | // This assumes that the instruction is not used in the other exception | ||||
| 118 | // blocks. Global code motion is responsible for maintaining this invariant. | ||||
| 119 | // Find the fall-thru projection | ||||
| 120 | while( 1 ) { | ||||
| 121 | const CatchProjNode *cp = b->get_node(++i)->as_CatchProj(); | ||||
| 122 | if( cp->_con == CatchProjNode::fall_through_index ) | ||||
| 123 | break; | ||||
| 124 | } | ||||
| 125 | int sidx = i - b->end_idx()-1; | ||||
| 126 | b = b->_succs[sidx]; // Switch to successor block | ||||
| 127 | i = 1; // Right at start of block | ||||
| 128 | } | ||||
| 129 | |||||
| 130 | b->insert_node(spill, i); // Insert node in block | ||||
| 131 | _cfg.map_node_to_block(spill, b); // Update node->block mapping to reflect | ||||
| 132 | // Adjust the point where we go hi-pressure | ||||
| 133 | if( i <= b->_ihrp_index ) b->_ihrp_index++; | ||||
| 134 | if( i <= b->_fhrp_index ) b->_fhrp_index++; | ||||
| 135 | |||||
| 136 | // Assign a new Live Range Number to the SpillCopy and grow | ||||
| 137 | // the node->live range mapping. | ||||
| 138 | new_lrg(spill,maxlrg); | ||||
| 139 | } | ||||
| 140 | |||||
| 141 | //------------------------------split_DEF-------------------------------------- | ||||
| 142 | // There are four categories of Split; UP/DOWN x DEF/USE | ||||
| 143 | // Only three of these really occur as DOWN/USE will always color | ||||
| 144 | // Any Split with a DEF cannot CISC-Spill now. Thus we need | ||||
| 145 | // two helper routines, one for Split DEFS (insert after instruction), | ||||
| 146 | // one for Split USES (insert before instruction). DEF insertion | ||||
| 147 | // happens inside Split, where the Leaveblock array is updated. | ||||
| 148 | uint PhaseChaitin::split_DEF( Node *def, Block *b, int loc, uint maxlrg, Node **Reachblock, Node **debug_defs, GrowableArray<uint> splits, int slidx ) { | ||||
| 149 | #ifdef ASSERT1 | ||||
| 150 | // Increment the counter for this lrg | ||||
| 151 | splits.at_put(slidx, splits.at(slidx)+1); | ||||
| 152 | #endif | ||||
| 153 | // If we are spilling the memory op for an implicit null check, at the | ||||
| 154 | // null check location (ie - null check is in HRP block) we need to do | ||||
| 155 | // the null-check first, then spill-down in the following block. | ||||
| 156 | // (The implicit_null_check function ensures the use is also dominated | ||||
| 157 | // by the branch-not-taken block.) | ||||
| 158 | Node *be = b->end(); | ||||
| 159 | if( be->is_MachNullCheck() && be->in(1) == def && def == b->get_node(loc)) { | ||||
| 160 | // Spill goes in the branch-not-taken block | ||||
| 161 | b = b->_succs[b->get_node(b->end_idx()+1)->Opcode() == Op_IfTrue]; | ||||
| 162 | loc = 0; // Just past the Region | ||||
| 163 | } | ||||
| 164 | assert( loc >= 0, "must insert past block head" )do { if (!(loc >= 0)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/reg_split.cpp" , 164, "assert(" "loc >= 0" ") failed", "must insert past block head" ); ::breakpoint(); } } while (0); | ||||
| 165 | |||||
| 166 | // Get a def-side SpillCopy | ||||
| 167 | Node *spill = get_spillcopy_wide(MachSpillCopyNode::Definition, def, NULL__null, 0); | ||||
| 168 | // Did we fail to split?, then bail | ||||
| 169 | if (!spill) { | ||||
| 170 | return 0; | ||||
| 171 | } | ||||
| 172 | |||||
| 173 | // Insert the spill at chosen location | ||||
| 174 | insert_proj( b, loc+1, spill, maxlrg++); | ||||
| 175 | |||||
| 176 | // Insert new node into Reaches array | ||||
| 177 | Reachblock[slidx] = spill; | ||||
| 178 | // Update debug list of reaching down definitions by adding this one | ||||
| 179 | debug_defs[slidx] = spill; | ||||
| 180 | |||||
| 181 | // return updated count of live ranges | ||||
| 182 | return maxlrg; | ||||
| 183 | } | ||||
| 184 | |||||
| 185 | //------------------------------split_USE-------------------------------------- | ||||
| 186 | // Splits at uses can involve redeffing the LRG, so no CISC Spilling there. | ||||
| 187 | // Debug uses want to know if def is already stack enabled. | ||||
| 188 | // Return value | ||||
| 189 | // -1 : bailout, 0: no spillcopy created, 1: create a new spillcopy | ||||
| 190 | int PhaseChaitin::split_USE(MachSpillCopyNode::SpillType spill_type, Node *def, Block *b, Node *use, uint useidx, uint maxlrg, bool def_down, bool cisc_sp, GrowableArray<uint> splits, int slidx ) { | ||||
| 191 | #ifdef ASSERT1 | ||||
| 192 | // Increment the counter for this lrg | ||||
| 193 | splits.at_put(slidx, splits.at(slidx)+1); | ||||
| 194 | #endif | ||||
| 195 | |||||
| 196 | // Some setup stuff for handling debug node uses | ||||
| 197 | JVMState* jvms = use->jvms(); | ||||
| 198 | uint debug_start = jvms ? jvms->debug_start() : 999999; | ||||
| 199 | uint debug_end = jvms ? jvms->debug_end() : 999999; | ||||
| 200 | |||||
| 201 | //------------------------------------------- | ||||
| 202 | // Check for use of debug info | ||||
| 203 | if (useidx >= debug_start && useidx < debug_end) { | ||||
| 204 | // Actually it's perfectly legal for constant debug info to appear | ||||
| 205 | // just unlikely. In this case the optimizer left a ConI of a 4 | ||||
| 206 | // as both inputs to a Phi with only a debug use. It's a single-def | ||||
| 207 | // live range of a rematerializable value. The live range spills, | ||||
| 208 | // rematerializes and now the ConI directly feeds into the debug info. | ||||
| 209 | // assert(!def->is_Con(), "constant debug info already constructed directly"); | ||||
| 210 | |||||
| 211 | // Special split handling for Debug Info | ||||
| 212 | // If DEF is DOWN, just hook the edge and return | ||||
| 213 | // If DEF is UP, Split it DOWN for this USE. | ||||
| 214 | if( def->is_Mach() ) { | ||||
| 215 | if( def_down ) { | ||||
| 216 | // DEF is DOWN, so connect USE directly to the DEF | ||||
| 217 | use->set_req(useidx, def); | ||||
| 218 | return 0; | ||||
| 219 | } else { | ||||
| 220 | // Block and index where the use occurs. | ||||
| 221 | Block *b = _cfg.get_block_for_node(use); | ||||
| 222 | // Put the clone just prior to use | ||||
| 223 | int bindex = b->find_node(use); | ||||
| 224 | // DEF is UP, so must copy it DOWN and hook in USE | ||||
| 225 | // Insert SpillCopy before the USE, which uses DEF as its input, | ||||
| 226 | // and defs a new live range, which is used by this node. | ||||
| 227 | Node *spill = get_spillcopy_wide(spill_type, def,use,useidx); | ||||
| 228 | // did we fail to split? | ||||
| 229 | if (!spill) { | ||||
| 230 | // Bail | ||||
| 231 | return -1; | ||||
| 232 | } | ||||
| 233 | // insert into basic block | ||||
| 234 | insert_proj( b, bindex, spill, maxlrg ); | ||||
| 235 | // Use the new split | ||||
| 236 | use->set_req(useidx,spill); | ||||
| 237 | return 1; | ||||
| 238 | } | ||||
| 239 | // No further split handling needed for this use | ||||
| 240 | } // End special splitting for debug info live range | ||||
| 241 | } // If debug info | ||||
| 242 | |||||
| 243 | // CISC-SPILLING | ||||
| 244 | // Finally, check to see if USE is CISC-Spillable, and if so, | ||||
| 245 | // gather_lrg_masks will add the flags bit to its mask, and | ||||
| 246 | // no use side copy is needed. This frees up the live range | ||||
| 247 | // register choices without causing copy coalescing, etc. | ||||
| 248 | if( UseCISCSpill && cisc_sp ) { | ||||
| 249 | int inp = use->cisc_operand(); | ||||
| 250 | if( inp != AdlcVMDeps::Not_cisc_spillable ) | ||||
| 251 | // Convert operand number to edge index number | ||||
| 252 | inp = use->as_Mach()->operand_index(inp); | ||||
| 253 | if( inp == (int)useidx ) { | ||||
| 254 | use->set_req(useidx, def); | ||||
| 255 | #ifndef PRODUCT | ||||
| 256 | if( TraceCISCSpill ) { | ||||
| 257 | tty->print(" set_split: "); | ||||
| 258 | use->dump(); | ||||
| 259 | } | ||||
| 260 | #endif | ||||
| 261 | return 0; | ||||
| 262 | } | ||||
| 263 | } | ||||
| 264 | |||||
| 265 | //------------------------------------------- | ||||
| 266 | // Insert a Copy before the use | ||||
| 267 | |||||
| 268 | // Block and index where the use occurs. | ||||
| 269 | int bindex; | ||||
| 270 | // Phi input spill-copys belong at the end of the prior block | ||||
| 271 | if( use->is_Phi() ) { | ||||
| 272 | b = _cfg.get_block_for_node(b->pred(useidx)); | ||||
| 273 | bindex = b->end_idx(); | ||||
| 274 | } else { | ||||
| 275 | // Put the clone just prior to use | ||||
| 276 | bindex = b->find_node(use); | ||||
| 277 | } | ||||
| 278 | |||||
| 279 | Node *spill = get_spillcopy_wide(spill_type, def, use, useidx ); | ||||
| 280 | if( !spill ) return -1; // Bailed out | ||||
| 281 | // Insert SpillCopy before the USE, which uses the reaching DEF as | ||||
| 282 | // its input, and defs a new live range, which is used by this node. | ||||
| 283 | insert_proj( b, bindex, spill, maxlrg ); | ||||
| 284 | // Use the spill/clone | ||||
| 285 | use->set_req(useidx,spill); | ||||
| 286 | |||||
| 287 | return 1; | ||||
| 288 | } | ||||
| 289 | |||||
| 290 | //------------------------------clone_node---------------------------- | ||||
| 291 | // Clone node with anti dependence check. | ||||
| 292 | Node* clone_node(Node* def, Block *b, Compile* C) { | ||||
| 293 | if (def->needs_anti_dependence_check()) { | ||||
| 294 | #ifdef ASSERT1 | ||||
| 295 | if (PrintOpto && WizardMode) { | ||||
| 296 | tty->print_cr("RA attempts to clone node with anti_dependence:"); | ||||
| 297 | def->dump(-1); tty->cr(); | ||||
| 298 | tty->print_cr("into block:"); | ||||
| 299 | b->dump(); | ||||
| 300 | } | ||||
| 301 | #endif | ||||
| 302 | if (C->subsume_loads() == true && !C->failing()) { | ||||
| 303 | // Retry with subsume_loads == false | ||||
| 304 | // If this is the first failure, the sentinel string will "stick" | ||||
| 305 | // to the Compile object, and the C2Compiler will see it and retry. | ||||
| 306 | C->record_failure(C2Compiler::retry_no_subsuming_loads()); | ||||
| 307 | } else { | ||||
| 308 | // Bailout without retry | ||||
| 309 | C->record_method_not_compilable("RA Split failed: attempt to clone node with anti_dependence"); | ||||
| 310 | } | ||||
| 311 | return 0; | ||||
| 312 | } | ||||
| 313 | return def->clone(); | ||||
| 314 | } | ||||
| 315 | |||||
| 316 | //------------------------------split_Rematerialize---------------------------- | ||||
| 317 | // Clone a local copy of the def. | ||||
| 318 | Node *PhaseChaitin::split_Rematerialize(Node *def, Block *b, uint insidx, uint &maxlrg, | ||||
| 319 | GrowableArray<uint> splits, int slidx, uint *lrg2reach, | ||||
| 320 | Node **Reachblock, bool walkThru) { | ||||
| 321 | // The input live ranges will be stretched to the site of the new | ||||
| 322 | // instruction. They might be stretched past a def and will thus | ||||
| 323 | // have the old and new values of the same live range alive at the | ||||
| 324 | // same time - a definite no-no. Split out private copies of | ||||
| 325 | // the inputs. | ||||
| 326 | if (def->req() > 1) { | ||||
| 327 | for (uint i = 1; i < def->req(); i++) { | ||||
| 328 | Node *in = def->in(i); | ||||
| 329 | uint lidx = _lrg_map.live_range_id(in); | ||||
| 330 | // We do not need this for live ranges that are only defined once. | ||||
| 331 | // However, this is not true for spill copies that are added in this | ||||
| 332 | // Split() pass, since they might get coalesced later on in this pass. | ||||
| 333 | if (lidx < _lrg_map.max_lrg_id() && lrgs(lidx).is_singledef()) { | ||||
| 334 | continue; | ||||
| 335 | } | ||||
| 336 | |||||
| 337 | Block *b_def = _cfg.get_block_for_node(def); | ||||
| 338 | int idx_def = b_def->find_node(def); | ||||
| 339 | // Cannot spill Op_RegFlags. | ||||
| 340 | Node *in_spill; | ||||
| 341 | if (in->ideal_reg() != Op_RegFlags) { | ||||
| 342 | in_spill = get_spillcopy_wide(MachSpillCopyNode::InputToRematerialization, in, def, i); | ||||
| 343 | if (!in_spill) { return 0; } // Bailed out | ||||
| 344 | insert_proj(b_def, idx_def, in_spill, maxlrg++); | ||||
| 345 | if (b_def == b) { | ||||
| 346 | insidx++; | ||||
| 347 | } | ||||
| 348 | def->set_req(i, in_spill); | ||||
| 349 | } else { | ||||
| 350 | // The 'in' defines a flag register. Flag registers can not be spilled. | ||||
| 351 | // Register allocation handles live ranges with flag registers | ||||
| 352 | // by rematerializing the def (in this case 'in'). Thus, this is not | ||||
| 353 | // critical if the input can be rematerialized, too. | ||||
| 354 | if (!in->rematerialize()) { | ||||
| 355 | assert(false, "Can not rematerialize %d: %s. Prolongs RegFlags live"do { if (!(false)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/reg_split.cpp" , 357, "assert(" "false" ") failed", "Can not rematerialize %d: %s. Prolongs RegFlags live" " range and defining node %d: %s may not be rematerialized." , def->_idx, def->Name(), in->_idx, in->Name()); :: breakpoint(); } } while (0) | ||||
| 356 | " range and defining node %d: %s may not be rematerialized.",do { if (!(false)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/reg_split.cpp" , 357, "assert(" "false" ") failed", "Can not rematerialize %d: %s. Prolongs RegFlags live" " range and defining node %d: %s may not be rematerialized." , def->_idx, def->Name(), in->_idx, in->Name()); :: breakpoint(); } } while (0) | ||||
| 357 | def->_idx, def->Name(), in->_idx, in->Name())do { if (!(false)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/reg_split.cpp" , 357, "assert(" "false" ") failed", "Can not rematerialize %d: %s. Prolongs RegFlags live" " range and defining node %d: %s may not be rematerialized." , def->_idx, def->Name(), in->_idx, in->Name()); :: breakpoint(); } } while (0); | ||||
| 358 | C->record_method_not_compilable("attempted to spill a non-spillable item with RegFlags input"); | ||||
| 359 | return 0; // Bailed out | ||||
| 360 | } | ||||
| 361 | } | ||||
| 362 | } | ||||
| 363 | } | ||||
| 364 | |||||
| 365 | Node *spill = clone_node(def, b, C); | ||||
| 366 | if (spill == NULL__null || C->check_node_count(NodeLimitFudgeFactor, out_of_nodes)) { | ||||
| 367 | // Check when generating nodes | ||||
| 368 | return 0; | ||||
| 369 | } | ||||
| 370 | |||||
| 371 | // See if any inputs are currently being spilled, and take the | ||||
| 372 | // latest copy of spilled inputs. | ||||
| 373 | if( spill->req() > 1 ) { | ||||
| 374 | for( uint i = 1; i < spill->req(); i++ ) { | ||||
| 375 | Node *in = spill->in(i); | ||||
| 376 | uint lidx = _lrg_map.find_id(in); | ||||
| 377 | |||||
| 378 | // Walk backwards thru spill copy node intermediates | ||||
| 379 | if (walkThru) { | ||||
| 380 | while (in->is_SpillCopy() && lidx >= _lrg_map.max_lrg_id()) { | ||||
| 381 | in = in->in(1); | ||||
| 382 | lidx = _lrg_map.find_id(in); | ||||
| 383 | } | ||||
| 384 | |||||
| 385 | if (lidx < _lrg_map.max_lrg_id() && lrgs(lidx).is_multidef()) { | ||||
| 386 | // walkThru found a multidef LRG, which is unsafe to use, so | ||||
| 387 | // just keep the original def used in the clone. | ||||
| 388 | in = spill->in(i); | ||||
| 389 | lidx = _lrg_map.find_id(in); | ||||
| 390 | } | ||||
| 391 | } | ||||
| 392 | |||||
| 393 | if (lidx < _lrg_map.max_lrg_id() && lrgs(lidx).reg() >= LRG::SPILL_REG) { | ||||
| 394 | Node *rdef = Reachblock[lrg2reach[lidx]]; | ||||
| 395 | if (rdef) { | ||||
| 396 | spill->set_req(i, rdef); | ||||
| 397 | } | ||||
| 398 | } | ||||
| 399 | } | ||||
| 400 | } | ||||
| 401 | |||||
| 402 | |||||
| 403 | assert( spill->out_RegMask().is_UP(), "rematerialize to a reg" )do { if (!(spill->out_RegMask().is_UP())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/reg_split.cpp" , 403, "assert(" "spill->out_RegMask().is_UP()" ") failed" , "rematerialize to a reg"); ::breakpoint(); } } while (0); | ||||
| 404 | // Rematerialized op is def->spilled+1 | ||||
| 405 | set_was_spilled(spill); | ||||
| 406 | if( _spilled_once.test(def->_idx) ) | ||||
| 407 | set_was_spilled(spill); | ||||
| 408 | |||||
| 409 | insert_proj( b, insidx, spill, maxlrg++ ); | ||||
| 410 | #ifdef ASSERT1 | ||||
| 411 | // Increment the counter for this lrg | ||||
| 412 | splits.at_put(slidx, splits.at(slidx)+1); | ||||
| 413 | #endif | ||||
| 414 | // See if the cloned def kills any flags, and copy those kills as well | ||||
| 415 | uint i = insidx+1; | ||||
| 416 | int found_projs = clone_projs( b, i, def, spill, maxlrg); | ||||
| 417 | if (found_projs > 0) { | ||||
| 418 | // Adjust the point where we go hi-pressure | ||||
| 419 | if (i <= b->_ihrp_index) { | ||||
| 420 | b->_ihrp_index += found_projs; | ||||
| 421 | } | ||||
| 422 | if (i <= b->_fhrp_index) { | ||||
| 423 | b->_fhrp_index += found_projs; | ||||
| 424 | } | ||||
| 425 | } | ||||
| 426 | |||||
| 427 | return spill; | ||||
| 428 | } | ||||
| 429 | |||||
| 430 | //------------------------------is_high_pressure------------------------------- | ||||
| 431 | // Function to compute whether or not this live range is "high pressure" | ||||
| 432 | // in this block - whether it spills eagerly or not. | ||||
| 433 | bool PhaseChaitin::is_high_pressure( Block *b, LRG *lrg, uint insidx ) { | ||||
| 434 | if( lrg->_was_spilled1 ) return true; | ||||
| 435 | // Forced spilling due to conflict? Then split only at binding uses | ||||
| 436 | // or defs, not for supposed capacity problems. | ||||
| 437 | // CNC - Turned off 7/8/99, causes too much spilling | ||||
| 438 | // if( lrg->_is_bound ) return false; | ||||
| 439 | |||||
| 440 | // Use float pressure numbers for vectors. | ||||
| 441 | bool is_float_or_vector = lrg->_is_float || lrg->_is_vector; | ||||
| 442 | // Not yet reached the high-pressure cutoff point, so low pressure | ||||
| 443 | uint hrp_idx = is_float_or_vector ? b->_fhrp_index : b->_ihrp_index; | ||||
| 444 | if( insidx < hrp_idx ) return false; | ||||
| 445 | // Register pressure for the block as a whole depends on reg class | ||||
| 446 | int block_pres = is_float_or_vector ? b->_freg_pressure : b->_reg_pressure; | ||||
| 447 | // Bound live ranges will split at the binding points first; | ||||
| 448 | // Intermediate splits should assume the live range's register set | ||||
| 449 | // got "freed up" and that num_regs will become INT_PRESSURE. | ||||
| 450 | int bound_pres = is_float_or_vector ? Matcher::float_pressure_limit() : Matcher::int_pressure_limit(); | ||||
| 451 | // Effective register pressure limit. | ||||
| 452 | int lrg_pres = (lrg->get_invalid_mask_size() > lrg->num_regs()) | ||||
| 453 | ? (lrg->get_invalid_mask_size() >> (lrg->num_regs()-1)) : bound_pres; | ||||
| 454 | // High pressure if block pressure requires more register freedom | ||||
| 455 | // than live range has. | ||||
| 456 | return block_pres >= lrg_pres; | ||||
| 457 | } | ||||
| 458 | |||||
| 459 | |||||
| 460 | //------------------------------prompt_use--------------------------------- | ||||
| 461 | // True if lidx is used before any real register is def'd in the block | ||||
| 462 | bool PhaseChaitin::prompt_use( Block *b, uint lidx ) { | ||||
| 463 | if (lrgs(lidx)._was_spilled2) { | ||||
| 464 | return false; | ||||
| 465 | } | ||||
| 466 | |||||
| 467 | // Scan block for 1st use. | ||||
| 468 | for( uint i = 1; i <= b->end_idx(); i++ ) { | ||||
| 469 | Node *n = b->get_node(i); | ||||
| 470 | // Ignore PHI use, these can be up or down | ||||
| 471 | if (n->is_Phi()) { | ||||
| 472 | continue; | ||||
| 473 | } | ||||
| 474 | for (uint j = 1; j < n->req(); j++) { | ||||
| 475 | if (_lrg_map.find_id(n->in(j)) == lidx) { | ||||
| 476 | return true; // Found 1st use! | ||||
| 477 | } | ||||
| 478 | } | ||||
| 479 | if (n->out_RegMask().is_NotEmpty()) { | ||||
| 480 | return false; | ||||
| 481 | } | ||||
| 482 | } | ||||
| 483 | return false; | ||||
| 484 | } | ||||
| 485 | |||||
| 486 | //------------------------------Split-------------------------------------- | ||||
| 487 | //----------Split Routine---------- | ||||
| 488 | // ***** NEW SPLITTING HEURISTIC ***** | ||||
| 489 | // DEFS: If the DEF is in a High Register Pressure(HRP) Block, split there. | ||||
| 490 | // Else, no split unless there is a HRP block between a DEF and | ||||
| 491 | // one of its uses, and then split at the HRP block. | ||||
| 492 | // | ||||
| 493 | // USES: If USE is in HRP, split at use to leave main LRG on stack. | ||||
| 494 | // Else, hoist LRG back up to register only (ie - split is also DEF) | ||||
| 495 | // We will compute a new maxlrg as we go | ||||
| 496 | uint PhaseChaitin::Split(uint maxlrg, ResourceArea* split_arena) { | ||||
| 497 | Compile::TracePhase tp("regAllocSplit", &timers[_t_regAllocSplit]); | ||||
| 498 | |||||
| 499 | // Free thread local resources used by this method on exit. | ||||
| 500 | ResourceMark rm(split_arena); | ||||
| 501 | |||||
| 502 | uint bidx, pidx, slidx, insidx, inpidx, twoidx; | ||||
| 503 | uint non_phi = 1, spill_cnt = 0; | ||||
| 504 | Node *n1, *n2, *n3; | ||||
| 505 | Node_List *defs,*phis; | ||||
| 506 | bool *UPblock; | ||||
| 507 | bool u1, u2, u3; | ||||
| 508 | Block *b, *pred; | ||||
| 509 | PhiNode *phi; | ||||
| 510 | GrowableArray<uint> lidxs(split_arena, maxlrg, 0, 0); | ||||
| 511 | |||||
| 512 | // Array of counters to count splits per live range | ||||
| 513 | GrowableArray<uint> splits(split_arena, maxlrg, 0, 0); | ||||
| 514 | |||||
| 515 | #define NEW_SPLIT_ARRAY(type, size)\ | ||||
| 516 | (type*) split_arena->allocate_bytes((size) * sizeof(type)) | ||||
| 517 | |||||
| 518 | //----------Setup Code---------- | ||||
| 519 | // Create a convenient mapping from lrg numbers to reaches/leaves indices | ||||
| 520 | uint *lrg2reach = NEW_SPLIT_ARRAY(uint, maxlrg); | ||||
| 521 | // Keep track of DEFS & Phis for later passes | ||||
| 522 | defs = new Node_List(); | ||||
| 523 | phis = new Node_List(); | ||||
| 524 | // Gather info on which LRG's are spilling, and build maps | ||||
| 525 | for (bidx = 1; bidx < maxlrg; bidx++) { | ||||
| |||||
| 526 | if (lrgs(bidx).alive() && lrgs(bidx).reg() >= LRG::SPILL_REG) { | ||||
| 527 | assert(!lrgs(bidx).mask().is_AllStack(),"AllStack should color")do { if (!(!lrgs(bidx).mask().is_AllStack())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/reg_split.cpp" , 527, "assert(" "!lrgs(bidx).mask().is_AllStack()" ") failed" , "AllStack should color"); ::breakpoint(); } } while (0); | ||||
| 528 | lrg2reach[bidx] = spill_cnt; | ||||
| 529 | spill_cnt++; | ||||
| 530 | lidxs.append(bidx); | ||||
| 531 | #ifdef ASSERT1 | ||||
| 532 | // Initialize the split counts to zero | ||||
| 533 | splits.append(0); | ||||
| 534 | #endif | ||||
| 535 | if (PrintOpto && WizardMode && lrgs(bidx)._was_spilled1) { | ||||
| 536 | tty->print_cr("Warning, 2nd spill of L%d",bidx); | ||||
| 537 | } | ||||
| 538 | } | ||||
| 539 | } | ||||
| 540 | |||||
| 541 | // Create side arrays for propagating reaching defs info. | ||||
| 542 | // Each block needs a node pointer for each spilling live range for the | ||||
| 543 | // Def which is live into the block. Phi nodes handle multiple input | ||||
| 544 | // Defs by querying the output of their predecessor blocks and resolving | ||||
| 545 | // them to a single Def at the phi. The pointer is updated for each | ||||
| 546 | // Def in the block, and then becomes the output for the block when | ||||
| 547 | // processing of the block is complete. We also need to track whether | ||||
| 548 | // a Def is UP or DOWN. UP means that it should get a register (ie - | ||||
| 549 | // it is always in LRP regions), and DOWN means that it is probably | ||||
| 550 | // on the stack (ie - it crosses HRP regions). | ||||
| 551 | Node ***Reaches = NEW_SPLIT_ARRAY( Node**, _cfg.number_of_blocks() + 1); | ||||
| 552 | bool **UP = NEW_SPLIT_ARRAY( bool*, _cfg.number_of_blocks() + 1); | ||||
| 553 | Node **debug_defs = NEW_SPLIT_ARRAY( Node*, spill_cnt ); | ||||
| 554 | VectorSet **UP_entry= NEW_SPLIT_ARRAY( VectorSet*, spill_cnt ); | ||||
| 555 | |||||
| 556 | // Initialize Reaches & UP | ||||
| 557 | for (bidx = 0; bidx < _cfg.number_of_blocks() + 1; bidx++) { | ||||
| 558 | Reaches[bidx] = NEW_SPLIT_ARRAY( Node*, spill_cnt ); | ||||
| 559 | UP[bidx] = NEW_SPLIT_ARRAY( bool, spill_cnt ); | ||||
| 560 | Node **Reachblock = Reaches[bidx]; | ||||
| 561 | bool *UPblock = UP[bidx]; | ||||
| 562 | for( slidx = 0; slidx < spill_cnt; slidx++ ) { | ||||
| 563 | UPblock[slidx] = true; // Assume they start in registers | ||||
| 564 | Reachblock[slidx] = NULL__null; // Assume that no def is present | ||||
| 565 | } | ||||
| 566 | } | ||||
| 567 | |||||
| 568 | #undef NEW_SPLIT_ARRAY | ||||
| 569 | |||||
| 570 | // Initialize to array of empty vectorsets | ||||
| 571 | for( slidx = 0; slidx < spill_cnt; slidx++ ) | ||||
| 572 | UP_entry[slidx] = new VectorSet(split_arena); | ||||
| 573 | |||||
| 574 | //----------PASS 1---------- | ||||
| 575 | //----------Propagation & Node Insertion Code---------- | ||||
| 576 | // Walk the Blocks in RPO for DEF & USE info | ||||
| 577 | for( bidx = 0; bidx < _cfg.number_of_blocks(); bidx++ ) { | ||||
| 578 | |||||
| 579 | if (C->check_node_count(spill_cnt, out_of_nodes)) { | ||||
| 580 | return 0; | ||||
| 581 | } | ||||
| 582 | |||||
| 583 | b = _cfg.get_block(bidx); | ||||
| 584 | // Reaches & UP arrays for this block | ||||
| 585 | Node** Reachblock = Reaches[b->_pre_order]; | ||||
| 586 | UPblock = UP[b->_pre_order]; | ||||
| 587 | // Reset counter of start of non-Phi nodes in block | ||||
| 588 | non_phi = 1; | ||||
| 589 | //----------Block Entry Handling---------- | ||||
| 590 | // Check for need to insert a new phi | ||||
| 591 | // Cycle through this block's predecessors, collecting Reaches | ||||
| 592 | // info for each spilled LRG. If they are identical, no phi is | ||||
| 593 | // needed. If they differ, check for a phi, and insert if missing, | ||||
| 594 | // or update edges if present. Set current block's Reaches set to | ||||
| 595 | // be either the phi's or the reaching def, as appropriate. | ||||
| 596 | // If no Phi is needed, check if the LRG needs to spill on entry | ||||
| 597 | // to the block due to HRP. | ||||
| 598 | for( slidx = 0; slidx < spill_cnt; slidx++ ) { | ||||
| 599 | // Grab the live range number | ||||
| 600 | uint lidx = lidxs.at(slidx); | ||||
| 601 | // Do not bother splitting or putting in Phis for single-def | ||||
| 602 | // rematerialized live ranges. This happens alot to constants | ||||
| 603 | // with long live ranges. | ||||
| 604 | if( lrgs(lidx).is_singledef() && | ||||
| 605 | lrgs(lidx)._def->rematerialize() ) { | ||||
| 606 | // reset the Reaches & UP entries | ||||
| 607 | Reachblock[slidx] = lrgs(lidx)._def; | ||||
| 608 | UPblock[slidx] = true; | ||||
| 609 | // Record following instruction in case 'n' rematerializes and | ||||
| 610 | // kills flags | ||||
| 611 | Block *pred1 = _cfg.get_block_for_node(b->pred(1)); | ||||
| 612 | continue; | ||||
| 613 | } | ||||
| 614 | |||||
| 615 | // Initialize needs_phi and needs_split | ||||
| 616 | bool needs_phi = false; | ||||
| 617 | bool needs_split = false; | ||||
| 618 | bool has_phi = false; | ||||
| 619 | // Walk the predecessor blocks to check inputs for that live range | ||||
| 620 | // Grab predecessor block header | ||||
| 621 | n1 = b->pred(1); | ||||
| 622 | // Grab the appropriate reaching def info for inpidx | ||||
| 623 | pred = _cfg.get_block_for_node(n1); | ||||
| 624 | pidx = pred->_pre_order; | ||||
| 625 | Node **Ltmp = Reaches[pidx]; | ||||
| 626 | bool *Utmp = UP[pidx]; | ||||
| 627 | n1 = Ltmp[slidx]; | ||||
| 628 | u1 = Utmp[slidx]; | ||||
| 629 | // Initialize node for saving type info | ||||
| 630 | n3 = n1; | ||||
| 631 | u3 = u1; | ||||
| 632 | |||||
| 633 | // Compare inputs to see if a Phi is needed | ||||
| 634 | for( inpidx = 2; inpidx < b->num_preds(); inpidx++ ) { | ||||
| 635 | // Grab predecessor block headers | ||||
| 636 | n2 = b->pred(inpidx); | ||||
| 637 | // Grab the appropriate reaching def info for inpidx | ||||
| 638 | pred = _cfg.get_block_for_node(n2); | ||||
| 639 | pidx = pred->_pre_order; | ||||
| 640 | Ltmp = Reaches[pidx]; | ||||
| 641 | Utmp = UP[pidx]; | ||||
| 642 | n2 = Ltmp[slidx]; | ||||
| 643 | u2 = Utmp[slidx]; | ||||
| 644 | // For each LRG, decide if a phi is necessary | ||||
| 645 | if( n1 != n2 ) { | ||||
| 646 | needs_phi = true; | ||||
| 647 | } | ||||
| 648 | // See if the phi has mismatched inputs, UP vs. DOWN | ||||
| 649 | if( n1 && n2 && (u1 != u2) ) { | ||||
| 650 | needs_split = true; | ||||
| 651 | } | ||||
| 652 | // Move n2/u2 to n1/u1 for next iteration | ||||
| 653 | n1 = n2; | ||||
| 654 | u1 = u2; | ||||
| 655 | // Preserve a non-NULL predecessor for later type referencing | ||||
| 656 | if( (n3 == NULL__null) && (n2 != NULL__null) ){ | ||||
| 657 | n3 = n2; | ||||
| 658 | u3 = u2; | ||||
| 659 | } | ||||
| 660 | } // End for all potential Phi inputs | ||||
| 661 | |||||
| 662 | // check block for appropriate phinode & update edges | ||||
| 663 | for( insidx = 1; insidx <= b->end_idx(); insidx++ ) { | ||||
| 664 | n1 = b->get_node(insidx); | ||||
| 665 | // bail if this is not a phi | ||||
| 666 | phi = n1->is_Phi() ? n1->as_Phi() : NULL__null; | ||||
| 667 | if( phi == NULL__null ) { | ||||
| 668 | // Keep track of index of first non-PhiNode instruction in block | ||||
| 669 | non_phi = insidx; | ||||
| 670 | // break out of the for loop as we have handled all phi nodes | ||||
| 671 | break; | ||||
| 672 | } | ||||
| 673 | // must be looking at a phi | ||||
| 674 | if (_lrg_map.find_id(n1) == lidxs.at(slidx)) { | ||||
| 675 | // found the necessary phi | ||||
| 676 | needs_phi = false; | ||||
| 677 | has_phi = true; | ||||
| 678 | // initialize the Reaches entry for this LRG | ||||
| 679 | Reachblock[slidx] = phi; | ||||
| 680 | break; | ||||
| 681 | } // end if found correct phi | ||||
| 682 | } // end for all phi's | ||||
| 683 | |||||
| 684 | // If a phi is needed or exist, check for it | ||||
| 685 | if( needs_phi || has_phi ) { | ||||
| 686 | // add new phinode if one not already found | ||||
| 687 | if( needs_phi ) { | ||||
| 688 | // create a new phi node and insert it into the block | ||||
| 689 | // type is taken from left over pointer to a predecessor | ||||
| 690 | guarantee(n3, "No non-NULL reaching DEF for a Phi")do { if (!(n3)) { (*g_assert_poison) = 'X';; report_vm_error( "/home/daniel/Projects/java/jdk/src/hotspot/share/opto/reg_split.cpp" , 690, "guarantee(" "n3" ") failed", "No non-NULL reaching DEF for a Phi" ); ::breakpoint(); } } while (0); | ||||
| 691 | phi = new PhiNode(b->head(), n3->bottom_type()); | ||||
| 692 | // initialize the Reaches entry for this LRG | ||||
| 693 | Reachblock[slidx] = phi; | ||||
| 694 | |||||
| 695 | // add node to block & node_to_block mapping | ||||
| 696 | insert_proj(b, insidx++, phi, maxlrg++); | ||||
| 697 | non_phi++; | ||||
| 698 | // Reset new phi's mapping to be the spilling live range | ||||
| 699 | _lrg_map.map(phi->_idx, lidx); | ||||
| 700 | assert(_lrg_map.find_id(phi) == lidx, "Bad update on Union-Find mapping")do { if (!(_lrg_map.find_id(phi) == lidx)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/reg_split.cpp" , 700, "assert(" "_lrg_map.find_id(phi) == lidx" ") failed", "Bad update on Union-Find mapping" ); ::breakpoint(); } } while (0); | ||||
| 701 | } // end if not found correct phi | ||||
| 702 | // Here you have either found or created the Phi, so record it | ||||
| 703 | assert(phi != NULL,"Must have a Phi Node here")do { if (!(phi != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/reg_split.cpp" , 703, "assert(" "phi != __null" ") failed", "Must have a Phi Node here" ); ::breakpoint(); } } while (0); | ||||
| 704 | phis->push(phi); | ||||
| 705 | // PhiNodes should either force the LRG UP or DOWN depending | ||||
| 706 | // on its inputs and the register pressure in the Phi's block. | ||||
| 707 | UPblock[slidx] = true; // Assume new DEF is UP | ||||
| 708 | // If entering a high-pressure area with no immediate use, | ||||
| 709 | // assume Phi is DOWN | ||||
| 710 | if( is_high_pressure( b, &lrgs(lidx), b->end_idx()) && !prompt_use(b,lidx) ) | ||||
| 711 | UPblock[slidx] = false; | ||||
| 712 | // If we are not split up/down and all inputs are down, then we | ||||
| 713 | // are down | ||||
| 714 | if( !needs_split && !u3 ) | ||||
| 715 | UPblock[slidx] = false; | ||||
| 716 | } // end if phi is needed | ||||
| 717 | |||||
| 718 | // Do not need a phi, so grab the reaching DEF | ||||
| 719 | else { | ||||
| 720 | // Grab predecessor block header | ||||
| 721 | n1 = b->pred(1); | ||||
| 722 | // Grab the appropriate reaching def info for k | ||||
| 723 | pred = _cfg.get_block_for_node(n1); | ||||
| 724 | pidx = pred->_pre_order; | ||||
| 725 | Node **Ltmp = Reaches[pidx]; | ||||
| 726 | bool *Utmp = UP[pidx]; | ||||
| 727 | // reset the Reaches & UP entries | ||||
| 728 | Reachblock[slidx] = Ltmp[slidx]; | ||||
| 729 | UPblock[slidx] = Utmp[slidx]; | ||||
| 730 | } // end else no Phi is needed | ||||
| 731 | } // end for all spilling live ranges | ||||
| 732 | // DEBUG | ||||
| 733 | #ifndef PRODUCT | ||||
| 734 | if(trace_spilling()) { | ||||
| 735 | tty->print("/`\nBlock %d: ", b->_pre_order); | ||||
| 736 | tty->print("Reaching Definitions after Phi handling\n"); | ||||
| 737 | for( uint x = 0; x < spill_cnt; x++ ) { | ||||
| 738 | tty->print("Spill Idx %d: UP %d: Node\n",x,UPblock[x]); | ||||
| 739 | if( Reachblock[x] ) | ||||
| 740 | Reachblock[x]->dump(); | ||||
| 741 | else | ||||
| 742 | tty->print("Undefined\n"); | ||||
| 743 | } | ||||
| 744 | } | ||||
| 745 | #endif | ||||
| 746 | |||||
| 747 | //----------Non-Phi Node Splitting---------- | ||||
| 748 | // Since phi-nodes have now been handled, the Reachblock array for this | ||||
| 749 | // block is initialized with the correct starting value for the defs which | ||||
| 750 | // reach non-phi instructions in this block. Thus, process non-phi | ||||
| 751 | // instructions normally, inserting SpillCopy nodes for all spill | ||||
| 752 | // locations. | ||||
| 753 | |||||
| 754 | // Memoize any DOWN reaching definitions for use as DEBUG info | ||||
| 755 | for( insidx = 0; insidx < spill_cnt; insidx++ ) { | ||||
| 756 | debug_defs[insidx] = (UPblock[insidx]) ? NULL__null : Reachblock[insidx]; | ||||
| 757 | if( UPblock[insidx] ) // Memoize UP decision at block start | ||||
| 758 | UP_entry[insidx]->set( b->_pre_order ); | ||||
| 759 | } | ||||
| 760 | |||||
| 761 | //----------Walk Instructions in the Block and Split---------- | ||||
| 762 | // For all non-phi instructions in the block | ||||
| 763 | for( insidx = 1; insidx <= b->end_idx(); insidx++ ) { | ||||
| 764 | Node *n = b->get_node(insidx); | ||||
| 765 | // Find the defining Node's live range index | ||||
| 766 | uint defidx = _lrg_map.find_id(n); | ||||
| 767 | uint cnt = n->req(); | ||||
| 768 | |||||
| 769 | if (n->is_Phi()) { | ||||
| 770 | // Skip phi nodes after removing dead copies. | ||||
| 771 | if (defidx < _lrg_map.max_lrg_id()) { | ||||
| 772 | // Check for useless Phis. These appear if we spill, then | ||||
| 773 | // coalesce away copies. Dont touch Phis in spilling live | ||||
| 774 | // ranges; they are busy getting modifed in this pass. | ||||
| 775 | if( lrgs(defidx).reg() < LRG::SPILL_REG ) { | ||||
| 776 | uint i; | ||||
| 777 | Node *u = NULL__null; | ||||
| 778 | // Look for the Phi merging 2 unique inputs | ||||
| 779 | for( i = 1; i < cnt; i++ ) { | ||||
| 780 | // Ignore repeats and self | ||||
| 781 | if( n->in(i) != u && n->in(i) != n ) { | ||||
| 782 | // Found a unique input | ||||
| 783 | if( u != NULL__null ) // If it's the 2nd, bail out | ||||
| 784 | break; | ||||
| 785 | u = n->in(i); // Else record it | ||||
| 786 | } | ||||
| 787 | } | ||||
| 788 | assert( u, "at least 1 valid input expected" )do { if (!(u)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/reg_split.cpp" , 788, "assert(" "u" ") failed", "at least 1 valid input expected" ); ::breakpoint(); } } while (0); | ||||
| 789 | if (i >= cnt) { // Found one unique input | ||||
| 790 | assert(_lrg_map.find_id(n) == _lrg_map.find_id(u), "should be the same lrg")do { if (!(_lrg_map.find_id(n) == _lrg_map.find_id(u))) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/reg_split.cpp" , 790, "assert(" "_lrg_map.find_id(n) == _lrg_map.find_id(u)" ") failed", "should be the same lrg"); ::breakpoint(); } } while (0); | ||||
| 791 | n->replace_by(u); // Then replace with unique input | ||||
| 792 | n->disconnect_inputs(C); | ||||
| 793 | b->remove_node(insidx); | ||||
| 794 | insidx--; | ||||
| 795 | b->_ihrp_index--; | ||||
| 796 | b->_fhrp_index--; | ||||
| 797 | } | ||||
| 798 | } | ||||
| 799 | } | ||||
| 800 | continue; | ||||
| 801 | } | ||||
| 802 | assert( insidx > b->_ihrp_index ||do { if (!(insidx > b->_ihrp_index || (b->_reg_pressure < Matcher::int_pressure_limit()) || b->_ihrp_index > 4000000 || b->_ihrp_index >= b->end_idx() || !b-> get_node(b->_ihrp_index)->is_Proj())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/reg_split.cpp" , 806, "assert(" "insidx > b->_ihrp_index || (b->_reg_pressure < Matcher::int_pressure_limit()) || b->_ihrp_index > 4000000 || b->_ihrp_index >= b->end_idx() || !b->get_node(b->_ihrp_index)->is_Proj()" ") failed", ""); ::breakpoint(); } } while (0) | ||||
| 803 | (b->_reg_pressure < Matcher::int_pressure_limit()) ||do { if (!(insidx > b->_ihrp_index || (b->_reg_pressure < Matcher::int_pressure_limit()) || b->_ihrp_index > 4000000 || b->_ihrp_index >= b->end_idx() || !b-> get_node(b->_ihrp_index)->is_Proj())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/reg_split.cpp" , 806, "assert(" "insidx > b->_ihrp_index || (b->_reg_pressure < Matcher::int_pressure_limit()) || b->_ihrp_index > 4000000 || b->_ihrp_index >= b->end_idx() || !b->get_node(b->_ihrp_index)->is_Proj()" ") failed", ""); ::breakpoint(); } } while (0) | ||||
| 804 | b->_ihrp_index > 4000000 ||do { if (!(insidx > b->_ihrp_index || (b->_reg_pressure < Matcher::int_pressure_limit()) || b->_ihrp_index > 4000000 || b->_ihrp_index >= b->end_idx() || !b-> get_node(b->_ihrp_index)->is_Proj())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/reg_split.cpp" , 806, "assert(" "insidx > b->_ihrp_index || (b->_reg_pressure < Matcher::int_pressure_limit()) || b->_ihrp_index > 4000000 || b->_ihrp_index >= b->end_idx() || !b->get_node(b->_ihrp_index)->is_Proj()" ") failed", ""); ::breakpoint(); } } while (0) | ||||
| 805 | b->_ihrp_index >= b->end_idx() ||do { if (!(insidx > b->_ihrp_index || (b->_reg_pressure < Matcher::int_pressure_limit()) || b->_ihrp_index > 4000000 || b->_ihrp_index >= b->end_idx() || !b-> get_node(b->_ihrp_index)->is_Proj())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/reg_split.cpp" , 806, "assert(" "insidx > b->_ihrp_index || (b->_reg_pressure < Matcher::int_pressure_limit()) || b->_ihrp_index > 4000000 || b->_ihrp_index >= b->end_idx() || !b->get_node(b->_ihrp_index)->is_Proj()" ") failed", ""); ::breakpoint(); } } while (0) | ||||
| 806 | !b->get_node(b->_ihrp_index)->is_Proj(), "" )do { if (!(insidx > b->_ihrp_index || (b->_reg_pressure < Matcher::int_pressure_limit()) || b->_ihrp_index > 4000000 || b->_ihrp_index >= b->end_idx() || !b-> get_node(b->_ihrp_index)->is_Proj())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/reg_split.cpp" , 806, "assert(" "insidx > b->_ihrp_index || (b->_reg_pressure < Matcher::int_pressure_limit()) || b->_ihrp_index > 4000000 || b->_ihrp_index >= b->end_idx() || !b->get_node(b->_ihrp_index)->is_Proj()" ") failed", ""); ::breakpoint(); } } while (0); | ||||
| 807 | assert( insidx > b->_fhrp_index ||do { if (!(insidx > b->_fhrp_index || (b->_freg_pressure < Matcher::float_pressure_limit()) || b->_fhrp_index > 4000000 || b->_fhrp_index >= b->end_idx() || !b-> get_node(b->_fhrp_index)->is_Proj())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/reg_split.cpp" , 811, "assert(" "insidx > b->_fhrp_index || (b->_freg_pressure < Matcher::float_pressure_limit()) || b->_fhrp_index > 4000000 || b->_fhrp_index >= b->end_idx() || !b->get_node(b->_fhrp_index)->is_Proj()" ") failed", ""); ::breakpoint(); } } while (0) | ||||
| 808 | (b->_freg_pressure < Matcher::float_pressure_limit()) ||do { if (!(insidx > b->_fhrp_index || (b->_freg_pressure < Matcher::float_pressure_limit()) || b->_fhrp_index > 4000000 || b->_fhrp_index >= b->end_idx() || !b-> get_node(b->_fhrp_index)->is_Proj())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/reg_split.cpp" , 811, "assert(" "insidx > b->_fhrp_index || (b->_freg_pressure < Matcher::float_pressure_limit()) || b->_fhrp_index > 4000000 || b->_fhrp_index >= b->end_idx() || !b->get_node(b->_fhrp_index)->is_Proj()" ") failed", ""); ::breakpoint(); } } while (0) | ||||
| 809 | b->_fhrp_index > 4000000 ||do { if (!(insidx > b->_fhrp_index || (b->_freg_pressure < Matcher::float_pressure_limit()) || b->_fhrp_index > 4000000 || b->_fhrp_index >= b->end_idx() || !b-> get_node(b->_fhrp_index)->is_Proj())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/reg_split.cpp" , 811, "assert(" "insidx > b->_fhrp_index || (b->_freg_pressure < Matcher::float_pressure_limit()) || b->_fhrp_index > 4000000 || b->_fhrp_index >= b->end_idx() || !b->get_node(b->_fhrp_index)->is_Proj()" ") failed", ""); ::breakpoint(); } } while (0) | ||||
| 810 | b->_fhrp_index >= b->end_idx() ||do { if (!(insidx > b->_fhrp_index || (b->_freg_pressure < Matcher::float_pressure_limit()) || b->_fhrp_index > 4000000 || b->_fhrp_index >= b->end_idx() || !b-> get_node(b->_fhrp_index)->is_Proj())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/reg_split.cpp" , 811, "assert(" "insidx > b->_fhrp_index || (b->_freg_pressure < Matcher::float_pressure_limit()) || b->_fhrp_index > 4000000 || b->_fhrp_index >= b->end_idx() || !b->get_node(b->_fhrp_index)->is_Proj()" ") failed", ""); ::breakpoint(); } } while (0) | ||||
| 811 | !b->get_node(b->_fhrp_index)->is_Proj(), "" )do { if (!(insidx > b->_fhrp_index || (b->_freg_pressure < Matcher::float_pressure_limit()) || b->_fhrp_index > 4000000 || b->_fhrp_index >= b->end_idx() || !b-> get_node(b->_fhrp_index)->is_Proj())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/reg_split.cpp" , 811, "assert(" "insidx > b->_fhrp_index || (b->_freg_pressure < Matcher::float_pressure_limit()) || b->_fhrp_index > 4000000 || b->_fhrp_index >= b->end_idx() || !b->get_node(b->_fhrp_index)->is_Proj()" ") failed", ""); ::breakpoint(); } } while (0); | ||||
| 812 | |||||
| 813 | // ********** Handle Crossing HRP Boundry ********** | ||||
| 814 | if( (insidx
| ||||
| 815 | for( slidx = 0; slidx < spill_cnt; slidx++ ) { | ||||
| 816 | // Check for need to split at HRP boundary - split if UP | ||||
| 817 | n1 = Reachblock[slidx]; | ||||
| 818 | // bail out if no reaching DEF | ||||
| 819 | if( n1 == NULL__null ) continue; | ||||
| 820 | // bail out if live range is 'isolated' around inner loop | ||||
| 821 | uint lidx = lidxs.at(slidx); | ||||
| 822 | // If live range is currently UP | ||||
| 823 | if( UPblock[slidx] ) { | ||||
| 824 | // set location to insert spills at | ||||
| 825 | // SPLIT DOWN HERE - NO CISC SPILL | ||||
| 826 | if( is_high_pressure( b, &lrgs(lidx), insidx ) && | ||||
| 827 | !n1->rematerialize() ) { | ||||
| 828 | // If there is already a valid stack definition available, use it | ||||
| 829 | if( debug_defs[slidx] != NULL__null ) { | ||||
| 830 | Reachblock[slidx] = debug_defs[slidx]; | ||||
| 831 | } | ||||
| 832 | else { | ||||
| 833 | // Insert point is just past last use or def in the block | ||||
| 834 | int insert_point = insidx-1; | ||||
| 835 | while( insert_point > 0 ) { | ||||
| 836 | Node *n = b->get_node(insert_point); | ||||
| 837 | // Hit top of block? Quit going backwards | ||||
| 838 | if (n->is_Phi()) { | ||||
| 839 | break; | ||||
| 840 | } | ||||
| 841 | // Found a def? Better split after it. | ||||
| 842 | if (_lrg_map.live_range_id(n) == lidx) { | ||||
| 843 | break; | ||||
| 844 | } | ||||
| 845 | // Look for a use | ||||
| 846 | uint i; | ||||
| 847 | for( i = 1; i < n->req(); i++ ) { | ||||
| 848 | if (_lrg_map.live_range_id(n->in(i)) == lidx) { | ||||
| 849 | break; | ||||
| 850 | } | ||||
| 851 | } | ||||
| 852 | // Found a use? Better split after it. | ||||
| 853 | if (i < n->req()) { | ||||
| 854 | break; | ||||
| 855 | } | ||||
| 856 | insert_point--; | ||||
| 857 | } | ||||
| 858 | uint orig_eidx = b->end_idx(); | ||||
| 859 | maxlrg = split_DEF( n1, b, insert_point, maxlrg, Reachblock, debug_defs, splits, slidx); | ||||
| 860 | // If it wasn't split bail | ||||
| 861 | if (!maxlrg) { | ||||
| 862 | return 0; | ||||
| 863 | } | ||||
| 864 | // Spill of NULL check mem op goes into the following block. | ||||
| 865 | if (b->end_idx() > orig_eidx) { | ||||
| 866 | insidx++; | ||||
| 867 | } | ||||
| 868 | } | ||||
| 869 | // This is a new DEF, so update UP | ||||
| 870 | UPblock[slidx] = false; | ||||
| 871 | #ifndef PRODUCT | ||||
| 872 | // DEBUG | ||||
| 873 | if( trace_spilling() ) { | ||||
| 874 | tty->print("\nNew Split DOWN DEF of Spill Idx "); | ||||
| 875 | tty->print("%d, UP %d:\n",slidx,false); | ||||
| 876 | n1->dump(); | ||||
| 877 | } | ||||
| 878 | #endif | ||||
| 879 | } | ||||
| 880 | } // end if LRG is UP | ||||
| 881 | } // end for all spilling live ranges | ||||
| 882 | assert( b->get_node(insidx) == n, "got insidx set incorrectly" )do { if (!(b->get_node(insidx) == n)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/reg_split.cpp" , 882, "assert(" "b->get_node(insidx) == n" ") failed", "got insidx set incorrectly" ); ::breakpoint(); } } while (0); | ||||
| 883 | } // end if crossing HRP Boundry | ||||
| 884 | |||||
| 885 | // If the LRG index is oob, then this is a new spillcopy, skip it. | ||||
| 886 | if (defidx >= _lrg_map.max_lrg_id()) { | ||||
| 887 | continue; | ||||
| 888 | } | ||||
| 889 | LRG &deflrg = lrgs(defidx); | ||||
| 890 | uint copyidx = n->is_Copy(); | ||||
| 891 | // Remove coalesced copy from CFG | ||||
| 892 | if (copyidx && defidx == _lrg_map.live_range_id(n->in(copyidx))) { | ||||
| 893 | n->replace_by( n->in(copyidx) ); | ||||
| 894 | n->set_req( copyidx, NULL__null ); | ||||
| 895 | b->remove_node(insidx--); | ||||
| 896 | b->_ihrp_index--; // Adjust the point where we go hi-pressure | ||||
| 897 | b->_fhrp_index--; | ||||
| 898 | continue; | ||||
| 899 | } | ||||
| 900 | |||||
| 901 | #define DERIVED0 0 | ||||
| 902 | |||||
| 903 | // ********** Handle USES ********** | ||||
| 904 | bool nullcheck = false; | ||||
| 905 | // Implicit null checks never use the spilled value | ||||
| 906 | if( n->is_MachNullCheck() ) | ||||
| 907 | nullcheck = true; | ||||
| 908 | if( !nullcheck
| ||||
| 909 | // Search all inputs for a Spill-USE | ||||
| 910 | JVMState* jvms = n->jvms(); | ||||
| 911 | uint oopoff = jvms ? jvms->oopoff() : cnt; | ||||
| 912 | uint old_last = cnt - 1; | ||||
| 913 | for( inpidx = 1; inpidx < cnt; inpidx++ ) { | ||||
| 914 | // Derived/base pairs may be added to our inputs during this loop. | ||||
| 915 | // If inpidx > old_last, then one of these new inputs is being | ||||
| 916 | // handled. Skip the derived part of the pair, but process | ||||
| 917 | // the base like any other input. | ||||
| 918 | if (inpidx > old_last && ((inpidx - oopoff) & 1) == DERIVED0) { | ||||
| 919 | continue; // skip derived_debug added below | ||||
| 920 | } | ||||
| 921 | // Get lidx of input | ||||
| 922 | uint useidx = _lrg_map.find_id(n->in(inpidx)); | ||||
| 923 | // Not a brand-new split, and it is a spill use | ||||
| 924 | if (useidx < _lrg_map.max_lrg_id() && lrgs(useidx).reg() >= LRG::SPILL_REG) { | ||||
| 925 | // Check for valid reaching DEF | ||||
| 926 | slidx = lrg2reach[useidx]; | ||||
| 927 | Node *def = Reachblock[slidx]; | ||||
| 928 | assert( def != NULL, "Using Undefined Value in Split()\n")do { if (!(def != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/reg_split.cpp" , 928, "assert(" "def != __null" ") failed", "Using Undefined Value in Split()\n" ); ::breakpoint(); } } while (0); | ||||
| 929 | |||||
| 930 | // (+++) %%%% remove this in favor of pre-pass in matcher.cpp | ||||
| 931 | // monitor references do not care where they live, so just hook | ||||
| 932 | if ( jvms && jvms->is_monitor_use(inpidx) ) { | ||||
| 933 | // The effect of this clone is to drop the node out of the block, | ||||
| 934 | // so that the allocator does not see it anymore, and therefore | ||||
| 935 | // does not attempt to assign it a register. | ||||
| 936 | def = clone_node(def, b, C); | ||||
| 937 | if (def == NULL__null || C->check_node_count(NodeLimitFudgeFactor, out_of_nodes)) { | ||||
| 938 | return 0; | ||||
| 939 | } | ||||
| 940 | _lrg_map.extend(def->_idx, 0); | ||||
| 941 | _cfg.map_node_to_block(def, b); | ||||
| 942 | n->set_req(inpidx, def); | ||||
| 943 | continue; | ||||
| 944 | } | ||||
| 945 | |||||
| 946 | // Rematerializable? Then clone def at use site instead | ||||
| 947 | // of store/load | ||||
| 948 | if( def->rematerialize() ) { | ||||
| 949 | int old_size = b->number_of_nodes(); | ||||
| 950 | def = split_Rematerialize( def, b, insidx, maxlrg, splits, slidx, lrg2reach, Reachblock, true ); | ||||
| 951 | if( !def ) return 0; // Bail out | ||||
| 952 | insidx += b->number_of_nodes()-old_size; | ||||
| 953 | } | ||||
| 954 | |||||
| 955 | MachNode *mach = n->is_Mach() ? n->as_Mach() : NULL__null; | ||||
| 956 | // Base pointers and oopmap references do not care where they live. | ||||
| 957 | if ((inpidx >= oopoff) || | ||||
| 958 | (mach && mach->ideal_Opcode() == Op_AddP && inpidx == AddPNode::Base)) { | ||||
| 959 | if (def->rematerialize() && lrgs(useidx)._was_spilled2) { | ||||
| 960 | // This def has been rematerialized a couple of times without | ||||
| 961 | // progress. It doesn't care if it lives UP or DOWN, so | ||||
| 962 | // spill it down now. | ||||
| 963 | int delta = split_USE(MachSpillCopyNode::BasePointerToMem, def,b,n,inpidx,maxlrg,false,false,splits,slidx); | ||||
| 964 | // If it wasn't split bail | ||||
| 965 | if (delta < 0) { | ||||
| 966 | return 0; | ||||
| 967 | } | ||||
| 968 | maxlrg += delta; | ||||
| 969 | insidx += delta; // Reset iterator to skip USE side split | ||||
| 970 | } else { | ||||
| 971 | // Just hook the def edge | ||||
| 972 | n->set_req(inpidx, def); | ||||
| 973 | } | ||||
| 974 | |||||
| 975 | if (inpidx >= oopoff) { | ||||
| 976 | // After oopoff, we have derived/base pairs. We must mention all | ||||
| 977 | // derived pointers here as derived/base pairs for GC. If the | ||||
| 978 | // derived value is spilling and we have a copy both in Reachblock | ||||
| 979 | // (called here 'def') and debug_defs[slidx] we need to mention | ||||
| 980 | // both in derived/base pairs or kill one. | ||||
| 981 | Node *derived_debug = debug_defs[slidx]; | ||||
| 982 | if( ((inpidx - oopoff) & 1) == DERIVED0 && // derived vs base? | ||||
| 983 | mach && mach->ideal_Opcode() != Op_Halt && | ||||
| 984 | derived_debug != NULL__null && | ||||
| 985 | derived_debug != def ) { // Actual 2nd value appears | ||||
| 986 | // We have already set 'def' as a derived value. | ||||
| 987 | // Also set debug_defs[slidx] as a derived value. | ||||
| 988 | uint k; | ||||
| 989 | for( k = oopoff; k < cnt; k += 2 ) | ||||
| 990 | if( n->in(k) == derived_debug ) | ||||
| 991 | break; // Found an instance of debug derived | ||||
| 992 | if( k == cnt ) {// No instance of debug_defs[slidx] | ||||
| 993 | // Add a derived/base pair to cover the debug info. | ||||
| 994 | // We have to process the added base later since it is not | ||||
| 995 | // handled yet at this point but skip derived part. | ||||
| 996 | assert(((n->req() - oopoff) & 1) == DERIVED,do { if (!(((n->req() - oopoff) & 1) == 0)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/reg_split.cpp" , 997, "assert(" "((n->req() - oopoff) & 1) == 0" ") failed" , "must match skip condition above"); ::breakpoint(); } } while (0) | ||||
| 997 | "must match skip condition above")do { if (!(((n->req() - oopoff) & 1) == 0)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/reg_split.cpp" , 997, "assert(" "((n->req() - oopoff) & 1) == 0" ") failed" , "must match skip condition above"); ::breakpoint(); } } while (0); | ||||
| 998 | n->add_req( derived_debug ); // this will be skipped above | ||||
| 999 | n->add_req( n->in(inpidx+1) ); // this will be processed | ||||
| 1000 | // Increment cnt to handle added input edges on | ||||
| 1001 | // subsequent iterations. | ||||
| 1002 | cnt += 2; | ||||
| 1003 | } | ||||
| 1004 | } | ||||
| 1005 | } | ||||
| 1006 | continue; | ||||
| 1007 | } | ||||
| 1008 | // Special logic for DEBUG info | ||||
| 1009 | if( jvms && b->_freq > BLOCK_FREQUENCY(0.5)((0.5 * (double) 1500) / FreqCountInvocations) ) { | ||||
| 1010 | uint debug_start = jvms->debug_start(); | ||||
| 1011 | // If this is debug info use & there is a reaching DOWN def | ||||
| 1012 | if ((debug_start <= inpidx) && (debug_defs[slidx] != NULL__null)) { | ||||
| 1013 | assert(inpidx < oopoff, "handle only debug info here")do { if (!(inpidx < oopoff)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/reg_split.cpp" , 1013, "assert(" "inpidx < oopoff" ") failed", "handle only debug info here" ); ::breakpoint(); } } while (0); | ||||
| 1014 | // Just hook it in & move on | ||||
| 1015 | n->set_req(inpidx, debug_defs[slidx]); | ||||
| 1016 | // (Note that this can make two sides of a split live at the | ||||
| 1017 | // same time: The debug def on stack, and another def in a | ||||
| 1018 | // register. The GC needs to know about both of them, but any | ||||
| 1019 | // derived pointers after oopoff will refer to only one of the | ||||
| 1020 | // two defs and the GC would therefore miss the other. Thus | ||||
| 1021 | // this hack is only allowed for debug info which is Java state | ||||
| 1022 | // and therefore never a derived pointer.) | ||||
| 1023 | continue; | ||||
| 1024 | } | ||||
| 1025 | } | ||||
| 1026 | // Grab register mask info | ||||
| 1027 | const RegMask &dmask = def->out_RegMask(); | ||||
| 1028 | const RegMask &umask = n->in_RegMask(inpidx); | ||||
| 1029 | bool is_vect = RegMask::is_vector(def->ideal_reg()); | ||||
| 1030 | assert(inpidx < oopoff, "cannot use-split oop map info")do { if (!(inpidx < oopoff)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/reg_split.cpp" , 1030, "assert(" "inpidx < oopoff" ") failed", "cannot use-split oop map info" ); ::breakpoint(); } } while (0); | ||||
| 1031 | |||||
| 1032 | bool dup = UPblock[slidx]; | ||||
| 1033 | bool uup = umask.is_UP(); | ||||
| 1034 | |||||
| 1035 | // Need special logic to handle bound USES. Insert a split at this | ||||
| 1036 | // bound use if we can't rematerialize the def, or if we need the | ||||
| 1037 | // split to form a misaligned pair. | ||||
| 1038 | if( !umask.is_AllStack() && | ||||
| 1039 | (int)umask.Size() <= lrgs(useidx).num_regs() && | ||||
| 1040 | (!def->rematerialize() || | ||||
| 1041 | (!is_vect && umask.is_misaligned_pair()))) { | ||||
| 1042 | // These need a Split regardless of overlap or pressure | ||||
| 1043 | // SPLIT - NO DEF - NO CISC SPILL | ||||
| 1044 | int delta = split_USE(MachSpillCopyNode::Bound, def,b,n,inpidx,maxlrg,dup,false, splits,slidx); | ||||
| 1045 | // If it wasn't split bail | ||||
| 1046 | if (delta < 0) { | ||||
| 1047 | return 0; | ||||
| 1048 | } | ||||
| 1049 | maxlrg += delta; | ||||
| 1050 | insidx += delta; // Reset iterator to skip USE side split | ||||
| 1051 | continue; | ||||
| 1052 | } | ||||
| 1053 | |||||
| 1054 | if (UseFPUForSpilling && n->is_MachCall() && !uup && !dup ) { | ||||
| 1055 | // The use at the call can force the def down so insert | ||||
| 1056 | // a split before the use to allow the def more freedom. | ||||
| 1057 | int delta = split_USE(MachSpillCopyNode::CallUse, def,b,n,inpidx,maxlrg,dup,false, splits,slidx); | ||||
| 1058 | // If it wasn't split bail | ||||
| 1059 | if (delta < 0) { | ||||
| 1060 | return 0; | ||||
| 1061 | } | ||||
| 1062 | maxlrg += delta; | ||||
| 1063 | insidx += delta; // Reset iterator to skip USE side split | ||||
| 1064 | continue; | ||||
| 1065 | } | ||||
| 1066 | |||||
| 1067 | // Here is the logic chart which describes USE Splitting: | ||||
| 1068 | // 0 = false or DOWN, 1 = true or UP | ||||
| 1069 | // | ||||
| 1070 | // Overlap | DEF | USE | Action | ||||
| 1071 | //------------------------------------------------------- | ||||
| 1072 | // 0 | 0 | 0 | Copy - mem -> mem | ||||
| 1073 | // 0 | 0 | 1 | Split-UP - Check HRP | ||||
| 1074 | // 0 | 1 | 0 | Split-DOWN - Debug Info? | ||||
| 1075 | // 0 | 1 | 1 | Copy - reg -> reg | ||||
| 1076 | // 1 | 0 | 0 | Reset Input Edge (no Split) | ||||
| 1077 | // 1 | 0 | 1 | Split-UP - Check HRP | ||||
| 1078 | // 1 | 1 | 0 | Split-DOWN - Debug Info? | ||||
| 1079 | // 1 | 1 | 1 | Reset Input Edge (no Split) | ||||
| 1080 | // | ||||
| 1081 | // So, if (dup == uup), then overlap test determines action, | ||||
| 1082 | // with true being no split, and false being copy. Else, | ||||
| 1083 | // if DEF is DOWN, Split-UP, and check HRP to decide on | ||||
| 1084 | // resetting DEF. Finally if DEF is UP, Split-DOWN, with | ||||
| 1085 | // special handling for Debug Info. | ||||
| 1086 | if( dup == uup ) { | ||||
| 1087 | if( dmask.overlap(umask) ) { | ||||
| 1088 | // Both are either up or down, and there is overlap, No Split | ||||
| 1089 | n->set_req(inpidx, def); | ||||
| 1090 | } | ||||
| 1091 | else { // Both are either up or down, and there is no overlap | ||||
| 1092 | if( dup ) { // If UP, reg->reg copy | ||||
| 1093 | // COPY ACROSS HERE - NO DEF - NO CISC SPILL | ||||
| 1094 | int delta = split_USE(MachSpillCopyNode::RegToReg, def,b,n,inpidx,maxlrg,false,false, splits,slidx); | ||||
| 1095 | // If it wasn't split bail | ||||
| 1096 | if (delta < 0) { | ||||
| 1097 | return 0; | ||||
| 1098 | } | ||||
| 1099 | maxlrg += delta; | ||||
| 1100 | insidx += delta; // Reset iterator to skip USE side split | ||||
| 1101 | } | ||||
| 1102 | else { // DOWN, mem->mem copy | ||||
| 1103 | // COPY UP & DOWN HERE - NO DEF - NO CISC SPILL | ||||
| 1104 | // First Split-UP to move value into Register | ||||
| 1105 | uint def_ideal = def->ideal_reg(); | ||||
| 1106 | const RegMask* tmp_rm = Matcher::idealreg2regmask[def_ideal]; | ||||
| 1107 | Node *spill = new MachSpillCopyNode(MachSpillCopyNode::MemToReg, def, dmask, *tmp_rm); | ||||
| 1108 | insert_proj( b, insidx, spill, maxlrg ); | ||||
| 1109 | maxlrg++; insidx++; | ||||
| 1110 | // Then Split-DOWN as if previous Split was DEF | ||||
| 1111 | int delta = split_USE(MachSpillCopyNode::RegToMem, spill,b,n,inpidx,maxlrg,false,false, splits,slidx); | ||||
| 1112 | // If it wasn't split bail | ||||
| 1113 | if (delta < 0) { | ||||
| 1114 | return 0; | ||||
| 1115 | } | ||||
| 1116 | maxlrg += delta; | ||||
| 1117 | insidx += delta; // Reset iterator to skip USE side splits | ||||
| 1118 | } | ||||
| 1119 | } // End else no overlap | ||||
| 1120 | } // End if dup == uup | ||||
| 1121 | // dup != uup, so check dup for direction of Split | ||||
| 1122 | else { | ||||
| 1123 | if( dup ) { // If UP, Split-DOWN and check Debug Info | ||||
| 1124 | // If this node is already a SpillCopy, just patch the edge | ||||
| 1125 | // except the case of spilling to stack. | ||||
| 1126 | if( n->is_SpillCopy() ) { | ||||
| 1127 | RegMask tmp_rm(umask); | ||||
| 1128 | tmp_rm.SUBTRACT(Matcher::STACK_ONLY_mask); | ||||
| 1129 | if( dmask.overlap(tmp_rm) ) { | ||||
| 1130 | if( def != n->in(inpidx) ) { | ||||
| 1131 | n->set_req(inpidx, def); | ||||
| 1132 | } | ||||
| 1133 | continue; | ||||
| 1134 | } | ||||
| 1135 | } | ||||
| 1136 | // COPY DOWN HERE - NO DEF - NO CISC SPILL | ||||
| 1137 | int delta = split_USE(MachSpillCopyNode::RegToMem, def,b,n,inpidx,maxlrg,false,false, splits,slidx); | ||||
| 1138 | // If it wasn't split bail | ||||
| 1139 | if (delta < 0) { | ||||
| 1140 | return 0; | ||||
| 1141 | } | ||||
| 1142 | maxlrg += delta; | ||||
| 1143 | insidx += delta; // Reset iterator to skip USE side split | ||||
| 1144 | // Check for debug-info split. Capture it for later | ||||
| 1145 | // debug splits of the same value | ||||
| 1146 | if (jvms && jvms->debug_start() <= inpidx && inpidx < oopoff) | ||||
| 1147 | debug_defs[slidx] = n->in(inpidx); | ||||
| 1148 | |||||
| 1149 | } | ||||
| 1150 | else { // DOWN, Split-UP and check register pressure | ||||
| 1151 | if( is_high_pressure( b, &lrgs(useidx), insidx ) ) { | ||||
| 1152 | // COPY UP HERE - NO DEF - CISC SPILL | ||||
| 1153 | int delta = split_USE(MachSpillCopyNode::MemToReg, def,b,n,inpidx,maxlrg,true,true, splits,slidx); | ||||
| 1154 | // If it wasn't split bail | ||||
| 1155 | if (delta < 0) { | ||||
| 1156 | return 0; | ||||
| 1157 | } | ||||
| 1158 | maxlrg += delta; | ||||
| 1159 | insidx += delta; // Reset iterator to skip USE side split | ||||
| 1160 | } else { // LRP | ||||
| 1161 | // COPY UP HERE - WITH DEF - NO CISC SPILL | ||||
| 1162 | int delta = split_USE(MachSpillCopyNode::MemToReg, def,b,n,inpidx,maxlrg,true,false, splits,slidx); | ||||
| 1163 | // If it wasn't split bail | ||||
| 1164 | if (delta < 0) { | ||||
| 1165 | return 0; | ||||
| 1166 | } | ||||
| 1167 | // Flag this lift-up in a low-pressure block as | ||||
| 1168 | // already-spilled, so if it spills again it will | ||||
| 1169 | // spill hard (instead of not spilling hard and | ||||
| 1170 | // coalescing away). | ||||
| 1171 | set_was_spilled(n->in(inpidx)); | ||||
| 1172 | // Since this is a new DEF, update Reachblock & UP | ||||
| 1173 | Reachblock[slidx] = n->in(inpidx); | ||||
| 1174 | UPblock[slidx] = true; | ||||
| 1175 | maxlrg += delta; | ||||
| 1176 | insidx += delta; // Reset iterator to skip USE side split | ||||
| 1177 | } | ||||
| 1178 | } // End else DOWN | ||||
| 1179 | } // End dup != uup | ||||
| 1180 | } // End if Spill USE | ||||
| 1181 | } // End For All Inputs | ||||
| 1182 | } // End If not nullcheck | ||||
| 1183 | |||||
| 1184 | // ********** Handle DEFS ********** | ||||
| 1185 | // DEFS either Split DOWN in HRP regions or when the LRG is bound, or | ||||
| 1186 | // just reset the Reaches info in LRP regions. DEFS must always update | ||||
| 1187 | // UP info. | ||||
| 1188 | if( deflrg.reg() >= LRG::SPILL_REG ) { // Spilled? | ||||
| 1189 | uint slidx = lrg2reach[defidx]; | ||||
| 1190 | // Add to defs list for later assignment of new live range number | ||||
| 1191 | defs->push(n); | ||||
| 1192 | // Set a flag on the Node indicating it has already spilled. | ||||
| 1193 | // Only do it for capacity spills not conflict spills. | ||||
| 1194 | if( !deflrg._direct_conflict ) | ||||
| 1195 | set_was_spilled(n); | ||||
| 1196 | assert(!n->is_Phi(),"Cannot insert Phi into DEFS list")do { if (!(!n->is_Phi())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/reg_split.cpp" , 1196, "assert(" "!n->is_Phi()" ") failed", "Cannot insert Phi into DEFS list" ); ::breakpoint(); } } while (0); | ||||
| 1197 | // Grab UP info for DEF | ||||
| 1198 | const RegMask &dmask = n->out_RegMask(); | ||||
| 1199 | bool defup = dmask.is_UP(); | ||||
| 1200 | uint ireg = n->ideal_reg(); | ||||
| 1201 | bool is_vect = RegMask::is_vector(ireg); | ||||
| 1202 | // Only split at Def if this is a HRP block or bound (and spilled once) | ||||
| 1203 | if( !n->rematerialize() && | ||||
| 1204 | (((dmask.is_bound(ireg) || (!is_vect && dmask.is_misaligned_pair())) && | ||||
| 1205 | (deflrg._direct_conflict || deflrg._must_spill)) || | ||||
| 1206 | // Check for LRG being up in a register and we are inside a high | ||||
| 1207 | // pressure area. Spill it down immediately. | ||||
| 1208 | (defup && is_high_pressure(b,&deflrg,insidx) && !n->is_SpillCopy())) ) { | ||||
| 1209 | assert( !n->rematerialize(), "" )do { if (!(!n->rematerialize())) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/reg_split.cpp" , 1209, "assert(" "!n->rematerialize()" ") failed", ""); :: breakpoint(); } } while (0); | ||||
| 1210 | // Do a split at the def site. | ||||
| 1211 | maxlrg = split_DEF( n, b, insidx, maxlrg, Reachblock, debug_defs, splits, slidx ); | ||||
| 1212 | // If it wasn't split bail | ||||
| 1213 | if (!maxlrg) { | ||||
| 1214 | return 0; | ||||
| 1215 | } | ||||
| 1216 | // Split DEF's Down | ||||
| 1217 | UPblock[slidx] = 0; | ||||
| 1218 | #ifndef PRODUCT | ||||
| 1219 | // DEBUG | ||||
| 1220 | if( trace_spilling() ) { | ||||
| 1221 | tty->print("\nNew Split DOWN DEF of Spill Idx "); | ||||
| 1222 | tty->print("%d, UP %d:\n",slidx,false); | ||||
| 1223 | n->dump(); | ||||
| 1224 | } | ||||
| 1225 | #endif | ||||
| 1226 | } | ||||
| 1227 | else { // Neither bound nor HRP, must be LRP | ||||
| 1228 | // otherwise, just record the def | ||||
| 1229 | Reachblock[slidx] = n; | ||||
| 1230 | // UP should come from the outRegmask() of the DEF | ||||
| 1231 | UPblock[slidx] = defup; | ||||
| 1232 | // Update debug list of reaching down definitions, kill if DEF is UP | ||||
| 1233 | debug_defs[slidx] = defup ? NULL__null : n; | ||||
| 1234 | #ifndef PRODUCT | ||||
| 1235 | // DEBUG | ||||
| 1236 | if( trace_spilling() ) { | ||||
| 1237 | tty->print("\nNew DEF of Spill Idx "); | ||||
| 1238 | tty->print("%d, UP %d:\n",slidx,defup); | ||||
| 1239 | n->dump(); | ||||
| 1240 | } | ||||
| 1241 | #endif | ||||
| 1242 | } // End else LRP | ||||
| 1243 | } // End if spill def | ||||
| 1244 | |||||
| 1245 | // ********** Split Left Over Mem-Mem Moves ********** | ||||
| 1246 | // Check for mem-mem copies and split them now. Do not do this | ||||
| 1247 | // to copies about to be spilled; they will be Split shortly. | ||||
| 1248 | if (copyidx) { | ||||
| 1249 | Node *use = n->in(copyidx); | ||||
| 1250 | uint useidx = _lrg_map.find_id(use); | ||||
| 1251 | if (useidx < _lrg_map.max_lrg_id() && // This is not a new split | ||||
| 1252 | OptoReg::is_stack(deflrg.reg()) && | ||||
| 1253 | deflrg.reg() < LRG::SPILL_REG ) { // And DEF is from stack | ||||
| 1254 | LRG &uselrg = lrgs(useidx); | ||||
| 1255 | if( OptoReg::is_stack(uselrg.reg()) && | ||||
| 1256 | uselrg.reg() < LRG::SPILL_REG && // USE is from stack | ||||
| 1257 | deflrg.reg() != uselrg.reg() ) { // Not trivially removed | ||||
| 1258 | uint def_ideal_reg = n->bottom_type()->ideal_reg(); | ||||
| 1259 | const RegMask &def_rm = *Matcher::idealreg2regmask[def_ideal_reg]; | ||||
| 1260 | const RegMask &use_rm = n->in_RegMask(copyidx); | ||||
| 1261 | if( def_rm.overlap(use_rm) && n->is_SpillCopy() ) { // Bug 4707800, 'n' may be a storeSSL | ||||
| 1262 | if (C->check_node_count(NodeLimitFudgeFactor, out_of_nodes)) { // Check when generating nodes | ||||
| 1263 | return 0; | ||||
| 1264 | } | ||||
| 1265 | Node *spill = new MachSpillCopyNode(MachSpillCopyNode::MemToReg, use,use_rm,def_rm); | ||||
| 1266 | n->set_req(copyidx,spill); | ||||
| 1267 | n->as_MachSpillCopy()->set_in_RegMask(def_rm); | ||||
| 1268 | // Put the spill just before the copy | ||||
| 1269 | insert_proj( b, insidx++, spill, maxlrg++ ); | ||||
| 1270 | } | ||||
| 1271 | } | ||||
| 1272 | } | ||||
| 1273 | } | ||||
| 1274 | } // End For All Instructions in Block - Non-PHI Pass | ||||
| 1275 | |||||
| 1276 | // Check if each LRG is live out of this block so as not to propagate | ||||
| 1277 | // beyond the last use of a LRG. | ||||
| 1278 | for( slidx = 0; slidx < spill_cnt; slidx++ ) { | ||||
| 1279 | uint defidx = lidxs.at(slidx); | ||||
| 1280 | IndexSet *liveout = _live->live(b); | ||||
| 1281 | if( !liveout->member(defidx) ) { | ||||
| 1282 | #ifdef ASSERT1 | ||||
| 1283 | if (VerifyRegisterAllocator) { | ||||
| 1284 | // The index defidx is not live. Check the liveout array to ensure that | ||||
| 1285 | // it contains no members which compress to defidx. Finding such an | ||||
| 1286 | // instance may be a case to add liveout adjustment in compress_uf_map(). | ||||
| 1287 | // See 5063219. | ||||
| 1288 | if (!liveout->is_empty()) { | ||||
| 1289 | uint member; | ||||
| 1290 | IndexSetIterator isi(liveout); | ||||
| 1291 | while ((member = isi.next()) != 0) { | ||||
| 1292 | assert(defidx != _lrg_map.find_const(member), "Live out member has not been compressed")do { if (!(defidx != _lrg_map.find_const(member))) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/reg_split.cpp" , 1292, "assert(" "defidx != _lrg_map.find_const(member)" ") failed" , "Live out member has not been compressed"); ::breakpoint(); } } while (0); | ||||
| 1293 | } | ||||
| 1294 | } | ||||
| 1295 | } | ||||
| 1296 | #endif | ||||
| 1297 | Reachblock[slidx] = NULL__null; | ||||
| 1298 | } else { | ||||
| 1299 | assert(Reachblock[slidx] != NULL,"No reaching definition for liveout value")do { if (!(Reachblock[slidx] != __null)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/reg_split.cpp" , 1299, "assert(" "Reachblock[slidx] != __null" ") failed", "No reaching definition for liveout value" ); ::breakpoint(); } } while (0); | ||||
| 1300 | } | ||||
| 1301 | } | ||||
| 1302 | #ifndef PRODUCT | ||||
| 1303 | if( trace_spilling() ) | ||||
| 1304 | b->dump(); | ||||
| 1305 | #endif | ||||
| 1306 | } // End For All Blocks | ||||
| 1307 | |||||
| 1308 | //----------PASS 2---------- | ||||
| 1309 | // Reset all DEF live range numbers here | ||||
| 1310 | for( insidx = 0; insidx < defs->size(); insidx++ ) { | ||||
| 1311 | // Grab the def | ||||
| 1312 | n1 = defs->at(insidx); | ||||
| 1313 | // Set new lidx for DEF | ||||
| 1314 | new_lrg(n1, maxlrg++); | ||||
| 1315 | } | ||||
| 1316 | //----------Phi Node Splitting---------- | ||||
| 1317 | // Clean up a phi here, and assign a new live range number | ||||
| 1318 | // Cycle through this block's predecessors, collecting Reaches | ||||
| 1319 | // info for each spilled LRG and update edges. | ||||
| 1320 | // Walk the phis list to patch inputs, split phis, and name phis | ||||
| 1321 | uint lrgs_before_phi_split = maxlrg; | ||||
| 1322 | for( insidx = 0; insidx < phis->size(); insidx++ ) { | ||||
| 1323 | Node *phi = phis->at(insidx); | ||||
| 1324 | assert(phi->is_Phi(),"This list must only contain Phi Nodes")do { if (!(phi->is_Phi())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/reg_split.cpp" , 1324, "assert(" "phi->is_Phi()" ") failed", "This list must only contain Phi Nodes" ); ::breakpoint(); } } while (0); | ||||
| 1325 | Block *b = _cfg.get_block_for_node(phi); | ||||
| 1326 | // Grab the live range number | ||||
| 1327 | uint lidx = _lrg_map.find_id(phi); | ||||
| 1328 | uint slidx = lrg2reach[lidx]; | ||||
| 1329 | // Update node to lidx map | ||||
| 1330 | new_lrg(phi, maxlrg++); | ||||
| 1331 | // Get PASS1's up/down decision for the block. | ||||
| 1332 | int phi_up = !!UP_entry[slidx]->test(b->_pre_order); | ||||
| 1333 | |||||
| 1334 | // Force down if double-spilling live range | ||||
| 1335 | if( lrgs(lidx)._was_spilled1 ) | ||||
| 1336 | phi_up = false; | ||||
| 1337 | |||||
| 1338 | // When splitting a Phi we an split it normal or "inverted". | ||||
| 1339 | // An inverted split makes the splits target the Phi's UP/DOWN | ||||
| 1340 | // sense inverted; then the Phi is followed by a final def-side | ||||
| 1341 | // split to invert back. It changes which blocks the spill code | ||||
| 1342 | // goes in. | ||||
| 1343 | |||||
| 1344 | // Walk the predecessor blocks and assign the reaching def to the Phi. | ||||
| 1345 | // Split Phi nodes by placing USE side splits wherever the reaching | ||||
| 1346 | // DEF has the wrong UP/DOWN value. | ||||
| 1347 | for( uint i = 1; i < b->num_preds(); i++ ) { | ||||
| 1348 | // Get predecessor block pre-order number | ||||
| 1349 | Block *pred = _cfg.get_block_for_node(b->pred(i)); | ||||
| 1350 | pidx = pred->_pre_order; | ||||
| 1351 | // Grab reaching def | ||||
| 1352 | Node *def = Reaches[pidx][slidx]; | ||||
| 1353 | Node** Reachblock = Reaches[pidx]; | ||||
| 1354 | assert( def, "must have reaching def" )do { if (!(def)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/reg_split.cpp" , 1354, "assert(" "def" ") failed", "must have reaching def") ; ::breakpoint(); } } while (0); | ||||
| 1355 | // If input up/down sense and reg-pressure DISagree | ||||
| 1356 | if (def->rematerialize()) { | ||||
| 1357 | // Place the rematerialized node above any MSCs created during | ||||
| 1358 | // phi node splitting. end_idx points at the insertion point | ||||
| 1359 | // so look at the node before it. | ||||
| 1360 | int insert = pred->end_idx(); | ||||
| 1361 | while (insert >= 1 && | ||||
| 1362 | pred->get_node(insert - 1)->is_SpillCopy() && | ||||
| 1363 | _lrg_map.find(pred->get_node(insert - 1)) >= lrgs_before_phi_split) { | ||||
| 1364 | insert--; | ||||
| 1365 | } | ||||
| 1366 | def = split_Rematerialize(def, pred, insert, maxlrg, splits, slidx, lrg2reach, Reachblock, false); | ||||
| 1367 | if (!def) { | ||||
| 1368 | return 0; // Bail out | ||||
| 1369 | } | ||||
| 1370 | } | ||||
| 1371 | // Update the Phi's input edge array | ||||
| 1372 | phi->set_req(i,def); | ||||
| 1373 | // Grab the UP/DOWN sense for the input | ||||
| 1374 | u1 = UP[pidx][slidx]; | ||||
| 1375 | if( u1 != (phi_up != 0)) { | ||||
| 1376 | int delta = split_USE(MachSpillCopyNode::PhiLocationDifferToInputLocation, def, b, phi, i, maxlrg, !u1, false, splits,slidx); | ||||
| 1377 | // If it wasn't split bail | ||||
| 1378 | if (delta < 0) { | ||||
| 1379 | return 0; | ||||
| 1380 | } | ||||
| 1381 | maxlrg += delta; | ||||
| 1382 | } | ||||
| 1383 | } // End for all inputs to the Phi | ||||
| 1384 | } // End for all Phi Nodes | ||||
| 1385 | // Update _maxlrg to save Union asserts | ||||
| 1386 | _lrg_map.set_max_lrg_id(maxlrg); | ||||
| 1387 | |||||
| 1388 | |||||
| 1389 | //----------PASS 3---------- | ||||
| 1390 | // Pass over all Phi's to union the live ranges | ||||
| 1391 | for( insidx = 0; insidx < phis->size(); insidx++ ) { | ||||
| 1392 | Node *phi = phis->at(insidx); | ||||
| 1393 | assert(phi->is_Phi(),"This list must only contain Phi Nodes")do { if (!(phi->is_Phi())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/reg_split.cpp" , 1393, "assert(" "phi->is_Phi()" ") failed", "This list must only contain Phi Nodes" ); ::breakpoint(); } } while (0); | ||||
| 1394 | // Walk all inputs to Phi and Union input live range with Phi live range | ||||
| 1395 | for( uint i = 1; i < phi->req(); i++ ) { | ||||
| 1396 | // Grab the input node | ||||
| 1397 | Node *n = phi->in(i); | ||||
| 1398 | assert(n, "node should exist")do { if (!(n)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/reg_split.cpp" , 1398, "assert(" "n" ") failed", "node should exist"); ::breakpoint (); } } while (0); | ||||
| 1399 | uint lidx = _lrg_map.find(n); | ||||
| 1400 | uint pidx = _lrg_map.find(phi); | ||||
| 1401 | if (lidx < pidx) { | ||||
| 1402 | Union(n, phi); | ||||
| 1403 | } | ||||
| 1404 | else if(lidx > pidx) { | ||||
| 1405 | Union(phi, n); | ||||
| 1406 | } | ||||
| 1407 | } // End for all inputs to the Phi Node | ||||
| 1408 | } // End for all Phi Nodes | ||||
| 1409 | // Now union all two address instructions | ||||
| 1410 | for (insidx = 0; insidx < defs->size(); insidx++) { | ||||
| 1411 | // Grab the def | ||||
| 1412 | n1 = defs->at(insidx); | ||||
| 1413 | // Set new lidx for DEF & handle 2-addr instructions | ||||
| 1414 | if (n1->is_Mach() && ((twoidx = n1->as_Mach()->two_adr()) != 0)) { | ||||
| 1415 | assert(_lrg_map.find(n1->in(twoidx)) < maxlrg,"Assigning bad live range index")do { if (!(_lrg_map.find(n1->in(twoidx)) < maxlrg)) { ( *g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/reg_split.cpp" , 1415, "assert(" "_lrg_map.find(n1->in(twoidx)) < maxlrg" ") failed", "Assigning bad live range index"); ::breakpoint( ); } } while (0); | ||||
| 1416 | // Union the input and output live ranges | ||||
| 1417 | uint lr1 = _lrg_map.find(n1); | ||||
| 1418 | uint lr2 = _lrg_map.find(n1->in(twoidx)); | ||||
| 1419 | if (lr1 < lr2) { | ||||
| 1420 | Union(n1, n1->in(twoidx)); | ||||
| 1421 | } | ||||
| 1422 | else if (lr1 > lr2) { | ||||
| 1423 | Union(n1->in(twoidx), n1); | ||||
| 1424 | } | ||||
| 1425 | } // End if two address | ||||
| 1426 | } // End for all defs | ||||
| 1427 | // DEBUG | ||||
| 1428 | #ifdef ASSERT1 | ||||
| 1429 | // Validate all live range index assignments | ||||
| 1430 | for (bidx = 0; bidx < _cfg.number_of_blocks(); bidx++) { | ||||
| 1431 | b = _cfg.get_block(bidx); | ||||
| 1432 | for (insidx = 0; insidx <= b->end_idx(); insidx++) { | ||||
| 1433 | Node *n = b->get_node(insidx); | ||||
| 1434 | uint defidx = _lrg_map.find(n); | ||||
| 1435 | assert(defidx < _lrg_map.max_lrg_id(), "Bad live range index in Split")do { if (!(defidx < _lrg_map.max_lrg_id())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/reg_split.cpp" , 1435, "assert(" "defidx < _lrg_map.max_lrg_id()" ") failed" , "Bad live range index in Split"); ::breakpoint(); } } while (0); | ||||
| 1436 | assert(defidx < maxlrg,"Bad live range index in Split")do { if (!(defidx < maxlrg)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/opto/reg_split.cpp" , 1436, "assert(" "defidx < maxlrg" ") failed", "Bad live range index in Split" ); ::breakpoint(); } } while (0); | ||||
| 1437 | } | ||||
| 1438 | } | ||||
| 1439 | // Issue a warning if splitting made no progress | ||||
| 1440 | int noprogress = 0; | ||||
| 1441 | for (slidx = 0; slidx < spill_cnt; slidx++) { | ||||
| 1442 | if (PrintOpto && WizardMode && splits.at(slidx) == 0) { | ||||
| 1443 | tty->print_cr("Failed to split live range %d", lidxs.at(slidx)); | ||||
| 1444 | //BREAKPOINT; | ||||
| 1445 | } | ||||
| 1446 | else { | ||||
| 1447 | noprogress++; | ||||
| 1448 | } | ||||
| 1449 | } | ||||
| 1450 | if(!noprogress) { | ||||
| 1451 | tty->print_cr("Failed to make progress in Split"); | ||||
| 1452 | //BREAKPOINT; | ||||
| 1453 | } | ||||
| 1454 | #endif | ||||
| 1455 | // Return updated count of live ranges | ||||
| 1456 | return maxlrg; | ||||
| 1457 | } |