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

Side by Side Diff: test/cctest/interpreter/test-source-positions.cc

Issue 2038083002: [Interpreter] Add a simple dead-code elimination bytecode optimizer. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@int_jump_writer
Patch Set: Fix tests Created 4 years, 6 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
« no previous file with comments | « test/cctest/interpreter/test-interpreter.cc ('k') | test/unittests/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/pipeline.h" 7 #include "src/compiler/pipeline.h"
8 #include "src/handles.h" 8 #include "src/handles.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"
11 #include "src/isolate.h" 11 #include "src/isolate.h"
12 #include "src/parsing/parser.h" 12 #include "src/parsing/parser.h"
13 #include "test/cctest/cctest.h" 13 #include "test/cctest/cctest.h"
14 #include "test/cctest/interpreter/source-position-matcher.h" 14 #include "test/cctest/interpreter/source-position-matcher.h"
15 15
16 namespace v8 { 16 namespace v8 {
17 namespace internal { 17 namespace internal {
18 namespace interpreter { 18 namespace interpreter {
19 19
20 // Flags enabling optimizations that change generated bytecode array. 20 // Flags enabling optimizations that change generated bytecode array.
21 // Format is <command-line flag> <flag name> <bit index> 21 // Format is <command-line flag> <flag name> <bit index>
22 #define OPTIMIZATION_FLAGS(V) \ 22 #define OPTIMIZATION_FLAGS(V) \
23 V(FLAG_ignition_reo, kUseReo, 0) \ 23 V(FLAG_ignition_reo, kUseReo, 0) \
24 V(FLAG_ignition_peephole, kUsePeephole, 1) \ 24 V(FLAG_ignition_peephole, kUsePeephole, 1) \
25 V(FLAG_ignition_filter_expression_positions, \ 25 V(FLAG_ignition_filter_expression_positions, kUseFilterExpressionPositions, \
26 kUseUseFilterExpressionPositions, 2) 26 2) \
27 V(FLAG_ignition_deadcode, kUseDeadCode, 3)
27 28
28 #define DECLARE_BIT(_, Name, BitIndex) static const int Name = 1 << BitIndex; 29 #define DECLARE_BIT(_, Name, BitIndex) static const int Name = 1 << BitIndex;
29 OPTIMIZATION_FLAGS(DECLARE_BIT) 30 OPTIMIZATION_FLAGS(DECLARE_BIT)
30 #undef DECLARE_BIT 31 #undef DECLARE_BIT
31 32
32 // Test cases source positions are checked for. Please ensure all 33 // Test cases source positions are checked for. Please ensure all
33 // combinations of flags are present here. This is done manually 34 // combinations of flags are present here. This is done manually
34 // because it provides easier to comprehend failure case for humans. 35 // because it provides easier to comprehend failure case for humans.
35 #define TEST_CASES(V) \ 36 #define TEST_CASES(V) \
36 V(UsingReo, kUseReo) \ 37 V(UsingReo, kUseReo) \
37 V(UsingPeephole, kUsePeephole) \ 38 V(UsingPeephole, kUsePeephole) \
38 V(UsingReoAndPeephole, kUseReo | kUsePeephole) \ 39 V(UsingDeadCode, kUseDeadCode) \
39 V(UsingUseFilterExpressionPositions, kUseUseFilterExpressionPositions) \ 40 V(UsingFilterExpressionPositions, kUseFilterExpressionPositions) \
40 V(UsingReoAndUseFilterExpressionPositions, \ 41 V(UsingReoAndPeephole, kUseReo | kUsePeephole) \
41 kUseReo | kUseUseFilterExpressionPositions) \ 42 V(UsingReoAndFilterExpressionPositions, \
42 V(UsingPeepholeAndUseFilterExpressionPositions, \ 43 kUseReo | kUseFilterExpressionPositions) \
43 kUsePeephole | kUseUseFilterExpressionPositions) \ 44 V(UsingReoAndDeadCode, kUseReo | kUseDeadCode) \
44 V(UsingAllOptimizations, \ 45 V(UsingPeepholeAndFilterExpressionPositions, \
45 kUseReo | kUsePeephole | kUseUseFilterExpressionPositions) 46 kUsePeephole | kUseFilterExpressionPositions) \
47 V(UsingPeepholeAndDeadCode, kUsePeephole | kUseDeadCode) \
48 V(UsingFilterExpressionPositionsAndDeadCode, \
49 kUseFilterExpressionPositions | kUseDeadCode) \
50 V(UsingAllOptimizations, \
51 kUseReo | kUsePeephole | kUseFilterExpressionPositions | kUseDeadCode)
46 52
47 struct TestCaseData { 53 struct TestCaseData {
48 TestCaseData(const char* const script, 54 TestCaseData(const char* const script,
49 const char* const declaration_parameters = "", 55 const char* const declaration_parameters = "",
50 const char* const arguments = "") 56 const char* const arguments = "")
51 : script_(script), 57 : script_(script),
52 declaration_parameters_(declaration_parameters), 58 declaration_parameters_(declaration_parameters),
53 arguments_(arguments) {} 59 arguments_(arguments) {}
54 60
55 const char* const script() const { return script_; } 61 const char* const script() const { return script_; }
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 141
136 bool SourcePositionsMatch(int optimization_bitmap, const char* function_body, 142 bool SourcePositionsMatch(int optimization_bitmap, const char* function_body,
137 const char* function_decl_params, 143 const char* function_decl_params,
138 const char* function_args); 144 const char* function_args);
139 145
140 private: 146 private:
141 Handle<BytecodeArray> MakeBytecode(int optimization_bitmap, 147 Handle<BytecodeArray> MakeBytecode(int optimization_bitmap,
142 const char* function_body, 148 const char* function_body,
143 const char* function_decl_params, 149 const char* function_decl_params,
144 const char* function_args); 150 const char* function_args);
145 static std::string MakeFunctionName(int optimization_bitmap); 151 static std::string MakeScript(const char* function_body,
146 static std::string MakeScript(const char* function_name,
147 const char* function_body,
148 const char* function_decl_params, 152 const char* function_decl_params,
149 const char* function_args); 153 const char* function_args);
150 154
151 void SetOptimizationFlags(int optimization_bitmap); 155 void SetOptimizationFlags(int optimization_bitmap);
152 void SaveOptimizationFlags(); 156 void SaveOptimizationFlags();
153 void RestoreOptimizationFlags(); 157 void RestoreOptimizationFlags();
154 158
155 Isolate* isolate() const { return isolate_; } 159 Isolate* isolate() const { return isolate_; }
156 160
157 Isolate* isolate_; 161 Isolate* isolate_;
158 int saved_optimization_bitmap_; 162 int saved_optimization_bitmap_;
159 bool saved_flag_ignition_; 163 bool saved_flag_ignition_;
160 bool saved_flag_always_opt_; 164 bool saved_flag_always_opt_;
161 }; 165 };
162 166
163 // static 167 // static
164 std::string OptimizedBytecodeSourcePositionTester::MakeFunctionName( 168 std::string OptimizedBytecodeSourcePositionTester::MakeScript(
165 int optimization_bitmap) { 169 const char* function_body, const char* function_decl_params,
170 const char* function_args) {
166 std::ostringstream os; 171 std::ostringstream os;
167 os << "test_function_" << optimization_bitmap; 172 os << "function test_function"
168 return os.str(); 173 << "(" << function_decl_params << ") {";
169 }
170
171 // static
172 std::string OptimizedBytecodeSourcePositionTester::MakeScript(
173 const char* function_name, const char* function_body,
174 const char* function_decl_params, const char* function_args) {
175 std::ostringstream os;
176 os << "function " << function_name << "(" << function_decl_params << ") {";
177 os << function_body; 174 os << function_body;
178 os << "}"; 175 os << "}";
179 os << function_name << "(" << function_args << ");"; 176 os << "test_function(" << function_args << ");";
180 return os.str(); 177 return os.str();
181 } 178 }
182 179
183 Handle<BytecodeArray> OptimizedBytecodeSourcePositionTester::MakeBytecode( 180 Handle<BytecodeArray> OptimizedBytecodeSourcePositionTester::MakeBytecode(
184 int optimization_bitmap, const char* function_body, 181 int optimization_bitmap, const char* function_body,
185 const char* function_decl_params, const char* function_args) { 182 const char* function_decl_params, const char* function_args) {
186 std::string function_name = MakeFunctionName(optimization_bitmap); 183 std::string script =
187 std::string script = MakeScript(function_name.c_str(), function_body, 184 MakeScript(function_body, function_decl_params, function_args);
188 function_decl_params, function_args);
189 SetOptimizationFlags(optimization_bitmap); 185 SetOptimizationFlags(optimization_bitmap);
190 CompileRun(script.c_str()); 186 CompileRun(script.c_str());
191 187
192 Local<Function> api_function = 188 Local<Function> api_function = Local<Function>::Cast(
193 Local<Function>::Cast(CcTest::global() 189 CcTest::global()
194 ->Get(CcTest::isolate()->GetCurrentContext(), 190 ->Get(CcTest::isolate()->GetCurrentContext(), v8_str("test_function"))
195 v8_str(function_name.c_str())) 191 .ToLocalChecked());
196 .ToLocalChecked());
197 Handle<JSFunction> function = 192 Handle<JSFunction> function =
198 Handle<JSFunction>::cast(v8::Utils::OpenHandle(*api_function)); 193 Handle<JSFunction>::cast(v8::Utils::OpenHandle(*api_function));
199 return handle(function->shared()->bytecode_array()); 194 return handle(function->shared()->bytecode_array());
200 } 195 }
201 196
202 void OptimizedBytecodeSourcePositionTester::SetOptimizationFlags( 197 void OptimizedBytecodeSourcePositionTester::SetOptimizationFlags(
203 int optimization_bitmap) { 198 int optimization_bitmap) {
204 #define SET_FLAG(V8Flag, BitName, _) \ 199 #define SET_FLAG(V8Flag, BitName, _) \
205 V8Flag = (optimization_bitmap & BitName) ? true : false; 200 V8Flag = (optimization_bitmap & BitName) ? true : false;
206 OPTIMIZATION_FLAGS(SET_FLAG) 201 OPTIMIZATION_FLAGS(SET_FLAG)
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 #define MAKE_TEST(Name, Bitmap) \ 243 #define MAKE_TEST(Name, Bitmap) \
249 TEST(TestSourcePositionsEquivalent##Name) { \ 244 TEST(TestSourcePositionsEquivalent##Name) { \
250 TestSourcePositionsEquivalent(Bitmap); \ 245 TestSourcePositionsEquivalent(Bitmap); \
251 } 246 }
252 TEST_CASES(MAKE_TEST) 247 TEST_CASES(MAKE_TEST)
253 #undef MAKE_TEST 248 #undef MAKE_TEST
254 249
255 } // namespace interpreter 250 } // namespace interpreter
256 } // namespace internal 251 } // namespace internal
257 } // namespace v8 252 } // namespace v8
OLDNEW
« no previous file with comments | « test/cctest/interpreter/test-interpreter.cc ('k') | test/unittests/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698