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