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

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: style fixes 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
« no previous file with comments | « src/arm/lithium-codegen-arm.cc ('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 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 // This case is checked statically so no need to
3854 // perform checks here
3855 UNREACHABLE();
3856 default:
3857 mode = HStoreContextSlot::kNoCheck;
3858 }
3859
3844 HValue* context = BuildContextChainWalk(var); 3860 HValue* context = BuildContextChainWalk(var);
3845 HStoreContextSlot::Mode mode =
3846 (var->mode() == LET || var->mode() == CONST_HARMONY)
3847 ? HStoreContextSlot::kAssignCheck : HStoreContextSlot::kAssign;
3848 HStoreContextSlot* instr = 3861 HStoreContextSlot* instr =
3849 new(zone()) HStoreContextSlot(context, var->index(), mode, Top()); 3862 new(zone()) HStoreContextSlot(context, var->index(), mode, Top());
3850 AddInstruction(instr); 3863 AddInstruction(instr);
3851 if (instr->HasObservableSideEffects()) { 3864 if (instr->HasObservableSideEffects()) {
3852 AddSimulate(expr->AssignmentId()); 3865 AddSimulate(expr->AssignmentId());
3853 } 3866 }
3854 break; 3867 break;
3855 } 3868 }
3856 3869
3857 case Variable::LOOKUP: 3870 case Variable::LOOKUP:
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
3948 3961
3949 if (expr->is_compound()) { 3962 if (expr->is_compound()) {
3950 HandleCompoundAssignment(expr); 3963 HandleCompoundAssignment(expr);
3951 return; 3964 return;
3952 } 3965 }
3953 3966
3954 if (prop != NULL) { 3967 if (prop != NULL) {
3955 HandlePropertyAssignment(expr); 3968 HandlePropertyAssignment(expr);
3956 } else if (proxy != NULL) { 3969 } else if (proxy != NULL) {
3957 Variable* var = proxy->var(); 3970 Variable* var = proxy->var();
3971
3958 if (var->mode() == CONST) { 3972 if (var->mode() == CONST) {
3959 if (expr->op() != Token::INIT_CONST) { 3973 if (expr->op() != Token::INIT_CONST) {
3960 return Bailout("non-initializer assignment to const"); 3974 CHECK_ALIVE(VisitForValue(expr->value()));
3975 return ast_context()->ReturnValue(Pop());
3961 } 3976 }
3962 if (!var->IsStackAllocated()) { 3977
3963 return Bailout("assignment to const context slot"); 3978 if (var->IsStackAllocated()) {
3979 // We insert a use of the old value to detect unsupported uses of const
3980 // variables (e.g. initialization inside a loop).
3981 HValue* old_value = environment()->Lookup(var);
3982 AddInstruction(new HUseConst(old_value));
3964 } 3983 }
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) { 3984 } else if (var->mode() == CONST_HARMONY) {
3970 if (expr->op() != Token::INIT_CONST_HARMONY) { 3985 if (expr->op() != Token::INIT_CONST_HARMONY) {
3971 return Bailout("non-initializer assignment to const"); 3986 return Bailout("non-initializer assignment to const");
3972 } 3987 }
3973 } 3988 }
3974 3989
3975 if (proxy->IsArguments()) return Bailout("assignment to arguments"); 3990 if (proxy->IsArguments()) return Bailout("assignment to arguments");
3976 3991
3977 // Handle the assignment. 3992 // Handle the assignment.
3978 switch (var->location()) { 3993 switch (var->location()) {
(...skipping 18 matching lines...) Expand all
3997 // We do not allow the arguments object to occur in a context where it 4012 // We do not allow the arguments object to occur in a context where it
3998 // may escape, but assignments to stack-allocated locals are 4013 // may escape, but assignments to stack-allocated locals are
3999 // permitted. 4014 // permitted.
4000 CHECK_ALIVE(VisitForValue(expr->value(), ARGUMENTS_ALLOWED)); 4015 CHECK_ALIVE(VisitForValue(expr->value(), ARGUMENTS_ALLOWED));
4001 HValue* value = Pop(); 4016 HValue* value = Pop();
4002 Bind(var, value); 4017 Bind(var, value);
4003 return ast_context()->ReturnValue(value); 4018 return ast_context()->ReturnValue(value);
4004 } 4019 }
4005 4020
4006 case Variable::CONTEXT: { 4021 case Variable::CONTEXT: {
4007 ASSERT(var->mode() != CONST);
4008 // Bail out if we try to mutate a parameter value in a function using 4022 // 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 4023 // the arguments object. We do not (yet) correctly handle the
4010 // arguments property of the function. 4024 // arguments property of the function.
4011 if (info()->scope()->arguments() != NULL) { 4025 if (info()->scope()->arguments() != NULL) {
4012 // Parameters will rewrite to context slots. We have no direct way 4026 // Parameters will rewrite to context slots. We have no direct way
4013 // to detect that the variable is a parameter. 4027 // to detect that the variable is a parameter.
4014 int count = info()->scope()->num_parameters(); 4028 int count = info()->scope()->num_parameters();
4015 for (int i = 0; i < count; ++i) { 4029 for (int i = 0; i < count; ++i) {
4016 if (var == info()->scope()->parameter(i)) { 4030 if (var == info()->scope()->parameter(i)) {
4017 return Bailout("assignment to parameter in arguments object"); 4031 return Bailout("assignment to parameter in arguments object");
4018 } 4032 }
4019 } 4033 }
4020 } 4034 }
4021 4035
4022 CHECK_ALIVE(VisitForValue(expr->value())); 4036 CHECK_ALIVE(VisitForValue(expr->value()));
4023 HValue* context = BuildContextChainWalk(var);
4024 HStoreContextSlot::Mode mode; 4037 HStoreContextSlot::Mode mode;
4025 if (expr->op() == Token::ASSIGN) { 4038 if (expr->op() == Token::ASSIGN) {
4026 mode = (var->mode() == LET || var->mode() == CONST_HARMONY) 4039 switch (var->mode()) {
4027 ? HStoreContextSlot::kAssignCheck : HStoreContextSlot::kAssign; 4040 case LET:
4041 mode = HStoreContextSlot::kCheckDeoptimize;
4042 break;
4043 case CONST:
4044 return ast_context()->ReturnValue(Pop());
4045 case CONST_HARMONY:
4046 // This case is checked statically so no need to
4047 // perform checks here
4048 UNREACHABLE();
4049 default:
4050 mode = HStoreContextSlot::kNoCheck;
4051 }
4052 } else if (expr->op() == Token::INIT_VAR ||
4053 expr->op() == Token::INIT_LET ||
4054 expr->op() == Token::INIT_CONST_HARMONY) {
4055 mode = HStoreContextSlot::kNoCheck;
4028 } else { 4056 } else {
4029 ASSERT(expr->op() == Token::INIT_VAR || 4057 ASSERT(expr->op() == Token::INIT_CONST);
4030 expr->op() == Token::INIT_LET || 4058
4031 expr->op() == Token::INIT_CONST_HARMONY); 4059 mode = HStoreContextSlot::kCheckIgnoreAssignment;
4032 mode = HStoreContextSlot::kAssign;
4033 } 4060 }
4061
4062 HValue* context = BuildContextChainWalk(var);
4034 HStoreContextSlot* instr = new(zone()) HStoreContextSlot( 4063 HStoreContextSlot* instr = new(zone()) HStoreContextSlot(
4035 context, var->index(), mode, Top()); 4064 context, var->index(), mode, Top());
4036 AddInstruction(instr); 4065 AddInstruction(instr);
4037 if (instr->HasObservableSideEffects()) { 4066 if (instr->HasObservableSideEffects()) {
4038 AddSimulate(expr->AssignmentId()); 4067 AddSimulate(expr->AssignmentId());
4039 } 4068 }
4040 return ast_context()->ReturnValue(Pop()); 4069 return ast_context()->ReturnValue(Pop());
4041 } 4070 }
4042 4071
4043 case Variable::LOOKUP: 4072 case Variable::LOOKUP:
(...skipping 1592 matching lines...) Expand 10 before | Expand all | Expand 10 after
5636 for (int i = 0; i < count; ++i) { 5665 for (int i = 0; i < count; ++i) {
5637 if (var == info()->scope()->parameter(i)) { 5666 if (var == info()->scope()->parameter(i)) {
5638 return Bailout("assignment to parameter in arguments object"); 5667 return Bailout("assignment to parameter in arguments object");
5639 } 5668 }
5640 } 5669 }
5641 } 5670 }
5642 5671
5643 HValue* context = BuildContextChainWalk(var); 5672 HValue* context = BuildContextChainWalk(var);
5644 HStoreContextSlot::Mode mode = 5673 HStoreContextSlot::Mode mode =
5645 (var->mode() == LET || var->mode() == CONST_HARMONY) 5674 (var->mode() == LET || var->mode() == CONST_HARMONY)
5646 ? HStoreContextSlot::kAssignCheck : HStoreContextSlot::kAssign; 5675 ? HStoreContextSlot::kCheckDeoptimize : HStoreContextSlot::kNoCheck;
5647 HStoreContextSlot* instr = 5676 HStoreContextSlot* instr =
5648 new(zone()) HStoreContextSlot(context, var->index(), mode, after); 5677 new(zone()) HStoreContextSlot(context, var->index(), mode, after);
5649 AddInstruction(instr); 5678 AddInstruction(instr);
5650 if (instr->HasObservableSideEffects()) { 5679 if (instr->HasObservableSideEffects()) {
5651 AddSimulate(expr->AssignmentId()); 5680 AddSimulate(expr->AssignmentId());
5652 } 5681 }
5653 break; 5682 break;
5654 } 5683 }
5655 5684
5656 case Variable::LOOKUP: 5685 case Variable::LOOKUP:
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after
6244 HValue* value = NULL; 6273 HValue* value = NULL;
6245 if (function != NULL) { 6274 if (function != NULL) {
6246 VisitForValue(function); 6275 VisitForValue(function);
6247 value = Pop(); 6276 value = Pop();
6248 } else { 6277 } else {
6249 value = graph()->GetConstantHole(); 6278 value = graph()->GetConstantHole();
6250 } 6279 }
6251 if (var->IsContextSlot()) { 6280 if (var->IsContextSlot()) {
6252 HValue* context = environment()->LookupContext(); 6281 HValue* context = environment()->LookupContext();
6253 HStoreContextSlot* store = new HStoreContextSlot( 6282 HStoreContextSlot* store = new HStoreContextSlot(
6254 context, var->index(), HStoreContextSlot::kAssign, value); 6283 context, var->index(), HStoreContextSlot::kNoCheck, value);
6255 AddInstruction(store); 6284 AddInstruction(store);
6256 if (store->HasObservableSideEffects()) AddSimulate(proxy->id()); 6285 if (store->HasObservableSideEffects()) AddSimulate(proxy->id());
6257 } else { 6286 } else {
6258 environment()->Bind(var, value); 6287 environment()->Bind(var, value);
6259 } 6288 }
6260 } 6289 }
6261 break; 6290 break;
6262 case Variable::LOOKUP: 6291 case Variable::LOOKUP:
6263 return Bailout("unsupported lookup slot in declaration"); 6292 return Bailout("unsupported lookup slot in declaration");
6264 } 6293 }
(...skipping 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after
7266 } 7295 }
7267 } 7296 }
7268 7297
7269 #ifdef DEBUG 7298 #ifdef DEBUG
7270 if (graph_ != NULL) graph_->Verify(false); // No full verify. 7299 if (graph_ != NULL) graph_->Verify(false); // No full verify.
7271 if (allocator_ != NULL) allocator_->Verify(); 7300 if (allocator_ != NULL) allocator_->Verify();
7272 #endif 7301 #endif
7273 } 7302 }
7274 7303
7275 } } // namespace v8::internal 7304 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/arm/lithium-codegen-arm.cc ('k') | src/hydrogen-instructions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698