| OLD | NEW |
| 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 4097 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4108 HValue* IndexBase() const { return index_base_; } | 4108 HValue* IndexBase() const { return index_base_; } |
| 4109 HValue* Length() const { return length_; } | 4109 HValue* Length() const { return length_; } |
| 4110 | 4110 |
| 4111 uint32_t Hash() { | 4111 uint32_t Hash() { |
| 4112 return static_cast<uint32_t>(index_base_->Hashcode() ^ length_->Hashcode()); | 4112 return static_cast<uint32_t>(index_base_->Hashcode() ^ length_->Hashcode()); |
| 4113 } | 4113 } |
| 4114 | 4114 |
| 4115 static BoundsCheckKey* Create(Zone* zone, | 4115 static BoundsCheckKey* Create(Zone* zone, |
| 4116 HBoundsCheck* check, | 4116 HBoundsCheck* check, |
| 4117 int32_t* offset) { | 4117 int32_t* offset) { |
| 4118 if (!check->index()->representation().IsInteger32()) return NULL; | 4118 if (!check->index()->representation().IsSmiOrInteger32()) return NULL; |
| 4119 | 4119 |
| 4120 HValue* index_base = NULL; | 4120 HValue* index_base = NULL; |
| 4121 HConstant* constant = NULL; | 4121 HConstant* constant = NULL; |
| 4122 bool is_sub = false; | 4122 bool is_sub = false; |
| 4123 | 4123 |
| 4124 if (check->index()->IsAdd()) { | 4124 if (check->index()->IsAdd()) { |
| 4125 HAdd* index = HAdd::cast(check->index()); | 4125 HAdd* index = HAdd::cast(check->index()); |
| 4126 if (index->left()->IsConstant()) { | 4126 if (index->left()->IsConstant()) { |
| 4127 constant = HConstant::cast(index->left()); | 4127 constant = HConstant::cast(index->left()); |
| 4128 index_base = index->right(); | 4128 index_base = index->right(); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4204 // | 4204 // |
| 4205 // If HasSingleCheck() is true then new_check is added as "second check" | 4205 // If HasSingleCheck() is true then new_check is added as "second check" |
| 4206 // (either upper or lower; note that HasSingleCheck() becomes false). | 4206 // (either upper or lower; note that HasSingleCheck() becomes false). |
| 4207 // Otherwise one of the current checks is modified so that it also covers | 4207 // Otherwise one of the current checks is modified so that it also covers |
| 4208 // new_offset, and new_check is removed. | 4208 // new_offset, and new_check is removed. |
| 4209 // | 4209 // |
| 4210 // If the check cannot be modified because the context is unknown it | 4210 // If the check cannot be modified because the context is unknown it |
| 4211 // returns false, otherwise it returns true. | 4211 // returns false, otherwise it returns true. |
| 4212 bool CoverCheck(HBoundsCheck* new_check, | 4212 bool CoverCheck(HBoundsCheck* new_check, |
| 4213 int32_t new_offset) { | 4213 int32_t new_offset) { |
| 4214 ASSERT(new_check->index()->representation().IsInteger32()); | 4214 ASSERT(new_check->index()->representation().IsSmiOrInteger32()); |
| 4215 bool keep_new_check = false; | 4215 bool keep_new_check = false; |
| 4216 | 4216 |
| 4217 if (new_offset > upper_offset_) { | 4217 if (new_offset > upper_offset_) { |
| 4218 upper_offset_ = new_offset; | 4218 upper_offset_ = new_offset; |
| 4219 if (HasSingleCheck()) { | 4219 if (HasSingleCheck()) { |
| 4220 keep_new_check = true; | 4220 keep_new_check = true; |
| 4221 upper_check_ = new_check; | 4221 upper_check_ = new_check; |
| 4222 } else { | 4222 } else { |
| 4223 bool result = BuildOffsetAdd(upper_check_, | 4223 bool result = BuildOffsetAdd(upper_check_, |
| 4224 &added_upper_index_, | 4224 &added_upper_index_, |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4313 // current context cannot be determined. | 4313 // current context cannot be determined. |
| 4314 bool BuildOffsetAdd(HBoundsCheck* check, | 4314 bool BuildOffsetAdd(HBoundsCheck* check, |
| 4315 HInstruction** add, | 4315 HInstruction** add, |
| 4316 HConstant** constant, | 4316 HConstant** constant, |
| 4317 HValue* original_value, | 4317 HValue* original_value, |
| 4318 Representation representation, | 4318 Representation representation, |
| 4319 int32_t new_offset) { | 4319 int32_t new_offset) { |
| 4320 HValue* index_context = IndexContext(*add, check); | 4320 HValue* index_context = IndexContext(*add, check); |
| 4321 if (index_context == NULL) return false; | 4321 if (index_context == NULL) return false; |
| 4322 | 4322 |
| 4323 HConstant* new_constant = new(BasicBlock()->zone()) | 4323 HConstant* new_constant = new(BasicBlock()->zone()) HConstant( |
| 4324 HConstant(new_offset, Representation::Integer32()); | 4324 new_offset, representation); |
| 4325 if (*add == NULL) { | 4325 if (*add == NULL) { |
| 4326 new_constant->InsertBefore(check); | 4326 new_constant->InsertBefore(check); |
| 4327 (*add) = HAdd::New( | 4327 (*add) = HAdd::New( |
| 4328 BasicBlock()->zone(), index_context, original_value, new_constant); | 4328 BasicBlock()->zone(), index_context, original_value, new_constant); |
| 4329 (*add)->AssumeRepresentation(representation); | 4329 (*add)->AssumeRepresentation(representation); |
| 4330 (*add)->InsertBefore(check); | 4330 (*add)->InsertBefore(check); |
| 4331 } else { | 4331 } else { |
| 4332 new_constant->InsertBefore(*add); | 4332 new_constant->InsertBefore(*add); |
| 4333 (*constant)->DeleteAndReplaceWith(new_constant); | 4333 (*constant)->DeleteAndReplaceWith(new_constant); |
| 4334 } | 4334 } |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4446 | 4446 |
| 4447 void HGraph::EliminateRedundantBoundsChecks() { | 4447 void HGraph::EliminateRedundantBoundsChecks() { |
| 4448 HPhase phase("H_Eliminate bounds checks", this); | 4448 HPhase phase("H_Eliminate bounds checks", this); |
| 4449 BoundsCheckTable checks_table(zone()); | 4449 BoundsCheckTable checks_table(zone()); |
| 4450 EliminateRedundantBoundsChecks(entry_block(), &checks_table); | 4450 EliminateRedundantBoundsChecks(entry_block(), &checks_table); |
| 4451 } | 4451 } |
| 4452 | 4452 |
| 4453 | 4453 |
| 4454 static void DehoistArrayIndex(ArrayInstructionInterface* array_operation) { | 4454 static void DehoistArrayIndex(ArrayInstructionInterface* array_operation) { |
| 4455 HValue* index = array_operation->GetKey()->ActualValue(); | 4455 HValue* index = array_operation->GetKey()->ActualValue(); |
| 4456 if (!index->representation().IsInteger32()) return; | 4456 if (!index->representation().IsSmiOrInteger32()) return; |
| 4457 | 4457 |
| 4458 HConstant* constant; | 4458 HConstant* constant; |
| 4459 HValue* subexpression; | 4459 HValue* subexpression; |
| 4460 int32_t sign; | 4460 int32_t sign; |
| 4461 if (index->IsAdd()) { | 4461 if (index->IsAdd()) { |
| 4462 sign = 1; | 4462 sign = 1; |
| 4463 HAdd* add = HAdd::cast(index); | 4463 HAdd* add = HAdd::cast(index); |
| 4464 if (add->left()->IsConstant()) { | 4464 if (add->left()->IsConstant()) { |
| 4465 subexpression = add->right(); | 4465 subexpression = add->right(); |
| 4466 constant = HConstant::cast(add->left()); | 4466 constant = HConstant::cast(add->left()); |
| (...skipping 7142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11609 } | 11609 } |
| 11610 } | 11610 } |
| 11611 | 11611 |
| 11612 #ifdef DEBUG | 11612 #ifdef DEBUG |
| 11613 if (graph_ != NULL) graph_->Verify(false); // No full verify. | 11613 if (graph_ != NULL) graph_->Verify(false); // No full verify. |
| 11614 if (allocator_ != NULL) allocator_->Verify(); | 11614 if (allocator_ != NULL) allocator_->Verify(); |
| 11615 #endif | 11615 #endif |
| 11616 } | 11616 } |
| 11617 | 11617 |
| 11618 } } // namespace v8::internal | 11618 } } // namespace v8::internal |
| OLD | NEW |