annotate src/share/vm/opto/optoreg.hpp @ 216:8d191a7697e2

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