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/gap-resolver.h" | 8 #include "src/compiler/gap-resolver.h" |
9 #include "src/compiler/node-matchers.h" | 9 #include "src/compiler/node-matchers.h" |
10 #include "src/scopes.h" | 10 #include "src/scopes.h" |
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 __ cmpp(rsi, FieldOperand(func, JSFunction::kContextOffset)); | 525 __ cmpp(rsi, FieldOperand(func, JSFunction::kContextOffset)); |
526 __ Assert(equal, kWrongFunctionContext); | 526 __ Assert(equal, kWrongFunctionContext); |
527 } | 527 } |
528 __ Call(FieldOperand(func, JSFunction::kCodeEntryOffset)); | 528 __ Call(FieldOperand(func, JSFunction::kCodeEntryOffset)); |
529 AddSafepointAndDeopt(instr); | 529 AddSafepointAndDeopt(instr); |
530 break; | 530 break; |
531 } | 531 } |
532 case kArchJmp: | 532 case kArchJmp: |
533 AssembleArchJump(i.InputRpo(0)); | 533 AssembleArchJump(i.InputRpo(0)); |
534 break; | 534 break; |
| 535 case kArchSwitch: |
| 536 AssembleArchSwitch(instr); |
| 537 break; |
535 case kArchNop: | 538 case kArchNop: |
536 // don't emit code for nops. | 539 // don't emit code for nops. |
537 break; | 540 break; |
538 case kArchRet: | 541 case kArchRet: |
539 AssembleReturn(); | 542 AssembleReturn(); |
540 break; | 543 break; |
541 case kArchStackPointer: | 544 case kArchStackPointer: |
542 __ movq(i.OutputRegister(), rsp); | 545 __ movq(i.OutputRegister(), rsp); |
543 break; | 546 break; |
544 case kArchTruncateDoubleToI: { | 547 case kArchTruncateDoubleToI: { |
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1060 } | 1063 } |
1061 if (!branch->fallthru) __ jmp(flabel, flabel_distance); | 1064 if (!branch->fallthru) __ jmp(flabel, flabel_distance); |
1062 } | 1065 } |
1063 | 1066 |
1064 | 1067 |
1065 void CodeGenerator::AssembleArchJump(BasicBlock::RpoNumber target) { | 1068 void CodeGenerator::AssembleArchJump(BasicBlock::RpoNumber target) { |
1066 if (!IsNextInAssemblyOrder(target)) __ jmp(GetLabel(target)); | 1069 if (!IsNextInAssemblyOrder(target)) __ jmp(GetLabel(target)); |
1067 } | 1070 } |
1068 | 1071 |
1069 | 1072 |
| 1073 void CodeGenerator::AssembleArchSwitch(Instruction* instr) { |
| 1074 X64OperandConverter i(this, instr); |
| 1075 size_t const label_count = instr->InputCount() - 1; |
| 1076 Label** labels = zone()->NewArray<Label*>(static_cast<int>(label_count)); |
| 1077 for (size_t index = 0; index < label_count; ++index) { |
| 1078 labels[index] = GetLabel(i.InputRpo(static_cast<int>(index + 1))); |
| 1079 } |
| 1080 Label* const table = AddJumpTable(labels, label_count); |
| 1081 __ leaq(kScratchRegister, Operand(table)); |
| 1082 __ jmp(Operand(kScratchRegister, i.InputRegister(0), times_8, 0)); |
| 1083 } |
| 1084 |
| 1085 |
1070 // Assembles boolean materializations after this instruction. | 1086 // Assembles boolean materializations after this instruction. |
1071 void CodeGenerator::AssembleArchBoolean(Instruction* instr, | 1087 void CodeGenerator::AssembleArchBoolean(Instruction* instr, |
1072 FlagsCondition condition) { | 1088 FlagsCondition condition) { |
1073 X64OperandConverter i(this, instr); | 1089 X64OperandConverter i(this, instr); |
1074 Label done; | 1090 Label done; |
1075 | 1091 |
1076 // Materialize a full 64-bit 1 or 0 value. The result register is always the | 1092 // Materialize a full 64-bit 1 or 0 value. The result register is always the |
1077 // last output of the instruction. | 1093 // last output of the instruction. |
1078 Label check; | 1094 Label check; |
1079 DCHECK_NE(0, static_cast<int>(instr->OutputCount())); | 1095 DCHECK_NE(0, static_cast<int>(instr->OutputCount())); |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1373 __ movsd(xmm0, src); | 1389 __ movsd(xmm0, src); |
1374 __ movsd(src, dst); | 1390 __ movsd(src, dst); |
1375 __ movsd(dst, xmm0); | 1391 __ movsd(dst, xmm0); |
1376 } else { | 1392 } else { |
1377 // No other combinations are possible. | 1393 // No other combinations are possible. |
1378 UNREACHABLE(); | 1394 UNREACHABLE(); |
1379 } | 1395 } |
1380 } | 1396 } |
1381 | 1397 |
1382 | 1398 |
| 1399 void CodeGenerator::AssembleJumpTable(Label** targets, size_t target_count) { |
| 1400 for (size_t index = 0; index < target_count; ++index) { |
| 1401 __ dq(targets[index]); |
| 1402 } |
| 1403 } |
| 1404 |
| 1405 |
1383 void CodeGenerator::AddNopForSmiCodeInlining() { __ nop(); } | 1406 void CodeGenerator::AddNopForSmiCodeInlining() { __ nop(); } |
1384 | 1407 |
1385 | 1408 |
1386 void CodeGenerator::EnsureSpaceForLazyDeopt() { | 1409 void CodeGenerator::EnsureSpaceForLazyDeopt() { |
1387 int space_needed = Deoptimizer::patch_size(); | 1410 int space_needed = Deoptimizer::patch_size(); |
1388 if (!info()->IsStub()) { | 1411 if (!info()->IsStub()) { |
1389 // Ensure that we have enough space after the previous lazy-bailout | 1412 // Ensure that we have enough space after the previous lazy-bailout |
1390 // instruction for patching the code here. | 1413 // instruction for patching the code here. |
1391 int current_pc = masm()->pc_offset(); | 1414 int current_pc = masm()->pc_offset(); |
1392 if (current_pc < last_lazy_deopt_pc_ + space_needed) { | 1415 if (current_pc < last_lazy_deopt_pc_ + space_needed) { |
1393 int padding_size = last_lazy_deopt_pc_ + space_needed - current_pc; | 1416 int padding_size = last_lazy_deopt_pc_ + space_needed - current_pc; |
1394 __ Nop(padding_size); | 1417 __ Nop(padding_size); |
1395 } | 1418 } |
1396 } | 1419 } |
1397 MarkLazyDeoptSite(); | 1420 MarkLazyDeoptSite(); |
1398 } | 1421 } |
1399 | 1422 |
1400 #undef __ | 1423 #undef __ |
1401 | 1424 |
1402 } // namespace internal | 1425 } // namespace internal |
1403 } // namespace compiler | 1426 } // namespace compiler |
1404 } // namespace v8 | 1427 } // namespace v8 |
OLD | NEW |