OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 #include "test/cctest/cctest.h" | 6 #include "test/cctest/cctest.h" |
7 | 7 |
8 #include "src/compiler/code-generator.h" | 8 #include "src/compiler/code-generator.h" |
9 #include "src/compiler/common-operator.h" | 9 #include "src/compiler/common-operator.h" |
10 #include "src/compiler/graph.h" | 10 #include "src/compiler/graph.h" |
11 #include "src/compiler/instruction-selector.h" | 11 #include "src/compiler/instruction-selector.h" |
12 #include "src/compiler/machine-operator.h" | 12 #include "src/compiler/machine-operator.h" |
13 #include "src/compiler/node.h" | 13 #include "src/compiler/node.h" |
14 #include "src/compiler/operator.h" | 14 #include "src/compiler/operator.h" |
15 #include "src/compiler/raw-machine-assembler.h" | 15 #include "src/compiler/raw-machine-assembler.h" |
16 #include "src/compiler/register-allocator.h" | 16 #include "src/compiler/register-allocator.h" |
17 #include "src/compiler/schedule.h" | 17 #include "src/compiler/schedule.h" |
18 | 18 |
19 #include "src/full-codegen.h" | 19 #include "src/full-codegen.h" |
20 #include "src/parser.h" | 20 #include "src/parser.h" |
21 #include "src/rewriter.h" | 21 #include "src/rewriter.h" |
22 | 22 |
| 23 #include "test/cctest/compiler/c-signature.h" |
23 #include "test/cctest/compiler/function-tester.h" | 24 #include "test/cctest/compiler/function-tester.h" |
24 | 25 |
25 using namespace v8::internal; | 26 using namespace v8::internal; |
26 using namespace v8::internal::compiler; | 27 using namespace v8::internal::compiler; |
27 | 28 |
28 | 29 |
29 #if V8_TURBOFAN_TARGET | 30 #if V8_TURBOFAN_TARGET |
30 | 31 |
31 typedef RawMachineAssembler::Label MLabel; | 32 typedef RawMachineAssembler::Label MLabel; |
32 | 33 |
(...skipping 24 matching lines...) Expand all Loading... |
57 | 58 |
58 DCHECK(info.shared_info()->has_deoptimization_support()); | 59 DCHECK(info.shared_info()->has_deoptimization_support()); |
59 | 60 |
60 graph = new (scope_->main_zone()) Graph(scope_->main_zone()); | 61 graph = new (scope_->main_zone()) Graph(scope_->main_zone()); |
61 } | 62 } |
62 | 63 |
63 virtual ~DeoptCodegenTester() { delete code; } | 64 virtual ~DeoptCodegenTester() { delete code; } |
64 | 65 |
65 void GenerateCodeFromSchedule(Schedule* schedule) { | 66 void GenerateCodeFromSchedule(Schedule* schedule) { |
66 OFStream os(stdout); | 67 OFStream os(stdout); |
67 os << *schedule; | 68 if (FLAG_trace_turbo) { |
| 69 os << *schedule; |
| 70 } |
68 | 71 |
69 // Initialize the codegen and generate code. | 72 // Initialize the codegen and generate code. |
70 Linkage* linkage = new (scope_->main_zone()) Linkage(&info); | 73 Linkage* linkage = new (scope_->main_zone()) Linkage(&info); |
71 code = new v8::internal::compiler::InstructionSequence(linkage, graph, | 74 code = new v8::internal::compiler::InstructionSequence(linkage, graph, |
72 schedule); | 75 schedule); |
73 SourcePositionTable source_positions(graph); | 76 SourcePositionTable source_positions(graph); |
74 InstructionSelector selector(code, &source_positions); | 77 InstructionSelector selector(code, &source_positions); |
75 selector.SelectInstructions(); | 78 selector.SelectInstructions(); |
76 | 79 |
77 os << "----- Instruction sequence before register allocation -----\n" | 80 if (FLAG_trace_turbo) { |
78 << *code; | 81 os << "----- Instruction sequence before register allocation -----\n" |
| 82 << *code; |
| 83 } |
79 | 84 |
80 RegisterAllocator allocator(code); | 85 RegisterAllocator allocator(code); |
81 CHECK(allocator.Allocate()); | 86 CHECK(allocator.Allocate()); |
82 | 87 |
83 os << "----- Instruction sequence after register allocation -----\n" | 88 if (FLAG_trace_turbo) { |
84 << *code; | 89 os << "----- Instruction sequence after register allocation -----\n" |
| 90 << *code; |
| 91 } |
85 | 92 |
86 compiler::CodeGenerator generator(code); | 93 compiler::CodeGenerator generator(code); |
87 result_code = generator.GenerateCode(); | 94 result_code = generator.GenerateCode(); |
88 | 95 |
89 #ifdef DEBUG | 96 #ifdef OBJECT_PRINT |
90 result_code->Print(); | 97 if (FLAG_print_opt_code || FLAG_trace_turbo) { |
| 98 result_code->Print(); |
| 99 } |
91 #endif | 100 #endif |
92 } | 101 } |
93 | 102 |
94 Zone* zone() { return scope_->main_zone(); } | 103 Zone* zone() { return scope_->main_zone(); } |
95 | 104 |
96 HandleAndZoneScope* scope_; | 105 HandleAndZoneScope* scope_; |
97 Handle<JSFunction> function; | 106 Handle<JSFunction> function; |
98 CompilationInfo info; | 107 CompilationInfo info; |
99 BailoutId bailout_id; | 108 BailoutId bailout_id; |
100 Handle<Code> result_code; | 109 Handle<Code> result_code; |
(...skipping 14 matching lines...) Expand all Loading... |
115 | 124 |
116 Schedule* BuildGraphAndSchedule(Graph* graph) { | 125 Schedule* BuildGraphAndSchedule(Graph* graph) { |
117 Isolate* isolate = info.isolate(); | 126 Isolate* isolate = info.isolate(); |
118 CommonOperatorBuilder common(zone()); | 127 CommonOperatorBuilder common(zone()); |
119 | 128 |
120 // Manually construct a schedule for the function below: | 129 // Manually construct a schedule for the function below: |
121 // function foo() { | 130 // function foo() { |
122 // deopt(); | 131 // deopt(); |
123 // } | 132 // } |
124 | 133 |
125 MachineType parameter_reps[] = {kMachAnyTagged}; | 134 CSignature1<Object*, Object*> sig; |
126 MachineCallDescriptorBuilder descriptor_builder(kMachAnyTagged, 1, | 135 RawMachineAssembler m(graph, &sig); |
127 parameter_reps); | |
128 | |
129 RawMachineAssembler m(graph, &descriptor_builder); | |
130 | 136 |
131 Handle<Object> undef_object = | 137 Handle<Object> undef_object = |
132 Handle<Object>(isolate->heap()->undefined_value(), isolate); | 138 Handle<Object>(isolate->heap()->undefined_value(), isolate); |
133 PrintableUnique<Object> undef_constant = | 139 PrintableUnique<Object> undef_constant = |
134 PrintableUnique<Object>::CreateUninitialized(zone(), undef_object); | 140 PrintableUnique<Object>::CreateUninitialized(zone(), undef_object); |
135 Node* undef_node = m.NewNode(common.HeapConstant(undef_constant)); | 141 Node* undef_node = m.NewNode(common.HeapConstant(undef_constant)); |
136 | 142 |
137 Handle<JSFunction> deopt_function = | 143 Handle<JSFunction> deopt_function = |
138 NewFunction("function deopt() { %DeoptimizeFunction(foo); }; deopt"); | 144 NewFunction("function deopt() { %DeoptimizeFunction(foo); }; deopt"); |
139 PrintableUnique<Object> deopt_fun_constant = | 145 PrintableUnique<Object> deopt_fun_constant = |
140 PrintableUnique<Object>::CreateUninitialized(zone(), deopt_function); | 146 PrintableUnique<Object>::CreateUninitialized(zone(), deopt_function); |
141 Node* deopt_fun_node = m.NewNode(common.HeapConstant(deopt_fun_constant)); | 147 Node* deopt_fun_node = m.NewNode(common.HeapConstant(deopt_fun_constant)); |
142 | 148 |
| 149 Handle<Context> context(deopt_function->context(), isolate); |
| 150 PrintableUnique<Object> context_constant = |
| 151 PrintableUnique<Object>::CreateUninitialized(zone(), context); |
| 152 Node* context_node = m.NewNode(common.HeapConstant(context_constant)); |
143 | 153 |
144 bailout_id = GetCallBailoutId(); | 154 bailout_id = GetCallBailoutId(); |
145 Node* parameters = m.NewNode(common.StateValues(1), undef_node); | 155 Node* parameters = m.NewNode(common.StateValues(1), undef_node); |
146 Node* locals = m.NewNode(common.StateValues(0)); | 156 Node* locals = m.NewNode(common.StateValues(0)); |
147 Node* stack = m.NewNode(common.StateValues(0)); | 157 Node* stack = m.NewNode(common.StateValues(0)); |
148 | 158 |
149 Node* state_node = m.NewNode(common.FrameState(bailout_id, kIgnoreOutput), | 159 Node* state_node = m.NewNode(common.FrameState(bailout_id, kIgnoreOutput), |
150 parameters, locals, stack, undef_node); | 160 parameters, locals, stack, undef_node); |
151 | 161 |
152 m.CallJS0(deopt_fun_node, undef_node, state_node); | 162 m.CallJS0(deopt_fun_node, undef_node, context_node, state_node); |
153 | 163 |
154 m.Return(undef_node); | 164 m.Return(undef_node); |
155 | 165 |
156 // Schedule the graph: | 166 // Schedule the graph: |
157 Schedule* schedule = m.Export(); | 167 Schedule* schedule = m.Export(); |
158 | 168 |
159 return schedule; | 169 return schedule; |
160 } | 170 } |
161 | 171 |
162 BailoutId GetCallBailoutId() { | 172 BailoutId GetCallBailoutId() { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 | 241 |
232 Schedule* BuildGraphAndSchedule(Graph* graph) { | 242 Schedule* BuildGraphAndSchedule(Graph* graph) { |
233 Isolate* isolate = info.isolate(); | 243 Isolate* isolate = info.isolate(); |
234 CommonOperatorBuilder common(zone()); | 244 CommonOperatorBuilder common(zone()); |
235 | 245 |
236 // Manually construct a schedule for the function below: | 246 // Manually construct a schedule for the function below: |
237 // function foo() { | 247 // function foo() { |
238 // %DeoptimizeFunction(foo); | 248 // %DeoptimizeFunction(foo); |
239 // } | 249 // } |
240 | 250 |
241 MachineType parameter_reps[] = {kMachAnyTagged}; | 251 CSignature1<Object*, Object*> sig; |
242 MachineCallDescriptorBuilder descriptor_builder(kMachAnyTagged, 2, | 252 RawMachineAssembler m(graph, &sig); |
243 parameter_reps); | |
244 | |
245 RawMachineAssembler m(graph, &descriptor_builder); | |
246 | 253 |
247 Handle<Object> undef_object = | 254 Handle<Object> undef_object = |
248 Handle<Object>(isolate->heap()->undefined_value(), isolate); | 255 Handle<Object>(isolate->heap()->undefined_value(), isolate); |
249 PrintableUnique<Object> undef_constant = | 256 PrintableUnique<Object> undef_constant = |
250 PrintableUnique<Object>::CreateUninitialized(zone(), undef_object); | 257 PrintableUnique<Object>::CreateUninitialized(zone(), undef_object); |
251 Node* undef_node = m.NewNode(common.HeapConstant(undef_constant)); | 258 Node* undef_node = m.NewNode(common.HeapConstant(undef_constant)); |
252 | 259 |
253 PrintableUnique<Object> this_fun_constant = | 260 PrintableUnique<Object> this_fun_constant = |
254 PrintableUnique<Object>::CreateUninitialized(zone(), function); | 261 PrintableUnique<Object>::CreateUninitialized(zone(), function); |
255 Node* this_fun_node = m.NewNode(common.HeapConstant(this_fun_constant)); | 262 Node* this_fun_node = m.NewNode(common.HeapConstant(this_fun_constant)); |
256 | 263 |
| 264 Handle<Context> context(function->context(), isolate); |
| 265 PrintableUnique<Object> context_constant = |
| 266 PrintableUnique<Object>::CreateUninitialized(zone(), context); |
| 267 Node* context_node = m.NewNode(common.HeapConstant(context_constant)); |
| 268 |
257 bailout_id = GetCallBailoutId(); | 269 bailout_id = GetCallBailoutId(); |
258 Node* parameters = m.NewNode(common.StateValues(1), undef_node); | 270 Node* parameters = m.NewNode(common.StateValues(1), undef_node); |
259 Node* locals = m.NewNode(common.StateValues(0)); | 271 Node* locals = m.NewNode(common.StateValues(0)); |
260 Node* stack = m.NewNode(common.StateValues(0)); | 272 Node* stack = m.NewNode(common.StateValues(0)); |
261 | 273 |
262 Node* state_node = m.NewNode(common.FrameState(bailout_id, kIgnoreOutput), | 274 Node* state_node = m.NewNode(common.FrameState(bailout_id, kIgnoreOutput), |
263 parameters, locals, stack, undef_node); | 275 parameters, locals, stack, undef_node); |
264 | 276 |
265 m.CallRuntime1(Runtime::kDeoptimizeFunction, this_fun_node, state_node); | 277 m.CallRuntime1(Runtime::kDeoptimizeFunction, this_fun_node, context_node, |
| 278 state_node); |
266 | 279 |
267 m.Return(undef_node); | 280 m.Return(undef_node); |
268 | 281 |
269 // Schedule the graph: | 282 // Schedule the graph: |
270 Schedule* schedule = m.Export(); | 283 Schedule* schedule = m.Export(); |
271 | 284 |
272 return schedule; | 285 return schedule; |
273 } | 286 } |
274 | 287 |
275 BailoutId GetCallBailoutId() { | 288 BailoutId GetCallBailoutId() { |
(...skipping 27 matching lines...) Expand all Loading... |
303 Handle<Object> result; | 316 Handle<Object> result; |
304 bool has_pending_exception = | 317 bool has_pending_exception = |
305 !Execution::Call(isolate, t.function, | 318 !Execution::Call(isolate, t.function, |
306 isolate->factory()->undefined_value(), 0, NULL, | 319 isolate->factory()->undefined_value(), 0, NULL, |
307 false).ToHandle(&result); | 320 false).ToHandle(&result); |
308 CHECK(!has_pending_exception); | 321 CHECK(!has_pending_exception); |
309 CHECK(result->SameValue(Smi::FromInt(42))); | 322 CHECK(result->SameValue(Smi::FromInt(42))); |
310 } | 323 } |
311 | 324 |
312 #endif | 325 #endif |
OLD | NEW |