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

Side by Side Diff: src/hydrogen.cc

Issue 10544196: Defer creating Handles for HConstants to the code generation phase. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Review. Created 8 years, 5 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 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 561 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 if (!pointer->is_set()) { 572 if (!pointer->is_set()) {
573 HConstant* constant = new(zone()) HConstant(value, 573 HConstant* constant = new(zone()) HConstant(value,
574 Representation::Tagged()); 574 Representation::Tagged());
575 constant->InsertAfter(GetConstantUndefined()); 575 constant->InsertAfter(GetConstantUndefined());
576 pointer->set(constant); 576 pointer->set(constant);
577 } 577 }
578 return pointer->get(); 578 return pointer->get();
579 } 579 }
580 580
581 581
582 HConstant* HGraph::GetConstantInt32(SetOncePointer<HConstant>* pointer,
583 int32_t value) {
584 if (!pointer->is_set()) {
585 HConstant* constant =
586 new(zone()) HConstant(value, Representation::Integer32());
587 constant->InsertAfter(GetConstantUndefined());
588 pointer->set(constant);
589 }
590 return pointer->get();
591 }
592
593
582 HConstant* HGraph::GetConstant1() { 594 HConstant* HGraph::GetConstant1() {
583 return GetConstant(&constant_1_, Handle<Smi>(Smi::FromInt(1))); 595 return GetConstantInt32(&constant_1_, 1);
584 } 596 }
585 597
586 598
587 HConstant* HGraph::GetConstantMinus1() { 599 HConstant* HGraph::GetConstantMinus1() {
588 return GetConstant(&constant_minus1_, Handle<Smi>(Smi::FromInt(-1))); 600 return GetConstantInt32(&constant_minus1_, -1);
589 } 601 }
590 602
591 603
592 HConstant* HGraph::GetConstantTrue() { 604 HConstant* HGraph::GetConstantTrue() {
593 return GetConstant(&constant_true_, isolate()->factory()->true_value()); 605 return GetConstant(&constant_true_, isolate()->factory()->true_value());
594 } 606 }
595 607
596 608
597 HConstant* HGraph::GetConstantFalse() { 609 HConstant* HGraph::GetConstantFalse() {
598 return GetConstant(&constant_false_, isolate()->factory()->false_value()); 610 return GetConstant(&constant_false_, isolate()->factory()->false_value());
(...skipping 2445 matching lines...) Expand 10 before | Expand all | Expand 10 after
3044 for (int i = 0; i < exprs->length(); ++i) { 3056 for (int i = 0; i < exprs->length(); ++i) {
3045 CHECK_ALIVE(VisitForValue(exprs->at(i))); 3057 CHECK_ALIVE(VisitForValue(exprs->at(i)));
3046 } 3058 }
3047 } 3059 }
3048 3060
3049 3061
3050 HGraph* HGraphBuilder::CreateGraph() { 3062 HGraph* HGraphBuilder::CreateGraph() {
3051 graph_ = new(zone()) HGraph(info()); 3063 graph_ = new(zone()) HGraph(info());
3052 if (FLAG_hydrogen_stats) HStatistics::Instance()->Initialize(info()); 3064 if (FLAG_hydrogen_stats) HStatistics::Instance()->Initialize(info());
3053 3065
3066 Factory* f = info()->isolate()->factory();
Michael Starzinger 2012/07/10 12:05:51 I don't think this change is actually needed.
3067 constant_undefined_ = new(zone()) HConstant(f->undefined_value(),
3068 Representation::Tagged());
3069 constant_null_ = new(zone()) HConstant(f->null_value(),
3070 Representation::Tagged());
3071
3054 { 3072 {
3055 HPhase phase("H_Block building"); 3073 HPhase phase("H_Block building");
3056 CompilationHandleScope handle_scope(info()); 3074 CompilationHandleScope handle_scope(info());
3057 current_block_ = graph()->entry_block(); 3075 current_block_ = graph()->entry_block();
3058 3076
3059 Scope* scope = info()->scope(); 3077 Scope* scope = info()->scope();
3060 if (scope->HasIllegalRedeclaration()) { 3078 if (scope->HasIllegalRedeclaration()) {
3061 Bailout("function with illegal redeclaration"); 3079 Bailout("function with illegal redeclaration");
3062 return NULL; 3080 return NULL;
3063 } 3081 }
(...skipping 4801 matching lines...) Expand 10 before | Expand all | Expand 10 after
7865 instr = HShl::NewHShl(zone(), context, left, right); 7883 instr = HShl::NewHShl(zone(), context, left, right);
7866 break; 7884 break;
7867 default: 7885 default:
7868 UNREACHABLE(); 7886 UNREACHABLE();
7869 } 7887 }
7870 7888
7871 // If we hit an uninitialized binary op stub we will get type info 7889 // If we hit an uninitialized binary op stub we will get type info
7872 // for a smi operation. If one of the operands is a constant string 7890 // for a smi operation. If one of the operands is a constant string
7873 // do not generate code assuming it is a smi operation. 7891 // do not generate code assuming it is a smi operation.
7874 if (info.IsSmi() && 7892 if (info.IsSmi() &&
7875 ((left->IsConstant() && HConstant::cast(left)->HasStringValue()) || 7893 ((left->IsConstant() && HConstant::cast(left)->handle()->IsString()) ||
7876 (right->IsConstant() && HConstant::cast(right)->HasStringValue()))) { 7894 (right->IsConstant() && HConstant::cast(right)->handle()->IsString()))) {
7877 return instr; 7895 return instr;
7878 } 7896 }
7879 Representation rep = ToRepresentation(info); 7897 Representation rep = ToRepresentation(info);
7880 // We only generate either int32 or generic tagged bitwise operations. 7898 // We only generate either int32 or generic tagged bitwise operations.
7881 if (instr->IsBitwiseBinaryOperation()) { 7899 if (instr->IsBitwiseBinaryOperation()) {
7882 HBitwiseBinaryOperation::cast(instr)-> 7900 HBitwiseBinaryOperation::cast(instr)->
7883 InitializeObservedInputRepresentation(rep); 7901 InitializeObservedInputRepresentation(rep);
7884 if (rep.IsDouble()) rep = Representation::Integer32(); 7902 if (rep.IsDouble()) rep = Representation::Integer32();
7885 } 7903 }
7886 TraceRepresentation(expr->op(), info, instr, rep); 7904 TraceRepresentation(expr->op(), info, instr, rep);
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
8064 HValue* value = typeof_expr->value(); 8082 HValue* value = typeof_expr->value();
8065 HTypeofIsAndBranch* instr = new(zone()) HTypeofIsAndBranch(value, check); 8083 HTypeofIsAndBranch* instr = new(zone()) HTypeofIsAndBranch(value, check);
8066 instr->set_position(expr->position()); 8084 instr->set_position(expr->position());
8067 return ast_context()->ReturnControl(instr, expr->id()); 8085 return ast_context()->ReturnControl(instr, expr->id());
8068 } 8086 }
8069 8087
8070 8088
8071 static bool MatchLiteralCompareNil(HValue* left, 8089 static bool MatchLiteralCompareNil(HValue* left,
8072 Token::Value op, 8090 Token::Value op,
8073 HValue* right, 8091 HValue* right,
8074 Handle<Object> nil, 8092 HConstant* nil,
Michael Starzinger 2012/07/10 12:05:51 I don't think any of the changes in this file from
8075 HValue** expr) { 8093 HValue** expr) {
8094 ASSERT(nil->IsTagged());
8076 if (left->IsConstant() && 8095 if (left->IsConstant() &&
8077 HConstant::cast(left)->handle().is_identical_to(nil) && 8096 HConstant::cast(left)->IsTagged() &&
8097 HConstant::cast(left)->handle().is_identical_to(nil->handle()) &&
8078 Token::IsEqualityOp(op)) { 8098 Token::IsEqualityOp(op)) {
8079 *expr = right; 8099 *expr = right;
8080 return true; 8100 return true;
8081 } 8101 }
8082 return false; 8102 return false;
8083 } 8103 }
8084 8104
8085 8105
8086 static bool MatchLiteralCompareTypeof(HValue* left, 8106 static bool MatchLiteralCompareTypeof(HValue* left,
8087 Token::Value op, 8107 Token::Value op,
8088 HValue* right, 8108 HValue* right,
8089 HTypeof** typeof_expr, 8109 HTypeof** typeof_expr,
8090 Handle<String>* check) { 8110 Handle<String>* check) {
8091 if (left->IsTypeof() && 8111 if (left->IsTypeof() &&
8092 Token::IsEqualityOp(op) && 8112 Token::IsEqualityOp(op) &&
8093 right->IsConstant() && 8113 right->IsConstant() &&
8094 HConstant::cast(right)->HasStringValue()) { 8114 HConstant::cast(right)->handle()->IsString()) {
8095 *typeof_expr = HTypeof::cast(left); 8115 *typeof_expr = HTypeof::cast(left);
8096 *check = Handle<String>::cast(HConstant::cast(right)->handle()); 8116 *check = Handle<String>::cast(HConstant::cast(right)->handle());
8097 return true; 8117 return true;
8098 } 8118 }
8099 return false; 8119 return false;
8100 } 8120 }
8101 8121
8102 8122
8103 static bool IsLiteralCompareTypeof(HValue* left, 8123 static bool IsLiteralCompareTypeof(HValue* left,
8104 Token::Value op, 8124 Token::Value op,
8105 HValue* right, 8125 HValue* right,
8106 HTypeof** typeof_expr, 8126 HTypeof** typeof_expr,
8107 Handle<String>* check) { 8127 Handle<String>* check) {
8108 return MatchLiteralCompareTypeof(left, op, right, typeof_expr, check) || 8128 return MatchLiteralCompareTypeof(left, op, right, typeof_expr, check) ||
8109 MatchLiteralCompareTypeof(right, op, left, typeof_expr, check); 8129 MatchLiteralCompareTypeof(right, op, left, typeof_expr, check);
8110 } 8130 }
8111 8131
8112 8132
8113 static bool IsLiteralCompareNil(HValue* left, 8133 static bool IsLiteralCompareNil(HValue* left,
8114 Token::Value op, 8134 Token::Value op,
8115 HValue* right, 8135 HValue* right,
8116 Handle<Object> nil, 8136 HConstant* nil,
8117 HValue** expr) { 8137 HValue** expr) {
8118 return MatchLiteralCompareNil(left, op, right, nil, expr) || 8138 return MatchLiteralCompareNil(left, op, right, nil, expr) ||
8119 MatchLiteralCompareNil(right, op, left, nil, expr); 8139 MatchLiteralCompareNil(right, op, left, nil, expr);
8120 } 8140 }
8121 8141
8122 8142
8123 static bool IsLiteralCompareBool(HValue* left, 8143 static bool IsLiteralCompareBool(HValue* left,
8124 Token::Value op, 8144 Token::Value op,
8125 HValue* right) { 8145 HValue* right) {
8126 return op == Token::EQ_STRICT && 8146 return op == Token::EQ_STRICT &&
8127 ((left->IsConstant() && HConstant::cast(left)->handle()->IsBoolean()) || 8147 ((left->IsConstant() &&
8128 (right->IsConstant() && HConstant::cast(right)->handle()->IsBoolean())); 8148 HConstant::cast(left)->handle()->IsBoolean()) ||
8149 (right->IsConstant() &&
8150 HConstant::cast(right)->handle()->IsBoolean()));
8129 } 8151 }
8130 8152
8131 8153
8132 void HGraphBuilder::VisitCompareOperation(CompareOperation* expr) { 8154 void HGraphBuilder::VisitCompareOperation(CompareOperation* expr) {
8133 ASSERT(!HasStackOverflow()); 8155 ASSERT(!HasStackOverflow());
8134 ASSERT(current_block() != NULL); 8156 ASSERT(current_block() != NULL);
8135 ASSERT(current_block()->HasPredecessor()); 8157 ASSERT(current_block()->HasPredecessor());
8136 if (IsClassOfTest(expr)) { 8158 if (IsClassOfTest(expr)) {
8137 CallRuntime* call = expr->left()->AsCallRuntime(); 8159 CallRuntime* call = expr->left()->AsCallRuntime();
8138 ASSERT(call->arguments()->length() == 1); 8160 ASSERT(call->arguments()->length() == 1);
(...skipping 23 matching lines...) Expand all
8162 HValue* right = Pop(); 8184 HValue* right = Pop();
8163 HValue* left = Pop(); 8185 HValue* left = Pop();
8164 Token::Value op = expr->op(); 8186 Token::Value op = expr->op();
8165 8187
8166 HTypeof* typeof_expr = NULL; 8188 HTypeof* typeof_expr = NULL;
8167 Handle<String> check; 8189 Handle<String> check;
8168 if (IsLiteralCompareTypeof(left, op, right, &typeof_expr, &check)) { 8190 if (IsLiteralCompareTypeof(left, op, right, &typeof_expr, &check)) {
8169 return HandleLiteralCompareTypeof(expr, typeof_expr, check); 8191 return HandleLiteralCompareTypeof(expr, typeof_expr, check);
8170 } 8192 }
8171 HValue* sub_expr = NULL; 8193 HValue* sub_expr = NULL;
8172 Factory* f = graph()->isolate()->factory(); 8194 if (IsLiteralCompareNil(left, op, right, constant_undefined_, &sub_expr)) {
8173 if (IsLiteralCompareNil(left, op, right, f->undefined_value(), &sub_expr)) {
8174 return HandleLiteralCompareNil(expr, sub_expr, kUndefinedValue); 8195 return HandleLiteralCompareNil(expr, sub_expr, kUndefinedValue);
8175 } 8196 }
8176 if (IsLiteralCompareNil(left, op, right, f->null_value(), &sub_expr)) { 8197 if (IsLiteralCompareNil(left, op, right, constant_null_, &sub_expr)) {
8177 return HandleLiteralCompareNil(expr, sub_expr, kNullValue); 8198 return HandleLiteralCompareNil(expr, sub_expr, kNullValue);
8178 } 8199 }
8179 if (IsLiteralCompareBool(left, op, right)) { 8200 if (IsLiteralCompareBool(left, op, right)) {
8180 HCompareObjectEqAndBranch* result = 8201 HCompareObjectEqAndBranch* result =
8181 new(zone()) HCompareObjectEqAndBranch(left, right); 8202 new(zone()) HCompareObjectEqAndBranch(left, right);
8182 result->set_position(expr->position()); 8203 result->set_position(expr->position());
8183 return ast_context()->ReturnControl(result, expr->id()); 8204 return ast_context()->ReturnControl(result, expr->id());
8184 } 8205 }
8185 8206
8186 if (op == Token::INSTANCEOF) { 8207 if (op == Token::INSTANCEOF) {
(...skipping 1332 matching lines...) Expand 10 before | Expand all | Expand 10 after
9519 } 9540 }
9520 } 9541 }
9521 9542
9522 #ifdef DEBUG 9543 #ifdef DEBUG
9523 if (graph_ != NULL) graph_->Verify(false); // No full verify. 9544 if (graph_ != NULL) graph_->Verify(false); // No full verify.
9524 if (allocator_ != NULL) allocator_->Verify(); 9545 if (allocator_ != NULL) allocator_->Verify();
9525 #endif 9546 #endif
9526 } 9547 }
9527 9548
9528 } } // namespace v8::internal 9549 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698