OLD | NEW |
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 1876 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1887 visited->Add(id()); | 1887 visited->Add(id()); |
1888 // Propagate to the left argument. If the left argument cannot be -0, then | 1888 // Propagate to the left argument. If the left argument cannot be -0, then |
1889 // the result of the sub operation cannot be either. | 1889 // the result of the sub operation cannot be either. |
1890 if (range() == NULL || range()->CanBeMinusZero()) { | 1890 if (range() == NULL || range()->CanBeMinusZero()) { |
1891 return left(); | 1891 return left(); |
1892 } | 1892 } |
1893 return NULL; | 1893 return NULL; |
1894 } | 1894 } |
1895 | 1895 |
1896 | 1896 |
| 1897 #define H_CONSTANT_INT32(val) \ |
| 1898 new(zone) HConstant(FACTORY->NewNumberFromInt(val, TENURED), \ |
| 1899 Representation::Integer32()) |
| 1900 #define H_CONSTANT_DOUBLE(val) \ |
| 1901 new(zone) HConstant(FACTORY->NewNumber(val, TENURED), \ |
| 1902 Representation::Double()) |
| 1903 |
| 1904 #define DEFINE_NEW_H_SIMPLE_ARITHMETIC_INSTR(HInstr, op) \ |
| 1905 HInstruction* HInstr::New##HInstr(Zone* zone, \ |
| 1906 HValue* context, \ |
| 1907 HValue* left, \ |
| 1908 HValue* right) { \ |
| 1909 if (left->IsConstant() && right->IsConstant()) { \ |
| 1910 HConstant* c_left = HConstant::cast(left); \ |
| 1911 HConstant* c_right = HConstant::cast(right); \ |
| 1912 if ((c_left->HasNumberValue() && c_right->HasNumberValue())) { \ |
| 1913 double double_res = c_left->DoubleValue() op c_right->DoubleValue(); \ |
| 1914 if (TypeInfo::IsInt32Double(double_res)) { \ |
| 1915 return H_CONSTANT_INT32(static_cast<int32_t>(double_res)); \ |
| 1916 } \ |
| 1917 return H_CONSTANT_DOUBLE(double_res); \ |
| 1918 } \ |
| 1919 } \ |
| 1920 return new(zone) HInstr(context, left, right); \ |
| 1921 } |
| 1922 |
| 1923 |
| 1924 DEFINE_NEW_H_SIMPLE_ARITHMETIC_INSTR(HAdd, +) |
| 1925 DEFINE_NEW_H_SIMPLE_ARITHMETIC_INSTR(HMul, *) |
| 1926 DEFINE_NEW_H_SIMPLE_ARITHMETIC_INSTR(HSub, -) |
| 1927 |
| 1928 #undef DEFINE_NEW_H_SIMPLE_ARITHMETIC_INSTR |
| 1929 |
| 1930 |
| 1931 HInstruction* HMod::NewHMod(Zone* zone, |
| 1932 HValue* context, |
| 1933 HValue* left, |
| 1934 HValue* right) { |
| 1935 if (left->IsConstant() && right->IsConstant()) { |
| 1936 HConstant* c_left = HConstant::cast(left); |
| 1937 HConstant* c_right = HConstant::cast(right); |
| 1938 if (c_left->HasInteger32Value() && c_right->HasInteger32Value()) { |
| 1939 int32_t dividend = c_left->Integer32Value(); |
| 1940 int32_t divisor = c_right->Integer32Value(); |
| 1941 if (divisor != 0) { |
| 1942 int32_t res = dividend % divisor; |
| 1943 if ((res == 0) && (dividend < 0)) { |
| 1944 return H_CONSTANT_DOUBLE(-0.0); |
| 1945 } |
| 1946 return H_CONSTANT_INT32(res); |
| 1947 } |
| 1948 } |
| 1949 } |
| 1950 return new(zone) HMod(context, left, right); |
| 1951 } |
| 1952 |
| 1953 |
| 1954 HInstruction* HDiv::NewHDiv(Zone* zone, |
| 1955 HValue* context, |
| 1956 HValue* left, |
| 1957 HValue* right) { |
| 1958 // If left and right are constant values, try to return a constant value. |
| 1959 if (left->IsConstant() && right->IsConstant()) { |
| 1960 HConstant* c_left = HConstant::cast(left); |
| 1961 HConstant* c_right = HConstant::cast(right); |
| 1962 if ((c_left->HasNumberValue() && c_right->HasNumberValue())) { |
| 1963 if (c_right->DoubleValue() != 0) { |
| 1964 double double_res = c_left->DoubleValue() / c_right->DoubleValue(); |
| 1965 if (TypeInfo::IsInt32Double(double_res)) { |
| 1966 return H_CONSTANT_INT32(static_cast<int32_t>(double_res)); |
| 1967 } |
| 1968 return H_CONSTANT_DOUBLE(double_res); |
| 1969 } |
| 1970 } |
| 1971 } |
| 1972 return new(zone) HDiv(context, left, right); |
| 1973 } |
| 1974 |
| 1975 |
| 1976 HInstruction* HBitwise::NewHBitwise(Zone* zone, |
| 1977 Token::Value op, |
| 1978 HValue* context, |
| 1979 HValue* left, |
| 1980 HValue* right) { |
| 1981 if (left->IsConstant() && right->IsConstant()) { |
| 1982 HConstant* c_left = HConstant::cast(left); |
| 1983 HConstant* c_right = HConstant::cast(right); |
| 1984 if ((c_left->HasNumberValue() && c_right->HasNumberValue())) { |
| 1985 int32_t result; |
| 1986 int32_t v_left = c_left->NumberValueAsInteger32(); |
| 1987 int32_t v_right = c_right->NumberValueAsInteger32(); |
| 1988 switch (op) { |
| 1989 case Token::BIT_XOR: |
| 1990 result = v_left ^ v_right; |
| 1991 break; |
| 1992 case Token::BIT_AND: |
| 1993 result = v_left & v_right; |
| 1994 break; |
| 1995 case Token::BIT_OR: |
| 1996 result = v_left | v_right; |
| 1997 break; |
| 1998 default: |
| 1999 result = 0; // Please the compiler. |
| 2000 UNREACHABLE(); |
| 2001 } |
| 2002 return H_CONSTANT_INT32(result); |
| 2003 } |
| 2004 } |
| 2005 return new(zone) HBitwise(op, context, left, right); |
| 2006 } |
| 2007 |
| 2008 |
| 2009 #define DEFINE_NEW_H_BITWISE_INSTR(HInstr, result) \ |
| 2010 HInstruction* HInstr::New##HInstr(Zone* zone, \ |
| 2011 HValue* context, \ |
| 2012 HValue* left, \ |
| 2013 HValue* right) { \ |
| 2014 if (left->IsConstant() && right->IsConstant()) { \ |
| 2015 HConstant* c_left = HConstant::cast(left); \ |
| 2016 HConstant* c_right = HConstant::cast(right); \ |
| 2017 if ((c_left->HasNumberValue() && c_right->HasNumberValue())) { \ |
| 2018 return H_CONSTANT_INT32(result); \ |
| 2019 } \ |
| 2020 } \ |
| 2021 return new(zone) HInstr(context, left, right); \ |
| 2022 } |
| 2023 |
| 2024 |
| 2025 DEFINE_NEW_H_BITWISE_INSTR(HSar, |
| 2026 c_left->NumberValueAsInteger32() >> (c_right->NumberValueAsInteger32() & 0x1f)) |
| 2027 DEFINE_NEW_H_BITWISE_INSTR(HShl, |
| 2028 c_left->NumberValueAsInteger32() << (c_right->NumberValueAsInteger32() & 0x1f)) |
| 2029 |
| 2030 #undef DEFINE_NEW_H_BITWISE_INSTR |
| 2031 |
| 2032 |
| 2033 HInstruction* HShr::NewHShr(Zone* zone, |
| 2034 HValue* context, |
| 2035 HValue* left, |
| 2036 HValue* right) { |
| 2037 if (left->IsConstant() && right->IsConstant()) { |
| 2038 HConstant* c_left = HConstant::cast(left); |
| 2039 HConstant* c_right = HConstant::cast(right); |
| 2040 if ((c_left->HasNumberValue() && c_right->HasNumberValue())) { |
| 2041 int32_t left_val = c_left->NumberValueAsInteger32(); |
| 2042 int32_t right_val = c_right->NumberValueAsInteger32() & 0x1f; |
| 2043 if ((right_val == 0) && (left_val < 0)) { |
| 2044 return H_CONSTANT_DOUBLE( |
| 2045 static_cast<double>(static_cast<uint32_t>(left_val))); |
| 2046 } |
| 2047 return H_CONSTANT_INT32(static_cast<uint32_t>(left_val) >> right_val); |
| 2048 } |
| 2049 } |
| 2050 return new(zone) HShr(context, left, right); |
| 2051 } |
| 2052 |
| 2053 |
| 2054 #undef H_CONSTANT_INT32 |
| 2055 #undef H_CONSTANT_DOUBLE |
| 2056 |
| 2057 |
1897 void HIn::PrintDataTo(StringStream* stream) { | 2058 void HIn::PrintDataTo(StringStream* stream) { |
1898 key()->PrintNameTo(stream); | 2059 key()->PrintNameTo(stream); |
1899 stream->Add(" "); | 2060 stream->Add(" "); |
1900 object()->PrintNameTo(stream); | 2061 object()->PrintNameTo(stream); |
1901 } | 2062 } |
1902 | 2063 |
1903 | 2064 |
1904 // Node-specific verification code is only included in debug mode. | 2065 // Node-specific verification code is only included in debug mode. |
1905 #ifdef DEBUG | 2066 #ifdef DEBUG |
1906 | 2067 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1941 | 2102 |
1942 | 2103 |
1943 void HCheckPrototypeMaps::Verify() { | 2104 void HCheckPrototypeMaps::Verify() { |
1944 HInstruction::Verify(); | 2105 HInstruction::Verify(); |
1945 ASSERT(HasNoUses()); | 2106 ASSERT(HasNoUses()); |
1946 } | 2107 } |
1947 | 2108 |
1948 #endif | 2109 #endif |
1949 | 2110 |
1950 } } // namespace v8::internal | 2111 } } // namespace v8::internal |
OLD | NEW |