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

Side by Side Diff: src/scopes.cc

Issue 669270: Remove unneeded variable usage analysis. (Closed)
Patch Set: Created 10 years, 9 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
« no previous file with comments | « src/scopeinfo.cc ('k') | src/usage-analyzer.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 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 302
303 303
304 template<class Allocator> 304 template<class Allocator>
305 void Scope::CollectUsedVariables(List<Variable*, Allocator>* locals) { 305 void Scope::CollectUsedVariables(List<Variable*, Allocator>* locals) {
306 // Collect variables in this scope. 306 // Collect variables in this scope.
307 // Note that the function_ variable - if present - is not 307 // Note that the function_ variable - if present - is not
308 // collected here but handled separately in ScopeInfo 308 // collected here but handled separately in ScopeInfo
309 // which is the current user of this function). 309 // which is the current user of this function).
310 for (int i = 0; i < temps_.length(); i++) { 310 for (int i = 0; i < temps_.length(); i++) {
311 Variable* var = temps_[i]; 311 Variable* var = temps_[i];
312 if (var->var_uses()->is_used()) { 312 if (var->is_used()) {
313 locals->Add(var); 313 locals->Add(var);
314 } 314 }
315 } 315 }
316 for (VariableMap::Entry* p = variables_.Start(); 316 for (VariableMap::Entry* p = variables_.Start();
317 p != NULL; 317 p != NULL;
318 p = variables_.Next(p)) { 318 p = variables_.Next(p)) {
319 Variable* var = reinterpret_cast<Variable*>(p->value); 319 Variable* var = reinterpret_cast<Variable*>(p->value);
320 if (var->var_uses()->is_used()) { 320 if (var->is_used()) {
321 locals->Add(var); 321 locals->Add(var);
322 } 322 }
323 } 323 }
324 } 324 }
325 325
326 326
327 // Make sure the method gets instantiated by the template system. 327 // Make sure the method gets instantiated by the template system.
328 template void Scope::CollectUsedVariables( 328 template void Scope::CollectUsedVariables(
329 List<Variable*, FreeStoreAllocationPolicy>* locals); 329 List<Variable*, FreeStoreAllocationPolicy>* locals);
330 template void Scope::CollectUsedVariables( 330 template void Scope::CollectUsedVariables(
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 } 411 }
412 412
413 413
414 static void PrintName(Handle<String> name) { 414 static void PrintName(Handle<String> name) {
415 SmartPointer<char> s = name->ToCString(DISALLOW_NULLS); 415 SmartPointer<char> s = name->ToCString(DISALLOW_NULLS);
416 PrintF("%s", *s); 416 PrintF("%s", *s);
417 } 417 }
418 418
419 419
420 static void PrintVar(PrettyPrinter* printer, int indent, Variable* var) { 420 static void PrintVar(PrettyPrinter* printer, int indent, Variable* var) {
421 if (var->var_uses()->is_used() || var->rewrite() != NULL) { 421 if (var->is_used() || var->rewrite() != NULL) {
422 Indent(indent, Variable::Mode2String(var->mode())); 422 Indent(indent, Variable::Mode2String(var->mode()));
423 PrintF(" "); 423 PrintF(" ");
424 PrintName(var->name()); 424 PrintName(var->name());
425 PrintF("; // "); 425 PrintF("; // ");
426 if (var->rewrite() != NULL) PrintF("%s, ", printer->Print(var->rewrite())); 426 if (var->rewrite() != NULL) {
427 if (var->is_accessed_from_inner_scope()) PrintF("inner scope access, "); 427 PrintF("%s, ", printer->Print(var->rewrite()));
428 PrintF("var "); 428 if (var->is_accessed_from_inner_scope()) PrintF(", ");
429 var->var_uses()->Print(); 429 }
430 PrintF(", obj "); 430 if (var->is_accessed_from_inner_scope()) PrintF("inner scope access");
431 var->obj_uses()->Print();
432 PrintF("\n"); 431 PrintF("\n");
433 } 432 }
434 } 433 }
435 434
436 435
437 static void PrintMap(PrettyPrinter* printer, int indent, VariableMap* map) { 436 static void PrintMap(PrettyPrinter* printer, int indent, VariableMap* map) {
438 for (VariableMap::Entry* p = map->Start(); p != NULL; p = map->Next(p)) { 437 for (VariableMap::Entry* p = map->Start(); p != NULL; p = map->Next(p)) {
439 Variable* var = reinterpret_cast<Variable*>(p->value); 438 Variable* var = reinterpret_cast<Variable*>(p->value);
440 PrintVar(printer, indent, var); 439 PrintVar(printer, indent, var);
441 } 440 }
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 730
732 731
733 bool Scope::MustAllocate(Variable* var) { 732 bool Scope::MustAllocate(Variable* var) {
734 // Give var a read/write use if there is a chance it might be accessed 733 // Give var a read/write use if there is a chance it might be accessed
735 // via an eval() call. This is only possible if the variable has a 734 // via an eval() call. This is only possible if the variable has a
736 // visible name. 735 // visible name.
737 if ((var->is_this() || var->name()->length() > 0) && 736 if ((var->is_this() || var->name()->length() > 0) &&
738 (var->is_accessed_from_inner_scope_ || 737 (var->is_accessed_from_inner_scope_ ||
739 scope_calls_eval_ || inner_scope_calls_eval_ || 738 scope_calls_eval_ || inner_scope_calls_eval_ ||
740 scope_contains_with_)) { 739 scope_contains_with_)) {
741 var->var_uses()->RecordAccess(1); 740 var->set_is_used(true);
742 } 741 }
743 // Global variables do not need to be allocated. 742 // Global variables do not need to be allocated.
744 return !var->is_global() && var->var_uses()->is_used(); 743 return !var->is_global() && var->is_used();
745 } 744 }
746 745
747 746
748 bool Scope::MustAllocateInContext(Variable* var) { 747 bool Scope::MustAllocateInContext(Variable* var) {
749 // If var is accessed from an inner scope, or if there is a 748 // If var is accessed from an inner scope, or if there is a
750 // possibility that it might be accessed from the current or an inner 749 // possibility that it might be accessed from the current or an inner
751 // scope (through an eval() call), it must be allocated in the 750 // scope (through an eval() call), it must be allocated in the
752 // context. Exception: temporary variables are not allocated in the 751 // context. Exception: temporary variables are not allocated in the
753 // context. 752 // context.
754 return 753 return
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 // It is ok to set this only now, because arguments is a local 839 // It is ok to set this only now, because arguments is a local
841 // variable that is allocated after the parameters have been 840 // variable that is allocated after the parameters have been
842 // allocated. 841 // allocated.
843 arguments_shadow->is_accessed_from_inner_scope_ = true; 842 arguments_shadow->is_accessed_from_inner_scope_ = true;
844 } 843 }
845 var->rewrite_ = 844 var->rewrite_ =
846 new Property(arguments_shadow_, 845 new Property(arguments_shadow_,
847 new Literal(Handle<Object>(Smi::FromInt(i))), 846 new Literal(Handle<Object>(Smi::FromInt(i))),
848 RelocInfo::kNoPosition, 847 RelocInfo::kNoPosition,
849 Property::SYNTHETIC); 848 Property::SYNTHETIC);
850 arguments_shadow->var_uses()->RecordUses(var->var_uses()); 849 if (var->is_used()) arguments_shadow->set_is_used(true);
851 } 850 }
852 } 851 }
853 852
854 } else { 853 } else {
855 // The arguments object is not used, so we can access parameters directly. 854 // The arguments object is not used, so we can access parameters directly.
856 // The same parameter may occur multiple times in the parameters_ list. 855 // The same parameter may occur multiple times in the parameters_ list.
857 // If it does, and if it is not copied into the context object, it must 856 // If it does, and if it is not copied into the context object, it must
858 // receive the highest parameter index for that parameter; thus iteration 857 // receive the highest parameter index for that parameter; thus iteration
859 // order is relevant! 858 // order is relevant!
860 for (int i = 0; i < params_.length(); i++) { 859 for (int i = 0; i < params_.length(); i++) {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
954 if (num_heap_slots_ == Context::MIN_CONTEXT_SLOTS && 953 if (num_heap_slots_ == Context::MIN_CONTEXT_SLOTS &&
955 !must_have_local_context) { 954 !must_have_local_context) {
956 num_heap_slots_ = 0; 955 num_heap_slots_ = 0;
957 } 956 }
958 957
959 // Allocation done. 958 // Allocation done.
960 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS); 959 ASSERT(num_heap_slots_ == 0 || num_heap_slots_ >= Context::MIN_CONTEXT_SLOTS);
961 } 960 }
962 961
963 } } // namespace v8::internal 962 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/scopeinfo.cc ('k') | src/usage-analyzer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698