hotspot/src/share/vm/opto/optoreg.hpp
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 1 489c9b5090e2
child 5547 f4b087cbb361
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2006-2007 Sun Microsystems, Inc.  All Rights Reserved.
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
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
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
//------------------------------OptoReg----------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
// We eventually need Registers for the Real World.  Registers are essentially
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
// non-SSA names.  A Register is represented as a number.  Non-regular values
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
// (e.g., Control, Memory, I/O) use the Special register.  The actual machine
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
// registers (as described in the ADL file for a machine) start at zero.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
// Stack-slots (spill locations) start at the nest Chunk past the last machine
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
// register.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// Note that stack spill-slots are treated as a very large register set.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// They have all the correct properties for a Register: not aliased (unique
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// named).  There is some simple mapping from a stack-slot register number
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// to the actual location on the stack; this mapping depends on the calling
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// conventions and is described in the ADL.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// Note that Name is not enum. C++ standard defines that the range of enum
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
// is the range of smallest bit-field that can represent all enumerators
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
// declared in the enum. The result of assigning a value to enum is undefined
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
// if the value is outside the enumeration's valid range. OptoReg::Name is
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
// typedef'ed as int, because it needs to be able to represent spill-slots.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
class OptoReg VALUE_OBJ_CLASS_SPEC {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
 friend class C2Compiler;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  typedef int Name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  enum {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
    // Chunk 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
    Physical = AdlcVMDeps::Physical, // Start of physical regs
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    // A few oddballs at the edge of the world
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
    Special = -2,               // All special (not allocated) values
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
    Bad = -1                    // Not a register
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
 static const VMReg opto2vm[REG_COUNT];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
 static Name vm2opto[ConcreteRegisterImpl::number_of_registers];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  // Stack pointer register
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  static OptoReg::Name c_frame_pointer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  // Increment a register number.  As in:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  //    "for ( OptoReg::Name i; i=Control; i = add(i,1) ) ..."
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  static Name add( Name x, int y ) { return Name(x+y); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  // (We would like to have an operator+ for RegName, but it is not
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  // a class, so this would be illegal in C++.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  static void dump( int );
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  // Get the stack slot number of an OptoReg::Name
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  static unsigned int reg2stack( OptoReg::Name r) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    assert( r >= stack0(), " must be");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    return r - stack0();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  // convert a stack slot number into an OptoReg::Name
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  static OptoReg::Name stack2reg( int idx) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
    return Name(stack0() + idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  static bool is_stack(Name n) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    return n >= stack0();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  static bool is_valid(Name n) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
    return (n != Bad);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  static bool is_reg(Name n) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    return  is_valid(n) && !is_stack(n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  static VMReg as_VMReg(OptoReg::Name n) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    if (is_reg(n)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
      // Must use table, it'd be nice if Bad was indexable...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
      return opto2vm[n];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
      assert(!is_stack(n), "must un warp");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
      return VMRegImpl::Bad();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  // Can un-warp a stack slot or convert a register or Bad
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  static VMReg as_VMReg(OptoReg::Name n, int frame_size, int arg_count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    if (is_reg(n)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
      // Must use table, it'd be nice if Bad was indexable...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
      return opto2vm[n];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    } else if (is_stack(n)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
      int stack_slot = reg2stack(n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
      if (stack_slot < arg_count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
        return VMRegImpl::stack2reg(stack_slot + frame_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
      return VMRegImpl::stack2reg(stack_slot - arg_count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
      // return return VMRegImpl::stack2reg(reg2stack(OptoReg::add(n, -arg_count)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
      return VMRegImpl::Bad();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  static OptoReg::Name as_OptoReg(VMReg r) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    if (r->is_stack()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
      assert(false, "must warp");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
      return stack2reg(r->reg2stack());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    } else if (r->is_valid()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
      // Must use table, it'd be nice if Bad was indexable...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
      return vm2opto[r->value()];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
      return Bad;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  static OptoReg::Name stack0() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
    return VMRegImpl::stack0->value();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  static const char* regname(OptoReg::Name n) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
    return as_VMReg(n)->name();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
//---------------------------OptoRegPair-------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
// Pairs of 32-bit registers for the allocator.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
// This is a very similar class to VMRegPair. C2 only interfaces with VMRegPair
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
// via the calling convention code which is shared between the compilers.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
// Since C2 uses OptoRegs for register allocation it is more efficient to use
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
// VMRegPair internally for nodes that can contain a pair of OptoRegs rather
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
// than use VMRegPair and continually be converting back and forth. So normally
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
// C2 will take in a VMRegPair from the calling convention code and immediately
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
// convert them to an OptoRegPair and stay in the OptoReg world. The only over
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
// conversion between OptoRegs and VMRegs is for debug info and oopMaps. This
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
// is not a high bandwidth spot and so it is not an issue.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
// Note that onde other consequence of staying in the OptoReg world with OptoRegPairs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
// is that there are "physical" OptoRegs that are not representable in the VMReg
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
// world, notably flags. [ But by design there is "space" in the VMReg world
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
// for such registers they just may not be concrete ]. So if we were to use VMRegPair
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
// then the VMReg world would have to have a representation for these registers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
// so that a OptoReg->VMReg->OptoReg would reproduce ther original OptoReg. As it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
// stands if you convert a flag (condition code) to a VMReg you will get VMRegImpl::Bad
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
// and converting that will return OptoReg::Bad losing the identity of the OptoReg.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
class OptoRegPair {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
  short _second;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  short _first;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
  void set_bad (                   ) { _second = OptoReg::Bad; _first = OptoReg::Bad; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  void set1    ( OptoReg::Name n  ) { _second = OptoReg::Bad; _first = n; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  void set2    ( OptoReg::Name n  ) { _second = n + 1;       _first = n; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  void set_pair( OptoReg::Name second, OptoReg::Name first    ) { _second= second;    _first= first; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
  void set_ptr ( OptoReg::Name ptr ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
#ifdef _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    _second = ptr+1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
    _second = OptoReg::Bad;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
    _first = ptr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
  OptoReg::Name second() const { return _second; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  OptoReg::Name first() const { return _first; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  OptoRegPair(OptoReg::Name second, OptoReg::Name first) {  _second = second; _first = first; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  OptoRegPair(OptoReg::Name f) { _second = OptoReg::Bad; _first = f; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  OptoRegPair() { _second = OptoReg::Bad; _first = OptoReg::Bad; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
};