1 /*
2 * Copyright (c) 1997, 2015, 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 *
406 Node** p = &_in[i]; // cache this._in, across the del_out call
407 if (*p != NULL) (*p)->del_out((Node *)this);
408 (*p) = n;
409 if (n != NULL) n->add_out((Node *)this);
410 Compile::current()->record_modified_node(this);
411 }
412 // Light version of set_req() to init inputs after node creation.
413 void init_req( uint i, Node *n ) {
414 assert( i == 0 && this == n ||
415 is_not_dead(n), "can not use dead node");
416 assert( i < _cnt, "oob");
417 assert( !VerifyHashTableKeys || _hash_lock == 0,
418 "remove node from hash table before modifying it");
419 assert( _in[i] == NULL, "sanity");
420 _in[i] = n;
421 if (n != NULL) n->add_out((Node *)this);
422 Compile::current()->record_modified_node(this);
423 }
424 // Find first occurrence of n among my edges:
425 int find_edge(Node* n);
426 int replace_edge(Node* old, Node* neww);
427 int replace_edges_in_range(Node* old, Node* neww, int start, int end);
428 // NULL out all inputs to eliminate incoming Def-Use edges.
429 // Return the number of edges between 'n' and 'this'
430 int disconnect_inputs(Node *n, Compile *c);
431
432 // Quickly, return true if and only if I am Compile::current()->top().
433 bool is_top() const {
434 assert((this == (Node*) Compile::current()->top()) == (_out == NULL), "");
435 return (_out == NULL);
436 }
437 // Reaffirm invariants for is_top. (Only from Compile::set_cached_top_node.)
438 void setup_is_top();
439
440 // Strip away casting. (It is depth-limited.)
441 Node* uncast() const;
442 // Return whether two Nodes are equivalent, after stripping casting.
443 bool eqv_uncast(const Node* n) const {
444 return (this->uncast() == n->uncast());
445 }
459 if (is_top()) return;
460 if( _outcnt == _outmax ) out_grow(_outcnt);
461 _out[_outcnt++] = n;
462 }
463 // Delete an output edge
464 void del_out( Node *n ) {
465 if (is_top()) return;
466 Node** outp = &_out[_outcnt];
467 // Find and remove n
468 do {
469 assert(outp > _out, "Missing Def-Use edge");
470 } while (*--outp != n);
471 *outp = _out[--_outcnt];
472 // Smash the old edge so it can't be used accidentally.
473 debug_only(_out[_outcnt] = (Node *)(uintptr_t)0xdeadbeef);
474 // Record that a change happened here.
475 #if OPTO_DU_ITERATOR_ASSERT
476 debug_only(_last_del = n; ++_del_tick);
477 #endif
478 }
479
480 public:
481 // Globally replace this node by a given new node, updating all uses.
482 void replace_by(Node* new_node);
483 // Globally replace this node by a given new node, updating all uses
484 // and cutting input edges of old node.
485 void subsume_by(Node* new_node, Compile* c) {
486 replace_by(new_node);
487 disconnect_inputs(NULL, c);
488 }
489 void set_req_X( uint i, Node *n, PhaseIterGVN *igvn );
490 // Find the one non-null required input. RegionNode only
491 Node *nonnull_req() const;
492 // Add or remove precedence edges
493 void add_prec( Node *n );
494 void rm_prec( uint i );
495 void set_prec( uint i, Node *n ) {
496 assert( is_not_dead(n), "can not use dead node");
497 assert( i >= _cnt, "not a precedence edge");
498 if (_in[i] != NULL) _in[i]->del_out((Node *)this);
499 _in[i] = n;
500 if (n != NULL) n->add_out((Node *)this);
501 }
502 // Set this node's index, used by cisc_version to replace current node
503 void set_idx(uint new_idx) {
504 const node_idx_t* ref = &_idx;
505 *(node_idx_t*)ref = new_idx;
506 }
507 // Swap input edge order. (Edge indexes i1 and i2 are usually 1 and 2.)
508 void swap_edges(uint i1, uint i2) {
509 debug_only(uint check_hash = (VerifyHashTableKeys && _hash_lock) ? hash() : NO_HASH);
510 // Def-Use info is unchanged
511 Node* n1 = in(i1);
512 Node* n2 = in(i2);
513 _in[i1] = n2;
514 _in[i2] = n1;
515 // If this node is in the hash table, make sure it doesn't need a rehash.
516 assert(check_hash == NO_HASH || check_hash == hash(), "edge swap must preserve hash code");
517 }
518
519 // Iterators over input Nodes for a Node X are written as:
520 // for( i = 0; i < X.req(); i++ ) ... X[i] ...
521 // NOTE: Required edges can contain embedded NULL pointers.
|
1 /*
2 * Copyright (c) 1997, 2016, 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 *
406 Node** p = &_in[i]; // cache this._in, across the del_out call
407 if (*p != NULL) (*p)->del_out((Node *)this);
408 (*p) = n;
409 if (n != NULL) n->add_out((Node *)this);
410 Compile::current()->record_modified_node(this);
411 }
412 // Light version of set_req() to init inputs after node creation.
413 void init_req( uint i, Node *n ) {
414 assert( i == 0 && this == n ||
415 is_not_dead(n), "can not use dead node");
416 assert( i < _cnt, "oob");
417 assert( !VerifyHashTableKeys || _hash_lock == 0,
418 "remove node from hash table before modifying it");
419 assert( _in[i] == NULL, "sanity");
420 _in[i] = n;
421 if (n != NULL) n->add_out((Node *)this);
422 Compile::current()->record_modified_node(this);
423 }
424 // Find first occurrence of n among my edges:
425 int find_edge(Node* n);
426 int find_prec_edge(Node* n) {
427 for (uint i = req(); i < len(); i++) {
428 if (_in[i] == n) return i;
429 if (_in[i] == NULL) {
430 DEBUG_ONLY( while ((++i) < len()) assert(_in[i] == NULL, "Gap in prec edges!"); )
431 break;
432 }
433 }
434 return -1;
435 }
436 int replace_edge(Node* old, Node* neww);
437 int replace_edges_in_range(Node* old, Node* neww, int start, int end);
438 // NULL out all inputs to eliminate incoming Def-Use edges.
439 // Return the number of edges between 'n' and 'this'
440 int disconnect_inputs(Node *n, Compile *c);
441
442 // Quickly, return true if and only if I am Compile::current()->top().
443 bool is_top() const {
444 assert((this == (Node*) Compile::current()->top()) == (_out == NULL), "");
445 return (_out == NULL);
446 }
447 // Reaffirm invariants for is_top. (Only from Compile::set_cached_top_node.)
448 void setup_is_top();
449
450 // Strip away casting. (It is depth-limited.)
451 Node* uncast() const;
452 // Return whether two Nodes are equivalent, after stripping casting.
453 bool eqv_uncast(const Node* n) const {
454 return (this->uncast() == n->uncast());
455 }
469 if (is_top()) return;
470 if( _outcnt == _outmax ) out_grow(_outcnt);
471 _out[_outcnt++] = n;
472 }
473 // Delete an output edge
474 void del_out( Node *n ) {
475 if (is_top()) return;
476 Node** outp = &_out[_outcnt];
477 // Find and remove n
478 do {
479 assert(outp > _out, "Missing Def-Use edge");
480 } while (*--outp != n);
481 *outp = _out[--_outcnt];
482 // Smash the old edge so it can't be used accidentally.
483 debug_only(_out[_outcnt] = (Node *)(uintptr_t)0xdeadbeef);
484 // Record that a change happened here.
485 #if OPTO_DU_ITERATOR_ASSERT
486 debug_only(_last_del = n; ++_del_tick);
487 #endif
488 }
489 // Close gap after removing edge.
490 void close_prec_gap_at(uint gap) {
491 assert(_cnt <= gap && gap < _max, "no valid prec edge");
492 uint i = gap;
493 Node *last = NULL;
494 for (; i < _max-1; ++i) {
495 Node *next = _in[i+1];
496 if (next == NULL) break;
497 last = next;
498 }
499 _in[gap] = last; // Move last slot to empty one.
500 _in[i] = NULL; // NULL out last slot.
501 }
502
503 public:
504 // Globally replace this node by a given new node, updating all uses.
505 void replace_by(Node* new_node);
506 // Globally replace this node by a given new node, updating all uses
507 // and cutting input edges of old node.
508 void subsume_by(Node* new_node, Compile* c) {
509 replace_by(new_node);
510 disconnect_inputs(NULL, c);
511 }
512 void set_req_X( uint i, Node *n, PhaseIterGVN *igvn );
513 // Find the one non-null required input. RegionNode only
514 Node *nonnull_req() const;
515 // Add or remove precedence edges
516 void add_prec( Node *n );
517 void rm_prec( uint i );
518
519 // Note: prec(i) will not necessarily point to n if edge already exists.
520 void set_prec( uint i, Node *n ) {
521 assert(i < _max, "oob: i=%d, _max=%d", i, _max);
522 assert(is_not_dead(n), "can not use dead node");
523 assert(i >= _cnt, "not a precedence edge");
524 // Avoid spec violation: duplicated prec edge.
525 if (_in[i] == n) return;
526 if (n == NULL || find_prec_edge(n) != -1) {
527 rm_prec(i);
528 return;
529 }
530 if (_in[i] != NULL) _in[i]->del_out((Node *)this);
531 _in[i] = n;
532 if (n != NULL) n->add_out((Node *)this);
533 }
534
535 // Set this node's index, used by cisc_version to replace current node
536 void set_idx(uint new_idx) {
537 const node_idx_t* ref = &_idx;
538 *(node_idx_t*)ref = new_idx;
539 }
540 // Swap input edge order. (Edge indexes i1 and i2 are usually 1 and 2.)
541 void swap_edges(uint i1, uint i2) {
542 debug_only(uint check_hash = (VerifyHashTableKeys && _hash_lock) ? hash() : NO_HASH);
543 // Def-Use info is unchanged
544 Node* n1 = in(i1);
545 Node* n2 = in(i2);
546 _in[i1] = n2;
547 _in[i2] = n1;
548 // If this node is in the hash table, make sure it doesn't need a rehash.
549 assert(check_hash == NO_HASH || check_hash == hash(), "edge swap must preserve hash code");
550 }
551
552 // Iterators over input Nodes for a Node X are written as:
553 // for( i = 0; i < X.req(); i++ ) ... X[i] ...
554 // NOTE: Required edges can contain embedded NULL pointers.
|