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

Side by Side Diff: src/hydrogen.cc

Issue 6026006: Simple support for const variables in Crankshaft.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 9 years, 6 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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 514
515 HConstant* HGraph::GetConstantTrue() { 515 HConstant* HGraph::GetConstantTrue() {
516 return GetConstant(&constant_true_, isolate()->heap()->true_value()); 516 return GetConstant(&constant_true_, isolate()->heap()->true_value());
517 } 517 }
518 518
519 519
520 HConstant* HGraph::GetConstantFalse() { 520 HConstant* HGraph::GetConstantFalse() {
521 return GetConstant(&constant_false_, isolate()->heap()->false_value()); 521 return GetConstant(&constant_false_, isolate()->heap()->false_value());
522 } 522 }
523 523
524
525 HConstant* HGraph::GetConstantHole() {
526 return GetConstant(&constant_hole_, isolate()->heap()->the_hole_value());
527 }
528
529
524 HGraphBuilder::HGraphBuilder(CompilationInfo* info, 530 HGraphBuilder::HGraphBuilder(CompilationInfo* info,
525 TypeFeedbackOracle* oracle) 531 TypeFeedbackOracle* oracle)
526 : function_state_(NULL), 532 : function_state_(NULL),
527 initial_function_state_(this, info, oracle), 533 initial_function_state_(this, info, oracle),
528 ast_context_(NULL), 534 ast_context_(NULL),
529 break_scope_(NULL), 535 break_scope_(NULL),
530 graph_(NULL), 536 graph_(NULL),
531 current_block_(NULL), 537 current_block_(NULL),
532 inlined_count_(0), 538 inlined_count_(0),
533 zone_(info->isolate()->zone()), 539 zone_(info->isolate()->zone()),
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 825
820 bool HGraph::CollectPhis() { 826 bool HGraph::CollectPhis() {
821 int block_count = blocks_.length(); 827 int block_count = blocks_.length();
822 phi_list_ = new ZoneList<HPhi*>(block_count); 828 phi_list_ = new ZoneList<HPhi*>(block_count);
823 for (int i = 0; i < block_count; ++i) { 829 for (int i = 0; i < block_count; ++i) {
824 for (int j = 0; j < blocks_[i]->phis()->length(); ++j) { 830 for (int j = 0; j < blocks_[i]->phis()->length(); ++j) {
825 HPhi* phi = blocks_[i]->phis()->at(j); 831 HPhi* phi = blocks_[i]->phis()->at(j);
826 phi_list_->Add(phi); 832 phi_list_->Add(phi);
827 // We don't support phi uses of arguments for now. 833 // We don't support phi uses of arguments for now.
828 if (phi->CheckFlag(HValue::kIsArguments)) return false; 834 if (phi->CheckFlag(HValue::kIsArguments)) return false;
835 // Check for the hole value (from an uninitialized const).
836 for (int k = 0; k < phi->OperandCount(); k++) {
837 if (phi->OperandAt(k) == GetConstantHole()) return false;
838 }
829 } 839 }
830 } 840 }
831 return true; 841 return true;
832 } 842 }
833 843
834 844
835 void HGraph::InferTypes(ZoneList<HValue*>* worklist) { 845 void HGraph::InferTypes(ZoneList<HValue*>* worklist) {
836 BitVector in_worklist(GetMaximumValueID()); 846 BitVector in_worklist(GetMaximumValueID());
837 for (int i = 0; i < worklist->length(); ++i) { 847 for (int i = 0; i < worklist->length(); ++i) {
838 ASSERT(!in_worklist.Contains(worklist->at(i)->id())); 848 ASSERT(!in_worklist.Contains(worklist->at(i)->id()));
(...skipping 1379 matching lines...) Expand 10 before | Expand all | Expand 10 after
2218 current_block()->FinishExit(instr); 2228 current_block()->FinishExit(instr);
2219 set_current_block(NULL); 2229 set_current_block(NULL);
2220 } 2230 }
2221 } 2231 }
2222 2232
2223 graph()->OrderBlocks(); 2233 graph()->OrderBlocks();
2224 graph()->AssignDominators(); 2234 graph()->AssignDominators();
2225 graph()->EliminateRedundantPhis(); 2235 graph()->EliminateRedundantPhis();
2226 if (FLAG_eliminate_dead_phis) graph()->EliminateUnreachablePhis(); 2236 if (FLAG_eliminate_dead_phis) graph()->EliminateUnreachablePhis();
2227 if (!graph()->CollectPhis()) { 2237 if (!graph()->CollectPhis()) {
2228 Bailout("Phi-use of arguments object"); 2238 Bailout("Unsupported phi-use");
2229 return NULL; 2239 return NULL;
2230 } 2240 }
2231 2241
2232 HInferRepresentation rep(graph()); 2242 HInferRepresentation rep(graph());
2233 rep.Analyze(); 2243 rep.Analyze();
2234 2244
2235 if (FLAG_use_range) { 2245 if (FLAG_use_range) {
2236 HRangeAnalysis rangeAnalysis(graph()); 2246 HRangeAnalysis rangeAnalysis(graph());
2237 rangeAnalysis.Analyze(); 2247 rangeAnalysis.Analyze();
2238 } 2248 }
(...skipping 750 matching lines...) Expand 10 before | Expand all | Expand 10 after
2989 2999
2990 3000
2991 void HGraphBuilder::VisitVariableProxy(VariableProxy* expr) { 3001 void HGraphBuilder::VisitVariableProxy(VariableProxy* expr) {
2992 ASSERT(!HasStackOverflow()); 3002 ASSERT(!HasStackOverflow());
2993 ASSERT(current_block() != NULL); 3003 ASSERT(current_block() != NULL);
2994 ASSERT(current_block()->HasPredecessor()); 3004 ASSERT(current_block()->HasPredecessor());
2995 Variable* variable = expr->AsVariable(); 3005 Variable* variable = expr->AsVariable();
2996 if (variable == NULL) { 3006 if (variable == NULL) {
2997 return Bailout("reference to rewritten variable"); 3007 return Bailout("reference to rewritten variable");
2998 } else if (variable->IsStackAllocated()) { 3008 } else if (variable->IsStackAllocated()) {
2999 ast_context()->ReturnValue(environment()->Lookup(variable)); 3009 HValue* value = environment()->Lookup(variable);
3010 if (variable->mode() == Variable::CONST &&
3011 value == graph()->GetConstantHole()) {
3012 return Bailout("reference to uninitialized const variable");
3013 }
3014 ast_context()->ReturnValue(value);
3000 } else if (variable->IsContextSlot()) { 3015 } else if (variable->IsContextSlot()) {
3001 if (variable->mode() == Variable::CONST) { 3016 if (variable->mode() == Variable::CONST) {
3002 return Bailout("reference to const context slot"); 3017 return Bailout("reference to const context slot");
3003 } 3018 }
3004 HValue* context = BuildContextChainWalk(variable); 3019 HValue* context = BuildContextChainWalk(variable);
3005 int index = variable->AsSlot()->index(); 3020 int index = variable->AsSlot()->index();
3006 HLoadContextSlot* instr = new(zone()) HLoadContextSlot(context, index); 3021 HLoadContextSlot* instr = new(zone()) HLoadContextSlot(context, index);
3007 ast_context()->ReturnInstruction(instr, expr->id()); 3022 ast_context()->ReturnInstruction(instr, expr->id());
3008 } else if (variable->is_global()) { 3023 } else if (variable->is_global()) {
3009 LookupResult lookup; 3024 LookupResult lookup;
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
3444 VariableProxy* proxy = target->AsVariableProxy(); 3459 VariableProxy* proxy = target->AsVariableProxy();
3445 Variable* var = proxy->AsVariable(); 3460 Variable* var = proxy->AsVariable();
3446 Property* prop = target->AsProperty(); 3461 Property* prop = target->AsProperty();
3447 ASSERT(var == NULL || prop == NULL); 3462 ASSERT(var == NULL || prop == NULL);
3448 3463
3449 // We have a second position recorded in the FullCodeGenerator to have 3464 // We have a second position recorded in the FullCodeGenerator to have
3450 // type feedback for the binary operation. 3465 // type feedback for the binary operation.
3451 BinaryOperation* operation = expr->binary_operation(); 3466 BinaryOperation* operation = expr->binary_operation();
3452 3467
3453 if (var != NULL) { 3468 if (var != NULL) {
3469 if (var->mode() == Variable::CONST) {
3470 return Bailout("unsupported const compound assignment");
3471 }
3472
3454 CHECK_ALIVE(VisitForValue(operation)); 3473 CHECK_ALIVE(VisitForValue(operation));
3455 3474
3456 if (var->is_global()) { 3475 if (var->is_global()) {
3457 HandleGlobalVariableAssignment(var, 3476 HandleGlobalVariableAssignment(var,
3458 Top(), 3477 Top(),
3459 expr->position(), 3478 expr->position(),
3460 expr->AssignmentId()); 3479 expr->AssignmentId());
3461 } else if (var->IsStackAllocated()) { 3480 } else if (var->IsStackAllocated()) {
3462 Bind(var, Top()); 3481 Bind(var, Top());
3463 } else if (var->IsContextSlot()) { 3482 } else if (var->IsContextSlot()) {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
3550 Variable* var = proxy->AsVariable(); 3569 Variable* var = proxy->AsVariable();
3551 Property* prop = expr->target()->AsProperty(); 3570 Property* prop = expr->target()->AsProperty();
3552 ASSERT(var == NULL || prop == NULL); 3571 ASSERT(var == NULL || prop == NULL);
3553 3572
3554 if (expr->is_compound()) { 3573 if (expr->is_compound()) {
3555 HandleCompoundAssignment(expr); 3574 HandleCompoundAssignment(expr);
3556 return; 3575 return;
3557 } 3576 }
3558 3577
3559 if (var != NULL) { 3578 if (var != NULL) {
3579 if (var->mode() == Variable::CONST) {
3580 if (expr->op() != Token::INIT_CONST) {
3581 return Bailout("non-initializer assignment to const");
3582 }
3583 // We insert a use of the old value to detect unsupported uses of const
3584 // variables (e.g. initialization inside a loop).
3585 HValue* old_value = environment()->Lookup(var);
3586 AddInstruction(new HUseConst(old_value));
3587 }
3588
3560 if (proxy->IsArguments()) return Bailout("assignment to arguments"); 3589 if (proxy->IsArguments()) return Bailout("assignment to arguments");
3561 3590
3562 // Handle the assignment. 3591 // Handle the assignment.
3563 if (var->IsStackAllocated()) { 3592 if (var->IsStackAllocated()) {
3564 // We do not allow the arguments object to occur in a context where it 3593 // We do not allow the arguments object to occur in a context where it
3565 // may escape, but assignments to stack-allocated locals are 3594 // may escape, but assignments to stack-allocated locals are
3566 // permitted. 3595 // permitted.
3567 CHECK_ALIVE(VisitForValue(expr->value(), ARGUMENTS_ALLOWED)); 3596 CHECK_ALIVE(VisitForValue(expr->value(), ARGUMENTS_ALLOWED));
3568 HValue* value = Pop(); 3597 HValue* value = Pop();
3569 Bind(var, value); 3598 Bind(var, value);
(...skipping 1294 matching lines...) Expand 10 before | Expand all | Expand 10 after
4864 4893
4865 // Match the full code generator stack by simulating an extra stack 4894 // Match the full code generator stack by simulating an extra stack
4866 // element for postfix operations in a non-effect context. The return 4895 // element for postfix operations in a non-effect context. The return
4867 // value is ToNumber(input). 4896 // value is ToNumber(input).
4868 bool returns_original_input = 4897 bool returns_original_input =
4869 expr->is_postfix() && !ast_context()->IsEffect(); 4898 expr->is_postfix() && !ast_context()->IsEffect();
4870 HValue* input = NULL; // ToNumber(original_input). 4899 HValue* input = NULL; // ToNumber(original_input).
4871 HValue* after = NULL; // The result after incrementing or decrementing. 4900 HValue* after = NULL; // The result after incrementing or decrementing.
4872 4901
4873 if (var != NULL) { 4902 if (var != NULL) {
4903 if (var->mode() == Variable::CONST) {
4904 return Bailout("unsupported count operation with const");
4905 }
4874 // Argument of the count operation is a variable, not a property. 4906 // Argument of the count operation is a variable, not a property.
4875 ASSERT(prop == NULL); 4907 ASSERT(prop == NULL);
4876 CHECK_ALIVE(VisitForValue(target)); 4908 CHECK_ALIVE(VisitForValue(target));
4877 4909
4878 after = BuildIncrement(returns_original_input, expr); 4910 after = BuildIncrement(returns_original_input, expr);
4879 input = returns_original_input ? Top() : Pop(); 4911 input = returns_original_input ? Top() : Pop();
4880 Push(after); 4912 Push(after);
4881 4913
4882 if (var->is_global()) { 4914 if (var->is_global()) {
4883 HandleGlobalVariableAssignment(var, 4915 HandleGlobalVariableAssignment(var,
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
5328 void HGraphBuilder::VisitThisFunction(ThisFunction* expr) { 5360 void HGraphBuilder::VisitThisFunction(ThisFunction* expr) {
5329 ASSERT(!HasStackOverflow()); 5361 ASSERT(!HasStackOverflow());
5330 ASSERT(current_block() != NULL); 5362 ASSERT(current_block() != NULL);
5331 ASSERT(current_block()->HasPredecessor()); 5363 ASSERT(current_block()->HasPredecessor());
5332 return Bailout("ThisFunction"); 5364 return Bailout("ThisFunction");
5333 } 5365 }
5334 5366
5335 5367
5336 void HGraphBuilder::VisitDeclaration(Declaration* decl) { 5368 void HGraphBuilder::VisitDeclaration(Declaration* decl) {
5337 // We allow only declarations that do not require code generation. 5369 // We allow only declarations that do not require code generation.
5338 // The following all require code generation: global variables and 5370 // The following all require code generation: global variables,
5339 // functions, variables with slot type LOOKUP, declarations with 5371 // functions, and variables with slot type LOOKUP
5340 // mode CONST, and functions.
5341 Variable* var = decl->proxy()->var(); 5372 Variable* var = decl->proxy()->var();
5342 Slot* slot = var->AsSlot(); 5373 Slot* slot = var->AsSlot();
5343 if (var->is_global() || 5374 if (var->is_global() ||
5375 !var->IsStackAllocated() ||
5344 (slot != NULL && slot->type() == Slot::LOOKUP) || 5376 (slot != NULL && slot->type() == Slot::LOOKUP) ||
5345 decl->mode() == Variable::CONST ||
5346 decl->fun() != NULL) { 5377 decl->fun() != NULL) {
5347 return Bailout("unsupported declaration"); 5378 return Bailout("unsupported declaration");
5348 } 5379 }
5380
5381 if (decl->mode() == Variable::CONST) {
5382 environment()->Bind(var, graph()->GetConstantHole());
5383 }
5349 } 5384 }
5350 5385
5351 5386
5352 // Generators for inline runtime functions. 5387 // Generators for inline runtime functions.
5353 // Support for types. 5388 // Support for types.
5354 void HGraphBuilder::GenerateIsSmi(CallRuntime* call) { 5389 void HGraphBuilder::GenerateIsSmi(CallRuntime* call) {
5355 ASSERT(call->arguments()->length() == 1); 5390 ASSERT(call->arguments()->length() == 1);
5356 CHECK_ALIVE(VisitForValue(call->arguments()->at(0))); 5391 CHECK_ALIVE(VisitForValue(call->arguments()->at(0)));
5357 HValue* value = Pop(); 5392 HValue* value = Pop();
5358 HIsSmi* result = new(zone()) HIsSmi(value); 5393 HIsSmi* result = new(zone()) HIsSmi(value);
(...skipping 911 matching lines...) Expand 10 before | Expand all | Expand 10 after
6270 } 6305 }
6271 } 6306 }
6272 6307
6273 #ifdef DEBUG 6308 #ifdef DEBUG
6274 if (graph_ != NULL) graph_->Verify(); 6309 if (graph_ != NULL) graph_->Verify();
6275 if (allocator_ != NULL) allocator_->Verify(); 6310 if (allocator_ != NULL) allocator_->Verify();
6276 #endif 6311 #endif
6277 } 6312 }
6278 6313
6279 } } // namespace v8::internal 6314 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698