erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #ifndef V8_LITHIUM_H_ |
| 29 | #define V8_LITHIUM_H_ |
| 30 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 31 | #include "allocation.h" |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 32 | #include "hydrogen.h" |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 33 | #include "safepoint-table.h" |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 34 | |
| 35 | namespace v8 { |
| 36 | namespace internal { |
| 37 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 38 | #define LITHIUM_OPERAND_LIST(V) \ |
| 39 | V(ConstantOperand, CONSTANT_OPERAND) \ |
| 40 | V(StackSlot, STACK_SLOT) \ |
| 41 | V(DoubleStackSlot, DOUBLE_STACK_SLOT) \ |
| 42 | V(Register, REGISTER) \ |
| 43 | V(DoubleRegister, DOUBLE_REGISTER) |
| 44 | |
| 45 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 46 | class LOperand: public ZoneObject { |
| 47 | public: |
| 48 | enum Kind { |
| 49 | INVALID, |
| 50 | UNALLOCATED, |
| 51 | CONSTANT_OPERAND, |
| 52 | STACK_SLOT, |
| 53 | DOUBLE_STACK_SLOT, |
| 54 | REGISTER, |
| 55 | DOUBLE_REGISTER, |
| 56 | ARGUMENT |
| 57 | }; |
| 58 | |
| 59 | LOperand() : value_(KindField::encode(INVALID)) { } |
| 60 | |
| 61 | Kind kind() const { return KindField::decode(value_); } |
| 62 | int index() const { return static_cast<int>(value_) >> kKindFieldWidth; } |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 63 | #define LITHIUM_OPERAND_PREDICATE(name, type) \ |
| 64 | bool Is##name() const { return kind() == type; } |
| 65 | LITHIUM_OPERAND_LIST(LITHIUM_OPERAND_PREDICATE) |
| 66 | LITHIUM_OPERAND_PREDICATE(Argument, ARGUMENT) |
| 67 | LITHIUM_OPERAND_PREDICATE(Unallocated, UNALLOCATED) |
| 68 | LITHIUM_OPERAND_PREDICATE(Ignored, INVALID) |
| 69 | #undef LITHIUM_OPERAND_PREDICATE |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 70 | bool Equals(LOperand* other) const { return value_ == other->value_; } |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 71 | |
| 72 | void PrintTo(StringStream* stream); |
| 73 | void ConvertTo(Kind kind, int index) { |
| 74 | value_ = KindField::encode(kind); |
| 75 | value_ |= index << kKindFieldWidth; |
| 76 | ASSERT(this->index() == index); |
| 77 | } |
| 78 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 79 | // Calls SetUpCache()/TearDownCache() for each subclass. |
| 80 | static void SetUpCaches(); |
| 81 | static void TearDownCaches(); |
| 82 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 83 | protected: |
| 84 | static const int kKindFieldWidth = 3; |
| 85 | class KindField : public BitField<Kind, 0, kKindFieldWidth> { }; |
| 86 | |
| 87 | LOperand(Kind kind, int index) { ConvertTo(kind, index); } |
| 88 | |
| 89 | unsigned value_; |
| 90 | }; |
| 91 | |
| 92 | |
| 93 | class LUnallocated: public LOperand { |
| 94 | public: |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 95 | enum BasicPolicy { |
| 96 | FIXED_SLOT, |
| 97 | EXTENDED_POLICY |
| 98 | }; |
| 99 | |
| 100 | enum ExtendedPolicy { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 101 | NONE, |
| 102 | ANY, |
| 103 | FIXED_REGISTER, |
| 104 | FIXED_DOUBLE_REGISTER, |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 105 | MUST_HAVE_REGISTER, |
| 106 | WRITABLE_REGISTER, |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 107 | SAME_AS_FIRST_INPUT |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 108 | }; |
| 109 | |
| 110 | // Lifetime of operand inside the instruction. |
| 111 | enum Lifetime { |
| 112 | // USED_AT_START operand is guaranteed to be live only at |
| 113 | // instruction start. Register allocator is free to assign the same register |
| 114 | // to some other operand used inside instruction (i.e. temporary or |
| 115 | // output). |
| 116 | USED_AT_START, |
| 117 | |
| 118 | // USED_AT_END operand is treated as live until the end of |
| 119 | // instruction. This means that register allocator will not reuse it's |
| 120 | // register for any other operand inside instruction. |
| 121 | USED_AT_END |
| 122 | }; |
| 123 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 124 | explicit LUnallocated(ExtendedPolicy policy) : LOperand(UNALLOCATED, 0) { |
| 125 | value_ |= BasicPolicyField::encode(EXTENDED_POLICY); |
| 126 | value_ |= ExtendedPolicyField::encode(policy); |
| 127 | value_ |= LifetimeField::encode(USED_AT_END); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 128 | } |
| 129 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 130 | LUnallocated(BasicPolicy policy, int index) : LOperand(UNALLOCATED, 0) { |
| 131 | ASSERT(policy == FIXED_SLOT); |
| 132 | value_ |= BasicPolicyField::encode(policy); |
| 133 | value_ |= index << FixedSlotIndexField::kShift; |
| 134 | ASSERT(this->fixed_slot_index() == index); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 135 | } |
| 136 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 137 | LUnallocated(ExtendedPolicy policy, int index) : LOperand(UNALLOCATED, 0) { |
| 138 | ASSERT(policy == FIXED_REGISTER || policy == FIXED_DOUBLE_REGISTER); |
| 139 | value_ |= BasicPolicyField::encode(EXTENDED_POLICY); |
| 140 | value_ |= ExtendedPolicyField::encode(policy); |
| 141 | value_ |= LifetimeField::encode(USED_AT_END); |
| 142 | value_ |= FixedRegisterField::encode(index); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 143 | } |
| 144 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 145 | LUnallocated(ExtendedPolicy policy, Lifetime lifetime) |
| 146 | : LOperand(UNALLOCATED, 0) { |
| 147 | value_ |= BasicPolicyField::encode(EXTENDED_POLICY); |
| 148 | value_ |= ExtendedPolicyField::encode(policy); |
| 149 | value_ |= LifetimeField::encode(lifetime); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 150 | } |
| 151 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 152 | LUnallocated* CopyUnconstrained(Zone* zone) { |
| 153 | LUnallocated* result = new(zone) LUnallocated(ANY); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 154 | result->set_virtual_register(virtual_register()); |
| 155 | return result; |
| 156 | } |
| 157 | |
| 158 | static LUnallocated* cast(LOperand* op) { |
| 159 | ASSERT(op->IsUnallocated()); |
| 160 | return reinterpret_cast<LUnallocated*>(op); |
| 161 | } |
| 162 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 163 | // The encoding used for LUnallocated operands depends on the policy that is |
| 164 | // stored within the operand. The FIXED_SLOT policy uses a compact encoding |
| 165 | // because it accommodates a larger pay-load. |
| 166 | // |
| 167 | // For FIXED_SLOT policy: |
| 168 | // +------------------------------------------+ |
| 169 | // | slot_index | vreg | 0 | 001 | |
| 170 | // +------------------------------------------+ |
| 171 | // |
| 172 | // For all other (extended) policies: |
| 173 | // +------------------------------------------+ |
| 174 | // | reg_index | L | PPP | vreg | 1 | 001 | L ... Lifetime |
| 175 | // +------------------------------------------+ P ... Policy |
| 176 | // |
| 177 | // The slot index is a signed value which requires us to decode it manually |
| 178 | // instead of using the BitField utility class. |
| 179 | |
| 180 | // The superclass has a KindField. |
| 181 | STATIC_ASSERT(kKindFieldWidth == 3); |
| 182 | |
| 183 | // BitFields for all unallocated operands. |
| 184 | class BasicPolicyField : public BitField<BasicPolicy, 3, 1> {}; |
| 185 | class VirtualRegisterField : public BitField<unsigned, 4, 18> {}; |
| 186 | |
| 187 | // BitFields specific to BasicPolicy::FIXED_SLOT. |
| 188 | class FixedSlotIndexField : public BitField<int, 22, 10> {}; |
| 189 | |
| 190 | // BitFields specific to BasicPolicy::EXTENDED_POLICY. |
| 191 | class ExtendedPolicyField : public BitField<ExtendedPolicy, 22, 3> {}; |
| 192 | class LifetimeField : public BitField<Lifetime, 25, 1> {}; |
| 193 | class FixedRegisterField : public BitField<int, 26, 6> {}; |
| 194 | |
| 195 | static const int kMaxVirtualRegisters = VirtualRegisterField::kMax + 1; |
| 196 | static const int kFixedSlotIndexWidth = FixedSlotIndexField::kSize; |
| 197 | static const int kMaxFixedSlotIndex = (1 << (kFixedSlotIndexWidth - 1)) - 1; |
| 198 | static const int kMinFixedSlotIndex = -(1 << (kFixedSlotIndexWidth - 1)); |
| 199 | |
| 200 | // Predicates for the operand policy. |
| 201 | bool HasAnyPolicy() const { |
| 202 | return basic_policy() == EXTENDED_POLICY && |
| 203 | extended_policy() == ANY; |
| 204 | } |
| 205 | bool HasFixedPolicy() const { |
| 206 | return basic_policy() == FIXED_SLOT || |
| 207 | extended_policy() == FIXED_REGISTER || |
| 208 | extended_policy() == FIXED_DOUBLE_REGISTER; |
| 209 | } |
| 210 | bool HasRegisterPolicy() const { |
| 211 | return basic_policy() == EXTENDED_POLICY && ( |
| 212 | extended_policy() == WRITABLE_REGISTER || |
| 213 | extended_policy() == MUST_HAVE_REGISTER); |
| 214 | } |
| 215 | bool HasSameAsInputPolicy() const { |
| 216 | return basic_policy() == EXTENDED_POLICY && |
| 217 | extended_policy() == SAME_AS_FIRST_INPUT; |
| 218 | } |
| 219 | bool HasFixedSlotPolicy() const { |
| 220 | return basic_policy() == FIXED_SLOT; |
| 221 | } |
| 222 | bool HasFixedRegisterPolicy() const { |
| 223 | return basic_policy() == EXTENDED_POLICY && |
| 224 | extended_policy() == FIXED_REGISTER; |
| 225 | } |
| 226 | bool HasFixedDoubleRegisterPolicy() const { |
| 227 | return basic_policy() == EXTENDED_POLICY && |
| 228 | extended_policy() == FIXED_DOUBLE_REGISTER; |
| 229 | } |
| 230 | bool HasWritableRegisterPolicy() const { |
| 231 | return basic_policy() == EXTENDED_POLICY && |
| 232 | extended_policy() == WRITABLE_REGISTER; |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 233 | } |
| 234 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame^] | 235 | // [basic_policy]: Distinguish between FIXED_SLOT and all other policies. |
| 236 | BasicPolicy basic_policy() const { |
| 237 | return BasicPolicyField::decode(value_); |
| 238 | } |
| 239 | |
| 240 | // [extended_policy]: Only for non-FIXED_SLOT. The finer-grained policy. |
| 241 | ExtendedPolicy extended_policy() const { |
| 242 | ASSERT(basic_policy() == EXTENDED_POLICY); |
| 243 | return ExtendedPolicyField::decode(value_); |
| 244 | } |
| 245 | |
| 246 | // [fixed_slot_index]: Only for FIXED_SLOT. |
| 247 | int fixed_slot_index() const { |
| 248 | ASSERT(HasFixedSlotPolicy()); |
| 249 | return static_cast<int>(value_) >> FixedSlotIndexField::kShift; |
| 250 | } |
| 251 | |
| 252 | // [fixed_register_index]: Only for FIXED_REGISTER or FIXED_DOUBLE_REGISTER. |
| 253 | int fixed_register_index() const { |
| 254 | ASSERT(HasFixedRegisterPolicy() || HasFixedDoubleRegisterPolicy()); |
| 255 | return FixedRegisterField::decode(value_); |
| 256 | } |
| 257 | |
| 258 | // [virtual_register]: The virtual register ID for this operand. |
| 259 | int virtual_register() const { |
| 260 | return VirtualRegisterField::decode(value_); |
| 261 | } |
| 262 | void set_virtual_register(unsigned id) { |
| 263 | value_ = VirtualRegisterField::update(value_, id); |
| 264 | } |
| 265 | |
| 266 | // [lifetime]: Only for non-FIXED_SLOT. |
| 267 | bool IsUsedAtStart() { |
| 268 | ASSERT(basic_policy() == EXTENDED_POLICY); |
| 269 | return LifetimeField::decode(value_) == USED_AT_START; |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 270 | } |
| 271 | }; |
| 272 | |
| 273 | |
| 274 | class LMoveOperands BASE_EMBEDDED { |
| 275 | public: |
| 276 | LMoveOperands(LOperand* source, LOperand* destination) |
| 277 | : source_(source), destination_(destination) { |
| 278 | } |
| 279 | |
| 280 | LOperand* source() const { return source_; } |
| 281 | void set_source(LOperand* operand) { source_ = operand; } |
| 282 | |
| 283 | LOperand* destination() const { return destination_; } |
| 284 | void set_destination(LOperand* operand) { destination_ = operand; } |
| 285 | |
| 286 | // The gap resolver marks moves as "in-progress" by clearing the |
| 287 | // destination (but not the source). |
| 288 | bool IsPending() const { |
| 289 | return destination_ == NULL && source_ != NULL; |
| 290 | } |
| 291 | |
| 292 | // True if this move a move into the given destination operand. |
| 293 | bool Blocks(LOperand* operand) const { |
| 294 | return !IsEliminated() && source()->Equals(operand); |
| 295 | } |
| 296 | |
| 297 | // A move is redundant if it's been eliminated, if its source and |
| 298 | // destination are the same, or if its destination is unneeded. |
| 299 | bool IsRedundant() const { |
| 300 | return IsEliminated() || source_->Equals(destination_) || IsIgnored(); |
| 301 | } |
| 302 | |
| 303 | bool IsIgnored() const { |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 304 | return destination_ != NULL && destination_->IsIgnored(); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | // We clear both operands to indicate move that's been eliminated. |
| 308 | void Eliminate() { source_ = destination_ = NULL; } |
| 309 | bool IsEliminated() const { |
| 310 | ASSERT(source_ != NULL || destination_ == NULL); |
| 311 | return source_ == NULL; |
| 312 | } |
| 313 | |
| 314 | private: |
| 315 | LOperand* source_; |
| 316 | LOperand* destination_; |
| 317 | }; |
| 318 | |
| 319 | |
| 320 | class LConstantOperand: public LOperand { |
| 321 | public: |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 322 | static LConstantOperand* Create(int index, Zone* zone) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 323 | ASSERT(index >= 0); |
| 324 | if (index < kNumCachedOperands) return &cache[index]; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 325 | return new(zone) LConstantOperand(index); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | static LConstantOperand* cast(LOperand* op) { |
| 329 | ASSERT(op->IsConstantOperand()); |
| 330 | return reinterpret_cast<LConstantOperand*>(op); |
| 331 | } |
| 332 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 333 | static void SetUpCache(); |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 334 | static void TearDownCache(); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 335 | |
| 336 | private: |
| 337 | static const int kNumCachedOperands = 128; |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 338 | static LConstantOperand* cache; |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 339 | |
| 340 | LConstantOperand() : LOperand() { } |
| 341 | explicit LConstantOperand(int index) : LOperand(CONSTANT_OPERAND, index) { } |
| 342 | }; |
| 343 | |
| 344 | |
| 345 | class LArgument: public LOperand { |
| 346 | public: |
| 347 | explicit LArgument(int index) : LOperand(ARGUMENT, index) { } |
| 348 | |
| 349 | static LArgument* cast(LOperand* op) { |
| 350 | ASSERT(op->IsArgument()); |
| 351 | return reinterpret_cast<LArgument*>(op); |
| 352 | } |
| 353 | }; |
| 354 | |
| 355 | |
| 356 | class LStackSlot: public LOperand { |
| 357 | public: |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 358 | static LStackSlot* Create(int index, Zone* zone) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 359 | ASSERT(index >= 0); |
| 360 | if (index < kNumCachedOperands) return &cache[index]; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 361 | return new(zone) LStackSlot(index); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | static LStackSlot* cast(LOperand* op) { |
| 365 | ASSERT(op->IsStackSlot()); |
| 366 | return reinterpret_cast<LStackSlot*>(op); |
| 367 | } |
| 368 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 369 | static void SetUpCache(); |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 370 | static void TearDownCache(); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 371 | |
| 372 | private: |
| 373 | static const int kNumCachedOperands = 128; |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 374 | static LStackSlot* cache; |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 375 | |
| 376 | LStackSlot() : LOperand() { } |
| 377 | explicit LStackSlot(int index) : LOperand(STACK_SLOT, index) { } |
| 378 | }; |
| 379 | |
| 380 | |
| 381 | class LDoubleStackSlot: public LOperand { |
| 382 | public: |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 383 | static LDoubleStackSlot* Create(int index, Zone* zone) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 384 | ASSERT(index >= 0); |
| 385 | if (index < kNumCachedOperands) return &cache[index]; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 386 | return new(zone) LDoubleStackSlot(index); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | static LDoubleStackSlot* cast(LOperand* op) { |
| 390 | ASSERT(op->IsStackSlot()); |
| 391 | return reinterpret_cast<LDoubleStackSlot*>(op); |
| 392 | } |
| 393 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 394 | static void SetUpCache(); |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 395 | static void TearDownCache(); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 396 | |
| 397 | private: |
| 398 | static const int kNumCachedOperands = 128; |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 399 | static LDoubleStackSlot* cache; |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 400 | |
| 401 | LDoubleStackSlot() : LOperand() { } |
| 402 | explicit LDoubleStackSlot(int index) : LOperand(DOUBLE_STACK_SLOT, index) { } |
| 403 | }; |
| 404 | |
| 405 | |
| 406 | class LRegister: public LOperand { |
| 407 | public: |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 408 | static LRegister* Create(int index, Zone* zone) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 409 | ASSERT(index >= 0); |
| 410 | if (index < kNumCachedOperands) return &cache[index]; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 411 | return new(zone) LRegister(index); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | static LRegister* cast(LOperand* op) { |
| 415 | ASSERT(op->IsRegister()); |
| 416 | return reinterpret_cast<LRegister*>(op); |
| 417 | } |
| 418 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 419 | static void SetUpCache(); |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 420 | static void TearDownCache(); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 421 | |
| 422 | private: |
| 423 | static const int kNumCachedOperands = 16; |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 424 | static LRegister* cache; |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 425 | |
| 426 | LRegister() : LOperand() { } |
| 427 | explicit LRegister(int index) : LOperand(REGISTER, index) { } |
| 428 | }; |
| 429 | |
| 430 | |
| 431 | class LDoubleRegister: public LOperand { |
| 432 | public: |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 433 | static LDoubleRegister* Create(int index, Zone* zone) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 434 | ASSERT(index >= 0); |
| 435 | if (index < kNumCachedOperands) return &cache[index]; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 436 | return new(zone) LDoubleRegister(index); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | static LDoubleRegister* cast(LOperand* op) { |
| 440 | ASSERT(op->IsDoubleRegister()); |
| 441 | return reinterpret_cast<LDoubleRegister*>(op); |
| 442 | } |
| 443 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 444 | static void SetUpCache(); |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 445 | static void TearDownCache(); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 446 | |
| 447 | private: |
| 448 | static const int kNumCachedOperands = 16; |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 449 | static LDoubleRegister* cache; |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 450 | |
| 451 | LDoubleRegister() : LOperand() { } |
| 452 | explicit LDoubleRegister(int index) : LOperand(DOUBLE_REGISTER, index) { } |
| 453 | }; |
| 454 | |
| 455 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 456 | class LParallelMove : public ZoneObject { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 457 | public: |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 458 | explicit LParallelMove(Zone* zone) : move_operands_(4, zone) { } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 459 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 460 | void AddMove(LOperand* from, LOperand* to, Zone* zone) { |
| 461 | move_operands_.Add(LMoveOperands(from, to), zone); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | bool IsRedundant() const; |
| 465 | |
| 466 | const ZoneList<LMoveOperands>* move_operands() const { |
| 467 | return &move_operands_; |
| 468 | } |
| 469 | |
| 470 | void PrintDataTo(StringStream* stream) const; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 471 | |
| 472 | private: |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 473 | ZoneList<LMoveOperands> move_operands_; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 474 | }; |
| 475 | |
| 476 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 477 | class LPointerMap: public ZoneObject { |
| 478 | public: |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 479 | explicit LPointerMap(int position, Zone* zone) |
| 480 | : pointer_operands_(8, zone), |
| 481 | untagged_operands_(0, zone), |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 482 | position_(position), |
| 483 | lithium_position_(-1) { } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 484 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 485 | const ZoneList<LOperand*>* GetNormalizedOperands() { |
| 486 | for (int i = 0; i < untagged_operands_.length(); ++i) { |
| 487 | RemovePointer(untagged_operands_[i]); |
| 488 | } |
| 489 | untagged_operands_.Clear(); |
| 490 | return &pointer_operands_; |
| 491 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 492 | int position() const { return position_; } |
| 493 | int lithium_position() const { return lithium_position_; } |
| 494 | |
| 495 | void set_lithium_position(int pos) { |
| 496 | ASSERT(lithium_position_ == -1); |
| 497 | lithium_position_ = pos; |
| 498 | } |
| 499 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 500 | void RecordPointer(LOperand* op, Zone* zone); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 501 | void RemovePointer(LOperand* op); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 502 | void RecordUntagged(LOperand* op, Zone* zone); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 503 | void PrintTo(StringStream* stream); |
| 504 | |
| 505 | private: |
| 506 | ZoneList<LOperand*> pointer_operands_; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 507 | ZoneList<LOperand*> untagged_operands_; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 508 | int position_; |
| 509 | int lithium_position_; |
| 510 | }; |
| 511 | |
| 512 | |
| 513 | class LEnvironment: public ZoneObject { |
| 514 | public: |
| 515 | LEnvironment(Handle<JSFunction> closure, |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 516 | FrameType frame_type, |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 517 | BailoutId ast_id, |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 518 | int parameter_count, |
| 519 | int argument_count, |
| 520 | int value_count, |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 521 | LEnvironment* outer, |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 522 | HEnterInlined* entry, |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 523 | Zone* zone) |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 524 | : closure_(closure), |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 525 | frame_type_(frame_type), |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 526 | arguments_stack_height_(argument_count), |
| 527 | deoptimization_index_(Safepoint::kNoDeoptimizationIndex), |
| 528 | translation_index_(-1), |
| 529 | ast_id_(ast_id), |
| 530 | parameter_count_(parameter_count), |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 531 | pc_offset_(-1), |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 532 | values_(value_count, zone), |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 533 | is_tagged_(value_count, zone), |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 534 | is_uint32_(value_count, zone), |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 535 | spilled_registers_(NULL), |
| 536 | spilled_double_registers_(NULL), |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 537 | outer_(outer), |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 538 | entry_(entry), |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 539 | zone_(zone) { } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 540 | |
| 541 | Handle<JSFunction> closure() const { return closure_; } |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 542 | FrameType frame_type() const { return frame_type_; } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 543 | int arguments_stack_height() const { return arguments_stack_height_; } |
| 544 | int deoptimization_index() const { return deoptimization_index_; } |
| 545 | int translation_index() const { return translation_index_; } |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 546 | BailoutId ast_id() const { return ast_id_; } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 547 | int parameter_count() const { return parameter_count_; } |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 548 | int pc_offset() const { return pc_offset_; } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 549 | LOperand** spilled_registers() const { return spilled_registers_; } |
| 550 | LOperand** spilled_double_registers() const { |
| 551 | return spilled_double_registers_; |
| 552 | } |
| 553 | const ZoneList<LOperand*>* values() const { return &values_; } |
| 554 | LEnvironment* outer() const { return outer_; } |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 555 | HEnterInlined* entry() { return entry_; } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 556 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 557 | void AddValue(LOperand* operand, |
| 558 | Representation representation, |
| 559 | bool is_uint32) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 560 | values_.Add(operand, zone()); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 561 | if (representation.IsTagged()) { |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 562 | ASSERT(!is_uint32); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 563 | is_tagged_.Add(values_.length() - 1); |
| 564 | } |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 565 | |
| 566 | if (is_uint32) { |
| 567 | is_uint32_.Add(values_.length() - 1); |
| 568 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | bool HasTaggedValueAt(int index) const { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 572 | return is_tagged_.Contains(index); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 573 | } |
| 574 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 575 | bool HasUint32ValueAt(int index) const { |
| 576 | return is_uint32_.Contains(index); |
| 577 | } |
| 578 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 579 | void Register(int deoptimization_index, |
| 580 | int translation_index, |
| 581 | int pc_offset) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 582 | ASSERT(!HasBeenRegistered()); |
| 583 | deoptimization_index_ = deoptimization_index; |
| 584 | translation_index_ = translation_index; |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 585 | pc_offset_ = pc_offset; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 586 | } |
| 587 | bool HasBeenRegistered() const { |
| 588 | return deoptimization_index_ != Safepoint::kNoDeoptimizationIndex; |
| 589 | } |
| 590 | |
| 591 | void SetSpilledRegisters(LOperand** registers, |
| 592 | LOperand** double_registers) { |
| 593 | spilled_registers_ = registers; |
| 594 | spilled_double_registers_ = double_registers; |
| 595 | } |
| 596 | |
| 597 | void PrintTo(StringStream* stream); |
| 598 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 599 | Zone* zone() const { return zone_; } |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 600 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 601 | private: |
| 602 | Handle<JSFunction> closure_; |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 603 | FrameType frame_type_; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 604 | int arguments_stack_height_; |
| 605 | int deoptimization_index_; |
| 606 | int translation_index_; |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 607 | BailoutId ast_id_; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 608 | int parameter_count_; |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 609 | int pc_offset_; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 610 | ZoneList<LOperand*> values_; |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 611 | BitVector is_tagged_; |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 612 | BitVector is_uint32_; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 613 | |
| 614 | // Allocation index indexed arrays of spill slot operands for registers |
| 615 | // that are also in spill slots at an OSR entry. NULL for environments |
| 616 | // that do not correspond to an OSR entry. |
| 617 | LOperand** spilled_registers_; |
| 618 | LOperand** spilled_double_registers_; |
| 619 | |
| 620 | LEnvironment* outer_; |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 621 | HEnterInlined* entry_; |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 622 | |
| 623 | Zone* zone_; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 624 | }; |
| 625 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 626 | |
| 627 | // Iterates over the non-null, non-constant operands in an environment. |
| 628 | class ShallowIterator BASE_EMBEDDED { |
| 629 | public: |
| 630 | explicit ShallowIterator(LEnvironment* env) |
| 631 | : env_(env), |
| 632 | limit_(env != NULL ? env->values()->length() : 0), |
| 633 | current_(0) { |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 634 | SkipUninteresting(); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 635 | } |
| 636 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 637 | bool Done() { return current_ >= limit_; } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 638 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 639 | LOperand* Current() { |
| 640 | ASSERT(!Done()); |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 641 | ASSERT(env_->values()->at(current_) != NULL); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 642 | return env_->values()->at(current_); |
| 643 | } |
| 644 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 645 | void Advance() { |
| 646 | ASSERT(!Done()); |
| 647 | ++current_; |
| 648 | SkipUninteresting(); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 649 | } |
| 650 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 651 | LEnvironment* env() { return env_; } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 652 | |
| 653 | private: |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 654 | bool ShouldSkip(LOperand* op) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 655 | return op == NULL || op->IsConstantOperand() || op->IsArgument(); |
| 656 | } |
| 657 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 658 | // Skip until something interesting, beginning with and including current_. |
| 659 | void SkipUninteresting() { |
| 660 | while (current_ < limit_ && ShouldSkip(env_->values()->at(current_))) { |
| 661 | ++current_; |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 662 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 663 | } |
| 664 | |
| 665 | LEnvironment* env_; |
| 666 | int limit_; |
| 667 | int current_; |
| 668 | }; |
| 669 | |
| 670 | |
| 671 | // Iterator for non-null, non-constant operands incl. outer environments. |
| 672 | class DeepIterator BASE_EMBEDDED { |
| 673 | public: |
| 674 | explicit DeepIterator(LEnvironment* env) |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 675 | : current_iterator_(env) { |
| 676 | SkipUninteresting(); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 677 | } |
| 678 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 679 | bool Done() { return current_iterator_.Done(); } |
| 680 | |
| 681 | LOperand* Current() { |
| 682 | ASSERT(!current_iterator_.Done()); |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 683 | ASSERT(current_iterator_.Current() != NULL); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 684 | return current_iterator_.Current(); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 685 | } |
| 686 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 687 | void Advance() { |
| 688 | current_iterator_.Advance(); |
| 689 | SkipUninteresting(); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | private: |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 693 | void SkipUninteresting() { |
| 694 | while (current_iterator_.env() != NULL && current_iterator_.Done()) { |
| 695 | current_iterator_ = ShallowIterator(current_iterator_.env()->outer()); |
| 696 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | ShallowIterator current_iterator_; |
| 700 | }; |
| 701 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 702 | |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 703 | class LPlatformChunk; |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 704 | class LGap; |
| 705 | class LLabel; |
| 706 | |
| 707 | // Superclass providing data and behavior common to all the |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 708 | // arch-specific LPlatformChunk classes. |
| 709 | class LChunk: public ZoneObject { |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 710 | public: |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 711 | static LChunk* NewChunk(HGraph* graph); |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 712 | |
| 713 | void AddInstruction(LInstruction* instruction, HBasicBlock* block); |
| 714 | LConstantOperand* DefineConstantOperand(HConstant* constant); |
| 715 | HConstant* LookupConstant(LConstantOperand* operand) const; |
| 716 | Representation LookupLiteralRepresentation(LConstantOperand* operand) const; |
| 717 | |
| 718 | int ParameterAt(int index); |
| 719 | int GetParameterStackSlot(int index) const; |
| 720 | int spill_slot_count() const { return spill_slot_count_; } |
| 721 | CompilationInfo* info() const { return info_; } |
| 722 | HGraph* graph() const { return graph_; } |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 723 | Isolate* isolate() const { return graph_->isolate(); } |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 724 | const ZoneList<LInstruction*>* instructions() const { return &instructions_; } |
| 725 | void AddGapMove(int index, LOperand* from, LOperand* to); |
| 726 | LGap* GetGapAt(int index) const; |
| 727 | bool IsGapAt(int index) const; |
| 728 | int NearestGapPos(int index) const; |
| 729 | void MarkEmptyBlocks(); |
| 730 | const ZoneList<LPointerMap*>* pointer_maps() const { return &pointer_maps_; } |
| 731 | LLabel* GetLabel(int block_id) const; |
| 732 | int LookupDestination(int block_id) const; |
| 733 | Label* GetAssemblyLabel(int block_id) const; |
| 734 | |
| 735 | const ZoneList<Handle<JSFunction> >* inlined_closures() const { |
| 736 | return &inlined_closures_; |
| 737 | } |
| 738 | |
| 739 | void AddInlinedClosure(Handle<JSFunction> closure) { |
| 740 | inlined_closures_.Add(closure, zone()); |
| 741 | } |
| 742 | |
| 743 | Zone* zone() const { return info_->zone(); } |
| 744 | |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 745 | Handle<Code> Codegen(); |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 746 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 747 | void set_allocated_double_registers(BitVector* allocated_registers); |
| 748 | BitVector* allocated_double_registers() { |
| 749 | return allocated_double_registers_; |
| 750 | } |
| 751 | |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 752 | protected: |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 753 | LChunk(CompilationInfo* info, HGraph* graph); |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 754 | |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 755 | int spill_slot_count_; |
| 756 | |
| 757 | private: |
| 758 | CompilationInfo* info_; |
| 759 | HGraph* const graph_; |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 760 | BitVector* allocated_double_registers_; |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 761 | ZoneList<LInstruction*> instructions_; |
| 762 | ZoneList<LPointerMap*> pointer_maps_; |
| 763 | ZoneList<Handle<JSFunction> > inlined_closures_; |
| 764 | }; |
| 765 | |
| 766 | |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 767 | int ElementsKindToShiftSize(ElementsKind elements_kind); |
jkummerow@chromium.org | ac36071 | 2013-02-11 09:00:07 +0000 | [diff] [blame] | 768 | int StackSlotOffset(int index); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 769 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 770 | enum NumberUntagDMode { |
| 771 | NUMBER_CANDIDATE_IS_SMI, |
| 772 | NUMBER_CANDIDATE_IS_SMI_OR_HOLE, |
| 773 | NUMBER_CANDIDATE_IS_SMI_CONVERT_HOLE, |
| 774 | NUMBER_CANDIDATE_IS_ANY_TAGGED |
| 775 | }; |
| 776 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 777 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 778 | } } // namespace v8::internal |
| 779 | |
| 780 | #endif // V8_LITHIUM_H_ |