Fri, 12 Feb 2010 15:27:36 -0800
Merge
duke@435 | 1 | /* |
xdono@1383 | 2 | * Copyright 2005-2009 Sun Microsystems, Inc. All Rights Reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
duke@435 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@435 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@435 | 21 | * have any questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
duke@435 | 25 | #include "incls/_precompiled.incl" |
duke@435 | 26 | #include "incls/_idealKit.cpp.incl" |
duke@435 | 27 | |
duke@435 | 28 | // Static initialization |
duke@435 | 29 | |
duke@435 | 30 | // This declares the position where vars are kept in the cvstate |
duke@435 | 31 | // For some degree of consistency we use the TypeFunc enum to |
duke@435 | 32 | // soak up spots in the inputs even though we only use early Control |
duke@435 | 33 | // and Memory slots. (So far.) |
duke@435 | 34 | const uint IdealKit::first_var = TypeFunc::Parms + 1; |
duke@435 | 35 | |
duke@435 | 36 | //----------------------------IdealKit----------------------------------------- |
kvn@1286 | 37 | IdealKit::IdealKit(PhaseGVN &gvn, Node* control, Node* mem, bool delay_all_transforms, bool has_declarations) : |
duke@435 | 38 | _gvn(gvn), C(gvn.C) { |
duke@435 | 39 | _initial_ctrl = control; |
duke@435 | 40 | _initial_memory = mem; |
duke@435 | 41 | _delay_all_transforms = delay_all_transforms; |
duke@435 | 42 | _var_ct = 0; |
duke@435 | 43 | _cvstate = NULL; |
duke@435 | 44 | // We can go memory state free or else we need the entire memory state |
duke@435 | 45 | assert(mem == NULL || mem->Opcode() == Op_MergeMem, "memory must be pre-split"); |
duke@435 | 46 | int init_size = 5; |
duke@435 | 47 | _pending_cvstates = new (C->node_arena()) GrowableArray<Node*>(C->node_arena(), init_size, 0, 0); |
duke@435 | 48 | _delay_transform = new (C->node_arena()) GrowableArray<Node*>(C->node_arena(), init_size, 0, 0); |
duke@435 | 49 | DEBUG_ONLY(_state = new (C->node_arena()) GrowableArray<int>(C->node_arena(), init_size, 0, 0)); |
kvn@1286 | 50 | if (!has_declarations) { |
kvn@1286 | 51 | declarations_done(); |
kvn@1286 | 52 | } |
duke@435 | 53 | } |
duke@435 | 54 | |
duke@435 | 55 | //-------------------------------if_then------------------------------------- |
duke@435 | 56 | // Create: if(left relop right) |
duke@435 | 57 | // / \ |
duke@435 | 58 | // iffalse iftrue |
duke@435 | 59 | // Push the iffalse cvstate onto the stack. The iftrue becomes the current cvstate. |
duke@435 | 60 | void IdealKit::if_then(Node* left, BoolTest::mask relop, |
duke@435 | 61 | Node* right, float prob, float cnt, bool push_new_state) { |
duke@435 | 62 | assert((state() & (BlockS|LoopS|IfThenS|ElseS)), "bad state for new If"); |
duke@435 | 63 | Node* bol; |
duke@435 | 64 | if (left->bottom_type()->isa_ptr() == NULL) { |
duke@435 | 65 | if (left->bottom_type()->isa_int() != NULL) { |
duke@435 | 66 | bol = Bool(CmpI(left, right), relop); |
duke@435 | 67 | } else { |
duke@435 | 68 | assert(left->bottom_type()->isa_long() != NULL, "what else?"); |
duke@435 | 69 | bol = Bool(CmpL(left, right), relop); |
duke@435 | 70 | } |
duke@435 | 71 | |
duke@435 | 72 | } else { |
duke@435 | 73 | bol = Bool(CmpP(left, right), relop); |
duke@435 | 74 | } |
duke@435 | 75 | // Delay gvn.tranform on if-nodes until construction is finished |
duke@435 | 76 | // to prevent a constant bool input from discarding a control output. |
duke@435 | 77 | IfNode* iff = delay_transform(new (C, 2) IfNode(ctrl(), bol, prob, cnt))->as_If(); |
duke@435 | 78 | Node* then = IfTrue(iff); |
duke@435 | 79 | Node* elsen = IfFalse(iff); |
duke@435 | 80 | Node* else_cvstate = copy_cvstate(); |
duke@435 | 81 | else_cvstate->set_req(TypeFunc::Control, elsen); |
duke@435 | 82 | _pending_cvstates->push(else_cvstate); |
duke@435 | 83 | DEBUG_ONLY(if (push_new_state) _state->push(IfThenS)); |
duke@435 | 84 | set_ctrl(then); |
duke@435 | 85 | } |
duke@435 | 86 | |
duke@435 | 87 | //-------------------------------else_------------------------------------- |
duke@435 | 88 | // Pop the else cvstate off the stack, and push the (current) then cvstate. |
duke@435 | 89 | // The else cvstate becomes the current cvstate. |
duke@435 | 90 | void IdealKit::else_() { |
duke@435 | 91 | assert(state() == IfThenS, "bad state for new Else"); |
duke@435 | 92 | Node* else_cvstate = _pending_cvstates->pop(); |
duke@435 | 93 | DEBUG_ONLY(_state->pop()); |
duke@435 | 94 | // save current (then) cvstate for later use at endif |
duke@435 | 95 | _pending_cvstates->push(_cvstate); |
duke@435 | 96 | DEBUG_ONLY(_state->push(ElseS)); |
duke@435 | 97 | _cvstate = else_cvstate; |
duke@435 | 98 | } |
duke@435 | 99 | |
duke@435 | 100 | //-------------------------------end_if------------------------------------- |
duke@435 | 101 | // Merge the "then" and "else" cvstates. |
duke@435 | 102 | // |
kvn@1286 | 103 | // The if_then() pushed a copy of the current state for later use |
duke@435 | 104 | // as the initial state for a future "else" clause. The |
duke@435 | 105 | // current state then became the initial state for the |
duke@435 | 106 | // then clause. If an "else" clause was encountered, it will |
duke@435 | 107 | // pop the top state and use it for it's initial state. |
duke@435 | 108 | // It will also push the current state (the state at the end of |
duke@435 | 109 | // the "then" clause) for latter use at the end_if. |
duke@435 | 110 | // |
duke@435 | 111 | // At the endif, the states are: |
duke@435 | 112 | // 1) else exists a) current state is end of "else" clause |
duke@435 | 113 | // b) top stack state is end of "then" clause |
duke@435 | 114 | // |
duke@435 | 115 | // 2) no else: a) current state is end of "then" clause |
duke@435 | 116 | // b) top stack state is from the "if_then" which |
duke@435 | 117 | // would have been the initial state of the else. |
duke@435 | 118 | // |
duke@435 | 119 | // Merging the states is accomplished by: |
duke@435 | 120 | // 1) make a label for the merge |
duke@435 | 121 | // 2) terminate the current state with a goto to the label |
duke@435 | 122 | // 3) pop the top state from the stack and make it the |
duke@435 | 123 | // current state |
duke@435 | 124 | // 4) bind the label at the current state. Binding a label |
duke@435 | 125 | // terminates the current state with a goto to the |
duke@435 | 126 | // label and makes the label's state the current state. |
duke@435 | 127 | // |
duke@435 | 128 | void IdealKit::end_if() { |
duke@435 | 129 | assert(state() & (IfThenS|ElseS), "bad state for new Endif"); |
duke@435 | 130 | Node* lab = make_label(1); |
duke@435 | 131 | |
duke@435 | 132 | // Node* join_state = _pending_cvstates->pop(); |
duke@435 | 133 | /* merging, join */ |
duke@435 | 134 | goto_(lab); |
duke@435 | 135 | _cvstate = _pending_cvstates->pop(); |
duke@435 | 136 | |
duke@435 | 137 | bind(lab); |
duke@435 | 138 | DEBUG_ONLY(_state->pop()); |
duke@435 | 139 | } |
duke@435 | 140 | |
duke@435 | 141 | //-------------------------------loop------------------------------------- |
duke@435 | 142 | // Create the loop head portion (*) of: |
duke@435 | 143 | // * iv = init |
duke@435 | 144 | // * top: (region node) |
duke@435 | 145 | // * if (iv relop limit) { |
duke@435 | 146 | // loop body |
duke@435 | 147 | // i = i + 1 |
duke@435 | 148 | // goto top |
duke@435 | 149 | // * } else // exits loop |
duke@435 | 150 | // |
duke@435 | 151 | // Pushes the loop top cvstate first, then the else (loop exit) cvstate |
duke@435 | 152 | // onto the stack. |
duke@435 | 153 | void IdealKit::loop(IdealVariable& iv, Node* init, BoolTest::mask relop, Node* limit, float prob, float cnt) { |
duke@435 | 154 | assert((state() & (BlockS|LoopS|IfThenS|ElseS)), "bad state for new loop"); |
duke@435 | 155 | set(iv, init); |
duke@435 | 156 | Node* head = make_label(1); |
duke@435 | 157 | bind(head); |
duke@435 | 158 | _pending_cvstates->push(head); // push for use at end_loop |
duke@435 | 159 | _cvstate = copy_cvstate(); |
duke@435 | 160 | if_then(value(iv), relop, limit, prob, cnt, false /* no new state */); |
duke@435 | 161 | DEBUG_ONLY(_state->push(LoopS)); |
duke@435 | 162 | assert(ctrl()->is_IfTrue(), "true branch stays in loop"); |
duke@435 | 163 | assert(_pending_cvstates->top()->in(TypeFunc::Control)->is_IfFalse(), "false branch exits loop"); |
duke@435 | 164 | } |
duke@435 | 165 | |
duke@435 | 166 | //-------------------------------end_loop------------------------------------- |
duke@435 | 167 | // Creates the goto top label. |
duke@435 | 168 | // Expects the else (loop exit) cvstate to be on top of the |
duke@435 | 169 | // stack, and the loop top cvstate to be 2nd. |
duke@435 | 170 | void IdealKit::end_loop() { |
duke@435 | 171 | assert((state() == LoopS), "bad state for new end_loop"); |
duke@435 | 172 | Node* exit = _pending_cvstates->pop(); |
duke@435 | 173 | Node* head = _pending_cvstates->pop(); |
duke@435 | 174 | goto_(head); |
duke@435 | 175 | clear(head); |
duke@435 | 176 | DEBUG_ONLY(_state->pop()); |
duke@435 | 177 | _cvstate = exit; |
duke@435 | 178 | } |
duke@435 | 179 | |
duke@435 | 180 | //-------------------------------make_label------------------------------------- |
duke@435 | 181 | // Creates a label. The number of goto's |
duke@435 | 182 | // must be specified (which should be 1 less than |
duke@435 | 183 | // the number of precedessors.) |
duke@435 | 184 | Node* IdealKit::make_label(int goto_ct) { |
duke@435 | 185 | assert(_cvstate != NULL, "must declare variables before labels"); |
duke@435 | 186 | Node* lab = new_cvstate(); |
duke@435 | 187 | int sz = 1 + goto_ct + 1 /* fall thru */; |
duke@435 | 188 | Node* reg = delay_transform(new (C, sz) RegionNode(sz)); |
duke@435 | 189 | lab->init_req(TypeFunc::Control, reg); |
duke@435 | 190 | return lab; |
duke@435 | 191 | } |
duke@435 | 192 | |
duke@435 | 193 | //-------------------------------bind------------------------------------- |
duke@435 | 194 | // Bind a label at the current cvstate by simulating |
duke@435 | 195 | // a goto to the label. |
duke@435 | 196 | void IdealKit::bind(Node* lab) { |
duke@435 | 197 | goto_(lab, true /* bind */); |
duke@435 | 198 | _cvstate = lab; |
duke@435 | 199 | } |
duke@435 | 200 | |
duke@435 | 201 | //-------------------------------goto_------------------------------------- |
duke@435 | 202 | // Make the current cvstate a predecessor of the label, |
duke@435 | 203 | // creating phi's to merge values. If bind is true and |
duke@435 | 204 | // this is not the last control edge, then ensure that |
duke@435 | 205 | // all live values have phis created. Used to create phis |
duke@435 | 206 | // at loop-top regions. |
duke@435 | 207 | void IdealKit::goto_(Node* lab, bool bind) { |
duke@435 | 208 | Node* reg = lab->in(TypeFunc::Control); |
duke@435 | 209 | // find next empty slot in region |
duke@435 | 210 | uint slot = 1; |
duke@435 | 211 | while (slot < reg->req() && reg->in(slot) != NULL) slot++; |
duke@435 | 212 | assert(slot < reg->req(), "too many gotos"); |
duke@435 | 213 | // If this is last predecessor, then don't force phi creation |
duke@435 | 214 | if (slot == reg->req() - 1) bind = false; |
duke@435 | 215 | reg->init_req(slot, ctrl()); |
duke@435 | 216 | assert(first_var + _var_ct == _cvstate->req(), "bad _cvstate size"); |
duke@435 | 217 | for (uint i = first_var; i < _cvstate->req(); i++) { |
duke@435 | 218 | |
duke@435 | 219 | // l is the value of var reaching the label. Could be a single value |
duke@435 | 220 | // reaching the label, or a phi that merges multiples values reaching |
duke@435 | 221 | // the label. The latter is true if the label's input: in(..) is |
duke@435 | 222 | // a phi whose control input is the region node for the label. |
duke@435 | 223 | |
duke@435 | 224 | Node* l = lab->in(i); |
duke@435 | 225 | // Get the current value of the var |
duke@435 | 226 | Node* m = _cvstate->in(i); |
duke@435 | 227 | // If the var went unused no need for a phi |
duke@435 | 228 | if (m == NULL) { |
duke@435 | 229 | continue; |
duke@435 | 230 | } else if (l == NULL || m == l) { |
duke@435 | 231 | // Only one unique value "m" is known to reach this label so a phi |
duke@435 | 232 | // is not yet necessary unless: |
duke@435 | 233 | // the label is being bound and all predecessors have not been seen, |
duke@435 | 234 | // in which case "bind" will be true. |
duke@435 | 235 | if (bind) { |
duke@435 | 236 | m = promote_to_phi(m, reg); |
duke@435 | 237 | } |
duke@435 | 238 | // Record the phi/value used for this var in the label's cvstate |
duke@435 | 239 | lab->set_req(i, m); |
duke@435 | 240 | } else { |
duke@435 | 241 | // More than one value for the variable reaches this label so |
duke@435 | 242 | // a create a phi if one does not already exist. |
duke@435 | 243 | if (!was_promoted_to_phi(l, reg)) { |
duke@435 | 244 | l = promote_to_phi(l, reg); |
duke@435 | 245 | lab->set_req(i, l); |
duke@435 | 246 | } |
duke@435 | 247 | // Record in the phi, the var's value from the current state |
duke@435 | 248 | l->set_req(slot, m); |
duke@435 | 249 | } |
duke@435 | 250 | } |
duke@435 | 251 | do_memory_merge(_cvstate, lab); |
duke@435 | 252 | stop(); |
duke@435 | 253 | } |
duke@435 | 254 | |
duke@435 | 255 | //-----------------------------promote_to_phi----------------------------------- |
duke@435 | 256 | Node* IdealKit::promote_to_phi(Node* n, Node* reg) { |
duke@435 | 257 | assert(!was_promoted_to_phi(n, reg), "n already promoted to phi on this region"); |
duke@435 | 258 | // Get a conservative type for the phi |
duke@435 | 259 | const BasicType bt = n->bottom_type()->basic_type(); |
duke@435 | 260 | const Type* ct = Type::get_const_basic_type(bt); |
duke@435 | 261 | return delay_transform(PhiNode::make(reg, n, ct)); |
duke@435 | 262 | } |
duke@435 | 263 | |
kvn@1286 | 264 | //-----------------------------declarations_done------------------------------- |
kvn@1286 | 265 | void IdealKit::declarations_done() { |
duke@435 | 266 | _cvstate = new_cvstate(); // initialize current cvstate |
duke@435 | 267 | set_ctrl(_initial_ctrl); // initialize control in current cvstate |
duke@435 | 268 | set_all_memory(_initial_memory);// initialize memory in current cvstate |
duke@435 | 269 | DEBUG_ONLY(_state->push(BlockS)); |
duke@435 | 270 | } |
duke@435 | 271 | |
duke@435 | 272 | //-----------------------------transform----------------------------------- |
duke@435 | 273 | Node* IdealKit::transform(Node* n) { |
duke@435 | 274 | if (_delay_all_transforms) { |
duke@435 | 275 | return delay_transform(n); |
duke@435 | 276 | } else { |
duke@435 | 277 | return gvn().transform(n); |
duke@435 | 278 | } |
duke@435 | 279 | } |
duke@435 | 280 | |
duke@435 | 281 | //-----------------------------delay_transform----------------------------------- |
duke@435 | 282 | Node* IdealKit::delay_transform(Node* n) { |
kvn@1286 | 283 | if (!gvn().is_IterGVN() || !gvn().is_IterGVN()->delay_transform()) { |
kvn@1286 | 284 | gvn().set_type(n, n->bottom_type()); |
kvn@1286 | 285 | } |
duke@435 | 286 | _delay_transform->push(n); |
duke@435 | 287 | return n; |
duke@435 | 288 | } |
duke@435 | 289 | |
duke@435 | 290 | //-----------------------------new_cvstate----------------------------------- |
duke@435 | 291 | Node* IdealKit::new_cvstate() { |
duke@435 | 292 | uint sz = _var_ct + first_var; |
duke@435 | 293 | return new (C, sz) Node(sz); |
duke@435 | 294 | } |
duke@435 | 295 | |
duke@435 | 296 | //-----------------------------copy_cvstate----------------------------------- |
duke@435 | 297 | Node* IdealKit::copy_cvstate() { |
duke@435 | 298 | Node* ns = new_cvstate(); |
duke@435 | 299 | for (uint i = 0; i < ns->req(); i++) ns->init_req(i, _cvstate->in(i)); |
duke@435 | 300 | // We must clone memory since it will be updated as we do stores. |
duke@435 | 301 | ns->set_req(TypeFunc::Memory, MergeMemNode::make(C, ns->in(TypeFunc::Memory))); |
duke@435 | 302 | return ns; |
duke@435 | 303 | } |
duke@435 | 304 | |
duke@435 | 305 | //-----------------------------clear----------------------------------- |
duke@435 | 306 | void IdealKit::clear(Node* m) { |
duke@435 | 307 | for (uint i = 0; i < m->req(); i++) m->set_req(i, NULL); |
duke@435 | 308 | } |
duke@435 | 309 | |
duke@435 | 310 | //-----------------------------drain_delay_transform---------------------------- |
duke@435 | 311 | void IdealKit::drain_delay_transform() { |
duke@435 | 312 | while (_delay_transform->length() > 0) { |
duke@435 | 313 | Node* n = _delay_transform->pop(); |
duke@435 | 314 | gvn().transform(n); |
duke@435 | 315 | if (!gvn().is_IterGVN()) { |
duke@435 | 316 | C->record_for_igvn(n); |
duke@435 | 317 | } |
duke@435 | 318 | } |
duke@435 | 319 | } |
duke@435 | 320 | |
duke@435 | 321 | //-----------------------------IdealVariable---------------------------- |
duke@435 | 322 | IdealVariable::IdealVariable(IdealKit &k) { |
duke@435 | 323 | k.declare(this); |
duke@435 | 324 | } |
duke@435 | 325 | |
duke@435 | 326 | Node* IdealKit::memory(uint alias_idx) { |
duke@435 | 327 | MergeMemNode* mem = merged_memory(); |
duke@435 | 328 | Node* p = mem->memory_at(alias_idx); |
kvn@1286 | 329 | if (!gvn().is_IterGVN() || !gvn().is_IterGVN()->delay_transform()) { |
kvn@1286 | 330 | _gvn.set_type(p, Type::MEMORY); // must be mapped |
kvn@1286 | 331 | } |
duke@435 | 332 | return p; |
duke@435 | 333 | } |
duke@435 | 334 | |
duke@435 | 335 | void IdealKit::set_memory(Node* mem, uint alias_idx) { |
duke@435 | 336 | merged_memory()->set_memory_at(alias_idx, mem); |
duke@435 | 337 | } |
duke@435 | 338 | |
duke@435 | 339 | //----------------------------- make_load ---------------------------- |
duke@435 | 340 | Node* IdealKit::load(Node* ctl, |
duke@435 | 341 | Node* adr, |
duke@435 | 342 | const Type* t, |
duke@435 | 343 | BasicType bt, |
duke@435 | 344 | int adr_idx, |
duke@435 | 345 | bool require_atomic_access) { |
duke@435 | 346 | |
duke@435 | 347 | assert(adr_idx != Compile::AliasIdxTop, "use other make_load factory" ); |
duke@435 | 348 | const TypePtr* adr_type = NULL; // debug-mode-only argument |
duke@435 | 349 | debug_only(adr_type = C->get_adr_type(adr_idx)); |
duke@435 | 350 | Node* mem = memory(adr_idx); |
duke@435 | 351 | Node* ld; |
duke@435 | 352 | if (require_atomic_access && bt == T_LONG) { |
duke@435 | 353 | ld = LoadLNode::make_atomic(C, ctl, mem, adr, adr_type, t); |
duke@435 | 354 | } else { |
coleenp@548 | 355 | ld = LoadNode::make(_gvn, ctl, mem, adr, adr_type, t, bt); |
duke@435 | 356 | } |
duke@435 | 357 | return transform(ld); |
duke@435 | 358 | } |
duke@435 | 359 | |
duke@435 | 360 | Node* IdealKit::store(Node* ctl, Node* adr, Node *val, BasicType bt, |
duke@435 | 361 | int adr_idx, |
duke@435 | 362 | bool require_atomic_access) { |
duke@435 | 363 | assert(adr_idx != Compile::AliasIdxTop, "use other store_to_memory factory" ); |
duke@435 | 364 | const TypePtr* adr_type = NULL; |
duke@435 | 365 | debug_only(adr_type = C->get_adr_type(adr_idx)); |
duke@435 | 366 | Node *mem = memory(adr_idx); |
duke@435 | 367 | Node* st; |
duke@435 | 368 | if (require_atomic_access && bt == T_LONG) { |
duke@435 | 369 | st = StoreLNode::make_atomic(C, ctl, mem, adr, adr_type, val); |
duke@435 | 370 | } else { |
coleenp@548 | 371 | st = StoreNode::make(_gvn, ctl, mem, adr, adr_type, val, bt); |
duke@435 | 372 | } |
duke@435 | 373 | st = transform(st); |
duke@435 | 374 | set_memory(st, adr_idx); |
duke@435 | 375 | |
duke@435 | 376 | return st; |
duke@435 | 377 | } |
duke@435 | 378 | |
duke@435 | 379 | // Card mark store. Must be ordered so that it will come after the store of |
duke@435 | 380 | // the oop. |
cfang@1420 | 381 | Node* IdealKit::storeCM(Node* ctl, Node* adr, Node *val, Node* oop_store, int oop_adr_idx, |
duke@435 | 382 | BasicType bt, |
duke@435 | 383 | int adr_idx) { |
duke@435 | 384 | assert(adr_idx != Compile::AliasIdxTop, "use other store_to_memory factory" ); |
duke@435 | 385 | const TypePtr* adr_type = NULL; |
duke@435 | 386 | debug_only(adr_type = C->get_adr_type(adr_idx)); |
duke@435 | 387 | Node *mem = memory(adr_idx); |
duke@435 | 388 | |
duke@435 | 389 | // Add required edge to oop_store, optimizer does not support precedence edges. |
duke@435 | 390 | // Convert required edge to precedence edge before allocation. |
cfang@1420 | 391 | Node* st = new (C, 5) StoreCMNode(ctl, mem, adr, adr_type, val, oop_store, oop_adr_idx); |
duke@435 | 392 | |
duke@435 | 393 | st = transform(st); |
duke@435 | 394 | set_memory(st, adr_idx); |
duke@435 | 395 | |
duke@435 | 396 | return st; |
duke@435 | 397 | } |
duke@435 | 398 | |
duke@435 | 399 | //---------------------------- do_memory_merge -------------------------------- |
duke@435 | 400 | // The memory from one merging cvstate needs to be merged with the memory for another |
duke@435 | 401 | // join cvstate. If the join cvstate doesn't have a merged memory yet then we |
duke@435 | 402 | // can just copy the state from the merging cvstate |
duke@435 | 403 | |
duke@435 | 404 | // Merge one slow path into the rest of memory. |
duke@435 | 405 | void IdealKit::do_memory_merge(Node* merging, Node* join) { |
duke@435 | 406 | |
duke@435 | 407 | // Get the region for the join state |
duke@435 | 408 | Node* join_region = join->in(TypeFunc::Control); |
duke@435 | 409 | assert(join_region != NULL, "join region must exist"); |
duke@435 | 410 | if (join->in(TypeFunc::Memory) == NULL ) { |
duke@435 | 411 | join->set_req(TypeFunc::Memory, merging->in(TypeFunc::Memory)); |
duke@435 | 412 | return; |
duke@435 | 413 | } |
duke@435 | 414 | |
duke@435 | 415 | // The control flow for merging must have already been attached to the join region |
duke@435 | 416 | // we need its index for the phis. |
duke@435 | 417 | uint slot; |
duke@435 | 418 | for (slot = 1; slot < join_region->req() ; slot ++ ) { |
duke@435 | 419 | if (join_region->in(slot) == merging->in(TypeFunc::Control)) break; |
duke@435 | 420 | } |
duke@435 | 421 | assert(slot != join_region->req(), "edge must already exist"); |
duke@435 | 422 | |
duke@435 | 423 | MergeMemNode* join_m = join->in(TypeFunc::Memory)->as_MergeMem(); |
duke@435 | 424 | MergeMemNode* merging_m = merging->in(TypeFunc::Memory)->as_MergeMem(); |
duke@435 | 425 | |
duke@435 | 426 | // join_m should be an ancestor mergemem of merging |
duke@435 | 427 | // Slow path memory comes from the current map (which is from a slow call) |
duke@435 | 428 | // Fast path/null path memory comes from the call's input |
duke@435 | 429 | |
duke@435 | 430 | // Merge the other fast-memory inputs with the new slow-default memory. |
duke@435 | 431 | // for (MergeMemStream mms(merged_memory(), fast_mem->as_MergeMem()); mms.next_non_empty2(); ) { |
duke@435 | 432 | for (MergeMemStream mms(join_m, merging_m); mms.next_non_empty2(); ) { |
duke@435 | 433 | Node* join_slice = mms.force_memory(); |
duke@435 | 434 | Node* merging_slice = mms.memory2(); |
duke@435 | 435 | if (join_slice != merging_slice) { |
duke@435 | 436 | PhiNode* phi; |
duke@435 | 437 | // bool new_phi = false; |
duke@435 | 438 | // Is the phi for this slice one that we created for this join region or simply |
duke@435 | 439 | // one we copied? If it is ours then add |
duke@435 | 440 | if (join_slice->is_Phi() && join_slice->as_Phi()->region() == join_region) { |
duke@435 | 441 | phi = join_slice->as_Phi(); |
duke@435 | 442 | } else { |
duke@435 | 443 | // create the phi with join_slice filling supplying memory for all of the |
duke@435 | 444 | // control edges to the join region |
duke@435 | 445 | phi = PhiNode::make(join_region, join_slice, Type::MEMORY, mms.adr_type(C)); |
duke@435 | 446 | phi = (PhiNode*) delay_transform(phi); |
duke@435 | 447 | // gvn().set_type(phi, Type::MEMORY); |
duke@435 | 448 | // new_phi = true; |
duke@435 | 449 | } |
duke@435 | 450 | // Now update the phi with the slice for the merging slice |
duke@435 | 451 | phi->set_req(slot, merging_slice/* slow_path, slow_slice */); |
duke@435 | 452 | // this updates join_m with the phi |
duke@435 | 453 | mms.set_memory(phi); |
duke@435 | 454 | } |
duke@435 | 455 | } |
duke@435 | 456 | } |
duke@435 | 457 | |
duke@435 | 458 | |
duke@435 | 459 | //----------------------------- make_call ---------------------------- |
duke@435 | 460 | // Trivial runtime call |
duke@435 | 461 | void IdealKit::make_leaf_call(const TypeFunc *slow_call_type, |
duke@435 | 462 | address slow_call, |
duke@435 | 463 | const char *leaf_name, |
duke@435 | 464 | Node* parm0, |
duke@435 | 465 | Node* parm1, |
duke@435 | 466 | Node* parm2) { |
duke@435 | 467 | |
duke@435 | 468 | // We only handle taking in RawMem and modifying RawMem |
duke@435 | 469 | const TypePtr* adr_type = TypeRawPtr::BOTTOM; |
duke@435 | 470 | uint adr_idx = C->get_alias_index(adr_type); |
duke@435 | 471 | |
duke@435 | 472 | // Slow-path leaf call |
duke@435 | 473 | int size = slow_call_type->domain()->cnt(); |
duke@435 | 474 | CallNode *call = (CallNode*)new (C, size) CallLeafNode( slow_call_type, slow_call, leaf_name, adr_type); |
duke@435 | 475 | |
duke@435 | 476 | // Set fixed predefined input arguments |
duke@435 | 477 | call->init_req( TypeFunc::Control, ctrl() ); |
duke@435 | 478 | call->init_req( TypeFunc::I_O , top() ) ; // does no i/o |
duke@435 | 479 | // Narrow memory as only memory input |
duke@435 | 480 | call->init_req( TypeFunc::Memory , memory(adr_idx)); |
duke@435 | 481 | call->init_req( TypeFunc::FramePtr, top() /* frameptr() */ ); |
duke@435 | 482 | call->init_req( TypeFunc::ReturnAdr, top() ); |
duke@435 | 483 | |
duke@435 | 484 | if (parm0 != NULL) call->init_req(TypeFunc::Parms+0, parm0); |
duke@435 | 485 | if (parm1 != NULL) call->init_req(TypeFunc::Parms+1, parm1); |
duke@435 | 486 | if (parm2 != NULL) call->init_req(TypeFunc::Parms+2, parm2); |
duke@435 | 487 | |
duke@435 | 488 | // Node *c = _gvn.transform(call); |
duke@435 | 489 | call = (CallNode *) _gvn.transform(call); |
duke@435 | 490 | Node *c = call; // dbx gets confused with call call->dump() |
duke@435 | 491 | |
duke@435 | 492 | // Slow leaf call has no side-effects, sets few values |
duke@435 | 493 | |
duke@435 | 494 | set_ctrl(transform( new (C, 1) ProjNode(call,TypeFunc::Control) )); |
duke@435 | 495 | |
duke@435 | 496 | // Make memory for the call |
duke@435 | 497 | Node* mem = _gvn.transform( new (C, 1) ProjNode(call, TypeFunc::Memory) ); |
duke@435 | 498 | |
duke@435 | 499 | // Set the RawPtr memory state only. |
duke@435 | 500 | set_memory(mem, adr_idx); |
duke@435 | 501 | |
duke@435 | 502 | assert(C->alias_type(call->adr_type()) == C->alias_type(adr_type), |
duke@435 | 503 | "call node must be constructed correctly"); |
duke@435 | 504 | } |