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

Side by Side Diff: test/cctest/interpreter/test-bytecode-generator.cc

Issue 1502243002: [Interpreter] Local flow control in the bytecode graph builder. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase Created 5 years 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
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/compiler.h" 7 #include "src/compiler.h"
8 #include "src/interpreter/bytecode-array-iterator.h" 8 #include "src/interpreter/bytecode-array-iterator.h"
9 #include "src/interpreter/bytecode-generator.h" 9 #include "src/interpreter/bytecode-generator.h"
10 #include "src/interpreter/interpreter.h" 10 #include "src/interpreter/interpreter.h"
(...skipping 1955 matching lines...) Expand 10 before | Expand all | Expand 10 after
1966 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 1966 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
1967 } 1967 }
1968 } 1968 }
1969 1969
1970 1970
1971 TEST(BasicLoops) { 1971 TEST(BasicLoops) {
1972 InitializedHandleScope handle_scope; 1972 InitializedHandleScope handle_scope;
1973 BytecodeGeneratorHelper helper; 1973 BytecodeGeneratorHelper helper;
1974 1974
1975 ExpectedSnippet<int> snippets[] = { 1975 ExpectedSnippet<int> snippets[] = {
1976 {"var x = 0;\n"
1977 "while (false) { x = 99; break; continue; }\n"
1978 "return x;",
1979 1 * kPointerSize,
1980 1,
1981 4,
1982 {
1983 B(LdaZero), //
1984 B(Star), R(0), //
1985 B(Return) //
1986 }},
1987 {"var x = 0;"
1988 "while (false) {"
1989 " x = x + 1;"
1990 "};"
1991 "return x;",
1992 1 * kPointerSize,
1993 1,
1994 4,
1995 {
1996 B(LdaZero), //
1997 B(Star), R(0), //
1998 B(Return), //
1999 },
2000 0},
1976 {"var x = 0;" 2001 {"var x = 0;"
1977 "var y = 1;" 2002 "var y = 1;"
1978 "while (x < 10) {" 2003 "while (x < 10) {"
1979 " y = y * 12;" 2004 " y = y * 12;"
1980 " x = x + 1;" 2005 " x = x + 1;"
2006 " if (x == 3) continue;"
2007 " if (x == 4) break;"
1981 "}" 2008 "}"
1982 "return y;", 2009 "return y;",
1983 2 * kPointerSize, 2010 2 * kPointerSize,
1984 1, 2011 1,
1985 30, 2012 46,
1986 { 2013 {
1987 B(LdaZero), // 2014 B(LdaZero), //
1988 B(Star), R(0), // 2015 B(Star), R(0), //
1989 B(LdaSmi8), U8(1), // 2016 B(LdaSmi8), U8(1), //
1990 B(Star), R(1), // 2017 B(Star), R(1), //
1991 B(Jump), U8(14), // 2018 B(LdaSmi8), U8(10), //
2019 B(TestLessThan), R(0), //
2020 B(JumpIfFalse), U8(32), //
1992 B(LdaSmi8), U8(12), // 2021 B(LdaSmi8), U8(12), //
1993 B(Mul), R(1), // 2022 B(Mul), R(1), //
1994 B(Star), R(1), // 2023 B(Star), R(1), //
1995 B(LdaSmi8), U8(1), // 2024 B(LdaSmi8), U8(1), //
1996 B(Add), R(0), // 2025 B(Add), R(0), //
1997 B(Star), R(0), // 2026 B(Star), R(0), //
1998 B(LdaSmi8), U8(10), // 2027 B(LdaSmi8), U8(3), //
1999 B(TestLessThan), R(0), // 2028 B(TestEqual), R(0), //
2000 B(JumpIfTrue), U8(-16), // 2029 B(JumpIfFalse), U8(4), //
2030 B(Jump), U8(-24), //
2031 B(LdaSmi8), U8(4), //
2032 B(TestEqual), R(0), //
2033 B(JumpIfFalse), U8(4), //
2034 B(Jump), U8(4), //
2035 B(Jump), U8(-34), //
2001 B(Ldar), R(1), // 2036 B(Ldar), R(1), //
2002 B(Return), // 2037 B(Return), //
2003 }, 2038 },
2004 0}, 2039 0},
2005 {"var i = 0;" 2040 {"var i = 0;"
2006 "while(true) {" 2041 "while (true) {"
2007 " if (i < 0) continue;" 2042 " if (i < 0) continue;"
2008 " if (i == 3) break;" 2043 " if (i == 3) break;"
2009 " if (i == 4) break;" 2044 " if (i == 4) break;"
2010 " if (i == 10) continue;" 2045 " if (i == 10) continue;"
2011 " if (i == 5) break;" 2046 " if (i == 5) break;"
2012 " i = i + 1;" 2047 " i = i + 1;"
2013 "}" 2048 "}"
2014 "return i;", 2049 "return i;",
2015 1 * kPointerSize, 2050 1 * kPointerSize,
2016 1, 2051 1,
2017 53, 2052 53,
2018 { 2053 {
2019 B(LdaZero), // 2054 B(LdaZero), //
2020 B(Star), R(0), // 2055 B(Star), R(0), //
2021 B(LdaZero), // 2056 B(LdaZero), //
2022 B(TestLessThan), R(0), // 2057 B(TestLessThan), R(0), //
2023 B(JumpIfFalse), U8(4), // 2058 B(JumpIfFalse), U8(4), //
2024 B(Jump), U8(40), // 2059 B(Jump), U8(-5), //
2025 B(LdaSmi8), U8(3), // 2060 B(LdaSmi8), U8(3), //
2026 B(TestEqual), R(0), // 2061 B(TestEqual), R(0), //
2027 B(JumpIfFalse), U8(4), // 2062 B(JumpIfFalse), U8(4), //
2028 B(Jump), U8(34), // 2063 B(Jump), U8(34), //
2029 B(LdaSmi8), U8(4), // 2064 B(LdaSmi8), U8(4), //
2030 B(TestEqual), R(0), // 2065 B(TestEqual), R(0), //
2031 B(JumpIfFalse), U8(4), // 2066 B(JumpIfFalse), U8(4), //
2032 B(Jump), U8(26), // 2067 B(Jump), U8(26), //
2033 B(LdaSmi8), U8(10), // 2068 B(LdaSmi8), U8(10), //
2034 B(TestEqual), R(0), // 2069 B(TestEqual), R(0), //
2035 B(JumpIfFalse), U8(4), // 2070 B(JumpIfFalse), U8(4), //
2036 B(Jump), U8(16), // 2071 B(Jump), U8(-29), //
2037 B(LdaSmi8), U8(5), // 2072 B(LdaSmi8), U8(5), //
2038 B(TestEqual), R(0), // 2073 B(TestEqual), R(0), //
2039 B(JumpIfFalse), U8(4), // 2074 B(JumpIfFalse), U8(4), //
2040 B(Jump), U8(10), // 2075 B(Jump), U8(10), //
2041 B(LdaSmi8), U8(1), // 2076 B(LdaSmi8), U8(1), //
2042 B(Add), R(0), // 2077 B(Add), R(0), //
2043 B(Star), R(0), // 2078 B(Star), R(0), //
2044 B(Jump), U8(-45), // 2079 B(Jump), U8(-45), //
2045 B(Ldar), R(0), // 2080 B(Ldar), R(0), //
2046 B(Return), // 2081 B(Return), //
2047 }, 2082 },
2048 0}, 2083 0},
2049 {"var x = 0; var y = 1;"
2050 "do {"
2051 " y = y * 10;"
2052 " if (x == 5) break;"
2053 " if (x == 6) continue;"
2054 " x = x + 1;"
2055 "} while (x < 10);"
2056 "return y;",
2057 2 * kPointerSize,
2058 1,
2059 44,
2060 {
2061 B(LdaZero), //
2062 B(Star), R(0), //
2063 B(LdaSmi8), U8(1), //
2064 B(Star), R(1), //
2065 B(LdaSmi8), U8(10), //
2066 B(Mul), R(1), //
2067 B(Star), R(1), //
2068 B(LdaSmi8), U8(5), //
2069 B(TestEqual), R(0), //
2070 B(JumpIfFalse), U8(4), //
2071 B(Jump), U8(22), //
2072 B(LdaSmi8), U8(6), //
2073 B(TestEqual), R(0), //
2074 B(JumpIfFalse), U8(4), //
2075 B(Jump), U8(8), //
2076 B(LdaSmi8), U8(1), //
2077 B(Add), R(0), //
2078 B(Star), R(0), //
2079 B(LdaSmi8), U8(10), //
2080 B(TestLessThan), R(0), //
2081 B(JumpIfTrue), U8(-32), //
2082 B(Ldar), R(1), //
2083 B(Return), //
2084 },
2085 0},
2086 {"var x = 0; "
2087 "for(;;) {"
2088 " if (x == 1) break;"
2089 " x = x + 1;"
2090 "}",
2091 1 * kPointerSize,
2092 1,
2093 21,
2094 {
2095 B(LdaZero), //
2096 B(Star), R(0), //
2097 B(LdaSmi8), U8(1), //
2098 B(TestEqual), R(0), //
2099 B(JumpIfFalse), U8(4), //
2100 B(Jump), U8(10), //
2101 B(LdaSmi8), U8(1), //
2102 B(Add), R(0), //
2103 B(Star), R(0), //
2104 B(Jump), U8(-14), //
2105 B(LdaUndefined), //
2106 B(Return), //
2107 },
2108 0},
2109 {"var u = 0;"
2110 "for(var i = 0; i < 100; i = i + 1) {"
2111 " u = u + 1;"
2112 " continue;"
2113 "}",
2114 2 * kPointerSize,
2115 1,
2116 30,
2117 {
2118 B(LdaZero), //
2119 B(Star), R(0), //
2120 B(LdaZero), //
2121 B(Star), R(1), //
2122 B(Jump), U8(16), //
2123 B(LdaSmi8), U8(1), //
2124 B(Add), R(0), //
2125 B(Star), R(0), //
2126 B(Jump), U8(2), //
2127 B(LdaSmi8), U8(1), //
2128 B(Add), R(1), //
2129 B(Star), R(1), //
2130 B(LdaSmi8), U8(100), //
2131 B(TestLessThan), R(1), //
2132 B(JumpIfTrue), U8(-18), //
2133 B(LdaUndefined), //
2134 B(Return), //
2135 },
2136 0},
2137 {"var i = 0;" 2084 {"var i = 0;"
2138 "while(true) {" 2085 "while (true) {"
2139 " while (i < 3) {" 2086 " while (i < 3) {"
2140 " if (i == 2) break;" 2087 " if (i == 2) break;"
2141 " i = i + 1;" 2088 " i = i + 1;"
2142 " }" 2089 " }"
2143 " i = i + 1;" 2090 " i = i + 1;"
2144 " break;" 2091 " break;"
2145 "}" 2092 "}"
2146 "return i;", 2093 "return i;",
2147 1 * kPointerSize, 2094 1 * kPointerSize,
2148 1, 2095 1,
2149 38, 2096 38,
2150 { 2097 {
2151 B(LdaZero), // 2098 B(LdaZero), //
2152 B(Star), R(0), // 2099 B(Star), R(0), //
2153 B(Jump), U8(16), // 2100 B(LdaSmi8), U8(3), //
2101 B(TestLessThan), R(0), //
2102 B(JumpIfFalse), U8(18), //
2154 B(LdaSmi8), U8(2), // 2103 B(LdaSmi8), U8(2), //
2155 B(TestEqual), R(0), // 2104 B(TestEqual), R(0), //
2156 B(JumpIfFalse), U8(4), // 2105 B(JumpIfFalse), U8(4), //
2157 B(Jump), U8(14), // 2106 B(Jump), U8(10), //
2158 B(LdaSmi8), U8(1), // 2107 B(LdaSmi8), U8(1), //
2159 B(Add), R(0), // 2108 B(Add), R(0), //
2160 B(Star), R(0), // 2109 B(Star), R(0), //
2161 B(LdaSmi8), U8(3), // 2110 B(Jump), U8(-20), //
2162 B(TestLessThan), R(0), //
2163 B(JumpIfTrue), U8(-18), //
2164 B(LdaSmi8), U8(1), // 2111 B(LdaSmi8), U8(1), //
2165 B(Add), R(0), // 2112 B(Add), R(0), //
2166 B(Star), R(0), // 2113 B(Star), R(0), //
2167 B(Jump), U8(4), // 2114 B(Jump), U8(4), //
2168 B(Jump), U8(-30), // 2115 B(Jump), U8(-30), //
2169 B(Ldar), R(0), // 2116 B(Ldar), R(0), //
2170 B(Return), // 2117 B(Return), //
2171 }, 2118 },
2172 0}, 2119 0},
2173 {"var x = 10;" 2120 {"var x = 10;"
2174 "var y = 1;" 2121 "var y = 1;"
2175 "while (x) {" 2122 "while (x) {"
2176 " y = y * 12;" 2123 " y = y * 12;"
2177 " x = x - 1;" 2124 " x = x - 1;"
2178 "}" 2125 "}"
2179 "return y;", 2126 "return y;",
2180 2 * kPointerSize, 2127 2 * kPointerSize,
2181 1, 2128 1,
2182 29, 2129 29,
2183 { 2130 {
2184 B(LdaSmi8), U8(10), // 2131 B(LdaSmi8), U8(10), //
2185 B(Star), R(0), // 2132 B(Star), R(0), //
2186 B(LdaSmi8), U8(1), // 2133 B(LdaSmi8), U8(1), //
2187 B(Star), R(1), // 2134 B(Star), R(1), //
2188 B(Jump), U8(14), // 2135 B(Ldar), R(0), //
2136 B(JumpIfToBooleanFalse), U8(16), //
2189 B(LdaSmi8), U8(12), // 2137 B(LdaSmi8), U8(12), //
2190 B(Mul), R(1), // 2138 B(Mul), R(1), //
2191 B(Star), R(1), // 2139 B(Star), R(1), //
2192 B(LdaSmi8), U8(1), // 2140 B(LdaSmi8), U8(1), //
2193 B(Sub), R(0), // 2141 B(Sub), R(0), //
2194 B(Star), R(0), // 2142 B(Star), R(0), //
2195 B(Ldar), R(0), // 2143 B(Jump), U8(-16), //
2196 B(JumpIfToBooleanTrue), U8(-14), //
2197 B(Ldar), R(1), // 2144 B(Ldar), R(1), //
2198 B(Return), // 2145 B(Return), //
2199 }, 2146 },
2147 0},
2148 {"var x = 0; var y = 1;"
2149 "do {"
2150 " y = y * 10;"
2151 " if (x == 5) break;"
2152 " if (x == 6) continue;"
2153 " x = x + 1;"
2154 "} while (x < 10);"
2155 "return y;",
2156 2 * kPointerSize,
2157 1,
2158 44,
2159 {
2160 B(LdaZero), //
2161 B(Star), R(0), //
2162 B(LdaSmi8), U8(1), //
2163 B(Star), R(1), //
2164 B(LdaSmi8), U8(10), //
2165 B(Mul), R(1), //
2166 B(Star), R(1), //
2167 B(LdaSmi8), U8(5), //
2168 B(TestEqual), R(0), //
2169 B(JumpIfFalse), U8(4), //
2170 B(Jump), U8(22), //
2171 B(LdaSmi8), U8(6), //
2172 B(TestEqual), R(0), //
2173 B(JumpIfFalse), U8(4), //
2174 B(Jump), U8(8), //
2175 B(LdaSmi8), U8(1), //
2176 B(Add), R(0), //
2177 B(Star), R(0), //
2178 B(LdaSmi8), U8(10), //
2179 B(TestLessThan), R(0), //
2180 B(JumpIfTrue), U8(-32), //
2181 B(Ldar), R(1), //
2182 B(Return), //
2183 },
2200 0}, 2184 0},
2201 {"var x = 10;" 2185 {"var x = 10;"
2202 "var y = 1;" 2186 "var y = 1;"
2203 "do {" 2187 "do {"
2204 " y = y * 12;" 2188 " y = y * 12;"
2205 " x = x - 1;" 2189 " x = x - 1;"
2206 "} while(x);" 2190 "} while (x);"
2207 "return y;", 2191 "return y;",
2208 2 * kPointerSize, 2192 2 * kPointerSize,
2209 1, 2193 1,
2210 27, 2194 27,
2211 { 2195 {
2212 B(LdaSmi8), U8(10), // 2196 B(LdaSmi8), U8(10), //
2213 B(Star), R(0), // 2197 B(Star), R(0), //
2214 B(LdaSmi8), U8(1), // 2198 B(LdaSmi8), U8(1), //
2215 B(Star), R(1), // 2199 B(Star), R(1), //
2216 B(LdaSmi8), U8(12), // 2200 B(LdaSmi8), U8(12), //
2217 B(Mul), R(1), // 2201 B(Mul), R(1), //
2218 B(Star), R(1), // 2202 B(Star), R(1), //
2219 B(LdaSmi8), U8(1), // 2203 B(LdaSmi8), U8(1), //
2220 B(Sub), R(0), // 2204 B(Sub), R(0), //
2221 B(Star), R(0), // 2205 B(Star), R(0), //
2222 B(Ldar), R(0), // 2206 B(Ldar), R(0), //
2223 B(JumpIfToBooleanTrue), U8(-14), // 2207 B(JumpIfToBooleanTrue), U8(-14), //
2224 B(Ldar), R(1), // 2208 B(Ldar), R(1), //
2225 B(Return), // 2209 B(Return), //
2226 }, 2210 },
2227 0}, 2211 0},
2228 {"var y = 1;"
2229 "for (var x = 10; x; --x) {"
2230 " y = y * 12;"
2231 "}"
2232 "return y;",
2233 2 * kPointerSize,
2234 1,
2235 29,
2236 {
2237 B(LdaSmi8), U8(1), //
2238 B(Star), R(0), //
2239 B(LdaSmi8), U8(10), //
2240 B(Star), R(1), //
2241 B(Jump), U8(14), //
2242 B(LdaSmi8), U8(12), //
2243 B(Mul), R(0), //
2244 B(Star), R(0), //
2245 B(Ldar), R(1), //
2246 B(ToNumber), //
2247 B(Dec), //
2248 B(Star), R(1), //
2249 B(Ldar), R(1), //
2250 B(JumpIfToBooleanTrue), U8(-14), //
2251 B(Ldar), R(0), //
2252 B(Return), //
2253 },
2254 0},
2255 {"var x = 0; var y = 1;" 2212 {"var x = 0; var y = 1;"
2256 "do {" 2213 "do {"
2257 " y = y * 10;" 2214 " y = y * 10;"
2258 " if (x == 5) break;" 2215 " if (x == 5) break;"
2259 " x = x + 1;" 2216 " x = x + 1;"
2260 " if (x == 6) continue;" 2217 " if (x == 6) continue;"
2261 "} while (false);" 2218 "} while (false);"
2262 "return y;", 2219 "return y;",
2263 2 * kPointerSize, 2220 2 * kPointerSize,
2264 1, 2221 1,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
2308 B(LdaSmi8), U8(5), // 2265 B(LdaSmi8), U8(5), //
2309 B(TestEqual), R(0), // 2266 B(TestEqual), R(0), //
2310 B(JumpIfFalse), U8(4), // 2267 B(JumpIfFalse), U8(4), //
2311 B(Jump), U8(18), // 2268 B(Jump), U8(18), //
2312 B(LdaSmi8), U8(1), // 2269 B(LdaSmi8), U8(1), //
2313 B(Add), R(0), // 2270 B(Add), R(0), //
2314 B(Star), R(0), // 2271 B(Star), R(0), //
2315 B(LdaSmi8), U8(6), // 2272 B(LdaSmi8), U8(6), //
2316 B(TestEqual), R(0), // 2273 B(TestEqual), R(0), //
2317 B(JumpIfFalse), U8(4), // 2274 B(JumpIfFalse), U8(4), //
2318 B(Jump), U8(2), // 2275 B(Jump), U8(-26), //
2319 B(Jump), U8(-28), // 2276 B(Jump), U8(-28), //
2320 B(Ldar), R(1), // 2277 B(Ldar), R(1), //
2321 B(Return), // 2278 B(Return), //
2322 }, 2279 },
2323 0}, 2280 0},
2281 {"var x = 0; "
2282 "for (;;) {"
2283 " if (x == 1) break;"
2284 " if (x == 2) continue;"
2285 " x = x + 1;"
2286 "}",
2287 1 * kPointerSize,
2288 1,
2289 29,
2290 {
2291 B(LdaZero), //
2292 B(Star), R(0), //
2293 B(LdaSmi8), U8(1), //
2294 B(TestEqual), R(0), //
2295 B(JumpIfFalse), U8(4), //
2296 B(Jump), U8(18), //
2297 B(LdaSmi8), U8(2), //
2298 B(TestEqual), R(0), //
2299 B(JumpIfFalse), U8(4), //
2300 B(Jump), U8(-14), //
2301 B(LdaSmi8), U8(1), //
2302 B(Add), R(0), //
2303 B(Star), R(0), //
2304 B(Jump), U8(-22), //
2305 B(LdaUndefined), //
2306 B(Return), //
2307 },
2308 0},
2309 {"for (var x = 0;;) {"
2310 " if (x == 1) break;"
2311 " if (x == 2) continue;"
2312 " x = x + 1;"
2313 "}",
2314 1 * kPointerSize,
2315 1,
2316 29,
2317 {
2318 B(LdaZero), //
2319 B(Star), R(0), //
2320 B(LdaSmi8), U8(1), //
2321 B(TestEqual), R(0), //
2322 B(JumpIfFalse), U8(4), //
2323 B(Jump), U8(18), //
2324 B(LdaSmi8), U8(2), //
2325 B(TestEqual), R(0), //
2326 B(JumpIfFalse), U8(4), //
2327 B(Jump), U8(-14), //
2328 B(LdaSmi8), U8(1), //
2329 B(Add), R(0), //
2330 B(Star), R(0), //
2331 B(Jump), U8(-22), //
2332 B(LdaUndefined), //
2333 B(Return), //
2334 },
2335 0},
2336 {"var x = 0; "
2337 "for (;; x = x + 1) {"
2338 " if (x == 1) break;"
2339 " if (x == 2) continue;"
2340 "}",
2341 1 * kPointerSize,
2342 1,
2343 29,
2344 {
2345 B(LdaZero), //
2346 B(Star), R(0), //
2347 B(LdaSmi8), U8(1), //
2348 B(TestEqual), R(0), //
2349 B(JumpIfFalse), U8(4), //
2350 B(Jump), U8(18), //
2351 B(LdaSmi8), U8(2), //
2352 B(TestEqual), R(0), //
2353 B(JumpIfFalse), U8(4), //
2354 B(Jump), U8(2), //
2355 B(LdaSmi8), U8(1), //
2356 B(Add), R(0), //
2357 B(Star), R(0), //
2358 B(Jump), U8(-22), //
2359 B(LdaUndefined), //
2360 B(Return), //
2361 },
2362 0},
2363 {"for (var x = 0;; x = x + 1) {"
2364 " if (x == 1) break;"
2365 " if (x == 2) continue;"
2366 "}",
2367 1 * kPointerSize,
2368 1,
2369 29,
2370 {
2371 B(LdaZero), //
2372 B(Star), R(0), //
2373 B(LdaSmi8), U8(1), //
2374 B(TestEqual), R(0), //
2375 B(JumpIfFalse), U8(4), //
2376 B(Jump), U8(18), //
2377 B(LdaSmi8), U8(2), //
2378 B(TestEqual), R(0), //
2379 B(JumpIfFalse), U8(4), //
2380 B(Jump), U8(2), //
2381 B(LdaSmi8), U8(1), //
2382 B(Add), R(0), //
2383 B(Star), R(0), //
2384 B(Jump), U8(-22), //
2385 B(LdaUndefined), //
2386 B(Return), //
2387 },
2388 0},
2389 {"var u = 0;"
2390 "for (var i = 0; i < 100; i = i + 1) {"
2391 " u = u + 1;"
2392 " continue;"
2393 "}",
2394 2 * kPointerSize,
2395 1,
2396 30,
2397 {
2398 B(LdaZero), //
2399 B(Star), R(0), //
2400 B(LdaZero), //
2401 B(Star), R(1), //
2402 B(LdaSmi8), U8(100), //
2403 B(TestLessThan), R(1), //
2404 B(JumpIfFalse), U8(18), //
2405 B(LdaSmi8), U8(1), //
2406 B(Add), R(0), //
2407 B(Star), R(0), //
2408 B(Jump), U8(2), //
2409 B(LdaSmi8), U8(1), //
2410 B(Add), R(1), //
2411 B(Star), R(1), //
2412 B(Jump), U8(-20), //
2413 B(LdaUndefined), //
2414 B(Return), //
2415 },
2416 0},
2417 {"var y = 1;"
2418 "for (var x = 10; x; --x) {"
2419 " y = y * 12;"
2420 "}"
2421 "return y;",
2422 2 * kPointerSize,
2423 1,
2424 29,
2425 {
2426 B(LdaSmi8), U8(1), //
2427 B(Star), R(0), //
2428 B(LdaSmi8), U8(10), //
2429 B(Star), R(1), //
2430 B(Ldar), R(1), //
2431 B(JumpIfToBooleanFalse), U8(16), //
2432 B(LdaSmi8), U8(12), //
2433 B(Mul), R(0), //
2434 B(Star), R(0), //
2435 B(Ldar), R(1), //
2436 B(ToNumber), //
2437 B(Dec), //
2438 B(Star), R(1), //
2439 B(Jump), U8(-16), //
2440 B(Ldar), R(0), //
2441 B(Return), //
2442 },
2443 0},
2324 {"var x = 0;" 2444 {"var x = 0;"
2325 "while(false) {" 2445 "for (var i = 0; false; i++) {"
2326 " x = x + 1;" 2446 " x = x + 1;"
2327 "};" 2447 "};"
2328 "return x;", 2448 "return x;",
2329 1 * kPointerSize,
2330 1,
2331 4,
2332 {
2333 B(LdaZero), //
2334 B(Star), R(0), //
2335 B(Return), //
2336 },
2337 0},
2338 {"var x = 0;"
2339 "for( var i = 0; false; i++) {"
2340 " x = x + 1;"
2341 "};"
2342 "return x;",
2343 2 * kPointerSize, 2449 2 * kPointerSize,
2344 1, 2450 1,
2345 9, 2451 9,
2346 { 2452 {
2347 B(LdaZero), // 2453 B(LdaZero), //
2348 B(Star), R(0), // 2454 B(Star), R(0), //
2349 B(LdaZero), // 2455 B(LdaZero), //
2350 B(Star), R(1), // 2456 B(Star), R(1), //
2351 B(Ldar), R(0), // 2457 B(Ldar), R(0), //
2352 B(Return), // 2458 B(Return), //
2353 }, 2459 },
2354 0}, 2460 0},
2355 {"var x = 0;" 2461 {"var x = 0;"
2356 "for( var i = 0; true; ++i) {" 2462 "for (var i = 0; true; ++i) {"
2357 " x = x + 1;" 2463 " x = x + 1;"
2358 " if (x == 20) break;" 2464 " if (x == 20) break;"
2359 "};" 2465 "};"
2360 "return x;", 2466 "return x;",
2361 2 * kPointerSize, 2467 2 * kPointerSize,
2362 1, 2468 1,
2363 31, 2469 31,
2364 { 2470 {
2365 B(LdaZero), // 2471 B(LdaZero), //
2366 B(Star), R(0), // 2472 B(Star), R(0), //
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
2401 "while (x != 10) {" 2507 "while (x != 10) {"
2402 " x = x + 10;" 2508 " x = x + 10;"
2403 "}" 2509 "}"
2404 "return x;", 2510 "return x;",
2405 kPointerSize, 2511 kPointerSize,
2406 1, 2512 1,
2407 21, 2513 21,
2408 { 2514 {
2409 B(LdaZero), // 2515 B(LdaZero), //
2410 B(Star), R(0), // 2516 B(Star), R(0), //
2411 B(Jump), U8(8), //
2412 B(LdaSmi8), U8(10), //
2413 B(Add), R(0), //
2414 B(Star), R(0), //
2415 B(LdaSmi8), U8(10), // 2517 B(LdaSmi8), U8(10), //
2416 B(TestEqual), R(0), // 2518 B(TestEqual), R(0), //
2417 B(LogicalNot), // 2519 B(LogicalNot), //
2418 B(JumpIfTrue), U8(-11), // 2520 B(JumpIfFalse), U8(10), //
2521 B(LdaSmi8), U8(10), //
2522 B(Add), R(0), //
2523 B(Star), R(0), //
2524 B(Jump), U8(-13), //
2419 B(Ldar), R(0), // 2525 B(Ldar), R(0), //
2420 B(Return), // 2526 B(Return), //
2421 }, 2527 },
2422 0}, 2528 0},
2423 {"var x = false;" 2529 {"var x = false;"
2424 "do {" 2530 "do {"
2425 " x = !x;" 2531 " x = !x;"
2426 "} while(x == false);" 2532 "} while(x == false);"
2427 "return x;", 2533 "return x;",
2428 kPointerSize, 2534 kPointerSize,
(...skipping 2810 matching lines...) Expand 10 before | Expand all | Expand 10 after
5239 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 5345 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
5240 } 5346 }
5241 } 5347 }
5242 5348
5243 5349
5244 TEST(RemoveRedundantLdar) { 5350 TEST(RemoveRedundantLdar) {
5245 InitializedHandleScope handle_scope; 5351 InitializedHandleScope handle_scope;
5246 BytecodeGeneratorHelper helper; 5352 BytecodeGeneratorHelper helper;
5247 5353
5248 ExpectedSnippet<int> snippets[] = { 5354 ExpectedSnippet<int> snippets[] = {
5249 {"var ld_a = 1;\n" // This test is to check Ldar does not 5355 {"var ld_a = 1;\n" // This test is to check Ldar does not
5250 "while(true) {\n" // get removed if the preceding Star is 5356 "while(true) {\n" // get removed if the preceding Star is
5251 " ld_a = ld_a + ld_a;\n" // in a different basicblock. 5357 " ld_a = ld_a + ld_a;\n" // in a different basicblock.
5252 " if (ld_a > 10) break;\n" 5358 " if (ld_a > 10) break;\n"
5253 "}\n" 5359 "}\n"
5254 "return ld_a;", 5360 "return ld_a;",
5255 1 * kPointerSize, 5361 1 * kPointerSize,
5256 1, 5362 1,
5257 23, 5363 23,
5258 { 5364 {B(LdaSmi8), U8(1), //
5259 B(LdaSmi8), U8(1), // 5365 B(Star), R(0), //
5260 B(Star), R(0), // 5366 B(Ldar), R(0), // This load should not be removed as it
5261 B(Ldar), R(0), // This load should not be removed as it 5367 B(Add), R(0), // is the target of the branch.
5262 B(Add), R(0), // is the target of the branch. 5368 B(Star), R(0), //
5263 B(Star), R(0), // 5369 B(LdaSmi8), U8(10), //
5264 B(LdaSmi8), U8(10), // 5370 B(TestGreaterThan), R(0), //
5265 B(TestGreaterThan), R(0), // 5371 B(JumpIfFalse), U8(4), //
5266 B(JumpIfFalse), U8(4), // 5372 B(Jump), U8(4), //
5267 B(Jump), U8(4), // 5373 B(Jump), U8(-14), //
5268 B(Jump), U8(-14), // 5374 B(Ldar), R(0), //
5269 B(Ldar), R(0), // 5375 B(Return)}},
5270 B(Return)
5271 }},
5272 {"var ld_a = 1;\n" 5376 {"var ld_a = 1;\n"
5273 "do {\n" 5377 "do {\n"
5274 " ld_a = ld_a + ld_a;\n" 5378 " ld_a = ld_a + ld_a;\n"
5275 " if (ld_a > 10) continue;\n" 5379 " if (ld_a > 10) continue;\n"
5276 "} while(false);\n" 5380 "} while(false);\n"
5277 "return ld_a;", 5381 "return ld_a;",
5278 1 * kPointerSize, 5382 1 * kPointerSize,
5279 1, 5383 1,
5280 19, 5384 21,
5385 {B(LdaSmi8), U8(1), //
5386 B(Star), R(0), //
5387 B(Ldar), R(0), //
5388 B(Add), R(0), //
5389 B(Star), R(0), //
5390 B(LdaSmi8), U8(10), //
5391 B(TestGreaterThan), R(0), //
5392 B(JumpIfFalse), U8(4), //
5393 B(Jump), U8(2), //
5394 B(Ldar), R(0), //
5395 B(Return)}},
5396 {"var ld_a = 1;\n"
5397 " ld_a = ld_a + ld_a;\n"
5398 " return ld_a;",
5399 1 * kPointerSize,
5400 1,
5401 9,
5281 { 5402 {
5282 B(LdaSmi8), U8(1), // 5403 B(LdaSmi8), U8(1), //
5283 B(Star), R(0), // 5404 B(Star), R(0), //
5284 B(Add), R(0), // 5405 B(Add), R(0), //
5285 B(Star), R(0), // 5406 B(Star), R(0), //
5286 B(LdaSmi8), U8(10), // 5407 B(Return) //
5287 B(TestGreaterThan), R(0), //
5288 B(JumpIfFalse), U8(4), //
5289 B(Jump), U8(2), //
5290 B(Ldar), R(0), //
5291 B(Return)
5292 }}, 5408 }},
5293 }; 5409 };
5294 5410
5295 for (size_t i = 0; i < arraysize(snippets); i++) { 5411 for (size_t i = 0; i < arraysize(snippets); i++) {
5296 Handle<BytecodeArray> bytecode_array = 5412 Handle<BytecodeArray> bytecode_array =
5297 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); 5413 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
5298 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 5414 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
5299 } 5415 }
5300 } 5416 }
5301 5417
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
5514 for (size_t i = 0; i < arraysize(snippets); i++) { 5630 for (size_t i = 0; i < arraysize(snippets); i++) {
5515 Handle<BytecodeArray> bytecode_array = 5631 Handle<BytecodeArray> bytecode_array =
5516 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); 5632 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet);
5517 CheckBytecodeArrayEqual(snippets[i], bytecode_array); 5633 CheckBytecodeArrayEqual(snippets[i], bytecode_array);
5518 } 5634 }
5519 } 5635 }
5520 5636
5521 } // namespace interpreter 5637 } // namespace interpreter
5522 } // namespace internal 5638 } // namespace internal
5523 } // namespace v8 5639 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698