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

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
« no previous file with comments | « src/hydrogen.h ('k') | src/hydrogen-instructions.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
2294 AddInstruction(new(zone()) HPushArgument(arguments.RemoveLast())); 2304 AddInstruction(new(zone()) HPushArgument(arguments.RemoveLast()));
2295 } 2305 }
2296 return call; 2306 return call;
2297 } 2307 }
2298 2308
2299 2309
2300 void HGraphBuilder::SetupScope(Scope* scope) { 2310 void HGraphBuilder::SetupScope(Scope* scope) {
2301 // We don't yet handle the function name for named function expressions. 2311 // We don't yet handle the function name for named function expressions.
2302 if (scope->function() != NULL) return Bailout("named function expression"); 2312 if (scope->function() != NULL) return Bailout("named function expression");
2303 2313
2314 //TODO: ??
2315 //if (scope->HasIllegalRedeclaration()) BAILOUT("illegal redeclaration");
Kevin Millikin (Chromium) 2011/05/30 10:50:34 This should not be necessary, I think we check it
fschneider 2011/05/30 11:15:40 Done.
2316
2304 HConstant* undefined_constant = new(zone()) HConstant( 2317 HConstant* undefined_constant = new(zone()) HConstant(
2305 isolate()->factory()->undefined_value(), Representation::Tagged()); 2318 isolate()->factory()->undefined_value(), Representation::Tagged());
2306 AddInstruction(undefined_constant); 2319 AddInstruction(undefined_constant);
2307 graph_->set_undefined_constant(undefined_constant); 2320 graph_->set_undefined_constant(undefined_constant);
2308 2321
2309 // Set the initial values of parameters including "this". "This" has 2322 // Set the initial values of parameters including "this". "This" has
2310 // parameter index 0. 2323 // parameter index 0.
2311 ASSERT_EQ(scope->num_parameters() + 1, environment()->parameter_count()); 2324 ASSERT_EQ(scope->num_parameters() + 1, environment()->parameter_count());
2312 2325
2313 for (int i = 0; i < environment()->parameter_count(); ++i) { 2326 for (int i = 0; i < environment()->parameter_count(); ++i) {
(...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after
2989 3002
2990 3003
2991 void HGraphBuilder::VisitVariableProxy(VariableProxy* expr) { 3004 void HGraphBuilder::VisitVariableProxy(VariableProxy* expr) {
2992 ASSERT(!HasStackOverflow()); 3005 ASSERT(!HasStackOverflow());
2993 ASSERT(current_block() != NULL); 3006 ASSERT(current_block() != NULL);
2994 ASSERT(current_block()->HasPredecessor()); 3007 ASSERT(current_block()->HasPredecessor());
2995 Variable* variable = expr->AsVariable(); 3008 Variable* variable = expr->AsVariable();
2996 if (variable == NULL) { 3009 if (variable == NULL) {
2997 return Bailout("reference to rewritten variable"); 3010 return Bailout("reference to rewritten variable");
2998 } else if (variable->IsStackAllocated()) { 3011 } else if (variable->IsStackAllocated()) {
2999 ast_context()->ReturnValue(environment()->Lookup(variable)); 3012 HValue* value = environment()->Lookup(variable);
3013 if (variable->mode() == Variable::CONST &&
3014 value == graph()->GetConstantHole()) {
3015 return Bailout("unsupported reference to const variable");
Kevin Millikin (Chromium) 2011/05/30 10:50:34 Let's make this say something like "reference to u
fschneider 2011/05/30 11:15:40 Done.
3016 }
3017 ast_context()->ReturnValue(value);
3000 } else if (variable->IsContextSlot()) { 3018 } else if (variable->IsContextSlot()) {
3001 if (variable->mode() == Variable::CONST) { 3019 if (variable->mode() == Variable::CONST) {
3002 return Bailout("reference to const context slot"); 3020 return Bailout("reference to const context slot");
3003 } 3021 }
3004 HValue* context = BuildContextChainWalk(variable); 3022 HValue* context = BuildContextChainWalk(variable);
3005 int index = variable->AsSlot()->index(); 3023 int index = variable->AsSlot()->index();
3006 HLoadContextSlot* instr = new(zone()) HLoadContextSlot(context, index); 3024 HLoadContextSlot* instr = new(zone()) HLoadContextSlot(context, index);
3007 ast_context()->ReturnInstruction(instr, expr->id()); 3025 ast_context()->ReturnInstruction(instr, expr->id());
3008 } else if (variable->is_global()) { 3026 } else if (variable->is_global()) {
3009 LookupResult lookup; 3027 LookupResult lookup;
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
3444 VariableProxy* proxy = target->AsVariableProxy(); 3462 VariableProxy* proxy = target->AsVariableProxy();
3445 Variable* var = proxy->AsVariable(); 3463 Variable* var = proxy->AsVariable();
3446 Property* prop = target->AsProperty(); 3464 Property* prop = target->AsProperty();
3447 ASSERT(var == NULL || prop == NULL); 3465 ASSERT(var == NULL || prop == NULL);
3448 3466
3449 // We have a second position recorded in the FullCodeGenerator to have 3467 // We have a second position recorded in the FullCodeGenerator to have
3450 // type feedback for the binary operation. 3468 // type feedback for the binary operation.
3451 BinaryOperation* operation = expr->binary_operation(); 3469 BinaryOperation* operation = expr->binary_operation();
3452 3470
3453 if (var != NULL) { 3471 if (var != NULL) {
3472 if (var->mode() == Variable::CONST) return Bailout("unsupported const compou nd assignment");
Kevin Millikin (Chromium) 2011/05/30 10:50:34 Needs a line break before committing.
fschneider 2011/05/30 11:15:40 Done.
3473
3454 CHECK_ALIVE(VisitForValue(operation)); 3474 CHECK_ALIVE(VisitForValue(operation));
3455 3475
3456 if (var->is_global()) { 3476 if (var->is_global()) {
3457 HandleGlobalVariableAssignment(var, 3477 HandleGlobalVariableAssignment(var,
3458 Top(), 3478 Top(),
3459 expr->position(), 3479 expr->position(),
3460 expr->AssignmentId()); 3480 expr->AssignmentId());
3461 } else if (var->IsStackAllocated()) { 3481 } else if (var->IsStackAllocated()) {
3462 Bind(var, Top()); 3482 Bind(var, Top());
3463 } else if (var->IsContextSlot()) { 3483 } else if (var->IsContextSlot()) {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
3550 Variable* var = proxy->AsVariable(); 3570 Variable* var = proxy->AsVariable();
3551 Property* prop = expr->target()->AsProperty(); 3571 Property* prop = expr->target()->AsProperty();
3552 ASSERT(var == NULL || prop == NULL); 3572 ASSERT(var == NULL || prop == NULL);
3553 3573
3554 if (expr->is_compound()) { 3574 if (expr->is_compound()) {
3555 HandleCompoundAssignment(expr); 3575 HandleCompoundAssignment(expr);
3556 return; 3576 return;
3557 } 3577 }
3558 3578
3559 if (var != NULL) { 3579 if (var != NULL) {
3580 if (var->mode() == Variable::CONST) {
3581 if (expr->op() != Token::INIT_CONST) {
3582 return Bailout("unsupported const assignment");
Kevin Millikin (Chromium) 2011/05/30 10:50:34 Let's make the message something like "non-initial
fschneider 2011/05/30 11:15:40 Done.
3583 }
3584 // We insert a use of the old value to detect unsupported uses of const
3585 // variables (e.g. initialization inside a loop).
3586 HValue* old_value = environment()->Lookup(var);
3587 AddInstruction(new HUseConst(old_value));
3588 }
3589
3560 if (proxy->IsArguments()) return Bailout("assignment to arguments"); 3590 if (proxy->IsArguments()) return Bailout("assignment to arguments");
3561 3591
3562 // Handle the assignment. 3592 // Handle the assignment.
3563 if (var->IsStackAllocated()) { 3593 if (var->IsStackAllocated()) {
3564 // We do not allow the arguments object to occur in a context where it 3594 // We do not allow the arguments object to occur in a context where it
3565 // may escape, but assignments to stack-allocated locals are 3595 // may escape, but assignments to stack-allocated locals are
3566 // permitted. 3596 // permitted.
3567 CHECK_ALIVE(VisitForValue(expr->value(), ARGUMENTS_ALLOWED)); 3597 CHECK_ALIVE(VisitForValue(expr->value(), ARGUMENTS_ALLOWED));
3568 HValue* value = Pop(); 3598 HValue* value = Pop();
3569 Bind(var, value); 3599 Bind(var, value);
(...skipping 1294 matching lines...) Expand 10 before | Expand all | Expand 10 after
4864 4894
4865 // Match the full code generator stack by simulating an extra stack 4895 // Match the full code generator stack by simulating an extra stack
4866 // element for postfix operations in a non-effect context. The return 4896 // element for postfix operations in a non-effect context. The return
4867 // value is ToNumber(input). 4897 // value is ToNumber(input).
4868 bool returns_original_input = 4898 bool returns_original_input =
4869 expr->is_postfix() && !ast_context()->IsEffect(); 4899 expr->is_postfix() && !ast_context()->IsEffect();
4870 HValue* input = NULL; // ToNumber(original_input). 4900 HValue* input = NULL; // ToNumber(original_input).
4871 HValue* after = NULL; // The result after incrementing or decrementing. 4901 HValue* after = NULL; // The result after incrementing or decrementing.
4872 4902
4873 if (var != NULL) { 4903 if (var != NULL) {
4904 if (var->mode() == Variable::CONST) return Bailout("unsupported count operat ion");
Kevin Millikin (Chromium) 2011/05/30 10:50:34 Line break.
fschneider 2011/05/30 11:15:40 Done.
4874 // Argument of the count operation is a variable, not a property. 4905 // Argument of the count operation is a variable, not a property.
4875 ASSERT(prop == NULL); 4906 ASSERT(prop == NULL);
4876 CHECK_ALIVE(VisitForValue(target)); 4907 CHECK_ALIVE(VisitForValue(target));
4877 4908
4878 after = BuildIncrement(returns_original_input, expr); 4909 after = BuildIncrement(returns_original_input, expr);
4879 input = returns_original_input ? Top() : Pop(); 4910 input = returns_original_input ? Top() : Pop();
4880 Push(after); 4911 Push(after);
4881 4912
4882 if (var->is_global()) { 4913 if (var->is_global()) {
4883 HandleGlobalVariableAssignment(var, 4914 HandleGlobalVariableAssignment(var,
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
5328 void HGraphBuilder::VisitThisFunction(ThisFunction* expr) { 5359 void HGraphBuilder::VisitThisFunction(ThisFunction* expr) {
5329 ASSERT(!HasStackOverflow()); 5360 ASSERT(!HasStackOverflow());
5330 ASSERT(current_block() != NULL); 5361 ASSERT(current_block() != NULL);
5331 ASSERT(current_block()->HasPredecessor()); 5362 ASSERT(current_block()->HasPredecessor());
5332 return Bailout("ThisFunction"); 5363 return Bailout("ThisFunction");
5333 } 5364 }
5334 5365
5335 5366
5336 void HGraphBuilder::VisitDeclaration(Declaration* decl) { 5367 void HGraphBuilder::VisitDeclaration(Declaration* decl) {
5337 // We allow only declarations that do not require code generation. 5368 // We allow only declarations that do not require code generation.
5338 // The following all require code generation: global variables and 5369 // The following all require code generation: global variables,
5339 // functions, variables with slot type LOOKUP, declarations with 5370 // functions, and variables with slot type LOOKUP
5340 // mode CONST, and functions.
5341 Variable* var = decl->proxy()->var(); 5371 Variable* var = decl->proxy()->var();
5342 Slot* slot = var->AsSlot(); 5372 Slot* slot = var->AsSlot();
5343 if (var->is_global() || 5373 if (var->is_global() ||
5374 !var->IsStackAllocated() ||
5344 (slot != NULL && slot->type() == Slot::LOOKUP) || 5375 (slot != NULL && slot->type() == Slot::LOOKUP) ||
5345 decl->mode() == Variable::CONST ||
5346 decl->fun() != NULL) { 5376 decl->fun() != NULL) {
5347 return Bailout("unsupported declaration"); 5377 return Bailout("unsupported declaration");
5348 } 5378 }
5379
5380 if (decl->mode() == Variable::CONST) {
5381 environment()->Bind(var, graph()->GetConstantHole());
5382 }
5349 } 5383 }
5350 5384
5351 5385
5352 // Generators for inline runtime functions. 5386 // Generators for inline runtime functions.
5353 // Support for types. 5387 // Support for types.
5354 void HGraphBuilder::GenerateIsSmi(CallRuntime* call) { 5388 void HGraphBuilder::GenerateIsSmi(CallRuntime* call) {
5355 ASSERT(call->arguments()->length() == 1); 5389 ASSERT(call->arguments()->length() == 1);
5356 CHECK_ALIVE(VisitForValue(call->arguments()->at(0))); 5390 CHECK_ALIVE(VisitForValue(call->arguments()->at(0)));
5357 HValue* value = Pop(); 5391 HValue* value = Pop();
5358 HIsSmi* result = new(zone()) HIsSmi(value); 5392 HIsSmi* result = new(zone()) HIsSmi(value);
(...skipping 911 matching lines...) Expand 10 before | Expand all | Expand 10 after
6270 } 6304 }
6271 } 6305 }
6272 6306
6273 #ifdef DEBUG 6307 #ifdef DEBUG
6274 if (graph_ != NULL) graph_->Verify(); 6308 if (graph_ != NULL) graph_->Verify();
6275 if (allocator_ != NULL) allocator_->Verify(); 6309 if (allocator_ != NULL) allocator_->Verify();
6276 #endif 6310 #endif
6277 } 6311 }
6278 6312
6279 } } // namespace v8::internal 6313 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/hydrogen.h ('k') | src/hydrogen-instructions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698