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

Side by Side Diff: src/ia32/full-codegen-ia32.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 3912 matching lines...) Expand 10 before | Expand all | Expand 10 after
3923 __ bind(&done); 3923 __ bind(&done);
3924 3924
3925 context()->Plug(eax); 3925 context()->Plug(eax);
3926 } else { 3926 } else {
3927 // This expression cannot throw a reference error at the top level. 3927 // This expression cannot throw a reference error at the top level.
3928 VisitInCurrentContext(expr); 3928 VisitInCurrentContext(expr);
3929 } 3929 }
3930 } 3930 }
3931 3931
3932 3932
3933 bool FullCodeGenerator::TryLiteralCompare(Token::Value op, 3933 void FullCodeGenerator::EmitLiteralCompareTypeof(Expression* expr,
3934 Expression* left, 3934 Handle<String> check,
3935 Expression* right, 3935 Label* if_true,
3936 Label* if_true, 3936 Label* if_false,
3937 Label* if_false, 3937 Label* fall_through) {
3938 Label* fall_through) {
3939 if (op != Token::EQ && op != Token::EQ_STRICT) return false;
3940
3941 // Check for the pattern: typeof <expression> == <string literal>.
3942 Literal* right_literal = right->AsLiteral();
3943 if (right_literal == NULL) return false;
3944 Handle<Object> right_literal_value = right_literal->handle();
3945 if (!right_literal_value->IsString()) return false;
3946 UnaryOperation* left_unary = left->AsUnaryOperation();
3947 if (left_unary == NULL || left_unary->op() != Token::TYPEOF) return false;
3948 Handle<String> check = Handle<String>::cast(right_literal_value);
3949
3950 { AccumulatorValueContext context(this); 3938 { AccumulatorValueContext context(this);
3951 VisitForTypeofValue(left_unary->expression()); 3939 VisitForTypeofValue(expr);
3952 } 3940 }
3953 PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false); 3941 PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false);
3954 3942
3955 if (check->Equals(isolate()->heap()->number_symbol())) { 3943 if (check->Equals(isolate()->heap()->number_symbol())) {
3956 __ JumpIfSmi(eax, if_true); 3944 __ JumpIfSmi(eax, if_true);
3957 __ cmp(FieldOperand(eax, HeapObject::kMapOffset), 3945 __ cmp(FieldOperand(eax, HeapObject::kMapOffset),
3958 isolate()->factory()->heap_number_map()); 3946 isolate()->factory()->heap_number_map());
3959 Split(equal, if_true, if_false, fall_through); 3947 Split(equal, if_true, if_false, fall_through);
3960 } else if (check->Equals(isolate()->heap()->string_symbol())) { 3948 } else if (check->Equals(isolate()->heap()->string_symbol())) {
3961 __ JumpIfSmi(eax, if_false); 3949 __ JumpIfSmi(eax, if_false);
(...skipping 29 matching lines...) Expand all
3991 __ j(below, if_false); 3979 __ j(below, if_false);
3992 __ CmpInstanceType(edx, LAST_NONCALLABLE_SPEC_OBJECT_TYPE); 3980 __ CmpInstanceType(edx, LAST_NONCALLABLE_SPEC_OBJECT_TYPE);
3993 __ j(above, if_false); 3981 __ j(above, if_false);
3994 // Check for undetectable objects => false. 3982 // Check for undetectable objects => false.
3995 __ test_b(FieldOperand(edx, Map::kBitFieldOffset), 3983 __ test_b(FieldOperand(edx, Map::kBitFieldOffset),
3996 1 << Map::kIsUndetectable); 3984 1 << Map::kIsUndetectable);
3997 Split(zero, if_true, if_false, fall_through); 3985 Split(zero, if_true, if_false, fall_through);
3998 } else { 3986 } else {
3999 if (if_false != fall_through) __ jmp(if_false); 3987 if (if_false != fall_through) __ jmp(if_false);
4000 } 3988 }
4001
4002 return true;
4003 } 3989 }
4004 3990
4005 3991
3992 void FullCodeGenerator::EmitLiteralCompareUndefined(Expression* expr,
3993 Label* if_true,
3994 Label* if_false,
3995 Label* fall_through) {
3996 VisitForAccumulatorValue(expr);
3997 PrepareForBailoutBeforeSplit(TOS_REG, true, if_true, if_false);
3998
3999 __ cmp(eax, isolate()->factory()->undefined_value());
4000 Split(equal, if_true, if_false, fall_through);
4001 }
4002
4003
4006 void FullCodeGenerator::VisitCompareOperation(CompareOperation* expr) { 4004 void FullCodeGenerator::VisitCompareOperation(CompareOperation* expr) {
4007 Comment cmnt(masm_, "[ CompareOperation"); 4005 Comment cmnt(masm_, "[ CompareOperation");
4008 SetSourcePosition(expr->position()); 4006 SetSourcePosition(expr->position());
4009 4007
4010 // Always perform the comparison for its control flow. Pack the result 4008 // Always perform the comparison for its control flow. Pack the result
4011 // into the expression's context after the comparison is performed. 4009 // into the expression's context after the comparison is performed.
4012 4010
4013 Label materialize_true, materialize_false; 4011 Label materialize_true, materialize_false;
4014 Label* if_true = NULL; 4012 Label* if_true = NULL;
4015 Label* if_false = NULL; 4013 Label* if_false = NULL;
4016 Label* fall_through = NULL; 4014 Label* fall_through = NULL;
4017 context()->PrepareTest(&materialize_true, &materialize_false, 4015 context()->PrepareTest(&materialize_true, &materialize_false,
4018 &if_true, &if_false, &fall_through); 4016 &if_true, &if_false, &fall_through);
4019 4017
4020 // First we try a fast inlined version of the compare when one of 4018 // First we try a fast inlined version of the compare when one of
4021 // the operands is a literal. 4019 // the operands is a literal.
4022 Token::Value op = expr->op(); 4020 if (TryLiteralCompare(expr, if_true, if_false, fall_through)) {
4023 Expression* left = expr->left();
4024 Expression* right = expr->right();
4025 if (TryLiteralCompare(op, left, right, if_true, if_false, fall_through)) {
4026 context()->Plug(if_true, if_false); 4021 context()->Plug(if_true, if_false);
4027 return; 4022 return;
4028 } 4023 }
4029 4024
4025 Token::Value op = expr->op();
4030 VisitForStackValue(expr->left()); 4026 VisitForStackValue(expr->left());
4031 switch (expr->op()) { 4027 switch (expr->op()) {
4032 case Token::IN: 4028 case Token::IN:
4033 VisitForStackValue(expr->right()); 4029 VisitForStackValue(expr->right());
4034 __ InvokeBuiltin(Builtins::IN, CALL_FUNCTION); 4030 __ InvokeBuiltin(Builtins::IN, CALL_FUNCTION);
4035 PrepareForBailoutBeforeSplit(TOS_REG, false, NULL, NULL); 4031 PrepareForBailoutBeforeSplit(TOS_REG, false, NULL, NULL);
4036 __ cmp(eax, isolate()->factory()->true_value()); 4032 __ cmp(eax, isolate()->factory()->true_value());
4037 Split(equal, if_true, if_false, fall_through); 4033 Split(equal, if_true, if_false, fall_through);
4038 break; 4034 break;
4039 4035
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
4252 // And return. 4248 // And return.
4253 __ ret(0); 4249 __ ret(0);
4254 } 4250 }
4255 4251
4256 4252
4257 #undef __ 4253 #undef __
4258 4254
4259 } } // namespace v8::internal 4255 } } // namespace v8::internal
4260 4256
4261 #endif // V8_TARGET_ARCH_IA32 4257 #endif // V8_TARGET_ARCH_IA32
OLDNEW
« src/ast.cc ('K') | « src/hydrogen.cc ('k') | src/x64/full-codegen-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698