Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 10023 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10034 Representation HOptimizedGraphBuilder::ToRepresentation(TypeInfo info) { | 10034 Representation HOptimizedGraphBuilder::ToRepresentation(TypeInfo info) { |
| 10035 if (info.IsUninitialized()) return Representation::None(); | 10035 if (info.IsUninitialized()) return Representation::None(); |
| 10036 if (info.IsSmi()) return Representation::Integer32(); | 10036 if (info.IsSmi()) return Representation::Integer32(); |
| 10037 if (info.IsInteger32()) return Representation::Integer32(); | 10037 if (info.IsInteger32()) return Representation::Integer32(); |
| 10038 if (info.IsDouble()) return Representation::Double(); | 10038 if (info.IsDouble()) return Representation::Double(); |
| 10039 if (info.IsNumber()) return Representation::Double(); | 10039 if (info.IsNumber()) return Representation::Double(); |
| 10040 return Representation::Tagged(); | 10040 return Representation::Tagged(); |
| 10041 } | 10041 } |
| 10042 | 10042 |
| 10043 | 10043 |
| 10044 void HOptimizedGraphBuilder::HandleTripleShiftZeroCompare( | |
| 10045 CompareOperation* expr, | |
| 10046 HValue* input) { | |
| 10047 // (i >>> 0) === i is transformed to i >= 0. | |
| 10048 // (i >>> 0) !== i is transformed to i < 0. | |
| 10049 Token::Value op = (expr->op() == Token::EQ_STRICT) ? Token::GTE : Token::LT; | |
| 10050 HCompareIDAndBranch* compare = | |
| 10051 new(zone()) HCompareIDAndBranch(input, graph()->GetConstant0(), op); | |
| 10052 compare->set_observed_input_representation(Representation::Integer32(), | |
|
Jakob Kummerow
2013/04/23 11:09:23
Manually setting observed input representations is
| |
| 10053 Representation::Integer32()); | |
| 10054 compare->set_position(expr->position()); | |
| 10055 return ast_context()->ReturnControl(compare, expr->id()); | |
| 10056 } | |
| 10057 | |
| 10058 | |
| 10044 void HOptimizedGraphBuilder::HandleLiteralCompareTypeof(CompareOperation* expr, | 10059 void HOptimizedGraphBuilder::HandleLiteralCompareTypeof(CompareOperation* expr, |
| 10045 HTypeof* typeof_expr, | 10060 HTypeof* typeof_expr, |
| 10046 Handle<String> check) { | 10061 Handle<String> check) { |
| 10047 // Note: The HTypeof itself is removed during canonicalization, if possible. | 10062 // Note: The HTypeof itself is removed during canonicalization, if possible. |
| 10048 HValue* value = typeof_expr->value(); | 10063 HValue* value = typeof_expr->value(); |
| 10049 HTypeofIsAndBranch* instr = new(zone()) HTypeofIsAndBranch(value, check); | 10064 HTypeofIsAndBranch* instr = new(zone()) HTypeofIsAndBranch(value, check); |
| 10050 instr->set_position(expr->position()); | 10065 instr->set_position(expr->position()); |
| 10051 return ast_context()->ReturnControl(instr, expr->id()); | 10066 return ast_context()->ReturnControl(instr, expr->id()); |
| 10052 } | 10067 } |
| 10053 | 10068 |
| 10054 | 10069 |
| 10055 static bool MatchLiteralCompareNil(HValue* left, | 10070 static bool MatchLiteralCompareNil(HValue* left, |
| 10056 Token::Value op, | 10071 Token::Value op, |
| 10057 HValue* right, | 10072 HValue* right, |
| 10058 Handle<Object> nil, | 10073 Handle<Object> nil, |
| 10059 HValue** expr) { | 10074 HValue** expr) { |
| 10060 if (left->IsConstant() && | 10075 if (left->IsConstant() && |
| 10061 HConstant::cast(left)->handle().is_identical_to(nil) && | 10076 HConstant::cast(left)->handle().is_identical_to(nil) && |
| 10062 Token::IsEqualityOp(op)) { | 10077 Token::IsEqualityOp(op)) { |
| 10063 *expr = right; | 10078 *expr = right; |
| 10064 return true; | 10079 return true; |
| 10065 } | 10080 } |
| 10066 return false; | 10081 return false; |
| 10067 } | 10082 } |
| 10068 | 10083 |
| 10069 | 10084 |
| 10085 // Recognize the pattern (i >>> 0) !== i. | |
| 10086 static bool MatchTripleShiftZeroCompare(HValue* left, | |
| 10087 Token::Value op, | |
| 10088 HValue* right, | |
| 10089 HValue** input) { | |
| 10090 if (!right->representation().IsInteger32()) return false; | |
|
Jakob Kummerow
2013/04/23 11:09:23
You can't rely on representations at graph constru
| |
| 10091 if (!left->IsShr()) return false; | |
| 10092 HShr* shr = HShr::cast(left); | |
| 10093 if (right != shr->left()) return false; | |
| 10094 if (!shr->right()->IsConstant()) return false; | |
| 10095 HConstant* shiftOperand = HConstant::cast(shr->right()); | |
| 10096 if (*(shiftOperand->handle()) != Smi::FromInt(0)) return false; | |
| 10097 *input = right; | |
| 10098 return true; | |
| 10099 } | |
| 10100 | |
| 10101 | |
| 10102 static bool IsTripleShiftZeroCompare(HValue* left, | |
| 10103 Token::Value op, | |
| 10104 HValue* right, | |
| 10105 HValue** input) { | |
| 10106 if (!Token::IsStrictOp(op)) return false; | |
| 10107 return MatchTripleShiftZeroCompare(left, op, right, input) || | |
| 10108 MatchTripleShiftZeroCompare(right, op, left, input); | |
| 10109 } | |
| 10110 | |
| 10111 | |
| 10112 | |
| 10070 static bool MatchLiteralCompareTypeof(HValue* left, | 10113 static bool MatchLiteralCompareTypeof(HValue* left, |
| 10071 Token::Value op, | 10114 Token::Value op, |
| 10072 HValue* right, | 10115 HValue* right, |
| 10073 HTypeof** typeof_expr, | 10116 HTypeof** typeof_expr, |
| 10074 Handle<String>* check) { | 10117 Handle<String>* check) { |
| 10075 if (left->IsTypeof() && | 10118 if (left->IsTypeof() && |
| 10076 Token::IsEqualityOp(op) && | 10119 Token::IsEqualityOp(op) && |
| 10077 right->IsConstant() && | 10120 right->IsConstant() && |
| 10078 HConstant::cast(right)->handle()->IsString()) { | 10121 HConstant::cast(right)->handle()->IsString()) { |
| 10079 *typeof_expr = HTypeof::cast(left); | 10122 *typeof_expr = HTypeof::cast(left); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10149 HValue* right = Pop(); | 10192 HValue* right = Pop(); |
| 10150 HValue* left = Pop(); | 10193 HValue* left = Pop(); |
| 10151 Token::Value op = expr->op(); | 10194 Token::Value op = expr->op(); |
| 10152 | 10195 |
| 10153 HTypeof* typeof_expr = NULL; | 10196 HTypeof* typeof_expr = NULL; |
| 10154 Handle<String> check; | 10197 Handle<String> check; |
| 10155 if (IsLiteralCompareTypeof(left, op, right, &typeof_expr, &check)) { | 10198 if (IsLiteralCompareTypeof(left, op, right, &typeof_expr, &check)) { |
| 10156 return HandleLiteralCompareTypeof(expr, typeof_expr, check); | 10199 return HandleLiteralCompareTypeof(expr, typeof_expr, check); |
| 10157 } | 10200 } |
| 10158 HValue* sub_expr = NULL; | 10201 HValue* sub_expr = NULL; |
| 10202 if (IsTripleShiftZeroCompare(left, op, right, &sub_expr)) { | |
| 10203 return HandleTripleShiftZeroCompare(expr, sub_expr); | |
| 10204 } | |
| 10159 Factory* f = isolate()->factory(); | 10205 Factory* f = isolate()->factory(); |
| 10160 if (IsLiteralCompareNil(left, op, right, f->undefined_value(), &sub_expr)) { | 10206 if (IsLiteralCompareNil(left, op, right, f->undefined_value(), &sub_expr)) { |
| 10161 return HandleLiteralCompareNil(expr, sub_expr, kUndefinedValue); | 10207 return HandleLiteralCompareNil(expr, sub_expr, kUndefinedValue); |
| 10162 } | 10208 } |
| 10163 if (IsLiteralCompareNil(left, op, right, f->null_value(), &sub_expr)) { | 10209 if (IsLiteralCompareNil(left, op, right, f->null_value(), &sub_expr)) { |
| 10164 return HandleLiteralCompareNil(expr, sub_expr, kNullValue); | 10210 return HandleLiteralCompareNil(expr, sub_expr, kNullValue); |
| 10165 } | 10211 } |
| 10166 if (IsLiteralCompareBool(left, op, right)) { | 10212 if (IsLiteralCompareBool(left, op, right)) { |
| 10167 HCompareObjectEqAndBranch* result = | 10213 HCompareObjectEqAndBranch* result = |
| 10168 new(zone()) HCompareObjectEqAndBranch(left, right); | 10214 new(zone()) HCompareObjectEqAndBranch(left, right); |
| (...skipping 1703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 11872 } | 11918 } |
| 11873 } | 11919 } |
| 11874 | 11920 |
| 11875 #ifdef DEBUG | 11921 #ifdef DEBUG |
| 11876 if (graph_ != NULL) graph_->Verify(false); // No full verify. | 11922 if (graph_ != NULL) graph_->Verify(false); // No full verify. |
| 11877 if (allocator_ != NULL) allocator_->Verify(); | 11923 if (allocator_ != NULL) allocator_->Verify(); |
| 11878 #endif | 11924 #endif |
| 11879 } | 11925 } |
| 11880 | 11926 |
| 11881 } } // namespace v8::internal | 11927 } } // namespace v8::internal |
| OLD | NEW |