OLD | NEW |
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 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 1972 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1983 } | 1983 } |
1984 | 1984 |
1985 | 1985 |
1986 const char* TRBinaryOpIC::GetName(TypeInfo type_info) { | 1986 const char* TRBinaryOpIC::GetName(TypeInfo type_info) { |
1987 switch (type_info) { | 1987 switch (type_info) { |
1988 case UNINITIALIZED: return "Uninitialized"; | 1988 case UNINITIALIZED: return "Uninitialized"; |
1989 case SMI: return "SMI"; | 1989 case SMI: return "SMI"; |
1990 case INT32: return "Int32s"; | 1990 case INT32: return "Int32s"; |
1991 case HEAP_NUMBER: return "HeapNumbers"; | 1991 case HEAP_NUMBER: return "HeapNumbers"; |
1992 case ODDBALL: return "Oddball"; | 1992 case ODDBALL: return "Oddball"; |
| 1993 case BOTH_STRING: return "BothStrings"; |
1993 case STRING: return "Strings"; | 1994 case STRING: return "Strings"; |
1994 case GENERIC: return "Generic"; | 1995 case GENERIC: return "Generic"; |
1995 default: return "Invalid"; | 1996 default: return "Invalid"; |
1996 } | 1997 } |
1997 } | 1998 } |
1998 | 1999 |
1999 | 2000 |
2000 TRBinaryOpIC::State TRBinaryOpIC::ToState(TypeInfo type_info) { | 2001 TRBinaryOpIC::State TRBinaryOpIC::ToState(TypeInfo type_info) { |
2001 switch (type_info) { | 2002 switch (type_info) { |
2002 case UNINITIALIZED: | 2003 case UNINITIALIZED: |
2003 return ::v8::internal::UNINITIALIZED; | 2004 return ::v8::internal::UNINITIALIZED; |
2004 case SMI: | 2005 case SMI: |
2005 case INT32: | 2006 case INT32: |
2006 case HEAP_NUMBER: | 2007 case HEAP_NUMBER: |
2007 case ODDBALL: | 2008 case ODDBALL: |
| 2009 case BOTH_STRING: |
2008 case STRING: | 2010 case STRING: |
2009 return MONOMORPHIC; | 2011 return MONOMORPHIC; |
2010 case GENERIC: | 2012 case GENERIC: |
2011 return MEGAMORPHIC; | 2013 return MEGAMORPHIC; |
2012 } | 2014 } |
2013 UNREACHABLE(); | 2015 UNREACHABLE(); |
2014 return ::v8::internal::UNINITIALIZED; | 2016 return ::v8::internal::UNINITIALIZED; |
2015 } | 2017 } |
2016 | 2018 |
2017 | 2019 |
2018 TRBinaryOpIC::TypeInfo TRBinaryOpIC::JoinTypes(TRBinaryOpIC::TypeInfo x, | 2020 TRBinaryOpIC::TypeInfo TRBinaryOpIC::JoinTypes(TRBinaryOpIC::TypeInfo x, |
2019 TRBinaryOpIC::TypeInfo y) { | 2021 TRBinaryOpIC::TypeInfo y) { |
2020 if (x == UNINITIALIZED) return y; | 2022 if (x == UNINITIALIZED) return y; |
2021 if (y == UNINITIALIZED) return x; | 2023 if (y == UNINITIALIZED) return x; |
2022 if (x == STRING && y == STRING) return STRING; | 2024 if (x == y) return x; |
2023 if (x == STRING || y == STRING) return GENERIC; | 2025 if (x == BOTH_STRING && y == STRING) return STRING; |
2024 if (x >= y) return x; | 2026 if (x == STRING && y == BOTH_STRING) return STRING; |
| 2027 if (x == STRING || x == BOTH_STRING || y == STRING || y == BOTH_STRING) { |
| 2028 return GENERIC; |
| 2029 } |
| 2030 if (x > y) return x; |
2025 return y; | 2031 return y; |
2026 } | 2032 } |
2027 | 2033 |
| 2034 |
2028 TRBinaryOpIC::TypeInfo TRBinaryOpIC::GetTypeInfo(Handle<Object> left, | 2035 TRBinaryOpIC::TypeInfo TRBinaryOpIC::GetTypeInfo(Handle<Object> left, |
2029 Handle<Object> right) { | 2036 Handle<Object> right) { |
2030 ::v8::internal::TypeInfo left_type = | 2037 ::v8::internal::TypeInfo left_type = |
2031 ::v8::internal::TypeInfo::TypeFromValue(left); | 2038 ::v8::internal::TypeInfo::TypeFromValue(left); |
2032 ::v8::internal::TypeInfo right_type = | 2039 ::v8::internal::TypeInfo right_type = |
2033 ::v8::internal::TypeInfo::TypeFromValue(right); | 2040 ::v8::internal::TypeInfo::TypeFromValue(right); |
2034 | 2041 |
2035 if (left_type.IsSmi() && right_type.IsSmi()) { | 2042 if (left_type.IsSmi() && right_type.IsSmi()) { |
2036 return SMI; | 2043 return SMI; |
2037 } | 2044 } |
2038 | 2045 |
2039 if (left_type.IsInteger32() && right_type.IsInteger32()) { | 2046 if (left_type.IsInteger32() && right_type.IsInteger32()) { |
2040 // Platforms with 32-bit Smis have no distinct INT32 type. | 2047 // Platforms with 32-bit Smis have no distinct INT32 type. |
2041 if (kSmiValueSize == 32) return SMI; | 2048 if (kSmiValueSize == 32) return SMI; |
2042 return INT32; | 2049 return INT32; |
2043 } | 2050 } |
2044 | 2051 |
2045 if (left_type.IsNumber() && right_type.IsNumber()) { | 2052 if (left_type.IsNumber() && right_type.IsNumber()) { |
2046 return HEAP_NUMBER; | 2053 return HEAP_NUMBER; |
2047 } | 2054 } |
2048 | 2055 |
2049 if (left_type.IsString() || right_type.IsString()) { | 2056 // Patching for fast string ADD makes sense even if only one of the |
2050 // Patching for fast string ADD makes sense even if only one of the | 2057 // arguments is a string. |
2051 // arguments is a string. | 2058 if (left_type.IsString()) { |
| 2059 return right_type.IsString() ? BOTH_STRING : STRING; |
| 2060 } else if (right_type.IsString()) { |
2052 return STRING; | 2061 return STRING; |
2053 } | 2062 } |
2054 | 2063 |
2055 // Check for oddball objects. | 2064 // Check for oddball objects. |
2056 if (left->IsUndefined() && right->IsNumber()) return ODDBALL; | 2065 if (left->IsUndefined() && right->IsNumber()) return ODDBALL; |
2057 if (left->IsNumber() && right->IsUndefined()) return ODDBALL; | 2066 if (left->IsNumber() && right->IsUndefined()) return ODDBALL; |
2058 | 2067 |
2059 return GENERIC; | 2068 return GENERIC; |
2060 } | 2069 } |
2061 | 2070 |
(...skipping 12 matching lines...) Expand all Loading... |
2074 Handle<Object> left = args.at<Object>(0); | 2083 Handle<Object> left = args.at<Object>(0); |
2075 Handle<Object> right = args.at<Object>(1); | 2084 Handle<Object> right = args.at<Object>(1); |
2076 int key = Smi::cast(args[2])->value(); | 2085 int key = Smi::cast(args[2])->value(); |
2077 Token::Value op = static_cast<Token::Value>(Smi::cast(args[3])->value()); | 2086 Token::Value op = static_cast<Token::Value>(Smi::cast(args[3])->value()); |
2078 TRBinaryOpIC::TypeInfo previous_type = | 2087 TRBinaryOpIC::TypeInfo previous_type = |
2079 static_cast<TRBinaryOpIC::TypeInfo>(Smi::cast(args[4])->value()); | 2088 static_cast<TRBinaryOpIC::TypeInfo>(Smi::cast(args[4])->value()); |
2080 | 2089 |
2081 TRBinaryOpIC::TypeInfo type = TRBinaryOpIC::GetTypeInfo(left, right); | 2090 TRBinaryOpIC::TypeInfo type = TRBinaryOpIC::GetTypeInfo(left, right); |
2082 type = TRBinaryOpIC::JoinTypes(type, previous_type); | 2091 type = TRBinaryOpIC::JoinTypes(type, previous_type); |
2083 TRBinaryOpIC::TypeInfo result_type = TRBinaryOpIC::UNINITIALIZED; | 2092 TRBinaryOpIC::TypeInfo result_type = TRBinaryOpIC::UNINITIALIZED; |
2084 if (type == TRBinaryOpIC::STRING && op != Token::ADD) { | 2093 if ((type == TRBinaryOpIC::STRING || type == TRBinaryOpIC::BOTH_STRING) && |
| 2094 op != Token::ADD) { |
2085 type = TRBinaryOpIC::GENERIC; | 2095 type = TRBinaryOpIC::GENERIC; |
2086 } | 2096 } |
2087 if (type == TRBinaryOpIC::SMI && | 2097 if (type == TRBinaryOpIC::SMI && previous_type == TRBinaryOpIC::SMI) { |
2088 previous_type == TRBinaryOpIC::SMI) { | |
2089 if (op == Token::DIV || op == Token::MUL || kSmiValueSize == 32) { | 2098 if (op == Token::DIV || op == Token::MUL || kSmiValueSize == 32) { |
2090 // Arithmetic on two Smi inputs has yielded a heap number. | 2099 // Arithmetic on two Smi inputs has yielded a heap number. |
2091 // That is the only way to get here from the Smi stub. | 2100 // That is the only way to get here from the Smi stub. |
2092 // With 32-bit Smis, all overflows give heap numbers, but with | 2101 // With 32-bit Smis, all overflows give heap numbers, but with |
2093 // 31-bit Smis, most operations overflow to int32 results. | 2102 // 31-bit Smis, most operations overflow to int32 results. |
2094 result_type = TRBinaryOpIC::HEAP_NUMBER; | 2103 result_type = TRBinaryOpIC::HEAP_NUMBER; |
2095 } else { | 2104 } else { |
2096 // Other operations on SMIs that overflow yield int32s. | 2105 // Other operations on SMIs that overflow yield int32s. |
2097 result_type = TRBinaryOpIC::INT32; | 2106 result_type = TRBinaryOpIC::INT32; |
2098 } | 2107 } |
2099 } | 2108 } |
2100 if (type == TRBinaryOpIC::INT32 && | 2109 if (type == TRBinaryOpIC::INT32 && previous_type == TRBinaryOpIC::INT32) { |
2101 previous_type == TRBinaryOpIC::INT32) { | |
2102 // We must be here because an operation on two INT32 types overflowed. | 2110 // We must be here because an operation on two INT32 types overflowed. |
2103 result_type = TRBinaryOpIC::HEAP_NUMBER; | 2111 result_type = TRBinaryOpIC::HEAP_NUMBER; |
2104 } | 2112 } |
2105 | 2113 |
2106 Handle<Code> code = GetTypeRecordingBinaryOpStub(key, type, result_type); | 2114 Handle<Code> code = GetTypeRecordingBinaryOpStub(key, type, result_type); |
2107 if (!code.is_null()) { | 2115 if (!code.is_null()) { |
2108 if (FLAG_trace_ic) { | 2116 if (FLAG_trace_ic) { |
2109 PrintF("[TypeRecordingBinaryOpIC (%s->(%s->%s))#%s]\n", | 2117 PrintF("[TypeRecordingBinaryOpIC (%s->(%s->%s))#%s]\n", |
2110 TRBinaryOpIC::GetName(previous_type), | 2118 TRBinaryOpIC::GetName(previous_type), |
2111 TRBinaryOpIC::GetName(type), | 2119 TRBinaryOpIC::GetName(type), |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2238 #undef ADDR | 2246 #undef ADDR |
2239 }; | 2247 }; |
2240 | 2248 |
2241 | 2249 |
2242 Address IC::AddressFromUtilityId(IC::UtilityId id) { | 2250 Address IC::AddressFromUtilityId(IC::UtilityId id) { |
2243 return IC_utilities[id]; | 2251 return IC_utilities[id]; |
2244 } | 2252 } |
2245 | 2253 |
2246 | 2254 |
2247 } } // namespace v8::internal | 2255 } } // namespace v8::internal |
OLD | NEW |