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