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

Side by Side Diff: src/hydrogen.cc

Issue 8857001: [hydrogen] don't bailout assignments to consts (Closed) Base URL: gh:v8/v8@master
Patch Set: fix issues Created 9 years 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
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 3267 matching lines...) Expand 10 before | Expand all | Expand 10 after
3278 if (value == graph()->GetConstantHole()) { 3278 if (value == graph()->GetConstantHole()) {
3279 ASSERT(variable->mode() == CONST || 3279 ASSERT(variable->mode() == CONST ||
3280 variable->mode() == CONST_HARMONY || 3280 variable->mode() == CONST_HARMONY ||
3281 variable->mode() == LET); 3281 variable->mode() == LET);
3282 return Bailout("reference to uninitialized variable"); 3282 return Bailout("reference to uninitialized variable");
3283 } 3283 }
3284 return ast_context()->ReturnValue(value); 3284 return ast_context()->ReturnValue(value);
3285 } 3285 }
3286 3286
3287 case Variable::CONTEXT: { 3287 case Variable::CONTEXT: {
3288 if (variable->mode() == CONST) {
3289 return Bailout("reference to const context slot");
3290 }
3291 HValue* context = BuildContextChainWalk(variable); 3288 HValue* context = BuildContextChainWalk(variable);
3292 HLoadContextSlot* instr = new(zone()) HLoadContextSlot(context, variable); 3289 HLoadContextSlot* instr = new(zone()) HLoadContextSlot(context, variable);
3293 return ast_context()->ReturnInstruction(instr, expr->id()); 3290 return ast_context()->ReturnInstruction(instr, expr->id());
3294 } 3291 }
3295 3292
3296 case Variable::LOOKUP: 3293 case Variable::LOOKUP:
3297 return Bailout("reference to a variable which requires dynamic lookup"); 3294 return Bailout("reference to a variable which requires dynamic lookup");
3298 } 3295 }
3299 } 3296 }
3300 3297
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
3798 VariableProxy* proxy = target->AsVariableProxy(); 3795 VariableProxy* proxy = target->AsVariableProxy();
3799 Property* prop = target->AsProperty(); 3796 Property* prop = target->AsProperty();
3800 ASSERT(proxy == NULL || prop == NULL); 3797 ASSERT(proxy == NULL || prop == NULL);
3801 3798
3802 // We have a second position recorded in the FullCodeGenerator to have 3799 // We have a second position recorded in the FullCodeGenerator to have
3803 // type feedback for the binary operation. 3800 // type feedback for the binary operation.
3804 BinaryOperation* operation = expr->binary_operation(); 3801 BinaryOperation* operation = expr->binary_operation();
3805 3802
3806 if (proxy != NULL) { 3803 if (proxy != NULL) {
3807 Variable* var = proxy->var(); 3804 Variable* var = proxy->var();
3808 if (var->mode() == CONST || var->mode() == LET) { 3805 if (var->mode() == LET) {
3809 return Bailout("unsupported let or const compound assignment"); 3806 return Bailout("unsupported let compound assignment");
3810 } 3807 }
3811 3808
3812 CHECK_ALIVE(VisitForValue(operation)); 3809 CHECK_ALIVE(VisitForValue(operation));
3813 3810
3814 switch (var->location()) { 3811 switch (var->location()) {
3815 case Variable::UNALLOCATED: 3812 case Variable::UNALLOCATED:
3816 HandleGlobalVariableAssignment(var, 3813 HandleGlobalVariableAssignment(var,
3817 Top(), 3814 Top(),
3818 expr->position(), 3815 expr->position(),
3819 expr->AssignmentId()); 3816 expr->AssignmentId());
3820 break; 3817 break;
3821 3818
3822 case Variable::PARAMETER: 3819 case Variable::PARAMETER:
3823 case Variable::LOCAL: 3820 case Variable::LOCAL:
3821 if (var->mode() == CONST) {
3822 return Bailout("unsupported const compound assignment");
3823 }
3824 Bind(var, Top()); 3824 Bind(var, Top());
3825 break; 3825 break;
3826 3826
3827 case Variable::CONTEXT: { 3827 case Variable::CONTEXT: {
3828 // Bail out if we try to mutate a parameter value in a function 3828 // Bail out if we try to mutate a parameter value in a function
3829 // using the arguments object. We do not (yet) correctly handle the 3829 // using the arguments object. We do not (yet) correctly handle the
3830 // arguments property of the function. 3830 // arguments property of the function.
3831 if (info()->scope()->arguments() != NULL) { 3831 if (info()->scope()->arguments() != NULL) {
3832 // Parameters will be allocated to context slots. We have no 3832 // Parameters will be allocated to context slots. We have no
3833 // direct way to detect that the variable is a parameter so we do 3833 // direct way to detect that the variable is a parameter so we do
3834 // a linear search of the parameter variables. 3834 // a linear search of the parameter variables.
3835 int count = info()->scope()->num_parameters(); 3835 int count = info()->scope()->num_parameters();
3836 for (int i = 0; i < count; ++i) { 3836 for (int i = 0; i < count; ++i) {
3837 if (var == info()->scope()->parameter(i)) { 3837 if (var == info()->scope()->parameter(i)) {
3838 Bailout( 3838 Bailout(
3839 "assignment to parameter, function uses arguments object"); 3839 "assignment to parameter, function uses arguments object");
3840 } 3840 }
3841 } 3841 }
3842 } 3842 }
3843 3843
3844 HStoreContextSlot::Mode mode;
3845
3846 switch (var->mode()) {
3847 case LET:
3848 mode = HStoreContextSlot::kCheckDeoptimize;
3849 break;
3850 case CONST:
3851 return ast_context()->ReturnValue(Pop());
3852 case CONST_HARMONY:
3853 UNREACHABLE();
fschneider 2011/12/13 16:15:00 Maybe a short comment that this is checked statica
3854 default:
3855 mode = HStoreContextSlot::kNoCheck;
3856 }
3857
3844 HValue* context = BuildContextChainWalk(var); 3858 HValue* context = BuildContextChainWalk(var);
3845 HStoreContextSlot::Mode mode =
3846 (var->mode() == LET || var->mode() == CONST_HARMONY)
3847 ? HStoreContextSlot::kAssignCheck : HStoreContextSlot::kAssign;
3848 HStoreContextSlot* instr = 3859 HStoreContextSlot* instr =
3849 new(zone()) HStoreContextSlot(context, var->index(), mode, Top()); 3860 new(zone()) HStoreContextSlot(context, var->index(), mode, Top());
3850 AddInstruction(instr); 3861 AddInstruction(instr);
3851 if (instr->HasObservableSideEffects()) { 3862 if (instr->HasObservableSideEffects()) {
3852 AddSimulate(expr->AssignmentId()); 3863 AddSimulate(expr->AssignmentId());
3853 } 3864 }
3854 break; 3865 break;
3855 } 3866 }
3856 3867
3857 case Variable::LOOKUP: 3868 case Variable::LOOKUP:
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
3948 3959
3949 if (expr->is_compound()) { 3960 if (expr->is_compound()) {
3950 HandleCompoundAssignment(expr); 3961 HandleCompoundAssignment(expr);
3951 return; 3962 return;
3952 } 3963 }
3953 3964
3954 if (prop != NULL) { 3965 if (prop != NULL) {
3955 HandlePropertyAssignment(expr); 3966 HandlePropertyAssignment(expr);
3956 } else if (proxy != NULL) { 3967 } else if (proxy != NULL) {
3957 Variable* var = proxy->var(); 3968 Variable* var = proxy->var();
3969
3958 if (var->mode() == CONST) { 3970 if (var->mode() == CONST) {
3959 if (expr->op() != Token::INIT_CONST) { 3971 if (expr->op() != Token::INIT_CONST) {
3960 return Bailout("non-initializer assignment to const"); 3972 CHECK_ALIVE(VisitForValue(expr->value()));
3973 return ast_context()->ReturnValue(Pop());
3961 } 3974 }
3962 if (!var->IsStackAllocated()) { 3975
3963 return Bailout("assignment to const context slot"); 3976 if (var->IsStackAllocated()) {
3977 // We insert a use of the old value to detect unsupported uses of const
3978 // variables (e.g. initialization inside a loop).
3979 HValue* old_value = environment()->Lookup(var);
3980 AddInstruction(new HUseConst(old_value));
3964 } 3981 }
3965 // We insert a use of the old value to detect unsupported uses of const
3966 // variables (e.g. initialization inside a loop).
3967 HValue* old_value = environment()->Lookup(var);
3968 AddInstruction(new HUseConst(old_value));
3969 } else if (var->mode() == CONST_HARMONY) { 3982 } else if (var->mode() == CONST_HARMONY) {
3970 if (expr->op() != Token::INIT_CONST_HARMONY) { 3983 if (expr->op() != Token::INIT_CONST_HARMONY) {
3971 return Bailout("non-initializer assignment to const"); 3984 return Bailout("non-initializer assignment to const");
3972 } 3985 }
3973 } 3986 }
3974 3987
3975 if (proxy->IsArguments()) return Bailout("assignment to arguments"); 3988 if (proxy->IsArguments()) return Bailout("assignment to arguments");
3976 3989
3977 // Handle the assignment. 3990 // Handle the assignment.
3978 switch (var->location()) { 3991 switch (var->location()) {
(...skipping 18 matching lines...) Expand all
3997 // We do not allow the arguments object to occur in a context where it 4010 // We do not allow the arguments object to occur in a context where it
3998 // may escape, but assignments to stack-allocated locals are 4011 // may escape, but assignments to stack-allocated locals are
3999 // permitted. 4012 // permitted.
4000 CHECK_ALIVE(VisitForValue(expr->value(), ARGUMENTS_ALLOWED)); 4013 CHECK_ALIVE(VisitForValue(expr->value(), ARGUMENTS_ALLOWED));
4001 HValue* value = Pop(); 4014 HValue* value = Pop();
4002 Bind(var, value); 4015 Bind(var, value);
4003 return ast_context()->ReturnValue(value); 4016 return ast_context()->ReturnValue(value);
4004 } 4017 }
4005 4018
4006 case Variable::CONTEXT: { 4019 case Variable::CONTEXT: {
4007 ASSERT(var->mode() != CONST);
4008 // Bail out if we try to mutate a parameter value in a function using 4020 // Bail out if we try to mutate a parameter value in a function using
4009 // the arguments object. We do not (yet) correctly handle the 4021 // the arguments object. We do not (yet) correctly handle the
4010 // arguments property of the function. 4022 // arguments property of the function.
4011 if (info()->scope()->arguments() != NULL) { 4023 if (info()->scope()->arguments() != NULL) {
4012 // Parameters will rewrite to context slots. We have no direct way 4024 // Parameters will rewrite to context slots. We have no direct way
4013 // to detect that the variable is a parameter. 4025 // to detect that the variable is a parameter.
4014 int count = info()->scope()->num_parameters(); 4026 int count = info()->scope()->num_parameters();
4015 for (int i = 0; i < count; ++i) { 4027 for (int i = 0; i < count; ++i) {
4016 if (var == info()->scope()->parameter(i)) { 4028 if (var == info()->scope()->parameter(i)) {
4017 return Bailout("assignment to parameter in arguments object"); 4029 return Bailout("assignment to parameter in arguments object");
4018 } 4030 }
4019 } 4031 }
4020 } 4032 }
4021 4033
4022 CHECK_ALIVE(VisitForValue(expr->value())); 4034 CHECK_ALIVE(VisitForValue(expr->value()));
4023 HValue* context = BuildContextChainWalk(var);
4024 HStoreContextSlot::Mode mode; 4035 HStoreContextSlot::Mode mode;
4025 if (expr->op() == Token::ASSIGN) { 4036 if (expr->op() == Token::ASSIGN) {
4026 mode = (var->mode() == LET || var->mode() == CONST_HARMONY) 4037 switch (var->mode()) {
4027 ? HStoreContextSlot::kAssignCheck : HStoreContextSlot::kAssign; 4038 case LET:
4039 mode = HStoreContextSlot::kCheckDeoptimize;
4040 break;
4041 case CONST:
4042 return ast_context()->ReturnValue(Pop());
4043 case CONST_HARMONY:
4044 UNREACHABLE();
fschneider 2011/12/13 16:15:00 Also a short comment for the case here that this i
4045 default:
4046 mode = HStoreContextSlot::kNoCheck;
4047 }
4048 } else if (expr->op() == Token::INIT_VAR ||
4049 expr->op() == Token::INIT_LET ||
4050 expr->op() == Token::INIT_CONST_HARMONY) {
4051 mode = HStoreContextSlot::kNoCheck;
4028 } else { 4052 } else {
4029 ASSERT(expr->op() == Token::INIT_VAR || 4053 ASSERT(expr->op() == Token::INIT_CONST);
4030 expr->op() == Token::INIT_LET || 4054
4031 expr->op() == Token::INIT_CONST_HARMONY); 4055 mode = HStoreContextSlot::kCheckIgnoreAssignment;
4032 mode = HStoreContextSlot::kAssign;
4033 } 4056 }
4057
4058 HValue* context = BuildContextChainWalk(var);
4034 HStoreContextSlot* instr = new(zone()) HStoreContextSlot( 4059 HStoreContextSlot* instr = new(zone()) HStoreContextSlot(
4035 context, var->index(), mode, Top()); 4060 context, var->index(), mode, Top());
4036 AddInstruction(instr); 4061 AddInstruction(instr);
4037 if (instr->HasObservableSideEffects()) { 4062 if (instr->HasObservableSideEffects()) {
4038 AddSimulate(expr->AssignmentId()); 4063 AddSimulate(expr->AssignmentId());
4039 } 4064 }
4040 return ast_context()->ReturnValue(Pop()); 4065 return ast_context()->ReturnValue(Pop());
4041 } 4066 }
4042 4067
4043 case Variable::LOOKUP: 4068 case Variable::LOOKUP:
(...skipping 1592 matching lines...) Expand 10 before | Expand all | Expand 10 after
5636 for (int i = 0; i < count; ++i) { 5661 for (int i = 0; i < count; ++i) {
5637 if (var == info()->scope()->parameter(i)) { 5662 if (var == info()->scope()->parameter(i)) {
5638 return Bailout("assignment to parameter in arguments object"); 5663 return Bailout("assignment to parameter in arguments object");
5639 } 5664 }
5640 } 5665 }
5641 } 5666 }
5642 5667
5643 HValue* context = BuildContextChainWalk(var); 5668 HValue* context = BuildContextChainWalk(var);
5644 HStoreContextSlot::Mode mode = 5669 HStoreContextSlot::Mode mode =
5645 (var->mode() == LET || var->mode() == CONST_HARMONY) 5670 (var->mode() == LET || var->mode() == CONST_HARMONY)
5646 ? HStoreContextSlot::kAssignCheck : HStoreContextSlot::kAssign; 5671 ? HStoreContextSlot::kCheckDeoptimize : HStoreContextSlot::kNoCheck;
5647 HStoreContextSlot* instr = 5672 HStoreContextSlot* instr =
5648 new(zone()) HStoreContextSlot(context, var->index(), mode, after); 5673 new(zone()) HStoreContextSlot(context, var->index(), mode, after);
5649 AddInstruction(instr); 5674 AddInstruction(instr);
5650 if (instr->HasObservableSideEffects()) { 5675 if (instr->HasObservableSideEffects()) {
5651 AddSimulate(expr->AssignmentId()); 5676 AddSimulate(expr->AssignmentId());
5652 } 5677 }
5653 break; 5678 break;
5654 } 5679 }
5655 5680
5656 case Variable::LOOKUP: 5681 case Variable::LOOKUP:
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after
6244 HValue* value = NULL; 6269 HValue* value = NULL;
6245 if (function != NULL) { 6270 if (function != NULL) {
6246 VisitForValue(function); 6271 VisitForValue(function);
6247 value = Pop(); 6272 value = Pop();
6248 } else { 6273 } else {
6249 value = graph()->GetConstantHole(); 6274 value = graph()->GetConstantHole();
6250 } 6275 }
6251 if (var->IsContextSlot()) { 6276 if (var->IsContextSlot()) {
6252 HValue* context = environment()->LookupContext(); 6277 HValue* context = environment()->LookupContext();
6253 HStoreContextSlot* store = new HStoreContextSlot( 6278 HStoreContextSlot* store = new HStoreContextSlot(
6254 context, var->index(), HStoreContextSlot::kAssign, value); 6279 context, var->index(), HStoreContextSlot::kNoCheck, value);
6255 AddInstruction(store); 6280 AddInstruction(store);
6256 if (store->HasObservableSideEffects()) AddSimulate(proxy->id()); 6281 if (store->HasObservableSideEffects()) AddSimulate(proxy->id());
6257 } else { 6282 } else {
6258 environment()->Bind(var, value); 6283 environment()->Bind(var, value);
6259 } 6284 }
6260 } 6285 }
6261 break; 6286 break;
6262 case Variable::LOOKUP: 6287 case Variable::LOOKUP:
6263 return Bailout("unsupported lookup slot in declaration"); 6288 return Bailout("unsupported lookup slot in declaration");
6264 } 6289 }
(...skipping 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after
7266 } 7291 }
7267 } 7292 }
7268 7293
7269 #ifdef DEBUG 7294 #ifdef DEBUG
7270 if (graph_ != NULL) graph_->Verify(false); // No full verify. 7295 if (graph_ != NULL) graph_->Verify(false); // No full verify.
7271 if (allocator_ != NULL) allocator_->Verify(); 7296 if (allocator_ != NULL) allocator_->Verify();
7272 #endif 7297 #endif
7273 } 7298 }
7274 7299
7275 } } // namespace v8::internal 7300 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698