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

Side by Side Diff: src/hydrogen.cc

Issue 19582002: Synchronize Compare-Literal behavior in FullCodegen and Hydrogen (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 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
« no previous file with comments | « src/hydrogen.h ('k') | test/mjsunit/regress/regress-crbug-260345.js » ('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 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 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 8114 matching lines...) Expand 10 before | Expand all | Expand 10 after
8125 CHECK_ALIVE(VisitForValue(expr->right())); 8125 CHECK_ALIVE(VisitForValue(expr->right()));
8126 HValue* right = Pop(); 8126 HValue* right = Pop();
8127 HValue* left = Pop(); 8127 HValue* left = Pop();
8128 HInstruction* instr = BuildBinaryOperation(expr, left, right); 8128 HInstruction* instr = BuildBinaryOperation(expr, left, right);
8129 instr->set_position(expr->position()); 8129 instr->set_position(expr->position());
8130 return ast_context()->ReturnInstruction(instr, expr->id()); 8130 return ast_context()->ReturnInstruction(instr, expr->id());
8131 } 8131 }
8132 8132
8133 8133
8134 void HOptimizedGraphBuilder::HandleLiteralCompareTypeof(CompareOperation* expr, 8134 void HOptimizedGraphBuilder::HandleLiteralCompareTypeof(CompareOperation* expr,
8135 HTypeof* typeof_expr, 8135 Expression* sub_expr,
8136 Handle<String> check) { 8136 Handle<String> check) {
8137 // Note: The HTypeof itself is removed during canonicalization, if possible. 8137 CHECK_ALIVE(VisitForValue(sub_expr));
8138 HValue* value = typeof_expr->value(); 8138 HValue* value = Pop();
8139 HTypeofIsAndBranch* instr = new(zone()) HTypeofIsAndBranch(value, check); 8139 HTypeofIsAndBranch* instr = new(zone()) HTypeofIsAndBranch(value, check);
8140 instr->set_position(expr->position()); 8140 instr->set_position(expr->position());
8141 return ast_context()->ReturnControl(instr, expr->id()); 8141 return ast_context()->ReturnControl(instr, expr->id());
8142 } 8142 }
8143 8143
8144 8144
8145 static bool MatchLiteralCompareNil(HValue* left,
8146 Token::Value op,
8147 HValue* right,
8148 Handle<Object> nil,
8149 HValue** expr) {
8150 if (left->IsConstant() &&
8151 HConstant::cast(left)->handle().is_identical_to(nil) &&
8152 Token::IsEqualityOp(op)) {
8153 *expr = right;
8154 return true;
8155 }
8156 return false;
8157 }
8158
8159
8160 static bool MatchLiteralCompareTypeof(HValue* left,
8161 Token::Value op,
8162 HValue* right,
8163 HTypeof** typeof_expr,
8164 Handle<String>* check) {
8165 if (left->IsTypeof() &&
8166 Token::IsEqualityOp(op) &&
8167 right->IsConstant() &&
8168 HConstant::cast(right)->handle()->IsString()) {
8169 *typeof_expr = HTypeof::cast(left);
8170 *check = Handle<String>::cast(HConstant::cast(right)->handle());
8171 return true;
8172 }
8173 return false;
8174 }
8175
8176
8177 static bool IsLiteralCompareTypeof(HValue* left,
8178 Token::Value op,
8179 HValue* right,
8180 HTypeof** typeof_expr,
8181 Handle<String>* check) {
8182 return MatchLiteralCompareTypeof(left, op, right, typeof_expr, check) ||
8183 MatchLiteralCompareTypeof(right, op, left, typeof_expr, check);
8184 }
8185
8186
8187 static bool IsLiteralCompareNil(HValue* left,
8188 Token::Value op,
8189 HValue* right,
8190 Handle<Object> nil,
8191 HValue** expr) {
8192 return MatchLiteralCompareNil(left, op, right, nil, expr) ||
8193 MatchLiteralCompareNil(right, op, left, nil, expr);
8194 }
8195
8196
8197 static bool IsLiteralCompareBool(HValue* left, 8145 static bool IsLiteralCompareBool(HValue* left,
8198 Token::Value op, 8146 Token::Value op,
8199 HValue* right) { 8147 HValue* right) {
8200 return op == Token::EQ_STRICT && 8148 return op == Token::EQ_STRICT &&
8201 ((left->IsConstant() && HConstant::cast(left)->handle()->IsBoolean()) || 8149 ((left->IsConstant() && HConstant::cast(left)->handle()->IsBoolean()) ||
8202 (right->IsConstant() && HConstant::cast(right)->handle()->IsBoolean())); 8150 (right->IsConstant() && HConstant::cast(right)->handle()->IsBoolean()));
8203 } 8151 }
8204 8152
8205 8153
8206 void HOptimizedGraphBuilder::VisitCompareOperation(CompareOperation* expr) { 8154 void HOptimizedGraphBuilder::VisitCompareOperation(CompareOperation* expr) {
8207 ASSERT(!HasStackOverflow()); 8155 ASSERT(!HasStackOverflow());
8208 ASSERT(current_block() != NULL); 8156 ASSERT(current_block() != NULL);
8209 ASSERT(current_block()->HasPredecessor()); 8157 ASSERT(current_block()->HasPredecessor());
8158
8159 // Check for a few fast cases. The AST visiting behavior must be in sync
8160 // with the full codegen: We don't push both left and right values onto
8161 // the expression stack when one side is a special-case literal.
8162 Expression* sub_expr = NULL;
8163 Handle<String> check;
8164 if (expr->IsLiteralCompareTypeof(&sub_expr, &check)) {
8165 return HandleLiteralCompareTypeof(expr, sub_expr, check);
8166 }
8167 if (expr->IsLiteralCompareUndefined(&sub_expr)) {
8168 return HandleLiteralCompareNil(expr, sub_expr, kUndefinedValue);
8169 }
8170 if (expr->IsLiteralCompareNull(&sub_expr)) {
8171 return HandleLiteralCompareNil(expr, sub_expr, kNullValue);
8172 }
8173
8210 if (IsClassOfTest(expr)) { 8174 if (IsClassOfTest(expr)) {
8211 CallRuntime* call = expr->left()->AsCallRuntime(); 8175 CallRuntime* call = expr->left()->AsCallRuntime();
8212 ASSERT(call->arguments()->length() == 1); 8176 ASSERT(call->arguments()->length() == 1);
8213 CHECK_ALIVE(VisitForValue(call->arguments()->at(0))); 8177 CHECK_ALIVE(VisitForValue(call->arguments()->at(0)));
8214 HValue* value = Pop(); 8178 HValue* value = Pop();
8215 Literal* literal = expr->right()->AsLiteral(); 8179 Literal* literal = expr->right()->AsLiteral();
8216 Handle<String> rhs = Handle<String>::cast(literal->value()); 8180 Handle<String> rhs = Handle<String>::cast(literal->value());
8217 HClassOfTestAndBranch* instr = 8181 HClassOfTestAndBranch* instr =
8218 new(zone()) HClassOfTestAndBranch(value, rhs); 8182 new(zone()) HClassOfTestAndBranch(value, rhs);
8219 instr->set_position(expr->position()); 8183 instr->set_position(expr->position());
8220 return ast_context()->ReturnControl(instr, expr->id()); 8184 return ast_context()->ReturnControl(instr, expr->id());
8221 } 8185 }
8222 8186
8223 Handle<Type> left_type = expr->left()->bounds().lower; 8187 Handle<Type> left_type = expr->left()->bounds().lower;
8224 Handle<Type> right_type = expr->right()->bounds().lower; 8188 Handle<Type> right_type = expr->right()->bounds().lower;
8225 Handle<Type> combined_type = expr->combined_type(); 8189 Handle<Type> combined_type = expr->combined_type();
8226 Representation combined_rep = Representation::FromType(combined_type); 8190 Representation combined_rep = Representation::FromType(combined_type);
8227 Representation left_rep = Representation::FromType(left_type); 8191 Representation left_rep = Representation::FromType(left_type);
8228 Representation right_rep = Representation::FromType(right_type); 8192 Representation right_rep = Representation::FromType(right_type);
8229 8193
8230 CHECK_ALIVE(VisitForValue(expr->left())); 8194 CHECK_ALIVE(VisitForValue(expr->left()));
8231 CHECK_ALIVE(VisitForValue(expr->right())); 8195 CHECK_ALIVE(VisitForValue(expr->right()));
8232 8196
8233 HValue* context = environment()->LookupContext(); 8197 HValue* context = environment()->LookupContext();
8234 HValue* right = Pop(); 8198 HValue* right = Pop();
8235 HValue* left = Pop(); 8199 HValue* left = Pop();
8236 Token::Value op = expr->op(); 8200 Token::Value op = expr->op();
8237 8201
8238 HTypeof* typeof_expr = NULL;
8239 Handle<String> check;
8240 if (IsLiteralCompareTypeof(left, op, right, &typeof_expr, &check)) {
8241 return HandleLiteralCompareTypeof(expr, typeof_expr, check);
8242 }
8243 HValue* sub_expr = NULL;
8244 Factory* f = isolate()->factory();
8245 if (IsLiteralCompareNil(left, op, right, f->undefined_value(), &sub_expr)) {
8246 return HandleLiteralCompareNil(expr, sub_expr, kUndefinedValue);
8247 }
8248 if (IsLiteralCompareNil(left, op, right, f->null_value(), &sub_expr)) {
8249 return HandleLiteralCompareNil(expr, sub_expr, kNullValue);
8250 }
8251 if (IsLiteralCompareBool(left, op, right)) { 8202 if (IsLiteralCompareBool(left, op, right)) {
8252 HCompareObjectEqAndBranch* result = 8203 HCompareObjectEqAndBranch* result =
8253 new(zone()) HCompareObjectEqAndBranch(left, right); 8204 new(zone()) HCompareObjectEqAndBranch(left, right);
8254 result->set_position(expr->position()); 8205 result->set_position(expr->position());
8255 return ast_context()->ReturnControl(result, expr->id()); 8206 return ast_context()->ReturnControl(result, expr->id());
8256 } 8207 }
8257 8208
8258 if (op == Token::INSTANCEOF) { 8209 if (op == Token::INSTANCEOF) {
8259 // Check to see if the rhs of the instanceof is a global function not 8210 // Check to see if the rhs of the instanceof is a global function not
8260 // residing in new space. If it is we assume that the function will stay the 8211 // residing in new space. If it is we assume that the function will stay the
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
8367 new(zone()) HCompareNumericAndBranch(left, right, op); 8318 new(zone()) HCompareNumericAndBranch(left, right, op);
8368 result->set_observed_input_representation(left_rep, right_rep); 8319 result->set_observed_input_representation(left_rep, right_rep);
8369 result->set_position(expr->position()); 8320 result->set_position(expr->position());
8370 return ast_context()->ReturnControl(result, expr->id()); 8321 return ast_context()->ReturnControl(result, expr->id());
8371 } 8322 }
8372 } 8323 }
8373 } 8324 }
8374 8325
8375 8326
8376 void HOptimizedGraphBuilder::HandleLiteralCompareNil(CompareOperation* expr, 8327 void HOptimizedGraphBuilder::HandleLiteralCompareNil(CompareOperation* expr,
8377 HValue* value, 8328 Expression* sub_expr,
8378 NilValue nil) { 8329 NilValue nil) {
8379 ASSERT(!HasStackOverflow()); 8330 ASSERT(!HasStackOverflow());
8380 ASSERT(current_block() != NULL); 8331 ASSERT(current_block() != NULL);
8381 ASSERT(current_block()->HasPredecessor()); 8332 ASSERT(current_block()->HasPredecessor());
8382 ASSERT(expr->op() == Token::EQ || expr->op() == Token::EQ_STRICT); 8333 ASSERT(expr->op() == Token::EQ || expr->op() == Token::EQ_STRICT);
8334 CHECK_ALIVE(VisitForValue(sub_expr));
8335 HValue* value = Pop();
8383 HIfContinuation continuation; 8336 HIfContinuation continuation;
8384 if (expr->op() == Token::EQ_STRICT) { 8337 if (expr->op() == Token::EQ_STRICT) {
8385 IfBuilder if_nil(this); 8338 IfBuilder if_nil(this);
8386 if_nil.If<HCompareObjectEqAndBranch>( 8339 if_nil.If<HCompareObjectEqAndBranch>(
8387 value, (nil == kNullValue) ? graph()->GetConstantNull() 8340 value, (nil == kNullValue) ? graph()->GetConstantNull()
8388 : graph()->GetConstantUndefined()); 8341 : graph()->GetConstantUndefined());
8389 if_nil.Then(); 8342 if_nil.Then();
8390 if_nil.Else(); 8343 if_nil.Else();
8391 if_nil.CaptureContinuation(&continuation); 8344 if_nil.CaptureContinuation(&continuation);
8392 return ast_context()->ReturnContinuation(&continuation, expr->id()); 8345 return ast_context()->ReturnContinuation(&continuation, expr->id());
(...skipping 1643 matching lines...) Expand 10 before | Expand all | Expand 10 after
10036 if (ShouldProduceTraceOutput()) { 9989 if (ShouldProduceTraceOutput()) {
10037 isolate()->GetHTracer()->TraceHydrogen(name(), graph_); 9990 isolate()->GetHTracer()->TraceHydrogen(name(), graph_);
10038 } 9991 }
10039 9992
10040 #ifdef DEBUG 9993 #ifdef DEBUG
10041 graph_->Verify(false); // No full verify. 9994 graph_->Verify(false); // No full verify.
10042 #endif 9995 #endif
10043 } 9996 }
10044 9997
10045 } } // namespace v8::internal 9998 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/hydrogen.h ('k') | test/mjsunit/regress/regress-crbug-260345.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698