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