OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 HDeoptimize* instr = new(zone()) HDeoptimize(environment->length(), zone()); | 126 HDeoptimize* instr = new(zone()) HDeoptimize(environment->length(), zone()); |
127 for (int i = 0; i < environment->length(); i++) { | 127 for (int i = 0; i < environment->length(); i++) { |
128 HValue* val = environment->values()->at(i); | 128 HValue* val = environment->values()->at(i); |
129 instr->AddEnvironmentValue(val, zone()); | 129 instr->AddEnvironmentValue(val, zone()); |
130 } | 130 } |
131 | 131 |
132 return instr; | 132 return instr; |
133 } | 133 } |
134 | 134 |
135 | 135 |
136 HSimulate* HBasicBlock::CreateSimulate(BailoutId ast_id) { | 136 HSimulate* HBasicBlock::CreateSimulate(BailoutId ast_id, |
| 137 RemovableSimulate removable) { |
137 ASSERT(HasEnvironment()); | 138 ASSERT(HasEnvironment()); |
138 HEnvironment* environment = last_environment(); | 139 HEnvironment* environment = last_environment(); |
139 ASSERT(ast_id.IsNone() || | 140 ASSERT(ast_id.IsNone() || |
140 environment->closure()->shared()->VerifyBailoutId(ast_id)); | 141 environment->closure()->shared()->VerifyBailoutId(ast_id)); |
141 | 142 |
142 int push_count = environment->push_count(); | 143 int push_count = environment->push_count(); |
143 int pop_count = environment->pop_count(); | 144 int pop_count = environment->pop_count(); |
144 | 145 |
145 HSimulate* instr = new(zone()) HSimulate(ast_id, pop_count, zone()); | 146 HSimulate* instr = |
146 for (int i = push_count - 1; i >= 0; --i) { | 147 new(zone()) HSimulate(ast_id, pop_count, zone(), removable); |
| 148 // Order of pushed values: newest (top of stack) first. This allows |
| 149 // HSimulate::MergeInto() to easily append additional pushed values |
| 150 // that are older (from further down the stack). |
| 151 for (int i = 0; i < push_count; ++i) { |
147 instr->AddPushedValue(environment->ExpressionStackAt(i)); | 152 instr->AddPushedValue(environment->ExpressionStackAt(i)); |
148 } | 153 } |
149 for (int i = 0; i < environment->assigned_variables()->length(); ++i) { | 154 for (int i = 0; i < environment->assigned_variables()->length(); ++i) { |
150 int index = environment->assigned_variables()->at(i); | 155 int index = environment->assigned_variables()->at(i); |
151 instr->AddAssignedValue(index, environment->Lookup(index)); | 156 instr->AddAssignedValue(index, environment->Lookup(index)); |
152 } | 157 } |
153 environment->ClearHistory(); | 158 environment->ClearHistory(); |
154 return instr; | 159 return instr; |
155 } | 160 } |
156 | 161 |
(...skipping 1127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1284 Analyze(block->dominated_blocks()->at(i)); | 1289 Analyze(block->dominated_blocks()->at(i)); |
1285 } | 1290 } |
1286 | 1291 |
1287 RollBackTo(last_changed_range); | 1292 RollBackTo(last_changed_range); |
1288 } | 1293 } |
1289 | 1294 |
1290 | 1295 |
1291 void HRangeAnalysis::InferControlFlowRange(HCompareIDAndBranch* test, | 1296 void HRangeAnalysis::InferControlFlowRange(HCompareIDAndBranch* test, |
1292 HBasicBlock* dest) { | 1297 HBasicBlock* dest) { |
1293 ASSERT((test->FirstSuccessor() == dest) == (test->SecondSuccessor() != dest)); | 1298 ASSERT((test->FirstSuccessor() == dest) == (test->SecondSuccessor() != dest)); |
1294 if (test->GetInputRepresentation().IsInteger32()) { | 1299 if (test->representation().IsInteger32()) { |
1295 Token::Value op = test->token(); | 1300 Token::Value op = test->token(); |
1296 if (test->SecondSuccessor() == dest) { | 1301 if (test->SecondSuccessor() == dest) { |
1297 op = Token::NegateCompareOp(op); | 1302 op = Token::NegateCompareOp(op); |
1298 } | 1303 } |
1299 Token::Value inverted_op = Token::InvertCompareOp(op); | 1304 Token::Value inverted_op = Token::InvertCompareOp(op); |
1300 UpdateControlFlowRange(op, test->left(), test->right()); | 1305 UpdateControlFlowRange(op, test->left(), test->right()); |
1301 UpdateControlFlowRange(inverted_op, test->right(), test->left()); | 1306 UpdateControlFlowRange(inverted_op, test->right(), test->left()); |
1302 } | 1307 } |
1303 } | 1308 } |
1304 | 1309 |
(...skipping 927 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2232 dominated); | 2237 dominated); |
2233 successor_map->Kill(side_effects_on_all_paths); | 2238 successor_map->Kill(side_effects_on_all_paths); |
2234 successor_dominators->Kill(side_effects_on_all_paths); | 2239 successor_dominators->Kill(side_effects_on_all_paths); |
2235 } | 2240 } |
2236 } | 2241 } |
2237 current = next; | 2242 current = next; |
2238 } | 2243 } |
2239 } | 2244 } |
2240 | 2245 |
2241 | 2246 |
2242 class HInferRepresentation BASE_EMBEDDED { | |
2243 public: | |
2244 explicit HInferRepresentation(HGraph* graph) | |
2245 : graph_(graph), | |
2246 worklist_(8, graph->zone()), | |
2247 in_worklist_(graph->GetMaximumValueID(), graph->zone()) { } | |
2248 | |
2249 void Analyze(); | |
2250 | |
2251 private: | |
2252 Representation TryChange(HValue* current); | |
2253 void AddToWorklist(HValue* current); | |
2254 void InferBasedOnInputs(HValue* current); | |
2255 void AddDependantsToWorklist(HValue* current); | |
2256 void InferBasedOnUses(HValue* current); | |
2257 | |
2258 Zone* zone() const { return graph_->zone(); } | |
2259 | |
2260 HGraph* graph_; | |
2261 ZoneList<HValue*> worklist_; | |
2262 BitVector in_worklist_; | |
2263 }; | |
2264 | |
2265 | |
2266 void HInferRepresentation::AddToWorklist(HValue* current) { | 2247 void HInferRepresentation::AddToWorklist(HValue* current) { |
2267 if (current->representation().IsSpecialization()) return; | 2248 if (current->representation().IsTagged()) return; |
2268 if (!current->CheckFlag(HValue::kFlexibleRepresentation)) return; | 2249 if (!current->CheckFlag(HValue::kFlexibleRepresentation)) return; |
2269 if (in_worklist_.Contains(current->id())) return; | 2250 if (in_worklist_.Contains(current->id())) return; |
2270 worklist_.Add(current, zone()); | 2251 worklist_.Add(current, zone()); |
2271 in_worklist_.Add(current->id()); | 2252 in_worklist_.Add(current->id()); |
2272 } | 2253 } |
2273 | 2254 |
2274 | 2255 |
2275 // This method tries to specialize the representation type of the value | |
2276 // given as a parameter. The value is asked to infer its representation type | |
2277 // based on its inputs. If the inferred type is more specialized, then this | |
2278 // becomes the new representation type of the node. | |
2279 void HInferRepresentation::InferBasedOnInputs(HValue* current) { | |
2280 Representation r = current->representation(); | |
2281 if (r.IsSpecialization()) return; | |
2282 ASSERT(current->CheckFlag(HValue::kFlexibleRepresentation)); | |
2283 Representation inferred = current->InferredRepresentation(); | |
2284 if (inferred.IsSpecialization()) { | |
2285 if (FLAG_trace_representation) { | |
2286 PrintF("Changing #%d representation %s -> %s based on inputs\n", | |
2287 current->id(), | |
2288 r.Mnemonic(), | |
2289 inferred.Mnemonic()); | |
2290 } | |
2291 current->ChangeRepresentation(inferred); | |
2292 AddDependantsToWorklist(current); | |
2293 } | |
2294 } | |
2295 | |
2296 | |
2297 void HInferRepresentation::AddDependantsToWorklist(HValue* value) { | |
2298 for (HUseIterator it(value->uses()); !it.Done(); it.Advance()) { | |
2299 AddToWorklist(it.value()); | |
2300 } | |
2301 for (int i = 0; i < value->OperandCount(); ++i) { | |
2302 AddToWorklist(value->OperandAt(i)); | |
2303 } | |
2304 } | |
2305 | |
2306 | |
2307 // This method calculates whether specializing the representation of the value | |
2308 // given as the parameter has a benefit in terms of less necessary type | |
2309 // conversions. If there is a benefit, then the representation of the value is | |
2310 // specialized. | |
2311 void HInferRepresentation::InferBasedOnUses(HValue* value) { | |
2312 Representation r = value->representation(); | |
2313 if (r.IsSpecialization() || value->HasNoUses()) return; | |
2314 ASSERT(value->CheckFlag(HValue::kFlexibleRepresentation)); | |
2315 Representation new_rep = TryChange(value); | |
2316 if (!new_rep.IsNone()) { | |
2317 if (!value->representation().Equals(new_rep)) { | |
2318 if (FLAG_trace_representation) { | |
2319 PrintF("Changing #%d representation %s -> %s based on uses\n", | |
2320 value->id(), | |
2321 r.Mnemonic(), | |
2322 new_rep.Mnemonic()); | |
2323 } | |
2324 value->ChangeRepresentation(new_rep); | |
2325 AddDependantsToWorklist(value); | |
2326 } | |
2327 } | |
2328 } | |
2329 | |
2330 | |
2331 Representation HInferRepresentation::TryChange(HValue* value) { | |
2332 // Array of use counts for each representation. | |
2333 int use_count[Representation::kNumRepresentations] = { 0 }; | |
2334 | |
2335 for (HUseIterator it(value->uses()); !it.Done(); it.Advance()) { | |
2336 HValue* use = it.value(); | |
2337 Representation rep = use->ObservedInputRepresentation(it.index()); | |
2338 if (rep.IsNone()) continue; | |
2339 if (FLAG_trace_representation) { | |
2340 PrintF("%d %s is used by %d %s as %s\n", | |
2341 value->id(), | |
2342 value->Mnemonic(), | |
2343 use->id(), | |
2344 use->Mnemonic(), | |
2345 rep.Mnemonic()); | |
2346 } | |
2347 if (use->IsPhi()) HPhi::cast(use)->AddIndirectUsesTo(&use_count[0]); | |
2348 use_count[rep.kind()] += use->LoopWeight(); | |
2349 } | |
2350 int tagged_count = use_count[Representation::kTagged]; | |
2351 int double_count = use_count[Representation::kDouble]; | |
2352 int int32_count = use_count[Representation::kInteger32]; | |
2353 int non_tagged_count = double_count + int32_count; | |
2354 | |
2355 // If a non-loop phi has tagged uses, don't convert it to untagged. | |
2356 if (value->IsPhi() && !value->block()->IsLoopHeader() && tagged_count > 0) { | |
2357 return Representation::None(); | |
2358 } | |
2359 | |
2360 // Prefer unboxing over boxing, the latter is more expensive. | |
2361 if (tagged_count > non_tagged_count) return Representation::None(); | |
2362 | |
2363 // Prefer Integer32 over Double, if possible. | |
2364 if (int32_count > 0 && value->IsConvertibleToInteger()) { | |
2365 return Representation::Integer32(); | |
2366 } | |
2367 | |
2368 if (double_count > 0) return Representation::Double(); | |
2369 | |
2370 return Representation::None(); | |
2371 } | |
2372 | |
2373 | |
2374 void HInferRepresentation::Analyze() { | 2256 void HInferRepresentation::Analyze() { |
2375 HPhase phase("H_Infer representations", graph_); | 2257 HPhase phase("H_Infer representations", graph_); |
2376 | 2258 |
2377 // (1) Initialize bit vectors and count real uses. Each phi gets a | 2259 // (1) Initialize bit vectors and count real uses. Each phi gets a |
2378 // bit-vector of length <number of phis>. | 2260 // bit-vector of length <number of phis>. |
2379 const ZoneList<HPhi*>* phi_list = graph_->phi_list(); | 2261 const ZoneList<HPhi*>* phi_list = graph_->phi_list(); |
2380 int phi_count = phi_list->length(); | 2262 int phi_count = phi_list->length(); |
2381 ZoneList<BitVector*> connected_phis(phi_count, graph_->zone()); | 2263 ZoneList<BitVector*> connected_phis(phi_count, graph_->zone()); |
2382 for (int i = 0; i < phi_count; ++i) { | 2264 for (int i = 0; i < phi_count; ++i) { |
2383 phi_list->at(i)->InitRealUses(i); | 2265 phi_list->at(i)->InitRealUses(i); |
(...skipping 30 matching lines...) Expand all Loading... |
2414 for (int i = 0; i < phi_count; ++i) { | 2296 for (int i = 0; i < phi_count; ++i) { |
2415 HPhi* phi = phi_list->at(i); | 2297 HPhi* phi = phi_list->at(i); |
2416 bool cti = phi->AllOperandsConvertibleToInteger(); | 2298 bool cti = phi->AllOperandsConvertibleToInteger(); |
2417 if (cti) continue; | 2299 if (cti) continue; |
2418 | 2300 |
2419 for (BitVector::Iterator it(connected_phis.at(i)); | 2301 for (BitVector::Iterator it(connected_phis.at(i)); |
2420 !it.Done(); | 2302 !it.Done(); |
2421 it.Advance()) { | 2303 it.Advance()) { |
2422 HPhi* phi = phi_list->at(it.Current()); | 2304 HPhi* phi = phi_list->at(it.Current()); |
2423 phi->set_is_convertible_to_integer(false); | 2305 phi->set_is_convertible_to_integer(false); |
2424 phi->ResetInteger32Uses(); | |
2425 } | 2306 } |
2426 } | 2307 } |
2427 | 2308 |
2428 // (3b) Use the phi reachability information from step 2 to | 2309 // (3b) Use the phi reachability information from step 2 to |
2429 // sum up the non-phi use counts of all connected phis. | 2310 // sum up the non-phi use counts of all connected phis. |
2430 for (int i = 0; i < phi_count; ++i) { | 2311 for (int i = 0; i < phi_count; ++i) { |
2431 HPhi* phi = phi_list->at(i); | 2312 HPhi* phi = phi_list->at(i); |
2432 for (BitVector::Iterator it(connected_phis.at(i)); | 2313 for (BitVector::Iterator it(connected_phis.at(i)); |
2433 !it.Done(); | 2314 !it.Done(); |
2434 it.Advance()) { | 2315 it.Advance()) { |
(...skipping 15 matching lines...) Expand all Loading... |
2450 while (current != NULL) { | 2331 while (current != NULL) { |
2451 AddToWorklist(current); | 2332 AddToWorklist(current); |
2452 current = current->next(); | 2333 current = current->next(); |
2453 } | 2334 } |
2454 } | 2335 } |
2455 | 2336 |
2456 // Do a fixed point iteration, trying to improve representations | 2337 // Do a fixed point iteration, trying to improve representations |
2457 while (!worklist_.is_empty()) { | 2338 while (!worklist_.is_empty()) { |
2458 HValue* current = worklist_.RemoveLast(); | 2339 HValue* current = worklist_.RemoveLast(); |
2459 in_worklist_.Remove(current->id()); | 2340 in_worklist_.Remove(current->id()); |
2460 InferBasedOnInputs(current); | 2341 current->InferRepresentation(this); |
2461 InferBasedOnUses(current); | 2342 } |
| 2343 |
| 2344 // Lastly: any instruction that we don't have representation information |
| 2345 // for defaults to Tagged. |
| 2346 for (int i = 0; i < graph_->blocks()->length(); ++i) { |
| 2347 HBasicBlock* block = graph_->blocks()->at(i); |
| 2348 const ZoneList<HPhi*>* phis = block->phis(); |
| 2349 for (int j = 0; j < phis->length(); ++j) { |
| 2350 HPhi* phi = phis->at(j); |
| 2351 if (phi->representation().IsNone()) { |
| 2352 phi->ChangeRepresentation(Representation::Tagged()); |
| 2353 } |
| 2354 } |
| 2355 for (HInstruction* current = block->first(); |
| 2356 current != NULL; current = current->next()) { |
| 2357 if (current->representation().IsNone() && |
| 2358 current->CheckFlag(HInstruction::kFlexibleRepresentation)) { |
| 2359 current->ChangeRepresentation(Representation::Tagged()); |
| 2360 } |
| 2361 } |
2462 } | 2362 } |
2463 } | 2363 } |
2464 | 2364 |
| 2365 |
| 2366 void HGraph::MergeRemovableSimulates() { |
| 2367 for (int i = 0; i < blocks()->length(); ++i) { |
| 2368 HBasicBlock* block = blocks()->at(i); |
| 2369 // Always reset the folding candidate at the start of a block. |
| 2370 HSimulate* folding_candidate = NULL; |
| 2371 // Nasty heuristic: Never remove the first simulate in a block. This |
| 2372 // just so happens to have a beneficial effect on register allocation. |
| 2373 bool first = true; |
| 2374 for (HInstruction* current = block->first(); |
| 2375 current != NULL; current = current->next()) { |
| 2376 if (current->IsLeaveInlined()) { |
| 2377 // Never fold simulates from inlined environments into simulates |
| 2378 // in the outer environment. |
| 2379 // (Before each HEnterInlined, there is a non-foldable HSimulate |
| 2380 // anyway, so we get the barrier in the other direction for free.) |
| 2381 if (folding_candidate != NULL) { |
| 2382 folding_candidate->DeleteAndReplaceWith(NULL); |
| 2383 } |
| 2384 folding_candidate = NULL; |
| 2385 continue; |
| 2386 } |
| 2387 // If we have an HSimulate and a candidate, perform the folding. |
| 2388 if (!current->IsSimulate()) continue; |
| 2389 if (first) { |
| 2390 first = false; |
| 2391 continue; |
| 2392 } |
| 2393 HSimulate* current_simulate = HSimulate::cast(current); |
| 2394 if (folding_candidate != NULL) { |
| 2395 folding_candidate->MergeInto(current_simulate); |
| 2396 folding_candidate->DeleteAndReplaceWith(NULL); |
| 2397 folding_candidate = NULL; |
| 2398 } |
| 2399 // Check if the current simulate is a candidate for folding. |
| 2400 if (current_simulate->previous()->HasObservableSideEffects() && |
| 2401 !current_simulate->next()->IsSimulate()) { |
| 2402 continue; |
| 2403 } |
| 2404 if (!current_simulate->is_candidate_for_removal()) { |
| 2405 continue; |
| 2406 } |
| 2407 folding_candidate = current_simulate; |
| 2408 } |
| 2409 } |
| 2410 } |
| 2411 |
2465 | 2412 |
2466 void HGraph::InitializeInferredTypes() { | 2413 void HGraph::InitializeInferredTypes() { |
2467 HPhase phase("H_Inferring types", this); | 2414 HPhase phase("H_Inferring types", this); |
2468 InitializeInferredTypes(0, this->blocks_.length() - 1); | 2415 InitializeInferredTypes(0, this->blocks_.length() - 1); |
2469 } | 2416 } |
2470 | 2417 |
2471 | 2418 |
2472 void HGraph::InitializeInferredTypes(int from_inclusive, int to_inclusive) { | 2419 void HGraph::InitializeInferredTypes(int from_inclusive, int to_inclusive) { |
2473 for (int i = from_inclusive; i <= to_inclusive; ++i) { | 2420 for (int i = from_inclusive; i <= to_inclusive; ++i) { |
2474 HBasicBlock* block = blocks_[i]; | 2421 HBasicBlock* block = blocks_[i]; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2546 int use_index, | 2493 int use_index, |
2547 Representation to) { | 2494 Representation to) { |
2548 // Insert the representation change right before its use. For phi-uses we | 2495 // Insert the representation change right before its use. For phi-uses we |
2549 // insert at the end of the corresponding predecessor. | 2496 // insert at the end of the corresponding predecessor. |
2550 HInstruction* next = NULL; | 2497 HInstruction* next = NULL; |
2551 if (use_value->IsPhi()) { | 2498 if (use_value->IsPhi()) { |
2552 next = use_value->block()->predecessors()->at(use_index)->end(); | 2499 next = use_value->block()->predecessors()->at(use_index)->end(); |
2553 } else { | 2500 } else { |
2554 next = HInstruction::cast(use_value); | 2501 next = HInstruction::cast(use_value); |
2555 } | 2502 } |
2556 | |
2557 // For constants we try to make the representation change at compile | 2503 // For constants we try to make the representation change at compile |
2558 // time. When a representation change is not possible without loss of | 2504 // time. When a representation change is not possible without loss of |
2559 // information we treat constants like normal instructions and insert the | 2505 // information we treat constants like normal instructions and insert the |
2560 // change instructions for them. | 2506 // change instructions for them. |
2561 HInstruction* new_value = NULL; | 2507 HInstruction* new_value = NULL; |
2562 bool is_truncating = use_value->CheckFlag(HValue::kTruncatingToInt32); | 2508 bool is_truncating = use_value->CheckFlag(HValue::kTruncatingToInt32); |
2563 bool deoptimize_on_undefined = | 2509 bool deoptimize_on_undefined = |
2564 use_value->CheckFlag(HValue::kDeoptimizeOnUndefined); | 2510 use_value->CheckFlag(HValue::kDeoptimizeOnUndefined); |
2565 if (value->IsConstant()) { | 2511 if (value->IsConstant()) { |
2566 HConstant* constant = HConstant::cast(value); | 2512 HConstant* constant = HConstant::cast(value); |
2567 // Try to create a new copy of the constant with the new representation. | 2513 // Try to create a new copy of the constant with the new representation. |
2568 new_value = is_truncating | 2514 new_value = (is_truncating && to.IsInteger32()) |
2569 ? constant->CopyToTruncatedInt32(zone()) | 2515 ? constant->CopyToTruncatedInt32(zone()) |
2570 : constant->CopyToRepresentation(to, zone()); | 2516 : constant->CopyToRepresentation(to, zone()); |
2571 } | 2517 } |
2572 | 2518 |
2573 if (new_value == NULL) { | 2519 if (new_value == NULL) { |
2574 new_value = new(zone()) HChange(value, to, | 2520 new_value = new(zone()) HChange(value, to, |
2575 is_truncating, deoptimize_on_undefined); | 2521 is_truncating, deoptimize_on_undefined); |
2576 } | 2522 } |
2577 | 2523 |
2578 new_value->InsertBefore(next); | 2524 new_value->InsertBefore(next); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2618 if (phi->representation().IsInteger32()) { | 2564 if (phi->representation().IsInteger32()) { |
2619 phi->SetFlag(HValue::kTruncatingToInt32); | 2565 phi->SetFlag(HValue::kTruncatingToInt32); |
2620 } | 2566 } |
2621 } | 2567 } |
2622 bool change = true; | 2568 bool change = true; |
2623 while (change) { | 2569 while (change) { |
2624 change = false; | 2570 change = false; |
2625 for (int i = 0; i < phi_list()->length(); i++) { | 2571 for (int i = 0; i < phi_list()->length(); i++) { |
2626 HPhi* phi = phi_list()->at(i); | 2572 HPhi* phi = phi_list()->at(i); |
2627 if (!phi->CheckFlag(HValue::kTruncatingToInt32)) continue; | 2573 if (!phi->CheckFlag(HValue::kTruncatingToInt32)) continue; |
2628 if (!phi->CheckUsesForFlag(HValue::kTruncatingToInt32)) { | 2574 for (HUseIterator it(phi->uses()); !it.Done(); it.Advance()) { |
2629 phi->ClearFlag(HValue::kTruncatingToInt32); | 2575 // If a Phi is used as a non-truncating int32 or as a double, |
2630 change = true; | 2576 // clear its "truncating" flag. |
| 2577 HValue* use = it.value(); |
| 2578 Representation input_representation = |
| 2579 use->RequiredInputRepresentation(it.index()); |
| 2580 if ((input_representation.IsInteger32() && |
| 2581 !use->CheckFlag(HValue::kTruncatingToInt32)) || |
| 2582 input_representation.IsDouble()) { |
| 2583 if (FLAG_trace_representation) { |
| 2584 PrintF("#%d Phi is not truncating because of #%d %s\n", |
| 2585 phi->id(), it.value()->id(), it.value()->Mnemonic()); |
| 2586 } |
| 2587 phi->ClearFlag(HValue::kTruncatingToInt32); |
| 2588 change = true; |
| 2589 break; |
| 2590 } |
2631 } | 2591 } |
2632 } | 2592 } |
2633 } | 2593 } |
2634 | 2594 |
2635 for (int i = 0; i < blocks_.length(); ++i) { | 2595 for (int i = 0; i < blocks_.length(); ++i) { |
2636 // Process phi instructions first. | 2596 // Process phi instructions first. |
2637 const ZoneList<HPhi*>* phis = blocks_[i]->phis(); | 2597 const ZoneList<HPhi*>* phis = blocks_[i]->phis(); |
2638 for (int j = 0; j < phis->length(); j++) { | 2598 for (int j = 0; j < phis->length(); j++) { |
2639 InsertRepresentationChangesForValue(phis->at(j)); | 2599 InsertRepresentationChangesForValue(phis->at(j)); |
2640 } | 2600 } |
2641 | 2601 |
2642 // Process normal instructions. | 2602 // Process normal instructions. |
2643 HInstruction* current = blocks_[i]->first(); | 2603 HInstruction* current = blocks_[i]->first(); |
2644 while (current != NULL) { | 2604 while (current != NULL) { |
| 2605 HInstruction* next = current->next(); |
2645 InsertRepresentationChangesForValue(current); | 2606 InsertRepresentationChangesForValue(current); |
2646 current = current->next(); | 2607 current = next; |
2647 } | 2608 } |
2648 } | 2609 } |
2649 } | 2610 } |
2650 | 2611 |
2651 | 2612 |
2652 void HGraph::RecursivelyMarkPhiDeoptimizeOnUndefined(HPhi* phi) { | 2613 void HGraph::RecursivelyMarkPhiDeoptimizeOnUndefined(HPhi* phi) { |
2653 if (phi->CheckFlag(HValue::kDeoptimizeOnUndefined)) return; | 2614 if (phi->CheckFlag(HValue::kDeoptimizeOnUndefined)) return; |
2654 phi->SetFlag(HValue::kDeoptimizeOnUndefined); | 2615 phi->SetFlag(HValue::kDeoptimizeOnUndefined); |
2655 for (int i = 0; i < phi->OperandCount(); ++i) { | 2616 for (int i = 0; i < phi->OperandCount(); ++i) { |
2656 HValue* input = phi->OperandAt(i); | 2617 HValue* input = phi->OperandAt(i); |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3031 | 2992 |
3032 | 2993 |
3033 void TestContext::ReturnValue(HValue* value) { | 2994 void TestContext::ReturnValue(HValue* value) { |
3034 BuildBranch(value); | 2995 BuildBranch(value); |
3035 } | 2996 } |
3036 | 2997 |
3037 | 2998 |
3038 void EffectContext::ReturnInstruction(HInstruction* instr, BailoutId ast_id) { | 2999 void EffectContext::ReturnInstruction(HInstruction* instr, BailoutId ast_id) { |
3039 ASSERT(!instr->IsControlInstruction()); | 3000 ASSERT(!instr->IsControlInstruction()); |
3040 owner()->AddInstruction(instr); | 3001 owner()->AddInstruction(instr); |
3041 if (instr->HasObservableSideEffects()) owner()->AddSimulate(ast_id); | 3002 if (instr->HasObservableSideEffects()) { |
| 3003 owner()->AddSimulate(ast_id, REMOVABLE); |
| 3004 } |
3042 } | 3005 } |
3043 | 3006 |
3044 | 3007 |
3045 void EffectContext::ReturnControl(HControlInstruction* instr, | 3008 void EffectContext::ReturnControl(HControlInstruction* instr, |
3046 BailoutId ast_id) { | 3009 BailoutId ast_id) { |
3047 ASSERT(!instr->HasObservableSideEffects()); | 3010 ASSERT(!instr->HasObservableSideEffects()); |
3048 HBasicBlock* empty_true = owner()->graph()->CreateBasicBlock(); | 3011 HBasicBlock* empty_true = owner()->graph()->CreateBasicBlock(); |
3049 HBasicBlock* empty_false = owner()->graph()->CreateBasicBlock(); | 3012 HBasicBlock* empty_false = owner()->graph()->CreateBasicBlock(); |
3050 instr->SetSuccessorAt(0, empty_true); | 3013 instr->SetSuccessorAt(0, empty_true); |
3051 instr->SetSuccessorAt(1, empty_false); | 3014 instr->SetSuccessorAt(1, empty_false); |
3052 owner()->current_block()->Finish(instr); | 3015 owner()->current_block()->Finish(instr); |
3053 HBasicBlock* join = owner()->CreateJoin(empty_true, empty_false, ast_id); | 3016 HBasicBlock* join = owner()->CreateJoin(empty_true, empty_false, ast_id); |
3054 owner()->set_current_block(join); | 3017 owner()->set_current_block(join); |
3055 } | 3018 } |
3056 | 3019 |
3057 | 3020 |
3058 void ValueContext::ReturnInstruction(HInstruction* instr, BailoutId ast_id) { | 3021 void ValueContext::ReturnInstruction(HInstruction* instr, BailoutId ast_id) { |
3059 ASSERT(!instr->IsControlInstruction()); | 3022 ASSERT(!instr->IsControlInstruction()); |
3060 if (!arguments_allowed() && instr->CheckFlag(HValue::kIsArguments)) { | 3023 if (!arguments_allowed() && instr->CheckFlag(HValue::kIsArguments)) { |
3061 return owner()->Bailout("bad value context for arguments object value"); | 3024 return owner()->Bailout("bad value context for arguments object value"); |
3062 } | 3025 } |
3063 owner()->AddInstruction(instr); | 3026 owner()->AddInstruction(instr); |
3064 owner()->Push(instr); | 3027 owner()->Push(instr); |
3065 if (instr->HasObservableSideEffects()) owner()->AddSimulate(ast_id); | 3028 if (instr->HasObservableSideEffects()) { |
| 3029 owner()->AddSimulate(ast_id, REMOVABLE); |
| 3030 } |
3066 } | 3031 } |
3067 | 3032 |
3068 | 3033 |
3069 void ValueContext::ReturnControl(HControlInstruction* instr, BailoutId ast_id) { | 3034 void ValueContext::ReturnControl(HControlInstruction* instr, BailoutId ast_id) { |
3070 ASSERT(!instr->HasObservableSideEffects()); | 3035 ASSERT(!instr->HasObservableSideEffects()); |
3071 if (!arguments_allowed() && instr->CheckFlag(HValue::kIsArguments)) { | 3036 if (!arguments_allowed() && instr->CheckFlag(HValue::kIsArguments)) { |
3072 return owner()->Bailout("bad value context for arguments object value"); | 3037 return owner()->Bailout("bad value context for arguments object value"); |
3073 } | 3038 } |
3074 HBasicBlock* materialize_false = owner()->graph()->CreateBasicBlock(); | 3039 HBasicBlock* materialize_false = owner()->graph()->CreateBasicBlock(); |
3075 HBasicBlock* materialize_true = owner()->graph()->CreateBasicBlock(); | 3040 HBasicBlock* materialize_true = owner()->graph()->CreateBasicBlock(); |
(...skipping 11 matching lines...) Expand all Loading... |
3087 | 3052 |
3088 | 3053 |
3089 void TestContext::ReturnInstruction(HInstruction* instr, BailoutId ast_id) { | 3054 void TestContext::ReturnInstruction(HInstruction* instr, BailoutId ast_id) { |
3090 ASSERT(!instr->IsControlInstruction()); | 3055 ASSERT(!instr->IsControlInstruction()); |
3091 HGraphBuilder* builder = owner(); | 3056 HGraphBuilder* builder = owner(); |
3092 builder->AddInstruction(instr); | 3057 builder->AddInstruction(instr); |
3093 // We expect a simulate after every expression with side effects, though | 3058 // We expect a simulate after every expression with side effects, though |
3094 // this one isn't actually needed (and wouldn't work if it were targeted). | 3059 // this one isn't actually needed (and wouldn't work if it were targeted). |
3095 if (instr->HasObservableSideEffects()) { | 3060 if (instr->HasObservableSideEffects()) { |
3096 builder->Push(instr); | 3061 builder->Push(instr); |
3097 builder->AddSimulate(ast_id); | 3062 builder->AddSimulate(ast_id, REMOVABLE); |
3098 builder->Pop(); | 3063 builder->Pop(); |
3099 } | 3064 } |
3100 BuildBranch(instr); | 3065 BuildBranch(instr); |
3101 } | 3066 } |
3102 | 3067 |
3103 | 3068 |
3104 void TestContext::ReturnControl(HControlInstruction* instr, BailoutId ast_id) { | 3069 void TestContext::ReturnControl(HControlInstruction* instr, BailoutId ast_id) { |
3105 ASSERT(!instr->HasObservableSideEffects()); | 3070 ASSERT(!instr->HasObservableSideEffects()); |
3106 HBasicBlock* empty_true = owner()->graph()->CreateBasicBlock(); | 3071 HBasicBlock* empty_true = owner()->graph()->CreateBasicBlock(); |
3107 HBasicBlock* empty_false = owner()->graph()->CreateBasicBlock(); | 3072 HBasicBlock* empty_false = owner()->graph()->CreateBasicBlock(); |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3314 const ZoneList<HPhi*>* phis = osr_loop_entry()->phis(); | 3279 const ZoneList<HPhi*>* phis = osr_loop_entry()->phis(); |
3315 for (int j = 0; j < phis->length(); j++) { | 3280 for (int j = 0; j < phis->length(); j++) { |
3316 HPhi* phi = phis->at(j); | 3281 HPhi* phi = phis->at(j); |
3317 osr_values()->at(phi->merged_index())->set_incoming_value(phi); | 3282 osr_values()->at(phi->merged_index())->set_incoming_value(phi); |
3318 } | 3283 } |
3319 } | 3284 } |
3320 | 3285 |
3321 HInferRepresentation rep(this); | 3286 HInferRepresentation rep(this); |
3322 rep.Analyze(); | 3287 rep.Analyze(); |
3323 | 3288 |
| 3289 // Remove HSimulate instructions that have turned out not to be needed |
| 3290 // after all by folding them into the following HSimulate. |
| 3291 // This must happen after inferring representations. |
| 3292 MergeRemovableSimulates(); |
| 3293 |
3324 MarkDeoptimizeOnUndefined(); | 3294 MarkDeoptimizeOnUndefined(); |
3325 InsertRepresentationChanges(); | 3295 InsertRepresentationChanges(); |
3326 | 3296 |
3327 InitializeInferredTypes(); | 3297 InitializeInferredTypes(); |
3328 | 3298 |
3329 // Must be performed before canonicalization to ensure that Canonicalize | 3299 // Must be performed before canonicalization to ensure that Canonicalize |
3330 // will not remove semantically meaningful ToInt32 operations e.g. BIT_OR with | 3300 // will not remove semantically meaningful ToInt32 operations e.g. BIT_OR with |
3331 // zero. | 3301 // zero. |
3332 ComputeSafeUint32Operations(); | 3302 ComputeSafeUint32Operations(); |
3333 | 3303 |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3803 } | 3773 } |
3804 | 3774 |
3805 | 3775 |
3806 HInstruction* HGraphBuilder::AddInstruction(HInstruction* instr) { | 3776 HInstruction* HGraphBuilder::AddInstruction(HInstruction* instr) { |
3807 ASSERT(current_block() != NULL); | 3777 ASSERT(current_block() != NULL); |
3808 current_block()->AddInstruction(instr); | 3778 current_block()->AddInstruction(instr); |
3809 return instr; | 3779 return instr; |
3810 } | 3780 } |
3811 | 3781 |
3812 | 3782 |
3813 void HGraphBuilder::AddSimulate(BailoutId ast_id) { | 3783 void HGraphBuilder::AddSimulate(BailoutId ast_id, RemovableSimulate removable) { |
3814 ASSERT(current_block() != NULL); | 3784 ASSERT(current_block() != NULL); |
3815 current_block()->AddSimulate(ast_id); | 3785 current_block()->AddSimulate(ast_id, removable); |
3816 } | 3786 } |
3817 | 3787 |
3818 | 3788 |
3819 void HGraphBuilder::AddPhi(HPhi* instr) { | 3789 void HGraphBuilder::AddPhi(HPhi* instr) { |
3820 ASSERT(current_block() != NULL); | 3790 ASSERT(current_block() != NULL); |
3821 current_block()->AddPhi(instr); | 3791 current_block()->AddPhi(instr); |
3822 } | 3792 } |
3823 | 3793 |
3824 | 3794 |
3825 void HGraphBuilder::PushAndAdd(HInstruction* instr) { | 3795 void HGraphBuilder::PushAndAdd(HInstruction* instr) { |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4162 switch_type = SMI_SWITCH; | 4132 switch_type = SMI_SWITCH; |
4163 } else if (clause->label()->IsStringLiteral()) { | 4133 } else if (clause->label()->IsStringLiteral()) { |
4164 switch_type = STRING_SWITCH; | 4134 switch_type = STRING_SWITCH; |
4165 } else { | 4135 } else { |
4166 return Bailout("SwitchStatement: non-literal switch label"); | 4136 return Bailout("SwitchStatement: non-literal switch label"); |
4167 } | 4137 } |
4168 } else if ((switch_type == STRING_SWITCH && | 4138 } else if ((switch_type == STRING_SWITCH && |
4169 !clause->label()->IsStringLiteral()) || | 4139 !clause->label()->IsStringLiteral()) || |
4170 (switch_type == SMI_SWITCH && | 4140 (switch_type == SMI_SWITCH && |
4171 !clause->label()->IsSmiLiteral())) { | 4141 !clause->label()->IsSmiLiteral())) { |
4172 return Bailout("SwitchStatemnt: mixed label types are not supported"); | 4142 return Bailout("SwitchStatement: mixed label types are not supported"); |
4173 } | 4143 } |
4174 } | 4144 } |
4175 | 4145 |
4176 HUnaryControlInstruction* string_check = NULL; | 4146 HUnaryControlInstruction* string_check = NULL; |
4177 HBasicBlock* not_string_block = NULL; | 4147 HBasicBlock* not_string_block = NULL; |
4178 | 4148 |
4179 // Test switch's tag value if all clauses are string literals | 4149 // Test switch's tag value if all clauses are string literals |
4180 if (switch_type == STRING_SWITCH) { | 4150 if (switch_type == STRING_SWITCH) { |
4181 string_check = new(zone()) HIsStringAndBranch(tag_value); | 4151 string_check = new(zone()) HIsStringAndBranch(tag_value); |
4182 first_test_block = graph()->CreateBasicBlock(); | 4152 first_test_block = graph()->CreateBasicBlock(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4216 // account for invisible uses. | 4186 // account for invisible uses. |
4217 current_block()->FinishExitWithDeoptimization(HDeoptimize::kUseAll); | 4187 current_block()->FinishExitWithDeoptimization(HDeoptimize::kUseAll); |
4218 set_current_block(NULL); | 4188 set_current_block(NULL); |
4219 break; | 4189 break; |
4220 } | 4190 } |
4221 | 4191 |
4222 HCompareIDAndBranch* compare_ = | 4192 HCompareIDAndBranch* compare_ = |
4223 new(zone()) HCompareIDAndBranch(tag_value, | 4193 new(zone()) HCompareIDAndBranch(tag_value, |
4224 label_value, | 4194 label_value, |
4225 Token::EQ_STRICT); | 4195 Token::EQ_STRICT); |
4226 compare_->SetInputRepresentation(Representation::Integer32()); | 4196 compare_->set_observed_input_representation( |
| 4197 Representation::Integer32(), Representation::Integer32()); |
4227 compare = compare_; | 4198 compare = compare_; |
4228 } else { | 4199 } else { |
4229 compare = new(zone()) HStringCompareAndBranch(context, tag_value, | 4200 compare = new(zone()) HStringCompareAndBranch(context, tag_value, |
4230 label_value, | 4201 label_value, |
4231 Token::EQ_STRICT); | 4202 Token::EQ_STRICT); |
4232 } | 4203 } |
4233 | 4204 |
4234 compare->SetSuccessorAt(0, body_block); | 4205 compare->SetSuccessorAt(0, body_block); |
4235 compare->SetSuccessorAt(1, next_test_block); | 4206 compare->SetSuccessorAt(1, next_test_block); |
4236 current_block()->Finish(compare); | 4207 current_block()->Finish(compare); |
4237 | 4208 |
4238 set_current_block(next_test_block); | 4209 set_current_block(next_test_block); |
4239 } | 4210 } |
4240 | 4211 |
4241 // Save the current block to use for the default or to join with the | 4212 // Save the current block to use for the default or to join with the |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4580 current_block()->Goto(loop_entry); | 4551 current_block()->Goto(loop_entry); |
4581 set_current_block(loop_entry); | 4552 set_current_block(loop_entry); |
4582 if (osr_entry) graph()->set_osr_loop_entry(loop_entry); | 4553 if (osr_entry) graph()->set_osr_loop_entry(loop_entry); |
4583 | 4554 |
4584 HValue* index = environment()->ExpressionStackAt(0); | 4555 HValue* index = environment()->ExpressionStackAt(0); |
4585 HValue* limit = environment()->ExpressionStackAt(1); | 4556 HValue* limit = environment()->ExpressionStackAt(1); |
4586 | 4557 |
4587 // Check that we still have more keys. | 4558 // Check that we still have more keys. |
4588 HCompareIDAndBranch* compare_index = | 4559 HCompareIDAndBranch* compare_index = |
4589 new(zone()) HCompareIDAndBranch(index, limit, Token::LT); | 4560 new(zone()) HCompareIDAndBranch(index, limit, Token::LT); |
4590 compare_index->SetInputRepresentation(Representation::Integer32()); | 4561 compare_index->set_observed_input_representation( |
| 4562 Representation::Integer32(), Representation::Integer32()); |
4591 | 4563 |
4592 HBasicBlock* loop_body = graph()->CreateBasicBlock(); | 4564 HBasicBlock* loop_body = graph()->CreateBasicBlock(); |
4593 HBasicBlock* loop_successor = graph()->CreateBasicBlock(); | 4565 HBasicBlock* loop_successor = graph()->CreateBasicBlock(); |
4594 | 4566 |
4595 compare_index->SetSuccessorAt(0, loop_body); | 4567 compare_index->SetSuccessorAt(0, loop_body); |
4596 compare_index->SetSuccessorAt(1, loop_successor); | 4568 compare_index->SetSuccessorAt(1, loop_successor); |
4597 current_block()->Finish(compare_index); | 4569 current_block()->Finish(compare_index); |
4598 | 4570 |
4599 set_current_block(loop_successor); | 4571 set_current_block(loop_successor); |
4600 Drop(5); | 4572 Drop(5); |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4855 return Bailout("reference to a variable which requires dynamic lookup"); | 4827 return Bailout("reference to a variable which requires dynamic lookup"); |
4856 } | 4828 } |
4857 } | 4829 } |
4858 | 4830 |
4859 | 4831 |
4860 void HGraphBuilder::VisitLiteral(Literal* expr) { | 4832 void HGraphBuilder::VisitLiteral(Literal* expr) { |
4861 ASSERT(!HasStackOverflow()); | 4833 ASSERT(!HasStackOverflow()); |
4862 ASSERT(current_block() != NULL); | 4834 ASSERT(current_block() != NULL); |
4863 ASSERT(current_block()->HasPredecessor()); | 4835 ASSERT(current_block()->HasPredecessor()); |
4864 HConstant* instr = | 4836 HConstant* instr = |
4865 new(zone()) HConstant(expr->handle(), Representation::Tagged()); | 4837 new(zone()) HConstant(expr->handle(), Representation::None()); |
4866 return ast_context()->ReturnInstruction(instr, expr->id()); | 4838 return ast_context()->ReturnInstruction(instr, expr->id()); |
4867 } | 4839 } |
4868 | 4840 |
4869 | 4841 |
4870 void HGraphBuilder::VisitRegExpLiteral(RegExpLiteral* expr) { | 4842 void HGraphBuilder::VisitRegExpLiteral(RegExpLiteral* expr) { |
4871 ASSERT(!HasStackOverflow()); | 4843 ASSERT(!HasStackOverflow()); |
4872 ASSERT(current_block() != NULL); | 4844 ASSERT(current_block() != NULL); |
4873 ASSERT(current_block()->HasPredecessor()); | 4845 ASSERT(current_block()->HasPredecessor()); |
4874 Handle<JSFunction> closure = function_state()->compilation_info()->closure(); | 4846 Handle<JSFunction> closure = function_state()->compilation_info()->closure(); |
4875 Handle<FixedArray> literals(closure->literals()); | 4847 Handle<FixedArray> literals(closure->literals()); |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5092 Handle<JSFunction> setter; | 5064 Handle<JSFunction> setter; |
5093 Handle<JSObject> holder; | 5065 Handle<JSObject> holder; |
5094 ASSERT(!LookupSetter(map, name, &setter, &holder)); | 5066 ASSERT(!LookupSetter(map, name, &setter, &holder)); |
5095 #endif | 5067 #endif |
5096 CHECK_ALIVE(store = BuildStoreNamedMonomorphic(literal, | 5068 CHECK_ALIVE(store = BuildStoreNamedMonomorphic(literal, |
5097 name, | 5069 name, |
5098 value, | 5070 value, |
5099 map)); | 5071 map)); |
5100 } | 5072 } |
5101 AddInstruction(store); | 5073 AddInstruction(store); |
5102 if (store->HasObservableSideEffects()) AddSimulate(key->id()); | 5074 if (store->HasObservableSideEffects()) { |
| 5075 AddSimulate(key->id(), REMOVABLE); |
| 5076 } |
5103 } else { | 5077 } else { |
5104 CHECK_ALIVE(VisitForEffect(value)); | 5078 CHECK_ALIVE(VisitForEffect(value)); |
5105 } | 5079 } |
5106 break; | 5080 break; |
5107 } | 5081 } |
5108 // Fall through. | 5082 // Fall through. |
5109 case ObjectLiteral::Property::PROTOTYPE: | 5083 case ObjectLiteral::Property::PROTOTYPE: |
5110 case ObjectLiteral::Property::SETTER: | 5084 case ObjectLiteral::Property::SETTER: |
5111 case ObjectLiteral::Property::GETTER: | 5085 case ObjectLiteral::Property::GETTER: |
5112 return Bailout("Object literal with complex property"); | 5086 return Bailout("Object literal with complex property"); |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5473 | 5447 |
5474 if (join != NULL) { | 5448 if (join != NULL) { |
5475 if (!ast_context()->IsEffect()) Push(value); | 5449 if (!ast_context()->IsEffect()) Push(value); |
5476 current_block()->Goto(join); | 5450 current_block()->Goto(join); |
5477 } else { | 5451 } else { |
5478 // The HSimulate for the store should not see the stored value in | 5452 // The HSimulate for the store should not see the stored value in |
5479 // effect contexts (it is not materialized at expr->id() in the | 5453 // effect contexts (it is not materialized at expr->id() in the |
5480 // unoptimized code). | 5454 // unoptimized code). |
5481 if (instr->HasObservableSideEffects()) { | 5455 if (instr->HasObservableSideEffects()) { |
5482 if (ast_context()->IsEffect()) { | 5456 if (ast_context()->IsEffect()) { |
5483 AddSimulate(expr->id()); | 5457 AddSimulate(expr->id(), REMOVABLE); |
5484 } else { | 5458 } else { |
5485 Push(value); | 5459 Push(value); |
5486 AddSimulate(expr->id()); | 5460 AddSimulate(expr->id(), REMOVABLE); |
5487 Drop(1); | 5461 Drop(1); |
5488 } | 5462 } |
5489 } | 5463 } |
5490 return ast_context()->ReturnValue(value); | 5464 return ast_context()->ReturnValue(value); |
5491 } | 5465 } |
5492 } | 5466 } |
5493 | 5467 |
5494 ASSERT(join != NULL); | 5468 ASSERT(join != NULL); |
5495 join->SetJoinId(expr->id()); | 5469 join->SetJoinId(expr->id()); |
5496 set_current_block(join); | 5470 set_current_block(join); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5546 Drop(2); | 5520 Drop(2); |
5547 return HandlePolymorphicStoreNamedField(expr, object, value, types, name); | 5521 return HandlePolymorphicStoreNamedField(expr, object, value, types, name); |
5548 } else { | 5522 } else { |
5549 Drop(2); | 5523 Drop(2); |
5550 instr = BuildStoreNamedGeneric(object, name, value); | 5524 instr = BuildStoreNamedGeneric(object, name, value); |
5551 } | 5525 } |
5552 | 5526 |
5553 Push(value); | 5527 Push(value); |
5554 instr->set_position(expr->position()); | 5528 instr->set_position(expr->position()); |
5555 AddInstruction(instr); | 5529 AddInstruction(instr); |
5556 if (instr->HasObservableSideEffects()) AddSimulate(expr->AssignmentId()); | 5530 if (instr->HasObservableSideEffects()) { |
| 5531 AddSimulate(expr->AssignmentId(), REMOVABLE); |
| 5532 } |
5557 return ast_context()->ReturnValue(Pop()); | 5533 return ast_context()->ReturnValue(Pop()); |
5558 | 5534 |
5559 } else { | 5535 } else { |
5560 // Keyed store. | 5536 // Keyed store. |
5561 CHECK_ALIVE(VisitForValue(prop->key())); | 5537 CHECK_ALIVE(VisitForValue(prop->key())); |
5562 CHECK_ALIVE(VisitForValue(expr->value())); | 5538 CHECK_ALIVE(VisitForValue(expr->value())); |
5563 HValue* value = Pop(); | 5539 HValue* value = Pop(); |
5564 HValue* key = Pop(); | 5540 HValue* key = Pop(); |
5565 HValue* object = Pop(); | 5541 HValue* object = Pop(); |
5566 bool has_side_effects = false; | 5542 bool has_side_effects = false; |
5567 HandleKeyedElementAccess(object, key, value, expr, expr->AssignmentId(), | 5543 HandleKeyedElementAccess(object, key, value, expr, expr->AssignmentId(), |
5568 expr->position(), | 5544 expr->position(), |
5569 true, // is_store | 5545 true, // is_store |
5570 &has_side_effects); | 5546 &has_side_effects); |
5571 Push(value); | 5547 Push(value); |
5572 ASSERT(has_side_effects); // Stores always have side effects. | 5548 ASSERT(has_side_effects); // Stores always have side effects. |
5573 AddSimulate(expr->AssignmentId()); | 5549 AddSimulate(expr->AssignmentId(), REMOVABLE); |
5574 return ast_context()->ReturnValue(Pop()); | 5550 return ast_context()->ReturnValue(Pop()); |
5575 } | 5551 } |
5576 } | 5552 } |
5577 | 5553 |
5578 | 5554 |
5579 // Because not every expression has a position and there is not common | 5555 // Because not every expression has a position and there is not common |
5580 // superclass of Assignment and CountOperation, we cannot just pass the | 5556 // superclass of Assignment and CountOperation, we cannot just pass the |
5581 // owning expression instead of position and ast_id separately. | 5557 // owning expression instead of position and ast_id separately. |
5582 void HGraphBuilder::HandleGlobalVariableAssignment(Variable* var, | 5558 void HGraphBuilder::HandleGlobalVariableAssignment(Variable* var, |
5583 HValue* value, | 5559 HValue* value, |
5584 int position, | 5560 int position, |
5585 BailoutId ast_id) { | 5561 BailoutId ast_id) { |
5586 LookupResult lookup(isolate()); | 5562 LookupResult lookup(isolate()); |
5587 GlobalPropertyAccess type = LookupGlobalProperty(var, &lookup, true); | 5563 GlobalPropertyAccess type = LookupGlobalProperty(var, &lookup, true); |
5588 if (type == kUseCell) { | 5564 if (type == kUseCell) { |
5589 Handle<GlobalObject> global(info()->global_object()); | 5565 Handle<GlobalObject> global(info()->global_object()); |
5590 Handle<JSGlobalPropertyCell> cell(global->GetPropertyCell(&lookup)); | 5566 Handle<JSGlobalPropertyCell> cell(global->GetPropertyCell(&lookup)); |
5591 HInstruction* instr = | 5567 HInstruction* instr = |
5592 new(zone()) HStoreGlobalCell(value, cell, lookup.GetPropertyDetails()); | 5568 new(zone()) HStoreGlobalCell(value, cell, lookup.GetPropertyDetails()); |
5593 instr->set_position(position); | 5569 instr->set_position(position); |
5594 AddInstruction(instr); | 5570 AddInstruction(instr); |
5595 if (instr->HasObservableSideEffects()) AddSimulate(ast_id); | 5571 if (instr->HasObservableSideEffects()) AddSimulate(ast_id, REMOVABLE); |
5596 } else { | 5572 } else { |
5597 HValue* context = environment()->LookupContext(); | 5573 HValue* context = environment()->LookupContext(); |
5598 HGlobalObject* global_object = new(zone()) HGlobalObject(context); | 5574 HGlobalObject* global_object = new(zone()) HGlobalObject(context); |
5599 AddInstruction(global_object); | 5575 AddInstruction(global_object); |
5600 HStoreGlobalGeneric* instr = | 5576 HStoreGlobalGeneric* instr = |
5601 new(zone()) HStoreGlobalGeneric(context, | 5577 new(zone()) HStoreGlobalGeneric(context, |
5602 global_object, | 5578 global_object, |
5603 var->name(), | 5579 var->name(), |
5604 value, | 5580 value, |
5605 function_strict_mode_flag()); | 5581 function_strict_mode_flag()); |
5606 instr->set_position(position); | 5582 instr->set_position(position); |
5607 AddInstruction(instr); | 5583 AddInstruction(instr); |
5608 ASSERT(instr->HasObservableSideEffects()); | 5584 ASSERT(instr->HasObservableSideEffects()); |
5609 if (instr->HasObservableSideEffects()) AddSimulate(ast_id); | 5585 AddSimulate(ast_id, REMOVABLE); |
5610 } | 5586 } |
5611 } | 5587 } |
5612 | 5588 |
5613 | 5589 |
5614 void HGraphBuilder::HandleCompoundAssignment(Assignment* expr) { | 5590 void HGraphBuilder::HandleCompoundAssignment(Assignment* expr) { |
5615 Expression* target = expr->target(); | 5591 Expression* target = expr->target(); |
5616 VariableProxy* proxy = target->AsVariableProxy(); | 5592 VariableProxy* proxy = target->AsVariableProxy(); |
5617 Property* prop = target->AsProperty(); | 5593 Property* prop = target->AsProperty(); |
5618 ASSERT(proxy == NULL || prop == NULL); | 5594 ASSERT(proxy == NULL || prop == NULL); |
5619 | 5595 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5676 UNREACHABLE(); | 5652 UNREACHABLE(); |
5677 default: | 5653 default: |
5678 mode = HStoreContextSlot::kNoCheck; | 5654 mode = HStoreContextSlot::kNoCheck; |
5679 } | 5655 } |
5680 | 5656 |
5681 HValue* context = BuildContextChainWalk(var); | 5657 HValue* context = BuildContextChainWalk(var); |
5682 HStoreContextSlot* instr = | 5658 HStoreContextSlot* instr = |
5683 new(zone()) HStoreContextSlot(context, var->index(), mode, Top()); | 5659 new(zone()) HStoreContextSlot(context, var->index(), mode, Top()); |
5684 AddInstruction(instr); | 5660 AddInstruction(instr); |
5685 if (instr->HasObservableSideEffects()) { | 5661 if (instr->HasObservableSideEffects()) { |
5686 AddSimulate(expr->AssignmentId()); | 5662 AddSimulate(expr->AssignmentId(), REMOVABLE); |
5687 } | 5663 } |
5688 break; | 5664 break; |
5689 } | 5665 } |
5690 | 5666 |
5691 case Variable::LOOKUP: | 5667 case Variable::LOOKUP: |
5692 return Bailout("compound assignment to lookup slot"); | 5668 return Bailout("compound assignment to lookup slot"); |
5693 } | 5669 } |
5694 return ast_context()->ReturnValue(Pop()); | 5670 return ast_context()->ReturnValue(Pop()); |
5695 | 5671 |
5696 } else if (prop != NULL) { | 5672 } else if (prop != NULL) { |
(...skipping 19 matching lines...) Expand all Loading... |
5716 Handle<JSObject> holder; | 5692 Handle<JSObject> holder; |
5717 if (LookupGetter(map, name, &getter, &holder)) { | 5693 if (LookupGetter(map, name, &getter, &holder)) { |
5718 load = BuildCallGetter(object, map, getter, holder); | 5694 load = BuildCallGetter(object, map, getter, holder); |
5719 } else { | 5695 } else { |
5720 load = BuildLoadNamedMonomorphic(object, name, prop, map); | 5696 load = BuildLoadNamedMonomorphic(object, name, prop, map); |
5721 } | 5697 } |
5722 } else { | 5698 } else { |
5723 load = BuildLoadNamedGeneric(object, name, prop); | 5699 load = BuildLoadNamedGeneric(object, name, prop); |
5724 } | 5700 } |
5725 PushAndAdd(load); | 5701 PushAndAdd(load); |
5726 if (load->HasObservableSideEffects()) AddSimulate(prop->LoadId()); | 5702 if (load->HasObservableSideEffects()) { |
| 5703 AddSimulate(prop->LoadId(), REMOVABLE); |
| 5704 } |
5727 | 5705 |
5728 CHECK_ALIVE(VisitForValue(expr->value())); | 5706 CHECK_ALIVE(VisitForValue(expr->value())); |
5729 HValue* right = Pop(); | 5707 HValue* right = Pop(); |
5730 HValue* left = Pop(); | 5708 HValue* left = Pop(); |
5731 | 5709 |
5732 HInstruction* instr = BuildBinaryOperation(operation, left, right); | 5710 HInstruction* instr = BuildBinaryOperation(operation, left, right); |
5733 PushAndAdd(instr); | 5711 PushAndAdd(instr); |
5734 if (instr->HasObservableSideEffects()) AddSimulate(operation->id()); | 5712 if (instr->HasObservableSideEffects()) { |
| 5713 AddSimulate(operation->id(), REMOVABLE); |
| 5714 } |
5735 | 5715 |
5736 HInstruction* store; | 5716 HInstruction* store; |
5737 if (!monomorphic) { | 5717 if (!monomorphic) { |
5738 // If we don't know the monomorphic type, do a generic store. | 5718 // If we don't know the monomorphic type, do a generic store. |
5739 CHECK_ALIVE(store = BuildStoreNamedGeneric(object, name, instr)); | 5719 CHECK_ALIVE(store = BuildStoreNamedGeneric(object, name, instr)); |
5740 } else { | 5720 } else { |
5741 Handle<JSFunction> setter; | 5721 Handle<JSFunction> setter; |
5742 Handle<JSObject> holder; | 5722 Handle<JSObject> holder; |
5743 if (LookupSetter(map, name, &setter, &holder)) { | 5723 if (LookupSetter(map, name, &setter, &holder)) { |
5744 store = BuildCallSetter(object, instr, map, setter, holder); | 5724 store = BuildCallSetter(object, instr, map, setter, holder); |
5745 } else { | 5725 } else { |
5746 CHECK_ALIVE(store = BuildStoreNamedMonomorphic(object, | 5726 CHECK_ALIVE(store = BuildStoreNamedMonomorphic(object, |
5747 name, | 5727 name, |
5748 instr, | 5728 instr, |
5749 map)); | 5729 map)); |
5750 } | 5730 } |
5751 } | 5731 } |
5752 AddInstruction(store); | 5732 AddInstruction(store); |
5753 // Drop the simulated receiver and value. Return the value. | 5733 // Drop the simulated receiver and value. Return the value. |
5754 Drop(2); | 5734 Drop(2); |
5755 Push(instr); | 5735 Push(instr); |
5756 if (store->HasObservableSideEffects()) AddSimulate(expr->AssignmentId()); | 5736 if (store->HasObservableSideEffects()) { |
| 5737 AddSimulate(expr->AssignmentId(), REMOVABLE); |
| 5738 } |
5757 return ast_context()->ReturnValue(Pop()); | 5739 return ast_context()->ReturnValue(Pop()); |
5758 | 5740 |
5759 } else { | 5741 } else { |
5760 // Keyed property. | 5742 // Keyed property. |
5761 CHECK_ALIVE(VisitForValue(prop->obj())); | 5743 CHECK_ALIVE(VisitForValue(prop->obj())); |
5762 CHECK_ALIVE(VisitForValue(prop->key())); | 5744 CHECK_ALIVE(VisitForValue(prop->key())); |
5763 HValue* obj = environment()->ExpressionStackAt(1); | 5745 HValue* obj = environment()->ExpressionStackAt(1); |
5764 HValue* key = environment()->ExpressionStackAt(0); | 5746 HValue* key = environment()->ExpressionStackAt(0); |
5765 | 5747 |
5766 bool has_side_effects = false; | 5748 bool has_side_effects = false; |
5767 HValue* load = HandleKeyedElementAccess( | 5749 HValue* load = HandleKeyedElementAccess( |
5768 obj, key, NULL, prop, prop->LoadId(), RelocInfo::kNoPosition, | 5750 obj, key, NULL, prop, prop->LoadId(), RelocInfo::kNoPosition, |
5769 false, // is_store | 5751 false, // is_store |
5770 &has_side_effects); | 5752 &has_side_effects); |
5771 Push(load); | 5753 Push(load); |
5772 if (has_side_effects) AddSimulate(prop->LoadId()); | 5754 if (has_side_effects) AddSimulate(prop->LoadId(), REMOVABLE); |
5773 | 5755 |
5774 | 5756 |
5775 CHECK_ALIVE(VisitForValue(expr->value())); | 5757 CHECK_ALIVE(VisitForValue(expr->value())); |
5776 HValue* right = Pop(); | 5758 HValue* right = Pop(); |
5777 HValue* left = Pop(); | 5759 HValue* left = Pop(); |
5778 | 5760 |
5779 HInstruction* instr = BuildBinaryOperation(operation, left, right); | 5761 HInstruction* instr = BuildBinaryOperation(operation, left, right); |
5780 PushAndAdd(instr); | 5762 PushAndAdd(instr); |
5781 if (instr->HasObservableSideEffects()) AddSimulate(operation->id()); | 5763 if (instr->HasObservableSideEffects()) { |
| 5764 AddSimulate(operation->id(), REMOVABLE); |
| 5765 } |
5782 | 5766 |
5783 expr->RecordTypeFeedback(oracle(), zone()); | 5767 expr->RecordTypeFeedback(oracle(), zone()); |
5784 HandleKeyedElementAccess(obj, key, instr, expr, expr->AssignmentId(), | 5768 HandleKeyedElementAccess(obj, key, instr, expr, expr->AssignmentId(), |
5785 RelocInfo::kNoPosition, | 5769 RelocInfo::kNoPosition, |
5786 true, // is_store | 5770 true, // is_store |
5787 &has_side_effects); | 5771 &has_side_effects); |
5788 | 5772 |
5789 // Drop the simulated receiver, key, and value. Return the value. | 5773 // Drop the simulated receiver, key, and value. Return the value. |
5790 Drop(3); | 5774 Drop(3); |
5791 Push(instr); | 5775 Push(instr); |
5792 ASSERT(has_side_effects); // Stores always have side effects. | 5776 ASSERT(has_side_effects); // Stores always have side effects. |
5793 AddSimulate(expr->AssignmentId()); | 5777 AddSimulate(expr->AssignmentId(), REMOVABLE); |
5794 return ast_context()->ReturnValue(Pop()); | 5778 return ast_context()->ReturnValue(Pop()); |
5795 } | 5779 } |
5796 | 5780 |
5797 } else { | 5781 } else { |
5798 return Bailout("invalid lhs in compound assignment"); | 5782 return Bailout("invalid lhs in compound assignment"); |
5799 } | 5783 } |
5800 } | 5784 } |
5801 | 5785 |
5802 | 5786 |
5803 void HGraphBuilder::VisitAssignment(Assignment* expr) { | 5787 void HGraphBuilder::VisitAssignment(Assignment* expr) { |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5906 ASSERT(expr->op() == Token::INIT_CONST); | 5890 ASSERT(expr->op() == Token::INIT_CONST); |
5907 | 5891 |
5908 mode = HStoreContextSlot::kCheckIgnoreAssignment; | 5892 mode = HStoreContextSlot::kCheckIgnoreAssignment; |
5909 } | 5893 } |
5910 | 5894 |
5911 HValue* context = BuildContextChainWalk(var); | 5895 HValue* context = BuildContextChainWalk(var); |
5912 HStoreContextSlot* instr = new(zone()) HStoreContextSlot( | 5896 HStoreContextSlot* instr = new(zone()) HStoreContextSlot( |
5913 context, var->index(), mode, Top()); | 5897 context, var->index(), mode, Top()); |
5914 AddInstruction(instr); | 5898 AddInstruction(instr); |
5915 if (instr->HasObservableSideEffects()) { | 5899 if (instr->HasObservableSideEffects()) { |
5916 AddSimulate(expr->AssignmentId()); | 5900 AddSimulate(expr->AssignmentId(), REMOVABLE); |
5917 } | 5901 } |
5918 return ast_context()->ReturnValue(Pop()); | 5902 return ast_context()->ReturnValue(Pop()); |
5919 } | 5903 } |
5920 | 5904 |
5921 case Variable::LOOKUP: | 5905 case Variable::LOOKUP: |
5922 return Bailout("assignment to LOOKUP variable"); | 5906 return Bailout("assignment to LOOKUP variable"); |
5923 } | 5907 } |
5924 } else { | 5908 } else { |
5925 return Bailout("invalid left-hand side in assignment"); | 5909 return Bailout("invalid left-hand side in assignment"); |
5926 } | 5910 } |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6044 case EXTERNAL_PIXEL_ELEMENTS: { | 6028 case EXTERNAL_PIXEL_ELEMENTS: { |
6045 val = AddInstruction(new(zone()) HClampToUint8(val)); | 6029 val = AddInstruction(new(zone()) HClampToUint8(val)); |
6046 break; | 6030 break; |
6047 } | 6031 } |
6048 case EXTERNAL_BYTE_ELEMENTS: | 6032 case EXTERNAL_BYTE_ELEMENTS: |
6049 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: | 6033 case EXTERNAL_UNSIGNED_BYTE_ELEMENTS: |
6050 case EXTERNAL_SHORT_ELEMENTS: | 6034 case EXTERNAL_SHORT_ELEMENTS: |
6051 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: | 6035 case EXTERNAL_UNSIGNED_SHORT_ELEMENTS: |
6052 case EXTERNAL_INT_ELEMENTS: | 6036 case EXTERNAL_INT_ELEMENTS: |
6053 case EXTERNAL_UNSIGNED_INT_ELEMENTS: { | 6037 case EXTERNAL_UNSIGNED_INT_ELEMENTS: { |
6054 if (!val->representation().IsInteger32()) { | |
6055 val = AddInstruction(new(zone()) HChange( | |
6056 val, | |
6057 Representation::Integer32(), | |
6058 true, // Truncate to int32. | |
6059 false)); // Don't deoptimize undefined (irrelevant here). | |
6060 } | |
6061 break; | 6038 break; |
6062 } | 6039 } |
6063 case EXTERNAL_FLOAT_ELEMENTS: | 6040 case EXTERNAL_FLOAT_ELEMENTS: |
6064 case EXTERNAL_DOUBLE_ELEMENTS: | 6041 case EXTERNAL_DOUBLE_ELEMENTS: |
6065 break; | 6042 break; |
6066 case FAST_SMI_ELEMENTS: | 6043 case FAST_SMI_ELEMENTS: |
6067 case FAST_ELEMENTS: | 6044 case FAST_ELEMENTS: |
6068 case FAST_DOUBLE_ELEMENTS: | 6045 case FAST_DOUBLE_ELEMENTS: |
6069 case FAST_HOLEY_SMI_ELEMENTS: | 6046 case FAST_HOLEY_SMI_ELEMENTS: |
6070 case FAST_HOLEY_ELEMENTS: | 6047 case FAST_HOLEY_ELEMENTS: |
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6671 HValue* key = Pop(); | 6648 HValue* key = Pop(); |
6672 HValue* obj = Pop(); | 6649 HValue* obj = Pop(); |
6673 | 6650 |
6674 bool has_side_effects = false; | 6651 bool has_side_effects = false; |
6675 HValue* load = HandleKeyedElementAccess( | 6652 HValue* load = HandleKeyedElementAccess( |
6676 obj, key, NULL, expr, expr->id(), expr->position(), | 6653 obj, key, NULL, expr, expr->id(), expr->position(), |
6677 false, // is_store | 6654 false, // is_store |
6678 &has_side_effects); | 6655 &has_side_effects); |
6679 if (has_side_effects) { | 6656 if (has_side_effects) { |
6680 if (ast_context()->IsEffect()) { | 6657 if (ast_context()->IsEffect()) { |
6681 AddSimulate(expr->id()); | 6658 AddSimulate(expr->id(), REMOVABLE); |
6682 } else { | 6659 } else { |
6683 Push(load); | 6660 Push(load); |
6684 AddSimulate(expr->id()); | 6661 AddSimulate(expr->id(), REMOVABLE); |
6685 Drop(1); | 6662 Drop(1); |
6686 } | 6663 } |
6687 } | 6664 } |
6688 return ast_context()->ReturnValue(load); | 6665 return ast_context()->ReturnValue(load); |
6689 } | 6666 } |
6690 instr->set_position(expr->position()); | 6667 instr->set_position(expr->position()); |
6691 return ast_context()->ReturnInstruction(instr, expr->id()); | 6668 return ast_context()->ReturnInstruction(instr, expr->id()); |
6692 } | 6669 } |
6693 | 6670 |
6694 | 6671 |
(...skipping 1228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7923 } | 7900 } |
7924 | 7901 |
7925 | 7902 |
7926 void HGraphBuilder::VisitSub(UnaryOperation* expr) { | 7903 void HGraphBuilder::VisitSub(UnaryOperation* expr) { |
7927 CHECK_ALIVE(VisitForValue(expr->expression())); | 7904 CHECK_ALIVE(VisitForValue(expr->expression())); |
7928 HValue* value = Pop(); | 7905 HValue* value = Pop(); |
7929 HValue* context = environment()->LookupContext(); | 7906 HValue* context = environment()->LookupContext(); |
7930 HInstruction* instr = | 7907 HInstruction* instr = |
7931 new(zone()) HMul(context, value, graph_->GetConstantMinus1()); | 7908 new(zone()) HMul(context, value, graph_->GetConstantMinus1()); |
7932 TypeInfo info = oracle()->UnaryType(expr); | 7909 TypeInfo info = oracle()->UnaryType(expr); |
| 7910 Representation rep = ToRepresentation(info); |
7933 if (info.IsUninitialized()) { | 7911 if (info.IsUninitialized()) { |
7934 AddInstruction(new(zone()) HSoftDeoptimize); | 7912 AddInstruction(new(zone()) HSoftDeoptimize); |
7935 current_block()->MarkAsDeoptimizing(); | 7913 current_block()->MarkAsDeoptimizing(); |
7936 info = TypeInfo::Unknown(); | 7914 info = TypeInfo::Unknown(); |
7937 } | 7915 } |
7938 Representation rep = ToRepresentation(info); | 7916 HBinaryOperation::cast(instr)->set_observed_input_representation(rep, rep); |
7939 TraceRepresentation(expr->op(), info, instr, rep); | |
7940 instr->AssumeRepresentation(rep); | |
7941 return ast_context()->ReturnInstruction(instr, expr->id()); | 7917 return ast_context()->ReturnInstruction(instr, expr->id()); |
7942 } | 7918 } |
7943 | 7919 |
7944 | 7920 |
7945 void HGraphBuilder::VisitBitNot(UnaryOperation* expr) { | 7921 void HGraphBuilder::VisitBitNot(UnaryOperation* expr) { |
7946 CHECK_ALIVE(VisitForValue(expr->expression())); | 7922 CHECK_ALIVE(VisitForValue(expr->expression())); |
7947 HValue* value = Pop(); | 7923 HValue* value = Pop(); |
7948 TypeInfo info = oracle()->UnaryType(expr); | 7924 TypeInfo info = oracle()->UnaryType(expr); |
7949 if (info.IsUninitialized()) { | 7925 if (info.IsUninitialized()) { |
7950 AddInstruction(new(zone()) HSoftDeoptimize); | 7926 AddInstruction(new(zone()) HSoftDeoptimize); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8019 } | 7995 } |
8020 | 7996 |
8021 // The addition has no side effects, so we do not need | 7997 // The addition has no side effects, so we do not need |
8022 // to simulate the expression stack after this instruction. | 7998 // to simulate the expression stack after this instruction. |
8023 // Any later failures deopt to the load of the input or earlier. | 7999 // Any later failures deopt to the load of the input or earlier. |
8024 HConstant* delta = (expr->op() == Token::INC) | 8000 HConstant* delta = (expr->op() == Token::INC) |
8025 ? graph_->GetConstant1() | 8001 ? graph_->GetConstant1() |
8026 : graph_->GetConstantMinus1(); | 8002 : graph_->GetConstantMinus1(); |
8027 HValue* context = environment()->LookupContext(); | 8003 HValue* context = environment()->LookupContext(); |
8028 HInstruction* instr = new(zone()) HAdd(context, Top(), delta); | 8004 HInstruction* instr = new(zone()) HAdd(context, Top(), delta); |
8029 TraceRepresentation(expr->op(), info, instr, rep); | 8005 // We can't insert a simulate here, because it would break deoptimization, |
| 8006 // so the HAdd must not have side effects, so we must freeze its |
| 8007 // representation. |
8030 instr->AssumeRepresentation(rep); | 8008 instr->AssumeRepresentation(rep); |
| 8009 instr->ClearAllSideEffects(); |
8031 AddInstruction(instr); | 8010 AddInstruction(instr); |
8032 return instr; | 8011 return instr; |
8033 } | 8012 } |
8034 | 8013 |
8035 | 8014 |
8036 void HGraphBuilder::VisitCountOperation(CountOperation* expr) { | 8015 void HGraphBuilder::VisitCountOperation(CountOperation* expr) { |
8037 ASSERT(!HasStackOverflow()); | 8016 ASSERT(!HasStackOverflow()); |
8038 ASSERT(current_block() != NULL); | 8017 ASSERT(current_block() != NULL); |
8039 ASSERT(current_block()->HasPredecessor()); | 8018 ASSERT(current_block()->HasPredecessor()); |
8040 Expression* target = expr->expression(); | 8019 Expression* target = expr->expression(); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8094 } | 8073 } |
8095 } | 8074 } |
8096 | 8075 |
8097 HValue* context = BuildContextChainWalk(var); | 8076 HValue* context = BuildContextChainWalk(var); |
8098 HStoreContextSlot::Mode mode = IsLexicalVariableMode(var->mode()) | 8077 HStoreContextSlot::Mode mode = IsLexicalVariableMode(var->mode()) |
8099 ? HStoreContextSlot::kCheckDeoptimize : HStoreContextSlot::kNoCheck; | 8078 ? HStoreContextSlot::kCheckDeoptimize : HStoreContextSlot::kNoCheck; |
8100 HStoreContextSlot* instr = | 8079 HStoreContextSlot* instr = |
8101 new(zone()) HStoreContextSlot(context, var->index(), mode, after); | 8080 new(zone()) HStoreContextSlot(context, var->index(), mode, after); |
8102 AddInstruction(instr); | 8081 AddInstruction(instr); |
8103 if (instr->HasObservableSideEffects()) { | 8082 if (instr->HasObservableSideEffects()) { |
8104 AddSimulate(expr->AssignmentId()); | 8083 AddSimulate(expr->AssignmentId(), REMOVABLE); |
8105 } | 8084 } |
8106 break; | 8085 break; |
8107 } | 8086 } |
8108 | 8087 |
8109 case Variable::LOOKUP: | 8088 case Variable::LOOKUP: |
8110 return Bailout("lookup variable in count operation"); | 8089 return Bailout("lookup variable in count operation"); |
8111 } | 8090 } |
8112 | 8091 |
8113 } else { | 8092 } else { |
8114 // Argument of the count operation is a property. | 8093 // Argument of the count operation is a property. |
(...skipping 20 matching lines...) Expand all Loading... |
8135 Handle<JSObject> holder; | 8114 Handle<JSObject> holder; |
8136 if (LookupGetter(map, name, &getter, &holder)) { | 8115 if (LookupGetter(map, name, &getter, &holder)) { |
8137 load = BuildCallGetter(object, map, getter, holder); | 8116 load = BuildCallGetter(object, map, getter, holder); |
8138 } else { | 8117 } else { |
8139 load = BuildLoadNamedMonomorphic(object, name, prop, map); | 8118 load = BuildLoadNamedMonomorphic(object, name, prop, map); |
8140 } | 8119 } |
8141 } else { | 8120 } else { |
8142 load = BuildLoadNamedGeneric(object, name, prop); | 8121 load = BuildLoadNamedGeneric(object, name, prop); |
8143 } | 8122 } |
8144 PushAndAdd(load); | 8123 PushAndAdd(load); |
8145 if (load->HasObservableSideEffects()) AddSimulate(prop->LoadId()); | 8124 if (load->HasObservableSideEffects()) { |
| 8125 AddSimulate(prop->LoadId(), REMOVABLE); |
| 8126 } |
8146 | 8127 |
8147 after = BuildIncrement(returns_original_input, expr); | 8128 after = BuildIncrement(returns_original_input, expr); |
8148 input = Pop(); | 8129 input = Pop(); |
8149 | 8130 |
8150 HInstruction* store; | 8131 HInstruction* store; |
8151 if (!monomorphic) { | 8132 if (!monomorphic) { |
8152 // If we don't know the monomorphic type, do a generic store. | 8133 // If we don't know the monomorphic type, do a generic store. |
8153 CHECK_ALIVE(store = BuildStoreNamedGeneric(object, name, after)); | 8134 CHECK_ALIVE(store = BuildStoreNamedGeneric(object, name, after)); |
8154 } else { | 8135 } else { |
8155 Handle<JSFunction> setter; | 8136 Handle<JSFunction> setter; |
8156 Handle<JSObject> holder; | 8137 Handle<JSObject> holder; |
8157 if (LookupSetter(map, name, &setter, &holder)) { | 8138 if (LookupSetter(map, name, &setter, &holder)) { |
8158 store = BuildCallSetter(object, after, map, setter, holder); | 8139 store = BuildCallSetter(object, after, map, setter, holder); |
8159 } else { | 8140 } else { |
8160 CHECK_ALIVE(store = BuildStoreNamedMonomorphic(object, | 8141 CHECK_ALIVE(store = BuildStoreNamedMonomorphic(object, |
8161 name, | 8142 name, |
8162 after, | 8143 after, |
8163 map)); | 8144 map)); |
8164 } | 8145 } |
8165 } | 8146 } |
8166 AddInstruction(store); | 8147 AddInstruction(store); |
8167 | 8148 |
8168 // Overwrite the receiver in the bailout environment with the result | 8149 // Overwrite the receiver in the bailout environment with the result |
8169 // of the operation, and the placeholder with the original value if | 8150 // of the operation, and the placeholder with the original value if |
8170 // necessary. | 8151 // necessary. |
8171 environment()->SetExpressionStackAt(0, after); | 8152 environment()->SetExpressionStackAt(0, after); |
8172 if (returns_original_input) environment()->SetExpressionStackAt(1, input); | 8153 if (returns_original_input) environment()->SetExpressionStackAt(1, input); |
8173 if (store->HasObservableSideEffects()) AddSimulate(expr->AssignmentId()); | 8154 if (store->HasObservableSideEffects()) { |
| 8155 AddSimulate(expr->AssignmentId(), REMOVABLE); |
| 8156 } |
8174 | 8157 |
8175 } else { | 8158 } else { |
8176 // Keyed property. | 8159 // Keyed property. |
8177 if (returns_original_input) Push(graph_->GetConstantUndefined()); | 8160 if (returns_original_input) Push(graph_->GetConstantUndefined()); |
8178 | 8161 |
8179 CHECK_ALIVE(VisitForValue(prop->obj())); | 8162 CHECK_ALIVE(VisitForValue(prop->obj())); |
8180 CHECK_ALIVE(VisitForValue(prop->key())); | 8163 CHECK_ALIVE(VisitForValue(prop->key())); |
8181 HValue* obj = environment()->ExpressionStackAt(1); | 8164 HValue* obj = environment()->ExpressionStackAt(1); |
8182 HValue* key = environment()->ExpressionStackAt(0); | 8165 HValue* key = environment()->ExpressionStackAt(0); |
8183 | 8166 |
8184 bool has_side_effects = false; | 8167 bool has_side_effects = false; |
8185 HValue* load = HandleKeyedElementAccess( | 8168 HValue* load = HandleKeyedElementAccess( |
8186 obj, key, NULL, prop, prop->LoadId(), RelocInfo::kNoPosition, | 8169 obj, key, NULL, prop, prop->LoadId(), RelocInfo::kNoPosition, |
8187 false, // is_store | 8170 false, // is_store |
8188 &has_side_effects); | 8171 &has_side_effects); |
8189 Push(load); | 8172 Push(load); |
8190 if (has_side_effects) AddSimulate(prop->LoadId()); | 8173 if (has_side_effects) AddSimulate(prop->LoadId(), REMOVABLE); |
8191 | 8174 |
8192 after = BuildIncrement(returns_original_input, expr); | 8175 after = BuildIncrement(returns_original_input, expr); |
8193 input = Pop(); | 8176 input = Pop(); |
8194 | 8177 |
8195 expr->RecordTypeFeedback(oracle(), zone()); | 8178 expr->RecordTypeFeedback(oracle(), zone()); |
8196 HandleKeyedElementAccess(obj, key, after, expr, expr->AssignmentId(), | 8179 HandleKeyedElementAccess(obj, key, after, expr, expr->AssignmentId(), |
8197 RelocInfo::kNoPosition, | 8180 RelocInfo::kNoPosition, |
8198 true, // is_store | 8181 true, // is_store |
8199 &has_side_effects); | 8182 &has_side_effects); |
8200 | 8183 |
8201 // Drop the key from the bailout environment. Overwrite the receiver | 8184 // Drop the key from the bailout environment. Overwrite the receiver |
8202 // with the result of the operation, and the placeholder with the | 8185 // with the result of the operation, and the placeholder with the |
8203 // original value if necessary. | 8186 // original value if necessary. |
8204 Drop(1); | 8187 Drop(1); |
8205 environment()->SetExpressionStackAt(0, after); | 8188 environment()->SetExpressionStackAt(0, after); |
8206 if (returns_original_input) environment()->SetExpressionStackAt(1, input); | 8189 if (returns_original_input) environment()->SetExpressionStackAt(1, input); |
8207 ASSERT(has_side_effects); // Stores always have side effects. | 8190 ASSERT(has_side_effects); // Stores always have side effects. |
8208 AddSimulate(expr->AssignmentId()); | 8191 AddSimulate(expr->AssignmentId(), REMOVABLE); |
8209 } | 8192 } |
8210 } | 8193 } |
8211 | 8194 |
8212 Drop(returns_original_input ? 2 : 1); | 8195 Drop(returns_original_input ? 2 : 1); |
8213 return ast_context()->ReturnValue(expr->is_postfix() ? input : after); | 8196 return ast_context()->ReturnValue(expr->is_postfix() ? input : after); |
8214 } | 8197 } |
8215 | 8198 |
8216 | 8199 |
8217 HStringCharCodeAt* HGraphBuilder::BuildStringCharCodeAt(HValue* context, | 8200 HStringCharCodeAt* HGraphBuilder::BuildStringCharCodeAt(HValue* context, |
8218 HValue* string, | 8201 HValue* string, |
8219 HValue* index) { | 8202 HValue* index) { |
8220 AddInstruction(new(zone()) HCheckNonSmi(string)); | 8203 AddInstruction(new(zone()) HCheckNonSmi(string)); |
8221 AddInstruction(HCheckInstanceType::NewIsString(string, zone())); | 8204 AddInstruction(HCheckInstanceType::NewIsString(string, zone())); |
8222 HStringLength* length = new(zone()) HStringLength(string); | 8205 HStringLength* length = new(zone()) HStringLength(string); |
8223 AddInstruction(length); | 8206 AddInstruction(length); |
8224 HInstruction* checked_index = | 8207 HInstruction* checked_index = |
8225 AddInstruction(new(zone()) HBoundsCheck(index, length)); | 8208 AddInstruction(new(zone()) HBoundsCheck(index, length)); |
8226 return new(zone()) HStringCharCodeAt(context, string, checked_index); | 8209 return new(zone()) HStringCharCodeAt(context, string, checked_index); |
8227 } | 8210 } |
8228 | 8211 |
8229 | 8212 |
8230 HInstruction* HGraphBuilder::BuildBinaryOperation(BinaryOperation* expr, | 8213 HInstruction* HGraphBuilder::BuildBinaryOperation(BinaryOperation* expr, |
8231 HValue* left, | 8214 HValue* left, |
8232 HValue* right) { | 8215 HValue* right) { |
8233 HValue* context = environment()->LookupContext(); | 8216 HValue* context = environment()->LookupContext(); |
8234 TypeInfo info = oracle()->BinaryType(expr); | 8217 TypeInfo left_info, right_info, result_info, combined_info; |
8235 if (info.IsUninitialized()) { | 8218 oracle()->BinaryType(expr, &left_info, &right_info, &result_info); |
| 8219 Representation left_rep = ToRepresentation(left_info); |
| 8220 Representation right_rep = ToRepresentation(right_info); |
| 8221 Representation result_rep = ToRepresentation(result_info); |
| 8222 if (left_info.IsUninitialized()) { |
| 8223 // Can't have initialized one but not the other. |
| 8224 ASSERT(right_info.IsUninitialized()); |
8236 AddInstruction(new(zone()) HSoftDeoptimize); | 8225 AddInstruction(new(zone()) HSoftDeoptimize); |
8237 current_block()->MarkAsDeoptimizing(); | 8226 current_block()->MarkAsDeoptimizing(); |
8238 info = TypeInfo::Unknown(); | 8227 left_info = right_info = TypeInfo::Unknown(); |
8239 } | 8228 } |
8240 HInstruction* instr = NULL; | 8229 HInstruction* instr = NULL; |
8241 switch (expr->op()) { | 8230 switch (expr->op()) { |
8242 case Token::ADD: | 8231 case Token::ADD: |
8243 if (info.IsString()) { | 8232 if (left_info.IsString() && right_info.IsString()) { |
8244 AddInstruction(new(zone()) HCheckNonSmi(left)); | 8233 AddInstruction(new(zone()) HCheckNonSmi(left)); |
8245 AddInstruction(HCheckInstanceType::NewIsString(left, zone())); | 8234 AddInstruction(HCheckInstanceType::NewIsString(left, zone())); |
8246 AddInstruction(new(zone()) HCheckNonSmi(right)); | 8235 AddInstruction(new(zone()) HCheckNonSmi(right)); |
8247 AddInstruction(HCheckInstanceType::NewIsString(right, zone())); | 8236 AddInstruction(HCheckInstanceType::NewIsString(right, zone())); |
8248 instr = new(zone()) HStringAdd(context, left, right); | 8237 instr = new(zone()) HStringAdd(context, left, right); |
8249 } else { | 8238 } else { |
8250 instr = HAdd::NewHAdd(zone(), context, left, right); | 8239 instr = HAdd::NewHAdd(zone(), context, left, right); |
8251 } | 8240 } |
8252 break; | 8241 break; |
8253 case Token::SUB: | 8242 case Token::SUB: |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8285 if (can_be_shift_by_zero) graph()->RecordUint32Instruction(instr); | 8274 if (can_be_shift_by_zero) graph()->RecordUint32Instruction(instr); |
8286 } | 8275 } |
8287 break; | 8276 break; |
8288 case Token::SHL: | 8277 case Token::SHL: |
8289 instr = HShl::NewHShl(zone(), context, left, right); | 8278 instr = HShl::NewHShl(zone(), context, left, right); |
8290 break; | 8279 break; |
8291 default: | 8280 default: |
8292 UNREACHABLE(); | 8281 UNREACHABLE(); |
8293 } | 8282 } |
8294 | 8283 |
8295 // If we hit an uninitialized binary op stub we will get type info | 8284 if (instr->IsBinaryOperation()) { |
8296 // for a smi operation. If one of the operands is a constant string | 8285 HBinaryOperation* binop = HBinaryOperation::cast(instr); |
8297 // do not generate code assuming it is a smi operation. | 8286 binop->set_observed_input_representation(left_rep, right_rep); |
8298 if (info.IsSmi() && | 8287 binop->initialize_output_representation(result_rep); |
8299 ((left->IsConstant() && HConstant::cast(left)->handle()->IsString()) || | |
8300 (right->IsConstant() && HConstant::cast(right)->handle()->IsString()))) { | |
8301 return instr; | |
8302 } | 8288 } |
8303 Representation rep = ToRepresentation(info); | |
8304 // We only generate either int32 or generic tagged bitwise operations. | |
8305 if (instr->IsBitwiseBinaryOperation()) { | |
8306 HBitwiseBinaryOperation::cast(instr)-> | |
8307 InitializeObservedInputRepresentation(rep); | |
8308 if (rep.IsDouble()) rep = Representation::Integer32(); | |
8309 } | |
8310 TraceRepresentation(expr->op(), info, instr, rep); | |
8311 instr->AssumeRepresentation(rep); | |
8312 return instr; | 8289 return instr; |
8313 } | 8290 } |
8314 | 8291 |
8315 | 8292 |
8316 // Check for the form (%_ClassOf(foo) === 'BarClass'). | 8293 // Check for the form (%_ClassOf(foo) === 'BarClass'). |
8317 static bool IsClassOfTest(CompareOperation* expr) { | 8294 static bool IsClassOfTest(CompareOperation* expr) { |
8318 if (expr->op() != Token::EQ_STRICT) return false; | 8295 if (expr->op() != Token::EQ_STRICT) return false; |
8319 CallRuntime* call = expr->left()->AsCallRuntime(); | 8296 CallRuntime* call = expr->left()->AsCallRuntime(); |
8320 if (call == NULL) return false; | 8297 if (call == NULL) return false; |
8321 Literal* literal = expr->right()->AsLiteral(); | 8298 Literal* literal = expr->right()->AsLiteral(); |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8445 CHECK_ALIVE(VisitForValue(expr->left())); | 8422 CHECK_ALIVE(VisitForValue(expr->left())); |
8446 CHECK_ALIVE(VisitForValue(expr->right())); | 8423 CHECK_ALIVE(VisitForValue(expr->right())); |
8447 HValue* right = Pop(); | 8424 HValue* right = Pop(); |
8448 HValue* left = Pop(); | 8425 HValue* left = Pop(); |
8449 HInstruction* instr = BuildBinaryOperation(expr, left, right); | 8426 HInstruction* instr = BuildBinaryOperation(expr, left, right); |
8450 instr->set_position(expr->position()); | 8427 instr->set_position(expr->position()); |
8451 return ast_context()->ReturnInstruction(instr, expr->id()); | 8428 return ast_context()->ReturnInstruction(instr, expr->id()); |
8452 } | 8429 } |
8453 | 8430 |
8454 | 8431 |
8455 void HGraphBuilder::TraceRepresentation(Token::Value op, | |
8456 TypeInfo info, | |
8457 HValue* value, | |
8458 Representation rep) { | |
8459 if (!FLAG_trace_representation) return; | |
8460 // TODO(svenpanne) Under which circumstances are we actually not flexible? | |
8461 // At first glance, this looks a bit weird... | |
8462 bool flexible = value->CheckFlag(HValue::kFlexibleRepresentation); | |
8463 PrintF("Operation %s has type info %s, %schange representation assumption " | |
8464 "for %s (ID %d) from %s to %s\n", | |
8465 Token::Name(op), | |
8466 info.ToString(), | |
8467 flexible ? "" : " DO NOT ", | |
8468 value->Mnemonic(), | |
8469 graph_->GetMaximumValueID(), | |
8470 value->representation().Mnemonic(), | |
8471 rep.Mnemonic()); | |
8472 } | |
8473 | |
8474 | |
8475 Representation HGraphBuilder::ToRepresentation(TypeInfo info) { | 8432 Representation HGraphBuilder::ToRepresentation(TypeInfo info) { |
| 8433 if (info.IsUninitialized()) return Representation::None(); |
8476 if (info.IsSmi()) return Representation::Integer32(); | 8434 if (info.IsSmi()) return Representation::Integer32(); |
8477 if (info.IsInteger32()) return Representation::Integer32(); | 8435 if (info.IsInteger32()) return Representation::Integer32(); |
8478 if (info.IsDouble()) return Representation::Double(); | 8436 if (info.IsDouble()) return Representation::Double(); |
8479 if (info.IsNumber()) return Representation::Double(); | 8437 if (info.IsNumber()) return Representation::Double(); |
8480 return Representation::Tagged(); | 8438 return Representation::Tagged(); |
8481 } | 8439 } |
8482 | 8440 |
8483 | 8441 |
8484 void HGraphBuilder::HandleLiteralCompareTypeof(CompareOperation* expr, | 8442 void HGraphBuilder::HandleLiteralCompareTypeof(CompareOperation* expr, |
8485 HTypeof* typeof_expr, | 8443 HTypeof* typeof_expr, |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8563 CHECK_ALIVE(VisitForValue(call->arguments()->at(0))); | 8521 CHECK_ALIVE(VisitForValue(call->arguments()->at(0))); |
8564 HValue* value = Pop(); | 8522 HValue* value = Pop(); |
8565 Literal* literal = expr->right()->AsLiteral(); | 8523 Literal* literal = expr->right()->AsLiteral(); |
8566 Handle<String> rhs = Handle<String>::cast(literal->handle()); | 8524 Handle<String> rhs = Handle<String>::cast(literal->handle()); |
8567 HClassOfTestAndBranch* instr = | 8525 HClassOfTestAndBranch* instr = |
8568 new(zone()) HClassOfTestAndBranch(value, rhs); | 8526 new(zone()) HClassOfTestAndBranch(value, rhs); |
8569 instr->set_position(expr->position()); | 8527 instr->set_position(expr->position()); |
8570 return ast_context()->ReturnControl(instr, expr->id()); | 8528 return ast_context()->ReturnControl(instr, expr->id()); |
8571 } | 8529 } |
8572 | 8530 |
8573 TypeInfo type_info = oracle()->CompareType(expr); | 8531 TypeInfo left_type, right_type, overall_type_info; |
| 8532 oracle()->CompareType(expr, &left_type, &right_type, &overall_type_info); |
| 8533 Representation combined_rep = ToRepresentation(overall_type_info); |
| 8534 Representation left_rep = ToRepresentation(left_type); |
| 8535 Representation right_rep = ToRepresentation(right_type); |
8574 // Check if this expression was ever executed according to type feedback. | 8536 // Check if this expression was ever executed according to type feedback. |
8575 // Note that for the special typeof/null/undefined cases we get unknown here. | 8537 // Note that for the special typeof/null/undefined cases we get unknown here. |
8576 if (type_info.IsUninitialized()) { | 8538 if (overall_type_info.IsUninitialized()) { |
8577 AddInstruction(new(zone()) HSoftDeoptimize); | 8539 AddInstruction(new(zone()) HSoftDeoptimize); |
8578 current_block()->MarkAsDeoptimizing(); | 8540 current_block()->MarkAsDeoptimizing(); |
8579 type_info = TypeInfo::Unknown(); | 8541 overall_type_info = left_type = right_type = TypeInfo::Unknown(); |
8580 } | 8542 } |
8581 | 8543 |
8582 CHECK_ALIVE(VisitForValue(expr->left())); | 8544 CHECK_ALIVE(VisitForValue(expr->left())); |
8583 CHECK_ALIVE(VisitForValue(expr->right())); | 8545 CHECK_ALIVE(VisitForValue(expr->right())); |
8584 | 8546 |
8585 HValue* context = environment()->LookupContext(); | 8547 HValue* context = environment()->LookupContext(); |
8586 HValue* right = Pop(); | 8548 HValue* right = Pop(); |
8587 HValue* left = Pop(); | 8549 HValue* left = Pop(); |
8588 Token::Value op = expr->op(); | 8550 Token::Value op = expr->op(); |
8589 | 8551 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8641 AddInstruction(new(zone()) HCheckFunction(right, target)); | 8603 AddInstruction(new(zone()) HCheckFunction(right, target)); |
8642 HInstanceOfKnownGlobal* result = | 8604 HInstanceOfKnownGlobal* result = |
8643 new(zone()) HInstanceOfKnownGlobal(context, left, target); | 8605 new(zone()) HInstanceOfKnownGlobal(context, left, target); |
8644 result->set_position(expr->position()); | 8606 result->set_position(expr->position()); |
8645 return ast_context()->ReturnInstruction(result, expr->id()); | 8607 return ast_context()->ReturnInstruction(result, expr->id()); |
8646 } | 8608 } |
8647 } else if (op == Token::IN) { | 8609 } else if (op == Token::IN) { |
8648 HIn* result = new(zone()) HIn(context, left, right); | 8610 HIn* result = new(zone()) HIn(context, left, right); |
8649 result->set_position(expr->position()); | 8611 result->set_position(expr->position()); |
8650 return ast_context()->ReturnInstruction(result, expr->id()); | 8612 return ast_context()->ReturnInstruction(result, expr->id()); |
8651 } else if (type_info.IsNonPrimitive()) { | 8613 } else if (overall_type_info.IsNonPrimitive()) { |
8652 switch (op) { | 8614 switch (op) { |
8653 case Token::EQ: | 8615 case Token::EQ: |
8654 case Token::EQ_STRICT: { | 8616 case Token::EQ_STRICT: { |
8655 // Can we get away with map check and not instance type check? | 8617 // Can we get away with map check and not instance type check? |
8656 Handle<Map> map = oracle()->GetCompareMap(expr); | 8618 Handle<Map> map = oracle()->GetCompareMap(expr); |
8657 if (!map.is_null()) { | 8619 if (!map.is_null()) { |
8658 AddCheckMapsWithTransitions(left, map); | 8620 AddCheckMapsWithTransitions(left, map); |
8659 AddCheckMapsWithTransitions(right, map); | 8621 AddCheckMapsWithTransitions(right, map); |
8660 HCompareObjectEqAndBranch* result = | 8622 HCompareObjectEqAndBranch* result = |
8661 new(zone()) HCompareObjectEqAndBranch(left, right); | 8623 new(zone()) HCompareObjectEqAndBranch(left, right); |
8662 result->set_position(expr->position()); | 8624 result->set_position(expr->position()); |
8663 return ast_context()->ReturnControl(result, expr->id()); | 8625 return ast_context()->ReturnControl(result, expr->id()); |
8664 } else { | 8626 } else { |
8665 AddInstruction(new(zone()) HCheckNonSmi(left)); | 8627 AddInstruction(new(zone()) HCheckNonSmi(left)); |
8666 AddInstruction(HCheckInstanceType::NewIsSpecObject(left, zone())); | 8628 AddInstruction(HCheckInstanceType::NewIsSpecObject(left, zone())); |
8667 AddInstruction(new(zone()) HCheckNonSmi(right)); | 8629 AddInstruction(new(zone()) HCheckNonSmi(right)); |
8668 AddInstruction(HCheckInstanceType::NewIsSpecObject(right, zone())); | 8630 AddInstruction(HCheckInstanceType::NewIsSpecObject(right, zone())); |
8669 HCompareObjectEqAndBranch* result = | 8631 HCompareObjectEqAndBranch* result = |
8670 new(zone()) HCompareObjectEqAndBranch(left, right); | 8632 new(zone()) HCompareObjectEqAndBranch(left, right); |
8671 result->set_position(expr->position()); | 8633 result->set_position(expr->position()); |
8672 return ast_context()->ReturnControl(result, expr->id()); | 8634 return ast_context()->ReturnControl(result, expr->id()); |
8673 } | 8635 } |
8674 } | 8636 } |
8675 default: | 8637 default: |
8676 return Bailout("Unsupported non-primitive compare"); | 8638 return Bailout("Unsupported non-primitive compare"); |
8677 } | 8639 } |
8678 } else if (type_info.IsString() && oracle()->IsSymbolCompare(expr) && | 8640 } else if (overall_type_info.IsSymbol() && Token::IsEqualityOp(op)) { |
8679 (op == Token::EQ || op == Token::EQ_STRICT)) { | |
8680 AddInstruction(new(zone()) HCheckNonSmi(left)); | 8641 AddInstruction(new(zone()) HCheckNonSmi(left)); |
8681 AddInstruction(HCheckInstanceType::NewIsSymbol(left, zone())); | 8642 AddInstruction(HCheckInstanceType::NewIsSymbol(left, zone())); |
8682 AddInstruction(new(zone()) HCheckNonSmi(right)); | 8643 AddInstruction(new(zone()) HCheckNonSmi(right)); |
8683 AddInstruction(HCheckInstanceType::NewIsSymbol(right, zone())); | 8644 AddInstruction(HCheckInstanceType::NewIsSymbol(right, zone())); |
8684 HCompareObjectEqAndBranch* result = | 8645 HCompareObjectEqAndBranch* result = |
8685 new(zone()) HCompareObjectEqAndBranch(left, right); | 8646 new(zone()) HCompareObjectEqAndBranch(left, right); |
8686 result->set_position(expr->position()); | 8647 result->set_position(expr->position()); |
8687 return ast_context()->ReturnControl(result, expr->id()); | 8648 return ast_context()->ReturnControl(result, expr->id()); |
8688 } else { | 8649 } else { |
8689 Representation r = ToRepresentation(type_info); | 8650 if (combined_rep.IsTagged() || combined_rep.IsNone()) { |
8690 if (r.IsTagged()) { | |
8691 HCompareGeneric* result = | 8651 HCompareGeneric* result = |
8692 new(zone()) HCompareGeneric(context, left, right, op); | 8652 new(zone()) HCompareGeneric(context, left, right, op); |
| 8653 result->set_observed_input_representation(left_rep, right_rep); |
8693 result->set_position(expr->position()); | 8654 result->set_position(expr->position()); |
8694 return ast_context()->ReturnInstruction(result, expr->id()); | 8655 return ast_context()->ReturnInstruction(result, expr->id()); |
8695 } else { | 8656 } else { |
8696 HCompareIDAndBranch* result = | 8657 HCompareIDAndBranch* result = |
8697 new(zone()) HCompareIDAndBranch(left, right, op); | 8658 new(zone()) HCompareIDAndBranch(left, right, op); |
| 8659 result->set_observed_input_representation(left_rep, right_rep); |
8698 result->set_position(expr->position()); | 8660 result->set_position(expr->position()); |
8699 result->SetInputRepresentation(r); | |
8700 return ast_context()->ReturnControl(result, expr->id()); | 8661 return ast_context()->ReturnControl(result, expr->id()); |
8701 } | 8662 } |
8702 } | 8663 } |
8703 } | 8664 } |
8704 | 8665 |
8705 | 8666 |
8706 void HGraphBuilder::HandleLiteralCompareNil(CompareOperation* expr, | 8667 void HGraphBuilder::HandleLiteralCompareNil(CompareOperation* expr, |
8707 HValue* value, | 8668 HValue* value, |
8708 NilValue nil) { | 8669 NilValue nil) { |
8709 ASSERT(!HasStackOverflow()); | 8670 ASSERT(!HasStackOverflow()); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8776 environment()->Bind(variable, value); | 8737 environment()->Bind(variable, value); |
8777 } | 8738 } |
8778 break; | 8739 break; |
8779 case Variable::CONTEXT: | 8740 case Variable::CONTEXT: |
8780 if (hole_init) { | 8741 if (hole_init) { |
8781 HValue* value = graph()->GetConstantHole(); | 8742 HValue* value = graph()->GetConstantHole(); |
8782 HValue* context = environment()->LookupContext(); | 8743 HValue* context = environment()->LookupContext(); |
8783 HStoreContextSlot* store = new(zone()) HStoreContextSlot( | 8744 HStoreContextSlot* store = new(zone()) HStoreContextSlot( |
8784 context, variable->index(), HStoreContextSlot::kNoCheck, value); | 8745 context, variable->index(), HStoreContextSlot::kNoCheck, value); |
8785 AddInstruction(store); | 8746 AddInstruction(store); |
8786 if (store->HasObservableSideEffects()) AddSimulate(proxy->id()); | 8747 if (store->HasObservableSideEffects()) { |
| 8748 AddSimulate(proxy->id(), REMOVABLE); |
| 8749 } |
8787 } | 8750 } |
8788 break; | 8751 break; |
8789 case Variable::LOOKUP: | 8752 case Variable::LOOKUP: |
8790 return Bailout("unsupported lookup slot in declaration"); | 8753 return Bailout("unsupported lookup slot in declaration"); |
8791 } | 8754 } |
8792 } | 8755 } |
8793 | 8756 |
8794 | 8757 |
8795 void HGraphBuilder::VisitFunctionDeclaration(FunctionDeclaration* declaration) { | 8758 void HGraphBuilder::VisitFunctionDeclaration(FunctionDeclaration* declaration) { |
8796 VariableProxy* proxy = declaration->proxy(); | 8759 VariableProxy* proxy = declaration->proxy(); |
(...skipping 15 matching lines...) Expand all Loading... |
8812 environment()->Bind(variable, value); | 8775 environment()->Bind(variable, value); |
8813 break; | 8776 break; |
8814 } | 8777 } |
8815 case Variable::CONTEXT: { | 8778 case Variable::CONTEXT: { |
8816 CHECK_ALIVE(VisitForValue(declaration->fun())); | 8779 CHECK_ALIVE(VisitForValue(declaration->fun())); |
8817 HValue* value = Pop(); | 8780 HValue* value = Pop(); |
8818 HValue* context = environment()->LookupContext(); | 8781 HValue* context = environment()->LookupContext(); |
8819 HStoreContextSlot* store = new(zone()) HStoreContextSlot( | 8782 HStoreContextSlot* store = new(zone()) HStoreContextSlot( |
8820 context, variable->index(), HStoreContextSlot::kNoCheck, value); | 8783 context, variable->index(), HStoreContextSlot::kNoCheck, value); |
8821 AddInstruction(store); | 8784 AddInstruction(store); |
8822 if (store->HasObservableSideEffects()) AddSimulate(proxy->id()); | 8785 if (store->HasObservableSideEffects()) { |
| 8786 AddSimulate(proxy->id(), REMOVABLE); |
| 8787 } |
8823 break; | 8788 break; |
8824 } | 8789 } |
8825 case Variable::LOOKUP: | 8790 case Variable::LOOKUP: |
8826 return Bailout("unsupported lookup slot in declaration"); | 8791 return Bailout("unsupported lookup slot in declaration"); |
8827 } | 8792 } |
8828 } | 8793 } |
8829 | 8794 |
8830 | 8795 |
8831 void HGraphBuilder::VisitModuleDeclaration(ModuleDeclaration* declaration) { | 8796 void HGraphBuilder::VisitModuleDeclaration(ModuleDeclaration* declaration) { |
8832 UNREACHABLE(); | 8797 UNREACHABLE(); |
(...skipping 1122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9955 } | 9920 } |
9956 } | 9921 } |
9957 | 9922 |
9958 #ifdef DEBUG | 9923 #ifdef DEBUG |
9959 if (graph_ != NULL) graph_->Verify(false); // No full verify. | 9924 if (graph_ != NULL) graph_->Verify(false); // No full verify. |
9960 if (allocator_ != NULL) allocator_->Verify(); | 9925 if (allocator_ != NULL) allocator_->Verify(); |
9961 #endif | 9926 #endif |
9962 } | 9927 } |
9963 | 9928 |
9964 } } // namespace v8::internal | 9929 } } // namespace v8::internal |
OLD | NEW |