src/share/vm/opto/idealKit.cpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

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

mercurial