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