erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 28 | #include "v8.h" |
| 29 | |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 30 | #if V8_TARGET_ARCH_X64 |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 31 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 32 | #include "lithium-allocator-inl.h" |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 33 | #include "x64/lithium-x64.h" |
| 34 | #include "x64/lithium-codegen-x64.h" |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 35 | #include "hydrogen-osr.h" |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 36 | |
| 37 | namespace v8 { |
| 38 | namespace internal { |
| 39 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 40 | #define DEFINE_COMPILE(type) \ |
| 41 | void L##type::CompileToNative(LCodeGen* generator) { \ |
| 42 | generator->Do##type(this); \ |
| 43 | } |
| 44 | LITHIUM_CONCRETE_INSTRUCTION_LIST(DEFINE_COMPILE) |
| 45 | #undef DEFINE_COMPILE |
| 46 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 47 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 48 | #ifdef DEBUG |
| 49 | void LInstruction::VerifyCall() { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 50 | // Call instructions can use only fixed registers as temporaries and |
| 51 | // outputs because all registers are blocked by the calling convention. |
| 52 | // Inputs operands must use a fixed register or use-at-start policy or |
| 53 | // a non-register policy. |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 54 | ASSERT(Output() == NULL || |
| 55 | LUnallocated::cast(Output())->HasFixedPolicy() || |
| 56 | !LUnallocated::cast(Output())->HasRegisterPolicy()); |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 57 | for (UseIterator it(this); !it.Done(); it.Advance()) { |
| 58 | LUnallocated* operand = LUnallocated::cast(it.Current()); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 59 | ASSERT(operand->HasFixedPolicy() || |
| 60 | operand->IsUsedAtStart()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 61 | } |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 62 | for (TempIterator it(this); !it.Done(); it.Advance()) { |
| 63 | LUnallocated* operand = LUnallocated::cast(it.Current()); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 64 | ASSERT(operand->HasFixedPolicy() ||!operand->HasRegisterPolicy()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 65 | } |
| 66 | } |
| 67 | #endif |
| 68 | |
| 69 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 70 | void LInstruction::PrintTo(StringStream* stream) { |
| 71 | stream->Add("%s ", this->Mnemonic()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 72 | |
| 73 | PrintOutputOperandTo(stream); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 74 | |
| 75 | PrintDataTo(stream); |
| 76 | |
| 77 | if (HasEnvironment()) { |
| 78 | stream->Add(" "); |
| 79 | environment()->PrintTo(stream); |
| 80 | } |
| 81 | |
| 82 | if (HasPointerMap()) { |
| 83 | stream->Add(" "); |
| 84 | pointer_map()->PrintTo(stream); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | |
mstarzinger@chromium.org | 88d326b | 2012-04-23 12:57:22 +0000 | [diff] [blame] | 89 | void LInstruction::PrintDataTo(StringStream* stream) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 90 | stream->Add("= "); |
mstarzinger@chromium.org | 88d326b | 2012-04-23 12:57:22 +0000 | [diff] [blame] | 91 | for (int i = 0; i < InputCount(); i++) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 92 | if (i > 0) stream->Add(" "); |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 93 | if (InputAt(i) == NULL) { |
| 94 | stream->Add("NULL"); |
| 95 | } else { |
| 96 | InputAt(i)->PrintTo(stream); |
| 97 | } |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 98 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | |
mstarzinger@chromium.org | 88d326b | 2012-04-23 12:57:22 +0000 | [diff] [blame] | 102 | void LInstruction::PrintOutputOperandTo(StringStream* stream) { |
| 103 | if (HasResult()) result()->PrintTo(stream); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | |
| 107 | void LLabel::PrintDataTo(StringStream* stream) { |
| 108 | LGap::PrintDataTo(stream); |
| 109 | LLabel* rep = replacement(); |
| 110 | if (rep != NULL) { |
| 111 | stream->Add(" Dead block replaced with B%d", rep->block_id()); |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | |
| 116 | bool LGap::IsRedundant() const { |
| 117 | for (int i = 0; i < 4; i++) { |
| 118 | if (parallel_moves_[i] != NULL && !parallel_moves_[i]->IsRedundant()) { |
| 119 | return false; |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | return true; |
| 124 | } |
| 125 | |
| 126 | |
| 127 | void LGap::PrintDataTo(StringStream* stream) { |
| 128 | for (int i = 0; i < 4; i++) { |
| 129 | stream->Add("("); |
| 130 | if (parallel_moves_[i] != NULL) { |
| 131 | parallel_moves_[i]->PrintDataTo(stream); |
| 132 | } |
| 133 | stream->Add(") "); |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | |
| 138 | const char* LArithmeticD::Mnemonic() const { |
| 139 | switch (op()) { |
| 140 | case Token::ADD: return "add-d"; |
| 141 | case Token::SUB: return "sub-d"; |
| 142 | case Token::MUL: return "mul-d"; |
| 143 | case Token::DIV: return "div-d"; |
| 144 | case Token::MOD: return "mod-d"; |
| 145 | default: |
| 146 | UNREACHABLE(); |
| 147 | return NULL; |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | |
| 152 | const char* LArithmeticT::Mnemonic() const { |
| 153 | switch (op()) { |
| 154 | case Token::ADD: return "add-t"; |
| 155 | case Token::SUB: return "sub-t"; |
| 156 | case Token::MUL: return "mul-t"; |
| 157 | case Token::MOD: return "mod-t"; |
| 158 | case Token::DIV: return "div-t"; |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 159 | case Token::BIT_AND: return "bit-and-t"; |
| 160 | case Token::BIT_OR: return "bit-or-t"; |
| 161 | case Token::BIT_XOR: return "bit-xor-t"; |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 162 | case Token::ROR: return "ror-t"; |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 163 | case Token::SHL: return "sal-t"; |
| 164 | case Token::SAR: return "sar-t"; |
| 165 | case Token::SHR: return "shr-t"; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 166 | default: |
| 167 | UNREACHABLE(); |
| 168 | return NULL; |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 173 | bool LGoto::HasInterestingComment(LCodeGen* gen) const { |
| 174 | return !gen->IsNextEmittedBlock(block_id()); |
| 175 | } |
| 176 | |
| 177 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 178 | void LGoto::PrintDataTo(StringStream* stream) { |
| 179 | stream->Add("B%d", block_id()); |
| 180 | } |
| 181 | |
| 182 | |
| 183 | void LBranch::PrintDataTo(StringStream* stream) { |
| 184 | stream->Add("B%d | B%d on ", true_block_id(), false_block_id()); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 185 | value()->PrintTo(stream); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 189 | void LCompareNumericAndBranch::PrintDataTo(StringStream* stream) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 190 | stream->Add("if "); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 191 | left()->PrintTo(stream); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 192 | stream->Add(" %s ", Token::String(op())); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 193 | right()->PrintTo(stream); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 194 | stream->Add(" then B%d else B%d", true_block_id(), false_block_id()); |
| 195 | } |
| 196 | |
| 197 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 198 | void LIsObjectAndBranch::PrintDataTo(StringStream* stream) { |
| 199 | stream->Add("if is_object("); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 200 | value()->PrintTo(stream); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 201 | stream->Add(") then B%d else B%d", true_block_id(), false_block_id()); |
| 202 | } |
| 203 | |
| 204 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 205 | void LIsStringAndBranch::PrintDataTo(StringStream* stream) { |
| 206 | stream->Add("if is_string("); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 207 | value()->PrintTo(stream); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 208 | stream->Add(") then B%d else B%d", true_block_id(), false_block_id()); |
| 209 | } |
| 210 | |
| 211 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 212 | void LIsSmiAndBranch::PrintDataTo(StringStream* stream) { |
| 213 | stream->Add("if is_smi("); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 214 | value()->PrintTo(stream); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 215 | stream->Add(") then B%d else B%d", true_block_id(), false_block_id()); |
| 216 | } |
| 217 | |
| 218 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 219 | void LIsUndetectableAndBranch::PrintDataTo(StringStream* stream) { |
| 220 | stream->Add("if is_undetectable("); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 221 | value()->PrintTo(stream); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 222 | stream->Add(") then B%d else B%d", true_block_id(), false_block_id()); |
| 223 | } |
| 224 | |
| 225 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 226 | void LStringCompareAndBranch::PrintDataTo(StringStream* stream) { |
| 227 | stream->Add("if string_compare("); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 228 | left()->PrintTo(stream); |
| 229 | right()->PrintTo(stream); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 230 | stream->Add(") then B%d else B%d", true_block_id(), false_block_id()); |
| 231 | } |
| 232 | |
| 233 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 234 | void LHasInstanceTypeAndBranch::PrintDataTo(StringStream* stream) { |
| 235 | stream->Add("if has_instance_type("); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 236 | value()->PrintTo(stream); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 237 | stream->Add(") then B%d else B%d", true_block_id(), false_block_id()); |
| 238 | } |
| 239 | |
| 240 | |
| 241 | void LHasCachedArrayIndexAndBranch::PrintDataTo(StringStream* stream) { |
| 242 | stream->Add("if has_cached_array_index("); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 243 | value()->PrintTo(stream); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 244 | stream->Add(") then B%d else B%d", true_block_id(), false_block_id()); |
| 245 | } |
| 246 | |
| 247 | |
| 248 | void LClassOfTestAndBranch::PrintDataTo(StringStream* stream) { |
| 249 | stream->Add("if class_of_test("); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 250 | value()->PrintTo(stream); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 251 | stream->Add(", \"%o\") then B%d else B%d", |
| 252 | *hydrogen()->class_name(), |
| 253 | true_block_id(), |
| 254 | false_block_id()); |
| 255 | } |
| 256 | |
| 257 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 258 | void LTypeofIsAndBranch::PrintDataTo(StringStream* stream) { |
| 259 | stream->Add("if typeof "); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 260 | value()->PrintTo(stream); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 261 | stream->Add(" == \"%s\" then B%d else B%d", |
| 262 | *hydrogen()->type_literal()->ToCString(), |
| 263 | true_block_id(), false_block_id()); |
| 264 | } |
| 265 | |
| 266 | |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 267 | void LStoreCodeEntry::PrintDataTo(StringStream* stream) { |
| 268 | stream->Add(" = "); |
| 269 | function()->PrintTo(stream); |
| 270 | stream->Add(".code_entry = "); |
| 271 | code_object()->PrintTo(stream); |
| 272 | } |
| 273 | |
| 274 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 275 | void LInnerAllocatedObject::PrintDataTo(StringStream* stream) { |
| 276 | stream->Add(" = "); |
| 277 | base_object()->PrintTo(stream); |
| 278 | stream->Add(" + %d", offset()); |
| 279 | } |
| 280 | |
| 281 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 282 | void LCallConstantFunction::PrintDataTo(StringStream* stream) { |
| 283 | stream->Add("#%d / ", arity()); |
| 284 | } |
| 285 | |
| 286 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 287 | void LLoadContextSlot::PrintDataTo(StringStream* stream) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 288 | context()->PrintTo(stream); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 289 | stream->Add("[%d]", slot_index()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 293 | void LStoreContextSlot::PrintDataTo(StringStream* stream) { |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 294 | context()->PrintTo(stream); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 295 | stream->Add("[%d] <- ", slot_index()); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 296 | value()->PrintTo(stream); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 300 | void LInvokeFunction::PrintDataTo(StringStream* stream) { |
| 301 | stream->Add("= "); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 302 | function()->PrintTo(stream); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 303 | stream->Add(" #%d / ", arity()); |
| 304 | } |
| 305 | |
| 306 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 307 | void LCallKeyed::PrintDataTo(StringStream* stream) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 308 | stream->Add("[rcx] #%d / ", arity()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | |
| 312 | void LCallNamed::PrintDataTo(StringStream* stream) { |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 313 | SmartArrayPointer<char> name_string = name()->ToCString(); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 314 | stream->Add("%s #%d / ", *name_string, arity()); |
| 315 | } |
| 316 | |
| 317 | |
| 318 | void LCallGlobal::PrintDataTo(StringStream* stream) { |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 319 | SmartArrayPointer<char> name_string = name()->ToCString(); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 320 | stream->Add("%s #%d / ", *name_string, arity()); |
| 321 | } |
| 322 | |
| 323 | |
| 324 | void LCallKnownGlobal::PrintDataTo(StringStream* stream) { |
| 325 | stream->Add("#%d / ", arity()); |
| 326 | } |
| 327 | |
| 328 | |
| 329 | void LCallNew::PrintDataTo(StringStream* stream) { |
| 330 | stream->Add("= "); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 331 | constructor()->PrintTo(stream); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 332 | stream->Add(" #%d / ", arity()); |
| 333 | } |
| 334 | |
| 335 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 336 | void LCallNewArray::PrintDataTo(StringStream* stream) { |
| 337 | stream->Add("= "); |
| 338 | constructor()->PrintTo(stream); |
| 339 | stream->Add(" #%d / ", arity()); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 340 | ElementsKind kind = hydrogen()->elements_kind(); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 341 | stream->Add(" (%s) ", ElementsKindToString(kind)); |
| 342 | } |
| 343 | |
| 344 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 345 | void LAccessArgumentsAt::PrintDataTo(StringStream* stream) { |
| 346 | arguments()->PrintTo(stream); |
| 347 | |
| 348 | stream->Add(" length "); |
| 349 | length()->PrintTo(stream); |
| 350 | |
| 351 | stream->Add(" index "); |
| 352 | index()->PrintTo(stream); |
| 353 | } |
| 354 | |
| 355 | |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 356 | int LPlatformChunk::GetNextSpillIndex(RegisterKind kind) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 357 | return spill_slot_count_++; |
| 358 | } |
| 359 | |
| 360 | |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 361 | LOperand* LPlatformChunk::GetNextSpillSlot(RegisterKind kind) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 362 | // All stack slots are Double stack slots on x64. |
| 363 | // Alternatively, at some point, start using half-size |
| 364 | // stack slots for int32 values. |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 365 | int index = GetNextSpillIndex(kind); |
| 366 | if (kind == DOUBLE_REGISTERS) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 367 | return LDoubleStackSlot::Create(index, zone()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 368 | } else { |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 369 | ASSERT(kind == GENERAL_REGISTERS); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 370 | return LStackSlot::Create(index, zone()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 371 | } |
| 372 | } |
| 373 | |
| 374 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 375 | void LStoreNamedField::PrintDataTo(StringStream* stream) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 376 | object()->PrintTo(stream); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 377 | hydrogen()->access().PrintTo(stream); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 378 | stream->Add(" <- "); |
| 379 | value()->PrintTo(stream); |
| 380 | } |
| 381 | |
| 382 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 383 | void LStoreNamedGeneric::PrintDataTo(StringStream* stream) { |
| 384 | object()->PrintTo(stream); |
| 385 | stream->Add("."); |
| 386 | stream->Add(*String::cast(*name())->ToCString()); |
| 387 | stream->Add(" <- "); |
| 388 | value()->PrintTo(stream); |
| 389 | } |
| 390 | |
| 391 | |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 392 | void LLoadKeyed::PrintDataTo(StringStream* stream) { |
| 393 | elements()->PrintTo(stream); |
| 394 | stream->Add("["); |
| 395 | key()->PrintTo(stream); |
| 396 | if (hydrogen()->IsDehoisted()) { |
| 397 | stream->Add(" + %d]", additional_index()); |
| 398 | } else { |
| 399 | stream->Add("]"); |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 404 | void LStoreKeyed::PrintDataTo(StringStream* stream) { |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 405 | elements()->PrintTo(stream); |
| 406 | stream->Add("["); |
| 407 | key()->PrintTo(stream); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 408 | if (hydrogen()->IsDehoisted()) { |
| 409 | stream->Add(" + %d] <-", additional_index()); |
| 410 | } else { |
| 411 | stream->Add("] <- "); |
| 412 | } |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 413 | |
| 414 | if (value() == NULL) { |
| 415 | ASSERT(hydrogen()->IsConstantHoleStore() && |
| 416 | hydrogen()->value()->representation().IsDouble()); |
| 417 | stream->Add("<the hole(nan)>"); |
| 418 | } else { |
| 419 | value()->PrintTo(stream); |
| 420 | } |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 424 | void LStoreKeyedGeneric::PrintDataTo(StringStream* stream) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 425 | object()->PrintTo(stream); |
| 426 | stream->Add("["); |
| 427 | key()->PrintTo(stream); |
| 428 | stream->Add("] <- "); |
| 429 | value()->PrintTo(stream); |
| 430 | } |
| 431 | |
| 432 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 433 | void LTransitionElementsKind::PrintDataTo(StringStream* stream) { |
| 434 | object()->PrintTo(stream); |
| 435 | stream->Add(" %p -> %p", *original_map(), *transitioned_map()); |
| 436 | } |
| 437 | |
| 438 | |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 439 | LPlatformChunk* LChunkBuilder::Build() { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 440 | ASSERT(is_unused()); |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame] | 441 | chunk_ = new(zone()) LPlatformChunk(info(), graph()); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 442 | LPhase phase("L_Building chunk", chunk_); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 443 | status_ = BUILDING; |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 444 | |
| 445 | // If compiling for OSR, reserve space for the unoptimized frame, |
| 446 | // which will be subsumed into this frame. |
| 447 | if (graph()->has_osr()) { |
| 448 | for (int i = graph()->osr()->UnoptimizedFrameSlots(); i > 0; i--) { |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 449 | chunk_->GetNextSpillIndex(GENERAL_REGISTERS); |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 450 | } |
| 451 | } |
| 452 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 453 | const ZoneList<HBasicBlock*>* blocks = graph()->blocks(); |
| 454 | for (int i = 0; i < blocks->length(); i++) { |
| 455 | HBasicBlock* next = NULL; |
| 456 | if (i < blocks->length() - 1) next = blocks->at(i + 1); |
| 457 | DoBasicBlock(blocks->at(i), next); |
| 458 | if (is_aborted()) return NULL; |
| 459 | } |
| 460 | status_ = DONE; |
| 461 | return chunk_; |
| 462 | } |
| 463 | |
| 464 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 465 | void LCodeGen::Abort(BailoutReason reason) { |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 466 | info()->set_bailout_reason(reason); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 467 | status_ = ABORTED; |
| 468 | } |
| 469 | |
| 470 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 471 | LUnallocated* LChunkBuilder::ToUnallocated(Register reg) { |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 472 | return new(zone()) LUnallocated(LUnallocated::FIXED_REGISTER, |
| 473 | Register::ToAllocationIndex(reg)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | |
| 477 | LUnallocated* LChunkBuilder::ToUnallocated(XMMRegister reg) { |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 478 | return new(zone()) LUnallocated(LUnallocated::FIXED_DOUBLE_REGISTER, |
| 479 | XMMRegister::ToAllocationIndex(reg)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | |
| 483 | LOperand* LChunkBuilder::UseFixed(HValue* value, Register fixed_register) { |
| 484 | return Use(value, ToUnallocated(fixed_register)); |
| 485 | } |
| 486 | |
| 487 | |
| 488 | LOperand* LChunkBuilder::UseFixedDouble(HValue* value, XMMRegister reg) { |
| 489 | return Use(value, ToUnallocated(reg)); |
| 490 | } |
| 491 | |
| 492 | |
| 493 | LOperand* LChunkBuilder::UseRegister(HValue* value) { |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 494 | return Use(value, new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | |
| 498 | LOperand* LChunkBuilder::UseRegisterAtStart(HValue* value) { |
| 499 | return Use(value, |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 500 | new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER, |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 501 | LUnallocated::USED_AT_START)); |
| 502 | } |
| 503 | |
| 504 | |
| 505 | LOperand* LChunkBuilder::UseTempRegister(HValue* value) { |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 506 | return Use(value, new(zone()) LUnallocated(LUnallocated::WRITABLE_REGISTER)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | |
| 510 | LOperand* LChunkBuilder::Use(HValue* value) { |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 511 | return Use(value, new(zone()) LUnallocated(LUnallocated::NONE)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | |
| 515 | LOperand* LChunkBuilder::UseAtStart(HValue* value) { |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 516 | return Use(value, new(zone()) LUnallocated(LUnallocated::NONE, |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 517 | LUnallocated::USED_AT_START)); |
| 518 | } |
| 519 | |
| 520 | |
| 521 | LOperand* LChunkBuilder::UseOrConstant(HValue* value) { |
| 522 | return value->IsConstant() |
| 523 | ? chunk_->DefineConstantOperand(HConstant::cast(value)) |
| 524 | : Use(value); |
| 525 | } |
| 526 | |
| 527 | |
| 528 | LOperand* LChunkBuilder::UseOrConstantAtStart(HValue* value) { |
| 529 | return value->IsConstant() |
| 530 | ? chunk_->DefineConstantOperand(HConstant::cast(value)) |
| 531 | : UseAtStart(value); |
| 532 | } |
| 533 | |
| 534 | |
| 535 | LOperand* LChunkBuilder::UseRegisterOrConstant(HValue* value) { |
| 536 | return value->IsConstant() |
| 537 | ? chunk_->DefineConstantOperand(HConstant::cast(value)) |
| 538 | : UseRegister(value); |
| 539 | } |
| 540 | |
| 541 | |
| 542 | LOperand* LChunkBuilder::UseRegisterOrConstantAtStart(HValue* value) { |
| 543 | return value->IsConstant() |
| 544 | ? chunk_->DefineConstantOperand(HConstant::cast(value)) |
| 545 | : UseRegisterAtStart(value); |
| 546 | } |
| 547 | |
| 548 | |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 549 | LOperand* LChunkBuilder::UseConstant(HValue* value) { |
| 550 | return chunk_->DefineConstantOperand(HConstant::cast(value)); |
| 551 | } |
| 552 | |
| 553 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 554 | LOperand* LChunkBuilder::UseAny(HValue* value) { |
| 555 | return value->IsConstant() |
| 556 | ? chunk_->DefineConstantOperand(HConstant::cast(value)) |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 557 | : Use(value, new(zone()) LUnallocated(LUnallocated::ANY)); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 561 | LOperand* LChunkBuilder::Use(HValue* value, LUnallocated* operand) { |
| 562 | if (value->EmitAtUses()) { |
| 563 | HInstruction* instr = HInstruction::cast(value); |
| 564 | VisitInstruction(instr); |
| 565 | } |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 566 | operand->set_virtual_register(value->id()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 567 | return operand; |
| 568 | } |
| 569 | |
| 570 | |
| 571 | template<int I, int T> |
| 572 | LInstruction* LChunkBuilder::Define(LTemplateInstruction<1, I, T>* instr, |
| 573 | LUnallocated* result) { |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 574 | result->set_virtual_register(current_instruction_->id()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 575 | instr->set_result(result); |
| 576 | return instr; |
| 577 | } |
| 578 | |
| 579 | |
| 580 | template<int I, int T> |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 581 | LInstruction* LChunkBuilder::DefineAsRegister( |
| 582 | LTemplateInstruction<1, I, T>* instr) { |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 583 | return Define(instr, |
| 584 | new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | |
| 588 | template<int I, int T> |
| 589 | LInstruction* LChunkBuilder::DefineAsSpilled( |
| 590 | LTemplateInstruction<1, I, T>* instr, |
| 591 | int index) { |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 592 | return Define(instr, |
| 593 | new(zone()) LUnallocated(LUnallocated::FIXED_SLOT, index)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | |
| 597 | template<int I, int T> |
| 598 | LInstruction* LChunkBuilder::DefineSameAsFirst( |
| 599 | LTemplateInstruction<1, I, T>* instr) { |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 600 | return Define(instr, |
| 601 | new(zone()) LUnallocated(LUnallocated::SAME_AS_FIRST_INPUT)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | |
| 605 | template<int I, int T> |
| 606 | LInstruction* LChunkBuilder::DefineFixed(LTemplateInstruction<1, I, T>* instr, |
| 607 | Register reg) { |
| 608 | return Define(instr, ToUnallocated(reg)); |
| 609 | } |
| 610 | |
| 611 | |
| 612 | template<int I, int T> |
| 613 | LInstruction* LChunkBuilder::DefineFixedDouble( |
| 614 | LTemplateInstruction<1, I, T>* instr, |
| 615 | XMMRegister reg) { |
| 616 | return Define(instr, ToUnallocated(reg)); |
| 617 | } |
| 618 | |
| 619 | |
| 620 | LInstruction* LChunkBuilder::AssignEnvironment(LInstruction* instr) { |
| 621 | HEnvironment* hydrogen_env = current_block_->last_environment(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 622 | int argument_index_accumulator = 0; |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 623 | ZoneList<HValue*> objects_to_materialize(0, zone()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 624 | instr->set_environment(CreateEnvironment(hydrogen_env, |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 625 | &argument_index_accumulator, |
| 626 | &objects_to_materialize)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 627 | return instr; |
| 628 | } |
| 629 | |
| 630 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 631 | LInstruction* LChunkBuilder::MarkAsCall(LInstruction* instr, |
| 632 | HInstruction* hinstr, |
| 633 | CanDeoptimize can_deoptimize) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 634 | info()->MarkAsNonDeferredCalling(); |
| 635 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 636 | #ifdef DEBUG |
| 637 | instr->VerifyCall(); |
| 638 | #endif |
| 639 | instr->MarkAsCall(); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 640 | instr = AssignPointerMap(instr); |
| 641 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 642 | if (hinstr->HasObservableSideEffects()) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 643 | ASSERT(hinstr->next()->IsSimulate()); |
| 644 | HSimulate* sim = HSimulate::cast(hinstr->next()); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 645 | ASSERT(instruction_pending_deoptimization_environment_ == NULL); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 646 | ASSERT(pending_deoptimization_ast_id_.IsNone()); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 647 | instruction_pending_deoptimization_environment_ = instr; |
| 648 | pending_deoptimization_ast_id_ = sim->ast_id(); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | // If instruction does not have side-effects lazy deoptimization |
| 652 | // after the call will try to deoptimize to the point before the call. |
| 653 | // Thus we still need to attach environment to this call even if |
| 654 | // call sequence can not deoptimize eagerly. |
| 655 | bool needs_environment = |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 656 | (can_deoptimize == CAN_DEOPTIMIZE_EAGERLY) || |
| 657 | !hinstr->HasObservableSideEffects(); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 658 | if (needs_environment && !instr->HasEnvironment()) { |
| 659 | instr = AssignEnvironment(instr); |
| 660 | } |
| 661 | |
| 662 | return instr; |
| 663 | } |
| 664 | |
| 665 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 666 | LInstruction* LChunkBuilder::AssignPointerMap(LInstruction* instr) { |
| 667 | ASSERT(!instr->HasPointerMap()); |
bmeurer@chromium.org | 71f9fca | 2013-10-22 08:00:09 +0000 | [diff] [blame] | 668 | instr->set_pointer_map(new(zone()) LPointerMap(zone())); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 669 | return instr; |
| 670 | } |
| 671 | |
| 672 | |
| 673 | LUnallocated* LChunkBuilder::TempRegister() { |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 674 | LUnallocated* operand = |
| 675 | new(zone()) LUnallocated(LUnallocated::MUST_HAVE_REGISTER); |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 676 | int vreg = allocator_->GetVirtualRegister(); |
| 677 | if (!allocator_->AllocationOk()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 678 | Abort(kOutOfVirtualRegistersWhileTryingToAllocateTempRegister); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 679 | vreg = 0; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 680 | } |
| 681 | operand->set_virtual_register(vreg); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 682 | return operand; |
| 683 | } |
| 684 | |
| 685 | |
| 686 | LOperand* LChunkBuilder::FixedTemp(Register reg) { |
| 687 | LUnallocated* operand = ToUnallocated(reg); |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 688 | ASSERT(operand->HasFixedPolicy()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 689 | return operand; |
| 690 | } |
| 691 | |
| 692 | |
| 693 | LOperand* LChunkBuilder::FixedTemp(XMMRegister reg) { |
| 694 | LUnallocated* operand = ToUnallocated(reg); |
rossberg@chromium.org | 994edf6 | 2012-02-06 10:12:55 +0000 | [diff] [blame] | 695 | ASSERT(operand->HasFixedPolicy()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 696 | return operand; |
| 697 | } |
| 698 | |
| 699 | |
| 700 | LInstruction* LChunkBuilder::DoBlockEntry(HBlockEntry* instr) { |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 701 | return new(zone()) LLabel(instr->block()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 702 | } |
| 703 | |
| 704 | |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 705 | LInstruction* LChunkBuilder::DoDummyUse(HDummyUse* instr) { |
| 706 | return DefineAsRegister(new(zone()) LDummyUse(UseAny(instr->value()))); |
| 707 | } |
| 708 | |
| 709 | |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 710 | LInstruction* LChunkBuilder::DoEnvironmentMarker(HEnvironmentMarker* instr) { |
| 711 | UNREACHABLE(); |
| 712 | return NULL; |
| 713 | } |
| 714 | |
| 715 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 716 | LInstruction* LChunkBuilder::DoDeoptimize(HDeoptimize* instr) { |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 717 | return AssignEnvironment(new(zone()) LDeoptimize); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 721 | LInstruction* LChunkBuilder::DoShift(Token::Value op, |
| 722 | HBitwiseBinaryOperation* instr) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 723 | if (instr->representation().IsSmiOrInteger32()) { |
| 724 | ASSERT(instr->left()->representation().Equals(instr->representation())); |
| 725 | ASSERT(instr->right()->representation().Equals(instr->representation())); |
| 726 | LOperand* left = UseRegisterAtStart(instr->left()); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 727 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 728 | HValue* right_value = instr->right(); |
| 729 | LOperand* right = NULL; |
| 730 | int constant_value = 0; |
| 731 | if (right_value->IsConstant()) { |
| 732 | HConstant* constant = HConstant::cast(right_value); |
| 733 | right = chunk_->DefineConstantOperand(constant); |
| 734 | constant_value = constant->Integer32Value() & 0x1f; |
hpayer@chromium.org | 2f877ac | 2013-09-18 15:29:06 +0000 | [diff] [blame] | 735 | } else { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 736 | right = UseFixed(right_value, rcx); |
hpayer@chromium.org | 2f877ac | 2013-09-18 15:29:06 +0000 | [diff] [blame] | 737 | } |
hpayer@chromium.org | 2f877ac | 2013-09-18 15:29:06 +0000 | [diff] [blame] | 738 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 739 | // Shift operations can only deoptimize if we do a logical shift by 0 and |
| 740 | // the result cannot be truncated to int32. |
| 741 | bool does_deopt = false; |
| 742 | if (op == Token::SHR && constant_value == 0) { |
| 743 | if (FLAG_opt_safe_uint32_operations) { |
| 744 | does_deopt = !instr->CheckFlag(HInstruction::kUint32); |
| 745 | } else { |
| 746 | does_deopt = !instr->CheckUsesForFlag(HValue::kTruncatingToInt32); |
| 747 | } |
| 748 | } |
| 749 | |
| 750 | LInstruction* result = |
| 751 | DefineSameAsFirst(new(zone()) LShiftI(op, left, right, does_deopt)); |
| 752 | return does_deopt ? AssignEnvironment(result) : result; |
| 753 | } else { |
| 754 | return DoArithmeticT(op, instr); |
| 755 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | |
| 759 | LInstruction* LChunkBuilder::DoArithmeticD(Token::Value op, |
| 760 | HArithmeticBinaryOperation* instr) { |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 761 | ASSERT(instr->representation().IsDouble()); |
| 762 | ASSERT(instr->left()->representation().IsDouble()); |
| 763 | ASSERT(instr->right()->representation().IsDouble()); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 764 | if (op == Token::MOD) { |
| 765 | LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand()); |
| 766 | LOperand* right = UseFixedDouble(instr->BetterRightOperand(), xmm1); |
| 767 | LArithmeticD* result = new(zone()) LArithmeticD(op, left, right); |
| 768 | return MarkAsCall(DefineSameAsFirst(result), instr); |
| 769 | } else { |
| 770 | LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand()); |
| 771 | LOperand* right = UseRegisterAtStart(instr->BetterRightOperand()); |
| 772 | LArithmeticD* result = new(zone()) LArithmeticD(op, left, right); |
| 773 | return DefineSameAsFirst(result); |
| 774 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | |
| 778 | LInstruction* LChunkBuilder::DoArithmeticT(Token::Value op, |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 779 | HBinaryOperation* instr) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 780 | HValue* left = instr->left(); |
| 781 | HValue* right = instr->right(); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 782 | ASSERT(left->representation().IsTagged()); |
| 783 | ASSERT(right->representation().IsTagged()); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 784 | LOperand* context = UseFixed(instr->context(), rsi); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 785 | LOperand* left_operand = UseFixed(left, rdx); |
| 786 | LOperand* right_operand = UseFixed(right, rax); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 787 | LArithmeticT* result = |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 788 | new(zone()) LArithmeticT(op, context, left_operand, right_operand); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 789 | return MarkAsCall(DefineFixed(result, rax), instr); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 790 | } |
| 791 | |
| 792 | |
| 793 | void LChunkBuilder::DoBasicBlock(HBasicBlock* block, HBasicBlock* next_block) { |
| 794 | ASSERT(is_building()); |
| 795 | current_block_ = block; |
| 796 | next_block_ = next_block; |
| 797 | if (block->IsStartBlock()) { |
| 798 | block->UpdateEnvironment(graph_->start_environment()); |
| 799 | argument_count_ = 0; |
| 800 | } else if (block->predecessors()->length() == 1) { |
| 801 | // We have a single predecessor => copy environment and outgoing |
| 802 | // argument count from the predecessor. |
| 803 | ASSERT(block->phis()->length() == 0); |
| 804 | HBasicBlock* pred = block->predecessors()->at(0); |
| 805 | HEnvironment* last_environment = pred->last_environment(); |
| 806 | ASSERT(last_environment != NULL); |
| 807 | // Only copy the environment, if it is later used again. |
| 808 | if (pred->end()->SecondSuccessor() == NULL) { |
| 809 | ASSERT(pred->end()->FirstSuccessor() == block); |
| 810 | } else { |
| 811 | if (pred->end()->FirstSuccessor()->block_id() > block->block_id() || |
| 812 | pred->end()->SecondSuccessor()->block_id() > block->block_id()) { |
| 813 | last_environment = last_environment->Copy(); |
| 814 | } |
| 815 | } |
| 816 | block->UpdateEnvironment(last_environment); |
| 817 | ASSERT(pred->argument_count() >= 0); |
| 818 | argument_count_ = pred->argument_count(); |
| 819 | } else { |
| 820 | // We are at a state join => process phis. |
| 821 | HBasicBlock* pred = block->predecessors()->at(0); |
| 822 | // No need to copy the environment, it cannot be used later. |
| 823 | HEnvironment* last_environment = pred->last_environment(); |
| 824 | for (int i = 0; i < block->phis()->length(); ++i) { |
| 825 | HPhi* phi = block->phis()->at(i); |
danno@chromium.org | ad75d6f | 2013-08-12 16:57:59 +0000 | [diff] [blame] | 826 | if (phi->HasMergedIndex()) { |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 827 | last_environment->SetValueAt(phi->merged_index(), phi); |
| 828 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 829 | } |
| 830 | for (int i = 0; i < block->deleted_phis()->length(); ++i) { |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 831 | if (block->deleted_phis()->at(i) < last_environment->length()) { |
| 832 | last_environment->SetValueAt(block->deleted_phis()->at(i), |
| 833 | graph_->GetConstantUndefined()); |
| 834 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 835 | } |
| 836 | block->UpdateEnvironment(last_environment); |
| 837 | // Pick up the outgoing argument count of one of the predecessors. |
| 838 | argument_count_ = pred->argument_count(); |
| 839 | } |
| 840 | HInstruction* current = block->first(); |
| 841 | int start = chunk_->instructions()->length(); |
| 842 | while (current != NULL && !is_aborted()) { |
| 843 | // Code for constants in registers is generated lazily. |
| 844 | if (!current->EmitAtUses()) { |
| 845 | VisitInstruction(current); |
| 846 | } |
| 847 | current = current->next(); |
| 848 | } |
| 849 | int end = chunk_->instructions()->length() - 1; |
| 850 | if (end >= start) { |
| 851 | block->set_first_instruction_index(start); |
| 852 | block->set_last_instruction_index(end); |
| 853 | } |
| 854 | block->set_argument_count(argument_count_); |
| 855 | next_block_ = NULL; |
| 856 | current_block_ = NULL; |
| 857 | } |
| 858 | |
| 859 | |
| 860 | void LChunkBuilder::VisitInstruction(HInstruction* current) { |
| 861 | HInstruction* old_current = current_instruction_; |
| 862 | current_instruction_ = current; |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 863 | |
| 864 | LInstruction* instr = NULL; |
| 865 | if (current->CanReplaceWithDummyUses()) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 866 | if (current->OperandCount() == 0) { |
| 867 | instr = DefineAsRegister(new(zone()) LDummy()); |
| 868 | } else { |
| 869 | instr = DefineAsRegister(new(zone()) |
| 870 | LDummyUse(UseAny(current->OperandAt(0)))); |
| 871 | } |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 872 | for (int i = 1; i < current->OperandCount(); ++i) { |
| 873 | LInstruction* dummy = |
| 874 | new(zone()) LDummyUse(UseAny(current->OperandAt(i))); |
| 875 | dummy->set_hydrogen_value(current); |
| 876 | chunk_->AddInstruction(dummy, current_block_); |
| 877 | } |
| 878 | } else { |
| 879 | instr = current->CompileToLithium(this); |
| 880 | } |
| 881 | |
| 882 | argument_count_ += current->argument_delta(); |
| 883 | ASSERT(argument_count_ >= 0); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 884 | |
| 885 | if (instr != NULL) { |
jkummerow@chromium.org | fb7a7c4 | 2013-10-02 11:41:02 +0000 | [diff] [blame] | 886 | // Associate the hydrogen instruction first, since we may need it for |
| 887 | // the ClobbersRegisters() or ClobbersDoubleRegisters() calls below. |
| 888 | instr->set_hydrogen_value(current); |
| 889 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 890 | #if DEBUG |
| 891 | // Make sure that the lithium instruction has either no fixed register |
| 892 | // constraints in temps or the result OR no uses that are only used at |
| 893 | // start. If this invariant doesn't hold, the register allocator can decide |
| 894 | // to insert a split of a range immediately before the instruction due to an |
| 895 | // already allocated register needing to be used for the instruction's fixed |
| 896 | // register constraint. In this case, The register allocator won't see an |
| 897 | // interference between the split child and the use-at-start (it would if |
| 898 | // the it was just a plain use), so it is free to move the split child into |
| 899 | // the same register that is used for the use-at-start. |
| 900 | // See https://code.google.com/p/chromium/issues/detail?id=201590 |
| 901 | if (!(instr->ClobbersRegisters() && instr->ClobbersDoubleRegisters())) { |
| 902 | int fixed = 0; |
| 903 | int used_at_start = 0; |
| 904 | for (UseIterator it(instr); !it.Done(); it.Advance()) { |
| 905 | LUnallocated* operand = LUnallocated::cast(it.Current()); |
| 906 | if (operand->IsUsedAtStart()) ++used_at_start; |
| 907 | } |
| 908 | if (instr->Output() != NULL) { |
| 909 | if (LUnallocated::cast(instr->Output())->HasFixedPolicy()) ++fixed; |
| 910 | } |
| 911 | for (TempIterator it(instr); !it.Done(); it.Advance()) { |
| 912 | LUnallocated* operand = LUnallocated::cast(it.Current()); |
| 913 | if (operand->HasFixedPolicy()) ++fixed; |
| 914 | } |
| 915 | ASSERT(fixed == 0 || used_at_start == 0); |
| 916 | } |
| 917 | #endif |
| 918 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 919 | if (FLAG_stress_pointer_maps && !instr->HasPointerMap()) { |
| 920 | instr = AssignPointerMap(instr); |
| 921 | } |
| 922 | if (FLAG_stress_environments && !instr->HasEnvironment()) { |
| 923 | instr = AssignEnvironment(instr); |
| 924 | } |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 925 | chunk_->AddInstruction(instr, current_block_); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 926 | } |
| 927 | current_instruction_ = old_current; |
| 928 | } |
| 929 | |
| 930 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 931 | LEnvironment* LChunkBuilder::CreateEnvironment( |
| 932 | HEnvironment* hydrogen_env, |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 933 | int* argument_index_accumulator, |
| 934 | ZoneList<HValue*>* objects_to_materialize) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 935 | if (hydrogen_env == NULL) return NULL; |
| 936 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 937 | LEnvironment* outer = CreateEnvironment(hydrogen_env->outer(), |
| 938 | argument_index_accumulator, |
| 939 | objects_to_materialize); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 940 | BailoutId ast_id = hydrogen_env->ast_id(); |
| 941 | ASSERT(!ast_id.IsNone() || |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 942 | hydrogen_env->frame_type() != JS_FUNCTION); |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 943 | int value_count = hydrogen_env->length() - hydrogen_env->specials_count(); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 944 | LEnvironment* result = new(zone()) LEnvironment( |
| 945 | hydrogen_env->closure(), |
| 946 | hydrogen_env->frame_type(), |
| 947 | ast_id, |
| 948 | hydrogen_env->parameter_count(), |
| 949 | argument_count_, |
| 950 | value_count, |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 951 | outer, |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 952 | hydrogen_env->entry(), |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 953 | zone()); |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 954 | int argument_index = *argument_index_accumulator; |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 955 | int object_index = objects_to_materialize->length(); |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 956 | for (int i = 0; i < hydrogen_env->length(); ++i) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 957 | if (hydrogen_env->is_special_index(i)) continue; |
| 958 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 959 | LOperand* op; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 960 | HValue* value = hydrogen_env->values()->at(i); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 961 | if (value->IsArgumentsObject() || value->IsCapturedObject()) { |
| 962 | objects_to_materialize->Add(value, zone()); |
| 963 | op = LEnvironment::materialization_marker(); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 964 | } else if (value->IsPushArgument()) { |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 965 | op = new(zone()) LArgument(argument_index++); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 966 | } else { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 967 | op = UseAny(value); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 968 | } |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 969 | result->AddValue(op, |
| 970 | value->representation(), |
| 971 | value->CheckFlag(HInstruction::kUint32)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 972 | } |
| 973 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 974 | for (int i = object_index; i < objects_to_materialize->length(); ++i) { |
| 975 | HValue* object_to_materialize = objects_to_materialize->at(i); |
| 976 | int previously_materialized_object = -1; |
| 977 | for (int prev = 0; prev < i; ++prev) { |
| 978 | if (objects_to_materialize->at(prev) == objects_to_materialize->at(i)) { |
| 979 | previously_materialized_object = prev; |
| 980 | break; |
| 981 | } |
| 982 | } |
| 983 | int length = object_to_materialize->OperandCount(); |
| 984 | bool is_arguments = object_to_materialize->IsArgumentsObject(); |
| 985 | if (previously_materialized_object >= 0) { |
| 986 | result->AddDuplicateObject(previously_materialized_object); |
| 987 | continue; |
| 988 | } else { |
| 989 | result->AddNewObject(is_arguments ? length - 1 : length, is_arguments); |
| 990 | } |
| 991 | for (int i = is_arguments ? 1 : 0; i < length; ++i) { |
| 992 | LOperand* op; |
| 993 | HValue* value = object_to_materialize->OperandAt(i); |
| 994 | if (value->IsArgumentsObject() || value->IsCapturedObject()) { |
| 995 | objects_to_materialize->Add(value, zone()); |
| 996 | op = LEnvironment::materialization_marker(); |
| 997 | } else { |
| 998 | ASSERT(!value->IsPushArgument()); |
| 999 | op = UseAny(value); |
| 1000 | } |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 1001 | result->AddValue(op, |
| 1002 | value->representation(), |
| 1003 | value->CheckFlag(HInstruction::kUint32)); |
| 1004 | } |
| 1005 | } |
| 1006 | |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 1007 | if (hydrogen_env->frame_type() == JS_FUNCTION) { |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 1008 | *argument_index_accumulator = argument_index; |
| 1009 | } |
| 1010 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1011 | return result; |
| 1012 | } |
| 1013 | |
| 1014 | |
| 1015 | LInstruction* LChunkBuilder::DoGoto(HGoto* instr) { |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 1016 | return new(zone()) LGoto(instr->FirstSuccessor()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1017 | } |
| 1018 | |
| 1019 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1020 | LInstruction* LChunkBuilder::DoDebugBreak(HDebugBreak* instr) { |
| 1021 | return new(zone()) LDebugBreak(); |
| 1022 | } |
| 1023 | |
| 1024 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1025 | LInstruction* LChunkBuilder::DoBranch(HBranch* instr) { |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 1026 | LInstruction* goto_instr = CheckElideControlInstruction(instr); |
| 1027 | if (goto_instr != NULL) return goto_instr; |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1028 | |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 1029 | HValue* value = instr->value(); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1030 | LBranch* result = new(zone()) LBranch(UseRegister(value)); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1031 | // Tagged values that are not known smis or booleans require a |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1032 | // deoptimization environment. If the instruction is generic no |
| 1033 | // environment is needed since all cases are handled. |
| 1034 | ToBooleanStub::Types expected = instr->expected_input_types(); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1035 | Representation rep = value->representation(); |
| 1036 | HType type = value->type(); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1037 | if (rep.IsTagged() && !type.IsSmi() && !type.IsBoolean() && |
| 1038 | !expected.IsGeneric()) { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1039 | return AssignEnvironment(result); |
| 1040 | } |
| 1041 | return result; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1042 | } |
| 1043 | |
| 1044 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1045 | LInstruction* LChunkBuilder::DoCompareMap(HCompareMap* instr) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1046 | ASSERT(instr->value()->representation().IsTagged()); |
| 1047 | LOperand* value = UseRegisterAtStart(instr->value()); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1048 | return new(zone()) LCmpMapAndBranch(value); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1049 | } |
| 1050 | |
| 1051 | |
| 1052 | LInstruction* LChunkBuilder::DoArgumentsLength(HArgumentsLength* length) { |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 1053 | info()->MarkAsRequiresFrame(); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1054 | return DefineAsRegister(new(zone()) LArgumentsLength(Use(length->value()))); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1055 | } |
| 1056 | |
| 1057 | |
| 1058 | LInstruction* LChunkBuilder::DoArgumentsElements(HArgumentsElements* elems) { |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 1059 | info()->MarkAsRequiresFrame(); |
danno@chromium.org | b2a1c07 | 2012-03-23 15:47:56 +0000 | [diff] [blame] | 1060 | return DefineAsRegister(new(zone()) LArgumentsElements); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | |
| 1064 | LInstruction* LChunkBuilder::DoInstanceOf(HInstanceOf* instr) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1065 | LOperand* left = UseFixed(instr->left(), rax); |
| 1066 | LOperand* right = UseFixed(instr->right(), rdx); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 1067 | LOperand* context = UseFixed(instr->context(), rsi); |
| 1068 | LInstanceOf* result = new(zone()) LInstanceOf(context, left, right); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1069 | return MarkAsCall(DefineFixed(result, rax), instr); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1070 | } |
| 1071 | |
| 1072 | |
| 1073 | LInstruction* LChunkBuilder::DoInstanceOfKnownGlobal( |
| 1074 | HInstanceOfKnownGlobal* instr) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1075 | LInstanceOfKnownGlobal* result = |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 1076 | new(zone()) LInstanceOfKnownGlobal(UseFixed(instr->context(), rsi), |
| 1077 | UseFixed(instr->left(), rax), |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1078 | FixedTemp(rdi)); |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1079 | return MarkAsCall(DefineFixed(result, rax), instr); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1080 | } |
| 1081 | |
| 1082 | |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 1083 | LInstruction* LChunkBuilder::DoWrapReceiver(HWrapReceiver* instr) { |
| 1084 | LOperand* receiver = UseRegister(instr->receiver()); |
| 1085 | LOperand* function = UseRegisterAtStart(instr->function()); |
| 1086 | LWrapReceiver* result = new(zone()) LWrapReceiver(receiver, function); |
| 1087 | return AssignEnvironment(DefineSameAsFirst(result)); |
| 1088 | } |
| 1089 | |
| 1090 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1091 | LInstruction* LChunkBuilder::DoApplyArguments(HApplyArguments* instr) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1092 | LOperand* function = UseFixed(instr->function(), rdi); |
| 1093 | LOperand* receiver = UseFixed(instr->receiver(), rax); |
| 1094 | LOperand* length = UseFixed(instr->length(), rbx); |
| 1095 | LOperand* elements = UseFixed(instr->elements(), rcx); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1096 | LApplyArguments* result = new(zone()) LApplyArguments(function, |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1097 | receiver, |
| 1098 | length, |
| 1099 | elements); |
| 1100 | return MarkAsCall(DefineFixed(result, rax), instr, CAN_DEOPTIMIZE_EAGERLY); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1101 | } |
| 1102 | |
| 1103 | |
| 1104 | LInstruction* LChunkBuilder::DoPushArgument(HPushArgument* instr) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1105 | LOperand* argument = UseOrConstant(instr->argument()); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1106 | return new(zone()) LPushArgument(argument); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1107 | } |
| 1108 | |
| 1109 | |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1110 | LInstruction* LChunkBuilder::DoStoreCodeEntry( |
| 1111 | HStoreCodeEntry* store_code_entry) { |
| 1112 | LOperand* function = UseRegister(store_code_entry->function()); |
| 1113 | LOperand* code_object = UseTempRegister(store_code_entry->code_object()); |
| 1114 | return new(zone()) LStoreCodeEntry(function, code_object); |
| 1115 | } |
| 1116 | |
| 1117 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 1118 | LInstruction* LChunkBuilder::DoInnerAllocatedObject( |
| 1119 | HInnerAllocatedObject* inner_object) { |
| 1120 | LOperand* base_object = UseRegisterAtStart(inner_object->base_object()); |
| 1121 | LInnerAllocatedObject* result = |
| 1122 | new(zone()) LInnerAllocatedObject(base_object); |
| 1123 | return DefineAsRegister(result); |
| 1124 | } |
| 1125 | |
| 1126 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1127 | LInstruction* LChunkBuilder::DoThisFunction(HThisFunction* instr) { |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1128 | return instr->HasNoUses() |
| 1129 | ? NULL |
| 1130 | : DefineAsRegister(new(zone()) LThisFunction); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1131 | } |
| 1132 | |
| 1133 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1134 | LInstruction* LChunkBuilder::DoContext(HContext* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 1135 | if (instr->HasNoUses()) return NULL; |
| 1136 | |
| 1137 | if (info()->IsStub()) { |
| 1138 | return DefineFixed(new(zone()) LContext, rsi); |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 1139 | } |
| 1140 | |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 1141 | return DefineAsRegister(new(zone()) LContext); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1142 | } |
| 1143 | |
| 1144 | |
| 1145 | LInstruction* LChunkBuilder::DoOuterContext(HOuterContext* instr) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1146 | LOperand* context = UseRegisterAtStart(instr->value()); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1147 | return DefineAsRegister(new(zone()) LOuterContext(context)); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1148 | } |
| 1149 | |
| 1150 | |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 1151 | LInstruction* LChunkBuilder::DoDeclareGlobals(HDeclareGlobals* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 1152 | LOperand* context = UseFixed(instr->context(), rsi); |
| 1153 | return MarkAsCall(new(zone()) LDeclareGlobals(context), instr); |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 1154 | } |
| 1155 | |
| 1156 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1157 | LInstruction* LChunkBuilder::DoGlobalObject(HGlobalObject* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 1158 | LOperand* context = UseRegisterAtStart(instr->value()); |
| 1159 | return DefineAsRegister(new(zone()) LGlobalObject(context)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1160 | } |
| 1161 | |
| 1162 | |
| 1163 | LInstruction* LChunkBuilder::DoGlobalReceiver(HGlobalReceiver* instr) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1164 | LOperand* global_object = UseRegisterAtStart(instr->value()); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1165 | return DefineAsRegister(new(zone()) LGlobalReceiver(global_object)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1166 | } |
| 1167 | |
| 1168 | |
| 1169 | LInstruction* LChunkBuilder::DoCallConstantFunction( |
| 1170 | HCallConstantFunction* instr) { |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1171 | return MarkAsCall(DefineFixed(new(zone()) LCallConstantFunction, rax), instr); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1172 | } |
| 1173 | |
| 1174 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1175 | LInstruction* LChunkBuilder::DoInvokeFunction(HInvokeFunction* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 1176 | LOperand* context = UseFixed(instr->context(), rsi); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1177 | LOperand* function = UseFixed(instr->function(), rdi); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 1178 | LInvokeFunction* result = new(zone()) LInvokeFunction(context, function); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1179 | return MarkAsCall(DefineFixed(result, rax), instr, CANNOT_DEOPTIMIZE_EAGERLY); |
| 1180 | } |
| 1181 | |
| 1182 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1183 | LInstruction* LChunkBuilder::DoUnaryMathOperation(HUnaryMathOperation* instr) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1184 | switch (instr->op()) { |
| 1185 | case kMathFloor: return DoMathFloor(instr); |
| 1186 | case kMathRound: return DoMathRound(instr); |
| 1187 | case kMathAbs: return DoMathAbs(instr); |
| 1188 | case kMathLog: return DoMathLog(instr); |
| 1189 | case kMathSin: return DoMathSin(instr); |
| 1190 | case kMathCos: return DoMathCos(instr); |
| 1191 | case kMathTan: return DoMathTan(instr); |
| 1192 | case kMathExp: return DoMathExp(instr); |
| 1193 | case kMathSqrt: return DoMathSqrt(instr); |
| 1194 | case kMathPowHalf: return DoMathPowHalf(instr); |
| 1195 | default: |
| 1196 | UNREACHABLE(); |
| 1197 | return NULL; |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1198 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1199 | } |
| 1200 | |
| 1201 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1202 | LInstruction* LChunkBuilder::DoMathFloor(HUnaryMathOperation* instr) { |
| 1203 | LOperand* input = UseRegisterAtStart(instr->value()); |
| 1204 | LMathFloor* result = new(zone()) LMathFloor(input); |
| 1205 | return AssignEnvironment(DefineAsRegister(result)); |
| 1206 | } |
| 1207 | |
| 1208 | |
| 1209 | LInstruction* LChunkBuilder::DoMathRound(HUnaryMathOperation* instr) { |
| 1210 | LOperand* input = UseRegisterAtStart(instr->value()); |
| 1211 | LMathRound* result = new(zone()) LMathRound(input); |
| 1212 | return AssignEnvironment(DefineAsRegister(result)); |
| 1213 | } |
| 1214 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 1215 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1216 | LInstruction* LChunkBuilder::DoMathAbs(HUnaryMathOperation* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 1217 | LOperand* context = UseAny(instr->context()); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1218 | LOperand* input = UseRegisterAtStart(instr->value()); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 1219 | LMathAbs* result = new(zone()) LMathAbs(context, input); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1220 | return AssignEnvironment(AssignPointerMap(DefineSameAsFirst(result))); |
| 1221 | } |
| 1222 | |
| 1223 | |
| 1224 | LInstruction* LChunkBuilder::DoMathLog(HUnaryMathOperation* instr) { |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 1225 | ASSERT(instr->representation().IsDouble()); |
| 1226 | ASSERT(instr->value()->representation().IsDouble()); |
| 1227 | LOperand* input = UseRegisterAtStart(instr->value()); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1228 | LMathLog* result = new(zone()) LMathLog(input); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 1229 | return DefineSameAsFirst(result); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 1230 | } |
| 1231 | |
| 1232 | |
| 1233 | LInstruction* LChunkBuilder::DoMathSin(HUnaryMathOperation* instr) { |
| 1234 | LOperand* input = UseFixedDouble(instr->value(), xmm1); |
| 1235 | LMathSin* result = new(zone()) LMathSin(input); |
| 1236 | return MarkAsCall(DefineFixedDouble(result, xmm1), instr); |
| 1237 | } |
| 1238 | |
| 1239 | |
| 1240 | LInstruction* LChunkBuilder::DoMathCos(HUnaryMathOperation* instr) { |
| 1241 | LOperand* input = UseFixedDouble(instr->value(), xmm1); |
| 1242 | LMathCos* result = new(zone()) LMathCos(input); |
| 1243 | return MarkAsCall(DefineFixedDouble(result, xmm1), instr); |
| 1244 | } |
| 1245 | |
| 1246 | |
| 1247 | LInstruction* LChunkBuilder::DoMathTan(HUnaryMathOperation* instr) { |
| 1248 | LOperand* input = UseFixedDouble(instr->value(), xmm1); |
| 1249 | LMathTan* result = new(zone()) LMathTan(input); |
| 1250 | return MarkAsCall(DefineFixedDouble(result, xmm1), instr); |
| 1251 | } |
| 1252 | |
| 1253 | |
| 1254 | LInstruction* LChunkBuilder::DoMathExp(HUnaryMathOperation* instr) { |
| 1255 | ASSERT(instr->representation().IsDouble()); |
| 1256 | ASSERT(instr->value()->representation().IsDouble()); |
| 1257 | LOperand* value = UseTempRegister(instr->value()); |
| 1258 | LOperand* temp1 = TempRegister(); |
| 1259 | LOperand* temp2 = TempRegister(); |
| 1260 | LMathExp* result = new(zone()) LMathExp(value, temp1, temp2); |
| 1261 | return DefineAsRegister(result); |
| 1262 | } |
| 1263 | |
| 1264 | |
| 1265 | LInstruction* LChunkBuilder::DoMathSqrt(HUnaryMathOperation* instr) { |
| 1266 | LOperand* input = UseRegisterAtStart(instr->value()); |
| 1267 | LMathSqrt* result = new(zone()) LMathSqrt(input); |
| 1268 | return DefineSameAsFirst(result); |
| 1269 | } |
| 1270 | |
| 1271 | |
| 1272 | LInstruction* LChunkBuilder::DoMathPowHalf(HUnaryMathOperation* instr) { |
| 1273 | LOperand* input = UseRegisterAtStart(instr->value()); |
| 1274 | LMathPowHalf* result = new(zone()) LMathPowHalf(input); |
| 1275 | return DefineSameAsFirst(result); |
| 1276 | } |
| 1277 | |
| 1278 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1279 | LInstruction* LChunkBuilder::DoCallKeyed(HCallKeyed* instr) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1280 | ASSERT(instr->key()->representation().IsTagged()); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 1281 | LOperand* context = UseFixed(instr->context(), rsi); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1282 | LOperand* key = UseFixed(instr->key(), rcx); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 1283 | LCallKeyed* result = new(zone()) LCallKeyed(context, key); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1284 | return MarkAsCall(DefineFixed(result, rax), instr); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1285 | } |
| 1286 | |
| 1287 | |
| 1288 | LInstruction* LChunkBuilder::DoCallNamed(HCallNamed* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 1289 | LOperand* context = UseFixed(instr->context(), rsi); |
| 1290 | LCallNamed* result = new(zone()) LCallNamed(context); |
| 1291 | return MarkAsCall(DefineFixed(result, rax), instr); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1292 | } |
| 1293 | |
| 1294 | |
| 1295 | LInstruction* LChunkBuilder::DoCallGlobal(HCallGlobal* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 1296 | LOperand* context = UseFixed(instr->context(), rsi); |
| 1297 | LCallGlobal* result = new(zone()) LCallGlobal(context); |
| 1298 | return MarkAsCall(DefineFixed(result, rax), instr); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1299 | } |
| 1300 | |
| 1301 | |
| 1302 | LInstruction* LChunkBuilder::DoCallKnownGlobal(HCallKnownGlobal* instr) { |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1303 | return MarkAsCall(DefineFixed(new(zone()) LCallKnownGlobal, rax), instr); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1304 | } |
| 1305 | |
| 1306 | |
| 1307 | LInstruction* LChunkBuilder::DoCallNew(HCallNew* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 1308 | LOperand* context = UseFixed(instr->context(), rsi); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1309 | LOperand* constructor = UseFixed(instr->constructor(), rdi); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 1310 | LCallNew* result = new(zone()) LCallNew(context, constructor); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1311 | return MarkAsCall(DefineFixed(result, rax), instr); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1312 | } |
| 1313 | |
| 1314 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1315 | LInstruction* LChunkBuilder::DoCallNewArray(HCallNewArray* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 1316 | LOperand* context = UseFixed(instr->context(), rsi); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1317 | LOperand* constructor = UseFixed(instr->constructor(), rdi); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 1318 | LCallNewArray* result = new(zone()) LCallNewArray(context, constructor); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1319 | return MarkAsCall(DefineFixed(result, rax), instr); |
| 1320 | } |
| 1321 | |
| 1322 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1323 | LInstruction* LChunkBuilder::DoCallFunction(HCallFunction* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 1324 | LOperand* context = UseFixed(instr->context(), rsi); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 1325 | LOperand* function = UseFixed(instr->function(), rdi); |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 1326 | LCallFunction* call = new(zone()) LCallFunction(context, function); |
| 1327 | LInstruction* result = DefineFixed(call, rax); |
| 1328 | if (instr->IsTailCall()) return result; |
| 1329 | return MarkAsCall(result, instr); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1330 | } |
| 1331 | |
| 1332 | |
| 1333 | LInstruction* LChunkBuilder::DoCallRuntime(HCallRuntime* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 1334 | LOperand* context = UseFixed(instr->context(), rsi); |
| 1335 | LCallRuntime* result = new(zone()) LCallRuntime(context); |
| 1336 | return MarkAsCall(DefineFixed(result, rax), instr); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1337 | } |
| 1338 | |
| 1339 | |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 1340 | LInstruction* LChunkBuilder::DoRor(HRor* instr) { |
| 1341 | return DoShift(Token::ROR, instr); |
| 1342 | } |
| 1343 | |
| 1344 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1345 | LInstruction* LChunkBuilder::DoShr(HShr* instr) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1346 | return DoShift(Token::SHR, instr); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1347 | } |
| 1348 | |
| 1349 | |
| 1350 | LInstruction* LChunkBuilder::DoSar(HSar* instr) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1351 | return DoShift(Token::SAR, instr); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1352 | } |
| 1353 | |
| 1354 | |
| 1355 | LInstruction* LChunkBuilder::DoShl(HShl* instr) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1356 | return DoShift(Token::SHL, instr); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1357 | } |
| 1358 | |
| 1359 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1360 | LInstruction* LChunkBuilder::DoBitwise(HBitwise* instr) { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1361 | if (instr->representation().IsSmiOrInteger32()) { |
| 1362 | ASSERT(instr->left()->representation().Equals(instr->representation())); |
| 1363 | ASSERT(instr->right()->representation().Equals(instr->representation())); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1364 | ASSERT(instr->CheckFlag(HValue::kTruncatingToInt32)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1365 | |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1366 | LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand()); |
| 1367 | LOperand* right = UseOrConstantAtStart(instr->BetterRightOperand()); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1368 | return DefineSameAsFirst(new(zone()) LBitI(left, right)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1369 | } else { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1370 | return DoArithmeticT(instr->op(), instr); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 1371 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1372 | } |
| 1373 | |
| 1374 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1375 | LInstruction* LChunkBuilder::DoDiv(HDiv* instr) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1376 | if (instr->representation().IsSmiOrInteger32()) { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1377 | ASSERT(instr->left()->representation().Equals(instr->representation())); |
| 1378 | ASSERT(instr->right()->representation().Equals(instr->representation())); |
jkummerow@chromium.org | 5323a9c | 2012-12-10 19:00:50 +0000 | [diff] [blame] | 1379 | if (instr->HasPowerOf2Divisor()) { |
| 1380 | ASSERT(!instr->CheckFlag(HValue::kCanBeDivByZero)); |
| 1381 | LOperand* value = UseRegisterAtStart(instr->left()); |
| 1382 | LDivI* div = |
| 1383 | new(zone()) LDivI(value, UseOrConstant(instr->right()), NULL); |
| 1384 | return AssignEnvironment(DefineSameAsFirst(div)); |
| 1385 | } |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1386 | // The temporary operand is necessary to ensure that right is not allocated |
| 1387 | // into rdx. |
| 1388 | LOperand* temp = FixedTemp(rdx); |
| 1389 | LOperand* dividend = UseFixed(instr->left(), rax); |
| 1390 | LOperand* divisor = UseRegister(instr->right()); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1391 | LDivI* result = new(zone()) LDivI(dividend, divisor, temp); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1392 | return AssignEnvironment(DefineFixed(result, rax)); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1393 | } else if (instr->representation().IsDouble()) { |
| 1394 | return DoArithmeticD(Token::DIV, instr); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1395 | } else { |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1396 | return DoArithmeticT(Token::DIV, instr); |
| 1397 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1398 | } |
| 1399 | |
| 1400 | |
yangguo@chromium.org | d2899aa | 2012-06-21 11:16:20 +0000 | [diff] [blame] | 1401 | HValue* LChunkBuilder::SimplifiedDivisorForMathFloorOfDiv(HValue* divisor) { |
| 1402 | if (divisor->IsConstant() && |
| 1403 | HConstant::cast(divisor)->HasInteger32Value()) { |
| 1404 | HConstant* constant_val = HConstant::cast(divisor); |
| 1405 | return constant_val->CopyToRepresentation(Representation::Integer32(), |
| 1406 | divisor->block()->zone()); |
| 1407 | } |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 1408 | // A value with an integer representation does not need to be transformed. |
| 1409 | if (divisor->representation().IsInteger32()) { |
| 1410 | return divisor; |
| 1411 | // A change from an integer32 can be replaced by the integer32 value. |
| 1412 | } else if (divisor->IsChange() && |
| 1413 | HChange::cast(divisor)->from().IsInteger32()) { |
| 1414 | return HChange::cast(divisor)->value(); |
| 1415 | } |
yangguo@chromium.org | d2899aa | 2012-06-21 11:16:20 +0000 | [diff] [blame] | 1416 | return NULL; |
| 1417 | } |
| 1418 | |
| 1419 | |
| 1420 | LInstruction* LChunkBuilder::DoMathFloorOfDiv(HMathFloorOfDiv* instr) { |
| 1421 | HValue* right = instr->right(); |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 1422 | if (!right->IsConstant()) { |
| 1423 | ASSERT(right->representation().IsInteger32()); |
| 1424 | // The temporary operand is necessary to ensure that right is not allocated |
| 1425 | // into rdx. |
| 1426 | LOperand* temp = FixedTemp(rdx); |
| 1427 | LOperand* dividend = UseFixed(instr->left(), rax); |
| 1428 | LOperand* divisor = UseRegister(instr->right()); |
| 1429 | LDivI* flooring_div = new(zone()) LDivI(dividend, divisor, temp); |
| 1430 | return AssignEnvironment(DefineFixed(flooring_div, rax)); |
| 1431 | } |
| 1432 | |
yangguo@chromium.org | d2899aa | 2012-06-21 11:16:20 +0000 | [diff] [blame] | 1433 | ASSERT(right->IsConstant() && HConstant::cast(right)->HasInteger32Value()); |
| 1434 | LOperand* divisor = chunk_->DefineConstantOperand(HConstant::cast(right)); |
| 1435 | int32_t divisor_si = HConstant::cast(right)->Integer32Value(); |
| 1436 | if (divisor_si == 0) { |
| 1437 | LOperand* dividend = UseRegister(instr->left()); |
| 1438 | return AssignEnvironment(DefineAsRegister( |
| 1439 | new(zone()) LMathFloorOfDiv(dividend, divisor, NULL))); |
| 1440 | } else if (IsPowerOf2(abs(divisor_si))) { |
| 1441 | LOperand* dividend = UseRegisterAtStart(instr->left()); |
| 1442 | LInstruction* result = DefineAsRegister( |
| 1443 | new(zone()) LMathFloorOfDiv(dividend, divisor, NULL)); |
| 1444 | return divisor_si < 0 ? AssignEnvironment(result) : result; |
| 1445 | } else { |
| 1446 | // use two r64 |
| 1447 | LOperand* dividend = UseRegisterAtStart(instr->left()); |
| 1448 | LOperand* temp = TempRegister(); |
| 1449 | LInstruction* result = DefineAsRegister( |
| 1450 | new(zone()) LMathFloorOfDiv(dividend, divisor, temp)); |
| 1451 | return divisor_si < 0 ? AssignEnvironment(result) : result; |
| 1452 | } |
| 1453 | } |
| 1454 | |
| 1455 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1456 | LInstruction* LChunkBuilder::DoMod(HMod* instr) { |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1457 | HValue* left = instr->left(); |
| 1458 | HValue* right = instr->right(); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1459 | if (instr->representation().IsSmiOrInteger32()) { |
| 1460 | ASSERT(left->representation().Equals(instr->representation())); |
| 1461 | ASSERT(right->representation().Equals(instr->representation())); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1462 | if (instr->HasPowerOf2Divisor()) { |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1463 | ASSERT(!right->CanBeZero()); |
| 1464 | LModI* mod = new(zone()) LModI(UseRegisterAtStart(left), |
| 1465 | UseOrConstant(right), |
| 1466 | NULL); |
| 1467 | LInstruction* result = DefineSameAsFirst(mod); |
| 1468 | return (left->CanBeNegative() && |
| 1469 | instr->CheckFlag(HValue::kBailoutOnMinusZero)) |
| 1470 | ? AssignEnvironment(result) |
| 1471 | : result; |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1472 | } else if (instr->fixed_right_arg().has_value) { |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1473 | LModI* mod = new(zone()) LModI(UseRegister(left), |
| 1474 | UseRegisterAtStart(right), |
| 1475 | NULL); |
| 1476 | return AssignEnvironment(DefineSameAsFirst(mod)); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1477 | } else { |
| 1478 | // The temporary operand is necessary to ensure that right is not |
| 1479 | // allocated into edx. |
verwaest@chromium.org | 8a00e82 | 2013-06-10 15:11:22 +0000 | [diff] [blame] | 1480 | LModI* mod = new(zone()) LModI(UseFixed(left, rax), |
| 1481 | UseRegister(right), |
| 1482 | FixedTemp(rdx)); |
| 1483 | LInstruction* result = DefineFixed(mod, rdx); |
| 1484 | return (right->CanBeZero() || |
| 1485 | (left->RangeCanInclude(kMinInt) && |
| 1486 | right->RangeCanInclude(-1) && |
| 1487 | instr->CheckFlag(HValue::kBailoutOnMinusZero)) || |
| 1488 | (left->CanBeNegative() && |
| 1489 | instr->CanBeZero() && |
| 1490 | instr->CheckFlag(HValue::kBailoutOnMinusZero))) |
| 1491 | ? AssignEnvironment(result) |
| 1492 | : result; |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 1493 | } |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1494 | } else if (instr->representation().IsDouble()) { |
| 1495 | return DoArithmeticD(Token::MOD, instr); |
hpayer@chromium.org | 2f877ac | 2013-09-18 15:29:06 +0000 | [diff] [blame] | 1496 | } else { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1497 | return DoArithmeticT(Token::MOD, instr); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1498 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1499 | } |
| 1500 | |
| 1501 | |
| 1502 | LInstruction* LChunkBuilder::DoMul(HMul* instr) { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1503 | if (instr->representation().IsSmiOrInteger32()) { |
| 1504 | ASSERT(instr->left()->representation().Equals(instr->representation())); |
| 1505 | ASSERT(instr->right()->representation().Equals(instr->representation())); |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1506 | LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand()); |
| 1507 | LOperand* right = UseOrConstant(instr->BetterRightOperand()); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1508 | LMulI* mul = new(zone()) LMulI(left, right); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1509 | if (instr->CheckFlag(HValue::kCanOverflow) || |
| 1510 | instr->CheckFlag(HValue::kBailoutOnMinusZero)) { |
| 1511 | AssignEnvironment(mul); |
| 1512 | } |
| 1513 | return DefineSameAsFirst(mul); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1514 | } else if (instr->representation().IsDouble()) { |
| 1515 | return DoArithmeticD(Token::MUL, instr); |
| 1516 | } else { |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1517 | return DoArithmeticT(Token::MUL, instr); |
| 1518 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1519 | } |
| 1520 | |
| 1521 | |
| 1522 | LInstruction* LChunkBuilder::DoSub(HSub* instr) { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1523 | if (instr->representation().IsSmiOrInteger32()) { |
| 1524 | ASSERT(instr->left()->representation().Equals(instr->representation())); |
| 1525 | ASSERT(instr->right()->representation().Equals(instr->representation())); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1526 | LOperand* left = UseRegisterAtStart(instr->left()); |
| 1527 | LOperand* right = UseOrConstantAtStart(instr->right()); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1528 | LSubI* sub = new(zone()) LSubI(left, right); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1529 | LInstruction* result = DefineSameAsFirst(sub); |
| 1530 | if (instr->CheckFlag(HValue::kCanOverflow)) { |
| 1531 | result = AssignEnvironment(result); |
| 1532 | } |
| 1533 | return result; |
| 1534 | } else if (instr->representation().IsDouble()) { |
| 1535 | return DoArithmeticD(Token::SUB, instr); |
| 1536 | } else { |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1537 | return DoArithmeticT(Token::SUB, instr); |
| 1538 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1539 | } |
| 1540 | |
| 1541 | |
| 1542 | LInstruction* LChunkBuilder::DoAdd(HAdd* instr) { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1543 | if (instr->representation().IsSmiOrInteger32()) { |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1544 | // Check to see if it would be advantageous to use an lea instruction rather |
| 1545 | // than an add. This is the case when no overflow check is needed and there |
| 1546 | // are multiple uses of the add's inputs, so using a 3-register add will |
| 1547 | // preserve all input values for later uses. |
| 1548 | bool use_lea = LAddI::UseLea(instr); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 1549 | ASSERT(instr->left()->representation().Equals(instr->representation())); |
| 1550 | ASSERT(instr->right()->representation().Equals(instr->representation())); |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1551 | LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand()); |
| 1552 | HValue* right_candidate = instr->BetterRightOperand(); |
| 1553 | LOperand* right = use_lea |
| 1554 | ? UseRegisterOrConstantAtStart(right_candidate) |
| 1555 | : UseOrConstantAtStart(right_candidate); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1556 | LAddI* add = new(zone()) LAddI(left, right); |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1557 | bool can_overflow = instr->CheckFlag(HValue::kCanOverflow); |
| 1558 | LInstruction* result = use_lea |
| 1559 | ? DefineAsRegister(add) |
| 1560 | : DefineSameAsFirst(add); |
| 1561 | if (can_overflow) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1562 | result = AssignEnvironment(result); |
| 1563 | } |
| 1564 | return result; |
| 1565 | } else if (instr->representation().IsDouble()) { |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1566 | return DoArithmeticD(Token::ADD, instr); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1567 | } else { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 1568 | return DoArithmeticT(Token::ADD, instr); |
| 1569 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1570 | return NULL; |
| 1571 | } |
| 1572 | |
| 1573 | |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1574 | LInstruction* LChunkBuilder::DoMathMinMax(HMathMinMax* instr) { |
| 1575 | LOperand* left = NULL; |
| 1576 | LOperand* right = NULL; |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 1577 | if (instr->representation().IsSmiOrInteger32()) { |
| 1578 | ASSERT(instr->left()->representation().Equals(instr->representation())); |
| 1579 | ASSERT(instr->right()->representation().Equals(instr->representation())); |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1580 | left = UseRegisterAtStart(instr->BetterLeftOperand()); |
| 1581 | right = UseOrConstantAtStart(instr->BetterRightOperand()); |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 1582 | } else { |
| 1583 | ASSERT(instr->representation().IsDouble()); |
| 1584 | ASSERT(instr->left()->representation().IsDouble()); |
| 1585 | ASSERT(instr->right()->representation().IsDouble()); |
| 1586 | left = UseRegisterAtStart(instr->left()); |
| 1587 | right = UseRegisterAtStart(instr->right()); |
| 1588 | } |
| 1589 | LMathMinMax* minmax = new(zone()) LMathMinMax(left, right); |
| 1590 | return DefineSameAsFirst(minmax); |
| 1591 | } |
| 1592 | |
| 1593 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1594 | LInstruction* LChunkBuilder::DoPower(HPower* instr) { |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1595 | ASSERT(instr->representation().IsDouble()); |
| 1596 | // We call a C function for double power. It can't trigger a GC. |
| 1597 | // We need to use fixed result register for the call. |
| 1598 | Representation exponent_type = instr->right()->representation(); |
| 1599 | ASSERT(instr->left()->representation().IsDouble()); |
| 1600 | LOperand* left = UseFixedDouble(instr->left(), xmm2); |
| 1601 | LOperand* right = exponent_type.IsDouble() ? |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 1602 | UseFixedDouble(instr->right(), xmm1) : UseFixed(instr->right(), rdx); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1603 | LPower* result = new(zone()) LPower(left, right); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1604 | return MarkAsCall(DefineFixedDouble(result, xmm3), instr, |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1605 | CAN_DEOPTIMIZE_EAGERLY); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1606 | } |
| 1607 | |
| 1608 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1609 | LInstruction* LChunkBuilder::DoRandom(HRandom* instr) { |
| 1610 | ASSERT(instr->representation().IsDouble()); |
| 1611 | ASSERT(instr->global_object()->representation().IsTagged()); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 1612 | LOperand* global_object = UseTempRegister(instr->global_object()); |
| 1613 | LOperand* scratch = TempRegister(); |
| 1614 | LOperand* scratch2 = TempRegister(); |
| 1615 | LOperand* scratch3 = TempRegister(); |
| 1616 | LRandom* result = new(zone()) LRandom( |
| 1617 | global_object, scratch, scratch2, scratch3); |
| 1618 | return DefineFixedDouble(result, xmm1); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1619 | } |
| 1620 | |
| 1621 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1622 | LInstruction* LChunkBuilder::DoCompareGeneric(HCompareGeneric* instr) { |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1623 | ASSERT(instr->left()->representation().IsTagged()); |
| 1624 | ASSERT(instr->right()->representation().IsTagged()); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 1625 | LOperand* context = UseFixed(instr->context(), rsi); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1626 | LOperand* left = UseFixed(instr->left(), rdx); |
| 1627 | LOperand* right = UseFixed(instr->right(), rax); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 1628 | LCmpT* result = new(zone()) LCmpT(context, left, right); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1629 | return MarkAsCall(DefineFixed(result, rax), instr); |
| 1630 | } |
| 1631 | |
| 1632 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 1633 | LInstruction* LChunkBuilder::DoCompareNumericAndBranch( |
| 1634 | HCompareNumericAndBranch* instr) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1635 | Representation r = instr->representation(); |
jkummerow@chromium.org | c118402 | 2013-05-28 16:58:15 +0000 | [diff] [blame] | 1636 | if (r.IsSmiOrInteger32()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 1637 | ASSERT(instr->left()->representation().Equals(r)); |
| 1638 | ASSERT(instr->right()->representation().Equals(r)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1639 | LOperand* left = UseRegisterOrConstantAtStart(instr->left()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1640 | LOperand* right = UseOrConstantAtStart(instr->right()); |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 1641 | return new(zone()) LCompareNumericAndBranch(left, right); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1642 | } else { |
| 1643 | ASSERT(r.IsDouble()); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1644 | ASSERT(instr->left()->representation().IsDouble()); |
| 1645 | ASSERT(instr->right()->representation().IsDouble()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1646 | LOperand* left; |
| 1647 | LOperand* right; |
| 1648 | if (instr->left()->IsConstant() && instr->right()->IsConstant()) { |
| 1649 | left = UseRegisterOrConstantAtStart(instr->left()); |
| 1650 | right = UseRegisterOrConstantAtStart(instr->right()); |
| 1651 | } else { |
| 1652 | left = UseRegisterAtStart(instr->left()); |
| 1653 | right = UseRegisterAtStart(instr->right()); |
| 1654 | } |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 1655 | return new(zone()) LCompareNumericAndBranch(left, right); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 1656 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1657 | } |
| 1658 | |
| 1659 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1660 | LInstruction* LChunkBuilder::DoCompareObjectEqAndBranch( |
| 1661 | HCompareObjectEqAndBranch* instr) { |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 1662 | LInstruction* goto_instr = CheckElideControlInstruction(instr); |
| 1663 | if (goto_instr != NULL) return goto_instr; |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1664 | LOperand* left = UseRegisterAtStart(instr->left()); |
mstarzinger@chromium.org | b228be0 | 2013-04-18 14:56:59 +0000 | [diff] [blame] | 1665 | LOperand* right = UseRegisterOrConstantAtStart(instr->right()); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1666 | return new(zone()) LCmpObjectEqAndBranch(left, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1667 | } |
| 1668 | |
| 1669 | |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 1670 | LInstruction* LChunkBuilder::DoCompareHoleAndBranch( |
| 1671 | HCompareHoleAndBranch* instr) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1672 | LOperand* value = UseRegisterAtStart(instr->value()); |
| 1673 | return new(zone()) LCmpHoleAndBranch(value); |
danno@chromium.org | c00ec2b | 2013-08-14 17:13:49 +0000 | [diff] [blame] | 1674 | } |
| 1675 | |
| 1676 | |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 1677 | LInstruction* LChunkBuilder::DoCompareMinusZeroAndBranch( |
| 1678 | HCompareMinusZeroAndBranch* instr) { |
| 1679 | LInstruction* goto_instr = CheckElideControlInstruction(instr); |
| 1680 | if (goto_instr != NULL) return goto_instr; |
| 1681 | LOperand* value = UseRegister(instr->value()); |
| 1682 | return new(zone()) LCompareMinusZeroAndBranch(value); |
| 1683 | } |
| 1684 | |
| 1685 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1686 | LInstruction* LChunkBuilder::DoIsObjectAndBranch(HIsObjectAndBranch* instr) { |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1687 | ASSERT(instr->value()->representation().IsTagged()); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1688 | return new(zone()) LIsObjectAndBranch(UseRegisterAtStart(instr->value())); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1689 | } |
| 1690 | |
| 1691 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 1692 | LInstruction* LChunkBuilder::DoIsStringAndBranch(HIsStringAndBranch* instr) { |
| 1693 | ASSERT(instr->value()->representation().IsTagged()); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1694 | LOperand* value = UseRegisterAtStart(instr->value()); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 1695 | LOperand* temp = TempRegister(); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1696 | return new(zone()) LIsStringAndBranch(value, temp); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 1697 | } |
| 1698 | |
| 1699 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1700 | LInstruction* LChunkBuilder::DoIsSmiAndBranch(HIsSmiAndBranch* instr) { |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1701 | ASSERT(instr->value()->representation().IsTagged()); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1702 | return new(zone()) LIsSmiAndBranch(Use(instr->value())); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1703 | } |
| 1704 | |
| 1705 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1706 | LInstruction* LChunkBuilder::DoIsUndetectableAndBranch( |
| 1707 | HIsUndetectableAndBranch* instr) { |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1708 | ASSERT(instr->value()->representation().IsTagged()); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1709 | LOperand* value = UseRegisterAtStart(instr->value()); |
| 1710 | LOperand* temp = TempRegister(); |
| 1711 | return new(zone()) LIsUndetectableAndBranch(value, temp); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1712 | } |
| 1713 | |
| 1714 | |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 1715 | LInstruction* LChunkBuilder::DoStringCompareAndBranch( |
| 1716 | HStringCompareAndBranch* instr) { |
| 1717 | |
| 1718 | ASSERT(instr->left()->representation().IsTagged()); |
| 1719 | ASSERT(instr->right()->representation().IsTagged()); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 1720 | LOperand* context = UseFixed(instr->context(), rsi); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 1721 | LOperand* left = UseFixed(instr->left(), rdx); |
| 1722 | LOperand* right = UseFixed(instr->right(), rax); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1723 | LStringCompareAndBranch* result = |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 1724 | new(zone()) LStringCompareAndBranch(context, left, right); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 1725 | |
| 1726 | return MarkAsCall(result, instr); |
| 1727 | } |
| 1728 | |
| 1729 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1730 | LInstruction* LChunkBuilder::DoHasInstanceTypeAndBranch( |
| 1731 | HHasInstanceTypeAndBranch* instr) { |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 1732 | ASSERT(instr->value()->representation().IsTagged()); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1733 | LOperand* value = UseRegisterAtStart(instr->value()); |
| 1734 | return new(zone()) LHasInstanceTypeAndBranch(value); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1735 | } |
| 1736 | |
| 1737 | |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1738 | LInstruction* LChunkBuilder::DoGetCachedArrayIndex( |
| 1739 | HGetCachedArrayIndex* instr) { |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 1740 | ASSERT(instr->value()->representation().IsTagged()); |
| 1741 | LOperand* value = UseRegisterAtStart(instr->value()); |
| 1742 | |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1743 | return DefineAsRegister(new(zone()) LGetCachedArrayIndex(value)); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1744 | } |
| 1745 | |
| 1746 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1747 | LInstruction* LChunkBuilder::DoHasCachedArrayIndexAndBranch( |
| 1748 | HHasCachedArrayIndexAndBranch* instr) { |
ager@chromium.org | 9ee27ae | 2011-03-02 13:43:26 +0000 | [diff] [blame] | 1749 | ASSERT(instr->value()->representation().IsTagged()); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1750 | LOperand* value = UseRegisterAtStart(instr->value()); |
| 1751 | return new(zone()) LHasCachedArrayIndexAndBranch(value); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1752 | } |
| 1753 | |
| 1754 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 1755 | LInstruction* LChunkBuilder::DoClassOfTestAndBranch( |
| 1756 | HClassOfTestAndBranch* instr) { |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1757 | LOperand* value = UseRegister(instr->value()); |
| 1758 | return new(zone()) LClassOfTestAndBranch(value, |
| 1759 | TempRegister(), |
| 1760 | TempRegister()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1761 | } |
| 1762 | |
| 1763 | |
yangguo@chromium.org | 355cfd1 | 2012-08-29 15:32:24 +0000 | [diff] [blame] | 1764 | LInstruction* LChunkBuilder::DoMapEnumLength(HMapEnumLength* instr) { |
| 1765 | LOperand* map = UseRegisterAtStart(instr->value()); |
| 1766 | return DefineAsRegister(new(zone()) LMapEnumLength(map)); |
| 1767 | } |
| 1768 | |
| 1769 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1770 | LInstruction* LChunkBuilder::DoElementsKind(HElementsKind* instr) { |
| 1771 | LOperand* object = UseRegisterAtStart(instr->value()); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1772 | return DefineAsRegister(new(zone()) LElementsKind(object)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1773 | } |
| 1774 | |
| 1775 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1776 | LInstruction* LChunkBuilder::DoValueOf(HValueOf* instr) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1777 | LOperand* object = UseRegister(instr->value()); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1778 | LValueOf* result = new(zone()) LValueOf(object); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1779 | return DefineSameAsFirst(result); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1780 | } |
| 1781 | |
| 1782 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 1783 | LInstruction* LChunkBuilder::DoDateField(HDateField* instr) { |
| 1784 | LOperand* object = UseFixed(instr->value(), rax); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1785 | LDateField* result = new(zone()) LDateField(object, instr->index()); |
mstarzinger@chromium.org | de88679 | 2012-09-11 13:22:37 +0000 | [diff] [blame] | 1786 | return MarkAsCall(DefineFixed(result, rax), instr, CAN_DEOPTIMIZE_EAGERLY); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 1787 | } |
| 1788 | |
| 1789 | |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 1790 | LInstruction* LChunkBuilder::DoSeqStringGetChar(HSeqStringGetChar* instr) { |
| 1791 | LOperand* string = UseRegisterAtStart(instr->string()); |
| 1792 | LOperand* index = UseRegisterOrConstantAtStart(instr->index()); |
| 1793 | return DefineAsRegister(new(zone()) LSeqStringGetChar(string, index)); |
| 1794 | } |
| 1795 | |
| 1796 | |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1797 | LInstruction* LChunkBuilder::DoSeqStringSetChar(HSeqStringSetChar* instr) { |
machenbach@chromium.org | e8412be | 2013-11-08 10:23:52 +0000 | [diff] [blame] | 1798 | LOperand* string = UseRegisterAtStart(instr->string()); |
| 1799 | LOperand* index = UseRegisterOrConstantAtStart(instr->index()); |
| 1800 | LOperand* value = UseRegisterOrConstantAtStart(instr->value()); |
| 1801 | return new(zone()) LSeqStringSetChar(string, index, value); |
mstarzinger@chromium.org | 32280cf | 2012-12-06 17:32:37 +0000 | [diff] [blame] | 1802 | } |
| 1803 | |
| 1804 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1805 | LInstruction* LChunkBuilder::DoBoundsCheck(HBoundsCheck* instr) { |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1806 | LOperand* value = UseRegisterOrConstantAtStart(instr->index()); |
| 1807 | LOperand* length = Use(instr->length()); |
| 1808 | return AssignEnvironment(new(zone()) LBoundsCheck(value, length)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1809 | } |
| 1810 | |
| 1811 | |
svenpanne@chromium.org | 876cca8 | 2013-03-18 14:43:20 +0000 | [diff] [blame] | 1812 | LInstruction* LChunkBuilder::DoBoundsCheckBaseIndexInformation( |
| 1813 | HBoundsCheckBaseIndexInformation* instr) { |
| 1814 | UNREACHABLE(); |
| 1815 | return NULL; |
| 1816 | } |
| 1817 | |
| 1818 | |
jkummerow@chromium.org | c366976 | 2013-09-30 13:42:25 +0000 | [diff] [blame] | 1819 | LInstruction* LChunkBuilder::DoAbnormalExit(HAbnormalExit* instr) { |
| 1820 | // The control instruction marking the end of a block that completed |
| 1821 | // abruptly (e.g., threw an exception). There is nothing specific to do. |
| 1822 | return NULL; |
| 1823 | } |
| 1824 | |
| 1825 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1826 | LInstruction* LChunkBuilder::DoThrow(HThrow* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 1827 | LOperand* context = UseFixed(instr->context(), rsi); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 1828 | LOperand* value = UseFixed(instr->value(), rax); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 1829 | return MarkAsCall(new(zone()) LThrow(context, value), instr); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1830 | } |
| 1831 | |
| 1832 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 1833 | LInstruction* LChunkBuilder::DoUseConst(HUseConst* instr) { |
| 1834 | return NULL; |
| 1835 | } |
| 1836 | |
| 1837 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1838 | LInstruction* LChunkBuilder::DoForceRepresentation(HForceRepresentation* bad) { |
| 1839 | // All HForceRepresentation instructions should be eliminated in the |
| 1840 | // representation change phase of Hydrogen. |
| 1841 | UNREACHABLE(); |
| 1842 | return NULL; |
| 1843 | } |
| 1844 | |
| 1845 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1846 | LInstruction* LChunkBuilder::DoChange(HChange* instr) { |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1847 | Representation from = instr->from(); |
| 1848 | Representation to = instr->to(); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 1849 | if (from.IsSmi()) { |
| 1850 | if (to.IsTagged()) { |
| 1851 | LOperand* value = UseRegister(instr->value()); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 1852 | return DefineSameAsFirst(new(zone()) LDummyUse(value)); |
| 1853 | } |
| 1854 | from = Representation::Tagged(); |
| 1855 | } |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1856 | // Only mark conversions that might need to allocate as calling rather than |
| 1857 | // all changes. This makes simple, non-allocating conversion not have to force |
| 1858 | // building a stack frame. |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1859 | if (from.IsTagged()) { |
| 1860 | if (to.IsDouble()) { |
| 1861 | LOperand* value = UseRegister(instr->value()); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1862 | LNumberUntagD* res = new(zone()) LNumberUntagD(value); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1863 | return AssignEnvironment(DefineAsRegister(res)); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 1864 | } else if (to.IsSmi()) { |
| 1865 | HValue* val = instr->value(); |
| 1866 | LOperand* value = UseRegister(val); |
| 1867 | if (val->type().IsSmi()) { |
| 1868 | return DefineSameAsFirst(new(zone()) LDummyUse(value)); |
| 1869 | } |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 1870 | return AssignEnvironment(DefineSameAsFirst(new(zone()) LCheckSmi(value))); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1871 | } else { |
| 1872 | ASSERT(to.IsInteger32()); |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 1873 | HValue* val = instr->value(); |
| 1874 | LOperand* value = UseRegister(val); |
| 1875 | if (val->type().IsSmi() || val->representation().IsSmi()) { |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 1876 | return DefineSameAsFirst(new(zone()) LSmiUntag(value, false)); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1877 | } else { |
ricow@chromium.org | c54d365 | 2011-05-30 09:20:16 +0000 | [diff] [blame] | 1878 | bool truncating = instr->CanTruncateToInt32(); |
| 1879 | LOperand* xmm_temp = truncating ? NULL : FixedTemp(xmm1); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1880 | LTaggedToI* res = new(zone()) LTaggedToI(value, xmm_temp); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1881 | return AssignEnvironment(DefineSameAsFirst(res)); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1882 | } |
| 1883 | } |
| 1884 | } else if (from.IsDouble()) { |
| 1885 | if (to.IsTagged()) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1886 | info()->MarkAsDeferredCalling(); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1887 | LOperand* value = UseRegister(instr->value()); |
| 1888 | LOperand* temp = TempRegister(); |
| 1889 | |
| 1890 | // Make sure that temp and result_temp are different registers. |
| 1891 | LUnallocated* result_temp = TempRegister(); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1892 | LNumberTagD* result = new(zone()) LNumberTagD(value, temp); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1893 | return AssignPointerMap(Define(result, result_temp)); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 1894 | } else if (to.IsSmi()) { |
| 1895 | LOperand* value = UseRegister(instr->value()); |
| 1896 | return AssignEnvironment( |
| 1897 | DefineAsRegister(new(zone()) LDoubleToSmi(value))); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1898 | } else { |
| 1899 | ASSERT(to.IsInteger32()); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1900 | LOperand* value = UseRegister(instr->value()); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 1901 | return AssignEnvironment( |
| 1902 | DefineAsRegister(new(zone()) LDoubleToI(value))); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1903 | } |
| 1904 | } else if (from.IsInteger32()) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1905 | info()->MarkAsDeferredCalling(); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1906 | if (to.IsTagged()) { |
| 1907 | HValue* val = instr->value(); |
| 1908 | LOperand* value = UseRegister(val); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1909 | if (val->CheckFlag(HInstruction::kUint32)) { |
| 1910 | LOperand* temp = FixedTemp(xmm1); |
| 1911 | LNumberTagU* result = new(zone()) LNumberTagU(value, temp); |
| 1912 | return AssignEnvironment(AssignPointerMap(DefineSameAsFirst(result))); |
| 1913 | } else if (val->HasRange() && val->range()->IsInSmiRange()) { |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1914 | return DefineSameAsFirst(new(zone()) LSmiTag(value)); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1915 | } else { |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1916 | LNumberTagI* result = new(zone()) LNumberTagI(value); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1917 | return AssignEnvironment(AssignPointerMap(DefineSameAsFirst(result))); |
| 1918 | } |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 1919 | } else if (to.IsSmi()) { |
| 1920 | HValue* val = instr->value(); |
| 1921 | LOperand* value = UseRegister(val); |
machenbach@chromium.org | ed29eb2 | 2013-10-31 13:30:00 +0000 | [diff] [blame] | 1922 | LInstruction* result = NULL; |
| 1923 | if (val->CheckFlag(HInstruction::kUint32)) { |
| 1924 | result = DefineAsRegister(new(zone()) LUint32ToSmi(value)); |
| 1925 | if (val->HasRange() && val->range()->IsInSmiRange() && |
| 1926 | val->range()->upper() != kMaxInt) { |
| 1927 | return result; |
| 1928 | } |
| 1929 | } else { |
| 1930 | result = DefineAsRegister(new(zone()) LInteger32ToSmi(value)); |
| 1931 | if (val->HasRange() && val->range()->IsInSmiRange()) { |
| 1932 | return result; |
| 1933 | } |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 1934 | } |
| 1935 | return AssignEnvironment(result); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1936 | } else { |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1937 | if (instr->value()->CheckFlag(HInstruction::kUint32)) { |
| 1938 | LOperand* temp = FixedTemp(xmm1); |
| 1939 | return DefineAsRegister( |
| 1940 | new(zone()) LUint32ToDouble(UseRegister(instr->value()), temp)); |
| 1941 | } else { |
| 1942 | ASSERT(to.IsDouble()); |
| 1943 | LOperand* value = Use(instr->value()); |
| 1944 | return DefineAsRegister(new(zone()) LInteger32ToDouble(value)); |
| 1945 | } |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1946 | } |
| 1947 | } |
| 1948 | UNREACHABLE(); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1949 | return NULL; |
| 1950 | } |
| 1951 | |
| 1952 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1953 | LInstruction* LChunkBuilder::DoCheckHeapObject(HCheckHeapObject* instr) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1954 | LOperand* value = UseRegisterAtStart(instr->value()); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1955 | return AssignEnvironment(new(zone()) LCheckNonSmi(value)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1956 | } |
| 1957 | |
| 1958 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 1959 | LInstruction* LChunkBuilder::DoCheckSmi(HCheckSmi* instr) { |
| 1960 | LOperand* value = UseRegisterAtStart(instr->value()); |
| 1961 | return AssignEnvironment(new(zone()) LCheckSmi(value)); |
| 1962 | } |
| 1963 | |
| 1964 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1965 | LInstruction* LChunkBuilder::DoCheckInstanceType(HCheckInstanceType* instr) { |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1966 | LOperand* value = UseRegisterAtStart(instr->value()); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 1967 | LCheckInstanceType* result = new(zone()) LCheckInstanceType(value); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 1968 | return AssignEnvironment(result); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1969 | } |
| 1970 | |
| 1971 | |
mstarzinger@chromium.org | 1f410f9 | 2013-08-29 08:13:16 +0000 | [diff] [blame] | 1972 | LInstruction* LChunkBuilder::DoCheckValue(HCheckValue* instr) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 1973 | LOperand* value = UseRegisterAtStart(instr->value()); |
mstarzinger@chromium.org | 1f410f9 | 2013-08-29 08:13:16 +0000 | [diff] [blame] | 1974 | return AssignEnvironment(new(zone()) LCheckValue(value)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1975 | } |
| 1976 | |
| 1977 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 1978 | LInstruction* LChunkBuilder::DoCheckMaps(HCheckMaps* instr) { |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 1979 | LOperand* value = NULL; |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 1980 | if (!instr->CanOmitMapChecks()) { |
| 1981 | value = UseRegisterAtStart(instr->value()); |
| 1982 | if (instr->has_migration_target()) info()->MarkAsDeferredCalling(); |
| 1983 | } |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 1984 | LCheckMaps* result = new(zone()) LCheckMaps(value); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 1985 | if (!instr->CanOmitMapChecks()) { |
| 1986 | AssignEnvironment(result); |
| 1987 | if (instr->has_migration_target()) return AssignPointerMap(result); |
| 1988 | } |
| 1989 | return result; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 1990 | } |
| 1991 | |
| 1992 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1993 | LInstruction* LChunkBuilder::DoClampToUint8(HClampToUint8* instr) { |
| 1994 | HValue* value = instr->value(); |
| 1995 | Representation input_rep = value->representation(); |
| 1996 | LOperand* reg = UseRegister(value); |
| 1997 | if (input_rep.IsDouble()) { |
rossberg@chromium.org | 89e18f5 | 2012-10-22 13:09:53 +0000 | [diff] [blame] | 1998 | return DefineAsRegister(new(zone()) LClampDToUint8(reg)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1999 | } else if (input_rep.IsInteger32()) { |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 2000 | return DefineSameAsFirst(new(zone()) LClampIToUint8(reg)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2001 | } else { |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 2002 | ASSERT(input_rep.IsSmiOrTagged()); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2003 | // Register allocator doesn't (yet) support allocation of double |
| 2004 | // temps. Reserve xmm1 explicitly. |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 2005 | LClampTToUint8* result = new(zone()) LClampTToUint8(reg, |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 2006 | FixedTemp(xmm1)); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2007 | return AssignEnvironment(DefineSameAsFirst(result)); |
| 2008 | } |
| 2009 | } |
| 2010 | |
| 2011 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2012 | LInstruction* LChunkBuilder::DoReturn(HReturn* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2013 | LOperand* context = info()->IsStub() ? UseFixed(instr->context(), rsi) : NULL; |
ulan@chromium.org | 6e196bf | 2013-03-13 09:38:22 +0000 | [diff] [blame] | 2014 | LOperand* parameter_count = UseRegisterOrConstant(instr->parameter_count()); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2015 | return new(zone()) LReturn( |
| 2016 | UseFixed(instr->value(), rax), context, parameter_count); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2017 | } |
| 2018 | |
| 2019 | |
| 2020 | LInstruction* LChunkBuilder::DoConstant(HConstant* instr) { |
| 2021 | Representation r = instr->representation(); |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 2022 | if (r.IsSmi()) { |
| 2023 | return DefineAsRegister(new(zone()) LConstantS); |
| 2024 | } else if (r.IsInteger32()) { |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 2025 | return DefineAsRegister(new(zone()) LConstantI); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2026 | } else if (r.IsDouble()) { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2027 | LOperand* temp = TempRegister(); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 2028 | return DefineAsRegister(new(zone()) LConstantD(temp)); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 2029 | } else if (r.IsExternal()) { |
| 2030 | return DefineAsRegister(new(zone()) LConstantE); |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 2031 | } else if (r.IsTagged()) { |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 2032 | return DefineAsRegister(new(zone()) LConstantT); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2033 | } else { |
| 2034 | UNREACHABLE(); |
| 2035 | return NULL; |
| 2036 | } |
| 2037 | } |
| 2038 | |
| 2039 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2040 | LInstruction* LChunkBuilder::DoLoadGlobalCell(HLoadGlobalCell* instr) { |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 2041 | LLoadGlobalCell* result = new(zone()) LLoadGlobalCell; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2042 | return instr->RequiresHoleCheck() |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2043 | ? AssignEnvironment(DefineAsRegister(result)) |
| 2044 | : DefineAsRegister(result); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2045 | } |
| 2046 | |
| 2047 | |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2048 | LInstruction* LChunkBuilder::DoLoadGlobalGeneric(HLoadGlobalGeneric* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2049 | LOperand* context = UseFixed(instr->context(), rsi); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2050 | LOperand* global_object = UseFixed(instr->global_object(), rax); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2051 | LLoadGlobalGeneric* result = |
| 2052 | new(zone()) LLoadGlobalGeneric(context, global_object); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2053 | return MarkAsCall(DefineFixed(result, rax), instr); |
| 2054 | } |
| 2055 | |
| 2056 | |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 2057 | LInstruction* LChunkBuilder::DoStoreGlobalCell(HStoreGlobalCell* instr) { |
danno@chromium.org | e78f9fc | 2011-12-21 08:29:34 +0000 | [diff] [blame] | 2058 | LOperand* value = UseRegister(instr->value()); |
| 2059 | // Use a temp to avoid reloading the cell value address in the case where |
| 2060 | // we perform a hole check. |
| 2061 | return instr->RequiresHoleCheck() |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 2062 | ? AssignEnvironment(new(zone()) LStoreGlobalCell(value, TempRegister())) |
| 2063 | : new(zone()) LStoreGlobalCell(value, NULL); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2064 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2065 | |
| 2066 | |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 2067 | LInstruction* LChunkBuilder::DoStoreGlobalGeneric(HStoreGlobalGeneric* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2068 | LOperand* context = UseFixed(instr->context(), rsi); |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 2069 | LOperand* global_object = UseFixed(instr->global_object(), rdx); |
| 2070 | LOperand* value = UseFixed(instr->value(), rax); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2071 | LStoreGlobalGeneric* result = |
| 2072 | new(zone()) LStoreGlobalGeneric(context, global_object, value); |
vegorov@chromium.org | 74f333b | 2011-04-06 11:17:46 +0000 | [diff] [blame] | 2073 | return MarkAsCall(result, instr); |
| 2074 | } |
| 2075 | |
| 2076 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2077 | LInstruction* LChunkBuilder::DoLoadContextSlot(HLoadContextSlot* instr) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2078 | LOperand* context = UseRegisterAtStart(instr->value()); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 2079 | LInstruction* result = |
| 2080 | DefineAsRegister(new(zone()) LLoadContextSlot(context)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2081 | return instr->RequiresHoleCheck() ? AssignEnvironment(result) : result; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2082 | } |
| 2083 | |
| 2084 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2085 | LInstruction* LChunkBuilder::DoStoreContextSlot(HStoreContextSlot* instr) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2086 | LOperand* context; |
| 2087 | LOperand* value; |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 2088 | LOperand* temp; |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2089 | context = UseRegister(instr->context()); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2090 | if (instr->NeedsWriteBarrier()) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2091 | value = UseTempRegister(instr->value()); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 2092 | temp = TempRegister(); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2093 | } else { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2094 | value = UseRegister(instr->value()); |
karlklose@chromium.org | 8f806e8 | 2011-03-07 14:06:08 +0000 | [diff] [blame] | 2095 | temp = NULL; |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2096 | } |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 2097 | LInstruction* result = new(zone()) LStoreContextSlot(context, value, temp); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2098 | return instr->RequiresHoleCheck() ? AssignEnvironment(result) : result; |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2099 | } |
| 2100 | |
| 2101 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2102 | LInstruction* LChunkBuilder::DoLoadNamedField(HLoadNamedField* instr) { |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 2103 | // Use the special mov rax, moffs64 encoding for external |
| 2104 | // memory accesses with 64-bit word-sized values. |
| 2105 | if (instr->access().IsExternalMemory() && |
| 2106 | instr->access().offset() == 0 && |
| 2107 | (instr->access().representation().IsSmi() || |
| 2108 | instr->access().representation().IsTagged() || |
| 2109 | instr->access().representation().IsHeapObject() || |
| 2110 | instr->access().representation().IsExternal())) { |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 2111 | LOperand* obj = UseRegisterOrConstantAtStart(instr->object()); |
| 2112 | return DefineFixed(new(zone()) LLoadNamedField(obj), rax); |
| 2113 | } |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2114 | LOperand* obj = UseRegisterAtStart(instr->object()); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 2115 | return DefineAsRegister(new(zone()) LLoadNamedField(obj)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2116 | } |
| 2117 | |
| 2118 | |
| 2119 | LInstruction* LChunkBuilder::DoLoadNamedGeneric(HLoadNamedGeneric* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2120 | LOperand* context = UseFixed(instr->context(), rsi); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 2121 | LOperand* object = UseFixed(instr->object(), rax); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2122 | LLoadNamedGeneric* result = new(zone()) LLoadNamedGeneric(context, object); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 2123 | return MarkAsCall(DefineFixed(result, rax), instr); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2124 | } |
| 2125 | |
| 2126 | |
| 2127 | LInstruction* LChunkBuilder::DoLoadFunctionPrototype( |
| 2128 | HLoadFunctionPrototype* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2129 | return AssignEnvironment(DefineAsRegister( |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 2130 | new(zone()) LLoadFunctionPrototype(UseRegister(instr->function())))); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2131 | } |
| 2132 | |
| 2133 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2134 | LInstruction* LChunkBuilder::DoLoadRoot(HLoadRoot* instr) { |
| 2135 | return DefineAsRegister(new(zone()) LLoadRoot); |
| 2136 | } |
| 2137 | |
| 2138 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 2139 | LInstruction* LChunkBuilder::DoLoadExternalArrayPointer( |
| 2140 | HLoadExternalArrayPointer* instr) { |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2141 | LOperand* input = UseRegisterAtStart(instr->value()); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 2142 | return DefineAsRegister(new(zone()) LLoadExternalArrayPointer(input)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2143 | } |
| 2144 | |
| 2145 | |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 2146 | LInstruction* LChunkBuilder::DoLoadKeyed(HLoadKeyed* instr) { |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 2147 | ASSERT(instr->key()->representation().IsInteger32()); |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 2148 | ElementsKind elements_kind = instr->elements_kind(); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 2149 | LOperand* key = UseRegisterOrConstantAtStart(instr->key()); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2150 | LLoadKeyed* result = NULL; |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 2151 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2152 | if (!instr->is_external()) { |
| 2153 | LOperand* obj = UseRegisterAtStart(instr->elements()); |
| 2154 | result = new(zone()) LLoadKeyed(obj, key); |
| 2155 | } else { |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 2156 | ASSERT( |
| 2157 | (instr->representation().IsInteger32() && |
| 2158 | (elements_kind != EXTERNAL_FLOAT_ELEMENTS) && |
| 2159 | (elements_kind != EXTERNAL_DOUBLE_ELEMENTS)) || |
| 2160 | (instr->representation().IsDouble() && |
| 2161 | ((elements_kind == EXTERNAL_FLOAT_ELEMENTS) || |
| 2162 | (elements_kind == EXTERNAL_DOUBLE_ELEMENTS)))); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2163 | LOperand* external_pointer = UseRegister(instr->elements()); |
| 2164 | result = new(zone()) LLoadKeyed(external_pointer, key); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 2165 | } |
| 2166 | |
| 2167 | DefineAsRegister(result); |
| 2168 | bool can_deoptimize = instr->RequiresHoleCheck() || |
| 2169 | (elements_kind == EXTERNAL_UNSIGNED_INT_ELEMENTS); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2170 | // An unsigned int array load might overflow and cause a deopt, make sure it |
| 2171 | // has an environment. |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 2172 | return can_deoptimize ? AssignEnvironment(result) : result; |
sgjesse@chromium.org | 496c03a | 2011-02-14 12:05:43 +0000 | [diff] [blame] | 2173 | } |
| 2174 | |
| 2175 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2176 | LInstruction* LChunkBuilder::DoLoadKeyedGeneric(HLoadKeyedGeneric* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2177 | LOperand* context = UseFixed(instr->context(), rsi); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2178 | LOperand* object = UseFixed(instr->object(), rdx); |
| 2179 | LOperand* key = UseFixed(instr->key(), rax); |
| 2180 | |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2181 | LLoadKeyedGeneric* result = |
| 2182 | new(zone()) LLoadKeyedGeneric(context, object, key); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2183 | return MarkAsCall(DefineFixed(result, rax), instr); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2184 | } |
| 2185 | |
| 2186 | |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 2187 | LInstruction* LChunkBuilder::DoStoreKeyed(HStoreKeyed* instr) { |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2188 | ElementsKind elements_kind = instr->elements_kind(); |
verwaest@chromium.org | e4ee6de | 2012-11-06 12:13:00 +0000 | [diff] [blame] | 2189 | |
| 2190 | if (!instr->is_external()) { |
| 2191 | ASSERT(instr->elements()->representation().IsTagged()); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 2192 | bool needs_write_barrier = instr->NeedsWriteBarrier(); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2193 | LOperand* object = NULL; |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 2194 | LOperand* key = NULL; |
| 2195 | LOperand* val = NULL; |
| 2196 | |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2197 | if (instr->value()->representation().IsDouble()) { |
| 2198 | object = UseRegisterAtStart(instr->elements()); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 2199 | val = UseTempRegister(instr->value()); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 2200 | key = UseRegisterOrConstantAtStart(instr->key()); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2201 | } else { |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 2202 | ASSERT(instr->value()->representation().IsSmiOrTagged()); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2203 | object = UseTempRegister(instr->elements()); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 2204 | if (needs_write_barrier) { |
| 2205 | val = UseTempRegister(instr->value()); |
| 2206 | key = UseTempRegister(instr->key()); |
| 2207 | } else { |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 2208 | val = UseRegisterOrConstantAtStart(instr->value()); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 2209 | key = UseRegisterOrConstantAtStart(instr->key()); |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 2210 | } |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2211 | } |
| 2212 | |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 2213 | return new(zone()) LStoreKeyed(object, key, val); |
yangguo@chromium.org | eeb44b6 | 2012-11-13 13:56:09 +0000 | [diff] [blame] | 2214 | } |
| 2215 | |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 2216 | ASSERT( |
| 2217 | (instr->value()->representation().IsInteger32() && |
| 2218 | (elements_kind != EXTERNAL_FLOAT_ELEMENTS) && |
| 2219 | (elements_kind != EXTERNAL_DOUBLE_ELEMENTS)) || |
| 2220 | (instr->value()->representation().IsDouble() && |
| 2221 | ((elements_kind == EXTERNAL_FLOAT_ELEMENTS) || |
| 2222 | (elements_kind == EXTERNAL_DOUBLE_ELEMENTS)))); |
| 2223 | ASSERT(instr->elements()->representation().IsExternal()); |
| 2224 | bool val_is_temp_register = |
| 2225 | elements_kind == EXTERNAL_PIXEL_ELEMENTS || |
| 2226 | elements_kind == EXTERNAL_FLOAT_ELEMENTS; |
| 2227 | LOperand* val = val_is_temp_register ? UseTempRegister(instr->value()) |
| 2228 | : UseRegister(instr->value()); |
jkummerow@chromium.org | fb732b1 | 2013-07-26 10:27:09 +0000 | [diff] [blame] | 2229 | LOperand* key = UseRegisterOrConstantAtStart(instr->key()); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 2230 | LOperand* external_pointer = UseRegister(instr->elements()); |
| 2231 | return new(zone()) LStoreKeyed(external_pointer, key, val); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2232 | } |
| 2233 | |
| 2234 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2235 | LInstruction* LChunkBuilder::DoStoreKeyedGeneric(HStoreKeyedGeneric* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2236 | LOperand* context = UseFixed(instr->context(), rsi); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2237 | LOperand* object = UseFixed(instr->object(), rdx); |
| 2238 | LOperand* key = UseFixed(instr->key(), rcx); |
| 2239 | LOperand* value = UseFixed(instr->value(), rax); |
| 2240 | |
| 2241 | ASSERT(instr->object()->representation().IsTagged()); |
| 2242 | ASSERT(instr->key()->representation().IsTagged()); |
| 2243 | ASSERT(instr->value()->representation().IsTagged()); |
| 2244 | |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 2245 | LStoreKeyedGeneric* result = |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2246 | new(zone()) LStoreKeyedGeneric(context, object, key, value); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2247 | return MarkAsCall(result, instr); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2248 | } |
| 2249 | |
| 2250 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2251 | LInstruction* LChunkBuilder::DoTransitionElementsKind( |
| 2252 | HTransitionElementsKind* instr) { |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 2253 | LOperand* object = UseRegister(instr->object()); |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 2254 | if (IsSimpleMapChangeTransition(instr->from_kind(), instr->to_kind())) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2255 | LOperand* object = UseRegister(instr->object()); |
| 2256 | LOperand* new_map_reg = TempRegister(); |
| 2257 | LOperand* temp_reg = TempRegister(); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2258 | LTransitionElementsKind* result = new(zone()) LTransitionElementsKind( |
| 2259 | object, NULL, new_map_reg, temp_reg); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 2260 | return result; |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 2261 | } else { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2262 | LOperand* context = UseAny(instr->context()); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 2263 | LTransitionElementsKind* result = |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2264 | new(zone()) LTransitionElementsKind(object, context, NULL, NULL); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 2265 | return AssignPointerMap(result); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2266 | } |
| 2267 | } |
| 2268 | |
| 2269 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 2270 | LInstruction* LChunkBuilder::DoTrapAllocationMemento( |
| 2271 | HTrapAllocationMemento* instr) { |
| 2272 | LOperand* object = UseRegister(instr->object()); |
| 2273 | LOperand* temp = TempRegister(); |
| 2274 | LTrapAllocationMemento* result = |
| 2275 | new(zone()) LTrapAllocationMemento(object, temp); |
| 2276 | return AssignEnvironment(result); |
| 2277 | } |
| 2278 | |
| 2279 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2280 | LInstruction* LChunkBuilder::DoStoreNamedField(HStoreNamedField* instr) { |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 2281 | bool is_in_object = instr->access().IsInobject(); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 2282 | bool is_external_location = instr->access().IsExternalMemory() && |
| 2283 | instr->access().offset() == 0; |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2284 | bool needs_write_barrier = instr->NeedsWriteBarrier(); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 2285 | bool needs_write_barrier_for_map = instr->has_transition() && |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 2286 | instr->NeedsWriteBarrierForMap(); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2287 | |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 2288 | LOperand* obj; |
| 2289 | if (needs_write_barrier) { |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 2290 | obj = is_in_object |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 2291 | ? UseRegister(instr->object()) |
| 2292 | : UseTempRegister(instr->object()); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 2293 | } else if (is_external_location) { |
| 2294 | ASSERT(!is_in_object); |
| 2295 | ASSERT(!needs_write_barrier); |
| 2296 | ASSERT(!needs_write_barrier_for_map); |
| 2297 | obj = UseRegisterOrConstant(instr->object()); |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 2298 | } else { |
| 2299 | obj = needs_write_barrier_for_map |
| 2300 | ? UseRegister(instr->object()) |
| 2301 | : UseRegisterAtStart(instr->object()); |
| 2302 | } |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2303 | |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 2304 | bool can_be_constant = instr->value()->IsConstant() && |
| 2305 | HConstant::cast(instr->value())->NotInNewSpace() && |
| 2306 | !(FLAG_track_double_fields && instr->field_representation().IsDouble()); |
| 2307 | |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 2308 | LOperand* val; |
| 2309 | if (needs_write_barrier) { |
| 2310 | val = UseTempRegister(instr->value()); |
danno@chromium.org | d3c4210 | 2013-08-01 16:58:23 +0000 | [diff] [blame] | 2311 | } else if (is_external_location) { |
| 2312 | val = UseFixed(instr->value(), rax); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 2313 | } else if (can_be_constant) { |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 2314 | val = UseRegisterOrConstant(instr->value()); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 2315 | } else if (FLAG_track_fields && instr->field_representation().IsSmi()) { |
| 2316 | val = UseTempRegister(instr->value()); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 2317 | } else if (FLAG_track_double_fields && |
| 2318 | instr->field_representation().IsDouble()) { |
| 2319 | val = UseRegisterAtStart(instr->value()); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 2320 | } else { |
| 2321 | val = UseRegister(instr->value()); |
| 2322 | } |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2323 | |
| 2324 | // We only need a scratch register if we have a write barrier or we |
| 2325 | // have a store into the properties array (not in-object-property). |
svenpanne@chromium.org | 53ad175 | 2013-05-27 12:20:38 +0000 | [diff] [blame] | 2326 | LOperand* temp = (!is_in_object || needs_write_barrier || |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 2327 | needs_write_barrier_for_map) ? TempRegister() : NULL; |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2328 | |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 2329 | LStoreNamedField* result = new(zone()) LStoreNamedField(obj, val, temp); |
danno@chromium.org | 1fd77d5 | 2013-06-07 16:01:45 +0000 | [diff] [blame] | 2330 | if (FLAG_track_heap_object_fields && |
| 2331 | instr->field_representation().IsHeapObject()) { |
| 2332 | if (!instr->value()->type().IsHeapObject()) { |
| 2333 | return AssignEnvironment(result); |
| 2334 | } |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 2335 | } |
| 2336 | return result; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2337 | } |
| 2338 | |
| 2339 | |
| 2340 | LInstruction* LChunkBuilder::DoStoreNamedGeneric(HStoreNamedGeneric* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2341 | LOperand* context = UseFixed(instr->context(), rsi); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2342 | LOperand* object = UseFixed(instr->object(), rdx); |
| 2343 | LOperand* value = UseFixed(instr->value(), rax); |
| 2344 | |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2345 | LStoreNamedGeneric* result = |
| 2346 | new(zone()) LStoreNamedGeneric(context, object, value); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2347 | return MarkAsCall(result, instr); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2348 | } |
| 2349 | |
| 2350 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 2351 | LInstruction* LChunkBuilder::DoStringAdd(HStringAdd* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2352 | LOperand* context = UseFixed(instr->context(), rsi); |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 2353 | LOperand* left = FLAG_new_string_add |
| 2354 | ? UseFixed(instr->left(), rdx) |
| 2355 | : UseOrConstantAtStart(instr->left()); |
| 2356 | LOperand* right = FLAG_new_string_add |
| 2357 | ? UseFixed(instr->right(), rax) |
| 2358 | : UseOrConstantAtStart(instr->right()); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2359 | return MarkAsCall( |
| 2360 | DefineFixed(new(zone()) LStringAdd(context, left, right), rax), instr); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 2361 | } |
| 2362 | |
| 2363 | |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2364 | LInstruction* LChunkBuilder::DoStringCharCodeAt(HStringCharCodeAt* instr) { |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2365 | LOperand* string = UseTempRegister(instr->string()); |
| 2366 | LOperand* index = UseTempRegister(instr->index()); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2367 | LOperand* context = UseAny(instr->context()); |
| 2368 | LStringCharCodeAt* result = |
| 2369 | new(zone()) LStringCharCodeAt(context, string, index); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2370 | return AssignEnvironment(AssignPointerMap(DefineAsRegister(result))); |
vegorov@chromium.org | 0a4e901 | 2011-01-24 12:33:13 +0000 | [diff] [blame] | 2371 | } |
| 2372 | |
| 2373 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 2374 | LInstruction* LChunkBuilder::DoStringCharFromCode(HStringCharFromCode* instr) { |
| 2375 | LOperand* char_code = UseRegister(instr->value()); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2376 | LOperand* context = UseAny(instr->context()); |
| 2377 | LStringCharFromCode* result = |
| 2378 | new(zone()) LStringCharFromCode(context, char_code); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 2379 | return AssignPointerMap(DefineAsRegister(result)); |
| 2380 | } |
| 2381 | |
| 2382 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 2383 | LInstruction* LChunkBuilder::DoAllocate(HAllocate* instr) { |
| 2384 | info()->MarkAsDeferredCalling(); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2385 | LOperand* context = UseAny(instr->context()); |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 2386 | LOperand* size = instr->size()->IsConstant() |
| 2387 | ? UseConstant(instr->size()) |
| 2388 | : UseTempRegister(instr->size()); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 2389 | LOperand* temp = TempRegister(); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2390 | LAllocate* result = new(zone()) LAllocate(context, size, temp); |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 2391 | return AssignPointerMap(DefineAsRegister(result)); |
| 2392 | } |
| 2393 | |
| 2394 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2395 | LInstruction* LChunkBuilder::DoRegExpLiteral(HRegExpLiteral* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2396 | LOperand* context = UseFixed(instr->context(), rsi); |
| 2397 | LRegExpLiteral* result = new(zone()) LRegExpLiteral(context); |
| 2398 | return MarkAsCall(DefineFixed(result, rax), instr); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2399 | } |
| 2400 | |
| 2401 | |
| 2402 | LInstruction* LChunkBuilder::DoFunctionLiteral(HFunctionLiteral* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2403 | LOperand* context = UseFixed(instr->context(), rsi); |
| 2404 | LFunctionLiteral* result = new(zone()) LFunctionLiteral(context); |
| 2405 | return MarkAsCall(DefineFixed(result, rax), instr); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2406 | } |
| 2407 | |
| 2408 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2409 | LInstruction* LChunkBuilder::DoOsrEntry(HOsrEntry* instr) { |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2410 | ASSERT(argument_count_ == 0); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2411 | allocator_->MarkAsOsrEntry(); |
| 2412 | current_block_->last_environment()->set_ast_id(instr->ast_id()); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 2413 | return AssignEnvironment(new(zone()) LOsrEntry); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2414 | } |
| 2415 | |
| 2416 | |
| 2417 | LInstruction* LChunkBuilder::DoParameter(HParameter* instr) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2418 | LParameter* result = new(zone()) LParameter; |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 2419 | if (instr->kind() == HParameter::STACK_PARAMETER) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2420 | int spill_index = chunk()->GetParameterStackSlot(instr->index()); |
| 2421 | return DefineAsSpilled(result, spill_index); |
| 2422 | } else { |
| 2423 | ASSERT(info()->IsStub()); |
| 2424 | CodeStubInterfaceDescriptor* descriptor = |
| 2425 | info()->code_stub()->GetInterfaceDescriptor(info()->isolate()); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2426 | int index = static_cast<int>(instr->index()); |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 2427 | Register reg = descriptor->GetParameterRegister(index); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2428 | return DefineFixed(result, reg); |
| 2429 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2430 | } |
| 2431 | |
| 2432 | |
| 2433 | LInstruction* LChunkBuilder::DoUnknownOSRValue(HUnknownOSRValue* instr) { |
hpayer@chromium.org | c5d4971 | 2013-09-11 08:25:48 +0000 | [diff] [blame] | 2434 | // Use an index that corresponds to the location in the unoptimized frame, |
| 2435 | // which the optimized frame will subsume. |
| 2436 | int env_index = instr->index(); |
| 2437 | int spill_index = 0; |
| 2438 | if (instr->environment()->is_parameter_index(env_index)) { |
| 2439 | spill_index = chunk()->GetParameterStackSlot(env_index); |
| 2440 | } else { |
| 2441 | spill_index = env_index - instr->environment()->first_local_index(); |
| 2442 | if (spill_index > LUnallocated::kMaxFixedSlotIndex) { |
| 2443 | Abort(kTooManySpillSlotsNeededForOSR); |
| 2444 | spill_index = 0; |
| 2445 | } |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 2446 | } |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 2447 | return DefineAsSpilled(new(zone()) LUnknownOSRValue, spill_index); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2448 | } |
| 2449 | |
| 2450 | |
| 2451 | LInstruction* LChunkBuilder::DoCallStub(HCallStub* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2452 | LOperand* context = UseFixed(instr->context(), rsi); |
| 2453 | LCallStub* result = new(zone()) LCallStub(context); |
| 2454 | return MarkAsCall(DefineFixed(result, rax), instr); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2455 | } |
| 2456 | |
| 2457 | |
| 2458 | LInstruction* LChunkBuilder::DoArgumentsObject(HArgumentsObject* instr) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2459 | // There are no real uses of the arguments object. |
| 2460 | // arguments.length and element access are supported directly on |
| 2461 | // stack arguments, and any real arguments object use causes a bailout. |
| 2462 | // So this value is never used. |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2463 | return NULL; |
| 2464 | } |
| 2465 | |
| 2466 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 2467 | LInstruction* LChunkBuilder::DoCapturedObject(HCapturedObject* instr) { |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 2468 | instr->ReplayEnvironment(current_block_->last_environment()); |
jkummerow@chromium.org | 1e8da74 | 2013-08-26 17:13:35 +0000 | [diff] [blame] | 2469 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 2470 | // There are no real uses of a captured object. |
| 2471 | return NULL; |
| 2472 | } |
| 2473 | |
| 2474 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2475 | LInstruction* LChunkBuilder::DoAccessArgumentsAt(HAccessArgumentsAt* instr) { |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 2476 | info()->MarkAsRequiresFrame(); |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2477 | LOperand* args = UseRegister(instr->arguments()); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 2478 | LOperand* length; |
| 2479 | LOperand* index; |
| 2480 | if (instr->length()->IsConstant() && instr->index()->IsConstant()) { |
| 2481 | length = UseRegisterOrConstant(instr->length()); |
| 2482 | index = UseOrConstant(instr->index()); |
| 2483 | } else { |
| 2484 | length = UseTempRegister(instr->length()); |
| 2485 | index = Use(instr->index()); |
| 2486 | } |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 2487 | return DefineAsRegister(new(zone()) LAccessArgumentsAt(args, length, index)); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2488 | } |
| 2489 | |
| 2490 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2491 | LInstruction* LChunkBuilder::DoToFastProperties(HToFastProperties* instr) { |
| 2492 | LOperand* object = UseFixed(instr->value(), rax); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 2493 | LToFastProperties* result = new(zone()) LToFastProperties(object); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2494 | return MarkAsCall(DefineFixed(result, rax), instr); |
| 2495 | } |
| 2496 | |
| 2497 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2498 | LInstruction* LChunkBuilder::DoTypeof(HTypeof* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2499 | LOperand* context = UseFixed(instr->context(), rsi); |
| 2500 | LOperand* value = UseAtStart(instr->value()); |
| 2501 | LTypeof* result = new(zone()) LTypeof(context, value); |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2502 | return MarkAsCall(DefineFixed(result, rax), instr); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2503 | } |
| 2504 | |
| 2505 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2506 | LInstruction* LChunkBuilder::DoTypeofIsAndBranch(HTypeofIsAndBranch* instr) { |
machenbach@chromium.org | af9cfcb | 2013-11-19 11:05:18 +0000 | [diff] [blame^] | 2507 | LInstruction* goto_instr = CheckElideControlInstruction(instr); |
| 2508 | if (goto_instr != NULL) return goto_instr; |
| 2509 | |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 2510 | return new(zone()) LTypeofIsAndBranch(UseTempRegister(instr->value())); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2511 | } |
| 2512 | |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 2513 | |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 2514 | LInstruction* LChunkBuilder::DoIsConstructCallAndBranch( |
| 2515 | HIsConstructCallAndBranch* instr) { |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 2516 | return new(zone()) LIsConstructCallAndBranch(TempRegister()); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 2517 | } |
| 2518 | |
| 2519 | |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2520 | LInstruction* LChunkBuilder::DoSimulate(HSimulate* instr) { |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 2521 | instr->ReplayEnvironment(current_block_->last_environment()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2522 | |
| 2523 | // If there is an instruction pending deoptimization environment create a |
| 2524 | // lazy bailout instruction to capture the environment. |
fschneider@chromium.org | 1df6b47 | 2011-01-26 08:23:03 +0000 | [diff] [blame] | 2525 | if (pending_deoptimization_ast_id_ == instr->ast_id()) { |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 2526 | LLazyBailout* lazy_bailout = new(zone()) LLazyBailout; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2527 | LInstruction* result = AssignEnvironment(lazy_bailout); |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 2528 | // Store the lazy deopt environment with the instruction if needed. Right |
| 2529 | // now it is only used for LInstanceOfKnownGlobal. |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 2530 | instruction_pending_deoptimization_environment_-> |
danno@chromium.org | 1044a4d | 2012-04-30 12:34:39 +0000 | [diff] [blame] | 2531 | SetDeferredLazyDeoptimizationEnvironment(result->environment()); |
| 2532 | instruction_pending_deoptimization_environment_ = NULL; |
mstarzinger@chromium.org | 471f2f1 | 2012-08-10 14:46:33 +0000 | [diff] [blame] | 2533 | pending_deoptimization_ast_id_ = BailoutId::None(); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2534 | return result; |
| 2535 | } |
| 2536 | |
| 2537 | return NULL; |
| 2538 | } |
| 2539 | |
| 2540 | |
| 2541 | LInstruction* LChunkBuilder::DoStackCheck(HStackCheck* instr) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2542 | info()->MarkAsDeferredCalling(); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 2543 | if (instr->is_function_entry()) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2544 | LOperand* context = UseFixed(instr->context(), rsi); |
| 2545 | return MarkAsCall(new(zone()) LStackCheck(context), instr); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 2546 | } else { |
| 2547 | ASSERT(instr->is_backwards_branch()); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2548 | LOperand* context = UseAny(instr->context()); |
| 2549 | return AssignEnvironment( |
| 2550 | AssignPointerMap(new(zone()) LStackCheck(context))); |
ager@chromium.org | 04921a8 | 2011-06-27 13:21:41 +0000 | [diff] [blame] | 2551 | } |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2552 | } |
| 2553 | |
| 2554 | |
| 2555 | LInstruction* LChunkBuilder::DoEnterInlined(HEnterInlined* instr) { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2556 | HEnvironment* outer = current_block_->last_environment(); |
| 2557 | HConstant* undefined = graph()->GetConstantUndefined(); |
| 2558 | HEnvironment* inner = outer->CopyForInlining(instr->closure(), |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2559 | instr->arguments_count(), |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2560 | instr->function(), |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2561 | undefined, |
yangguo@chromium.org | 003650e | 2013-01-24 16:31:08 +0000 | [diff] [blame] | 2562 | instr->inlining_kind(), |
| 2563 | instr->undefined_receiver()); |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 2564 | // Only replay binding of arguments object if it wasn't removed from graph. |
| 2565 | if (instr->arguments_var() != NULL && instr->arguments_object()->IsLinked()) { |
| 2566 | inner->Bind(instr->arguments_var(), instr->arguments_object()); |
danno@chromium.org | 8c0a43f | 2012-04-03 08:37:53 +0000 | [diff] [blame] | 2567 | } |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2568 | inner->set_entry(instr); |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 2569 | current_block_->UpdateEnvironment(inner); |
| 2570 | chunk_->AddInlinedClosure(instr->closure()); |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2571 | return NULL; |
| 2572 | } |
| 2573 | |
| 2574 | |
| 2575 | LInstruction* LChunkBuilder::DoLeaveInlined(HLeaveInlined* instr) { |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 2576 | LInstruction* pop = NULL; |
| 2577 | |
| 2578 | HEnvironment* env = current_block_->last_environment(); |
| 2579 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2580 | if (env->entry()->arguments_pushed()) { |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 2581 | int argument_count = env->arguments_environment()->parameter_count(); |
| 2582 | pop = new(zone()) LDrop(argument_count); |
jkummerow@chromium.org | d8a3a14 | 2013-10-03 12:15:05 +0000 | [diff] [blame] | 2583 | ASSERT(instr->argument_delta() == -argument_count); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 2584 | } |
| 2585 | |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 2586 | HEnvironment* outer = current_block_->last_environment()-> |
| 2587 | DiscardInlined(false); |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 2588 | current_block_->UpdateEnvironment(outer); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 2589 | |
| 2590 | return pop; |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2591 | } |
| 2592 | |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 2593 | |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 2594 | LInstruction* LChunkBuilder::DoForInPrepareMap(HForInPrepareMap* instr) { |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2595 | LOperand* context = UseFixed(instr->context(), rsi); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 2596 | LOperand* object = UseFixed(instr->enumerable(), rax); |
machenbach@chromium.org | 935a779 | 2013-11-12 09:05:18 +0000 | [diff] [blame] | 2597 | LForInPrepareMap* result = new(zone()) LForInPrepareMap(context, object); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 2598 | return MarkAsCall(DefineFixed(result, rax), instr, CAN_DEOPTIMIZE_EAGERLY); |
| 2599 | } |
| 2600 | |
| 2601 | |
| 2602 | LInstruction* LChunkBuilder::DoForInCacheArray(HForInCacheArray* instr) { |
| 2603 | LOperand* map = UseRegister(instr->map()); |
| 2604 | return AssignEnvironment(DefineAsRegister( |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 2605 | new(zone()) LForInCacheArray(map))); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 2606 | } |
| 2607 | |
| 2608 | |
| 2609 | LInstruction* LChunkBuilder::DoCheckMapValue(HCheckMapValue* instr) { |
| 2610 | LOperand* value = UseRegisterAtStart(instr->value()); |
| 2611 | LOperand* map = UseRegisterAtStart(instr->map()); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 2612 | return AssignEnvironment(new(zone()) LCheckMapValue(value, map)); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 2613 | } |
| 2614 | |
| 2615 | |
| 2616 | LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) { |
| 2617 | LOperand* object = UseRegister(instr->object()); |
| 2618 | LOperand* index = UseTempRegister(instr->index()); |
ulan@chromium.org | 812308e | 2012-02-29 15:58:45 +0000 | [diff] [blame] | 2619 | return DefineSameAsFirst(new(zone()) LLoadFieldByIndex(object, index)); |
kmillikin@chromium.org | be6bd10 | 2012-02-23 08:45:21 +0000 | [diff] [blame] | 2620 | } |
| 2621 | |
| 2622 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2623 | } } // namespace v8::internal |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 2624 | |
| 2625 | #endif // V8_TARGET_ARCH_X64 |