hotspot/src/cpu/x86/vm/c1_LinearScan_x86.cpp
author phh
Fri, 07 Jan 2011 10:42:32 -0500
changeset 7724 a92d706dbdd5
parent 7397 5b173b4ca846
child 12739 09f26b73ae66
permissions -rw-r--r--
7003271: Hotspot should track cumulative Java heap bytes allocated on a per-thread basis Summary: Track allocated bytes in Thread's, update on TLAB retirement and direct allocation in Eden and tenured, add JNI methods for ThreadMXBean. Reviewed-by: coleenp, kvn, dholmes, ysr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
     2
 * Copyright (c) 2005, 2010, 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: 3800
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3800
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: 3800
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 "c1/c1_Instruction.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
#include "c1/c1_LinearScan.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    28
#include "utilities/bitMap.inline.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
//----------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// Allocation of FPU stack slots (Intel x86 only)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
//----------------------------------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
void LinearScan::allocate_fpu_stack() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
  // First compute which FPU registers are live at the start of each basic block
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
  // (To minimize the amount of work we have to do if we have to merge FPU stacks)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  if (ComputeExactFPURegisterUsage) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
    Interval* intervals_in_register, *intervals_in_memory;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
    create_unhandled_lists(&intervals_in_register, &intervals_in_memory, is_in_fpu_register, NULL);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
    // ignore memory intervals by overwriting intervals_in_memory
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
    // the dummy interval is needed to enforce the walker to walk until the given id:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
    // without it, the walker stops when the unhandled-list is empty -> live information
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
    // beyond this point would be incorrect.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
    Interval* dummy_interval = new Interval(any_reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
    dummy_interval->add_range(max_jint - 2, max_jint - 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
    dummy_interval->set_next(Interval::end());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
    intervals_in_memory = dummy_interval;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
    IntervalWalker iw(this, intervals_in_register, intervals_in_memory);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    const int num_blocks = block_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    for (int i = 0; i < num_blocks; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
      BlockBegin* b = block_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
      // register usage is only needed for merging stacks -> compute only
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
      // when more than one predecessor.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
      // the block must not have any spill moves at the beginning (checked by assertions)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
      // spill moves would use intervals that are marked as handled and so the usage bit
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
      // would been set incorrectly
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
      // NOTE: the check for number_of_preds > 1 is necessary. A block with only one
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
      //       predecessor may have spill moves at the begin of the block.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
      //       If an interval ends at the current instruction id, it is not possible
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
      //       to decide if the register is live or not at the block begin -> the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
      //       register information would be incorrect.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
      if (b->number_of_preds() > 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
        int id = b->first_lir_instruction_id();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
        BitMap regs(FrameMap::nof_fpu_regs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
        regs.clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
        iw.walk_to(id);   // walk after the first instruction (always a label) of the block
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
        assert(iw.current_position() == id, "did not walk completely to id");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
        // Only consider FPU values in registers
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
        Interval* interval = iw.active_first(fixedKind);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
        while (interval != Interval::end()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
          int reg = interval->assigned_reg();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
          assert(reg >= pd_first_fpu_reg && reg <= pd_last_fpu_reg, "no fpu register");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
          assert(interval->assigned_regHi() == -1, "must not have hi register (doubles stored in one register)");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
          assert(interval->from() <= id && id < interval->to(), "interval out of range");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
          if (TraceFPURegisterUsage) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
            tty->print("fpu reg %d is live because of ", reg - pd_first_fpu_reg); interval->print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
          regs.set_bit(reg - pd_first_fpu_reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
          interval = interval->next();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
        b->set_fpu_register_usage(regs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
        if (TraceFPURegisterUsage) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
          tty->print("FPU regs for block %d, LIR instr %d): ", b->block_id(), id); regs.print_on(tty); tty->print_cr("");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  FpuStackAllocator alloc(ir()->compilation(), this);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  _fpu_stack_allocator = &alloc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  alloc.allocate();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  _fpu_stack_allocator = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
FpuStackAllocator::FpuStackAllocator(Compilation* compilation, LinearScan* allocator)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  : _compilation(compilation)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  , _lir(NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  , _pos(-1)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  , _allocator(allocator)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
  , _sim(compilation)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  , _temp_sim(compilation)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
{}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
void FpuStackAllocator::allocate() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  int num_blocks = allocator()->block_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  for (int i = 0; i < num_blocks; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
    // Set up to process block
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
    BlockBegin* block = allocator()->block_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    intArray* fpu_stack_state = block->fpu_stack_state();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
    if (TraceFPUStack) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
      tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
      tty->print_cr("------- Begin of new Block %d -------", block->block_id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    assert(fpu_stack_state != NULL ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
           block->end()->as_Base() != NULL ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
           block->is_set(BlockBegin::exception_entry_flag),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
           "FPU stack state must be present due to linear-scan order for FPU stack allocation");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    // note: exception handler entries always start with an empty fpu stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
    //       because stack merging would be too complicated
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
    if (fpu_stack_state != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
      sim()->read_state(fpu_stack_state);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
      sim()->clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
    if (TraceFPUStack) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
      tty->print("Reading FPU state for block %d:", block->block_id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
      sim()->print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
      tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
    allocate_block(block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    CHECK_BAILOUT();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
void FpuStackAllocator::allocate_block(BlockBegin* block) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  bool processed_merge = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  LIR_OpList* insts = block->lir()->instructions_list();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  set_lir(block->lir());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  set_pos(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  // Note: insts->length() may change during loop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  while (pos() < insts->length()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
    LIR_Op* op = insts->at(pos());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
    _debug_information_computed = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
    if (TraceFPUStack) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
      op->print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
    check_invalid_lir_op(op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    LIR_OpBranch* branch = op->as_OpBranch();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    LIR_Op1* op1 = op->as_Op1();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    LIR_Op2* op2 = op->as_Op2();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
    LIR_OpCall* opCall = op->as_OpCall();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
    if (branch != NULL && branch->block() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
      if (!processed_merge) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
        // propagate stack at first branch to a successor
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
        processed_merge = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
        bool required_merge = merge_fpu_stack_with_successors(block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
        assert(!required_merge || branch->cond() == lir_cond_always, "splitting of critical edges should prevent FPU stack mismatches at cond branches");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
    } else if (op1 != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
      handle_op1(op1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
    } else if (op2 != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
      handle_op2(op2);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
    } else if (opCall != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
      handle_opCall(opCall);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
    compute_debug_information(op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
    set_pos(1 + pos());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  // Propagate stack when block does not end with branch
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  if (!processed_merge) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
    merge_fpu_stack_with_successors(block);
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
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
void FpuStackAllocator::compute_debug_information(LIR_Op* op) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  if (!_debug_information_computed && op->id() != -1 && allocator()->has_info(op->id())) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
    visitor.visit(op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
    // exception handling
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
    if (allocator()->compilation()->has_exception_handlers()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
      XHandlers* xhandlers = visitor.all_xhandler();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
      int n = xhandlers->length();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
      for (int k = 0; k < n; k++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
        allocate_exception_handler(xhandlers->handler_at(k));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
      assert(visitor.all_xhandler()->length() == 0, "missed exception handler");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
    // compute debug information
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
    int n = visitor.info_count();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
    assert(n > 0, "should not visit operation otherwise");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
    for (int j = 0; j < n; j++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
      CodeEmitInfo* info = visitor.info_at(j);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
      // Compute debug information
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
      allocator()->compute_debug_info(info, op->id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  _debug_information_computed = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
void FpuStackAllocator::allocate_exception_handler(XHandler* xhandler) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
  if (!sim()->is_empty()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
    LIR_List* old_lir = lir();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
    int old_pos = pos();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
    intArray* old_state = sim()->write_state();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
    if (TraceFPUStack) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
      tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
      tty->print_cr("------- begin of exception handler -------");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
    if (xhandler->entry_code() == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
      // need entry code to clear FPU stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
      LIR_List* entry_code = new LIR_List(_compilation);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
      entry_code->jump(xhandler->entry_block());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
      xhandler->set_entry_code(entry_code);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
    LIR_OpList* insts = xhandler->entry_code()->instructions_list();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
    set_lir(xhandler->entry_code());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
    set_pos(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
    // Note: insts->length() may change during loop
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
    while (pos() < insts->length()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
      LIR_Op* op = insts->at(pos());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
      if (TraceFPUStack) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
        op->print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
      check_invalid_lir_op(op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
      switch (op->code()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
        case lir_move:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
          assert(op->as_Op1() != NULL, "must be LIR_Op1");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
          assert(pos() != insts->length() - 1, "must not be last operation");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
          handle_op1((LIR_Op1*)op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
        case lir_branch:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
          assert(op->as_OpBranch()->cond() == lir_cond_always, "must be unconditional branch");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
          assert(pos() == insts->length() - 1, "must be last operation");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
          // remove all remaining dead registers from FPU stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
          clear_fpu_stack(LIR_OprFact::illegalOpr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
        default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
          // other operations not allowed in exception entry code
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
          ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
      set_pos(pos() + 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
    if (TraceFPUStack) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
      tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
      tty->print_cr("------- end of exception handler -------");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
    set_lir(old_lir);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
    set_pos(old_pos);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
    sim()->read_state(old_state);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
int FpuStackAllocator::fpu_num(LIR_Opr opr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
  assert(opr->is_fpu_register() && !opr->is_xmm_register(), "shouldn't call this otherwise");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  return opr->is_single_fpu() ? opr->fpu_regnr() : opr->fpu_regnrLo();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
int FpuStackAllocator::tos_offset(LIR_Opr opr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
  return sim()->offset_from_tos(fpu_num(opr));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
LIR_Opr FpuStackAllocator::to_fpu_stack(LIR_Opr opr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
  assert(opr->is_fpu_register() && !opr->is_xmm_register(), "shouldn't call this otherwise");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
  int stack_offset = tos_offset(opr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  if (opr->is_single_fpu()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
    return LIR_OprFact::single_fpu(stack_offset)->make_fpu_stack_offset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
    assert(opr->is_double_fpu(), "shouldn't call this otherwise");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
    return LIR_OprFact::double_fpu(stack_offset)->make_fpu_stack_offset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
LIR_Opr FpuStackAllocator::to_fpu_stack_top(LIR_Opr opr, bool dont_check_offset) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
  assert(opr->is_fpu_register() && !opr->is_xmm_register(), "shouldn't call this otherwise");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
  assert(dont_check_offset || tos_offset(opr) == 0, "operand is not on stack top");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  int stack_offset = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
  if (opr->is_single_fpu()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
    return LIR_OprFact::single_fpu(stack_offset)->make_fpu_stack_offset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
    assert(opr->is_double_fpu(), "shouldn't call this otherwise");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
    return LIR_OprFact::double_fpu(stack_offset)->make_fpu_stack_offset();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
void FpuStackAllocator::insert_op(LIR_Op* op) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
  lir()->insert_before(pos(), op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
  set_pos(1 + pos());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
void FpuStackAllocator::insert_exchange(int offset) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
  if (offset > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
    LIR_Op1* fxch_op = new LIR_Op1(lir_fxch, LIR_OprFact::intConst(offset), LIR_OprFact::illegalOpr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
    insert_op(fxch_op);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
    sim()->swap(offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
    if (TraceFPUStack) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
      tty->print("Exchanged register: %d         New state: ", sim()->get_slot(0)); sim()->print(); tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
void FpuStackAllocator::insert_exchange(LIR_Opr opr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
  insert_exchange(tos_offset(opr));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
void FpuStackAllocator::insert_free(int offset) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
  // move stack slot to the top of stack and then pop it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
  insert_exchange(offset);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
  LIR_Op* fpop = new LIR_Op0(lir_fpop_raw);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
  insert_op(fpop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
  sim()->pop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
    if (TraceFPUStack) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
      tty->print("Inserted pop                   New state: "); sim()->print(); tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
void FpuStackAllocator::insert_free_if_dead(LIR_Opr opr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
  if (sim()->contains(fpu_num(opr))) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
    int res_slot = tos_offset(opr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
    insert_free(res_slot);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
void FpuStackAllocator::insert_free_if_dead(LIR_Opr opr, LIR_Opr ignore) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
  if (fpu_num(opr) != fpu_num(ignore) && sim()->contains(fpu_num(opr))) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
    int res_slot = tos_offset(opr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
    insert_free(res_slot);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
void FpuStackAllocator::insert_copy(LIR_Opr from, LIR_Opr to) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
  int offset = tos_offset(from);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
  LIR_Op1* fld = new LIR_Op1(lir_fld, LIR_OprFact::intConst(offset), LIR_OprFact::illegalOpr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
  insert_op(fld);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
  sim()->push(fpu_num(to));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
  if (TraceFPUStack) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
    tty->print("Inserted copy (%d -> %d)         New state: ", fpu_num(from), fpu_num(to)); sim()->print(); tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
void FpuStackAllocator::do_rename(LIR_Opr from, LIR_Opr to) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
  sim()->rename(fpu_num(from), fpu_num(to));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
void FpuStackAllocator::do_push(LIR_Opr opr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
  sim()->push(fpu_num(opr));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
void FpuStackAllocator::pop_if_last_use(LIR_Op* op, LIR_Opr opr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
  assert(op->fpu_pop_count() == 0, "fpu_pop_count alredy set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
  assert(tos_offset(opr) == 0, "can only pop stack top");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
  if (opr->is_last_use()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
    op->set_fpu_pop_count(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
    sim()->pop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
void FpuStackAllocator::pop_always(LIR_Op* op, LIR_Opr opr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
  assert(op->fpu_pop_count() == 0, "fpu_pop_count alredy set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
  assert(tos_offset(opr) == 0, "can only pop stack top");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
  op->set_fpu_pop_count(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
  sim()->pop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
void FpuStackAllocator::clear_fpu_stack(LIR_Opr preserve) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
  int result_stack_size = (preserve->is_fpu_register() && !preserve->is_xmm_register() ? 1 : 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
  while (sim()->stack_size() > result_stack_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
    assert(!sim()->slot_is_empty(0), "not allowed");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
    if (result_stack_size == 0 || sim()->get_slot(0) != fpu_num(preserve)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
      insert_free(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
      // move "preserve" to bottom of stack so that all other stack slots can be popped
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
      insert_exchange(sim()->stack_size() - 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
void FpuStackAllocator::handle_op1(LIR_Op1* op1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
  LIR_Opr in  = op1->in_opr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
  LIR_Opr res = op1->result_opr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
  LIR_Opr new_in  = in;  // new operands relative to the actual fpu stack top
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
  LIR_Opr new_res = res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
  // Note: this switch is processed for all LIR_Op1, regardless if they have FPU-arguments,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
  //       so checks for is_float_kind() are necessary inside the cases
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
  switch (op1->code()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
    case lir_return: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
      // FPU-Stack must only contain the (optional) fpu return value.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
      // All remaining dead values are popped from the stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
      // If the input operand is a fpu-register, it is exchanged to the bottom of the stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
      clear_fpu_stack(in);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
      if (in->is_fpu_register() && !in->is_xmm_register()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
        new_in = to_fpu_stack_top(in);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
    case lir_move: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
      if (in->is_fpu_register() && !in->is_xmm_register()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
        if (res->is_xmm_register()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
          // move from fpu register to xmm register (necessary for operations that
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
          // are not available in the SSE instruction set)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
          insert_exchange(in);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
          new_in = to_fpu_stack_top(in);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
          pop_always(op1, in);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
        } else if (res->is_fpu_register() && !res->is_xmm_register()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
          // move from fpu-register to fpu-register:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
          // * input and result register equal:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
          //   nothing to do
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
          // * input register is last use:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
          //   rename the input register to result register -> input register
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
          //   not present on fpu-stack afterwards
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
          // * input register not last use:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
          //   duplicate input register to result register to preserve input
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
          //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
          // Note: The LIR-Assembler does not produce any code for fpu register moves,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
          //       so input and result stack index must be equal
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
          if (fpu_num(in) == fpu_num(res)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
            // nothing to do
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
          } else if (in->is_last_use()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
            insert_free_if_dead(res);//, in);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
            do_rename(in, res);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
          } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
            insert_free_if_dead(res);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
            insert_copy(in, res);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
          new_in = to_fpu_stack(res);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
          new_res = new_in;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
          // move from fpu-register to memory
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
          // input operand must be on top of stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
          insert_exchange(in);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
          // create debug information here because afterwards the register may have been popped
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
          compute_debug_information(op1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
          new_in = to_fpu_stack_top(in);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
          pop_if_last_use(op1, in);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
      } else if (res->is_fpu_register() && !res->is_xmm_register()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
        // move from memory/constant to fpu register
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
        // result is pushed on the stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
        insert_free_if_dead(res);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
        // create debug information before register is pushed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
        compute_debug_information(op1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
        do_push(res);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
        new_res = to_fpu_stack_top(res);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
    case lir_neg: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
      if (in->is_fpu_register() && !in->is_xmm_register()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
        assert(res->is_fpu_register() && !res->is_xmm_register(), "must be");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
        assert(in->is_last_use(), "old value gets destroyed");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
        insert_free_if_dead(res, in);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
        insert_exchange(in);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
        new_in = to_fpu_stack_top(in);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
        do_rename(in, res);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
        new_res = to_fpu_stack_top(res);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
    case lir_convert: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   565
      Bytecodes::Code bc = op1->as_OpConvert()->bytecode();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   566
      switch (bc) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
        case Bytecodes::_d2f:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   568
        case Bytecodes::_f2d:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   569
          assert(res->is_fpu_register(), "must be");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   570
          assert(in->is_fpu_register(), "must be");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   571
489c9b5090e2 Initial load
duke
parents:
diff changeset
   572
          if (!in->is_xmm_register() && !res->is_xmm_register()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   573
            // this is quite the same as a move from fpu-register to fpu-register
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
            // Note: input and result operands must have different types
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
            if (fpu_num(in) == fpu_num(res)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
              // nothing to do
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
              new_in = to_fpu_stack(in);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
            } else if (in->is_last_use()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
              insert_free_if_dead(res);//, in);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
              new_in = to_fpu_stack(in);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
              do_rename(in, res);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
            } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
              insert_free_if_dead(res);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
              insert_copy(in, res);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
              new_in = to_fpu_stack_top(in, true);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
            new_res = to_fpu_stack(res);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
        case Bytecodes::_i2f:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   593
        case Bytecodes::_l2f:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
        case Bytecodes::_i2d:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
        case Bytecodes::_l2d:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
          assert(res->is_fpu_register(), "must be");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
          if (!res->is_xmm_register()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
            insert_free_if_dead(res);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
            do_push(res);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
            new_res = to_fpu_stack_top(res);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   602
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
        case Bytecodes::_f2i:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   605
        case Bytecodes::_d2i:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   606
          assert(in->is_fpu_register(), "must be");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
          if (!in->is_xmm_register()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
            insert_exchange(in);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   609
            new_in = to_fpu_stack_top(in);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
            // TODO: update registes of stub
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
        case Bytecodes::_f2l:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
        case Bytecodes::_d2l:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
          assert(in->is_fpu_register(), "must be");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
          if (!in->is_xmm_register()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
            insert_exchange(in);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
            new_in = to_fpu_stack_top(in);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
            pop_always(op1, in);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
        case Bytecodes::_i2l:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
        case Bytecodes::_l2i:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
        case Bytecodes::_i2b:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
        case Bytecodes::_i2c:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
        case Bytecodes::_i2s:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
          // no fpu operands
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
        default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
          ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
    case lir_roundfp: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
      assert(in->is_fpu_register() && !in->is_xmm_register(), "input must be in register");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
      assert(res->is_stack(), "result must be on stack");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
      insert_exchange(in);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
      new_in = to_fpu_stack_top(in);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
      pop_if_last_use(op1, in);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
    default: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
      assert(!in->is_float_kind() && !res->is_float_kind(), "missed a fpu-operation");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
  op1->set_in_opr(new_in);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
  op1->set_result_opr(new_res);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
void FpuStackAllocator::handle_op2(LIR_Op2* op2) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
  LIR_Opr left  = op2->in_opr1();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
  if (!left->is_float_kind()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
  if (left->is_xmm_register()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
  LIR_Opr right = op2->in_opr2();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
  LIR_Opr res   = op2->result_opr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
  LIR_Opr new_left  = left;  // new operands relative to the actual fpu stack top
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
  LIR_Opr new_right = right;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   671
  LIR_Opr new_res   = res;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
  assert(!left->is_xmm_register() && !right->is_xmm_register() && !res->is_xmm_register(), "not for xmm registers");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   674
489c9b5090e2 Initial load
duke
parents:
diff changeset
   675
  switch (op2->code()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
    case lir_cmp:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
    case lir_cmp_fd2i:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
    case lir_ucmp_fd2i: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
      assert(left->is_fpu_register(), "invalid LIR");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   680
      assert(right->is_fpu_register(), "invalid LIR");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
489c9b5090e2 Initial load
duke
parents:
diff changeset
   682
      // the left-hand side must be on top of stack.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
      // the right-hand side is never popped, even if is_last_use is set
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
      insert_exchange(left);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
      new_left = to_fpu_stack_top(left);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   686
      new_right = to_fpu_stack(right);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
      pop_if_last_use(op2, left);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
    case lir_mul_strictfp:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
    case lir_div_strictfp: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
      assert(op2->tmp_opr()->is_fpu_register(), "strict operations need temporary fpu stack slot");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
      insert_free_if_dead(op2->tmp_opr());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
      assert(sim()->stack_size() <= 7, "at least one stack slot must be free");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
      // fall-through: continue with the normal handling of lir_mul and lir_div
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
    case lir_add:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
    case lir_sub:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
    case lir_mul:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
    case lir_div: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
      assert(left->is_fpu_register(), "must be");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
      assert(res->is_fpu_register(), "must be");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
      assert(left->is_equal(res), "must be");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
      // either the left-hand or the right-hand side must be on top of stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
      // (if right is not a register, left must be on top)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
      if (!right->is_fpu_register()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
        insert_exchange(left);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
        new_left = to_fpu_stack_top(left);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
        // no exchange necessary if right is alredy on top of stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
        if (tos_offset(right) == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
          new_left = to_fpu_stack(left);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
          new_right = to_fpu_stack_top(right);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
          insert_exchange(left);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   718
          new_left = to_fpu_stack_top(left);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   719
          new_right = to_fpu_stack(right);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
489c9b5090e2 Initial load
duke
parents:
diff changeset
   722
        if (right->is_last_use()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   723
          op2->set_fpu_pop_count(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   724
489c9b5090e2 Initial load
duke
parents:
diff changeset
   725
          if (tos_offset(right) == 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   726
            sim()->pop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   727
          } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   728
            // if left is on top of stack, the result is placed in the stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   729
            // slot of right, so a renaming from right to res is necessary
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
            assert(tos_offset(left) == 0, "must be");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
            sim()->pop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
            do_rename(right, res);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   736
      new_res = to_fpu_stack(res);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   737
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
    case lir_rem: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
      assert(left->is_fpu_register(), "must be");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
      assert(right->is_fpu_register(), "must be");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
      assert(res->is_fpu_register(), "must be");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
      assert(left->is_equal(res), "must be");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
      // Must bring both operands to top of stack with following operand ordering:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   748
      // * fpu stack before rem: ... right left
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
      // * fpu stack after rem:  ... left
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
      if (tos_offset(right) != 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
        insert_exchange(right);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
        insert_exchange(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
      insert_exchange(left);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
      assert(tos_offset(right) == 1, "check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   756
      assert(tos_offset(left) == 0, "check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   757
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
      new_left = to_fpu_stack_top(left);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
      new_right = to_fpu_stack(right);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
489c9b5090e2 Initial load
duke
parents:
diff changeset
   761
      op2->set_fpu_pop_count(1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
      sim()->pop();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
      do_rename(right, res);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   764
489c9b5090e2 Initial load
duke
parents:
diff changeset
   765
      new_res = to_fpu_stack_top(res);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   766
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   767
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
489c9b5090e2 Initial load
duke
parents:
diff changeset
   769
    case lir_abs:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   770
    case lir_sqrt: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   771
      // Right argument appears to be unused
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
      assert(right->is_illegal(), "must be");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
      assert(left->is_fpu_register(), "must be");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
      assert(res->is_fpu_register(), "must be");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
      assert(left->is_last_use(), "old value gets destroyed");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
      insert_free_if_dead(res, left);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
      insert_exchange(left);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
      do_rename(left, res);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
      new_left = to_fpu_stack_top(res);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
      new_res = new_left;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
      op2->set_fpu_stack_size(sim()->stack_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   785
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   786
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
3800
3195b4844b5a 6855215: Calculation error (NaN) after about 1500 calculations
never
parents: 1
diff changeset
   788
    case lir_log:
3195b4844b5a 6855215: Calculation error (NaN) after about 1500 calculations
never
parents: 1
diff changeset
   789
    case lir_log10: {
3195b4844b5a 6855215: Calculation error (NaN) after about 1500 calculations
never
parents: 1
diff changeset
   790
      // log and log10 needs one temporary fpu stack slot, so there is ontemporary
3195b4844b5a 6855215: Calculation error (NaN) after about 1500 calculations
never
parents: 1
diff changeset
   791
      // registers stored in temp of the operation.
3195b4844b5a 6855215: Calculation error (NaN) after about 1500 calculations
never
parents: 1
diff changeset
   792
      // the stack allocator must guarantee that the stack slots are really free,
3195b4844b5a 6855215: Calculation error (NaN) after about 1500 calculations
never
parents: 1
diff changeset
   793
      // otherwise there might be a stack overflow.
3195b4844b5a 6855215: Calculation error (NaN) after about 1500 calculations
never
parents: 1
diff changeset
   794
      assert(right->is_illegal(), "must be");
3195b4844b5a 6855215: Calculation error (NaN) after about 1500 calculations
never
parents: 1
diff changeset
   795
      assert(left->is_fpu_register(), "must be");
3195b4844b5a 6855215: Calculation error (NaN) after about 1500 calculations
never
parents: 1
diff changeset
   796
      assert(res->is_fpu_register(), "must be");
3195b4844b5a 6855215: Calculation error (NaN) after about 1500 calculations
never
parents: 1
diff changeset
   797
      assert(op2->tmp_opr()->is_fpu_register(), "must be");
3195b4844b5a 6855215: Calculation error (NaN) after about 1500 calculations
never
parents: 1
diff changeset
   798
3195b4844b5a 6855215: Calculation error (NaN) after about 1500 calculations
never
parents: 1
diff changeset
   799
      insert_free_if_dead(op2->tmp_opr());
3195b4844b5a 6855215: Calculation error (NaN) after about 1500 calculations
never
parents: 1
diff changeset
   800
      insert_free_if_dead(res, left);
3195b4844b5a 6855215: Calculation error (NaN) after about 1500 calculations
never
parents: 1
diff changeset
   801
      insert_exchange(left);
3195b4844b5a 6855215: Calculation error (NaN) after about 1500 calculations
never
parents: 1
diff changeset
   802
      do_rename(left, res);
3195b4844b5a 6855215: Calculation error (NaN) after about 1500 calculations
never
parents: 1
diff changeset
   803
3195b4844b5a 6855215: Calculation error (NaN) after about 1500 calculations
never
parents: 1
diff changeset
   804
      new_left = to_fpu_stack_top(res);
3195b4844b5a 6855215: Calculation error (NaN) after about 1500 calculations
never
parents: 1
diff changeset
   805
      new_res = new_left;
3195b4844b5a 6855215: Calculation error (NaN) after about 1500 calculations
never
parents: 1
diff changeset
   806
3195b4844b5a 6855215: Calculation error (NaN) after about 1500 calculations
never
parents: 1
diff changeset
   807
      op2->set_fpu_stack_size(sim()->stack_size());
3195b4844b5a 6855215: Calculation error (NaN) after about 1500 calculations
never
parents: 1
diff changeset
   808
      assert(sim()->stack_size() <= 7, "at least one stack slot must be free");
3195b4844b5a 6855215: Calculation error (NaN) after about 1500 calculations
never
parents: 1
diff changeset
   809
      break;
3195b4844b5a 6855215: Calculation error (NaN) after about 1500 calculations
never
parents: 1
diff changeset
   810
    }
3195b4844b5a 6855215: Calculation error (NaN) after about 1500 calculations
never
parents: 1
diff changeset
   811
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   812
489c9b5090e2 Initial load
duke
parents:
diff changeset
   813
    case lir_tan:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   814
    case lir_sin:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   815
    case lir_cos: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   816
      // sin and cos need two temporary fpu stack slots, so there are two temporary
489c9b5090e2 Initial load
duke
parents:
diff changeset
   817
      // registers (stored in right and temp of the operation).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   818
      // the stack allocator must guarantee that the stack slots are really free,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   819
      // otherwise there might be a stack overflow.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   820
      assert(left->is_fpu_register(), "must be");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   821
      assert(res->is_fpu_register(), "must be");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   822
      // assert(left->is_last_use(), "old value gets destroyed");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   823
      assert(right->is_fpu_register(), "right is used as the first temporary register");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   824
      assert(op2->tmp_opr()->is_fpu_register(), "temp is used as the second temporary register");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   825
      assert(fpu_num(left) != fpu_num(right) && fpu_num(right) != fpu_num(op2->tmp_opr()) && fpu_num(op2->tmp_opr()) != fpu_num(res), "need distinct temp registers");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   826
489c9b5090e2 Initial load
duke
parents:
diff changeset
   827
      insert_free_if_dead(right);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   828
      insert_free_if_dead(op2->tmp_opr());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   829
489c9b5090e2 Initial load
duke
parents:
diff changeset
   830
      insert_free_if_dead(res, left);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   831
      insert_exchange(left);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   832
      do_rename(left, res);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   833
489c9b5090e2 Initial load
duke
parents:
diff changeset
   834
      new_left = to_fpu_stack_top(res);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   835
      new_res = new_left;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   836
489c9b5090e2 Initial load
duke
parents:
diff changeset
   837
      op2->set_fpu_stack_size(sim()->stack_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   838
      assert(sim()->stack_size() <= 6, "at least two stack slots must be free");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   839
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   840
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   841
489c9b5090e2 Initial load
duke
parents:
diff changeset
   842
    default: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   843
      assert(false, "missed a fpu-operation");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   844
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   845
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   846
489c9b5090e2 Initial load
duke
parents:
diff changeset
   847
  op2->set_in_opr1(new_left);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   848
  op2->set_in_opr2(new_right);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   849
  op2->set_result_opr(new_res);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   850
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   851
489c9b5090e2 Initial load
duke
parents:
diff changeset
   852
void FpuStackAllocator::handle_opCall(LIR_OpCall* opCall) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   853
  LIR_Opr res = opCall->result_opr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   854
489c9b5090e2 Initial load
duke
parents:
diff changeset
   855
  // clear fpu-stack before call
489c9b5090e2 Initial load
duke
parents:
diff changeset
   856
  // it may contain dead values that could not have been remved by previous operations
489c9b5090e2 Initial load
duke
parents:
diff changeset
   857
  clear_fpu_stack(LIR_OprFact::illegalOpr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   858
  assert(sim()->is_empty(), "fpu stack must be empty now");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   859
489c9b5090e2 Initial load
duke
parents:
diff changeset
   860
  // compute debug information before (possible) fpu result is pushed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   861
  compute_debug_information(opCall);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   862
489c9b5090e2 Initial load
duke
parents:
diff changeset
   863
  if (res->is_fpu_register() && !res->is_xmm_register()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   864
    do_push(res);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   865
    opCall->set_result_opr(to_fpu_stack_top(res));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   866
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   867
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   868
489c9b5090e2 Initial load
duke
parents:
diff changeset
   869
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   870
void FpuStackAllocator::check_invalid_lir_op(LIR_Op* op) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   871
  switch (op->code()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   872
    case lir_24bit_FPU:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   873
    case lir_reset_FPU:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   874
    case lir_ffree:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   875
      assert(false, "operations not allowed in lir. If one of these operations is needed, check if they have fpu operands");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   876
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   877
489c9b5090e2 Initial load
duke
parents:
diff changeset
   878
    case lir_fpop_raw:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   879
    case lir_fxch:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   880
    case lir_fld:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   881
      assert(false, "operations only inserted by FpuStackAllocator");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   882
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   883
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   884
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   885
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   886
489c9b5090e2 Initial load
duke
parents:
diff changeset
   887
489c9b5090e2 Initial load
duke
parents:
diff changeset
   888
void FpuStackAllocator::merge_insert_add(LIR_List* instrs, FpuStackSim* cur_sim, int reg) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   889
  LIR_Op1* move = new LIR_Op1(lir_move, LIR_OprFact::doubleConst(0), LIR_OprFact::double_fpu(reg)->make_fpu_stack_offset());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   890
489c9b5090e2 Initial load
duke
parents:
diff changeset
   891
  instrs->instructions_list()->push(move);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   892
489c9b5090e2 Initial load
duke
parents:
diff changeset
   893
  cur_sim->push(reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   894
  move->set_result_opr(to_fpu_stack(move->result_opr()));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   895
489c9b5090e2 Initial load
duke
parents:
diff changeset
   896
  #ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   897
    if (TraceFPUStack) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   898
      tty->print("Added new register: %d         New state: ", reg); cur_sim->print(); tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   899
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   900
  #endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   901
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   902
489c9b5090e2 Initial load
duke
parents:
diff changeset
   903
void FpuStackAllocator::merge_insert_xchg(LIR_List* instrs, FpuStackSim* cur_sim, int slot) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   904
  assert(slot > 0, "no exchange necessary");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   905
489c9b5090e2 Initial load
duke
parents:
diff changeset
   906
  LIR_Op1* fxch = new LIR_Op1(lir_fxch, LIR_OprFact::intConst(slot));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   907
  instrs->instructions_list()->push(fxch);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   908
  cur_sim->swap(slot);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   909
489c9b5090e2 Initial load
duke
parents:
diff changeset
   910
  #ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   911
    if (TraceFPUStack) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   912
      tty->print("Exchanged register: %d         New state: ", cur_sim->get_slot(slot)); cur_sim->print(); tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   913
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   914
  #endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   915
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   916
489c9b5090e2 Initial load
duke
parents:
diff changeset
   917
void FpuStackAllocator::merge_insert_pop(LIR_List* instrs, FpuStackSim* cur_sim) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   918
  int reg = cur_sim->get_slot(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   919
489c9b5090e2 Initial load
duke
parents:
diff changeset
   920
  LIR_Op* fpop = new LIR_Op0(lir_fpop_raw);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   921
  instrs->instructions_list()->push(fpop);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   922
  cur_sim->pop(reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   923
489c9b5090e2 Initial load
duke
parents:
diff changeset
   924
  #ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   925
    if (TraceFPUStack) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   926
      tty->print("Removed register: %d           New state: ", reg); cur_sim->print(); tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   927
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   928
  #endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   929
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   930
489c9b5090e2 Initial load
duke
parents:
diff changeset
   931
bool FpuStackAllocator::merge_rename(FpuStackSim* cur_sim, FpuStackSim* sux_sim, int start_slot, int change_slot) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   932
  int reg = cur_sim->get_slot(change_slot);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   933
489c9b5090e2 Initial load
duke
parents:
diff changeset
   934
  for (int slot = start_slot; slot >= 0; slot--) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   935
    int new_reg = sux_sim->get_slot(slot);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   936
489c9b5090e2 Initial load
duke
parents:
diff changeset
   937
    if (!cur_sim->contains(new_reg)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   938
      cur_sim->set_slot(change_slot, new_reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   939
489c9b5090e2 Initial load
duke
parents:
diff changeset
   940
      #ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   941
        if (TraceFPUStack) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   942
          tty->print("Renamed register %d to %d       New state: ", reg, new_reg); cur_sim->print(); tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   943
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   944
      #endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   945
489c9b5090e2 Initial load
duke
parents:
diff changeset
   946
      return true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   947
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   948
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   949
  return false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   950
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   951
489c9b5090e2 Initial load
duke
parents:
diff changeset
   952
489c9b5090e2 Initial load
duke
parents:
diff changeset
   953
void FpuStackAllocator::merge_fpu_stack(LIR_List* instrs, FpuStackSim* cur_sim, FpuStackSim* sux_sim) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   954
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   955
  if (TraceFPUStack) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   956
    tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   957
    tty->print("before merging: pred: "); cur_sim->print(); tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   958
    tty->print("                 sux: "); sux_sim->print(); tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   959
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   960
489c9b5090e2 Initial load
duke
parents:
diff changeset
   961
  int slot;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   962
  for (slot = 0; slot < cur_sim->stack_size(); slot++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   963
    assert(!cur_sim->slot_is_empty(slot), "not handled by algorithm");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   964
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   965
  for (slot = 0; slot < sux_sim->stack_size(); slot++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   966
    assert(!sux_sim->slot_is_empty(slot), "not handled by algorithm");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   967
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   968
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   969
489c9b5090e2 Initial load
duke
parents:
diff changeset
   970
  // size difference between cur and sux that must be resolved by adding or removing values form the stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
   971
  int size_diff = cur_sim->stack_size() - sux_sim->stack_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   972
489c9b5090e2 Initial load
duke
parents:
diff changeset
   973
  if (!ComputeExactFPURegisterUsage) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   974
    // add slots that are currently free, but used in successor
489c9b5090e2 Initial load
duke
parents:
diff changeset
   975
    // When the exact FPU register usage is computed, the stack does
489c9b5090e2 Initial load
duke
parents:
diff changeset
   976
    // not contain dead values at merging -> no values must be added
489c9b5090e2 Initial load
duke
parents:
diff changeset
   977
489c9b5090e2 Initial load
duke
parents:
diff changeset
   978
    int sux_slot = sux_sim->stack_size() - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   979
    while (size_diff < 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   980
      assert(sux_slot >= 0, "slot out of bounds -> error in algorithm");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   981
489c9b5090e2 Initial load
duke
parents:
diff changeset
   982
      int reg = sux_sim->get_slot(sux_slot);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   983
      if (!cur_sim->contains(reg)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   984
        merge_insert_add(instrs, cur_sim, reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   985
        size_diff++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   986
489c9b5090e2 Initial load
duke
parents:
diff changeset
   987
        if (sux_slot + size_diff != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   988
          merge_insert_xchg(instrs, cur_sim, sux_slot + size_diff);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   989
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   990
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   991
     sux_slot--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   992
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   993
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   994
489c9b5090e2 Initial load
duke
parents:
diff changeset
   995
  assert(cur_sim->stack_size() >= sux_sim->stack_size(), "stack size must be equal or greater now");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   996
  assert(size_diff == cur_sim->stack_size() - sux_sim->stack_size(), "must be");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   997
489c9b5090e2 Initial load
duke
parents:
diff changeset
   998
  // stack merge algorithm:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   999
  // 1) as long as the current stack top is not in the right location (that meens
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1000
  //    it should not be on the stack top), exchange it into the right location
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1001
  // 2) if the stack top is right, but the remaining stack is not ordered correctly,
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1002
  //    the stack top is exchanged away to get another value on top ->
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1003
  //    now step 1) can be continued
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1004
  // the stack can also contain unused items -> these items are removed from stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1005
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1006
  int finished_slot = sux_sim->stack_size() - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1007
  while (finished_slot >= 0 || size_diff > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1008
    while (size_diff > 0 || (cur_sim->stack_size() > 0 && cur_sim->get_slot(0) != sux_sim->get_slot(0))) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1009
      int reg = cur_sim->get_slot(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1010
      if (sux_sim->contains(reg)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1011
        int sux_slot = sux_sim->offset_from_tos(reg);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1012
        merge_insert_xchg(instrs, cur_sim, sux_slot + size_diff);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1013
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1014
      } else if (!merge_rename(cur_sim, sux_sim, finished_slot, 0)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1015
        assert(size_diff > 0, "must be");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1016
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1017
        merge_insert_pop(instrs, cur_sim);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1018
        size_diff--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1019
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1020
      assert(cur_sim->stack_size() == 0 || cur_sim->get_slot(0) != reg, "register must have been changed");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1021
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1022
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1023
    while (finished_slot >= 0 && cur_sim->get_slot(finished_slot) == sux_sim->get_slot(finished_slot)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1024
      finished_slot--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1025
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1026
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1027
    if (finished_slot >= 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1028
      int reg = cur_sim->get_slot(finished_slot);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1029
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1030
      if (sux_sim->contains(reg) || !merge_rename(cur_sim, sux_sim, finished_slot, finished_slot)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1031
        assert(sux_sim->contains(reg) || size_diff > 0, "must be");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1032
        merge_insert_xchg(instrs, cur_sim, finished_slot);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1033
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1034
      assert(cur_sim->get_slot(finished_slot) != reg, "register must have been changed");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1035
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1036
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1037
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1038
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1039
  if (TraceFPUStack) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1040
    tty->print("after merging:  pred: "); cur_sim->print(); tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1041
    tty->print("                 sux: "); sux_sim->print(); tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1042
    tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1043
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1044
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1045
  assert(cur_sim->stack_size() == sux_sim->stack_size(), "stack size must be equal now");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1046
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1047
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1048
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1049
void FpuStackAllocator::merge_cleanup_fpu_stack(LIR_List* instrs, FpuStackSim* cur_sim, BitMap& live_fpu_regs) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1050
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1051
  if (TraceFPUStack) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1052
    tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1053
    tty->print("before cleanup: state: "); cur_sim->print(); tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1054
    tty->print("                live:  "); live_fpu_regs.print_on(tty); tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1055
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1056
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1057
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1058
  int slot = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1059
  while (slot < cur_sim->stack_size()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1060
    int reg = cur_sim->get_slot(slot);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1061
    if (!live_fpu_regs.at(reg)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1062
      if (slot != 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1063
        merge_insert_xchg(instrs, cur_sim, slot);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1064
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1065
      merge_insert_pop(instrs, cur_sim);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1066
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1067
      slot++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1068
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1069
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1070
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1071
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1072
  if (TraceFPUStack) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1073
    tty->print("after cleanup:  state: "); cur_sim->print(); tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1074
    tty->print("                live:  "); live_fpu_regs.print_on(tty); tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1075
    tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1076
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1077
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1078
  // check if fpu stack only contains live registers
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1079
  for (unsigned int i = 0; i < live_fpu_regs.size(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1080
    if (live_fpu_regs.at(i) != cur_sim->contains(i)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1081
      tty->print_cr("mismatch between required and actual stack content");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1082
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1083
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1084
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1085
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1086
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1087
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1088
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1089
bool FpuStackAllocator::merge_fpu_stack_with_successors(BlockBegin* block) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1090
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1091
  if (TraceFPUStack) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1092
    tty->print_cr("Propagating FPU stack state for B%d at LIR_Op position %d to successors:",
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1093
                  block->block_id(), pos());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1094
    sim()->print();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1095
    tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1096
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1097
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1098
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1099
  bool changed = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1100
  int number_of_sux = block->number_of_sux();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1101
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1102
  if (number_of_sux == 1 && block->sux_at(0)->number_of_preds() > 1) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1103
    // The successor has at least two incoming edges, so a stack merge will be necessary
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1104
    // If this block is the first predecessor, cleanup the current stack and propagate it
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1105
    // If this block is not the first predecessor, a stack merge will be necessary
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1106
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1107
    BlockBegin* sux = block->sux_at(0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1108
    intArray* state = sux->fpu_stack_state();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1109
    LIR_List* instrs = new LIR_List(_compilation);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1110
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1111
    if (state != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1112
      // Merge with a successors that already has a FPU stack state
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1113
      // the block must only have one successor because critical edges must been split
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1114
      FpuStackSim* cur_sim = sim();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1115
      FpuStackSim* sux_sim = temp_sim();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1116
      sux_sim->read_state(state);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1117
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1118
      merge_fpu_stack(instrs, cur_sim, sux_sim);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1119
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1120
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1121
      // propagate current FPU stack state to successor without state
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1122
      // clean up stack first so that there are no dead values on the stack
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1123
      if (ComputeExactFPURegisterUsage) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1124
        FpuStackSim* cur_sim = sim();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1125
        BitMap live_fpu_regs = block->sux_at(0)->fpu_register_usage();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1126
        assert(live_fpu_regs.size() == FrameMap::nof_fpu_regs, "missing register usage");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1127
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1128
        merge_cleanup_fpu_stack(instrs, cur_sim, live_fpu_regs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1129
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1130
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1131
      intArray* state = sim()->write_state();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1132
      if (TraceFPUStack) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1133
        tty->print_cr("Setting FPU stack state of B%d (merge path)", sux->block_id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1134
        sim()->print(); tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1135
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1136
      sux->set_fpu_stack_state(state);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1137
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1138
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1139
    if (instrs->instructions_list()->length() > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1140
      lir()->insert_before(pos(), instrs);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1141
      set_pos(instrs->instructions_list()->length() + pos());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1142
      changed = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1143
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1144
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1145
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1146
    // Propagate unmodified Stack to successors where a stack merge is not necessary
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1147
    intArray* state = sim()->write_state();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1148
    for (int i = 0; i < number_of_sux; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1149
      BlockBegin* sux = block->sux_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1150
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1151
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1152
      for (int j = 0; j < sux->number_of_preds(); j++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1153
        assert(block == sux->pred_at(j), "all critical edges must be broken");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1154
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1155
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1156
      // check if new state is same
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1157
      if (sux->fpu_stack_state() != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1158
        intArray* sux_state = sux->fpu_stack_state();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1159
        assert(state->length() == sux_state->length(), "overwriting existing stack state");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1160
        for (int j = 0; j < state->length(); j++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1161
          assert(state->at(j) == sux_state->at(j), "overwriting existing stack state");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1162
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1163
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1164
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1165
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1166
      if (TraceFPUStack) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1167
        tty->print_cr("Setting FPU stack state of B%d", sux->block_id());
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1168
        sim()->print(); tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1169
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1170
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1171
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1172
      sux->set_fpu_stack_state(state);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1173
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1174
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1175
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1176
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1177
  // assertions that FPU stack state conforms to all successors' states
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1178
  intArray* cur_state = sim()->write_state();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1179
  for (int i = 0; i < number_of_sux; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1180
    BlockBegin* sux = block->sux_at(i);
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1181
    intArray* sux_state = sux->fpu_stack_state();
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1182
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1183
    assert(sux_state != NULL, "no fpu state");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1184
    assert(cur_state->length() == sux_state->length(), "incorrect length");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1185
    for (int i = 0; i < cur_state->length(); i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1186
      assert(cur_state->at(i) == sux_state->at(i), "element not equal");
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1187
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1188
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1189
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1190
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1191
  return changed;
489c9b5090e2 Initial load
duke
parents:
diff changeset
  1192
}