OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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/compiler/code-generator.h" | 5 #include "src/compiler/code-generator.h" |
6 | 6 |
7 #include "src/compiler/code-generator-impl.h" | 7 #include "src/compiler/code-generator-impl.h" |
8 #include "src/compiler/linkage.h" | 8 #include "src/compiler/linkage.h" |
9 #include "src/compiler/pipeline.h" | 9 #include "src/compiler/pipeline.h" |
10 | 10 |
11 namespace v8 { | 11 namespace v8 { |
12 namespace internal { | 12 namespace internal { |
13 namespace compiler { | 13 namespace compiler { |
14 | 14 |
| 15 class CodeGenerator::JumpTable FINAL : public ZoneObject { |
| 16 public: |
| 17 JumpTable(JumpTable* next, Label** targets, size_t target_count) |
| 18 : next_(next), targets_(targets), target_count_(target_count) {} |
| 19 |
| 20 Label* label() { return &label_; } |
| 21 JumpTable* next() const { return next_; } |
| 22 Label** targets() const { return targets_; } |
| 23 size_t target_count() const { return target_count_; } |
| 24 |
| 25 private: |
| 26 Label label_; |
| 27 JumpTable* const next_; |
| 28 Label** const targets_; |
| 29 size_t const target_count_; |
| 30 }; |
| 31 |
| 32 |
15 CodeGenerator::CodeGenerator(Frame* frame, Linkage* linkage, | 33 CodeGenerator::CodeGenerator(Frame* frame, Linkage* linkage, |
16 InstructionSequence* code, CompilationInfo* info) | 34 InstructionSequence* code, CompilationInfo* info) |
17 : frame_(frame), | 35 : frame_(frame), |
18 linkage_(linkage), | 36 linkage_(linkage), |
19 code_(code), | 37 code_(code), |
20 info_(info), | 38 info_(info), |
21 labels_(zone()->NewArray<Label>(code->InstructionBlockCount())), | 39 labels_(zone()->NewArray<Label>(code->InstructionBlockCount())), |
22 current_block_(BasicBlock::RpoNumber::Invalid()), | 40 current_block_(BasicBlock::RpoNumber::Invalid()), |
23 current_source_position_(SourcePosition::Invalid()), | 41 current_source_position_(SourcePosition::Invalid()), |
24 masm_(info->isolate(), NULL, 0), | 42 masm_(info->isolate(), NULL, 0), |
25 resolver_(this), | 43 resolver_(this), |
26 safepoints_(code->zone()), | 44 safepoints_(code->zone()), |
27 deoptimization_states_(code->zone()), | 45 deoptimization_states_(code->zone()), |
28 deoptimization_literals_(code->zone()), | 46 deoptimization_literals_(code->zone()), |
29 translations_(code->zone()), | 47 translations_(code->zone()), |
30 last_lazy_deopt_pc_(0), | 48 last_lazy_deopt_pc_(0), |
| 49 jump_tables_(nullptr), |
31 ools_(nullptr), | 50 ools_(nullptr), |
32 osr_pc_offset_(-1) { | 51 osr_pc_offset_(-1) { |
33 for (int i = 0; i < code->InstructionBlockCount(); ++i) { | 52 for (int i = 0; i < code->InstructionBlockCount(); ++i) { |
34 new (&labels_[i]) Label; | 53 new (&labels_[i]) Label; |
35 } | 54 } |
36 } | 55 } |
37 | 56 |
38 | 57 |
39 Handle<Code> CodeGenerator::GenerateCode() { | 58 Handle<Code> CodeGenerator::GenerateCode() { |
40 CompilationInfo* info = this->info(); | 59 CompilationInfo* info = this->info(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 } | 93 } |
75 } | 94 } |
76 } | 95 } |
77 | 96 |
78 // Assemble all out-of-line code. | 97 // Assemble all out-of-line code. |
79 if (ools_) { | 98 if (ools_) { |
80 masm()->RecordComment("-- Out of line code --"); | 99 masm()->RecordComment("-- Out of line code --"); |
81 for (OutOfLineCode* ool = ools_; ool; ool = ool->next()) { | 100 for (OutOfLineCode* ool = ools_; ool; ool = ool->next()) { |
82 masm()->bind(ool->entry()); | 101 masm()->bind(ool->entry()); |
83 ool->Generate(); | 102 ool->Generate(); |
84 masm()->jmp(ool->exit()); | 103 if (ool->exit()->is_bound()) masm()->jmp(ool->exit()); |
85 } | 104 } |
86 } | 105 } |
87 | 106 |
88 // Ensure there is space for lazy deoptimization in the code. | 107 // Ensure there is space for lazy deoptimization in the code. |
89 if (!info->IsStub()) { | 108 if (!info->IsStub()) { |
90 int target_offset = masm()->pc_offset() + Deoptimizer::patch_size(); | 109 int target_offset = masm()->pc_offset() + Deoptimizer::patch_size(); |
91 while (masm()->pc_offset() < target_offset) { | 110 while (masm()->pc_offset() < target_offset) { |
92 masm()->nop(); | 111 masm()->nop(); |
93 } | 112 } |
94 } | 113 } |
95 | 114 |
96 FinishCode(masm()); | 115 FinishCode(masm()); |
97 | 116 |
| 117 // Emit the jump tables. |
| 118 if (jump_tables_) { |
| 119 masm()->Align(kPointerSize); |
| 120 for (JumpTable* table = jump_tables_; table; table = table->next()) { |
| 121 masm()->bind(table->label()); |
| 122 AssembleJumpTable(table->targets(), table->target_count()); |
| 123 } |
| 124 } |
| 125 |
98 safepoints()->Emit(masm(), frame()->GetSpillSlotCount()); | 126 safepoints()->Emit(masm(), frame()->GetSpillSlotCount()); |
99 | 127 |
100 // TODO(titzer): what are the right code flags here? | 128 // TODO(titzer): what are the right code flags here? |
101 Code::Kind kind = Code::STUB; | 129 Code::Kind kind = Code::STUB; |
102 if (linkage()->GetIncomingDescriptor()->IsJSFunctionCall()) { | 130 if (linkage()->GetIncomingDescriptor()->IsJSFunctionCall()) { |
103 kind = Code::OPTIMIZED_FUNCTION; | 131 kind = Code::OPTIMIZED_FUNCTION; |
104 } | 132 } |
105 Handle<Code> result = v8::internal::CodeGenerator::MakeCodeEpilogue( | 133 Handle<Code> result = v8::internal::CodeGenerator::MakeCodeEpilogue( |
106 masm(), Code::ComputeFlags(kind), info); | 134 masm(), Code::ComputeFlags(kind), info); |
107 result->set_is_turbofanned(true); | 135 result->set_is_turbofanned(true); |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 data->SetTranslationIndex( | 313 data->SetTranslationIndex( |
286 i, Smi::FromInt(deoptimization_states_[i]->translation_id())); | 314 i, Smi::FromInt(deoptimization_states_[i]->translation_id())); |
287 data->SetArgumentsStackHeight(i, Smi::FromInt(0)); | 315 data->SetArgumentsStackHeight(i, Smi::FromInt(0)); |
288 data->SetPc(i, Smi::FromInt(deoptimization_state->pc_offset())); | 316 data->SetPc(i, Smi::FromInt(deoptimization_state->pc_offset())); |
289 } | 317 } |
290 | 318 |
291 code_object->set_deoptimization_data(*data); | 319 code_object->set_deoptimization_data(*data); |
292 } | 320 } |
293 | 321 |
294 | 322 |
| 323 Label* CodeGenerator::AddJumpTable(Label** targets, size_t target_count) { |
| 324 jump_tables_ = new (zone()) JumpTable(jump_tables_, targets, target_count); |
| 325 return jump_tables_->label(); |
| 326 } |
| 327 |
| 328 |
295 void CodeGenerator::AddSafepointAndDeopt(Instruction* instr) { | 329 void CodeGenerator::AddSafepointAndDeopt(Instruction* instr) { |
296 CallDescriptor::Flags flags(MiscField::decode(instr->opcode())); | 330 CallDescriptor::Flags flags(MiscField::decode(instr->opcode())); |
297 | 331 |
298 bool needs_frame_state = (flags & CallDescriptor::kNeedsFrameState); | 332 bool needs_frame_state = (flags & CallDescriptor::kNeedsFrameState); |
299 | 333 |
300 RecordSafepoint( | 334 RecordSafepoint( |
301 instr->pointer_map(), Safepoint::kSimple, 0, | 335 instr->pointer_map(), Safepoint::kSimple, 0, |
302 needs_frame_state ? Safepoint::kLazyDeopt : Safepoint::kNoLazyDeopt); | 336 needs_frame_state ? Safepoint::kLazyDeopt : Safepoint::kNoLazyDeopt); |
303 | 337 |
304 if (flags & CallDescriptor::kNeedsNopAfterCall) { | 338 if (flags & CallDescriptor::kNeedsNopAfterCall) { |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 : masm_(gen->masm()), next_(gen->ools_) { | 618 : masm_(gen->masm()), next_(gen->ools_) { |
585 gen->ools_ = this; | 619 gen->ools_ = this; |
586 } | 620 } |
587 | 621 |
588 | 622 |
589 OutOfLineCode::~OutOfLineCode() {} | 623 OutOfLineCode::~OutOfLineCode() {} |
590 | 624 |
591 } // namespace compiler | 625 } // namespace compiler |
592 } // namespace internal | 626 } // namespace internal |
593 } // namespace v8 | 627 } // namespace v8 |
OLD | NEW |