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

Side by Side Diff: src/hydrogen.cc

Issue 6880010: Merge (7265, 7271] from bleeding_edge to experimental/gc branch.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/gc/
Patch Set: '' Created 9 years, 8 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
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #include "v8.h"
28 #include "hydrogen.h" 29 #include "hydrogen.h"
29 30
30 #include "codegen.h" 31 #include "codegen.h"
31 #include "data-flow.h" 32 #include "data-flow.h"
32 #include "full-codegen.h" 33 #include "full-codegen.h"
33 #include "hashmap.h" 34 #include "hashmap.h"
34 #include "lithium-allocator.h" 35 #include "lithium-allocator.h"
35 #include "parser.h" 36 #include "parser.h"
36 #include "scopes.h" 37 #include "scopes.h"
37 #include "stub-cache.h" 38 #include "stub-cache.h"
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 return GetConstant(&constant_1_, Smi::FromInt(1)); 505 return GetConstant(&constant_1_, Smi::FromInt(1));
505 } 506 }
506 507
507 508
508 HConstant* HGraph::GetConstantMinus1() { 509 HConstant* HGraph::GetConstantMinus1() {
509 return GetConstant(&constant_minus1_, Smi::FromInt(-1)); 510 return GetConstant(&constant_minus1_, Smi::FromInt(-1));
510 } 511 }
511 512
512 513
513 HConstant* HGraph::GetConstantTrue() { 514 HConstant* HGraph::GetConstantTrue() {
514 return GetConstant(&constant_true_, Heap::true_value()); 515 return GetConstant(&constant_true_, HEAP->true_value());
515 } 516 }
516 517
517 518
518 HConstant* HGraph::GetConstantFalse() { 519 HConstant* HGraph::GetConstantFalse() {
519 return GetConstant(&constant_false_, Heap::false_value()); 520 return GetConstant(&constant_false_, HEAP->false_value());
520 } 521 }
521 522
522 523
523 HBasicBlock* HGraphBuilder::CreateJoin(HBasicBlock* first, 524 HBasicBlock* HGraphBuilder::CreateJoin(HBasicBlock* first,
524 HBasicBlock* second, 525 HBasicBlock* second,
525 int join_id) { 526 int join_id) {
526 if (first == NULL) { 527 if (first == NULL) {
527 return second; 528 return second;
528 } else if (second == NULL) { 529 } else if (second == NULL) {
529 return first; 530 return first;
(...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after
1019 va_end(arguments); 1020 va_end(arguments);
1020 } 1021 }
1021 } 1022 }
1022 1023
1023 1024
1024 HValueMap::HValueMap(const HValueMap* other) 1025 HValueMap::HValueMap(const HValueMap* other)
1025 : array_size_(other->array_size_), 1026 : array_size_(other->array_size_),
1026 lists_size_(other->lists_size_), 1027 lists_size_(other->lists_size_),
1027 count_(other->count_), 1028 count_(other->count_),
1028 present_flags_(other->present_flags_), 1029 present_flags_(other->present_flags_),
1029 array_(Zone::NewArray<HValueMapListElement>(other->array_size_)), 1030 array_(ZONE->NewArray<HValueMapListElement>(other->array_size_)),
1030 lists_(Zone::NewArray<HValueMapListElement>(other->lists_size_)), 1031 lists_(ZONE->NewArray<HValueMapListElement>(other->lists_size_)),
1031 free_list_head_(other->free_list_head_) { 1032 free_list_head_(other->free_list_head_) {
1032 memcpy(array_, other->array_, array_size_ * sizeof(HValueMapListElement)); 1033 memcpy(array_, other->array_, array_size_ * sizeof(HValueMapListElement));
1033 memcpy(lists_, other->lists_, lists_size_ * sizeof(HValueMapListElement)); 1034 memcpy(lists_, other->lists_, lists_size_ * sizeof(HValueMapListElement));
1034 } 1035 }
1035 1036
1036 1037
1037 void HValueMap::Kill(int flags) { 1038 void HValueMap::Kill(int flags) {
1038 int depends_flags = HValue::ConvertChangesToDependsFlags(flags); 1039 int depends_flags = HValue::ConvertChangesToDependsFlags(flags);
1039 if ((present_flags_ & depends_flags) == 0) return; 1040 if ((present_flags_ & depends_flags) == 0) return;
1040 present_flags_ = 0; 1041 present_flags_ = 0;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1099 ASSERT(new_size > count_); 1100 ASSERT(new_size > count_);
1100 // Hashing the values into the new array has no more collisions than in the 1101 // Hashing the values into the new array has no more collisions than in the
1101 // old hash map, so we can use the existing lists_ array, if we are careful. 1102 // old hash map, so we can use the existing lists_ array, if we are careful.
1102 1103
1103 // Make sure we have at least one free element. 1104 // Make sure we have at least one free element.
1104 if (free_list_head_ == kNil) { 1105 if (free_list_head_ == kNil) {
1105 ResizeLists(lists_size_ << 1); 1106 ResizeLists(lists_size_ << 1);
1106 } 1107 }
1107 1108
1108 HValueMapListElement* new_array = 1109 HValueMapListElement* new_array =
1109 Zone::NewArray<HValueMapListElement>(new_size); 1110 ZONE->NewArray<HValueMapListElement>(new_size);
1110 memset(new_array, 0, sizeof(HValueMapListElement) * new_size); 1111 memset(new_array, 0, sizeof(HValueMapListElement) * new_size);
1111 1112
1112 HValueMapListElement* old_array = array_; 1113 HValueMapListElement* old_array = array_;
1113 int old_size = array_size_; 1114 int old_size = array_size_;
1114 1115
1115 int old_count = count_; 1116 int old_count = count_;
1116 count_ = 0; 1117 count_ = 0;
1117 // Do not modify present_flags_. It is currently correct. 1118 // Do not modify present_flags_. It is currently correct.
1118 array_size_ = new_size; 1119 array_size_ = new_size;
1119 array_ = new_array; 1120 array_ = new_array;
(...skipping 17 matching lines...) Expand all
1137 } 1138 }
1138 USE(old_count); 1139 USE(old_count);
1139 ASSERT(count_ == old_count); 1140 ASSERT(count_ == old_count);
1140 } 1141 }
1141 1142
1142 1143
1143 void HValueMap::ResizeLists(int new_size) { 1144 void HValueMap::ResizeLists(int new_size) {
1144 ASSERT(new_size > lists_size_); 1145 ASSERT(new_size > lists_size_);
1145 1146
1146 HValueMapListElement* new_lists = 1147 HValueMapListElement* new_lists =
1147 Zone::NewArray<HValueMapListElement>(new_size); 1148 ZONE->NewArray<HValueMapListElement>(new_size);
1148 memset(new_lists, 0, sizeof(HValueMapListElement) * new_size); 1149 memset(new_lists, 0, sizeof(HValueMapListElement) * new_size);
1149 1150
1150 HValueMapListElement* old_lists = lists_; 1151 HValueMapListElement* old_lists = lists_;
1151 int old_size = lists_size_; 1152 int old_size = lists_size_;
1152 1153
1153 lists_size_ = new_size; 1154 lists_size_ = new_size;
1154 lists_ = new_lists; 1155 lists_ = new_lists;
1155 1156
1156 if (old_lists != NULL) { 1157 if (old_lists != NULL) {
1157 memcpy(lists_, old_lists, old_size * sizeof(HValueMapListElement)); 1158 memcpy(lists_, old_lists, old_size * sizeof(HValueMapListElement));
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1240 } 1241 }
1241 1242
1242 1243
1243 class HGlobalValueNumberer BASE_EMBEDDED { 1244 class HGlobalValueNumberer BASE_EMBEDDED {
1244 public: 1245 public:
1245 explicit HGlobalValueNumberer(HGraph* graph, CompilationInfo* info) 1246 explicit HGlobalValueNumberer(HGraph* graph, CompilationInfo* info)
1246 : graph_(graph), 1247 : graph_(graph),
1247 info_(info), 1248 info_(info),
1248 block_side_effects_(graph_->blocks()->length()), 1249 block_side_effects_(graph_->blocks()->length()),
1249 loop_side_effects_(graph_->blocks()->length()) { 1250 loop_side_effects_(graph_->blocks()->length()) {
1250 ASSERT(Heap::allow_allocation(false)); 1251 ASSERT(HEAP->allow_allocation(false));
1251 block_side_effects_.AddBlock(0, graph_->blocks()->length()); 1252 block_side_effects_.AddBlock(0, graph_->blocks()->length());
1252 loop_side_effects_.AddBlock(0, graph_->blocks()->length()); 1253 loop_side_effects_.AddBlock(0, graph_->blocks()->length());
1253 } 1254 }
1254 ~HGlobalValueNumberer() { 1255 ~HGlobalValueNumberer() {
1255 ASSERT(!Heap::allow_allocation(true)); 1256 ASSERT(!HEAP->allow_allocation(true));
1256 } 1257 }
1257 1258
1258 void Analyze(); 1259 void Analyze();
1259 1260
1260 private: 1261 private:
1261 void AnalyzeBlock(HBasicBlock* block, HValueMap* map); 1262 void AnalyzeBlock(HBasicBlock* block, HValueMap* map);
1262 void ComputeBlockSideEffects(); 1263 void ComputeBlockSideEffects();
1263 void LoopInvariantCodeMotion(); 1264 void LoopInvariantCodeMotion();
1264 void ProcessLoopBlock(HBasicBlock* block, 1265 void ProcessLoopBlock(HBasicBlock* block,
1265 HBasicBlock* before_loop, 1266 HBasicBlock* before_loop,
(...skipping 1005 matching lines...) Expand 10 before | Expand all | Expand 10 after
2271 } 2272 }
2272 return call; 2273 return call;
2273 } 2274 }
2274 2275
2275 2276
2276 void HGraphBuilder::SetupScope(Scope* scope) { 2277 void HGraphBuilder::SetupScope(Scope* scope) {
2277 // We don't yet handle the function name for named function expressions. 2278 // We don't yet handle the function name for named function expressions.
2278 if (scope->function() != NULL) BAILOUT("named function expression"); 2279 if (scope->function() != NULL) BAILOUT("named function expression");
2279 2280
2280 HConstant* undefined_constant = 2281 HConstant* undefined_constant =
2281 new HConstant(Factory::undefined_value(), Representation::Tagged()); 2282 new HConstant(FACTORY->undefined_value(), Representation::Tagged());
2282 AddInstruction(undefined_constant); 2283 AddInstruction(undefined_constant);
2283 graph_->set_undefined_constant(undefined_constant); 2284 graph_->set_undefined_constant(undefined_constant);
2284 2285
2285 // Set the initial values of parameters including "this". "This" has 2286 // Set the initial values of parameters including "this". "This" has
2286 // parameter index 0. 2287 // parameter index 0.
2287 int count = scope->num_parameters() + 1; 2288 int count = scope->num_parameters() + 1;
2288 for (int i = 0; i < count; ++i) { 2289 for (int i = 0; i < count; ++i) {
2289 HInstruction* parameter = AddInstruction(new HParameter(i)); 2290 HInstruction* parameter = AddInstruction(new HParameter(i));
2290 environment()->Bind(i, parameter); 2291 environment()->Bind(i, parameter);
2291 } 2292 }
(...skipping 1325 matching lines...) Expand 10 before | Expand all | Expand 10 after
3617 HInstruction* HGraphBuilder::BuildStoreKeyedFastElement(HValue* object, 3618 HInstruction* HGraphBuilder::BuildStoreKeyedFastElement(HValue* object,
3618 HValue* key, 3619 HValue* key,
3619 HValue* val, 3620 HValue* val,
3620 Expression* expr) { 3621 Expression* expr) {
3621 ASSERT(expr->IsMonomorphic()); 3622 ASSERT(expr->IsMonomorphic());
3622 AddInstruction(new HCheckNonSmi(object)); 3623 AddInstruction(new HCheckNonSmi(object));
3623 Handle<Map> map = expr->GetMonomorphicReceiverType(); 3624 Handle<Map> map = expr->GetMonomorphicReceiverType();
3624 ASSERT(map->has_fast_elements()); 3625 ASSERT(map->has_fast_elements());
3625 AddInstruction(new HCheckMap(object, map)); 3626 AddInstruction(new HCheckMap(object, map));
3626 HInstruction* elements = AddInstruction(new HLoadElements(object)); 3627 HInstruction* elements = AddInstruction(new HLoadElements(object));
3627 AddInstruction(new HCheckMap(elements, Factory::fixed_array_map())); 3628 AddInstruction(new HCheckMap(elements, FACTORY->fixed_array_map()));
3628 bool is_array = (map->instance_type() == JS_ARRAY_TYPE); 3629 bool is_array = (map->instance_type() == JS_ARRAY_TYPE);
3629 HInstruction* length = NULL; 3630 HInstruction* length = NULL;
3630 if (is_array) { 3631 if (is_array) {
3631 length = AddInstruction(new HJSArrayLength(object)); 3632 length = AddInstruction(new HJSArrayLength(object));
3632 } else { 3633 } else {
3633 length = AddInstruction(new HFixedArrayLength(elements)); 3634 length = AddInstruction(new HFixedArrayLength(elements));
3634 } 3635 }
3635 AddInstruction(new HBoundsCheck(key, length)); 3636 AddInstruction(new HBoundsCheck(key, length));
3636 return new HStoreKeyedFastElement(elements, key, val); 3637 return new HStoreKeyedFastElement(elements, key, val);
3637 } 3638 }
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
3928 TraceInline(target, "cumulative AST node limit reached"); 3929 TraceInline(target, "cumulative AST node limit reached");
3929 return false; 3930 return false;
3930 } 3931 }
3931 3932
3932 int count_before = AstNode::Count(); 3933 int count_before = AstNode::Count();
3933 3934
3934 // Parse and allocate variables. 3935 // Parse and allocate variables.
3935 CompilationInfo target_info(target); 3936 CompilationInfo target_info(target);
3936 if (!ParserApi::Parse(&target_info) || 3937 if (!ParserApi::Parse(&target_info) ||
3937 !Scope::Analyze(&target_info)) { 3938 !Scope::Analyze(&target_info)) {
3938 if (Top::has_pending_exception()) { 3939 if (target_info.isolate()->has_pending_exception()) {
3939 // Parse or scope error, never optimize this function. 3940 // Parse or scope error, never optimize this function.
3940 SetStackOverflow(); 3941 SetStackOverflow();
3941 target->shared()->set_optimization_disabled(true); 3942 target->shared()->set_optimization_disabled(true);
3942 } 3943 }
3943 TraceInline(target, "parse failure"); 3944 TraceInline(target, "parse failure");
3944 return false; 3945 return false;
3945 } 3946 }
3946 3947
3947 if (target_info.scope()->num_heap_slots() > 0) { 3948 if (target_info.scope()->num_heap_slots() > 0) {
3948 TraceInline(target, "target has context-allocated variables"); 3949 TraceInline(target, "target has context-allocated variables");
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after
4428 INLINE_RUNTIME_FUNCTION_LIST(INLINE_FUNCTION_GENERATOR_ADDRESS) 4429 INLINE_RUNTIME_FUNCTION_LIST(INLINE_FUNCTION_GENERATOR_ADDRESS)
4429 }; 4430 };
4430 #undef INLINE_FUNCTION_GENERATOR_ADDRESS 4431 #undef INLINE_FUNCTION_GENERATOR_ADDRESS
4431 4432
4432 4433
4433 void HGraphBuilder::VisitCallRuntime(CallRuntime* expr) { 4434 void HGraphBuilder::VisitCallRuntime(CallRuntime* expr) {
4434 if (expr->is_jsruntime()) { 4435 if (expr->is_jsruntime()) {
4435 BAILOUT("call to a JavaScript runtime function"); 4436 BAILOUT("call to a JavaScript runtime function");
4436 } 4437 }
4437 4438
4438 Runtime::Function* function = expr->function(); 4439 const Runtime::Function* function = expr->function();
4439 ASSERT(function != NULL); 4440 ASSERT(function != NULL);
4440 if (function->intrinsic_type == Runtime::INLINE) { 4441 if (function->intrinsic_type == Runtime::INLINE) {
4441 ASSERT(expr->name()->length() > 0); 4442 ASSERT(expr->name()->length() > 0);
4442 ASSERT(expr->name()->Get(0) == '_'); 4443 ASSERT(expr->name()->Get(0) == '_');
4443 // Call to an inline function. 4444 // Call to an inline function.
4444 int lookup_index = static_cast<int>(function->function_id) - 4445 int lookup_index = static_cast<int>(function->function_id) -
4445 static_cast<int>(Runtime::kFirstInlineFunction); 4446 static_cast<int>(Runtime::kFirstInlineFunction);
4446 ASSERT(lookup_index >= 0); 4447 ASSERT(lookup_index >= 0);
4447 ASSERT(static_cast<size_t>(lookup_index) < 4448 ASSERT(static_cast<size_t>(lookup_index) <
4448 ARRAY_SIZE(kInlineFunctionGenerators)); 4449 ARRAY_SIZE(kInlineFunctionGenerators));
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
4967 Handle<String> name = var->name(); 4968 Handle<String> name = var->name();
4968 Handle<GlobalObject> global(info()->global_object()); 4969 Handle<GlobalObject> global(info()->global_object());
4969 LookupResult lookup; 4970 LookupResult lookup;
4970 global->Lookup(*name, &lookup); 4971 global->Lookup(*name, &lookup);
4971 if (lookup.IsProperty() && 4972 if (lookup.IsProperty() &&
4972 lookup.type() == NORMAL && 4973 lookup.type() == NORMAL &&
4973 lookup.GetValue()->IsJSFunction()) { 4974 lookup.GetValue()->IsJSFunction()) {
4974 Handle<JSFunction> candidate(JSFunction::cast(lookup.GetValue())); 4975 Handle<JSFunction> candidate(JSFunction::cast(lookup.GetValue()));
4975 // If the function is in new space we assume it's more likely to 4976 // If the function is in new space we assume it's more likely to
4976 // change and thus prefer the general IC code. 4977 // change and thus prefer the general IC code.
4977 if (!Heap::InNewSpace(*candidate)) { 4978 if (!Isolate::Current()->heap()->InNewSpace(*candidate)) {
4978 target = candidate; 4979 target = candidate;
4979 } 4980 }
4980 } 4981 }
4981 } 4982 }
4982 4983
4983 // If the target is not null we have found a known global function that is 4984 // If the target is not null we have found a known global function that is
4984 // assumed to stay the same for this instanceof. 4985 // assumed to stay the same for this instanceof.
4985 if (target.is_null()) { 4986 if (target.is_null()) {
4986 HContext* context = new HContext; 4987 HContext* context = new HContext;
4987 AddInstruction(context); 4988 AddInstruction(context);
(...skipping 938 matching lines...) Expand 10 before | Expand all | Expand 10 after
5926 } 5927 }
5927 } 5928 }
5928 5929
5929 #ifdef DEBUG 5930 #ifdef DEBUG
5930 if (graph_ != NULL) graph_->Verify(); 5931 if (graph_ != NULL) graph_->Verify();
5931 if (allocator_ != NULL) allocator_->Verify(); 5932 if (allocator_ != NULL) allocator_->Verify();
5932 #endif 5933 #endif
5933 } 5934 }
5934 5935
5935 } } // namespace v8::internal 5936 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698