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

Side by Side Diff: test/cctest/compiler/test-run-bytecode-graph-builder.cc

Issue 1641143002: [Interpreter] Adds a placeholder merge node when visiting jumps. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 months 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 <utility> 5 #include <utility>
6 6
7 #include "src/compiler/pipeline.h" 7 #include "src/compiler/pipeline.h"
8 #include "src/execution.h" 8 #include "src/execution.h"
9 #include "src/handles.h" 9 #include "src/handles.h"
10 #include "src/interpreter/bytecode-array-builder.h" 10 #include "src/interpreter/bytecode-array-builder.h"
(...skipping 1837 matching lines...) Expand 10 before | Expand all | Expand 10 after
1848 "} else {\n" 1848 "} else {\n"
1849 " if (p1 < -10) { return -2; } else { return -1; }\n" 1849 " if (p1 < -10) { return -2; } else { return -1; }\n"
1850 "}", 1850 "}",
1851 {factory->NewNumberFromInt(-2), factory->NewNumberFromInt(-11)}}, 1851 {factory->NewNumberFromInt(-2), factory->NewNumberFromInt(-11)}},
1852 {"if (p1 >= 0) {\n" 1852 {"if (p1 >= 0) {\n"
1853 " if (p1 > 10) { return 2; } else { return 1; }\n" 1853 " if (p1 > 10) { return 2; } else { return 1; }\n"
1854 "} else {\n" 1854 "} else {\n"
1855 " if (p1 < -10) { return -2; } else { return -1; }\n" 1855 " if (p1 < -10) { return -2; } else { return -1; }\n"
1856 "}", 1856 "}",
1857 {factory->NewNumberFromInt(-1), factory->NewNumberFromInt(-10)}}, 1857 {factory->NewNumberFromInt(-1), factory->NewNumberFromInt(-10)}},
1858 {"var b = 20, c;"
1859 "if (p1 >= 0) {\n"
1860 " if (b > 0) { c = 2; } else { c = 3; }\n"
1861 "} else {\n"
1862 " if (b < -10) { c = -2; } else { c = -1; }\n"
1863 "}"
1864 "return c;",
1865 {factory->NewNumberFromInt(-1), factory->NewNumberFromInt(-1)}},
1866 {"var b = 20, c = 10;"
1867 "if (p1 >= 0) {\n"
1868 " if (b < 0) { c = 2; }\n"
1869 "} else {\n"
1870 " if (b < -10) { c = -2; } else { c = -1; }\n"
1871 "}"
1872 "return c;",
1873 {factory->NewNumberFromInt(10), factory->NewNumberFromInt(1)}},
1874 {"var x = 2, a = 10, b = 20, c, d;"
1875 "x = 0;"
1876 "if (a) {\n"
1877 " b = x;"
1878 " if (b > 0) { c = 2; } else { c = 3; }\n"
1879 " x = 4; d = 2;"
1880 "} else {\n"
1881 " d = 3;\n"
1882 "}"
1883 "x = d;"
1884 "function f1() {x}"
1885 "return x + c;",
1886 {factory->NewNumberFromInt(5), factory->NewNumberFromInt(-1)}},
1858 }; 1887 };
1859 1888
1860 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]); 1889 size_t num_snippets = sizeof(snippets) / sizeof(snippets[0]);
1861 for (size_t i = 0; i < num_snippets; i++) { 1890 for (size_t i = 0; i < num_snippets; i++) {
1862 ScopedVector<char> script(2048); 1891 ScopedVector<char> script(2048);
1863 SNPrintF(script, "function %s(p1) { %s };\n%s(0);", kFunctionName, 1892 SNPrintF(script, "function %s(p1) { %s };\n%s(0);", kFunctionName,
1864 snippets[i].code_snippet, kFunctionName); 1893 snippets[i].code_snippet, kFunctionName);
1865 1894
1866 BytecodeGraphTester tester(isolate, zone, script.start()); 1895 BytecodeGraphTester tester(isolate, zone, script.start());
1867 auto callable = tester.GetCallable<Handle<Object>>(); 1896 auto callable = tester.GetCallable<Handle<Object>>();
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1944 snippets[i].code_snippet, kFunctionName); 1973 snippets[i].code_snippet, kFunctionName);
1945 1974
1946 BytecodeGraphTester tester(isolate, zone, script.start()); 1975 BytecodeGraphTester tester(isolate, zone, script.start());
1947 auto callable = tester.GetCallable<Handle<Object>>(); 1976 auto callable = tester.GetCallable<Handle<Object>>();
1948 Handle<Object> return_value = 1977 Handle<Object> return_value =
1949 callable(snippets[i].parameter(0)).ToHandleChecked(); 1978 callable(snippets[i].parameter(0)).ToHandleChecked();
1950 CHECK(return_value->SameValue(*snippets[i].return_value())); 1979 CHECK(return_value->SameValue(*snippets[i].return_value()));
1951 } 1980 }
1952 } 1981 }
1953 1982
1983 TEST(BytecodeGraphBuilderSwitchMerge) {
1984 HandleAndZoneScope scope;
1985 Isolate* isolate = scope.main_isolate();
1986 Zone* zone = scope.main_zone();
1987 Factory* factory = isolate->factory();
1988
1989 const char* switch_code =
1990 "var x = 10;"
1991 "switch (p1) {\n"
1992 " case 1: x = 0;\n"
1993 " case 2: x = 1;\n"
1994 " case 3:\n"
1995 " case 4: x = 2; break;\n"
1996 " case 5: x = 3;\n"
1997 " case 9: break;\n"
1998 " default: x = 4;\n"
1999 "}\n"
2000 "return x;";
2001
2002 ExpectedSnippet<1> snippets[] = {
2003 {switch_code,
2004 {factory->NewNumberFromInt(2), factory->NewNumberFromInt(1)}},
2005 {switch_code,
2006 {factory->NewNumberFromInt(2), factory->NewNumberFromInt(2)}},
2007 {switch_code,
2008 {factory->NewNumberFromInt(2), factory->NewNumberFromInt(3)}},
2009 {switch_code,
2010 {factory->NewNumberFromInt(2), factory->NewNumberFromInt(4)}},
2011 {switch_code,
2012 {factory->NewNumberFromInt(3), factory->NewNumberFromInt(5)}},
2013 {switch_code,
2014 {factory->NewNumberFromInt(10), factory->NewNumberFromInt(9)}},
2015 {switch_code,
2016 {factory->NewNumberFromInt(4), factory->NewNumberFromInt(6)}},
2017 };
2018
2019 for (size_t i = 0; i < arraysize(snippets); i++) {
2020 ScopedVector<char> script(2048);
2021 SNPrintF(script, "function %s(p1) { %s };\n%s(0);", kFunctionName,
2022 snippets[i].code_snippet, kFunctionName);
2023
2024 BytecodeGraphTester tester(isolate, zone, script.start());
2025 auto callable = tester.GetCallable<Handle<Object>>();
2026 Handle<Object> return_value =
2027 callable(snippets[i].parameter(0)).ToHandleChecked();
2028 CHECK(return_value->SameValue(*snippets[i].return_value()));
2029 }
2030 }
1954 2031
1955 TEST(BytecodeGraphBuilderNestedSwitch) { 2032 TEST(BytecodeGraphBuilderNestedSwitch) {
1956 HandleAndZoneScope scope; 2033 HandleAndZoneScope scope;
1957 Isolate* isolate = scope.main_isolate(); 2034 Isolate* isolate = scope.main_isolate();
1958 Zone* zone = scope.main_zone(); 2035 Zone* zone = scope.main_zone();
1959 Factory* factory = isolate->factory(); 2036 Factory* factory = isolate->factory();
1960 2037
1961 const char* switch_code = 2038 const char* switch_code =
1962 "switch (p1) {\n" 2039 "switch (p1) {\n"
1963 " case 0: {" 2040 " case 0: {"
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
2455 Handle<Object> return_value = callable().ToHandleChecked(); 2532 Handle<Object> return_value = callable().ToHandleChecked();
2456 CHECK(return_value->SameValue(*snippets[i].return_value())); 2533 CHECK(return_value->SameValue(*snippets[i].return_value()));
2457 } 2534 }
2458 2535
2459 FLAG_harmony_do_expressions = old_flag; 2536 FLAG_harmony_do_expressions = old_flag;
2460 } 2537 }
2461 2538
2462 } // namespace compiler 2539 } // namespace compiler
2463 } // namespace internal 2540 } // namespace internal
2464 } // namespace v8 2541 } // namespace v8
OLDNEW
« src/compiler/bytecode-graph-builder.cc ('K') | « src/compiler/bytecode-graph-builder.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698