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/address-map.h" | 7 #include "src/address-map.h" |
8 #include "src/compiler/code-generator-impl.h" | 8 #include "src/compiler/code-generator-impl.h" |
9 #include "src/compiler/linkage.h" | 9 #include "src/compiler/linkage.h" |
10 #include "src/compiler/pipeline.h" | 10 #include "src/compiler/pipeline.h" |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 AssembleConstructFrame(); | 149 AssembleConstructFrame(); |
150 // We need to setup the root register after we assemble the prologue, to | 150 // We need to setup the root register after we assemble the prologue, to |
151 // avoid clobbering callee saved registers in case of C linkage and | 151 // avoid clobbering callee saved registers in case of C linkage and |
152 // using the roots. | 152 // using the roots. |
153 // TODO(mtrofin): investigate how we can avoid doing this repeatedly. | 153 // TODO(mtrofin): investigate how we can avoid doing this repeatedly. |
154 if (linkage()->GetIncomingDescriptor()->InitializeRootRegister()) { | 154 if (linkage()->GetIncomingDescriptor()->InitializeRootRegister()) { |
155 masm()->InitializeRootRegister(); | 155 masm()->InitializeRootRegister(); |
156 } | 156 } |
157 } | 157 } |
158 | 158 |
| 159 CodeGenResult result; |
159 if (FLAG_enable_embedded_constant_pool && !block->needs_frame()) { | 160 if (FLAG_enable_embedded_constant_pool && !block->needs_frame()) { |
160 ConstantPoolUnavailableScope constant_pool_unavailable(masm()); | 161 ConstantPoolUnavailableScope constant_pool_unavailable(masm()); |
161 AssembleBlock(block); | 162 result = AssembleBlock(block); |
162 } else { | 163 } else { |
163 AssembleBlock(block); | 164 result = AssembleBlock(block); |
164 } | 165 } |
| 166 if (result != kSuccess) return Handle<Code>(); |
165 } | 167 } |
166 } | 168 } |
167 | 169 |
168 // Assemble all out-of-line code. | 170 // Assemble all out-of-line code. |
169 if (ools_) { | 171 if (ools_) { |
170 masm()->RecordComment("-- Out of line code --"); | 172 masm()->RecordComment("-- Out of line code --"); |
171 for (OutOfLineCode* ool = ools_; ool; ool = ool->next()) { | 173 for (OutOfLineCode* ool = ools_; ool; ool = ool->next()) { |
172 masm()->bind(ool->entry()); | 174 masm()->bind(ool->entry()); |
173 ool->Generate(); | 175 ool->Generate(); |
174 if (ool->exit()->is_bound()) masm()->jmp(ool->exit()); | 176 if (ool->exit()->is_bound()) masm()->jmp(ool->exit()); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 RootIndexMap map(isolate()); | 299 RootIndexMap map(isolate()); |
298 int root_index = map.Lookup(*object); | 300 int root_index = map.Lookup(*object); |
299 if (root_index != RootIndexMap::kInvalidRootIndex) { | 301 if (root_index != RootIndexMap::kInvalidRootIndex) { |
300 *index_return = static_cast<Heap::RootListIndex>(root_index); | 302 *index_return = static_cast<Heap::RootListIndex>(root_index); |
301 return true; | 303 return true; |
302 } | 304 } |
303 } | 305 } |
304 return false; | 306 return false; |
305 } | 307 } |
306 | 308 |
307 void CodeGenerator::AssembleBlock(const InstructionBlock* block) { | 309 CodeGenerator::CodeGenResult CodeGenerator::AssembleBlock( |
| 310 const InstructionBlock* block) { |
308 for (int i = block->code_start(); i < block->code_end(); ++i) { | 311 for (int i = block->code_start(); i < block->code_end(); ++i) { |
309 Instruction* instr = code()->InstructionAt(i); | 312 Instruction* instr = code()->InstructionAt(i); |
310 AssembleInstruction(instr, block); | 313 CodeGenResult result = AssembleInstruction(instr, block); |
| 314 if (result != kSuccess) return result; |
311 } | 315 } |
| 316 return kSuccess; |
312 } | 317 } |
313 | 318 |
314 void CodeGenerator::AssembleInstruction(Instruction* instr, | 319 CodeGenerator::CodeGenResult CodeGenerator::AssembleInstruction( |
315 const InstructionBlock* block) { | 320 Instruction* instr, const InstructionBlock* block) { |
316 AssembleGaps(instr); | 321 AssembleGaps(instr); |
317 DCHECK_IMPLIES( | 322 DCHECK_IMPLIES( |
318 block->must_deconstruct_frame(), | 323 block->must_deconstruct_frame(), |
319 instr != code()->InstructionAt(block->last_instruction_index()) || | 324 instr != code()->InstructionAt(block->last_instruction_index()) || |
320 instr->IsRet() || instr->IsJump()); | 325 instr->IsRet() || instr->IsJump()); |
321 if (instr->IsJump() && block->must_deconstruct_frame()) { | 326 if (instr->IsJump() && block->must_deconstruct_frame()) { |
322 AssembleDeconstructFrame(); | 327 AssembleDeconstructFrame(); |
323 } | 328 } |
324 AssembleSourcePosition(instr); | 329 AssembleSourcePosition(instr); |
325 // Assemble architecture-specific code for the instruction. | 330 // Assemble architecture-specific code for the instruction. |
326 AssembleArchInstruction(instr); | 331 CodeGenResult result = AssembleArchInstruction(instr); |
| 332 if (result != kSuccess) return result; |
327 | 333 |
328 FlagsMode mode = FlagsModeField::decode(instr->opcode()); | 334 FlagsMode mode = FlagsModeField::decode(instr->opcode()); |
329 FlagsCondition condition = FlagsConditionField::decode(instr->opcode()); | 335 FlagsCondition condition = FlagsConditionField::decode(instr->opcode()); |
330 switch (mode) { | 336 switch (mode) { |
331 case kFlags_branch: { | 337 case kFlags_branch: { |
332 // Assemble a branch after this instruction. | 338 // Assemble a branch after this instruction. |
333 InstructionOperandConverter i(this, instr); | 339 InstructionOperandConverter i(this, instr); |
334 RpoNumber true_rpo = i.InputRpo(instr->InputCount() - 2); | 340 RpoNumber true_rpo = i.InputRpo(instr->InputCount() - 2); |
335 RpoNumber false_rpo = i.InputRpo(instr->InputCount() - 1); | 341 RpoNumber false_rpo = i.InputRpo(instr->InputCount() - 1); |
336 | 342 |
337 if (true_rpo == false_rpo) { | 343 if (true_rpo == false_rpo) { |
338 // redundant branch. | 344 // redundant branch. |
339 if (!IsNextInAssemblyOrder(true_rpo)) { | 345 if (!IsNextInAssemblyOrder(true_rpo)) { |
340 AssembleArchJump(true_rpo); | 346 AssembleArchJump(true_rpo); |
341 } | 347 } |
342 return; | 348 return kSuccess; |
343 } | 349 } |
344 if (IsNextInAssemblyOrder(true_rpo)) { | 350 if (IsNextInAssemblyOrder(true_rpo)) { |
345 // true block is next, can fall through if condition negated. | 351 // true block is next, can fall through if condition negated. |
346 std::swap(true_rpo, false_rpo); | 352 std::swap(true_rpo, false_rpo); |
347 condition = NegateFlagsCondition(condition); | 353 condition = NegateFlagsCondition(condition); |
348 } | 354 } |
349 BranchInfo branch; | 355 BranchInfo branch; |
350 branch.condition = condition; | 356 branch.condition = condition; |
351 branch.true_label = GetLabel(true_rpo); | 357 branch.true_label = GetLabel(true_rpo); |
352 branch.false_label = GetLabel(false_rpo); | 358 branch.false_label = GetLabel(false_rpo); |
(...skipping 21 matching lines...) Expand all Loading... |
374 } | 380 } |
375 case kFlags_set: { | 381 case kFlags_set: { |
376 // Assemble a boolean materialization after this instruction. | 382 // Assemble a boolean materialization after this instruction. |
377 AssembleArchBoolean(instr, condition); | 383 AssembleArchBoolean(instr, condition); |
378 break; | 384 break; |
379 } | 385 } |
380 case kFlags_none: { | 386 case kFlags_none: { |
381 break; | 387 break; |
382 } | 388 } |
383 } | 389 } |
| 390 return kSuccess; |
384 } | 391 } |
385 | 392 |
386 | 393 |
387 void CodeGenerator::AssembleSourcePosition(Instruction* instr) { | 394 void CodeGenerator::AssembleSourcePosition(Instruction* instr) { |
388 SourcePosition source_position; | 395 SourcePosition source_position; |
389 if (!code()->GetSourcePosition(instr, &source_position)) return; | 396 if (!code()->GetSourcePosition(instr, &source_position)) return; |
390 if (source_position == current_source_position_) return; | 397 if (source_position == current_source_position_) return; |
391 current_source_position_ = source_position; | 398 current_source_position_ = source_position; |
392 if (source_position.IsUnknown()) return; | 399 if (source_position.IsUnknown()) return; |
393 int code_pos = source_position.raw(); | 400 int code_pos = source_position.raw(); |
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
804 : frame_(gen->frame()), masm_(gen->masm()), next_(gen->ools_) { | 811 : frame_(gen->frame()), masm_(gen->masm()), next_(gen->ools_) { |
805 gen->ools_ = this; | 812 gen->ools_ = this; |
806 } | 813 } |
807 | 814 |
808 | 815 |
809 OutOfLineCode::~OutOfLineCode() {} | 816 OutOfLineCode::~OutOfLineCode() {} |
810 | 817 |
811 } // namespace compiler | 818 } // namespace compiler |
812 } // namespace internal | 819 } // namespace internal |
813 } // namespace v8 | 820 } // namespace v8 |
OLD | NEW |