src/share/vm/opto/optoreg.hpp

Thu, 24 May 2018 19:26:50 +0800

author
aoqi
date
Thu, 24 May 2018 19:26:50 +0800
changeset 8862
fd13a567f179
parent 6876
710a3c8b516e
permissions
-rw-r--r--

#7046 C2 supports long branch
Contributed-by: fujie

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef SHARE_VM_OPTO_OPTOREG_HPP
aoqi@0 26 #define SHARE_VM_OPTO_OPTOREG_HPP
aoqi@0 27
aoqi@0 28 //------------------------------OptoReg----------------------------------------
aoqi@0 29 // We eventually need Registers for the Real World. Registers are essentially
aoqi@0 30 // non-SSA names. A Register is represented as a number. Non-regular values
aoqi@0 31 // (e.g., Control, Memory, I/O) use the Special register. The actual machine
aoqi@0 32 // registers (as described in the ADL file for a machine) start at zero.
aoqi@0 33 // Stack-slots (spill locations) start at the nest Chunk past the last machine
aoqi@0 34 // register.
aoqi@0 35 //
aoqi@0 36 // Note that stack spill-slots are treated as a very large register set.
aoqi@0 37 // They have all the correct properties for a Register: not aliased (unique
aoqi@0 38 // named). There is some simple mapping from a stack-slot register number
aoqi@0 39 // to the actual location on the stack; this mapping depends on the calling
aoqi@0 40 // conventions and is described in the ADL.
aoqi@0 41 //
aoqi@0 42 // Note that Name is not enum. C++ standard defines that the range of enum
aoqi@0 43 // is the range of smallest bit-field that can represent all enumerators
aoqi@0 44 // declared in the enum. The result of assigning a value to enum is undefined
aoqi@0 45 // if the value is outside the enumeration's valid range. OptoReg::Name is
aoqi@0 46 // typedef'ed as int, because it needs to be able to represent spill-slots.
aoqi@0 47 //
aoqi@0 48 class OptoReg VALUE_OBJ_CLASS_SPEC {
aoqi@0 49
aoqi@0 50 friend class C2Compiler;
aoqi@0 51 public:
aoqi@0 52 typedef int Name;
aoqi@0 53 enum {
aoqi@0 54 // Chunk 0
aoqi@0 55 Physical = AdlcVMDeps::Physical, // Start of physical regs
aoqi@0 56 // A few oddballs at the edge of the world
aoqi@0 57 Special = -2, // All special (not allocated) values
aoqi@0 58 Bad = -1 // Not a register
aoqi@0 59 };
aoqi@0 60
aoqi@0 61 private:
aoqi@0 62
aoqi@0 63 static const VMReg opto2vm[REG_COUNT];
aoqi@0 64 static Name vm2opto[ConcreteRegisterImpl::number_of_registers];
aoqi@0 65
aoqi@0 66 public:
aoqi@0 67
aoqi@0 68 // Stack pointer register
aoqi@0 69 static OptoReg::Name c_frame_pointer;
aoqi@0 70
aoqi@0 71
aoqi@0 72
aoqi@0 73 // Increment a register number. As in:
aoqi@0 74 // "for ( OptoReg::Name i; i=Control; i = add(i,1) ) ..."
aoqi@0 75 static Name add( Name x, int y ) { return Name(x+y); }
aoqi@0 76
aoqi@0 77 // (We would like to have an operator+ for RegName, but it is not
aoqi@0 78 // a class, so this would be illegal in C++.)
aoqi@0 79
aoqi@0 80 static void dump(int, outputStream *st = tty);
aoqi@0 81
aoqi@0 82 // Get the stack slot number of an OptoReg::Name
aoqi@0 83 static unsigned int reg2stack( OptoReg::Name r) {
aoqi@0 84 assert( r >= stack0(), " must be");
aoqi@0 85 return r - stack0();
aoqi@0 86 }
aoqi@0 87
aoqi@0 88 // convert a stack slot number into an OptoReg::Name
aoqi@0 89 static OptoReg::Name stack2reg( int idx) {
aoqi@0 90 return Name(stack0() + idx);
aoqi@0 91 }
aoqi@0 92
aoqi@0 93 static bool is_stack(Name n) {
aoqi@0 94 return n >= stack0();
aoqi@0 95 }
aoqi@0 96
aoqi@0 97 static bool is_valid(Name n) {
aoqi@0 98 return (n != Bad);
aoqi@0 99 }
aoqi@0 100
aoqi@0 101 static bool is_reg(Name n) {
aoqi@0 102 return is_valid(n) && !is_stack(n);
aoqi@0 103 }
aoqi@0 104
aoqi@0 105 static VMReg as_VMReg(OptoReg::Name n) {
aoqi@0 106 if (is_reg(n)) {
aoqi@0 107 // Must use table, it'd be nice if Bad was indexable...
aoqi@0 108 return opto2vm[n];
aoqi@0 109 } else {
aoqi@0 110 assert(!is_stack(n), "must un warp");
aoqi@0 111 return VMRegImpl::Bad();
aoqi@0 112 }
aoqi@0 113 }
aoqi@0 114
aoqi@0 115 // Can un-warp a stack slot or convert a register or Bad
aoqi@0 116 static VMReg as_VMReg(OptoReg::Name n, int frame_size, int arg_count) {
aoqi@0 117 if (is_reg(n)) {
aoqi@0 118 // Must use table, it'd be nice if Bad was indexable...
aoqi@0 119 return opto2vm[n];
aoqi@0 120 } else if (is_stack(n)) {
aoqi@0 121 int stack_slot = reg2stack(n);
aoqi@0 122 if (stack_slot < arg_count) {
aoqi@0 123 return VMRegImpl::stack2reg(stack_slot + frame_size);
aoqi@0 124 }
aoqi@0 125 return VMRegImpl::stack2reg(stack_slot - arg_count);
aoqi@0 126 // return return VMRegImpl::stack2reg(reg2stack(OptoReg::add(n, -arg_count)));
aoqi@0 127 } else {
aoqi@0 128 return VMRegImpl::Bad();
aoqi@0 129 }
aoqi@0 130 }
aoqi@0 131
aoqi@0 132 static OptoReg::Name as_OptoReg(VMReg r) {
aoqi@0 133 if (r->is_stack()) {
aoqi@0 134 assert(false, "must warp");
aoqi@0 135 return stack2reg(r->reg2stack());
aoqi@0 136 } else if (r->is_valid()) {
aoqi@0 137 // Must use table, it'd be nice if Bad was indexable...
aoqi@0 138 return vm2opto[r->value()];
aoqi@0 139 } else {
aoqi@0 140 return Bad;
aoqi@0 141 }
aoqi@0 142 }
aoqi@0 143
aoqi@0 144 static OptoReg::Name stack0() {
aoqi@0 145 return VMRegImpl::stack0->value();
aoqi@0 146 }
aoqi@0 147
aoqi@0 148 static const char* regname(OptoReg::Name n) {
aoqi@0 149 return as_VMReg(n)->name();
aoqi@0 150 }
aoqi@0 151
aoqi@0 152 };
aoqi@0 153
aoqi@0 154 //---------------------------OptoRegPair-------------------------------------------
aoqi@0 155 // Pairs of 32-bit registers for the allocator.
aoqi@0 156 // This is a very similar class to VMRegPair. C2 only interfaces with VMRegPair
aoqi@0 157 // via the calling convention code which is shared between the compilers.
aoqi@0 158 // Since C2 uses OptoRegs for register allocation it is more efficient to use
aoqi@0 159 // VMRegPair internally for nodes that can contain a pair of OptoRegs rather
aoqi@0 160 // than use VMRegPair and continually be converting back and forth. So normally
aoqi@0 161 // C2 will take in a VMRegPair from the calling convention code and immediately
aoqi@0 162 // convert them to an OptoRegPair and stay in the OptoReg world. The only over
aoqi@0 163 // conversion between OptoRegs and VMRegs is for debug info and oopMaps. This
aoqi@0 164 // is not a high bandwidth spot and so it is not an issue.
aoqi@0 165 // Note that onde other consequence of staying in the OptoReg world with OptoRegPairs
aoqi@0 166 // is that there are "physical" OptoRegs that are not representable in the VMReg
aoqi@0 167 // world, notably flags. [ But by design there is "space" in the VMReg world
aoqi@0 168 // for such registers they just may not be concrete ]. So if we were to use VMRegPair
aoqi@0 169 // then the VMReg world would have to have a representation for these registers
aoqi@0 170 // so that a OptoReg->VMReg->OptoReg would reproduce ther original OptoReg. As it
aoqi@0 171 // stands if you convert a flag (condition code) to a VMReg you will get VMRegImpl::Bad
aoqi@0 172 // and converting that will return OptoReg::Bad losing the identity of the OptoReg.
aoqi@0 173
aoqi@0 174 class OptoRegPair {
aoqi@0 175 friend class VMStructs;
aoqi@0 176 private:
aoqi@0 177 short _second;
aoqi@0 178 short _first;
aoqi@0 179 public:
aoqi@0 180 void set_bad ( ) { _second = OptoReg::Bad; _first = OptoReg::Bad; }
aoqi@0 181 void set1 ( OptoReg::Name n ) { _second = OptoReg::Bad; _first = n; }
aoqi@0 182 void set2 ( OptoReg::Name n ) { _second = n + 1; _first = n; }
aoqi@0 183 void set_pair( OptoReg::Name second, OptoReg::Name first ) { _second= second; _first= first; }
aoqi@0 184 void set_ptr ( OptoReg::Name ptr ) {
aoqi@0 185 #ifdef _LP64
aoqi@0 186 _second = ptr+1;
aoqi@0 187 #else
aoqi@0 188 _second = OptoReg::Bad;
aoqi@0 189 #endif
aoqi@0 190 _first = ptr;
aoqi@0 191 }
aoqi@0 192
aoqi@0 193 OptoReg::Name second() const { return _second; }
aoqi@0 194 OptoReg::Name first() const { return _first; }
aoqi@0 195 OptoRegPair(OptoReg::Name second, OptoReg::Name first) { _second = second; _first = first; }
aoqi@0 196 OptoRegPair(OptoReg::Name f) { _second = OptoReg::Bad; _first = f; }
aoqi@0 197 OptoRegPair() { _second = OptoReg::Bad; _first = OptoReg::Bad; }
aoqi@0 198 };
aoqi@0 199
aoqi@0 200 #endif // SHARE_VM_OPTO_OPTOREG_HPP

mercurial