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