kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1 | // Copyright 2011 the V8 project authors. All rights reserved. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +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 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 28 | #include "v8.h" |
| 29 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 30 | #include "lithium-allocator-inl.h" |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 31 | #include "arm/lithium-arm.h" |
| 32 | #include "arm/lithium-codegen-arm.h" |
| 33 | |
| 34 | namespace v8 { |
| 35 | namespace internal { |
| 36 | |
| 37 | #define DEFINE_COMPILE(type) \ |
| 38 | void L##type::CompileToNative(LCodeGen* generator) { \ |
| 39 | generator->Do##type(this); \ |
| 40 | } |
| 41 | LITHIUM_CONCRETE_INSTRUCTION_LIST(DEFINE_COMPILE) |
| 42 | #undef DEFINE_COMPILE |
| 43 | |
| 44 | LOsrEntry::LOsrEntry() { |
| 45 | for (int i = 0; i < Register::kNumAllocatableRegisters; ++i) { |
| 46 | register_spills_[i] = NULL; |
| 47 | } |
| 48 | for (int i = 0; i < DoubleRegister::kNumAllocatableRegisters; ++i) { |
| 49 | double_register_spills_[i] = NULL; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | |
| 54 | void LOsrEntry::MarkSpilledRegister(int allocation_index, |
| 55 | LOperand* spill_operand) { |
| 56 | ASSERT(spill_operand->IsStackSlot()); |
| 57 | ASSERT(register_spills_[allocation_index] == NULL); |
| 58 | register_spills_[allocation_index] = spill_operand; |
| 59 | } |
| 60 | |
| 61 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 62 | #ifdef DEBUG |
| 63 | void LInstruction::VerifyCall() { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 64 | // Call instructions can use only fixed registers as temporaries and |
| 65 | // outputs because all registers are blocked by the calling convention. |
| 66 | // Inputs operands must use a fixed register or use-at-start policy or |
| 67 | // a non-register policy. |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 68 | ASSERT(Output() == NULL || |
| 69 | LUnallocated::cast(Output())->HasFixedPolicy() || |
| 70 | !LUnallocated::cast(Output())->HasRegisterPolicy()); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame^] | 71 | for (UseIterator it(this); !it.Done(); it.Advance()) { |
| 72 | LUnallocated* operand = LUnallocated::cast(it.Current()); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 73 | ASSERT(operand->HasFixedPolicy() || |
| 74 | operand->IsUsedAtStart()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 75 | } |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame^] | 76 | for (TempIterator it(this); !it.Done(); it.Advance()) { |
| 77 | LUnallocated* operand = LUnallocated::cast(it.Current()); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 78 | ASSERT(operand->HasFixedPolicy() ||!operand->HasRegisterPolicy()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 79 | } |
| 80 | } |
| 81 | #endif |
| 82 | |
| 83 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 84 | void LOsrEntry::MarkSpilledDoubleRegister(int allocation_index, |
| 85 | LOperand* spill_operand) { |
| 86 | ASSERT(spill_operand->IsDoubleStackSlot()); |
| 87 | ASSERT(double_register_spills_[allocation_index] == NULL); |
| 88 | double_register_spills_[allocation_index] = spill_operand; |
| 89 | } |
| 90 | |
| 91 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 92 | void LInstruction::PrintTo(StringStream* stream) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 93 | stream->Add("%s ", this->Mnemonic()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 94 | |
| 95 | PrintOutputOperandTo(stream); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 96 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 97 | PrintDataTo(stream); |
| 98 | |
| 99 | if (HasEnvironment()) { |
| 100 | stream->Add(" "); |
| 101 | environment()->PrintTo(stream); |
| 102 | } |
| 103 | |
| 104 | if (HasPointerMap()) { |
| 105 | stream->Add(" "); |
| 106 | pointer_map()->PrintTo(stream); |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 111 | template<int R, int I, int T> |
| 112 | void LTemplateInstruction<R, I, T>::PrintDataTo(StringStream* stream) { |
| 113 | stream->Add("= "); |
| 114 | inputs_.PrintOperandsTo(stream); |
| 115 | } |
| 116 | |
| 117 | |
| 118 | template<int R, int I, int T> |
| 119 | void LTemplateInstruction<R, I, T>::PrintOutputOperandTo(StringStream* stream) { |
| 120 | results_.PrintOperandsTo(stream); |
| 121 | } |
| 122 | |
| 123 | |
| 124 | template<typename T, int N> |
| 125 | void OperandContainer<T, N>::PrintOperandsTo(StringStream* stream) { |
| 126 | for (int i = 0; i < N; i++) { |
| 127 | if (i > 0) stream->Add(" "); |
| 128 | elems_[i]->PrintTo(stream); |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | |
| 133 | void LLabel::PrintDataTo(StringStream* stream) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 134 | LGap::PrintDataTo(stream); |
| 135 | LLabel* rep = replacement(); |
| 136 | if (rep != NULL) { |
| 137 | stream->Add(" Dead block replaced with B%d", rep->block_id()); |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 142 | bool LGap::IsRedundant() const { |
| 143 | for (int i = 0; i < 4; i++) { |
| 144 | if (parallel_moves_[i] != NULL && !parallel_moves_[i]->IsRedundant()) { |
| 145 | return false; |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | return true; |
| 150 | } |
| 151 | |
| 152 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 153 | void LGap::PrintDataTo(StringStream* stream) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 154 | for (int i = 0; i < 4; i++) { |
| 155 | stream->Add("("); |
| 156 | if (parallel_moves_[i] != NULL) { |
| 157 | parallel_moves_[i]->PrintDataTo(stream); |
| 158 | } |
| 159 | stream->Add(") "); |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | |
| 164 | const char* LArithmeticD::Mnemonic() const { |
| 165 | switch (op()) { |
| 166 | case Token::ADD: return "add-d"; |
| 167 | case Token::SUB: return "sub-d"; |
| 168 | case Token::MUL: return "mul-d"; |
| 169 | case Token::DIV: return "div-d"; |
| 170 | case Token::MOD: return "mod-d"; |
| 171 | default: |
| 172 | UNREACHABLE(); |
| 173 | return NULL; |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | |
| 178 | const char* LArithmeticT::Mnemonic() const { |
| 179 | switch (op()) { |
| 180 | case Token::ADD: return "add-t"; |
| 181 | case Token::SUB: return "sub-t"; |
| 182 | case Token::MUL: return "mul-t"; |
| 183 | case Token::MOD: return "mod-t"; |
| 184 | case Token::DIV: return "div-t"; |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 185 | case Token::BIT_AND: return "bit-and-t"; |
| 186 | case Token::BIT_OR: return "bit-or-t"; |
| 187 | case Token::BIT_XOR: return "bit-xor-t"; |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 188 | case Token::SHL: return "shl-t"; |
| 189 | case Token::SAR: return "sar-t"; |
| 190 | case Token::SHR: return "shr-t"; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 191 | default: |
| 192 | UNREACHABLE(); |
| 193 | return NULL; |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 198 | void LGoto::PrintDataTo(StringStream* stream) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 199 | stream->Add("B%d", block_id()); |
| 200 | } |
| 201 | |
| 202 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 203 | void LBranch::PrintDataTo(StringStream* stream) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 204 | stream->Add("B%d | B%d on ", true_block_id(), false_block_id()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 205 | InputAt(0)->PrintTo(stream); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 209 | void LCmpIDAndBranch::PrintDataTo(StringStream* stream) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 210 | stream->Add("if "); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 211 | InputAt(0)->PrintTo(stream); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 212 | stream->Add(" %s ", Token::String(op())); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 213 | InputAt(1)->PrintTo(stream); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 214 | stream->Add(" then B%d else B%d", true_block_id(), false_block_id()); |
| 215 | } |
| 216 | |
| 217 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 218 | void LIsNullAndBranch::PrintDataTo(StringStream* stream) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 219 | stream->Add("if "); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 220 | InputAt(0)->PrintTo(stream); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 221 | stream->Add(is_strict() ? " === null" : " == null"); |
| 222 | stream->Add(" then B%d else B%d", true_block_id(), false_block_id()); |
| 223 | } |
| 224 | |
| 225 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 226 | void LIsObjectAndBranch::PrintDataTo(StringStream* stream) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 227 | stream->Add("if is_object("); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 228 | InputAt(0)->PrintTo(stream); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 229 | stream->Add(") then B%d else B%d", true_block_id(), false_block_id()); |
| 230 | } |
| 231 | |
| 232 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 233 | void LIsSmiAndBranch::PrintDataTo(StringStream* stream) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 234 | stream->Add("if is_smi("); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 235 | InputAt(0)->PrintTo(stream); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 236 | stream->Add(") then B%d else B%d", true_block_id(), false_block_id()); |
| 237 | } |
| 238 | |
| 239 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 240 | void LIsUndetectableAndBranch::PrintDataTo(StringStream* stream) { |
| 241 | stream->Add("if is_undetectable("); |
| 242 | InputAt(0)->PrintTo(stream); |
| 243 | stream->Add(") then B%d else B%d", true_block_id(), false_block_id()); |
| 244 | } |
| 245 | |
| 246 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 247 | void LHasInstanceTypeAndBranch::PrintDataTo(StringStream* stream) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 248 | stream->Add("if has_instance_type("); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 249 | InputAt(0)->PrintTo(stream); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 250 | stream->Add(") then B%d else B%d", true_block_id(), false_block_id()); |
| 251 | } |
| 252 | |
| 253 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 254 | void LHasCachedArrayIndexAndBranch::PrintDataTo(StringStream* stream) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 255 | stream->Add("if has_cached_array_index("); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 256 | InputAt(0)->PrintTo(stream); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 257 | stream->Add(") then B%d else B%d", true_block_id(), false_block_id()); |
| 258 | } |
| 259 | |
| 260 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 261 | void LClassOfTestAndBranch::PrintDataTo(StringStream* stream) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 262 | stream->Add("if class_of_test("); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 263 | InputAt(0)->PrintTo(stream); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 264 | stream->Add(", \"%o\") then B%d else B%d", |
| 265 | *hydrogen()->class_name(), |
| 266 | true_block_id(), |
| 267 | false_block_id()); |
| 268 | } |
| 269 | |
| 270 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 271 | void LTypeofIs::PrintDataTo(StringStream* stream) { |
| 272 | InputAt(0)->PrintTo(stream); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 273 | stream->Add(" == \"%s\"", *hydrogen()->type_literal()->ToCString()); |
| 274 | } |
| 275 | |
| 276 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 277 | void LTypeofIsAndBranch::PrintDataTo(StringStream* stream) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 278 | stream->Add("if typeof "); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 279 | InputAt(0)->PrintTo(stream); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 280 | stream->Add(" == \"%s\" then B%d else B%d", |
| 281 | *hydrogen()->type_literal()->ToCString(), |
| 282 | true_block_id(), false_block_id()); |
| 283 | } |
| 284 | |
| 285 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 286 | void LCallConstantFunction::PrintDataTo(StringStream* stream) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 287 | stream->Add("#%d / ", arity()); |
| 288 | } |
| 289 | |
| 290 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 291 | void LUnaryMathOperation::PrintDataTo(StringStream* stream) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 292 | stream->Add("/%s ", hydrogen()->OpName()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 293 | InputAt(0)->PrintTo(stream); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 297 | void LLoadContextSlot::PrintDataTo(StringStream* stream) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 298 | InputAt(0)->PrintTo(stream); |
| 299 | stream->Add("[%d]", slot_index()); |
| 300 | } |
| 301 | |
| 302 | |
| 303 | void LStoreContextSlot::PrintDataTo(StringStream* stream) { |
| 304 | InputAt(0)->PrintTo(stream); |
| 305 | stream->Add("[%d] <- ", slot_index()); |
| 306 | InputAt(1)->PrintTo(stream); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 310 | void LInvokeFunction::PrintDataTo(StringStream* stream) { |
| 311 | stream->Add("= "); |
| 312 | InputAt(0)->PrintTo(stream); |
| 313 | stream->Add(" #%d / ", arity()); |
| 314 | } |
| 315 | |
| 316 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 317 | void LCallKeyed::PrintDataTo(StringStream* stream) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 318 | stream->Add("[r2] #%d / ", arity()); |
| 319 | } |
| 320 | |
| 321 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 322 | void LCallNamed::PrintDataTo(StringStream* stream) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 323 | SmartPointer<char> name_string = name()->ToCString(); |
| 324 | stream->Add("%s #%d / ", *name_string, arity()); |
| 325 | } |
| 326 | |
| 327 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 328 | void LCallGlobal::PrintDataTo(StringStream* stream) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 329 | SmartPointer<char> name_string = name()->ToCString(); |
| 330 | stream->Add("%s #%d / ", *name_string, arity()); |
| 331 | } |
| 332 | |
| 333 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 334 | void LCallKnownGlobal::PrintDataTo(StringStream* stream) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 335 | stream->Add("#%d / ", arity()); |
| 336 | } |
| 337 | |
| 338 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 339 | void LCallNew::PrintDataTo(StringStream* stream) { |
| 340 | stream->Add("= "); |
| 341 | InputAt(0)->PrintTo(stream); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 342 | stream->Add(" #%d / ", arity()); |
| 343 | } |
| 344 | |
| 345 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 346 | void LClassOfTest::PrintDataTo(StringStream* stream) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 347 | stream->Add("= class_of_test("); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 348 | InputAt(0)->PrintTo(stream); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 349 | stream->Add(", \"%o\")", *hydrogen()->class_name()); |
| 350 | } |
| 351 | |
| 352 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 353 | void LAccessArgumentsAt::PrintDataTo(StringStream* stream) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 354 | arguments()->PrintTo(stream); |
| 355 | |
| 356 | stream->Add(" length "); |
| 357 | length()->PrintTo(stream); |
| 358 | |
| 359 | stream->Add(" index "); |
| 360 | index()->PrintTo(stream); |
| 361 | } |
| 362 | |
| 363 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 364 | void LStoreNamedField::PrintDataTo(StringStream* stream) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 365 | object()->PrintTo(stream); |
| 366 | stream->Add("."); |
| 367 | stream->Add(*String::cast(*name())->ToCString()); |
| 368 | stream->Add(" <- "); |
| 369 | value()->PrintTo(stream); |
| 370 | } |
| 371 | |
| 372 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 373 | void LStoreNamedGeneric::PrintDataTo(StringStream* stream) { |
| 374 | object()->PrintTo(stream); |
| 375 | stream->Add("."); |
| 376 | stream->Add(*String::cast(*name())->ToCString()); |
| 377 | stream->Add(" <- "); |
| 378 | value()->PrintTo(stream); |
| 379 | } |
| 380 | |
| 381 | |
| 382 | void LStoreKeyedFastElement::PrintDataTo(StringStream* stream) { |
| 383 | object()->PrintTo(stream); |
| 384 | stream->Add("["); |
| 385 | key()->PrintTo(stream); |
| 386 | stream->Add("] <- "); |
| 387 | value()->PrintTo(stream); |
| 388 | } |
| 389 | |
| 390 | |
| 391 | void LStoreKeyedGeneric::PrintDataTo(StringStream* stream) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 392 | object()->PrintTo(stream); |
| 393 | stream->Add("["); |
| 394 | key()->PrintTo(stream); |
| 395 | stream->Add("] <- "); |
| 396 | value()->PrintTo(stream); |
| 397 | } |
| 398 | |
| 399 | |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 400 | LChunk::LChunk(CompilationInfo* info, HGraph* graph) |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 401 | : spill_slot_count_(0), |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 402 | info_(info), |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 403 | graph_(graph), |
| 404 | instructions_(32), |
| 405 | pointer_maps_(8), |
| 406 | inlined_closures_(1) { |
| 407 | } |
| 408 | |
| 409 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 410 | int LChunk::GetNextSpillIndex(bool is_double) { |
| 411 | // Skip a slot if for a double-width slot. |
| 412 | if (is_double) spill_slot_count_++; |
| 413 | return spill_slot_count_++; |
| 414 | } |
| 415 | |
| 416 | |
| 417 | LOperand* LChunk::GetNextSpillSlot(bool is_double) { |
| 418 | int index = GetNextSpillIndex(is_double); |
| 419 | if (is_double) { |
| 420 | return LDoubleStackSlot::Create(index); |
| 421 | } else { |
| 422 | return LStackSlot::Create(index); |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | |
| 427 | void LChunk::MarkEmptyBlocks() { |
| 428 | HPhase phase("Mark empty blocks", this); |
| 429 | for (int i = 0; i < graph()->blocks()->length(); ++i) { |
| 430 | HBasicBlock* block = graph()->blocks()->at(i); |
| 431 | int first = block->first_instruction_index(); |
| 432 | int last = block->last_instruction_index(); |
| 433 | LInstruction* first_instr = instructions()->at(first); |
| 434 | LInstruction* last_instr = instructions()->at(last); |
| 435 | |
| 436 | LLabel* label = LLabel::cast(first_instr); |
| 437 | if (last_instr->IsGoto()) { |
| 438 | LGoto* goto_instr = LGoto::cast(last_instr); |
| 439 | if (!goto_instr->include_stack_check() && |
| 440 | label->IsRedundant() && |
| 441 | !label->is_loop_header()) { |
| 442 | bool can_eliminate = true; |
| 443 | for (int i = first + 1; i < last && can_eliminate; ++i) { |
| 444 | LInstruction* cur = instructions()->at(i); |
| 445 | if (cur->IsGap()) { |
| 446 | LGap* gap = LGap::cast(cur); |
| 447 | if (!gap->IsRedundant()) { |
| 448 | can_eliminate = false; |
| 449 | } |
| 450 | } else { |
| 451 | can_eliminate = false; |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | if (can_eliminate) { |
| 456 | label->set_replacement(GetLabel(goto_instr->block_id())); |
| 457 | } |
| 458 | } |
| 459 | } |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 464 | void LChunk::AddInstruction(LInstruction* instr, HBasicBlock* block) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 465 | LInstructionGap* gap = new LInstructionGap(block); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 466 | int index = -1; |
| 467 | if (instr->IsControl()) { |
| 468 | instructions_.Add(gap); |
| 469 | index = instructions_.length(); |
| 470 | instructions_.Add(instr); |
| 471 | } else { |
| 472 | index = instructions_.length(); |
| 473 | instructions_.Add(instr); |
| 474 | instructions_.Add(gap); |
| 475 | } |
| 476 | if (instr->HasPointerMap()) { |
| 477 | pointer_maps_.Add(instr->pointer_map()); |
| 478 | instr->pointer_map()->set_lithium_position(index); |
| 479 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | |
| 483 | LConstantOperand* LChunk::DefineConstantOperand(HConstant* constant) { |
| 484 | return LConstantOperand::Create(constant->id()); |
| 485 | } |
| 486 | |
| 487 | |
| 488 | int LChunk::GetParameterStackSlot(int index) const { |
| 489 | // The receiver is at index 0, the first parameter at index 1, so we |
| 490 | // shift all parameter indexes down by the number of parameters, and |
| 491 | // make sure they end up negative so they are distinguishable from |
| 492 | // spill slots. |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 493 | int result = index - info()->scope()->num_parameters() - 1; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 494 | ASSERT(result < 0); |
| 495 | return result; |
| 496 | } |
| 497 | |
| 498 | // A parameter relative to ebp in the arguments stub. |
| 499 | int LChunk::ParameterAt(int index) { |
| 500 | ASSERT(-1 <= index); // -1 is the receiver. |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 501 | return (1 + info()->scope()->num_parameters() - index) * |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 502 | kPointerSize; |
| 503 | } |
| 504 | |
| 505 | |
| 506 | LGap* LChunk::GetGapAt(int index) const { |
| 507 | return LGap::cast(instructions_[index]); |
| 508 | } |
| 509 | |
| 510 | |
| 511 | bool LChunk::IsGapAt(int index) const { |
| 512 | return instructions_[index]->IsGap(); |
| 513 | } |
| 514 | |
| 515 | |
| 516 | int LChunk::NearestGapPos(int index) const { |
| 517 | while (!IsGapAt(index)) index--; |
| 518 | return index; |
| 519 | } |
| 520 | |
| 521 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 522 | void LChunk::AddGapMove(int index, LOperand* from, LOperand* to) { |
| 523 | GetGapAt(index)->GetOrCreateParallelMove(LGap::START)->AddMove(from, to); |
| 524 | } |
| 525 | |
| 526 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 527 | Handle<Object> LChunk::LookupLiteral(LConstantOperand* operand) const { |
| 528 | return HConstant::cast(graph_->LookupValue(operand->index()))->handle(); |
| 529 | } |
| 530 | |
| 531 | |
| 532 | Representation LChunk::LookupLiteralRepresentation( |
| 533 | LConstantOperand* operand) const { |
| 534 | return graph_->LookupValue(operand->index())->representation(); |
| 535 | } |
| 536 | |
| 537 | |
| 538 | LChunk* LChunkBuilder::Build() { |
| 539 | ASSERT(is_unused()); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 540 | chunk_ = new LChunk(info(), graph()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 541 | HPhase phase("Building chunk", chunk_); |
| 542 | status_ = BUILDING; |
| 543 | const ZoneList<HBasicBlock*>* blocks = graph()->blocks(); |
| 544 | for (int i = 0; i < blocks->length(); i++) { |
| 545 | HBasicBlock* next = NULL; |
| 546 | if (i < blocks->length() - 1) next = blocks->at(i + 1); |
| 547 | DoBasicBlock(blocks->at(i), next); |
| 548 | if (is_aborted()) return NULL; |
| 549 | } |
| 550 | status_ = DONE; |
| 551 | return chunk_; |
| 552 | } |
| 553 | |
| 554 | |
| 555 | void LChunkBuilder::Abort(const char* format, ...) { |
| 556 | if (FLAG_trace_bailout) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 557 | SmartPointer<char> name(info()->shared_info()->DebugName()->ToCString()); |
| 558 | PrintF("Aborting LChunk building in @\"%s\": ", *name); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 559 | va_list arguments; |
| 560 | va_start(arguments, format); |
| 561 | OS::VPrint(format, arguments); |
| 562 | va_end(arguments); |
| 563 | PrintF("\n"); |
| 564 | } |
| 565 | status_ = ABORTED; |
| 566 | } |
| 567 | |
| 568 | |
| 569 | LRegister* LChunkBuilder::ToOperand(Register reg) { |
| 570 | return LRegister::Create(Register::ToAllocationIndex(reg)); |
| 571 | } |
| 572 | |
| 573 | |
| 574 | LUnallocated* LChunkBuilder::ToUnallocated(Register reg) { |
| 575 | return new LUnallocated(LUnallocated::FIXED_REGISTER, |
| 576 | Register::ToAllocationIndex(reg)); |
| 577 | } |
| 578 | |
| 579 | |
| 580 | LUnallocated* LChunkBuilder::ToUnallocated(DoubleRegister reg) { |
| 581 | return new LUnallocated(LUnallocated::FIXED_DOUBLE_REGISTER, |
| 582 | DoubleRegister::ToAllocationIndex(reg)); |
| 583 | } |
| 584 | |
| 585 | |
| 586 | LOperand* LChunkBuilder::UseFixed(HValue* value, Register fixed_register) { |
| 587 | return Use(value, ToUnallocated(fixed_register)); |
| 588 | } |
| 589 | |
| 590 | |
| 591 | LOperand* LChunkBuilder::UseFixedDouble(HValue* value, DoubleRegister reg) { |
| 592 | return Use(value, ToUnallocated(reg)); |
| 593 | } |
| 594 | |
| 595 | |
| 596 | LOperand* LChunkBuilder::UseRegister(HValue* value) { |
| 597 | return Use(value, new LUnallocated(LUnallocated::MUST_HAVE_REGISTER)); |
| 598 | } |
| 599 | |
| 600 | |
| 601 | LOperand* LChunkBuilder::UseRegisterAtStart(HValue* value) { |
| 602 | return Use(value, |
| 603 | new LUnallocated(LUnallocated::MUST_HAVE_REGISTER, |
| 604 | LUnallocated::USED_AT_START)); |
| 605 | } |
| 606 | |
| 607 | |
| 608 | LOperand* LChunkBuilder::UseTempRegister(HValue* value) { |
| 609 | return Use(value, new LUnallocated(LUnallocated::WRITABLE_REGISTER)); |
| 610 | } |
| 611 | |
| 612 | |
| 613 | LOperand* LChunkBuilder::Use(HValue* value) { |
| 614 | return Use(value, new LUnallocated(LUnallocated::NONE)); |
| 615 | } |
| 616 | |
| 617 | |
| 618 | LOperand* LChunkBuilder::UseAtStart(HValue* value) { |
| 619 | return Use(value, new LUnallocated(LUnallocated::NONE, |
| 620 | LUnallocated::USED_AT_START)); |
| 621 | } |
| 622 | |
| 623 | |
| 624 | LOperand* LChunkBuilder::UseOrConstant(HValue* value) { |
| 625 | return value->IsConstant() |
| 626 | ? chunk_->DefineConstantOperand(HConstant::cast(value)) |
| 627 | : Use(value); |
| 628 | } |
| 629 | |
| 630 | |
| 631 | LOperand* LChunkBuilder::UseOrConstantAtStart(HValue* value) { |
| 632 | return value->IsConstant() |
| 633 | ? chunk_->DefineConstantOperand(HConstant::cast(value)) |
| 634 | : UseAtStart(value); |
| 635 | } |
| 636 | |
| 637 | |
| 638 | LOperand* LChunkBuilder::UseRegisterOrConstant(HValue* value) { |
| 639 | return value->IsConstant() |
| 640 | ? chunk_->DefineConstantOperand(HConstant::cast(value)) |
| 641 | : UseRegister(value); |
| 642 | } |
| 643 | |
| 644 | |
| 645 | LOperand* LChunkBuilder::UseRegisterOrConstantAtStart(HValue* value) { |
| 646 | return value->IsConstant() |
| 647 | ? chunk_->DefineConstantOperand(HConstant::cast(value)) |
| 648 | : UseRegisterAtStart(value); |
| 649 | } |
| 650 | |
| 651 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 652 | LOperand* LChunkBuilder::UseAny(HValue* value) { |
| 653 | return value->IsConstant() |
| 654 | ? chunk_->DefineConstantOperand(HConstant::cast(value)) |
| 655 | : Use(value, new LUnallocated(LUnallocated::ANY)); |
| 656 | } |
| 657 | |
| 658 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 659 | LOperand* LChunkBuilder::Use(HValue* value, LUnallocated* operand) { |
| 660 | if (value->EmitAtUses()) { |
| 661 | HInstruction* instr = HInstruction::cast(value); |
| 662 | VisitInstruction(instr); |
| 663 | } |
| 664 | allocator_->RecordUse(value, operand); |
| 665 | return operand; |
| 666 | } |
| 667 | |
| 668 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 669 | template<int I, int T> |
| 670 | LInstruction* LChunkBuilder::Define(LTemplateInstruction<1, I, T>* instr, |
| 671 | LUnallocated* result) { |
| 672 | allocator_->RecordDefinition(current_instruction_, result); |
| 673 | instr->set_result(result); |
| 674 | return instr; |
| 675 | } |
| 676 | |
| 677 | |
| 678 | template<int I, int T> |
| 679 | LInstruction* LChunkBuilder::Define(LTemplateInstruction<1, I, T>* instr) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 680 | return Define(instr, new LUnallocated(LUnallocated::NONE)); |
| 681 | } |
| 682 | |
| 683 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 684 | template<int I, int T> |
| 685 | LInstruction* LChunkBuilder::DefineAsRegister( |
| 686 | LTemplateInstruction<1, I, T>* instr) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 687 | return Define(instr, new LUnallocated(LUnallocated::MUST_HAVE_REGISTER)); |
| 688 | } |
| 689 | |
| 690 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 691 | template<int I, int T> |
| 692 | LInstruction* LChunkBuilder::DefineAsSpilled( |
| 693 | LTemplateInstruction<1, I, T>* instr, int index) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 694 | return Define(instr, new LUnallocated(LUnallocated::FIXED_SLOT, index)); |
| 695 | } |
| 696 | |
| 697 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 698 | template<int I, int T> |
| 699 | LInstruction* LChunkBuilder::DefineSameAsFirst( |
| 700 | LTemplateInstruction<1, I, T>* instr) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 701 | return Define(instr, new LUnallocated(LUnallocated::SAME_AS_FIRST_INPUT)); |
| 702 | } |
| 703 | |
| 704 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 705 | template<int I, int T> |
| 706 | LInstruction* LChunkBuilder::DefineFixed( |
| 707 | LTemplateInstruction<1, I, T>* instr, Register reg) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 708 | return Define(instr, ToUnallocated(reg)); |
| 709 | } |
| 710 | |
| 711 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 712 | template<int I, int T> |
| 713 | LInstruction* LChunkBuilder::DefineFixedDouble( |
| 714 | LTemplateInstruction<1, I, T>* instr, DoubleRegister reg) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 715 | return Define(instr, ToUnallocated(reg)); |
| 716 | } |
| 717 | |
| 718 | |
| 719 | LInstruction* LChunkBuilder::AssignEnvironment(LInstruction* instr) { |
| 720 | HEnvironment* hydrogen_env = current_block_->last_environment(); |
| 721 | instr->set_environment(CreateEnvironment(hydrogen_env)); |
| 722 | return instr; |
| 723 | } |
| 724 | |
| 725 | |
fschneider@chromium.org | 1df6b47 | 2011-01-26 08:23:03 +0000 | [diff] [blame] | 726 | LInstruction* LChunkBuilder::SetInstructionPendingDeoptimizationEnvironment( |
| 727 | LInstruction* instr, int ast_id) { |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 728 | ASSERT(instruction_pending_deoptimization_environment_ == NULL); |
fschneider@chromium.org | 1df6b47 | 2011-01-26 08:23:03 +0000 | [diff] [blame] | 729 | ASSERT(pending_deoptimization_ast_id_ == AstNode::kNoNumber); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 730 | instruction_pending_deoptimization_environment_ = instr; |
fschneider@chromium.org | 1df6b47 | 2011-01-26 08:23:03 +0000 | [diff] [blame] | 731 | pending_deoptimization_ast_id_ = ast_id; |
| 732 | return instr; |
| 733 | } |
| 734 | |
| 735 | |
| 736 | void LChunkBuilder::ClearInstructionPendingDeoptimizationEnvironment() { |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 737 | instruction_pending_deoptimization_environment_ = NULL; |
fschneider@chromium.org | 1df6b47 | 2011-01-26 08:23:03 +0000 | [diff] [blame] | 738 | pending_deoptimization_ast_id_ = AstNode::kNoNumber; |
| 739 | } |
| 740 | |
| 741 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 742 | LInstruction* LChunkBuilder::MarkAsCall(LInstruction* instr, |
| 743 | HInstruction* hinstr, |
| 744 | CanDeoptimize can_deoptimize) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 745 | #ifdef DEBUG |
| 746 | instr->VerifyCall(); |
| 747 | #endif |
| 748 | instr->MarkAsCall(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 749 | instr = AssignPointerMap(instr); |
| 750 | |
| 751 | if (hinstr->HasSideEffects()) { |
| 752 | ASSERT(hinstr->next()->IsSimulate()); |
| 753 | HSimulate* sim = HSimulate::cast(hinstr->next()); |
fschneider@chromium.org | 1df6b47 | 2011-01-26 08:23:03 +0000 | [diff] [blame] | 754 | instr = SetInstructionPendingDeoptimizationEnvironment( |
| 755 | instr, sim->ast_id()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | // If instruction does not have side-effects lazy deoptimization |
| 759 | // after the call will try to deoptimize to the point before the call. |
| 760 | // Thus we still need to attach environment to this call even if |
| 761 | // call sequence can not deoptimize eagerly. |
| 762 | bool needs_environment = |
| 763 | (can_deoptimize == CAN_DEOPTIMIZE_EAGERLY) || !hinstr->HasSideEffects(); |
| 764 | if (needs_environment && !instr->HasEnvironment()) { |
| 765 | instr = AssignEnvironment(instr); |
| 766 | } |
| 767 | |
| 768 | return instr; |
| 769 | } |
| 770 | |
| 771 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 772 | LInstruction* LChunkBuilder::MarkAsSaveDoubles(LInstruction* instr) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 773 | instr->MarkAsSaveDoubles(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 774 | return instr; |
| 775 | } |
| 776 | |
| 777 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 778 | LInstruction* LChunkBuilder::AssignPointerMap(LInstruction* instr) { |
| 779 | ASSERT(!instr->HasPointerMap()); |
| 780 | instr->set_pointer_map(new LPointerMap(position_)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 781 | return instr; |
| 782 | } |
| 783 | |
| 784 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 785 | LUnallocated* LChunkBuilder::TempRegister() { |
| 786 | LUnallocated* operand = new LUnallocated(LUnallocated::MUST_HAVE_REGISTER); |
| 787 | allocator_->RecordTemporary(operand); |
| 788 | return operand; |
| 789 | } |
| 790 | |
| 791 | |
| 792 | LOperand* LChunkBuilder::FixedTemp(Register reg) { |
| 793 | LUnallocated* operand = ToUnallocated(reg); |
| 794 | allocator_->RecordTemporary(operand); |
| 795 | return operand; |
| 796 | } |
| 797 | |
| 798 | |
| 799 | LOperand* LChunkBuilder::FixedTemp(DoubleRegister reg) { |
| 800 | LUnallocated* operand = ToUnallocated(reg); |
| 801 | allocator_->RecordTemporary(operand); |
| 802 | return operand; |
| 803 | } |
| 804 | |
| 805 | |
| 806 | LInstruction* LChunkBuilder::DoBlockEntry(HBlockEntry* instr) { |
| 807 | return new LLabel(instr->block()); |
| 808 | } |
| 809 | |
| 810 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame^] | 811 | LInstruction* LChunkBuilder::DoSoftDeoptimize(HSoftDeoptimize* instr) { |
| 812 | return AssignEnvironment(new LDeoptimize); |
| 813 | } |
| 814 | |
| 815 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 816 | LInstruction* LChunkBuilder::DoDeoptimize(HDeoptimize* instr) { |
| 817 | return AssignEnvironment(new LDeoptimize); |
| 818 | } |
| 819 | |
| 820 | |
| 821 | LInstruction* LChunkBuilder::DoBit(Token::Value op, |
| 822 | HBitwiseBinaryOperation* instr) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 823 | if (instr->representation().IsInteger32()) { |
| 824 | ASSERT(instr->left()->representation().IsInteger32()); |
| 825 | ASSERT(instr->right()->representation().IsInteger32()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 826 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 827 | LOperand* left = UseRegisterAtStart(instr->LeastConstantOperand()); |
| 828 | LOperand* right = UseOrConstantAtStart(instr->MostConstantOperand()); |
| 829 | return DefineSameAsFirst(new LBitI(op, left, right)); |
| 830 | } else { |
| 831 | ASSERT(instr->representation().IsTagged()); |
| 832 | ASSERT(instr->left()->representation().IsTagged()); |
| 833 | ASSERT(instr->right()->representation().IsTagged()); |
| 834 | |
| 835 | LOperand* left = UseFixed(instr->left(), r1); |
| 836 | LOperand* right = UseFixed(instr->right(), r0); |
| 837 | LArithmeticT* result = new LArithmeticT(op, left, right); |
| 838 | return MarkAsCall(DefineFixed(result, r0), instr); |
| 839 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 840 | } |
| 841 | |
| 842 | |
| 843 | LInstruction* LChunkBuilder::DoShift(Token::Value op, |
| 844 | HBitwiseBinaryOperation* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 845 | if (instr->representation().IsTagged()) { |
| 846 | ASSERT(instr->left()->representation().IsTagged()); |
| 847 | ASSERT(instr->right()->representation().IsTagged()); |
| 848 | |
| 849 | LOperand* left = UseFixed(instr->left(), r1); |
| 850 | LOperand* right = UseFixed(instr->right(), r0); |
| 851 | LArithmeticT* result = new LArithmeticT(op, left, right); |
| 852 | return MarkAsCall(DefineFixed(result, r0), instr); |
| 853 | } |
| 854 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 855 | ASSERT(instr->representation().IsInteger32()); |
| 856 | ASSERT(instr->OperandAt(0)->representation().IsInteger32()); |
| 857 | ASSERT(instr->OperandAt(1)->representation().IsInteger32()); |
| 858 | LOperand* left = UseRegisterAtStart(instr->OperandAt(0)); |
| 859 | |
| 860 | HValue* right_value = instr->OperandAt(1); |
| 861 | LOperand* right = NULL; |
| 862 | int constant_value = 0; |
| 863 | if (right_value->IsConstant()) { |
| 864 | HConstant* constant = HConstant::cast(right_value); |
| 865 | right = chunk_->DefineConstantOperand(constant); |
| 866 | constant_value = constant->Integer32Value() & 0x1f; |
| 867 | } else { |
| 868 | right = UseRegister(right_value); |
| 869 | } |
| 870 | |
| 871 | // Shift operations can only deoptimize if we do a logical shift |
| 872 | // by 0 and the result cannot be truncated to int32. |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 873 | bool may_deopt = (op == Token::SHR && constant_value == 0); |
| 874 | bool does_deopt = false; |
| 875 | if (may_deopt) { |
| 876 | for (HUseIterator it(instr->uses()); !it.Done(); it.Advance()) { |
| 877 | if (!it.value()->CheckFlag(HValue::kTruncatingToInt32)) { |
| 878 | does_deopt = true; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 879 | break; |
| 880 | } |
| 881 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 882 | } |
| 883 | |
| 884 | LInstruction* result = |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 885 | DefineSameAsFirst(new LShiftI(op, left, right, does_deopt)); |
| 886 | return does_deopt ? AssignEnvironment(result) : result; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | |
| 890 | LInstruction* LChunkBuilder::DoArithmeticD(Token::Value op, |
| 891 | HArithmeticBinaryOperation* instr) { |
| 892 | ASSERT(instr->representation().IsDouble()); |
| 893 | ASSERT(instr->left()->representation().IsDouble()); |
| 894 | ASSERT(instr->right()->representation().IsDouble()); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 895 | ASSERT(op != Token::MOD); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 896 | LOperand* left = UseRegisterAtStart(instr->left()); |
| 897 | LOperand* right = UseRegisterAtStart(instr->right()); |
| 898 | LArithmeticD* result = new LArithmeticD(op, left, right); |
| 899 | return DefineSameAsFirst(result); |
| 900 | } |
| 901 | |
| 902 | |
| 903 | LInstruction* LChunkBuilder::DoArithmeticT(Token::Value op, |
| 904 | HArithmeticBinaryOperation* instr) { |
| 905 | ASSERT(op == Token::ADD || |
| 906 | op == Token::DIV || |
| 907 | op == Token::MOD || |
| 908 | op == Token::MUL || |
| 909 | op == Token::SUB); |
| 910 | HValue* left = instr->left(); |
| 911 | HValue* right = instr->right(); |
| 912 | ASSERT(left->representation().IsTagged()); |
| 913 | ASSERT(right->representation().IsTagged()); |
| 914 | LOperand* left_operand = UseFixed(left, r1); |
| 915 | LOperand* right_operand = UseFixed(right, r0); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 916 | LArithmeticT* result = new LArithmeticT(op, left_operand, right_operand); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 917 | return MarkAsCall(DefineFixed(result, r0), instr); |
| 918 | } |
| 919 | |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 920 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 921 | void LChunkBuilder::DoBasicBlock(HBasicBlock* block, HBasicBlock* next_block) { |
| 922 | ASSERT(is_building()); |
| 923 | current_block_ = block; |
| 924 | next_block_ = next_block; |
| 925 | if (block->IsStartBlock()) { |
| 926 | block->UpdateEnvironment(graph_->start_environment()); |
| 927 | argument_count_ = 0; |
| 928 | } else if (block->predecessors()->length() == 1) { |
| 929 | // We have a single predecessor => copy environment and outgoing |
| 930 | // argument count from the predecessor. |
| 931 | ASSERT(block->phis()->length() == 0); |
| 932 | HBasicBlock* pred = block->predecessors()->at(0); |
| 933 | HEnvironment* last_environment = pred->last_environment(); |
| 934 | ASSERT(last_environment != NULL); |
| 935 | // Only copy the environment, if it is later used again. |
| 936 | if (pred->end()->SecondSuccessor() == NULL) { |
| 937 | ASSERT(pred->end()->FirstSuccessor() == block); |
| 938 | } else { |
| 939 | if (pred->end()->FirstSuccessor()->block_id() > block->block_id() || |
| 940 | pred->end()->SecondSuccessor()->block_id() > block->block_id()) { |
| 941 | last_environment = last_environment->Copy(); |
| 942 | } |
| 943 | } |
| 944 | block->UpdateEnvironment(last_environment); |
| 945 | ASSERT(pred->argument_count() >= 0); |
| 946 | argument_count_ = pred->argument_count(); |
| 947 | } else { |
| 948 | // We are at a state join => process phis. |
| 949 | HBasicBlock* pred = block->predecessors()->at(0); |
| 950 | // No need to copy the environment, it cannot be used later. |
| 951 | HEnvironment* last_environment = pred->last_environment(); |
| 952 | for (int i = 0; i < block->phis()->length(); ++i) { |
| 953 | HPhi* phi = block->phis()->at(i); |
| 954 | last_environment->SetValueAt(phi->merged_index(), phi); |
| 955 | } |
| 956 | for (int i = 0; i < block->deleted_phis()->length(); ++i) { |
| 957 | last_environment->SetValueAt(block->deleted_phis()->at(i), |
| 958 | graph_->GetConstantUndefined()); |
| 959 | } |
| 960 | block->UpdateEnvironment(last_environment); |
| 961 | // Pick up the outgoing argument count of one of the predecessors. |
| 962 | argument_count_ = pred->argument_count(); |
| 963 | } |
| 964 | HInstruction* current = block->first(); |
| 965 | int start = chunk_->instructions()->length(); |
| 966 | while (current != NULL && !is_aborted()) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 967 | // Code for constants in registers is generated lazily. |
| 968 | if (!current->EmitAtUses()) { |
| 969 | VisitInstruction(current); |
| 970 | } |
| 971 | current = current->next(); |
| 972 | } |
| 973 | int end = chunk_->instructions()->length() - 1; |
| 974 | if (end >= start) { |
| 975 | block->set_first_instruction_index(start); |
| 976 | block->set_last_instruction_index(end); |
| 977 | } |
| 978 | block->set_argument_count(argument_count_); |
| 979 | next_block_ = NULL; |
| 980 | current_block_ = NULL; |
| 981 | } |
| 982 | |
| 983 | |
| 984 | void LChunkBuilder::VisitInstruction(HInstruction* current) { |
| 985 | HInstruction* old_current = current_instruction_; |
| 986 | current_instruction_ = current; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 987 | if (current->has_position()) position_ = current->position(); |
| 988 | LInstruction* instr = current->CompileToLithium(this); |
| 989 | |
| 990 | if (instr != NULL) { |
| 991 | if (FLAG_stress_pointer_maps && !instr->HasPointerMap()) { |
| 992 | instr = AssignPointerMap(instr); |
| 993 | } |
| 994 | if (FLAG_stress_environments && !instr->HasEnvironment()) { |
| 995 | instr = AssignEnvironment(instr); |
| 996 | } |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 997 | if (current->IsTest() && !instr->IsGoto()) { |
| 998 | ASSERT(instr->IsControl()); |
| 999 | HTest* test = HTest::cast(current); |
| 1000 | instr->set_hydrogen_value(test->value()); |
| 1001 | HBasicBlock* first = test->FirstSuccessor(); |
| 1002 | HBasicBlock* second = test->SecondSuccessor(); |
| 1003 | ASSERT(first != NULL && second != NULL); |
| 1004 | instr->SetBranchTargets(first->block_id(), second->block_id()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1005 | } else { |
| 1006 | instr->set_hydrogen_value(current); |
| 1007 | } |
| 1008 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1009 | chunk_->AddInstruction(instr, current_block_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1010 | } |
| 1011 | current_instruction_ = old_current; |
| 1012 | } |
| 1013 | |
| 1014 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1015 | LEnvironment* LChunkBuilder::CreateEnvironment(HEnvironment* hydrogen_env) { |
| 1016 | if (hydrogen_env == NULL) return NULL; |
| 1017 | |
| 1018 | LEnvironment* outer = CreateEnvironment(hydrogen_env->outer()); |
| 1019 | int ast_id = hydrogen_env->ast_id(); |
| 1020 | ASSERT(ast_id != AstNode::kNoNumber); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1021 | int value_count = hydrogen_env->length(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1022 | LEnvironment* result = new LEnvironment(hydrogen_env->closure(), |
| 1023 | ast_id, |
| 1024 | hydrogen_env->parameter_count(), |
| 1025 | argument_count_, |
| 1026 | value_count, |
| 1027 | outer); |
| 1028 | int argument_index = 0; |
| 1029 | for (int i = 0; i < value_count; ++i) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1030 | if (hydrogen_env->is_special_index(i)) continue; |
| 1031 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1032 | HValue* value = hydrogen_env->values()->at(i); |
| 1033 | LOperand* op = NULL; |
| 1034 | if (value->IsArgumentsObject()) { |
| 1035 | op = NULL; |
| 1036 | } else if (value->IsPushArgument()) { |
| 1037 | op = new LArgument(argument_index++); |
| 1038 | } else { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1039 | op = UseAny(value); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1040 | } |
| 1041 | result->AddValue(op, value->representation()); |
| 1042 | } |
| 1043 | |
| 1044 | return result; |
| 1045 | } |
| 1046 | |
| 1047 | |
| 1048 | LInstruction* LChunkBuilder::DoGoto(HGoto* instr) { |
| 1049 | LInstruction* result = new LGoto(instr->FirstSuccessor()->block_id(), |
| 1050 | instr->include_stack_check()); |
| 1051 | if (instr->include_stack_check()) result = AssignPointerMap(result); |
| 1052 | return result; |
| 1053 | } |
| 1054 | |
| 1055 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1056 | LInstruction* LChunkBuilder::DoTest(HTest* instr) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1057 | HValue* v = instr->value(); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1058 | if (!v->EmitAtUses()) { |
| 1059 | return new LBranch(UseRegisterAtStart(v)); |
| 1060 | } else if (v->IsClassOfTest()) { |
| 1061 | HClassOfTest* compare = HClassOfTest::cast(v); |
| 1062 | ASSERT(compare->value()->representation().IsTagged()); |
| 1063 | return new LClassOfTestAndBranch(UseTempRegister(compare->value()), |
| 1064 | TempRegister()); |
| 1065 | } else if (v->IsCompare()) { |
| 1066 | HCompare* compare = HCompare::cast(v); |
| 1067 | Token::Value op = compare->token(); |
| 1068 | HValue* left = compare->left(); |
| 1069 | HValue* right = compare->right(); |
| 1070 | Representation r = compare->GetInputRepresentation(); |
| 1071 | if (r.IsInteger32()) { |
| 1072 | ASSERT(left->representation().IsInteger32()); |
| 1073 | ASSERT(right->representation().IsInteger32()); |
| 1074 | return new LCmpIDAndBranch(UseRegisterAtStart(left), |
| 1075 | UseRegisterAtStart(right)); |
| 1076 | } else if (r.IsDouble()) { |
| 1077 | ASSERT(left->representation().IsDouble()); |
| 1078 | ASSERT(right->representation().IsDouble()); |
| 1079 | return new LCmpIDAndBranch(UseRegisterAtStart(left), |
| 1080 | UseRegisterAtStart(right)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1081 | } else { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1082 | ASSERT(left->representation().IsTagged()); |
| 1083 | ASSERT(right->representation().IsTagged()); |
| 1084 | bool reversed = op == Token::GT || op == Token::LTE; |
| 1085 | LOperand* left_operand = UseFixed(left, reversed ? r0 : r1); |
| 1086 | LOperand* right_operand = UseFixed(right, reversed ? r1 : r0); |
| 1087 | LInstruction* result = new LCmpTAndBranch(left_operand, right_operand); |
| 1088 | return MarkAsCall(result, instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1089 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1090 | } else if (v->IsIsSmi()) { |
| 1091 | HIsSmi* compare = HIsSmi::cast(v); |
| 1092 | ASSERT(compare->value()->representation().IsTagged()); |
| 1093 | return new LIsSmiAndBranch(Use(compare->value())); |
| 1094 | } else if (v->IsIsUndetectable()) { |
| 1095 | HIsUndetectable* compare = HIsUndetectable::cast(v); |
| 1096 | ASSERT(compare->value()->representation().IsTagged()); |
| 1097 | return new LIsUndetectableAndBranch(UseRegisterAtStart(compare->value()), |
| 1098 | TempRegister()); |
| 1099 | } else if (v->IsHasInstanceType()) { |
| 1100 | HHasInstanceType* compare = HHasInstanceType::cast(v); |
| 1101 | ASSERT(compare->value()->representation().IsTagged()); |
| 1102 | return new LHasInstanceTypeAndBranch(UseRegisterAtStart(compare->value())); |
| 1103 | } else if (v->IsHasCachedArrayIndex()) { |
| 1104 | HHasCachedArrayIndex* compare = HHasCachedArrayIndex::cast(v); |
| 1105 | ASSERT(compare->value()->representation().IsTagged()); |
| 1106 | return new LHasCachedArrayIndexAndBranch( |
| 1107 | UseRegisterAtStart(compare->value())); |
| 1108 | } else if (v->IsIsNull()) { |
| 1109 | HIsNull* compare = HIsNull::cast(v); |
| 1110 | ASSERT(compare->value()->representation().IsTagged()); |
| 1111 | return new LIsNullAndBranch(UseRegisterAtStart(compare->value())); |
| 1112 | } else if (v->IsIsObject()) { |
| 1113 | HIsObject* compare = HIsObject::cast(v); |
| 1114 | ASSERT(compare->value()->representation().IsTagged()); |
| 1115 | LOperand* temp = TempRegister(); |
| 1116 | return new LIsObjectAndBranch(UseRegisterAtStart(compare->value()), temp); |
| 1117 | } else if (v->IsCompareJSObjectEq()) { |
| 1118 | HCompareJSObjectEq* compare = HCompareJSObjectEq::cast(v); |
| 1119 | return new LCmpJSObjectEqAndBranch(UseRegisterAtStart(compare->left()), |
| 1120 | UseRegisterAtStart(compare->right())); |
| 1121 | } else if (v->IsCompareSymbolEq()) { |
| 1122 | HCompareSymbolEq* compare = HCompareSymbolEq::cast(v); |
| 1123 | return new LCmpSymbolEqAndBranch(UseRegisterAtStart(compare->left()), |
| 1124 | UseRegisterAtStart(compare->right())); |
| 1125 | } else if (v->IsInstanceOf()) { |
| 1126 | HInstanceOf* instance_of = HInstanceOf::cast(v); |
| 1127 | LInstruction* result = |
| 1128 | new LInstanceOfAndBranch(UseFixed(instance_of->left(), r0), |
| 1129 | UseFixed(instance_of->right(), r1)); |
| 1130 | return MarkAsCall(result, instr); |
| 1131 | } else if (v->IsTypeofIs()) { |
| 1132 | HTypeofIs* typeof_is = HTypeofIs::cast(v); |
| 1133 | return new LTypeofIsAndBranch(UseTempRegister(typeof_is->value())); |
| 1134 | } else if (v->IsIsConstructCall()) { |
| 1135 | return new LIsConstructCallAndBranch(TempRegister()); |
| 1136 | } else if (v->IsConstant()) { |
| 1137 | HBasicBlock* successor = HConstant::cast(v)->ToBoolean() |
| 1138 | ? instr->FirstSuccessor() |
| 1139 | : instr->SecondSuccessor(); |
| 1140 | return new LGoto(successor->block_id()); |
| 1141 | } else { |
| 1142 | Abort("Undefined compare before branch"); |
| 1143 | return NULL; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1144 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1145 | } |
| 1146 | |
| 1147 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1148 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1149 | LInstruction* LChunkBuilder::DoCompareMap(HCompareMap* instr) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1150 | ASSERT(instr->value()->representation().IsTagged()); |
| 1151 | LOperand* value = UseRegisterAtStart(instr->value()); |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1152 | LOperand* temp = TempRegister(); |
| 1153 | return new LCmpMapAndBranch(value, temp); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1154 | } |
| 1155 | |
| 1156 | |
| 1157 | LInstruction* LChunkBuilder::DoArgumentsLength(HArgumentsLength* length) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1158 | return DefineAsRegister(new LArgumentsLength(UseRegister(length->value()))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1159 | } |
| 1160 | |
| 1161 | |
| 1162 | LInstruction* LChunkBuilder::DoArgumentsElements(HArgumentsElements* elems) { |
| 1163 | return DefineAsRegister(new LArgumentsElements); |
| 1164 | } |
| 1165 | |
| 1166 | |
| 1167 | LInstruction* LChunkBuilder::DoInstanceOf(HInstanceOf* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1168 | LInstanceOf* result = |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 1169 | new LInstanceOf(UseFixed(instr->left(), r0), |
| 1170 | UseFixed(instr->right(), r1)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1171 | return MarkAsCall(DefineFixed(result, r0), instr); |
| 1172 | } |
| 1173 | |
| 1174 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1175 | LInstruction* LChunkBuilder::DoInstanceOfKnownGlobal( |
| 1176 | HInstanceOfKnownGlobal* instr) { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1177 | LInstanceOfKnownGlobal* result = |
| 1178 | new LInstanceOfKnownGlobal(UseFixed(instr->value(), r0), FixedTemp(r4)); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1179 | return MarkAsCall(DefineFixed(result, r0), instr); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1180 | } |
| 1181 | |
| 1182 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1183 | LInstruction* LChunkBuilder::DoApplyArguments(HApplyArguments* instr) { |
| 1184 | LOperand* function = UseFixed(instr->function(), r1); |
| 1185 | LOperand* receiver = UseFixed(instr->receiver(), r0); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 1186 | LOperand* length = UseFixed(instr->length(), r2); |
| 1187 | LOperand* elements = UseFixed(instr->elements(), r3); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1188 | LApplyArguments* result = new LApplyArguments(function, |
| 1189 | receiver, |
| 1190 | length, |
| 1191 | elements); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1192 | return MarkAsCall(DefineFixed(result, r0), instr, CAN_DEOPTIMIZE_EAGERLY); |
| 1193 | } |
| 1194 | |
| 1195 | |
| 1196 | LInstruction* LChunkBuilder::DoPushArgument(HPushArgument* instr) { |
| 1197 | ++argument_count_; |
| 1198 | LOperand* argument = Use(instr->argument()); |
| 1199 | return new LPushArgument(argument); |
| 1200 | } |
| 1201 | |
| 1202 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1203 | LInstruction* LChunkBuilder::DoThisFunction(HThisFunction* instr) { |
| 1204 | return instr->HasNoUses() ? NULL : DefineAsRegister(new LThisFunction); |
| 1205 | } |
| 1206 | |
| 1207 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1208 | LInstruction* LChunkBuilder::DoContext(HContext* instr) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1209 | return instr->HasNoUses() ? NULL : DefineAsRegister(new LContext); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1210 | } |
| 1211 | |
| 1212 | |
| 1213 | LInstruction* LChunkBuilder::DoOuterContext(HOuterContext* instr) { |
| 1214 | LOperand* context = UseRegisterAtStart(instr->value()); |
| 1215 | return DefineAsRegister(new LOuterContext(context)); |
| 1216 | } |
| 1217 | |
| 1218 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1219 | LInstruction* LChunkBuilder::DoGlobalObject(HGlobalObject* instr) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1220 | LOperand* context = UseRegisterAtStart(instr->value()); |
| 1221 | return DefineAsRegister(new LGlobalObject(context)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1222 | } |
| 1223 | |
| 1224 | |
| 1225 | LInstruction* LChunkBuilder::DoGlobalReceiver(HGlobalReceiver* instr) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1226 | LOperand* global_object = UseRegisterAtStart(instr->value()); |
| 1227 | return DefineAsRegister(new LGlobalReceiver(global_object)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1228 | } |
| 1229 | |
| 1230 | |
| 1231 | LInstruction* LChunkBuilder::DoCallConstantFunction( |
| 1232 | HCallConstantFunction* instr) { |
| 1233 | argument_count_ -= instr->argument_count(); |
| 1234 | return MarkAsCall(DefineFixed(new LCallConstantFunction, r0), instr); |
| 1235 | } |
| 1236 | |
| 1237 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1238 | LInstruction* LChunkBuilder::DoInvokeFunction(HInvokeFunction* instr) { |
| 1239 | LOperand* function = UseFixed(instr->function(), r1); |
| 1240 | argument_count_ -= instr->argument_count(); |
| 1241 | LInvokeFunction* result = new LInvokeFunction(function); |
| 1242 | return MarkAsCall(DefineFixed(result, r0), instr, CANNOT_DEOPTIMIZE_EAGERLY); |
| 1243 | } |
| 1244 | |
| 1245 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1246 | LInstruction* LChunkBuilder::DoUnaryMathOperation(HUnaryMathOperation* instr) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1247 | BuiltinFunctionId op = instr->op(); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1248 | if (op == kMathLog || op == kMathSin || op == kMathCos) { |
| 1249 | LOperand* input = UseFixedDouble(instr->value(), d2); |
| 1250 | LUnaryMathOperation* result = new LUnaryMathOperation(input, NULL); |
| 1251 | return MarkAsCall(DefineFixedDouble(result, d2), instr); |
| 1252 | } else { |
| 1253 | LOperand* input = UseRegisterAtStart(instr->value()); |
| 1254 | LOperand* temp = (op == kMathFloor) ? TempRegister() : NULL; |
| 1255 | LUnaryMathOperation* result = new LUnaryMathOperation(input, temp); |
| 1256 | switch (op) { |
| 1257 | case kMathAbs: |
| 1258 | return AssignEnvironment(AssignPointerMap(DefineSameAsFirst(result))); |
| 1259 | case kMathFloor: |
| 1260 | return AssignEnvironment(AssignPointerMap(DefineAsRegister(result))); |
| 1261 | case kMathSqrt: |
| 1262 | return DefineSameAsFirst(result); |
| 1263 | case kMathRound: |
| 1264 | return AssignEnvironment(DefineAsRegister(result)); |
| 1265 | case kMathPowHalf: |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 1266 | return DefineSameAsFirst(result); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1267 | default: |
| 1268 | UNREACHABLE(); |
| 1269 | return NULL; |
| 1270 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1271 | } |
| 1272 | } |
| 1273 | |
| 1274 | |
| 1275 | LInstruction* LChunkBuilder::DoCallKeyed(HCallKeyed* instr) { |
| 1276 | ASSERT(instr->key()->representation().IsTagged()); |
| 1277 | argument_count_ -= instr->argument_count(); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1278 | LOperand* key = UseFixed(instr->key(), r2); |
| 1279 | return MarkAsCall(DefineFixed(new LCallKeyed(key), r0), instr); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1280 | } |
| 1281 | |
| 1282 | |
| 1283 | LInstruction* LChunkBuilder::DoCallNamed(HCallNamed* instr) { |
| 1284 | argument_count_ -= instr->argument_count(); |
| 1285 | return MarkAsCall(DefineFixed(new LCallNamed, r0), instr); |
| 1286 | } |
| 1287 | |
| 1288 | |
| 1289 | LInstruction* LChunkBuilder::DoCallGlobal(HCallGlobal* instr) { |
| 1290 | argument_count_ -= instr->argument_count(); |
| 1291 | return MarkAsCall(DefineFixed(new LCallGlobal, r0), instr); |
| 1292 | } |
| 1293 | |
| 1294 | |
| 1295 | LInstruction* LChunkBuilder::DoCallKnownGlobal(HCallKnownGlobal* instr) { |
| 1296 | argument_count_ -= instr->argument_count(); |
| 1297 | return MarkAsCall(DefineFixed(new LCallKnownGlobal, r0), instr); |
| 1298 | } |
| 1299 | |
| 1300 | |
| 1301 | LInstruction* LChunkBuilder::DoCallNew(HCallNew* instr) { |
| 1302 | LOperand* constructor = UseFixed(instr->constructor(), r1); |
| 1303 | argument_count_ -= instr->argument_count(); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1304 | LCallNew* result = new LCallNew(constructor); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1305 | return MarkAsCall(DefineFixed(result, r0), instr); |
| 1306 | } |
| 1307 | |
| 1308 | |
| 1309 | LInstruction* LChunkBuilder::DoCallFunction(HCallFunction* instr) { |
| 1310 | argument_count_ -= instr->argument_count(); |
| 1311 | return MarkAsCall(DefineFixed(new LCallFunction, r0), instr); |
| 1312 | } |
| 1313 | |
| 1314 | |
| 1315 | LInstruction* LChunkBuilder::DoCallRuntime(HCallRuntime* instr) { |
| 1316 | argument_count_ -= instr->argument_count(); |
| 1317 | return MarkAsCall(DefineFixed(new LCallRuntime, r0), instr); |
| 1318 | } |
| 1319 | |
| 1320 | |
| 1321 | LInstruction* LChunkBuilder::DoShr(HShr* instr) { |
| 1322 | return DoShift(Token::SHR, instr); |
| 1323 | } |
| 1324 | |
| 1325 | |
| 1326 | LInstruction* LChunkBuilder::DoSar(HSar* instr) { |
| 1327 | return DoShift(Token::SAR, instr); |
| 1328 | } |
| 1329 | |
| 1330 | |
| 1331 | LInstruction* LChunkBuilder::DoShl(HShl* instr) { |
| 1332 | return DoShift(Token::SHL, instr); |
| 1333 | } |
| 1334 | |
| 1335 | |
| 1336 | LInstruction* LChunkBuilder::DoBitAnd(HBitAnd* instr) { |
| 1337 | return DoBit(Token::BIT_AND, instr); |
| 1338 | } |
| 1339 | |
| 1340 | |
| 1341 | LInstruction* LChunkBuilder::DoBitNot(HBitNot* instr) { |
| 1342 | ASSERT(instr->value()->representation().IsInteger32()); |
| 1343 | ASSERT(instr->representation().IsInteger32()); |
| 1344 | return DefineSameAsFirst(new LBitNotI(UseRegisterAtStart(instr->value()))); |
| 1345 | } |
| 1346 | |
| 1347 | |
| 1348 | LInstruction* LChunkBuilder::DoBitOr(HBitOr* instr) { |
| 1349 | return DoBit(Token::BIT_OR, instr); |
| 1350 | } |
| 1351 | |
| 1352 | |
| 1353 | LInstruction* LChunkBuilder::DoBitXor(HBitXor* instr) { |
| 1354 | return DoBit(Token::BIT_XOR, instr); |
| 1355 | } |
| 1356 | |
| 1357 | |
| 1358 | LInstruction* LChunkBuilder::DoDiv(HDiv* instr) { |
| 1359 | if (instr->representation().IsDouble()) { |
| 1360 | return DoArithmeticD(Token::DIV, instr); |
| 1361 | } else if (instr->representation().IsInteger32()) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1362 | // TODO(1042) The fixed register allocation |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1363 | // is needed because we call TypeRecordingBinaryOpStub from |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1364 | // the generated code, which requires registers r0 |
| 1365 | // and r1 to be used. We should remove that |
| 1366 | // when we provide a native implementation. |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1367 | LOperand* dividend = UseFixed(instr->left(), r0); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1368 | LOperand* divisor = UseFixed(instr->right(), r1); |
| 1369 | return AssignEnvironment(AssignPointerMap( |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1370 | DefineFixed(new LDivI(dividend, divisor), r0))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1371 | } else { |
| 1372 | return DoArithmeticT(Token::DIV, instr); |
| 1373 | } |
| 1374 | } |
| 1375 | |
| 1376 | |
| 1377 | LInstruction* LChunkBuilder::DoMod(HMod* instr) { |
| 1378 | if (instr->representation().IsInteger32()) { |
| 1379 | ASSERT(instr->left()->representation().IsInteger32()); |
| 1380 | ASSERT(instr->right()->representation().IsInteger32()); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1381 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1382 | LModI* mod; |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1383 | if (instr->HasPowerOf2Divisor()) { |
| 1384 | ASSERT(!instr->CheckFlag(HValue::kCanBeDivByZero)); |
| 1385 | LOperand* value = UseRegisterAtStart(instr->left()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1386 | mod = new LModI(value, UseOrConstant(instr->right())); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1387 | } else { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1388 | LOperand* dividend = UseRegister(instr->left()); |
| 1389 | LOperand* divisor = UseRegisterAtStart(instr->right()); |
| 1390 | mod = new LModI(dividend, |
| 1391 | divisor, |
| 1392 | TempRegister(), |
| 1393 | FixedTemp(d1), |
| 1394 | FixedTemp(d2)); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1395 | } |
| 1396 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1397 | return AssignEnvironment(DefineSameAsFirst(mod)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1398 | } else if (instr->representation().IsTagged()) { |
| 1399 | return DoArithmeticT(Token::MOD, instr); |
| 1400 | } else { |
| 1401 | ASSERT(instr->representation().IsDouble()); |
| 1402 | // We call a C function for double modulo. It can't trigger a GC. |
| 1403 | // We need to use fixed result register for the call. |
| 1404 | // TODO(fschneider): Allow any register as input registers. |
| 1405 | LOperand* left = UseFixedDouble(instr->left(), d1); |
| 1406 | LOperand* right = UseFixedDouble(instr->right(), d2); |
| 1407 | LArithmeticD* result = new LArithmeticD(Token::MOD, left, right); |
| 1408 | return MarkAsCall(DefineFixedDouble(result, d1), instr); |
| 1409 | } |
| 1410 | } |
| 1411 | |
| 1412 | |
| 1413 | LInstruction* LChunkBuilder::DoMul(HMul* instr) { |
| 1414 | if (instr->representation().IsInteger32()) { |
| 1415 | ASSERT(instr->left()->representation().IsInteger32()); |
| 1416 | ASSERT(instr->right()->representation().IsInteger32()); |
| 1417 | LOperand* left = UseRegisterAtStart(instr->LeastConstantOperand()); |
| 1418 | LOperand* right = UseOrConstant(instr->MostConstantOperand()); |
| 1419 | LOperand* temp = NULL; |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1420 | if (instr->CheckFlag(HValue::kBailoutOnMinusZero) && |
| 1421 | (instr->CheckFlag(HValue::kCanOverflow) || |
| 1422 | !right->IsConstantOperand())) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1423 | temp = TempRegister(); |
| 1424 | } |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1425 | return AssignEnvironment(DefineSameAsFirst(new LMulI(left, right, temp))); |
| 1426 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1427 | } else if (instr->representation().IsDouble()) { |
| 1428 | return DoArithmeticD(Token::MUL, instr); |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 1429 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1430 | } else { |
| 1431 | return DoArithmeticT(Token::MUL, instr); |
| 1432 | } |
| 1433 | } |
| 1434 | |
| 1435 | |
| 1436 | LInstruction* LChunkBuilder::DoSub(HSub* instr) { |
| 1437 | if (instr->representation().IsInteger32()) { |
| 1438 | ASSERT(instr->left()->representation().IsInteger32()); |
| 1439 | ASSERT(instr->right()->representation().IsInteger32()); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1440 | LOperand* left = UseRegisterAtStart(instr->left()); |
| 1441 | LOperand* right = UseOrConstantAtStart(instr->right()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1442 | LSubI* sub = new LSubI(left, right); |
| 1443 | LInstruction* result = DefineSameAsFirst(sub); |
| 1444 | if (instr->CheckFlag(HValue::kCanOverflow)) { |
| 1445 | result = AssignEnvironment(result); |
| 1446 | } |
| 1447 | return result; |
| 1448 | } else if (instr->representation().IsDouble()) { |
| 1449 | return DoArithmeticD(Token::SUB, instr); |
| 1450 | } else { |
| 1451 | return DoArithmeticT(Token::SUB, instr); |
| 1452 | } |
| 1453 | } |
| 1454 | |
| 1455 | |
| 1456 | LInstruction* LChunkBuilder::DoAdd(HAdd* instr) { |
| 1457 | if (instr->representation().IsInteger32()) { |
| 1458 | ASSERT(instr->left()->representation().IsInteger32()); |
| 1459 | ASSERT(instr->right()->representation().IsInteger32()); |
| 1460 | LOperand* left = UseRegisterAtStart(instr->LeastConstantOperand()); |
| 1461 | LOperand* right = UseOrConstantAtStart(instr->MostConstantOperand()); |
| 1462 | LAddI* add = new LAddI(left, right); |
| 1463 | LInstruction* result = DefineSameAsFirst(add); |
| 1464 | if (instr->CheckFlag(HValue::kCanOverflow)) { |
| 1465 | result = AssignEnvironment(result); |
| 1466 | } |
| 1467 | return result; |
| 1468 | } else if (instr->representation().IsDouble()) { |
| 1469 | return DoArithmeticD(Token::ADD, instr); |
| 1470 | } else { |
| 1471 | ASSERT(instr->representation().IsTagged()); |
| 1472 | return DoArithmeticT(Token::ADD, instr); |
| 1473 | } |
| 1474 | } |
| 1475 | |
| 1476 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1477 | LInstruction* LChunkBuilder::DoPower(HPower* instr) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1478 | ASSERT(instr->representation().IsDouble()); |
| 1479 | // We call a C function for double power. It can't trigger a GC. |
| 1480 | // We need to use fixed result register for the call. |
| 1481 | Representation exponent_type = instr->right()->representation(); |
| 1482 | ASSERT(instr->left()->representation().IsDouble()); |
| 1483 | LOperand* left = UseFixedDouble(instr->left(), d1); |
| 1484 | LOperand* right = exponent_type.IsDouble() ? |
| 1485 | UseFixedDouble(instr->right(), d2) : |
| 1486 | UseFixed(instr->right(), r0); |
| 1487 | LPower* result = new LPower(left, right); |
| 1488 | return MarkAsCall(DefineFixedDouble(result, d3), |
| 1489 | instr, |
| 1490 | CAN_DEOPTIMIZE_EAGERLY); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1491 | } |
| 1492 | |
| 1493 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1494 | LInstruction* LChunkBuilder::DoCompare(HCompare* instr) { |
| 1495 | Token::Value op = instr->token(); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1496 | Representation r = instr->GetInputRepresentation(); |
| 1497 | if (r.IsInteger32()) { |
| 1498 | ASSERT(instr->left()->representation().IsInteger32()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1499 | ASSERT(instr->right()->representation().IsInteger32()); |
| 1500 | LOperand* left = UseRegisterAtStart(instr->left()); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 1501 | LOperand* right = UseRegisterAtStart(instr->right()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1502 | return DefineAsRegister(new LCmpID(left, right)); |
| 1503 | } else if (r.IsDouble()) { |
| 1504 | ASSERT(instr->left()->representation().IsDouble()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1505 | ASSERT(instr->right()->representation().IsDouble()); |
| 1506 | LOperand* left = UseRegisterAtStart(instr->left()); |
| 1507 | LOperand* right = UseRegisterAtStart(instr->right()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1508 | return DefineAsRegister(new LCmpID(left, right)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1509 | } else { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1510 | ASSERT(instr->left()->representation().IsTagged()); |
| 1511 | ASSERT(instr->right()->representation().IsTagged()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1512 | bool reversed = (op == Token::GT || op == Token::LTE); |
| 1513 | LOperand* left = UseFixed(instr->left(), reversed ? r0 : r1); |
| 1514 | LOperand* right = UseFixed(instr->right(), reversed ? r1 : r0); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1515 | LCmpT* result = new LCmpT(left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1516 | return MarkAsCall(DefineFixed(result, r0), instr); |
| 1517 | } |
| 1518 | } |
| 1519 | |
| 1520 | |
| 1521 | LInstruction* LChunkBuilder::DoCompareJSObjectEq( |
| 1522 | HCompareJSObjectEq* instr) { |
| 1523 | LOperand* left = UseRegisterAtStart(instr->left()); |
| 1524 | LOperand* right = UseRegisterAtStart(instr->right()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1525 | LCmpJSObjectEq* result = new LCmpJSObjectEq(left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1526 | return DefineAsRegister(result); |
| 1527 | } |
| 1528 | |
| 1529 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1530 | LInstruction* LChunkBuilder::DoCompareSymbolEq( |
| 1531 | HCompareSymbolEq* instr) { |
| 1532 | LOperand* left = UseRegisterAtStart(instr->left()); |
| 1533 | LOperand* right = UseRegisterAtStart(instr->right()); |
| 1534 | LCmpSymbolEq* result = new LCmpSymbolEq(left, right); |
| 1535 | return DefineAsRegister(result); |
| 1536 | } |
| 1537 | |
| 1538 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1539 | LInstruction* LChunkBuilder::DoIsNull(HIsNull* instr) { |
| 1540 | ASSERT(instr->value()->representation().IsTagged()); |
| 1541 | LOperand* value = UseRegisterAtStart(instr->value()); |
| 1542 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1543 | return DefineAsRegister(new LIsNull(value)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1544 | } |
| 1545 | |
| 1546 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1547 | LInstruction* LChunkBuilder::DoIsObject(HIsObject* instr) { |
| 1548 | ASSERT(instr->value()->representation().IsTagged()); |
| 1549 | LOperand* value = UseRegisterAtStart(instr->value()); |
| 1550 | |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1551 | return DefineAsRegister(new LIsObject(value)); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1552 | } |
| 1553 | |
| 1554 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1555 | LInstruction* LChunkBuilder::DoIsSmi(HIsSmi* instr) { |
| 1556 | ASSERT(instr->value()->representation().IsTagged()); |
| 1557 | LOperand* value = UseAtStart(instr->value()); |
| 1558 | |
| 1559 | return DefineAsRegister(new LIsSmi(value)); |
| 1560 | } |
| 1561 | |
| 1562 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1563 | LInstruction* LChunkBuilder::DoIsUndetectable(HIsUndetectable* instr) { |
| 1564 | ASSERT(instr->value()->representation().IsTagged()); |
| 1565 | LOperand* value = UseRegisterAtStart(instr->value()); |
| 1566 | |
| 1567 | return DefineAsRegister(new LIsUndetectable(value)); |
| 1568 | } |
| 1569 | |
| 1570 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1571 | LInstruction* LChunkBuilder::DoHasInstanceType(HHasInstanceType* instr) { |
| 1572 | ASSERT(instr->value()->representation().IsTagged()); |
| 1573 | LOperand* value = UseRegisterAtStart(instr->value()); |
| 1574 | |
| 1575 | return DefineAsRegister(new LHasInstanceType(value)); |
| 1576 | } |
| 1577 | |
| 1578 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1579 | LInstruction* LChunkBuilder::DoGetCachedArrayIndex( |
| 1580 | HGetCachedArrayIndex* instr) { |
| 1581 | ASSERT(instr->value()->representation().IsTagged()); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1582 | LOperand* value = UseRegisterAtStart(instr->value()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1583 | |
| 1584 | return DefineAsRegister(new LGetCachedArrayIndex(value)); |
| 1585 | } |
| 1586 | |
| 1587 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1588 | LInstruction* LChunkBuilder::DoHasCachedArrayIndex( |
| 1589 | HHasCachedArrayIndex* instr) { |
| 1590 | ASSERT(instr->value()->representation().IsTagged()); |
| 1591 | LOperand* value = UseRegister(instr->value()); |
| 1592 | |
| 1593 | return DefineAsRegister(new LHasCachedArrayIndex(value)); |
| 1594 | } |
| 1595 | |
| 1596 | |
| 1597 | LInstruction* LChunkBuilder::DoClassOfTest(HClassOfTest* instr) { |
| 1598 | ASSERT(instr->value()->representation().IsTagged()); |
| 1599 | LOperand* value = UseTempRegister(instr->value()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1600 | return DefineSameAsFirst(new LClassOfTest(value)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1601 | } |
| 1602 | |
| 1603 | |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 1604 | LInstruction* LChunkBuilder::DoJSArrayLength(HJSArrayLength* instr) { |
| 1605 | LOperand* array = UseRegisterAtStart(instr->value()); |
| 1606 | return DefineAsRegister(new LJSArrayLength(array)); |
| 1607 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1608 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1609 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 1610 | LInstruction* LChunkBuilder::DoExternalArrayLength( |
| 1611 | HExternalArrayLength* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 1612 | LOperand* array = UseRegisterAtStart(instr->value()); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 1613 | return DefineAsRegister(new LExternalArrayLength(array)); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 1614 | } |
| 1615 | |
| 1616 | |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 1617 | LInstruction* LChunkBuilder::DoFixedArrayLength(HFixedArrayLength* instr) { |
| 1618 | LOperand* array = UseRegisterAtStart(instr->value()); |
| 1619 | return DefineAsRegister(new LFixedArrayLength(array)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1620 | } |
| 1621 | |
| 1622 | |
| 1623 | LInstruction* LChunkBuilder::DoValueOf(HValueOf* instr) { |
| 1624 | LOperand* object = UseRegister(instr->value()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1625 | LValueOf* result = new LValueOf(object, TempRegister()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1626 | return AssignEnvironment(DefineSameAsFirst(result)); |
| 1627 | } |
| 1628 | |
| 1629 | |
| 1630 | LInstruction* LChunkBuilder::DoBoundsCheck(HBoundsCheck* instr) { |
| 1631 | return AssignEnvironment(new LBoundsCheck(UseRegisterAtStart(instr->index()), |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1632 | UseRegister(instr->length()))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1633 | } |
| 1634 | |
| 1635 | |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 1636 | LInstruction* LChunkBuilder::DoAbnormalExit(HAbnormalExit* instr) { |
| 1637 | // The control instruction marking the end of a block that completed |
| 1638 | // abruptly (e.g., threw an exception). There is nothing specific to do. |
| 1639 | return NULL; |
| 1640 | } |
| 1641 | |
| 1642 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1643 | LInstruction* LChunkBuilder::DoThrow(HThrow* instr) { |
| 1644 | LOperand* value = UseFixed(instr->value(), r0); |
| 1645 | return MarkAsCall(new LThrow(value), instr); |
| 1646 | } |
| 1647 | |
| 1648 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1649 | LInstruction* LChunkBuilder::DoUseConst(HUseConst* instr) { |
| 1650 | return NULL; |
| 1651 | } |
| 1652 | |
| 1653 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1654 | LInstruction* LChunkBuilder::DoForceRepresentation(HForceRepresentation* bad) { |
| 1655 | // All HForceRepresentation instructions should be eliminated in the |
| 1656 | // representation change phase of Hydrogen. |
| 1657 | UNREACHABLE(); |
| 1658 | return NULL; |
| 1659 | } |
| 1660 | |
| 1661 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1662 | LInstruction* LChunkBuilder::DoChange(HChange* instr) { |
| 1663 | Representation from = instr->from(); |
| 1664 | Representation to = instr->to(); |
| 1665 | if (from.IsTagged()) { |
| 1666 | if (to.IsDouble()) { |
| 1667 | LOperand* value = UseRegister(instr->value()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1668 | LNumberUntagD* res = new LNumberUntagD(value); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1669 | return AssignEnvironment(DefineAsRegister(res)); |
| 1670 | } else { |
| 1671 | ASSERT(to.IsInteger32()); |
| 1672 | LOperand* value = UseRegister(instr->value()); |
| 1673 | bool needs_check = !instr->value()->type().IsSmi(); |
| 1674 | LInstruction* res = NULL; |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 1675 | if (!needs_check) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1676 | res = DefineSameAsFirst(new LSmiUntag(value, needs_check)); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 1677 | } else { |
| 1678 | LOperand* temp1 = TempRegister(); |
| 1679 | LOperand* temp2 = instr->CanTruncateToInt32() ? TempRegister() |
| 1680 | : NULL; |
| 1681 | LOperand* temp3 = instr->CanTruncateToInt32() ? FixedTemp(d3) |
| 1682 | : NULL; |
| 1683 | res = DefineSameAsFirst(new LTaggedToI(value, temp1, temp2, temp3)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1684 | res = AssignEnvironment(res); |
| 1685 | } |
| 1686 | return res; |
| 1687 | } |
| 1688 | } else if (from.IsDouble()) { |
| 1689 | if (to.IsTagged()) { |
| 1690 | LOperand* value = UseRegister(instr->value()); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1691 | LOperand* temp1 = TempRegister(); |
| 1692 | LOperand* temp2 = TempRegister(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1693 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1694 | // Make sure that the temp and result_temp registers are |
| 1695 | // different. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1696 | LUnallocated* result_temp = TempRegister(); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1697 | LNumberTagD* result = new LNumberTagD(value, temp1, temp2); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1698 | Define(result, result_temp); |
| 1699 | return AssignPointerMap(result); |
| 1700 | } else { |
| 1701 | ASSERT(to.IsInteger32()); |
| 1702 | LOperand* value = UseRegister(instr->value()); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 1703 | LDoubleToI* res = |
| 1704 | new LDoubleToI(value, |
| 1705 | TempRegister(), |
| 1706 | instr->CanTruncateToInt32() ? TempRegister() : NULL); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1707 | return AssignEnvironment(DefineAsRegister(res)); |
| 1708 | } |
| 1709 | } else if (from.IsInteger32()) { |
| 1710 | if (to.IsTagged()) { |
| 1711 | HValue* val = instr->value(); |
| 1712 | LOperand* value = UseRegister(val); |
| 1713 | if (val->HasRange() && val->range()->IsInSmiRange()) { |
| 1714 | return DefineSameAsFirst(new LSmiTag(value)); |
| 1715 | } else { |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1716 | LNumberTagI* result = new LNumberTagI(value); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1717 | return AssignEnvironment(AssignPointerMap(DefineSameAsFirst(result))); |
| 1718 | } |
| 1719 | } else { |
| 1720 | ASSERT(to.IsDouble()); |
| 1721 | LOperand* value = Use(instr->value()); |
| 1722 | return DefineAsRegister(new LInteger32ToDouble(value)); |
| 1723 | } |
| 1724 | } |
| 1725 | UNREACHABLE(); |
| 1726 | return NULL; |
| 1727 | } |
| 1728 | |
| 1729 | |
| 1730 | LInstruction* LChunkBuilder::DoCheckNonSmi(HCheckNonSmi* instr) { |
| 1731 | LOperand* value = UseRegisterAtStart(instr->value()); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 1732 | return AssignEnvironment(new LCheckNonSmi(value)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1733 | } |
| 1734 | |
| 1735 | |
| 1736 | LInstruction* LChunkBuilder::DoCheckInstanceType(HCheckInstanceType* instr) { |
| 1737 | LOperand* value = UseRegisterAtStart(instr->value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 1738 | LInstruction* result = new LCheckInstanceType(value); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1739 | return AssignEnvironment(result); |
| 1740 | } |
| 1741 | |
| 1742 | |
| 1743 | LInstruction* LChunkBuilder::DoCheckPrototypeMaps(HCheckPrototypeMaps* instr) { |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1744 | LOperand* temp1 = TempRegister(); |
| 1745 | LOperand* temp2 = TempRegister(); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1746 | LInstruction* result = new LCheckPrototypeMaps(temp1, temp2); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1747 | return AssignEnvironment(result); |
| 1748 | } |
| 1749 | |
| 1750 | |
| 1751 | LInstruction* LChunkBuilder::DoCheckSmi(HCheckSmi* instr) { |
| 1752 | LOperand* value = UseRegisterAtStart(instr->value()); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 1753 | return AssignEnvironment(new LCheckSmi(value)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1754 | } |
| 1755 | |
| 1756 | |
| 1757 | LInstruction* LChunkBuilder::DoCheckFunction(HCheckFunction* instr) { |
| 1758 | LOperand* value = UseRegisterAtStart(instr->value()); |
| 1759 | return AssignEnvironment(new LCheckFunction(value)); |
| 1760 | } |
| 1761 | |
| 1762 | |
| 1763 | LInstruction* LChunkBuilder::DoCheckMap(HCheckMap* instr) { |
| 1764 | LOperand* value = UseRegisterAtStart(instr->value()); |
| 1765 | LInstruction* result = new LCheckMap(value); |
| 1766 | return AssignEnvironment(result); |
| 1767 | } |
| 1768 | |
| 1769 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1770 | LInstruction* LChunkBuilder::DoClampToUint8(HClampToUint8* instr) { |
| 1771 | HValue* value = instr->value(); |
| 1772 | Representation input_rep = value->representation(); |
| 1773 | LOperand* reg = UseRegister(value); |
| 1774 | if (input_rep.IsDouble()) { |
| 1775 | return DefineAsRegister(new LClampDToUint8(reg, FixedTemp(d1))); |
| 1776 | } else if (input_rep.IsInteger32()) { |
| 1777 | return DefineAsRegister(new LClampIToUint8(reg)); |
| 1778 | } else { |
| 1779 | ASSERT(input_rep.IsTagged()); |
| 1780 | // Register allocator doesn't (yet) support allocation of double |
| 1781 | // temps. Reserve d1 explicitly. |
| 1782 | LClampTToUint8* result = new LClampTToUint8(reg, FixedTemp(d1)); |
| 1783 | return AssignEnvironment(DefineAsRegister(result)); |
| 1784 | } |
| 1785 | } |
| 1786 | |
| 1787 | |
ricow@chromium.org | c54d365 | 2011-05-30 09:20:16 +0000 | [diff] [blame] | 1788 | LInstruction* LChunkBuilder::DoToInt32(HToInt32* instr) { |
| 1789 | HValue* value = instr->value(); |
| 1790 | Representation input_rep = value->representation(); |
| 1791 | LOperand* reg = UseRegister(value); |
| 1792 | if (input_rep.IsDouble()) { |
| 1793 | LOperand* temp1 = TempRegister(); |
| 1794 | LOperand* temp2 = TempRegister(); |
| 1795 | LDoubleToI* res = new LDoubleToI(reg, temp1, temp2); |
| 1796 | return AssignEnvironment(DefineAsRegister(res)); |
| 1797 | } else if (input_rep.IsInteger32()) { |
| 1798 | // Canonicalization should already have removed the hydrogen instruction in |
| 1799 | // this case, since it is a noop. |
| 1800 | UNREACHABLE(); |
| 1801 | return NULL; |
| 1802 | } else { |
| 1803 | ASSERT(input_rep.IsTagged()); |
| 1804 | LOperand* temp1 = TempRegister(); |
| 1805 | LOperand* temp2 = TempRegister(); |
| 1806 | LOperand* temp3 = FixedTemp(d3); |
| 1807 | LTaggedToI* res = new LTaggedToI(reg, temp1, temp2, temp3); |
| 1808 | return AssignEnvironment(DefineSameAsFirst(res)); |
| 1809 | } |
| 1810 | } |
| 1811 | |
| 1812 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1813 | LInstruction* LChunkBuilder::DoReturn(HReturn* instr) { |
| 1814 | return new LReturn(UseFixed(instr->value(), r0)); |
| 1815 | } |
| 1816 | |
| 1817 | |
| 1818 | LInstruction* LChunkBuilder::DoConstant(HConstant* instr) { |
| 1819 | Representation r = instr->representation(); |
| 1820 | if (r.IsInteger32()) { |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1821 | return DefineAsRegister(new LConstantI); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1822 | } else if (r.IsDouble()) { |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1823 | return DefineAsRegister(new LConstantD); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1824 | } else if (r.IsTagged()) { |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1825 | return DefineAsRegister(new LConstantT); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1826 | } else { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1827 | UNREACHABLE(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1828 | return NULL; |
| 1829 | } |
| 1830 | } |
| 1831 | |
| 1832 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1833 | LInstruction* LChunkBuilder::DoLoadGlobalCell(HLoadGlobalCell* instr) { |
| 1834 | LLoadGlobalCell* result = new LLoadGlobalCell; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1835 | return instr->check_hole_value() |
| 1836 | ? AssignEnvironment(DefineAsRegister(result)) |
| 1837 | : DefineAsRegister(result); |
| 1838 | } |
| 1839 | |
| 1840 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1841 | LInstruction* LChunkBuilder::DoLoadGlobalGeneric(HLoadGlobalGeneric* instr) { |
| 1842 | LOperand* global_object = UseFixed(instr->global_object(), r0); |
| 1843 | LLoadGlobalGeneric* result = new LLoadGlobalGeneric(global_object); |
| 1844 | return MarkAsCall(DefineFixed(result, r0), instr); |
| 1845 | } |
| 1846 | |
| 1847 | |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 1848 | LInstruction* LChunkBuilder::DoStoreGlobalCell(HStoreGlobalCell* instr) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1849 | if (instr->check_hole_value()) { |
| 1850 | LOperand* temp = TempRegister(); |
| 1851 | LOperand* value = UseRegister(instr->value()); |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 1852 | return AssignEnvironment(new LStoreGlobalCell(value, temp)); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1853 | } else { |
| 1854 | LOperand* value = UseRegisterAtStart(instr->value()); |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 1855 | return new LStoreGlobalCell(value, NULL); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1856 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1857 | } |
| 1858 | |
| 1859 | |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 1860 | LInstruction* LChunkBuilder::DoStoreGlobalGeneric(HStoreGlobalGeneric* instr) { |
| 1861 | LOperand* global_object = UseFixed(instr->global_object(), r1); |
| 1862 | LOperand* value = UseFixed(instr->value(), r0); |
| 1863 | LStoreGlobalGeneric* result = |
| 1864 | new LStoreGlobalGeneric(global_object, value); |
| 1865 | return MarkAsCall(result, instr); |
| 1866 | } |
| 1867 | |
| 1868 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1869 | LInstruction* LChunkBuilder::DoLoadContextSlot(HLoadContextSlot* instr) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1870 | LOperand* context = UseRegisterAtStart(instr->value()); |
| 1871 | return DefineAsRegister(new LLoadContextSlot(context)); |
| 1872 | } |
| 1873 | |
| 1874 | |
| 1875 | LInstruction* LChunkBuilder::DoStoreContextSlot(HStoreContextSlot* instr) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1876 | LOperand* context; |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1877 | LOperand* value; |
| 1878 | if (instr->NeedsWriteBarrier()) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1879 | context = UseTempRegister(instr->context()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1880 | value = UseTempRegister(instr->value()); |
| 1881 | } else { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1882 | context = UseRegister(instr->context()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1883 | value = UseRegister(instr->value()); |
| 1884 | } |
| 1885 | return new LStoreContextSlot(context, value); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1886 | } |
| 1887 | |
| 1888 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1889 | LInstruction* LChunkBuilder::DoLoadNamedField(HLoadNamedField* instr) { |
| 1890 | return DefineAsRegister( |
| 1891 | new LLoadNamedField(UseRegisterAtStart(instr->object()))); |
| 1892 | } |
| 1893 | |
| 1894 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1895 | LInstruction* LChunkBuilder::DoLoadNamedFieldPolymorphic( |
| 1896 | HLoadNamedFieldPolymorphic* instr) { |
| 1897 | ASSERT(instr->representation().IsTagged()); |
| 1898 | if (instr->need_generic()) { |
| 1899 | LOperand* obj = UseFixed(instr->object(), r0); |
| 1900 | LLoadNamedFieldPolymorphic* result = new LLoadNamedFieldPolymorphic(obj); |
| 1901 | return MarkAsCall(DefineFixed(result, r0), instr); |
| 1902 | } else { |
| 1903 | LOperand* obj = UseRegisterAtStart(instr->object()); |
| 1904 | LLoadNamedFieldPolymorphic* result = new LLoadNamedFieldPolymorphic(obj); |
| 1905 | return AssignEnvironment(DefineAsRegister(result)); |
| 1906 | } |
| 1907 | } |
| 1908 | |
| 1909 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1910 | LInstruction* LChunkBuilder::DoLoadNamedGeneric(HLoadNamedGeneric* instr) { |
| 1911 | LOperand* object = UseFixed(instr->object(), r0); |
| 1912 | LInstruction* result = DefineFixed(new LLoadNamedGeneric(object), r0); |
| 1913 | return MarkAsCall(result, instr); |
| 1914 | } |
| 1915 | |
| 1916 | |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 1917 | LInstruction* LChunkBuilder::DoLoadFunctionPrototype( |
| 1918 | HLoadFunctionPrototype* instr) { |
| 1919 | return AssignEnvironment(DefineAsRegister( |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 1920 | new LLoadFunctionPrototype(UseRegister(instr->function())))); |
fschneider@chromium.org | 9e3e0b6 | 2011-01-03 10:16:46 +0000 | [diff] [blame] | 1921 | } |
| 1922 | |
| 1923 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1924 | LInstruction* LChunkBuilder::DoLoadElements(HLoadElements* instr) { |
| 1925 | LOperand* input = UseRegisterAtStart(instr->value()); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 1926 | return DefineAsRegister(new LLoadElements(input)); |
| 1927 | } |
| 1928 | |
| 1929 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 1930 | LInstruction* LChunkBuilder::DoLoadExternalArrayPointer( |
| 1931 | HLoadExternalArrayPointer* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 1932 | LOperand* input = UseRegisterAtStart(instr->value()); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 1933 | return DefineAsRegister(new LLoadExternalArrayPointer(input)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1934 | } |
| 1935 | |
| 1936 | |
| 1937 | LInstruction* LChunkBuilder::DoLoadKeyedFastElement( |
| 1938 | HLoadKeyedFastElement* instr) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1939 | ASSERT(instr->representation().IsTagged()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1940 | ASSERT(instr->key()->representation().IsInteger32()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1941 | LOperand* obj = UseRegisterAtStart(instr->object()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1942 | LOperand* key = UseRegisterAtStart(instr->key()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1943 | LLoadKeyedFastElement* result = new LLoadKeyedFastElement(obj, key); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1944 | return AssignEnvironment(DefineSameAsFirst(result)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1945 | } |
| 1946 | |
| 1947 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1948 | LInstruction* LChunkBuilder::DoLoadKeyedSpecializedArrayElement( |
| 1949 | HLoadKeyedSpecializedArrayElement* instr) { |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1950 | ExternalArrayType array_type = instr->array_type(); |
| 1951 | Representation representation(instr->representation()); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 1952 | ASSERT( |
| 1953 | (representation.IsInteger32() && (array_type != kExternalFloatArray && |
| 1954 | array_type != kExternalDoubleArray)) || |
| 1955 | (representation.IsDouble() && (array_type == kExternalFloatArray || |
| 1956 | array_type == kExternalDoubleArray))); |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 1957 | ASSERT(instr->key()->representation().IsInteger32()); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1958 | LOperand* external_pointer = UseRegister(instr->external_pointer()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1959 | LOperand* key = UseRegisterOrConstant(instr->key()); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1960 | LLoadKeyedSpecializedArrayElement* result = |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 1961 | new LLoadKeyedSpecializedArrayElement(external_pointer, key); |
| 1962 | LInstruction* load_instr = DefineAsRegister(result); |
| 1963 | // An unsigned int array load might overflow and cause a deopt, make sure it |
| 1964 | // has an environment. |
| 1965 | return (array_type == kExternalUnsignedIntArray) ? |
| 1966 | AssignEnvironment(load_instr) : load_instr; |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 1967 | } |
| 1968 | |
| 1969 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1970 | LInstruction* LChunkBuilder::DoLoadKeyedGeneric(HLoadKeyedGeneric* instr) { |
| 1971 | LOperand* object = UseFixed(instr->object(), r1); |
| 1972 | LOperand* key = UseFixed(instr->key(), r0); |
| 1973 | |
| 1974 | LInstruction* result = |
| 1975 | DefineFixed(new LLoadKeyedGeneric(object, key), r0); |
| 1976 | return MarkAsCall(result, instr); |
| 1977 | } |
| 1978 | |
| 1979 | |
| 1980 | LInstruction* LChunkBuilder::DoStoreKeyedFastElement( |
| 1981 | HStoreKeyedFastElement* instr) { |
| 1982 | bool needs_write_barrier = instr->NeedsWriteBarrier(); |
| 1983 | ASSERT(instr->value()->representation().IsTagged()); |
| 1984 | ASSERT(instr->object()->representation().IsTagged()); |
| 1985 | ASSERT(instr->key()->representation().IsInteger32()); |
| 1986 | |
| 1987 | LOperand* obj = UseTempRegister(instr->object()); |
| 1988 | LOperand* val = needs_write_barrier |
| 1989 | ? UseTempRegister(instr->value()) |
| 1990 | : UseRegisterAtStart(instr->value()); |
| 1991 | LOperand* key = needs_write_barrier |
| 1992 | ? UseTempRegister(instr->key()) |
| 1993 | : UseRegisterOrConstantAtStart(instr->key()); |
| 1994 | |
| 1995 | return AssignEnvironment(new LStoreKeyedFastElement(obj, key, val)); |
| 1996 | } |
| 1997 | |
| 1998 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1999 | LInstruction* LChunkBuilder::DoStoreKeyedSpecializedArrayElement( |
| 2000 | HStoreKeyedSpecializedArrayElement* instr) { |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2001 | Representation representation(instr->value()->representation()); |
| 2002 | ExternalArrayType array_type = instr->array_type(); |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 2003 | ASSERT( |
| 2004 | (representation.IsInteger32() && (array_type != kExternalFloatArray && |
| 2005 | array_type != kExternalDoubleArray)) || |
| 2006 | (representation.IsDouble() && (array_type == kExternalFloatArray || |
| 2007 | array_type == kExternalDoubleArray))); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 2008 | ASSERT(instr->external_pointer()->representation().IsExternal()); |
| 2009 | ASSERT(instr->key()->representation().IsInteger32()); |
| 2010 | |
| 2011 | LOperand* external_pointer = UseRegister(instr->external_pointer()); |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2012 | bool val_is_temp_register = array_type == kExternalPixelArray || |
| 2013 | array_type == kExternalFloatArray; |
| 2014 | LOperand* val = val_is_temp_register |
| 2015 | ? UseTempRegister(instr->value()) |
| 2016 | : UseRegister(instr->value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2017 | LOperand* key = UseRegisterOrConstant(instr->key()); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 2018 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2019 | return new LStoreKeyedSpecializedArrayElement(external_pointer, |
| 2020 | key, |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 2021 | val); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2022 | } |
| 2023 | |
| 2024 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2025 | LInstruction* LChunkBuilder::DoStoreKeyedGeneric(HStoreKeyedGeneric* instr) { |
| 2026 | LOperand* obj = UseFixed(instr->object(), r2); |
| 2027 | LOperand* key = UseFixed(instr->key(), r1); |
| 2028 | LOperand* val = UseFixed(instr->value(), r0); |
| 2029 | |
| 2030 | ASSERT(instr->object()->representation().IsTagged()); |
| 2031 | ASSERT(instr->key()->representation().IsTagged()); |
| 2032 | ASSERT(instr->value()->representation().IsTagged()); |
| 2033 | |
| 2034 | return MarkAsCall(new LStoreKeyedGeneric(obj, key, val), instr); |
| 2035 | } |
| 2036 | |
| 2037 | |
| 2038 | LInstruction* LChunkBuilder::DoStoreNamedField(HStoreNamedField* instr) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2039 | bool needs_write_barrier = instr->NeedsWriteBarrier(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2040 | |
| 2041 | LOperand* obj = needs_write_barrier |
| 2042 | ? UseTempRegister(instr->object()) |
| 2043 | : UseRegisterAtStart(instr->object()); |
| 2044 | |
| 2045 | LOperand* val = needs_write_barrier |
| 2046 | ? UseTempRegister(instr->value()) |
| 2047 | : UseRegister(instr->value()); |
| 2048 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2049 | return new LStoreNamedField(obj, val); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2050 | } |
| 2051 | |
| 2052 | |
| 2053 | LInstruction* LChunkBuilder::DoStoreNamedGeneric(HStoreNamedGeneric* instr) { |
| 2054 | LOperand* obj = UseFixed(instr->object(), r1); |
| 2055 | LOperand* val = UseFixed(instr->value(), r0); |
| 2056 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2057 | LInstruction* result = new LStoreNamedGeneric(obj, val); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2058 | return MarkAsCall(result, instr); |
| 2059 | } |
| 2060 | |
| 2061 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 2062 | LInstruction* LChunkBuilder::DoStringAdd(HStringAdd* instr) { |
| 2063 | LOperand* left = UseRegisterAtStart(instr->left()); |
| 2064 | LOperand* right = UseRegisterAtStart(instr->right()); |
| 2065 | return MarkAsCall(DefineFixed(new LStringAdd(left, right), r0), instr); |
| 2066 | } |
| 2067 | |
| 2068 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2069 | LInstruction* LChunkBuilder::DoStringCharCodeAt(HStringCharCodeAt* instr) { |
| 2070 | LOperand* string = UseRegister(instr->string()); |
| 2071 | LOperand* index = UseRegisterOrConstant(instr->index()); |
| 2072 | LStringCharCodeAt* result = new LStringCharCodeAt(string, index); |
| 2073 | return AssignEnvironment(AssignPointerMap(DefineAsRegister(result))); |
| 2074 | } |
| 2075 | |
| 2076 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 2077 | LInstruction* LChunkBuilder::DoStringCharFromCode(HStringCharFromCode* instr) { |
| 2078 | LOperand* char_code = UseRegister(instr->value()); |
| 2079 | LStringCharFromCode* result = new LStringCharFromCode(char_code); |
| 2080 | return AssignPointerMap(DefineAsRegister(result)); |
| 2081 | } |
| 2082 | |
| 2083 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2084 | LInstruction* LChunkBuilder::DoStringLength(HStringLength* instr) { |
| 2085 | LOperand* string = UseRegisterAtStart(instr->value()); |
| 2086 | return DefineAsRegister(new LStringLength(string)); |
| 2087 | } |
| 2088 | |
| 2089 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2090 | LInstruction* LChunkBuilder::DoArrayLiteral(HArrayLiteral* instr) { |
| 2091 | return MarkAsCall(DefineFixed(new LArrayLiteral, r0), instr); |
| 2092 | } |
| 2093 | |
| 2094 | |
| 2095 | LInstruction* LChunkBuilder::DoObjectLiteral(HObjectLiteral* instr) { |
| 2096 | return MarkAsCall(DefineFixed(new LObjectLiteral, r0), instr); |
| 2097 | } |
| 2098 | |
| 2099 | |
| 2100 | LInstruction* LChunkBuilder::DoRegExpLiteral(HRegExpLiteral* instr) { |
| 2101 | return MarkAsCall(DefineFixed(new LRegExpLiteral, r0), instr); |
| 2102 | } |
| 2103 | |
| 2104 | |
| 2105 | LInstruction* LChunkBuilder::DoFunctionLiteral(HFunctionLiteral* instr) { |
| 2106 | return MarkAsCall(DefineFixed(new LFunctionLiteral, r0), instr); |
| 2107 | } |
| 2108 | |
| 2109 | |
| 2110 | LInstruction* LChunkBuilder::DoDeleteProperty(HDeleteProperty* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2111 | LOperand* object = UseFixed(instr->object(), r0); |
| 2112 | LOperand* key = UseFixed(instr->key(), r1); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2113 | LDeleteProperty* result = new LDeleteProperty(object, key); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2114 | return MarkAsCall(DefineFixed(result, r0), instr); |
| 2115 | } |
| 2116 | |
| 2117 | |
| 2118 | LInstruction* LChunkBuilder::DoOsrEntry(HOsrEntry* instr) { |
| 2119 | allocator_->MarkAsOsrEntry(); |
| 2120 | current_block_->last_environment()->set_ast_id(instr->ast_id()); |
| 2121 | return AssignEnvironment(new LOsrEntry); |
| 2122 | } |
| 2123 | |
| 2124 | |
| 2125 | LInstruction* LChunkBuilder::DoParameter(HParameter* instr) { |
| 2126 | int spill_index = chunk()->GetParameterStackSlot(instr->index()); |
| 2127 | return DefineAsSpilled(new LParameter, spill_index); |
| 2128 | } |
| 2129 | |
| 2130 | |
| 2131 | LInstruction* LChunkBuilder::DoUnknownOSRValue(HUnknownOSRValue* instr) { |
| 2132 | int spill_index = chunk()->GetNextSpillIndex(false); // Not double-width. |
| 2133 | return DefineAsSpilled(new LUnknownOSRValue, spill_index); |
| 2134 | } |
| 2135 | |
| 2136 | |
| 2137 | LInstruction* LChunkBuilder::DoCallStub(HCallStub* instr) { |
| 2138 | argument_count_ -= instr->argument_count(); |
| 2139 | return MarkAsCall(DefineFixed(new LCallStub, r0), instr); |
| 2140 | } |
| 2141 | |
| 2142 | |
| 2143 | LInstruction* LChunkBuilder::DoArgumentsObject(HArgumentsObject* instr) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2144 | // There are no real uses of the arguments object. |
| 2145 | // arguments.length and element access are supported directly on |
| 2146 | // stack arguments, and any real arguments object use causes a bailout. |
| 2147 | // So this value is never used. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2148 | return NULL; |
| 2149 | } |
| 2150 | |
| 2151 | |
| 2152 | LInstruction* LChunkBuilder::DoAccessArgumentsAt(HAccessArgumentsAt* instr) { |
| 2153 | LOperand* arguments = UseRegister(instr->arguments()); |
| 2154 | LOperand* length = UseTempRegister(instr->length()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2155 | LOperand* index = UseRegister(instr->index()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2156 | LAccessArgumentsAt* result = new LAccessArgumentsAt(arguments, length, index); |
| 2157 | return AssignEnvironment(DefineAsRegister(result)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2158 | } |
| 2159 | |
| 2160 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2161 | LInstruction* LChunkBuilder::DoToFastProperties(HToFastProperties* instr) { |
| 2162 | LOperand* object = UseFixed(instr->value(), r0); |
| 2163 | LToFastProperties* result = new LToFastProperties(object); |
| 2164 | return MarkAsCall(DefineFixed(result, r0), instr); |
| 2165 | } |
| 2166 | |
| 2167 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2168 | LInstruction* LChunkBuilder::DoTypeof(HTypeof* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2169 | LTypeof* result = new LTypeof(UseFixed(instr->value(), r0)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2170 | return MarkAsCall(DefineFixed(result, r0), instr); |
| 2171 | } |
| 2172 | |
| 2173 | |
| 2174 | LInstruction* LChunkBuilder::DoTypeofIs(HTypeofIs* instr) { |
| 2175 | return DefineSameAsFirst(new LTypeofIs(UseRegister(instr->value()))); |
| 2176 | } |
| 2177 | |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 2178 | |
| 2179 | LInstruction* LChunkBuilder::DoIsConstructCall(HIsConstructCall* instr) { |
| 2180 | return DefineAsRegister(new LIsConstructCall()); |
| 2181 | } |
| 2182 | |
| 2183 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2184 | LInstruction* LChunkBuilder::DoSimulate(HSimulate* instr) { |
| 2185 | HEnvironment* env = current_block_->last_environment(); |
| 2186 | ASSERT(env != NULL); |
| 2187 | |
| 2188 | env->set_ast_id(instr->ast_id()); |
| 2189 | |
| 2190 | env->Drop(instr->pop_count()); |
| 2191 | for (int i = 0; i < instr->values()->length(); ++i) { |
| 2192 | HValue* value = instr->values()->at(i); |
| 2193 | if (instr->HasAssignedIndexAt(i)) { |
| 2194 | env->Bind(instr->GetAssignedIndexAt(i), value); |
| 2195 | } else { |
| 2196 | env->Push(value); |
| 2197 | } |
| 2198 | } |
| 2199 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2200 | // If there is an instruction pending deoptimization environment create a |
| 2201 | // lazy bailout instruction to capture the environment. |
fschneider@chromium.org | 1df6b47 | 2011-01-26 08:23:03 +0000 | [diff] [blame] | 2202 | if (pending_deoptimization_ast_id_ == instr->ast_id()) { |
| 2203 | LInstruction* result = new LLazyBailout; |
| 2204 | result = AssignEnvironment(result); |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2205 | instruction_pending_deoptimization_environment_-> |
fschneider@chromium.org | 1df6b47 | 2011-01-26 08:23:03 +0000 | [diff] [blame] | 2206 | set_deoptimization_environment(result->environment()); |
| 2207 | ClearInstructionPendingDeoptimizationEnvironment(); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2208 | return result; |
| 2209 | } |
| 2210 | |
| 2211 | return NULL; |
| 2212 | } |
| 2213 | |
| 2214 | |
| 2215 | LInstruction* LChunkBuilder::DoStackCheck(HStackCheck* instr) { |
| 2216 | return MarkAsCall(new LStackCheck, instr); |
| 2217 | } |
| 2218 | |
| 2219 | |
| 2220 | LInstruction* LChunkBuilder::DoEnterInlined(HEnterInlined* instr) { |
| 2221 | HEnvironment* outer = current_block_->last_environment(); |
| 2222 | HConstant* undefined = graph()->GetConstantUndefined(); |
| 2223 | HEnvironment* inner = outer->CopyForInlining(instr->closure(), |
| 2224 | instr->function(), |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 2225 | HEnvironment::LITHIUM, |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2226 | undefined, |
| 2227 | instr->call_kind()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2228 | current_block_->UpdateEnvironment(inner); |
| 2229 | chunk_->AddInlinedClosure(instr->closure()); |
| 2230 | return NULL; |
| 2231 | } |
| 2232 | |
| 2233 | |
| 2234 | LInstruction* LChunkBuilder::DoLeaveInlined(HLeaveInlined* instr) { |
| 2235 | HEnvironment* outer = current_block_->last_environment()->outer(); |
| 2236 | current_block_->UpdateEnvironment(outer); |
| 2237 | return NULL; |
| 2238 | } |
| 2239 | |
| 2240 | |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 2241 | LInstruction* LChunkBuilder::DoIn(HIn* instr) { |
| 2242 | LOperand* key = UseRegisterAtStart(instr->key()); |
| 2243 | LOperand* object = UseRegisterAtStart(instr->object()); |
| 2244 | LIn* result = new LIn(key, object); |
| 2245 | return MarkAsCall(DefineFixed(result, r0), instr); |
| 2246 | } |
| 2247 | |
| 2248 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2249 | } } // namespace v8::internal |