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