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

Side by Side Diff: src/x64/full-codegen-x64.cc

Issue 7216008: Better codegen for '<expression> === void <literal>'. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Applied your comments. Created 9 years, 6 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
(...skipping 3889 matching lines...) Expand 10 before | Expand all | Expand 10 after
3900 __ bind(&done); 3900 __ bind(&done);
3901 3901
3902 context()->Plug(rax); 3902 context()->Plug(rax);
3903 } else { 3903 } else {
3904 // This expression cannot throw a reference error at the top level. 3904 // This expression cannot throw a reference error at the top level.
3905 VisitInCurrentContext(expr); 3905 VisitInCurrentContext(expr);
3906 } 3906 }
3907 } 3907 }
3908 3908
3909 3909
3910 bool FullCodeGenerator::TryLiteralCompare(Token::Value op, 3910 void FullCodeGenerator::EmitLiteralCompareTypeof(Expression* expr,
3911 Expression* left, 3911 Handle<String> check,
3912 Expression* right, 3912 Label* if_true,
3913 Label* if_true, 3913 Label* if_false,
3914 Label* if_false, 3914 Label* fall_through) {
3915 Label* fall_through) {
3916 if (op != Token::EQ && op != Token::EQ_STRICT) return false;
3917
3918 // Check for the pattern: typeof <expression> == <string literal>.
3919 Literal* right_literal = right->AsLiteral();
3920 if (right_literal == NULL) return false;
3921 Handle<Object> right_literal_value = right_literal->handle();
3922 if (!right_literal_value->IsString()) return false;
3923 UnaryOperation* left_unary = left->AsUnaryOperation();
3924 if (left_unary == NULL || left_unary->op() != Token::TYPEOF) return false;
3925 Handle<String> check = Handle<String>::cast(right_literal_value);
3926
3927 { AccumulatorValueContext context(this); 3915 { AccumulatorValueContext context(this);
3928 VisitForTypeofValue(left_unary->expression()); 3916 VisitForTypeofValue(expr);
3929 } 3917 }
3930 PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); 3918 PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false);
3931 3919
3932 if (check->Equals(isolate()->heap()->number_symbol())) { 3920 if (check->Equals(isolate()->heap()->number_symbol())) {
3933 __ JumpIfSmi(rax, if_true); 3921 __ JumpIfSmi(rax, if_true);
3934 __ movq(rax, FieldOperand(rax, HeapObject::kMapOffset)); 3922 __ movq(rax, FieldOperand(rax, HeapObject::kMapOffset));
3935 __ CompareRoot(rax, Heap::kHeapNumberMapRootIndex); 3923 __ CompareRoot(rax, Heap::kHeapNumberMapRootIndex);
3936 Split(equal, if_true, if_false, fall_through); 3924 Split(equal, if_true, if_false, fall_through);
3937 } else if (check->Equals(isolate()->heap()->string_symbol())) { 3925 } else if (check->Equals(isolate()->heap()->string_symbol())) {
3938 __ JumpIfSmi(rax, if_false); 3926 __ JumpIfSmi(rax, if_false);
(...skipping 30 matching lines...) Expand all
3969 __ j(below, if_false); 3957 __ j(below, if_false);
3970 __ CmpInstanceType(rdx, LAST_NONCALLABLE_SPEC_OBJECT_TYPE); 3958 __ CmpInstanceType(rdx, LAST_NONCALLABLE_SPEC_OBJECT_TYPE);
3971 __ j(above, if_false); 3959 __ j(above, if_false);
3972 // Check for undetectable objects => false. 3960 // Check for undetectable objects => false.
3973 __ testb(FieldOperand(rdx, Map::kBitFieldOffset), 3961 __ testb(FieldOperand(rdx, Map::kBitFieldOffset),
3974 Immediate(1 << Map::kIsUndetectable)); 3962 Immediate(1 << Map::kIsUndetectable));
3975 Split(zero, if_true, if_false, fall_through); 3963 Split(zero, if_true, if_false, fall_through);
3976 } else { 3964 } else {
3977 if (if_false != fall_through) __ jmp(if_false); 3965 if (if_false != fall_through) __ jmp(if_false);
3978 } 3966 }
3979
3980 return true;
3981 } 3967 }
3982 3968
3983 3969
3970 void FullCodeGenerator::EmitLiteralCompareUndefined(Expression* expr,
3971 Label* if_true,
3972 Label* if_false,
3973 Label* fall_through) {
3974 VisitForAccumulatorValue(expr);
3975 PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false);
3976
3977 __ CompareRoot(rax, Heap::kUndefinedValueRootIndex);
3978 Split(equal, if_true, if_false, fall_through);
3979 }
3980
3981
3984 void FullCodeGenerator::VisitCompareOperation(CompareOperation* expr) { 3982 void FullCodeGenerator::VisitCompareOperation(CompareOperation* expr) {
3985 Comment cmnt(masm_, "[ CompareOperation"); 3983 Comment cmnt(masm_, "[ CompareOperation");
3986 SetSourcePosition(expr->position()); 3984 SetSourcePosition(expr->position());
3987 3985
3988 // Always perform the comparison for its control flow. Pack the result 3986 // Always perform the comparison for its control flow. Pack the result
3989 // into the expression's context after the comparison is performed. 3987 // into the expression's context after the comparison is performed.
3990 Label materialize_true, materialize_false; 3988 Label materialize_true, materialize_false;
3991 Label* if_true = NULL; 3989 Label* if_true = NULL;
3992 Label* if_false = NULL; 3990 Label* if_false = NULL;
3993 Label* fall_through = NULL; 3991 Label* fall_through = NULL;
3994 context()->PrepareTest(&materialize_true, &materialize_false, 3992 context()->PrepareTest(&materialize_true, &materialize_false,
3995 &if_true, &if_false, &fall_through); 3993 &if_true, &if_false, &fall_through);
3996 3994
3997 // First we try a fast inlined version of the compare when one of 3995 // First we try a fast inlined version of the compare when one of
3998 // the operands is a literal. 3996 // the operands is a literal.
3999 Token::Value op = expr->op(); 3997 if (TryLiteralCompare(expr, if_true, if_false, fall_through)) {
4000 Expression* left = expr->left();
4001 Expression* right = expr->right();
4002 if (TryLiteralCompare(op, left, right, if_true, if_false, fall_through)) {
4003 context()->Plug(if_true, if_false); 3998 context()->Plug(if_true, if_false);
4004 return; 3999 return;
4005 } 4000 }
4006 4001
4002 Token::Value op = expr->op();
4007 VisitForStackValue(expr->left()); 4003 VisitForStackValue(expr->left());
4008 switch (op) { 4004 switch (op) {
4009 case Token::IN: 4005 case Token::IN:
4010 VisitForStackValue(expr->right()); 4006 VisitForStackValue(expr->right());
4011 __ InvokeBuiltin(Builtins::IN, CALL_FUNCTION); 4007 __ InvokeBuiltin(Builtins::IN, CALL_FUNCTION);
4012 PrepareForBailoutBeforeSplit(TOS_REG, false, NULL, NULL); 4008 PrepareForBailoutBeforeSplit(TOS_REG, false, NULL, NULL);
4013 __ CompareRoot(rax, Heap::kTrueValueRootIndex); 4009 __ CompareRoot(rax, Heap::kTrueValueRootIndex);
4014 Split(equal, if_true, if_false, fall_through); 4010 Split(equal, if_true, if_false, fall_through);
4015 break; 4011 break;
4016 4012
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
4234 __ ret(0); 4230 __ ret(0);
4235 } 4231 }
4236 4232
4237 4233
4238 #undef __ 4234 #undef __
4239 4235
4240 4236
4241 } } // namespace v8::internal 4237 } } // namespace v8::internal
4242 4238
4243 #endif // V8_TARGET_ARCH_X64 4239 #endif // V8_TARGET_ARCH_X64
OLDNEW
« src/ast.cc ('K') | « src/ia32/full-codegen-ia32.cc ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698