Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: src/hydrogen.cc

Issue 9431030: Support OSR in for-in loops. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Extend OptimizeFunctionOnNextCall with an arguments to force OSR. Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 3040 matching lines...) Expand 10 before | Expand all | Expand 10 after
3051 HBasicBlock* osr_entry = graph()->CreateBasicBlock(); 3051 HBasicBlock* osr_entry = graph()->CreateBasicBlock();
3052 HValue* true_value = graph()->GetConstantTrue(); 3052 HValue* true_value = graph()->GetConstantTrue();
3053 HBranch* test = new(zone()) HBranch(true_value, non_osr_entry, osr_entry); 3053 HBranch* test = new(zone()) HBranch(true_value, non_osr_entry, osr_entry);
3054 current_block()->Finish(test); 3054 current_block()->Finish(test);
3055 3055
3056 HBasicBlock* loop_predecessor = graph()->CreateBasicBlock(); 3056 HBasicBlock* loop_predecessor = graph()->CreateBasicBlock();
3057 non_osr_entry->Goto(loop_predecessor); 3057 non_osr_entry->Goto(loop_predecessor);
3058 3058
3059 set_current_block(osr_entry); 3059 set_current_block(osr_entry);
3060 int osr_entry_id = statement->OsrEntryId(); 3060 int osr_entry_id = statement->OsrEntryId();
3061 // We want the correct environment at the OsrEntry instruction. Build 3061 int first_expression_index = environment()->first_expression_index();
3062 // it explicitly. The expression stack should be empty. 3062 int length = environment()->length();
3063 ASSERT(environment()->ExpressionStackIsEmpty()); 3063 for (int i = 0; i < first_expression_index; ++i) {
3064 for (int i = 0; i < environment()->length(); ++i) {
3065 HUnknownOSRValue* osr_value = new(zone()) HUnknownOSRValue; 3064 HUnknownOSRValue* osr_value = new(zone()) HUnknownOSRValue;
3066 AddInstruction(osr_value); 3065 AddInstruction(osr_value);
3067 environment()->Bind(i, osr_value); 3066 environment()->Bind(i, osr_value);
3068 } 3067 }
3069 3068
3069 if (first_expression_index != length) {
3070 environment()->Drop(length - first_expression_index);
3071 for (int i = first_expression_index; i < length; ++i) {
3072 HUnknownOSRValue* osr_value = new(zone()) HUnknownOSRValue;
3073 AddInstruction(osr_value);
3074 environment()->Push(osr_value);
3075 }
3076 }
3077
3078
3070 AddSimulate(osr_entry_id); 3079 AddSimulate(osr_entry_id);
3071 AddInstruction(new(zone()) HOsrEntry(osr_entry_id)); 3080 AddInstruction(new(zone()) HOsrEntry(osr_entry_id));
3072 HContext* context = new(zone()) HContext; 3081 HContext* context = new(zone()) HContext;
3073 AddInstruction(context); 3082 AddInstruction(context);
3074 environment()->BindContext(context); 3083 environment()->BindContext(context);
3075 current_block()->Goto(loop_predecessor); 3084 current_block()->Goto(loop_predecessor);
3076 loop_predecessor->SetJoinId(statement->EntryId()); 3085 loop_predecessor->SetJoinId(statement->EntryId());
3077 set_current_block(loop_predecessor); 3086 set_current_block(loop_predecessor);
3078 } 3087 }
3079 3088
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
3267 Push(start_index); 3276 Push(start_index);
3268 3277
3269 HInstruction* index_cache = AddInstruction( 3278 HInstruction* index_cache = AddInstruction(
3270 new(zone()) HForInCacheArray( 3279 new(zone()) HForInCacheArray(
3271 enumerable, 3280 enumerable,
3272 map, 3281 map,
3273 DescriptorArray::kEnumCacheBridgeIndicesCacheIndex)); 3282 DescriptorArray::kEnumCacheBridgeIndicesCacheIndex));
3274 HForInCacheArray::cast(array)->set_index_cache( 3283 HForInCacheArray::cast(array)->set_index_cache(
3275 HForInCacheArray::cast(index_cache)); 3284 HForInCacheArray::cast(index_cache));
3276 3285
3286 PreProcessOsrEntry(stmt);
3277 HBasicBlock* loop_entry = CreateLoopHeaderBlock(); 3287 HBasicBlock* loop_entry = CreateLoopHeaderBlock();
3278 current_block()->Goto(loop_entry); 3288 current_block()->Goto(loop_entry);
3279 set_current_block(loop_entry); 3289 set_current_block(loop_entry);
3280 3290
3281 HValue* index = Top(); 3291 HValue* index = environment()->ExpressionStackAt(0);
3292 HValue* limit = environment()->ExpressionStackAt(1);
3282 3293
3283 // Check that we still have more keys. 3294 // Check that we still have more keys.
3284 HCompareIDAndBranch* compare_index = 3295 HCompareIDAndBranch* compare_index =
3285 new(zone()) HCompareIDAndBranch(index, array_length, Token::LT); 3296 new(zone()) HCompareIDAndBranch(index, limit, Token::LT);
3286 compare_index->SetInputRepresentation(Representation::Integer32()); 3297 compare_index->SetInputRepresentation(Representation::Integer32());
3287 3298
3288 HBasicBlock* loop_body = graph()->CreateBasicBlock(); 3299 HBasicBlock* loop_body = graph()->CreateBasicBlock();
3289 HBasicBlock* loop_successor = graph()->CreateBasicBlock(); 3300 HBasicBlock* loop_successor = graph()->CreateBasicBlock();
3290 3301
3291 compare_index->SetSuccessorAt(0, loop_body); 3302 compare_index->SetSuccessorAt(0, loop_body);
3292 compare_index->SetSuccessorAt(1, loop_successor); 3303 compare_index->SetSuccessorAt(1, loop_successor);
3293 current_block()->Finish(compare_index); 3304 current_block()->Finish(compare_index);
3294 3305
3295 set_current_block(loop_successor); 3306 set_current_block(loop_successor);
3296 Drop(5); 3307 Drop(5);
3297 3308
3298 set_current_block(loop_body); 3309 set_current_block(loop_body);
3299 3310
3300 HValue* key = AddInstruction( 3311 HValue* key = AddInstruction(
3301 new(zone()) HLoadKeyedFastElement( 3312 new(zone()) HLoadKeyedFastElement(
3302 array, index, HLoadKeyedFastElement::OMIT_HOLE_CHECK)); 3313 environment()->ExpressionStackAt(2), // Enum cache.
3314 environment()->ExpressionStackAt(0), // Iteration index.
3315 HLoadKeyedFastElement::OMIT_HOLE_CHECK));
3303 3316
3304 // Check if the expected map still matches that of the enumerable. 3317 // Check if the expected map still matches that of the enumerable.
3305 // If not just deoptimize. 3318 // If not just deoptimize.
3306 AddInstruction(new(zone()) HCheckMapValue(enumerable, map)); 3319 AddInstruction(new(zone()) HCheckMapValue(
3320 environment()->ExpressionStackAt(4),
3321 environment()->ExpressionStackAt(3)));
3307 3322
3308 Bind(each_var, key); 3323 Bind(each_var, key);
3309 3324
3310 BreakAndContinueInfo break_info(stmt, 5); 3325 BreakAndContinueInfo break_info(stmt, 5);
3311 CHECK_BAILOUT(VisitLoopBody(stmt, loop_entry, &break_info)); 3326 CHECK_BAILOUT(VisitLoopBody(stmt, loop_entry, &break_info));
3312 3327
3313 HBasicBlock* body_exit = 3328 HBasicBlock* body_exit =
3314 JoinContinue(stmt, current_block(), break_info.continue_block()); 3329 JoinContinue(stmt, current_block(), break_info.continue_block());
3315 3330
3316 if (body_exit != NULL) { 3331 if (body_exit != NULL) {
(...skipping 4116 matching lines...) Expand 10 before | Expand all | Expand 10 after
7433 values_[index] = value; 7448 values_[index] = value;
7434 } 7449 }
7435 7450
7436 7451
7437 bool HEnvironment::HasExpressionAt(int index) const { 7452 bool HEnvironment::HasExpressionAt(int index) const {
7438 return index >= parameter_count_ + specials_count_ + local_count_; 7453 return index >= parameter_count_ + specials_count_ + local_count_;
7439 } 7454 }
7440 7455
7441 7456
7442 bool HEnvironment::ExpressionStackIsEmpty() const { 7457 bool HEnvironment::ExpressionStackIsEmpty() const {
7443 int first_expression = parameter_count() + specials_count() + local_count(); 7458 ASSERT(length() >= first_expression_index());
7444 ASSERT(length() >= first_expression); 7459 return length() == first_expression_index();
7445 return length() == first_expression;
7446 } 7460 }
7447 7461
7448 7462
7449 void HEnvironment::SetExpressionStackAt(int index_from_top, HValue* value) { 7463 void HEnvironment::SetExpressionStackAt(int index_from_top, HValue* value) {
7450 int count = index_from_top + 1; 7464 int count = index_from_top + 1;
7451 int index = values_.length() - count; 7465 int index = values_.length() - count;
7452 ASSERT(HasExpressionAt(index)); 7466 ASSERT(HasExpressionAt(index));
7453 // The push count must include at least the element in question or else 7467 // The push count must include at least the element in question or else
7454 // the new value will not be included in this environment's history. 7468 // the new value will not be included in this environment's history.
7455 if (push_count_ < count) { 7469 if (push_count_ < count) {
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
7882 } 7896 }
7883 } 7897 }
7884 7898
7885 #ifdef DEBUG 7899 #ifdef DEBUG
7886 if (graph_ != NULL) graph_->Verify(false); // No full verify. 7900 if (graph_ != NULL) graph_->Verify(false); // No full verify.
7887 if (allocator_ != NULL) allocator_->Verify(); 7901 if (allocator_ != NULL) allocator_->Verify();
7888 #endif 7902 #endif
7889 } 7903 }
7890 7904
7891 } } // namespace v8::internal 7905 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/hydrogen.h ('k') | src/runtime.h » ('j') | test/mjsunit/compiler/optimized-for-in.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698