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

Side by Side Diff: src/hydrogen.cc

Issue 10105026: Version 3.10.3 (Closed) Base URL: http://v8.googlecode.com/svn/trunk/
Patch Set: Created 8 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
« no previous file with comments | « src/hydrogen.h ('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 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 594 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 605
606 HGraphBuilder::HGraphBuilder(CompilationInfo* info, 606 HGraphBuilder::HGraphBuilder(CompilationInfo* info,
607 TypeFeedbackOracle* oracle) 607 TypeFeedbackOracle* oracle)
608 : function_state_(NULL), 608 : function_state_(NULL),
609 initial_function_state_(this, info, oracle, NORMAL_RETURN), 609 initial_function_state_(this, info, oracle, NORMAL_RETURN),
610 ast_context_(NULL), 610 ast_context_(NULL),
611 break_scope_(NULL), 611 break_scope_(NULL),
612 graph_(NULL), 612 graph_(NULL),
613 current_block_(NULL), 613 current_block_(NULL),
614 inlined_count_(0), 614 inlined_count_(0),
615 globals_(10),
615 zone_(info->isolate()->zone()), 616 zone_(info->isolate()->zone()),
616 inline_bailout_(false) { 617 inline_bailout_(false) {
617 // This is not initialized in the initializer list because the 618 // This is not initialized in the initializer list because the
618 // constructor for the initial state relies on function_state_ == NULL 619 // constructor for the initial state relies on function_state_ == NULL
619 // to know it's the initial state. 620 // to know it's the initial state.
620 function_state_= &initial_function_state_; 621 function_state_= &initial_function_state_;
621 } 622 }
622 623
623 HBasicBlock* HGraphBuilder::CreateJoin(HBasicBlock* first, 624 HBasicBlock* HGraphBuilder::CreateJoin(HBasicBlock* first,
624 HBasicBlock* second, 625 HBasicBlock* second,
(...skipping 1918 matching lines...) Expand 10 before | Expand all | Expand 10 after
2543 // not replayed by the Lithium translation. 2544 // not replayed by the Lithium translation.
2544 HEnvironment* initial_env = environment()->CopyWithoutHistory(); 2545 HEnvironment* initial_env = environment()->CopyWithoutHistory();
2545 HBasicBlock* body_entry = CreateBasicBlock(initial_env); 2546 HBasicBlock* body_entry = CreateBasicBlock(initial_env);
2546 current_block()->Goto(body_entry); 2547 current_block()->Goto(body_entry);
2547 body_entry->SetJoinId(AstNode::kFunctionEntryId); 2548 body_entry->SetJoinId(AstNode::kFunctionEntryId);
2548 set_current_block(body_entry); 2549 set_current_block(body_entry);
2549 2550
2550 // Handle implicit declaration of the function name in named function 2551 // Handle implicit declaration of the function name in named function
2551 // expressions before other declarations. 2552 // expressions before other declarations.
2552 if (scope->is_function_scope() && scope->function() != NULL) { 2553 if (scope->is_function_scope() && scope->function() != NULL) {
2553 HandleDeclaration(scope->function(), CONST, NULL, NULL); 2554 VisitVariableDeclaration(scope->function());
2554 } 2555 }
2555 VisitDeclarations(scope->declarations()); 2556 VisitDeclarations(scope->declarations());
2556 AddSimulate(AstNode::kDeclarationsId); 2557 AddSimulate(AstNode::kDeclarationsId);
2557 2558
2558 HValue* context = environment()->LookupContext(); 2559 HValue* context = environment()->LookupContext();
2559 AddInstruction( 2560 AddInstruction(
2560 new(zone()) HStackCheck(context, HStackCheck::kFunctionEntry)); 2561 new(zone()) HStackCheck(context, HStackCheck::kFunctionEntry));
2561 2562
2562 VisitStatements(info()->function()->body()); 2563 VisitStatements(info()->function()->body());
2563 if (HasStackOverflow()) return NULL; 2564 if (HasStackOverflow()) return NULL;
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
2760 header->SetInitialEnvironment(entry_env); 2761 header->SetInitialEnvironment(entry_env);
2761 header->AttachLoopInformation(); 2762 header->AttachLoopInformation();
2762 return header; 2763 return header;
2763 } 2764 }
2764 2765
2765 2766
2766 void HGraphBuilder::VisitBlock(Block* stmt) { 2767 void HGraphBuilder::VisitBlock(Block* stmt) {
2767 ASSERT(!HasStackOverflow()); 2768 ASSERT(!HasStackOverflow());
2768 ASSERT(current_block() != NULL); 2769 ASSERT(current_block() != NULL);
2769 ASSERT(current_block()->HasPredecessor()); 2770 ASSERT(current_block()->HasPredecessor());
2770 if (stmt->block_scope() != NULL) { 2771 if (stmt->scope() != NULL) {
2771 return Bailout("ScopedBlock"); 2772 return Bailout("ScopedBlock");
2772 } 2773 }
2773 BreakAndContinueInfo break_info(stmt); 2774 BreakAndContinueInfo break_info(stmt);
2774 { BreakAndContinueScope push(&break_info, this); 2775 { BreakAndContinueScope push(&break_info, this);
2775 CHECK_BAILOUT(VisitStatements(stmt->statements())); 2776 CHECK_BAILOUT(VisitStatements(stmt->statements()));
2776 } 2777 }
2777 HBasicBlock* break_block = break_info.break_block(); 2778 HBasicBlock* break_block = break_info.break_block();
2778 if (break_block != NULL) { 2779 if (break_block != NULL) {
2779 if (current_block() != NULL) current_block()->Goto(break_block); 2780 if (current_block() != NULL) current_block()->Goto(break_block);
2780 break_block->SetJoinId(stmt->ExitId()); 2781 break_block->SetJoinId(stmt->ExitId());
(...skipping 960 matching lines...) Expand 10 before | Expand all | Expand 10 after
3741 int* total_size) { 3742 int* total_size) {
3742 ASSERT(max_depth >= 0 && *max_properties >= 0); 3743 ASSERT(max_depth >= 0 && *max_properties >= 0);
3743 if (max_depth == 0) return false; 3744 if (max_depth == 0) return false;
3744 3745
3745 Handle<FixedArrayBase> elements(boilerplate->elements()); 3746 Handle<FixedArrayBase> elements(boilerplate->elements());
3746 if (elements->length() > 0 && 3747 if (elements->length() > 0 &&
3747 elements->map() != boilerplate->GetHeap()->fixed_cow_array_map()) { 3748 elements->map() != boilerplate->GetHeap()->fixed_cow_array_map()) {
3748 if (boilerplate->HasFastDoubleElements()) { 3749 if (boilerplate->HasFastDoubleElements()) {
3749 *total_size += FixedDoubleArray::SizeFor(elements->length()); 3750 *total_size += FixedDoubleArray::SizeFor(elements->length());
3750 } else if (boilerplate->HasFastElements()) { 3751 } else if (boilerplate->HasFastElements()) {
3752 Handle<FixedArray> fast_elements = Handle<FixedArray>::cast(elements);
3751 int length = elements->length(); 3753 int length = elements->length();
3752 for (int i = 0; i < length; i++) { 3754 for (int i = 0; i < length; i++) {
3753 if ((*max_properties)-- == 0) return false; 3755 if ((*max_properties)-- == 0) return false;
3754 Handle<Object> value = JSObject::GetElement(boilerplate, i); 3756 Handle<Object> value(fast_elements->get(i));
3755 if (value->IsJSObject()) { 3757 if (value->IsJSObject()) {
3756 Handle<JSObject> value_object = Handle<JSObject>::cast(value); 3758 Handle<JSObject> value_object = Handle<JSObject>::cast(value);
3757 if (!IsFastLiteral(value_object, 3759 if (!IsFastLiteral(value_object,
3758 max_depth - 1, 3760 max_depth - 1,
3759 max_properties, 3761 max_properties,
3760 total_size)) { 3762 total_size)) {
3761 return false; 3763 return false;
3762 } 3764 }
3763 } 3765 }
3764 } 3766 }
(...skipping 3388 matching lines...) Expand 10 before | Expand all | Expand 10 after
7153 ASSERT(!HasStackOverflow()); 7155 ASSERT(!HasStackOverflow());
7154 ASSERT(current_block() != NULL); 7156 ASSERT(current_block() != NULL);
7155 ASSERT(current_block()->HasPredecessor()); 7157 ASSERT(current_block()->HasPredecessor());
7156 HThisFunction* self = new(zone()) HThisFunction( 7158 HThisFunction* self = new(zone()) HThisFunction(
7157 function_state()->compilation_info()->closure()); 7159 function_state()->compilation_info()->closure());
7158 return ast_context()->ReturnInstruction(self, expr->id()); 7160 return ast_context()->ReturnInstruction(self, expr->id());
7159 } 7161 }
7160 7162
7161 7163
7162 void HGraphBuilder::VisitDeclarations(ZoneList<Declaration*>* declarations) { 7164 void HGraphBuilder::VisitDeclarations(ZoneList<Declaration*>* declarations) {
7163 int length = declarations->length(); 7165 ASSERT(globals_.is_empty());
7164 int global_count = 0; 7166 AstVisitor::VisitDeclarations(declarations);
7165 for (int i = 0; i < declarations->length(); i++) { 7167 if (!globals_.is_empty()) {
7166 Declaration* decl = declarations->at(i);
7167 FunctionDeclaration* fun_decl = decl->AsFunctionDeclaration();
7168 HandleDeclaration(decl->proxy(),
7169 decl->mode(),
7170 fun_decl != NULL ? fun_decl->fun() : NULL,
7171 &global_count);
7172 }
7173
7174 // Batch declare global functions and variables.
7175 if (global_count > 0) {
7176 Handle<FixedArray> array = 7168 Handle<FixedArray> array =
7177 isolate()->factory()->NewFixedArray(2 * global_count, TENURED); 7169 isolate()->factory()->NewFixedArray(globals_.length(), TENURED);
7178 for (int j = 0, i = 0; i < length; i++) { 7170 for (int i = 0; i < globals_.length(); ++i) array->set(i, *globals_.at(i));
7179 Declaration* decl = declarations->at(i);
7180 Variable* var = decl->proxy()->var();
7181
7182 if (var->IsUnallocated()) {
7183 array->set(j++, *(var->name()));
7184 FunctionDeclaration* fun_decl = decl->AsFunctionDeclaration();
7185 if (fun_decl == NULL) {
7186 if (var->binding_needs_init()) {
7187 // In case this binding needs initialization use the hole.
7188 array->set_the_hole(j++);
7189 } else {
7190 array->set_undefined(j++);
7191 }
7192 } else {
7193 Handle<SharedFunctionInfo> function =
7194 Compiler::BuildFunctionInfo(fun_decl->fun(), info()->script());
7195 // Check for stack-overflow exception.
7196 if (function.is_null()) {
7197 SetStackOverflow();
7198 return;
7199 }
7200 array->set(j++, *function);
7201 }
7202 }
7203 }
7204 int flags = DeclareGlobalsEvalFlag::encode(info()->is_eval()) | 7171 int flags = DeclareGlobalsEvalFlag::encode(info()->is_eval()) |
7205 DeclareGlobalsNativeFlag::encode(info()->is_native()) | 7172 DeclareGlobalsNativeFlag::encode(info()->is_native()) |
7206 DeclareGlobalsLanguageMode::encode(info()->language_mode()); 7173 DeclareGlobalsLanguageMode::encode(info()->language_mode());
7207 HInstruction* result = 7174 HInstruction* result = new(zone()) HDeclareGlobals(
7208 new(zone()) HDeclareGlobals(environment()->LookupContext(), 7175 environment()->LookupContext(), array, flags);
7209 array,
7210 flags);
7211 AddInstruction(result); 7176 AddInstruction(result);
7177 globals_.Clear();
7212 } 7178 }
7213 } 7179 }
7214 7180
7215 7181
7216 void HGraphBuilder::HandleDeclaration(VariableProxy* proxy, 7182 void HGraphBuilder::VisitVariableDeclaration(VariableDeclaration* declaration) {
7217 VariableMode mode, 7183 VariableProxy* proxy = declaration->proxy();
7218 FunctionLiteral* function, 7184 VariableMode mode = declaration->mode();
7219 int* global_count) { 7185 Variable* variable = proxy->var();
7220 Variable* var = proxy->var(); 7186 bool hole_init = mode == CONST || mode == CONST_HARMONY || mode == LET;
7221 bool binding_needs_init = 7187 switch (variable->location()) {
7222 (mode == CONST || mode == CONST_HARMONY || mode == LET);
7223 switch (var->location()) {
7224 case Variable::UNALLOCATED: 7188 case Variable::UNALLOCATED:
7225 ++(*global_count); 7189 globals_.Add(variable->name());
7190 globals_.Add(variable->binding_needs_init()
7191 ? isolate()->factory()->the_hole_value()
7192 : isolate()->factory()->undefined_value());
7226 return; 7193 return;
7227 case Variable::PARAMETER: 7194 case Variable::PARAMETER:
7228 case Variable::LOCAL: 7195 case Variable::LOCAL:
7196 if (hole_init) {
7197 HValue* value = graph()->GetConstantHole();
7198 environment()->Bind(variable, value);
7199 }
7200 break;
7229 case Variable::CONTEXT: 7201 case Variable::CONTEXT:
7230 if (binding_needs_init || function != NULL) { 7202 if (hole_init) {
7231 HValue* value = NULL; 7203 HValue* value = graph()->GetConstantHole();
7232 if (function != NULL) { 7204 HValue* context = environment()->LookupContext();
7233 CHECK_ALIVE(VisitForValue(function)); 7205 HStoreContextSlot* store = new HStoreContextSlot(
7234 value = Pop(); 7206 context, variable->index(), HStoreContextSlot::kNoCheck, value);
7235 } else { 7207 AddInstruction(store);
7236 value = graph()->GetConstantHole(); 7208 if (store->HasObservableSideEffects()) AddSimulate(proxy->id());
7237 }
7238 if (var->IsContextSlot()) {
7239 HValue* context = environment()->LookupContext();
7240 HStoreContextSlot* store = new HStoreContextSlot(
7241 context, var->index(), HStoreContextSlot::kNoCheck, value);
7242 AddInstruction(store);
7243 if (store->HasObservableSideEffects()) AddSimulate(proxy->id());
7244 } else {
7245 environment()->Bind(var, value);
7246 }
7247 } 7209 }
7248 break; 7210 break;
7249 case Variable::LOOKUP: 7211 case Variable::LOOKUP:
7250 return Bailout("unsupported lookup slot in declaration"); 7212 return Bailout("unsupported lookup slot in declaration");
7251 } 7213 }
7252 } 7214 }
7253 7215
7254 7216
7255 void HGraphBuilder::VisitVariableDeclaration(VariableDeclaration* decl) { 7217 void HGraphBuilder::VisitFunctionDeclaration(FunctionDeclaration* declaration) {
7218 VariableProxy* proxy = declaration->proxy();
7219 Variable* variable = proxy->var();
7220 switch (variable->location()) {
7221 case Variable::UNALLOCATED: {
7222 globals_.Add(variable->name());
7223 Handle<SharedFunctionInfo> function =
7224 Compiler::BuildFunctionInfo(declaration->fun(), info()->script());
7225 // Check for stack-overflow exception.
7226 if (function.is_null()) return SetStackOverflow();
7227 globals_.Add(function);
7228 return;
7229 }
7230 case Variable::PARAMETER:
7231 case Variable::LOCAL: {
7232 CHECK_ALIVE(VisitForValue(declaration->fun()));
7233 HValue* value = Pop();
7234 environment()->Bind(variable, value);
7235 break;
7236 }
7237 case Variable::CONTEXT: {
7238 CHECK_ALIVE(VisitForValue(declaration->fun()));
7239 HValue* value = Pop();
7240 HValue* context = environment()->LookupContext();
7241 HStoreContextSlot* store = new HStoreContextSlot(
7242 context, variable->index(), HStoreContextSlot::kNoCheck, value);
7243 AddInstruction(store);
7244 if (store->HasObservableSideEffects()) AddSimulate(proxy->id());
7245 break;
7246 }
7247 case Variable::LOOKUP:
7248 return Bailout("unsupported lookup slot in declaration");
7249 }
7250 }
7251
7252
7253 void HGraphBuilder::VisitModuleDeclaration(ModuleDeclaration* declaration) {
7256 UNREACHABLE(); 7254 UNREACHABLE();
7257 } 7255 }
7258 7256
7259 7257
7260 void HGraphBuilder::VisitFunctionDeclaration(FunctionDeclaration* decl) { 7258 void HGraphBuilder::VisitImportDeclaration(ImportDeclaration* declaration) {
7261 UNREACHABLE(); 7259 UNREACHABLE();
7262 } 7260 }
7263 7261
7264 7262
7265 void HGraphBuilder::VisitModuleDeclaration(ModuleDeclaration* decl) { 7263 void HGraphBuilder::VisitExportDeclaration(ExportDeclaration* declaration) {
7266 UNREACHABLE();
7267 }
7268
7269
7270 void HGraphBuilder::VisitImportDeclaration(ImportDeclaration* decl) {
7271 UNREACHABLE();
7272 }
7273
7274
7275 void HGraphBuilder::VisitExportDeclaration(ExportDeclaration* decl) {
7276 UNREACHABLE(); 7264 UNREACHABLE();
7277 } 7265 }
7278 7266
7279 7267
7280 void HGraphBuilder::VisitModuleLiteral(ModuleLiteral* module) { 7268 void HGraphBuilder::VisitModuleLiteral(ModuleLiteral* module) {
7281 // TODO(rossberg) 7269 UNREACHABLE();
7282 } 7270 }
7283 7271
7284 7272
7285 void HGraphBuilder::VisitModuleVariable(ModuleVariable* module) { 7273 void HGraphBuilder::VisitModuleVariable(ModuleVariable* module) {
7286 // TODO(rossberg) 7274 UNREACHABLE();
7287 } 7275 }
7288 7276
7289 7277
7290 void HGraphBuilder::VisitModulePath(ModulePath* module) { 7278 void HGraphBuilder::VisitModulePath(ModulePath* module) {
7291 // TODO(rossberg) 7279 UNREACHABLE();
7292 } 7280 }
7293 7281
7294 7282
7295 void HGraphBuilder::VisitModuleUrl(ModuleUrl* module) { 7283 void HGraphBuilder::VisitModuleUrl(ModuleUrl* module) {
7296 // TODO(rossberg) 7284 UNREACHABLE();
7297 } 7285 }
7298 7286
7299 7287
7300 // Generators for inline runtime functions. 7288 // Generators for inline runtime functions.
7301 // Support for types. 7289 // Support for types.
7302 void HGraphBuilder::GenerateIsSmi(CallRuntime* call) { 7290 void HGraphBuilder::GenerateIsSmi(CallRuntime* call) {
7303 ASSERT(call->arguments()->length() == 1); 7291 ASSERT(call->arguments()->length() == 1);
7304 CHECK_ALIVE(VisitForValue(call->arguments()->at(0))); 7292 CHECK_ALIVE(VisitForValue(call->arguments()->at(0)));
7305 HValue* value = Pop(); 7293 HValue* value = Pop();
7306 HIsSmiAndBranch* result = new(zone()) HIsSmiAndBranch(value); 7294 HIsSmiAndBranch* result = new(zone()) HIsSmiAndBranch(value);
(...skipping 1071 matching lines...) Expand 10 before | Expand all | Expand 10 after
8378 } 8366 }
8379 } 8367 }
8380 8368
8381 #ifdef DEBUG 8369 #ifdef DEBUG
8382 if (graph_ != NULL) graph_->Verify(false); // No full verify. 8370 if (graph_ != NULL) graph_->Verify(false); // No full verify.
8383 if (allocator_ != NULL) allocator_->Verify(); 8371 if (allocator_ != NULL) allocator_->Verify();
8384 #endif 8372 #endif
8385 } 8373 }
8386 8374
8387 } } // namespace v8::internal 8375 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/hydrogen.h ('k') | src/hydrogen-instructions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698