hotspot/src/share/vm/opto/postaloc.cpp
author roland
Thu, 10 Apr 2014 11:38:12 +0200
changeset 24002 4e6a72032a99
parent 22234 da823d78ad65
child 26913 9ad70cd32368
permissions -rw-r--r--
8005079: fix LogCompilation for incremental inlining Summary: report late inlining as part of the rest of the inlining output Reviewed-by: twisti, kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
22234
da823d78ad65 8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013
mikael
parents: 21200
diff changeset
     2
 * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3795
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3795
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3795
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#include "memory/allocation.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "opto/chaitin.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "opto/machnode.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
13104
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
    30
// See if this register (or pairs, or vector) already contains the value.
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
    31
static bool register_contains_value(Node* val, OptoReg::Name reg, int n_regs,
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
    32
                                    Node_List& value) {
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
    33
  for (int i = 0; i < n_regs; i++) {
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
    34
    OptoReg::Name nreg = OptoReg::add(reg,-i);
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
    35
    if (value[nreg] != val)
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
    36
      return false;
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
    37
  }
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
    38
  return true;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
1432
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 670
diff changeset
    41
//---------------------------may_be_copy_of_callee-----------------------------
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
// Check to see if we can possibly be a copy of a callee-save value.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
bool PhaseChaitin::may_be_copy_of_callee( Node *def ) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  // Short circuit if there are no callee save registers
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  if (_matcher.number_of_saved_registers() == 0) return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  // Expect only a spill-down and reload on exit for callee-save spills.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  // Chains of copies cannot be deep.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  // 5008997 - This is wishful thinking. Register allocator seems to
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  // be splitting live ranges for callee save registers to such
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
  // an extent that in large methods the chains can be very long
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  // (50+). The conservative answer is to return true if we don't
2131
98f9cef66a34 6810672: Comment typos
twisti
parents: 1432
diff changeset
    53
  // know as this prevents optimizations from occurring.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  const int limit = 60;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  int i;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  for( i=0; i < limit; i++ ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
    if( def->is_Proj() && def->in(0)->is_Start() &&
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 14623
diff changeset
    59
        _matcher.is_save_on_entry(lrgs(_lrg_map.live_range_id(def)).reg()))
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
      return true;              // Direct use of callee-save proj
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    if( def->is_Copy() )        // Copies carry value through
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
      def = def->in(def->is_Copy());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    else if( def->is_Phi() )    // Phis can merge it from any direction
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
      def = def->in(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
    else
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
    guarantee(def != NULL, "must not resurrect dead copy");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  // If we reached the end and didn't find a callee save proj
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  // then this may be a callee save proj so we return true
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  // as the conservative answer. If we didn't reach then end
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  // we must have discovered that it was not a callee save
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
  // else we would have returned.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  return i == limit;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
10542
93e6f995c75c 7087453: PhaseChaitin::yank_if_dead() should handle MachTemp inputs
roland
parents: 7433
diff changeset
    77
//------------------------------yank-----------------------------------
93e6f995c75c 7087453: PhaseChaitin::yank_if_dead() should handle MachTemp inputs
roland
parents: 7433
diff changeset
    78
// Helper function for yank_if_dead
93e6f995c75c 7087453: PhaseChaitin::yank_if_dead() should handle MachTemp inputs
roland
parents: 7433
diff changeset
    79
int PhaseChaitin::yank( Node *old, Block *current_block, Node_List *value, Node_List *regnd ) {
93e6f995c75c 7087453: PhaseChaitin::yank_if_dead() should handle MachTemp inputs
roland
parents: 7433
diff changeset
    80
  int blk_adjust=0;
19279
4be3c2e6663c 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 17013
diff changeset
    81
  Block *oldb = _cfg.get_block_for_node(old);
10542
93e6f995c75c 7087453: PhaseChaitin::yank_if_dead() should handle MachTemp inputs
roland
parents: 7433
diff changeset
    82
  oldb->find_remove(old);
93e6f995c75c 7087453: PhaseChaitin::yank_if_dead() should handle MachTemp inputs
roland
parents: 7433
diff changeset
    83
  // Count 1 if deleting an instruction from the current block
19279
4be3c2e6663c 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 17013
diff changeset
    84
  if (oldb == current_block) {
4be3c2e6663c 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 17013
diff changeset
    85
    blk_adjust++;
4be3c2e6663c 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 17013
diff changeset
    86
  }
4be3c2e6663c 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 17013
diff changeset
    87
  _cfg.unmap_node_from_block(old);
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 14623
diff changeset
    88
  OptoReg::Name old_reg = lrgs(_lrg_map.live_range_id(old)).reg();
10542
93e6f995c75c 7087453: PhaseChaitin::yank_if_dead() should handle MachTemp inputs
roland
parents: 7433
diff changeset
    89
  if( regnd && (*regnd)[old_reg]==old ) { // Instruction is currently available?
93e6f995c75c 7087453: PhaseChaitin::yank_if_dead() should handle MachTemp inputs
roland
parents: 7433
diff changeset
    90
    value->map(old_reg,NULL);  // Yank from value/regnd maps
93e6f995c75c 7087453: PhaseChaitin::yank_if_dead() should handle MachTemp inputs
roland
parents: 7433
diff changeset
    91
    regnd->map(old_reg,NULL);  // This register's value is now unknown
93e6f995c75c 7087453: PhaseChaitin::yank_if_dead() should handle MachTemp inputs
roland
parents: 7433
diff changeset
    92
  }
93e6f995c75c 7087453: PhaseChaitin::yank_if_dead() should handle MachTemp inputs
roland
parents: 7433
diff changeset
    93
  return blk_adjust;
93e6f995c75c 7087453: PhaseChaitin::yank_if_dead() should handle MachTemp inputs
roland
parents: 7433
diff changeset
    94
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
11444
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10549
diff changeset
    96
#ifdef ASSERT
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10549
diff changeset
    97
static bool expected_yanked_node(Node *old, Node *orig_old) {
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10549
diff changeset
    98
  // This code is expected only next original nodes:
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10549
diff changeset
    99
  // - load from constant table node which may have next data input nodes:
21200
5f7a5282462d 8026940: assert(n->outcnt() != 0 || C->top() == n || n->is_Proj()) failed: No dead instructions after post-alloc
adlertz
parents: 19717
diff changeset
   100
  //     MachConstantBase, MachTemp, MachSpillCopy
5f7a5282462d 8026940: assert(n->outcnt() != 0 || C->top() == n || n->is_Proj()) failed: No dead instructions after post-alloc
adlertz
parents: 19717
diff changeset
   101
  // - Phi nodes that are considered Junk
11444
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10549
diff changeset
   102
  // - load constant node which may have next data input nodes:
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10549
diff changeset
   103
  //     MachTemp, MachSpillCopy
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10549
diff changeset
   104
  // - MachSpillCopy
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10549
diff changeset
   105
  // - MachProj and Copy dead nodes
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10549
diff changeset
   106
  if (old->is_MachSpillCopy()) {
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10549
diff changeset
   107
    return true;
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10549
diff changeset
   108
  } else if (old->is_Con()) {
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10549
diff changeset
   109
    return true;
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10549
diff changeset
   110
  } else if (old->is_MachProj()) { // Dead kills projection of Con node
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10549
diff changeset
   111
    return (old == orig_old);
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10549
diff changeset
   112
  } else if (old->is_Copy()) {     // Dead copy of a callee-save value
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10549
diff changeset
   113
    return (old == orig_old);
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10549
diff changeset
   114
  } else if (old->is_MachTemp()) {
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10549
diff changeset
   115
    return orig_old->is_Con();
21200
5f7a5282462d 8026940: assert(n->outcnt() != 0 || C->top() == n || n->is_Proj()) failed: No dead instructions after post-alloc
adlertz
parents: 19717
diff changeset
   116
  } else if (old->is_Phi()) { // Junk phi's
5f7a5282462d 8026940: assert(n->outcnt() != 0 || C->top() == n || n->is_Proj()) failed: No dead instructions after post-alloc
adlertz
parents: 19717
diff changeset
   117
    return true;
5f7a5282462d 8026940: assert(n->outcnt() != 0 || C->top() == n || n->is_Proj()) failed: No dead instructions after post-alloc
adlertz
parents: 19717
diff changeset
   118
  } else if (old->is_MachConstantBase()) {
11444
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10549
diff changeset
   119
    return (orig_old->is_Con() && orig_old->is_MachConstant());
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10549
diff changeset
   120
  }
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10549
diff changeset
   121
  return false;
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10549
diff changeset
   122
}
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10549
diff changeset
   123
#endif
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10549
diff changeset
   124
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
//------------------------------yank_if_dead-----------------------------------
11444
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10549
diff changeset
   126
// Removed edges from 'old'.  Yank if dead.  Return adjustment counts to
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
// iterators in the current block.
11444
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10549
diff changeset
   128
int PhaseChaitin::yank_if_dead_recurse(Node *old, Node *orig_old, Block *current_block,
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10549
diff changeset
   129
                                       Node_List *value, Node_List *regnd) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  int blk_adjust=0;
11444
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10549
diff changeset
   131
  if (old->outcnt() == 0 && old != C->top()) {
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10549
diff changeset
   132
#ifdef ASSERT
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10549
diff changeset
   133
    if (!expected_yanked_node(old, orig_old)) {
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10549
diff changeset
   134
      tty->print_cr("==============================================");
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10549
diff changeset
   135
      tty->print_cr("orig_old:");
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10549
diff changeset
   136
      orig_old->dump();
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10549
diff changeset
   137
      tty->print_cr("old:");
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10549
diff changeset
   138
      old->dump();
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10549
diff changeset
   139
      assert(false, "unexpected yanked node");
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10549
diff changeset
   140
    }
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10549
diff changeset
   141
    if (old->is_Con())
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10549
diff changeset
   142
      orig_old = old; // Reset to satisfy expected nodes checks.
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10549
diff changeset
   143
#endif
10542
93e6f995c75c 7087453: PhaseChaitin::yank_if_dead() should handle MachTemp inputs
roland
parents: 7433
diff changeset
   144
    blk_adjust += yank(old, current_block, value, regnd);
93e6f995c75c 7087453: PhaseChaitin::yank_if_dead() should handle MachTemp inputs
roland
parents: 7433
diff changeset
   145
93e6f995c75c 7087453: PhaseChaitin::yank_if_dead() should handle MachTemp inputs
roland
parents: 7433
diff changeset
   146
    for (uint i = 1; i < old->req(); i++) {
11444
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10549
diff changeset
   147
      Node* n = old->in(i);
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10549
diff changeset
   148
      if (n != NULL) {
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10549
diff changeset
   149
        old->set_req(i, NULL);
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10549
diff changeset
   150
        blk_adjust += yank_if_dead_recurse(n, orig_old, current_block, value, regnd);
10542
93e6f995c75c 7087453: PhaseChaitin::yank_if_dead() should handle MachTemp inputs
roland
parents: 7433
diff changeset
   151
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
    }
11444
8a2619fd3fca 7110824: ctw/jarfiles/GUI3rdParty_jar/ob_mask_DateField crashes VM
kvn
parents: 10549
diff changeset
   153
    // Disconnect control and remove precedence edges if any exist
14623
70c4c1be0a14 7092905: C2: Keep track of the number of dead nodes
bharadwaj
parents: 13110
diff changeset
   154
    old->disconnect_inputs(NULL, C);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  return blk_adjust;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
//------------------------------use_prior_register-----------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
// Use the prior value instead of the current value, in an effort to make
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
// the current value go dead.  Return block iterator adjustment, in case
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
// we yank some instructions from this block.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
int PhaseChaitin::use_prior_register( Node *n, uint idx, Node *def, Block *current_block, Node_List &value, Node_List &regnd ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  // No effect?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  if( def == n->in(idx) ) return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  // Def is currently dead and can be removed?  Do not resurrect
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
  if( def->outcnt() == 0 ) return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  // Not every pair of physical registers are assignment compatible,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  // e.g. on sparc floating point registers are not assignable to integer
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  // registers.
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 14623
diff changeset
   172
  const LRG &def_lrg = lrgs(_lrg_map.live_range_id(def));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  OptoReg::Name def_reg = def_lrg.reg();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  const RegMask &use_mask = n->in_RegMask(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  bool can_use = ( RegMask::can_represent(def_reg) ? (use_mask.Member(def_reg) != 0)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
                                                   : (use_mask.is_AllStack() != 0));
13104
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   177
  if (!RegMask::is_vector(def->ideal_reg())) {
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   178
    // Check for a copy to or from a misaligned pair.
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   179
    // It is workaround for a sparc with misaligned pairs.
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   180
    can_use = can_use && !use_mask.is_misaligned_pair() && !def_lrg.mask().is_misaligned_pair();
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   181
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  if (!can_use)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
    return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  // Capture the old def in case it goes dead...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
  Node *old = n->in(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  // Save-on-call copies can only be elided if the entire copy chain can go
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  // away, lest we get the same callee-save value alive in 2 locations at
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  // once.  We check for the obvious trivial case here.  Although it can
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  // sometimes be elided with cooperation outside our scope, here we will just
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  // miss the opportunity.  :-(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  if( may_be_copy_of_callee(def) ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
    if( old->outcnt() > 1 ) return 0; // We're the not last user
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    int idx = old->is_Copy();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
    assert( idx, "chain of copies being removed" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
    Node *old2 = old->in(idx);  // Chain of copies
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
    if( old2->outcnt() > 1 ) return 0; // old is not the last user
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
    int idx2 = old2->is_Copy();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
    if( !idx2 ) return 0;       // Not a chain of 2 copies
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
    if( def != old2->in(idx2) ) return 0; // Chain of exactly 2 copies
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  // Use the new def
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  n->set_req(idx,def);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  _post_alloc++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  // Is old def now dead?  We successfully yanked a copy?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  return yank_if_dead(old,current_block,&value,&regnd);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
//------------------------------skip_copies------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
// Skip through any number of copies (that don't mod oop-i-ness)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
Node *PhaseChaitin::skip_copies( Node *c ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  int idx = c->is_Copy();
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 14623
diff changeset
   217
  uint is_oop = lrgs(_lrg_map.live_range_id(c))._is_oop;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  while (idx != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
    guarantee(c->in(idx) != NULL, "must not resurrect dead copy");
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 14623
diff changeset
   220
    if (lrgs(_lrg_map.live_range_id(c->in(idx)))._is_oop != is_oop) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
      break;  // casting copy, not the same value
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 14623
diff changeset
   222
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
    c = c->in(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
    idx = c->is_Copy();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  return c;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
//------------------------------elide_copy-------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
// Remove (bypass) copies along Node n, edge k.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
int PhaseChaitin::elide_copy( Node *n, int k, Block *current_block, Node_List &value, Node_List &regnd, bool can_change_regs ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  int blk_adjust = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 14623
diff changeset
   234
  uint nk_idx = _lrg_map.live_range_id(n->in(k));
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 14623
diff changeset
   235
  OptoReg::Name nk_reg = lrgs(nk_idx).reg();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  // Remove obvious same-register copies
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  Node *x = n->in(k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  int idx;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  while( (idx=x->is_Copy()) != 0 ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
    Node *copy = x->in(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
    guarantee(copy != NULL, "must not resurrect dead copy");
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 14623
diff changeset
   243
    if(lrgs(_lrg_map.live_range_id(copy)).reg() != nk_reg) {
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 14623
diff changeset
   244
      break;
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 14623
diff changeset
   245
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
    blk_adjust += use_prior_register(n,k,copy,current_block,value,regnd);
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 14623
diff changeset
   247
    if (n->in(k) != copy) {
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 14623
diff changeset
   248
      break; // Failed for some cutout?
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 14623
diff changeset
   249
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
    x = copy;                   // Progress, try again
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  // Phis and 2-address instructions cannot change registers so easily - their
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  // outputs must match their input.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  if( !can_change_regs )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
    return blk_adjust;          // Only check stupid copies!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  // Loop backedges won't have a value-mapping yet
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
  if( &value == NULL ) return blk_adjust;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
  // Skip through all copies to the _value_ being used.  Do not change from
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
  // int to pointer.  This attempts to jump through a chain of copies, where
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
  // intermediate copies might be illegal, i.e., value is stored down to stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
  // then reloaded BUT survives in a register the whole way.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
  Node *val = skip_copies(n->in(k));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
   267
  if (val == x && nk_idx != 0 &&
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
   268
      regnd[nk_reg] != NULL && regnd[nk_reg] != x &&
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 14623
diff changeset
   269
      _lrg_map.live_range_id(x) == _lrg_map.live_range_id(regnd[nk_reg])) {
7433
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
   270
    // When rematerialzing nodes and stretching lifetimes, the
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
   271
    // allocator will reuse the original def for multidef LRG instead
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
   272
    // of the current reaching def because it can't know it's safe to
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
   273
    // do so.  After allocation completes if they are in the same LRG
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
   274
    // then it should use the current reaching def instead.
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
   275
    n->set_req(k, regnd[nk_reg]);
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
   276
    blk_adjust += yank_if_dead(val, current_block, &value, &regnd);
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
   277
    val = skip_copies(n->in(k));
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
   278
  }
b418028612ad 6961690: load oops from constant table on SPARC
twisti
parents: 7397
diff changeset
   279
13104
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   280
  if (val == x) return blk_adjust; // No progress?
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
13104
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   282
  int n_regs = RegMask::num_registers(val->ideal_reg());
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 14623
diff changeset
   283
  uint val_idx = _lrg_map.live_range_id(val);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  OptoReg::Name val_reg = lrgs(val_idx).reg();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
  // See if it happens to already be in the correct register!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
  // (either Phi's direct register, or the common case of the name
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  // never-clobbered original-def register)
13104
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   289
  if (register_contains_value(val, val_reg, n_regs, value)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
    blk_adjust += use_prior_register(n,k,regnd[val_reg],current_block,value,regnd);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
    if( n->in(k) == regnd[val_reg] ) // Success!  Quit trying
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
      return blk_adjust;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  // See if we can skip the copy by changing registers.  Don't change from
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  // using a register to using the stack unless we know we can remove a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  // copy-load.  Otherwise we might end up making a pile of Intel cisc-spill
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
  // ops reading from memory instead of just loading once and using the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
  // register.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
  // Also handle duplicate copies here.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
  const Type *t = val->is_Con() ? val->bottom_type() : NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  // Scan all registers to see if this value is around already
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
  for( uint reg = 0; reg < (uint)_max_reg; reg++ ) {
1432
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 670
diff changeset
   306
    if (reg == (uint)nk_reg) {
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 670
diff changeset
   307
      // Found ourselves so check if there is only one user of this
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 670
diff changeset
   308
      // copy and keep on searching for a better copy if so.
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 670
diff changeset
   309
      bool ignore_self = true;
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 670
diff changeset
   310
      x = n->in(k);
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 670
diff changeset
   311
      DUIterator_Fast imax, i = x->fast_outs(imax);
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 670
diff changeset
   312
      Node* first = x->fast_out(i); i++;
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 670
diff changeset
   313
      while (i < imax && ignore_self) {
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 670
diff changeset
   314
        Node* use = x->fast_out(i); i++;
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 670
diff changeset
   315
        if (use != first) ignore_self = false;
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 670
diff changeset
   316
      }
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 670
diff changeset
   317
      if (ignore_self) continue;
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 670
diff changeset
   318
    }
44f076e3d2a4 6667595: Set probability FAIR for pre-, post- loops and ALWAYS for main loop
kvn
parents: 670
diff changeset
   319
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
    Node *vv = value[reg];
13110
f84319c2aca0 7178280: Failed new vector regression tests
kvn
parents: 13104
diff changeset
   321
    if (n_regs > 1) { // Doubles and vectors check for aligned-adjacent set
f84319c2aca0 7178280: Failed new vector regression tests
kvn
parents: 13104
diff changeset
   322
      uint last = (n_regs-1); // Looking for the last part of a set
f84319c2aca0 7178280: Failed new vector regression tests
kvn
parents: 13104
diff changeset
   323
      if ((reg&last) != last) continue; // Wrong part of a set
f84319c2aca0 7178280: Failed new vector regression tests
kvn
parents: 13104
diff changeset
   324
      if (!register_contains_value(vv, reg, n_regs, value)) continue; // Different value
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
    if( vv == val ||            // Got a direct hit?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
        (t && vv && vv->bottom_type() == t && vv->is_Mach() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
         vv->as_Mach()->rule() == val->as_Mach()->rule()) ) { // Or same constant?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
      assert( !n->is_Phi(), "cannot change registers at a Phi so easily" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
      if( OptoReg::is_stack(nk_reg) || // CISC-loading from stack OR
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
          OptoReg::is_reg(reg) || // turning into a register use OR
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
          regnd[reg]->outcnt()==1 ) { // last use of a spill-load turns into a CISC use
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
        blk_adjust += use_prior_register(n,k,regnd[reg],current_block,value,regnd);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
        if( n->in(k) == regnd[reg] ) // Success!  Quit trying
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
          return blk_adjust;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
      } // End of if not degrading to a stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
    } // End of if found value in another register
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
  } // End of scan all machine registers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
  return blk_adjust;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
// Check if nreg already contains the constant value val.  Normal copy
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
// elimination doesn't doesn't work on constants because multiple
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
// nodes can represent the same constant so the type and rule of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
// MachNode must be checked to ensure equivalence.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
//
243
79b67a7a584a 6661247: Internal bug in 32-bit HotSpot optimizer while bit manipulations
never
parents: 1
diff changeset
   349
bool PhaseChaitin::eliminate_copy_of_constant(Node* val, Node* n,
79b67a7a584a 6661247: Internal bug in 32-bit HotSpot optimizer while bit manipulations
never
parents: 1
diff changeset
   350
                                              Block *current_block,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
                                              Node_List& value, Node_List& regnd,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
                                              OptoReg::Name nreg, OptoReg::Name nreg2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
  if (value[nreg] != val && val->is_Con() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
      value[nreg] != NULL && value[nreg]->is_Con() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
      (nreg2 == OptoReg::Bad || value[nreg] == value[nreg2]) &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
      value[nreg]->bottom_type() == val->bottom_type() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
      value[nreg]->as_Mach()->rule() == val->as_Mach()->rule()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
    // This code assumes that two MachNodes representing constants
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
    // which have the same rule and the same bottom type will produce
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
    // identical effects into a register.  This seems like it must be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
    // objectively true unless there are hidden inputs to the nodes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
    // but if that were to change this code would need to updated.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
    // Since they are equivalent the second one if redundant and can
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
    // be removed.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
    //
243
79b67a7a584a 6661247: Internal bug in 32-bit HotSpot optimizer while bit manipulations
never
parents: 1
diff changeset
   366
    // n will be replaced with the old value but n might have
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
    // kills projections associated with it so remove them now so that
2131
98f9cef66a34 6810672: Comment typos
twisti
parents: 1432
diff changeset
   368
    // yank_if_dead will be able to eliminate the copy once the uses
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
    // have been transferred to the old[value].
243
79b67a7a584a 6661247: Internal bug in 32-bit HotSpot optimizer while bit manipulations
never
parents: 1
diff changeset
   370
    for (DUIterator_Fast imax, i = n->fast_outs(imax); i < imax; i++) {
79b67a7a584a 6661247: Internal bug in 32-bit HotSpot optimizer while bit manipulations
never
parents: 1
diff changeset
   371
      Node* use = n->fast_out(i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
      if (use->is_Proj() && use->outcnt() == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
        // Kill projections have no users and one input
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
        use->set_req(0, C->top());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
        yank_if_dead(use, current_block, &value, &regnd);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
        --i; --imax;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
    _post_alloc++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
    return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
//------------------------------post_allocate_copy_removal---------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
// Post-Allocation peephole copy removal.  We do this in 1 pass over the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
// basic blocks.  We maintain a mapping of registers to Nodes (an  array of
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
// Nodes indexed by machine register or stack slot number).  NULL means that a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
// register is not mapped to any Node.  We can (want to have!) have several
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
// registers map to the same Node.  We walk forward over the instructions
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
// updating the mapping as we go.  At merge points we force a NULL if we have
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
// to merge 2 different Nodes into the same register.  Phi functions will give
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
// us a new Node if there is a proper value merging.  Since the blocks are
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
// arranged in some RPO, we will visit all parent blocks before visiting any
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
// successor blocks (except at loops).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
// If we find a Copy we look to see if the Copy's source register is a stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
// slot and that value has already been loaded into some machine register; if
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
// so we use machine register directly.  This turns a Load into a reg-reg
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
// Move.  We also look for reloads of identical constants.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
// When we see a use from a reg-reg Copy, we will attempt to use the copy's
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
// source directly and make the copy go dead.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
void PhaseChaitin::post_allocate_copy_removal() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
  NOT_PRODUCT( Compile::TracePhase t3("postAllocCopyRemoval", &_t_postAllocCopyRemoval, TimeCompiler); )
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
  ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
  // Need a mapping from basic block Node_Lists.  We need a Node_List to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
  // map from register number to value-producing Node.
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   411
  Node_List **blk2value = NEW_RESOURCE_ARRAY( Node_List *, _cfg.number_of_blocks() + 1);
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   412
  memset(blk2value, 0, sizeof(Node_List*) * (_cfg.number_of_blocks() + 1));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
  // Need a mapping from basic block Node_Lists.  We need a Node_List to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
  // map from register number to register-defining Node.
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   415
  Node_List **blk2regnd = NEW_RESOURCE_ARRAY( Node_List *, _cfg.number_of_blocks() + 1);
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   416
  memset(blk2regnd, 0, sizeof(Node_List*) * (_cfg.number_of_blocks() + 1));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
  // We keep unused Node_Lists on a free_list to avoid wasting
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
  // memory.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
  GrowableArray<Node_List*> free_list = GrowableArray<Node_List*>(16);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
  // For all blocks
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   423
  for (uint i = 0; i < _cfg.number_of_blocks(); i++) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
    uint j;
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   425
    Block* block = _cfg.get_block(i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
    // Count of Phis in block
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
    uint phi_dex;
19717
7819ffdaf0ff 8023691: Create interface for nodes in class Block
adlertz
parents: 19330
diff changeset
   429
    for (phi_dex = 1; phi_dex < block->number_of_nodes(); phi_dex++) {
7819ffdaf0ff 8023691: Create interface for nodes in class Block
adlertz
parents: 19330
diff changeset
   430
      Node* phi = block->get_node(phi_dex);
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   431
      if (!phi->is_Phi()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
        break;
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   433
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
    // If any predecessor has not been visited, we do not know the state
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
    // of registers at the start.  Check for this, while updating copies
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
    // along Phi input edges
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
    bool missing_some_inputs = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
    Block *freed = NULL;
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   441
    for (j = 1; j < block->num_preds(); j++) {
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   442
      Block* pb = _cfg.get_block_for_node(block->pred(j));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
      // Remove copies along phi edges
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   444
      for (uint k = 1; k < phi_dex; k++) {
19717
7819ffdaf0ff 8023691: Create interface for nodes in class Block
adlertz
parents: 19330
diff changeset
   445
        elide_copy(block->get_node(k), j, block, *blk2value[pb->_pre_order], *blk2regnd[pb->_pre_order], false);
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   446
      }
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   447
      if (blk2value[pb->_pre_order]) { // Have a mapping on this edge?
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
        // See if this predecessor's mappings have been used by everybody
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
        // who wants them.  If so, free 'em.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
        uint k;
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   451
        for (k = 0; k < pb->_num_succs; k++) {
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   452
          Block* pbsucc = pb->_succs[k];
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   453
          if (!blk2value[pbsucc->_pre_order] && pbsucc != block) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
            break;              // Found a future user
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   455
          }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
        }
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   457
        if (k >= pb->_num_succs) { // No more uses, free!
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
          freed = pb;           // Record last block freed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
          free_list.push(blk2value[pb->_pre_order]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
          free_list.push(blk2regnd[pb->_pre_order]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
      } else {                  // This block has unvisited (loopback) inputs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
        missing_some_inputs = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
    // Extract Node_List mappings.  If 'freed' is non-zero, we just popped
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
    // 'freed's blocks off the list
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
    Node_List &regnd = *(free_list.is_empty() ? new Node_List() : free_list.pop());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
    Node_List &value = *(free_list.is_empty() ? new Node_List() : free_list.pop());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
    assert( !freed || blk2value[freed->_pre_order] == &value, "" );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
    value.map(_max_reg,NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
    regnd.map(_max_reg,NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
    // Set mappings as OUR mappings
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   476
    blk2value[block->_pre_order] = &value;
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   477
    blk2regnd[block->_pre_order] = &regnd;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
    // Initialize value & regnd for this block
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   480
    if (missing_some_inputs) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
      // Some predecessor has not yet been visited; zap map to empty
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   482
      for (uint k = 0; k < (uint)_max_reg; k++) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
        value.map(k,NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
        regnd.map(k,NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
      if( !freed ) {            // Didn't get a freebie prior block
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
        // Must clone some data
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   489
        freed = _cfg.get_block_for_node(block->pred(1));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
        Node_List &f_value = *blk2value[freed->_pre_order];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
        Node_List &f_regnd = *blk2regnd[freed->_pre_order];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
        for( uint k = 0; k < (uint)_max_reg; k++ ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
          value.map(k,f_value[k]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
          regnd.map(k,f_regnd[k]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
      // Merge all inputs together, setting to NULL any conflicts.
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   498
      for (j = 1; j < block->num_preds(); j++) {
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   499
        Block* pb = _cfg.get_block_for_node(block->pred(j));
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   500
        if (pb == freed) {
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   501
          continue; // Did self already via freelist
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   502
        }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
        Node_List &p_regnd = *blk2regnd[pb->_pre_order];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
        for( uint k = 0; k < (uint)_max_reg; k++ ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
          if( regnd[k] != p_regnd[k] ) { // Conflict on reaching defs?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
            value.map(k,NULL); // Then no value handy
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
            regnd.map(k,NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
    // For all Phi's
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   514
    for (j = 1; j < phi_dex; j++) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
      uint k;
19717
7819ffdaf0ff 8023691: Create interface for nodes in class Block
adlertz
parents: 19330
diff changeset
   516
      Node *phi = block->get_node(j);
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 14623
diff changeset
   517
      uint pidx = _lrg_map.live_range_id(phi);
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 14623
diff changeset
   518
      OptoReg::Name preg = lrgs(_lrg_map.live_range_id(phi)).reg();
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
      // Remove copies remaining on edges.  Check for junk phi.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
      Node *u = NULL;
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 14623
diff changeset
   522
      for (k = 1; k < phi->req(); k++) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
        Node *x = phi->in(k);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
        if( phi != x && u != x ) // Found a different input
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
          u = u ? NodeSentinel : x; // Capture unique input, or NodeSentinel for 2nd input
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
      }
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   527
      if (u != NodeSentinel) {    // Junk Phi.  Remove
21200
5f7a5282462d 8026940: assert(n->outcnt() != 0 || C->top() == n || n->is_Proj()) failed: No dead instructions after post-alloc
adlertz
parents: 19717
diff changeset
   528
        phi->replace_by(u);
5f7a5282462d 8026940: assert(n->outcnt() != 0 || C->top() == n || n->is_Proj()) failed: No dead instructions after post-alloc
adlertz
parents: 19717
diff changeset
   529
        j -= yank_if_dead(phi, block, &value, &regnd);
19279
4be3c2e6663c 8022284: Hide internal data structure in PhaseCFG
adlertz
parents: 17013
diff changeset
   530
        phi_dex--;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
        continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
      // Note that if value[pidx] exists, then we merged no new values here
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
      // and the phi is useless.  This can happen even with the above phi
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
      // removal for complex flows.  I cannot keep the better known value here
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
      // because locally the phi appears to define a new merged value.  If I
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
      // keep the better value then a copy of the phi, being unable to use the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
      // global flow analysis, can't "peek through" the phi to the original
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
      // reaching value and so will act like it's defining a new value.  This
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
      // can lead to situations where some uses are from the old and some from
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
      // the new values.  Not illegal by itself but throws the over-strong
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
      // assert in scheduling.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
      if( pidx ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
        value.map(preg,phi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
        regnd.map(preg,phi);
13104
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   546
        int n_regs = RegMask::num_registers(phi->ideal_reg());
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   547
        for (int l = 1; l < n_regs; l++) {
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   548
          OptoReg::Name preg_lo = OptoReg::add(preg,-l);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
          value.map(preg_lo,phi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
          regnd.map(preg_lo,phi);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
    // For all remaining instructions
19717
7819ffdaf0ff 8023691: Create interface for nodes in class Block
adlertz
parents: 19330
diff changeset
   556
    for (j = phi_dex; j < block->number_of_nodes(); j++) {
7819ffdaf0ff 8023691: Create interface for nodes in class Block
adlertz
parents: 19330
diff changeset
   557
      Node* n = block->get_node(j);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   559
      if(n->outcnt() == 0 &&   // Dead?
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   560
         n != C->top() &&      // (ignore TOP, it has no du info)
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   561
         !n->is_Proj() ) {     // fat-proj kills
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   562
        j -= yank_if_dead(n, block, &value, &regnd);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
        continue;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
      // Improve reaching-def info.  Occasionally post-alloc's liveness gives
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
      // up (at loop backedges, because we aren't doing a full flow pass).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
      // The presence of a live use essentially asserts that the use's def is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
      // alive and well at the use (or else the allocator fubar'd).  Take
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
      // advantage of this info to set a reaching def for the use-reg.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
      uint k;
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 14623
diff changeset
   572
      for (k = 1; k < n->req(); k++) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
        Node *def = n->in(k);   // n->in(k) is a USE; def is the DEF for this USE
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
        guarantee(def != NULL, "no disconnected nodes at this point");
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 14623
diff changeset
   575
        uint useidx = _lrg_map.live_range_id(def); // useidx is the live range index for this USE
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
        if( useidx ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
          OptoReg::Name ureg = lrgs(useidx).reg();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
          if( !value[ureg] ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
            int idx;            // Skip occasional useless copy
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
            while( (idx=def->is_Copy()) != 0 &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
                   def->in(idx) != NULL &&  // NULL should not happen
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 14623
diff changeset
   583
                   ureg == lrgs(_lrg_map.live_range_id(def->in(idx))).reg())
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
              def = def->in(idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
            Node *valdef = skip_copies(def); // tighten up val through non-useless copies
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
            value.map(ureg,valdef); // record improved reaching-def info
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
            regnd.map(ureg,   def);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
            // Record other half of doubles
13104
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   589
            uint def_ideal_reg = def->ideal_reg();
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   590
            int n_regs = RegMask::num_registers(def_ideal_reg);
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   591
            for (int l = 1; l < n_regs; l++) {
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   592
              OptoReg::Name ureg_lo = OptoReg::add(ureg,-l);
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   593
              if (!value[ureg_lo] &&
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   594
                  (!RegMask::can_represent(ureg_lo) ||
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   595
                   lrgs(useidx).mask().Member(ureg_lo))) { // Nearly always adjacent
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   596
                value.map(ureg_lo,valdef); // record improved reaching-def info
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   597
                regnd.map(ureg_lo,   def);
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   598
              }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
      const uint two_adr = n->is_Mach() ? n->as_Mach()->two_adr() : 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
      // Remove copies along input edges
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   607
      for (k = 1; k < n->req(); k++) {
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   608
        j -= elide_copy(n, k, block, value, regnd, two_adr != k);
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   609
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
      // Unallocated Nodes define no registers
17013
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 14623
diff changeset
   612
      uint lidx = _lrg_map.live_range_id(n);
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 14623
diff changeset
   613
      if (!lidx) {
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 14623
diff changeset
   614
        continue;
22a05c7f3314 8011621: live_ranges_in_separate_class.patch
neliasso
parents: 14623
diff changeset
   615
      }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
      // Update the register defined by this instruction
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
      OptoReg::Name nreg = lrgs(lidx).reg();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
      // Skip through all copies to the _value_ being defined.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
      // Do not change from int to pointer
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
      Node *val = skip_copies(n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
3678
d797d97552e4 6862863: C2 compiler fails in elide_copy()
never
parents: 2131
diff changeset
   623
      // Clear out a dead definition before starting so that the
d797d97552e4 6862863: C2 compiler fails in elide_copy()
never
parents: 2131
diff changeset
   624
      // elimination code doesn't have to guard against it.  The
d797d97552e4 6862863: C2 compiler fails in elide_copy()
never
parents: 2131
diff changeset
   625
      // definition could in fact be a kill projection with a count of
d797d97552e4 6862863: C2 compiler fails in elide_copy()
never
parents: 2131
diff changeset
   626
      // 0 which is safe but since those are uninteresting for copy
d797d97552e4 6862863: C2 compiler fails in elide_copy()
never
parents: 2131
diff changeset
   627
      // elimination just delete them as well.
d797d97552e4 6862863: C2 compiler fails in elide_copy()
never
parents: 2131
diff changeset
   628
      if (regnd[nreg] != NULL && regnd[nreg]->outcnt() == 0) {
d797d97552e4 6862863: C2 compiler fails in elide_copy()
never
parents: 2131
diff changeset
   629
        regnd.map(nreg, NULL);
d797d97552e4 6862863: C2 compiler fails in elide_copy()
never
parents: 2131
diff changeset
   630
        value.map(nreg, NULL);
d797d97552e4 6862863: C2 compiler fails in elide_copy()
never
parents: 2131
diff changeset
   631
      }
d797d97552e4 6862863: C2 compiler fails in elide_copy()
never
parents: 2131
diff changeset
   632
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
      uint n_ideal_reg = n->ideal_reg();
13104
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   634
      int n_regs = RegMask::num_registers(n_ideal_reg);
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   635
      if (n_regs == 1) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
        // If Node 'n' does not change the value mapped by the register,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
        // then 'n' is a useless copy.  Do not update the register->node
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
        // mapping so 'n' will go dead.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
        if( value[nreg] != val ) {
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   640
          if (eliminate_copy_of_constant(val, n, block, value, regnd, nreg, OptoReg::Bad)) {
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   641
            j -= replace_and_yank_if_dead(n, nreg, block, value, regnd);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
          } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
            // Update the mapping: record new Node defined by the register
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
            regnd.map(nreg,n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
            // Update mapping for defined *value*, which is the defined
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
            // Node after skipping all copies.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
            value.map(nreg,val);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
          }
3678
d797d97552e4 6862863: C2 compiler fails in elide_copy()
never
parents: 2131
diff changeset
   649
        } else if( !may_be_copy_of_callee(n) ) {
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   650
          assert(n->is_Copy(), "");
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   651
          j -= replace_and_yank_if_dead(n, nreg, block, value, regnd);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
        }
13104
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   653
      } else if (RegMask::is_vector(n_ideal_reg)) {
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   654
        // If Node 'n' does not change the value mapped by the register,
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   655
        // then 'n' is a useless copy.  Do not update the register->node
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   656
        // mapping so 'n' will go dead.
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   657
        if (!register_contains_value(val, nreg, n_regs, value)) {
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   658
          // Update the mapping: record new Node defined by the register
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   659
          regnd.map(nreg,n);
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   660
          // Update mapping for defined *value*, which is the defined
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   661
          // Node after skipping all copies.
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   662
          value.map(nreg,val);
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   663
          for (int l = 1; l < n_regs; l++) {
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   664
            OptoReg::Name nreg_lo = OptoReg::add(nreg,-l);
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   665
            regnd.map(nreg_lo, n );
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   666
            value.map(nreg_lo,val);
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   667
          }
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   668
        } else if (n->is_Copy()) {
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   669
          // Note: vector can't be constant and can't be copy of calee.
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   670
          j -= replace_and_yank_if_dead(n, nreg, block, value, regnd);
13104
657b387034fb 7119644: Increase superword's vector size up to 256 bits
kvn
parents: 11444
diff changeset
   671
        }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
        // If the value occupies a register pair, record same info
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
        // in both registers.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
        OptoReg::Name nreg_lo = OptoReg::add(nreg,-1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
        if( RegMask::can_represent(nreg_lo) &&     // Either a spill slot, or
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
            !lrgs(lidx).mask().Member(nreg_lo) ) { // Nearly always adjacent
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
          // Sparc occasionally has non-adjacent pairs.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
          // Find the actual other value
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
          RegMask tmp = lrgs(lidx).mask();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
          tmp.Remove(nreg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
          nreg_lo = tmp.find_first_elem();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
        }
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   684
        if (value[nreg] != val || value[nreg_lo] != val) {
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   685
          if (eliminate_copy_of_constant(val, n, block, value, regnd, nreg, nreg_lo)) {
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   686
            j -= replace_and_yank_if_dead(n, nreg, block, value, regnd);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
          } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
            regnd.map(nreg   , n );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
            regnd.map(nreg_lo, n );
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
            value.map(nreg   ,val);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
            value.map(nreg_lo,val);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
          }
19330
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   693
        } else if (!may_be_copy_of_callee(n)) {
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   694
          assert(n->is_Copy(), "");
49d6711171e6 8023003: Cleanup the public interface to PhaseCFG
adlertz
parents: 19279
diff changeset
   695
          j -= replace_and_yank_if_dead(n, nreg, block, value, regnd);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
      // Fat projections kill many registers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
      if( n_ideal_reg == MachProjNode::fat_proj ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
        RegMask rm = n->out_RegMask();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
        // wow, what an expensive iterator...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
        nreg = rm.find_first_elem();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
        while( OptoReg::is_valid(nreg)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
          rm.Remove(nreg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
          value.map(nreg,n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
          regnd.map(nreg,n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
          nreg = rm.find_first_elem();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
    } // End of for all instructions in the block
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
  } // End for all blocks
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
}