| 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 if (FLAG_print_opt_code || FLAG_trace_turbo) { |
| 90 result_code->Print(); | 97 result_code->Print(); |
| 91 #endif | 98 } |
| 92 } | 99 } |
| 93 | 100 |
| 94 Zone* zone() { return scope_->main_zone(); } | 101 Zone* zone() { return scope_->main_zone(); } |
| 95 | 102 |
| 96 HandleAndZoneScope* scope_; | 103 HandleAndZoneScope* scope_; |
| 97 Handle<JSFunction> function; | 104 Handle<JSFunction> function; |
| 98 CompilationInfo info; | 105 CompilationInfo info; |
| 99 BailoutId bailout_id; | 106 BailoutId bailout_id; |
| 100 Handle<Code> result_code; | 107 Handle<Code> result_code; |
| 101 v8::internal::compiler::InstructionSequence* code; | 108 v8::internal::compiler::InstructionSequence* code; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 115 | 122 |
| 116 Schedule* BuildGraphAndSchedule(Graph* graph) { | 123 Schedule* BuildGraphAndSchedule(Graph* graph) { |
| 117 Isolate* isolate = info.isolate(); | 124 Isolate* isolate = info.isolate(); |
| 118 CommonOperatorBuilder common(zone()); | 125 CommonOperatorBuilder common(zone()); |
| 119 | 126 |
| 120 // Manually construct a schedule for the function below: | 127 // Manually construct a schedule for the function below: |
| 121 // function foo() { | 128 // function foo() { |
| 122 // deopt(); | 129 // deopt(); |
| 123 // } | 130 // } |
| 124 | 131 |
| 125 MachineType parameter_reps[] = {kMachAnyTagged}; | 132 CSignature1<Object*, Object*> sig; |
| 126 MachineCallDescriptorBuilder descriptor_builder(kMachAnyTagged, 1, | 133 RawMachineAssembler m(graph, &sig); |
| 127 parameter_reps); | |
| 128 | |
| 129 RawMachineAssembler m(graph, &descriptor_builder); | |
| 130 | 134 |
| 131 Handle<Object> undef_object = | 135 Handle<Object> undef_object = |
| 132 Handle<Object>(isolate->heap()->undefined_value(), isolate); | 136 Handle<Object>(isolate->heap()->undefined_value(), isolate); |
| 133 PrintableUnique<Object> undef_constant = | 137 PrintableUnique<Object> undef_constant = |
| 134 PrintableUnique<Object>::CreateUninitialized(zone(), undef_object); | 138 PrintableUnique<Object>::CreateUninitialized(zone(), undef_object); |
| 135 Node* undef_node = m.NewNode(common.HeapConstant(undef_constant)); | 139 Node* undef_node = m.NewNode(common.HeapConstant(undef_constant)); |
| 136 | 140 |
| 137 Handle<JSFunction> deopt_function = | 141 Handle<JSFunction> deopt_function = |
| 138 NewFunction("function deopt() { %DeoptimizeFunction(foo); }; deopt"); | 142 NewFunction("function deopt() { %DeoptimizeFunction(foo); }; deopt"); |
| 139 PrintableUnique<Object> deopt_fun_constant = | 143 PrintableUnique<Object> deopt_fun_constant = |
| 140 PrintableUnique<Object>::CreateUninitialized(zone(), deopt_function); | 144 PrintableUnique<Object>::CreateUninitialized(zone(), deopt_function); |
| 141 Node* deopt_fun_node = m.NewNode(common.HeapConstant(deopt_fun_constant)); | 145 Node* deopt_fun_node = m.NewNode(common.HeapConstant(deopt_fun_constant)); |
| 142 | 146 |
| 147 Handle<Context> context(deopt_function->context(), isolate); |
| 148 PrintableUnique<Object> context_constant = |
| 149 PrintableUnique<Object>::CreateUninitialized(zone(), context); |
| 150 Node* context_node = m.NewNode(common.HeapConstant(context_constant)); |
| 143 | 151 |
| 144 bailout_id = GetCallBailoutId(); | 152 bailout_id = GetCallBailoutId(); |
| 145 Node* parameters = m.NewNode(common.StateValues(1), undef_node); | 153 Node* parameters = m.NewNode(common.StateValues(1), undef_node); |
| 146 Node* locals = m.NewNode(common.StateValues(0)); | 154 Node* locals = m.NewNode(common.StateValues(0)); |
| 147 Node* stack = m.NewNode(common.StateValues(0)); | 155 Node* stack = m.NewNode(common.StateValues(0)); |
| 148 | 156 |
| 149 Node* state_node = m.NewNode(common.FrameState(bailout_id, kIgnoreOutput), | 157 Node* state_node = m.NewNode(common.FrameState(bailout_id, kIgnoreOutput), |
| 150 parameters, locals, stack, undef_node); | 158 parameters, locals, stack, undef_node); |
| 151 | 159 |
| 152 m.CallJS0(deopt_fun_node, undef_node, state_node); | 160 m.CallJS0(deopt_fun_node, undef_node, context_node, state_node); |
| 153 | 161 |
| 154 m.Return(undef_node); | 162 m.Return(undef_node); |
| 155 | 163 |
| 156 // Schedule the graph: | 164 // Schedule the graph: |
| 157 Schedule* schedule = m.Export(); | 165 Schedule* schedule = m.Export(); |
| 158 | 166 |
| 159 return schedule; | 167 return schedule; |
| 160 } | 168 } |
| 161 | 169 |
| 162 BailoutId GetCallBailoutId() { | 170 BailoutId GetCallBailoutId() { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 | 239 |
| 232 Schedule* BuildGraphAndSchedule(Graph* graph) { | 240 Schedule* BuildGraphAndSchedule(Graph* graph) { |
| 233 Isolate* isolate = info.isolate(); | 241 Isolate* isolate = info.isolate(); |
| 234 CommonOperatorBuilder common(zone()); | 242 CommonOperatorBuilder common(zone()); |
| 235 | 243 |
| 236 // Manually construct a schedule for the function below: | 244 // Manually construct a schedule for the function below: |
| 237 // function foo() { | 245 // function foo() { |
| 238 // %DeoptimizeFunction(foo); | 246 // %DeoptimizeFunction(foo); |
| 239 // } | 247 // } |
| 240 | 248 |
| 241 MachineType parameter_reps[] = {kMachAnyTagged}; | 249 CSignature1<Object*, Object*> sig; |
| 242 MachineCallDescriptorBuilder descriptor_builder(kMachAnyTagged, 2, | 250 RawMachineAssembler m(graph, &sig); |
| 243 parameter_reps); | |
| 244 | |
| 245 RawMachineAssembler m(graph, &descriptor_builder); | |
| 246 | 251 |
| 247 Handle<Object> undef_object = | 252 Handle<Object> undef_object = |
| 248 Handle<Object>(isolate->heap()->undefined_value(), isolate); | 253 Handle<Object>(isolate->heap()->undefined_value(), isolate); |
| 249 PrintableUnique<Object> undef_constant = | 254 PrintableUnique<Object> undef_constant = |
| 250 PrintableUnique<Object>::CreateUninitialized(zone(), undef_object); | 255 PrintableUnique<Object>::CreateUninitialized(zone(), undef_object); |
| 251 Node* undef_node = m.NewNode(common.HeapConstant(undef_constant)); | 256 Node* undef_node = m.NewNode(common.HeapConstant(undef_constant)); |
| 252 | 257 |
| 253 PrintableUnique<Object> this_fun_constant = | 258 PrintableUnique<Object> this_fun_constant = |
| 254 PrintableUnique<Object>::CreateUninitialized(zone(), function); | 259 PrintableUnique<Object>::CreateUninitialized(zone(), function); |
| 255 Node* this_fun_node = m.NewNode(common.HeapConstant(this_fun_constant)); | 260 Node* this_fun_node = m.NewNode(common.HeapConstant(this_fun_constant)); |
| 256 | 261 |
| 262 Handle<Context> context(function->context(), isolate); |
| 263 PrintableUnique<Object> context_constant = |
| 264 PrintableUnique<Object>::CreateUninitialized(zone(), context); |
| 265 Node* context_node = m.NewNode(common.HeapConstant(context_constant)); |
| 266 |
| 257 bailout_id = GetCallBailoutId(); | 267 bailout_id = GetCallBailoutId(); |
| 258 Node* parameters = m.NewNode(common.StateValues(1), undef_node); | 268 Node* parameters = m.NewNode(common.StateValues(1), undef_node); |
| 259 Node* locals = m.NewNode(common.StateValues(0)); | 269 Node* locals = m.NewNode(common.StateValues(0)); |
| 260 Node* stack = m.NewNode(common.StateValues(0)); | 270 Node* stack = m.NewNode(common.StateValues(0)); |
| 261 | 271 |
| 262 Node* state_node = m.NewNode(common.FrameState(bailout_id, kIgnoreOutput), | 272 Node* state_node = m.NewNode(common.FrameState(bailout_id, kIgnoreOutput), |
| 263 parameters, locals, stack, undef_node); | 273 parameters, locals, stack, undef_node); |
| 264 | 274 |
| 265 m.CallRuntime1(Runtime::kDeoptimizeFunction, this_fun_node, state_node); | 275 m.CallRuntime1(Runtime::kDeoptimizeFunction, this_fun_node, context_node, |
| 276 state_node); |
| 266 | 277 |
| 267 m.Return(undef_node); | 278 m.Return(undef_node); |
| 268 | 279 |
| 269 // Schedule the graph: | 280 // Schedule the graph: |
| 270 Schedule* schedule = m.Export(); | 281 Schedule* schedule = m.Export(); |
| 271 | 282 |
| 272 return schedule; | 283 return schedule; |
| 273 } | 284 } |
| 274 | 285 |
| 275 BailoutId GetCallBailoutId() { | 286 BailoutId GetCallBailoutId() { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 303 Handle<Object> result; | 314 Handle<Object> result; |
| 304 bool has_pending_exception = | 315 bool has_pending_exception = |
| 305 !Execution::Call(isolate, t.function, | 316 !Execution::Call(isolate, t.function, |
| 306 isolate->factory()->undefined_value(), 0, NULL, | 317 isolate->factory()->undefined_value(), 0, NULL, |
| 307 false).ToHandle(&result); | 318 false).ToHandle(&result); |
| 308 CHECK(!has_pending_exception); | 319 CHECK(!has_pending_exception); |
| 309 CHECK(result->SameValue(Smi::FromInt(42))); | 320 CHECK(result->SameValue(Smi::FromInt(42))); |
| 310 } | 321 } |
| 311 | 322 |
| 312 #endif | 323 #endif |
| OLD | NEW |