src/hotspot/share/opto/optoreg.hpp
author coleenp
Fri, 09 Mar 2018 20:01:38 -0500
changeset 49373 47b5652f2928
parent 47216 71c04702a3d5
child 53244 9807daeb47c4
permissions -rw-r--r--
8199283: Remove ValueObj class for allocation subclassing for compiler code Reviewed-by: stefank, tschatzl
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
49373
47b5652f2928 8199283: Remove ValueObj class for allocation subclassing for compiler code
coleenp
parents: 47216
diff changeset
     2
 * Copyright (c) 2006, 2018, 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: 1
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1
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: 1
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    25
#ifndef SHARE_VM_OPTO_OPTOREG_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    26
#define SHARE_VM_OPTO_OPTOREG_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
40010
e32d5e545789 8161258: Simplify including platform files.
goetz
parents: 30624
diff changeset
    28
#include "utilities/macros.hpp"
e32d5e545789 8161258: Simplify including platform files.
goetz
parents: 30624
diff changeset
    29
25715
d5a8dbdc5150 8049325: Introduce and clean up umbrella headers for the files in the cpu subdirectories.
goetz
parents: 22234
diff changeset
    30
// AdGlobals contains c2 specific register handling code as specified
d5a8dbdc5150 8049325: Introduce and clean up umbrella headers for the files in the cpu subdirectories.
goetz
parents: 22234
diff changeset
    31
// in the .ad files.
40010
e32d5e545789 8161258: Simplify including platform files.
goetz
parents: 30624
diff changeset
    32
#include CPU_HEADER(adfiles/adGlobals)
25715
d5a8dbdc5150 8049325: Introduce and clean up umbrella headers for the files in the cpu subdirectories.
goetz
parents: 22234
diff changeset
    33
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
//------------------------------OptoReg----------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// We eventually need Registers for the Real World.  Registers are essentially
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// non-SSA names.  A Register is represented as a number.  Non-regular values
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// (e.g., Control, Memory, I/O) use the Special register.  The actual machine
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
// registers (as described in the ADL file for a machine) start at zero.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// Stack-slots (spill locations) start at the nest Chunk past the last machine
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
// register.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
// Note that stack spill-slots are treated as a very large register set.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
// They have all the correct properties for a Register: not aliased (unique
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
// named).  There is some simple mapping from a stack-slot register number
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
// to the actual location on the stack; this mapping depends on the calling
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
// conventions and is described in the ADL.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
// Note that Name is not enum. C++ standard defines that the range of enum
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
// is the range of smallest bit-field that can represent all enumerators
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
// declared in the enum. The result of assigning a value to enum is undefined
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
// if the value is outside the enumeration's valid range. OptoReg::Name is
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
// typedef'ed as int, because it needs to be able to represent spill-slots.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
//
49373
47b5652f2928 8199283: Remove ValueObj class for allocation subclassing for compiler code
coleenp
parents: 47216
diff changeset
    54
class OptoReg {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
 friend class C2Compiler;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  typedef int Name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  enum {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    // Chunk 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
    Physical = AdlcVMDeps::Physical, // Start of physical regs
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    // A few oddballs at the edge of the world
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    Special = -2,               // All special (not allocated) values
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
    Bad = -1                    // Not a register
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
 static const VMReg opto2vm[REG_COUNT];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
 static Name vm2opto[ConcreteRegisterImpl::number_of_registers];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  // Stack pointer register
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  static OptoReg::Name c_frame_pointer;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  // Increment a register number.  As in:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  //    "for ( OptoReg::Name i; i=Control; i = add(i,1) ) ..."
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  static Name add( Name x, int y ) { return Name(x+y); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  // (We would like to have an operator+ for RegName, but it is not
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  // a class, so this would be illegal in C++.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
15241
87d217c2d183 8005055: pass outputStream to more opto debug routines
kvn
parents: 10547
diff changeset
    86
  static void dump(int, outputStream *st = tty);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  // Get the stack slot number of an OptoReg::Name
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  static unsigned int reg2stack( OptoReg::Name r) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
    assert( r >= stack0(), " must be");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
    return r - stack0();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
30624
2e1803c8a26d 8076276: Add support for AVX512
kvn
parents: 29474
diff changeset
    94
  static void invalidate(Name n) {
2e1803c8a26d 8076276: Add support for AVX512
kvn
parents: 29474
diff changeset
    95
    vm2opto[n] = Bad;
2e1803c8a26d 8076276: Add support for AVX512
kvn
parents: 29474
diff changeset
    96
  }
2e1803c8a26d 8076276: Add support for AVX512
kvn
parents: 29474
diff changeset
    97
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  // convert a stack slot number into an OptoReg::Name
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  static OptoReg::Name stack2reg( int idx) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    return Name(stack0() + idx);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  static bool is_stack(Name n) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    return n >= stack0();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  static bool is_valid(Name n) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    return (n != 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
  static bool is_reg(Name n) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    return  is_valid(n) && !is_stack(n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  static VMReg as_VMReg(OptoReg::Name n) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
    if (is_reg(n)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
      // Must use table, it'd be nice if Bad was indexable...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
      return opto2vm[n];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
      assert(!is_stack(n), "must un warp");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
      return VMRegImpl::Bad();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  // Can un-warp a stack slot or convert a register or Bad
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  static VMReg as_VMReg(OptoReg::Name n, int frame_size, int arg_count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    if (is_reg(n)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
      // Must use table, it'd be nice if Bad was indexable...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
      return opto2vm[n];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
    } else if (is_stack(n)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
      int stack_slot = reg2stack(n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
      if (stack_slot < arg_count) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
        return VMRegImpl::stack2reg(stack_slot + frame_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
      return VMRegImpl::stack2reg(stack_slot - arg_count);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
      // return return VMRegImpl::stack2reg(reg2stack(OptoReg::add(n, -arg_count)));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
      return VMRegImpl::Bad();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  static OptoReg::Name as_OptoReg(VMReg r) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
    if (r->is_stack()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
      assert(false, "must warp");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
      return stack2reg(r->reg2stack());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
    } else if (r->is_valid()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
      // Must use table, it'd be nice if Bad was indexable...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
      return vm2opto[r->value()];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
      return Bad;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  static OptoReg::Name stack0() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
    return VMRegImpl::stack0->value();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  static const char* regname(OptoReg::Name n) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
    return as_VMReg(n)->name();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
//---------------------------OptoRegPair-------------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
// Pairs of 32-bit registers for the allocator.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
// This is a very similar class to VMRegPair. C2 only interfaces with VMRegPair
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
// via the calling convention code which is shared between the compilers.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
// Since C2 uses OptoRegs for register allocation it is more efficient to use
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
// VMRegPair internally for nodes that can contain a pair of OptoRegs rather
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
// than use VMRegPair and continually be converting back and forth. So normally
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
// C2 will take in a VMRegPair from the calling convention code and immediately
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
// convert them to an OptoRegPair and stay in the OptoReg world. The only over
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
// conversion between OptoRegs and VMRegs is for debug info and oopMaps. This
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
// is not a high bandwidth spot and so it is not an issue.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
// Note that onde other consequence of staying in the OptoReg world with OptoRegPairs
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
// is that there are "physical" OptoRegs that are not representable in the VMReg
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
// world, notably flags. [ But by design there is "space" in the VMReg world
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
// for such registers they just may not be concrete ]. So if we were to use VMRegPair
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
// then the VMReg world would have to have a representation for these registers
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
// so that a OptoReg->VMReg->OptoReg would reproduce ther original OptoReg. As it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
// stands if you convert a flag (condition code) to a VMReg you will get VMRegImpl::Bad
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
// and converting that will return OptoReg::Bad losing the identity of the OptoReg.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
class OptoRegPair {
10547
ea4a2ec31ae2 7088955: add C2 IR support to the SA
never
parents: 7397
diff changeset
   185
  friend class VMStructs;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
  short _second;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
  short _first;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
  void set_bad (                   ) { _second = OptoReg::Bad; _first = OptoReg::Bad; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
  void set1    ( OptoReg::Name n  ) { _second = OptoReg::Bad; _first = n; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
  void set2    ( OptoReg::Name n  ) { _second = n + 1;       _first = n; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  void set_pair( OptoReg::Name second, OptoReg::Name first    ) { _second= second;    _first= first; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
  void set_ptr ( OptoReg::Name ptr ) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
#ifdef _LP64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
    _second = ptr+1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
#else
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
    _second = OptoReg::Bad;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
    _first = ptr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
  OptoReg::Name second() const { return _second; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  OptoReg::Name first() const { return _first; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
  OptoRegPair(OptoReg::Name second, OptoReg::Name first) {  _second = second; _first = first; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  OptoRegPair(OptoReg::Name f) { _second = OptoReg::Bad; _first = f; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  OptoRegPair() { _second = OptoReg::Bad; _first = OptoReg::Bad; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   209
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
   210
#endif // SHARE_VM_OPTO_OPTOREG_HPP