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/compiler/code-generator.h" | 5 #include "src/compiler/code-generator.h" |
6 | 6 |
7 #include "src/arm/macro-assembler-arm.h" | 7 #include "src/arm/macro-assembler-arm.h" |
8 #include "src/compiler/code-generator-impl.h" | 8 #include "src/compiler/code-generator-impl.h" |
9 #include "src/compiler/gap-resolver.h" | 9 #include "src/compiler/gap-resolver.h" |
10 #include "src/compiler/node-matchers.h" | 10 #include "src/compiler/node-matchers.h" |
| 11 #include "src/compiler/osr.h" |
11 #include "src/scopes.h" | 12 #include "src/scopes.h" |
12 | 13 |
13 namespace v8 { | 14 namespace v8 { |
14 namespace internal { | 15 namespace internal { |
15 namespace compiler { | 16 namespace compiler { |
16 | 17 |
17 #define __ masm()-> | 18 #define __ masm()-> |
18 | 19 |
19 | 20 |
20 #define kScratchReg r9 | 21 #define kScratchReg r9 |
(...skipping 916 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
937 void CodeGenerator::AssembleDeoptimizerCall( | 938 void CodeGenerator::AssembleDeoptimizerCall( |
938 int deoptimization_id, Deoptimizer::BailoutType bailout_type) { | 939 int deoptimization_id, Deoptimizer::BailoutType bailout_type) { |
939 Address deopt_entry = Deoptimizer::GetDeoptimizationEntry( | 940 Address deopt_entry = Deoptimizer::GetDeoptimizationEntry( |
940 isolate(), deoptimization_id, bailout_type); | 941 isolate(), deoptimization_id, bailout_type); |
941 __ Call(deopt_entry, RelocInfo::RUNTIME_ENTRY); | 942 __ Call(deopt_entry, RelocInfo::RUNTIME_ENTRY); |
942 } | 943 } |
943 | 944 |
944 | 945 |
945 void CodeGenerator::AssemblePrologue() { | 946 void CodeGenerator::AssemblePrologue() { |
946 CallDescriptor* descriptor = linkage()->GetIncomingDescriptor(); | 947 CallDescriptor* descriptor = linkage()->GetIncomingDescriptor(); |
947 int stack_slots = frame()->GetSpillSlotCount(); | |
948 if (descriptor->kind() == CallDescriptor::kCallAddress) { | 948 if (descriptor->kind() == CallDescriptor::kCallAddress) { |
949 bool saved_pp; | |
950 if (FLAG_enable_embedded_constant_pool) { | 949 if (FLAG_enable_embedded_constant_pool) { |
951 __ Push(lr, fp, pp); | 950 __ Push(lr, fp, pp); |
952 // Adjust FP to point to saved FP. | 951 // Adjust FP to point to saved FP. |
953 __ sub(fp, sp, Operand(StandardFrameConstants::kConstantPoolOffset)); | 952 __ sub(fp, sp, Operand(StandardFrameConstants::kConstantPoolOffset)); |
954 saved_pp = true; | |
955 } else { | 953 } else { |
956 __ Push(lr, fp); | 954 __ Push(lr, fp); |
957 __ mov(fp, sp); | 955 __ mov(fp, sp); |
958 saved_pp = false; | |
959 } | |
960 int register_save_area_size = saved_pp ? kPointerSize : 0; | |
961 const RegList saves = descriptor->CalleeSavedRegisters(); | |
962 if (saves != 0 || saved_pp) { | |
963 // Save callee-saved registers. | |
964 __ stm(db_w, sp, saves); | |
965 register_save_area_size += | |
966 kPointerSize * base::bits::CountPopulation32(saves); | |
967 } | |
968 const RegList saves_fp = descriptor->CalleeSavedFPRegisters(); | |
969 if (saves_fp != 0) { | |
970 // Save callee-saved FP registers. | |
971 STATIC_ASSERT(DwVfpRegister::kMaxNumRegisters == 32); | |
972 uint32_t last = base::bits::CountLeadingZeros32(saves_fp) - 1; | |
973 uint32_t first = base::bits::CountTrailingZeros32(saves_fp); | |
974 DCHECK_EQ((last - first + 1), base::bits::CountPopulation32(saves_fp)); | |
975 | |
976 __ vstm(db_w, sp, DwVfpRegister::from_code(first), | |
977 DwVfpRegister::from_code(last)); | |
978 register_save_area_size += 2 * kPointerSize * (last - first + 1); | |
979 } | |
980 if (register_save_area_size > 0) { | |
981 frame()->SetRegisterSaveAreaSize(register_save_area_size); | |
982 } | 956 } |
983 } else if (descriptor->IsJSFunctionCall()) { | 957 } else if (descriptor->IsJSFunctionCall()) { |
984 CompilationInfo* info = this->info(); | 958 CompilationInfo* info = this->info(); |
985 __ Prologue(info->IsCodePreAgingActive()); | 959 __ Prologue(info->IsCodePreAgingActive()); |
986 frame()->SetRegisterSaveAreaSize( | |
987 StandardFrameConstants::kFixedFrameSizeFromFp); | |
988 } else if (needs_frame_) { | 960 } else if (needs_frame_) { |
989 __ StubPrologue(); | 961 __ StubPrologue(); |
990 frame()->SetRegisterSaveAreaSize( | |
991 StandardFrameConstants::kFixedFrameSizeFromFp); | |
992 } else { | 962 } else { |
993 frame()->SetPCOnStack(false); | 963 frame()->SetElidedFrameSizeInSlots(0); |
994 } | 964 } |
995 | 965 |
| 966 int stack_shrink_slots = frame()->GetSpillSlotCount(); |
996 if (info()->is_osr()) { | 967 if (info()->is_osr()) { |
997 // TurboFan OSR-compiled functions cannot be entered directly. | 968 // TurboFan OSR-compiled functions cannot be entered directly. |
998 __ Abort(kShouldNotDirectlyEnterOsrFunction); | 969 __ Abort(kShouldNotDirectlyEnterOsrFunction); |
999 | 970 |
1000 // Unoptimized code jumps directly to this entrypoint while the unoptimized | 971 // Unoptimized code jumps directly to this entrypoint while the unoptimized |
1001 // frame is still on the stack. Optimized code uses OSR values directly from | 972 // frame is still on the stack. Optimized code uses OSR values directly from |
1002 // the unoptimized frame. Thus, all that needs to be done is to allocate the | 973 // the unoptimized frame. Thus, all that needs to be done is to allocate the |
1003 // remaining stack slots. | 974 // remaining stack slots. |
1004 if (FLAG_code_comments) __ RecordComment("-- OSR entrypoint --"); | 975 if (FLAG_code_comments) __ RecordComment("-- OSR entrypoint --"); |
1005 osr_pc_offset_ = __ pc_offset(); | 976 osr_pc_offset_ = __ pc_offset(); |
1006 // TODO(titzer): cannot address target function == local #-1 | 977 // TODO(titzer): cannot address target function == local #-1 |
1007 __ ldr(r1, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); | 978 __ ldr(r1, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); |
1008 DCHECK(stack_slots >= frame()->GetOsrStackSlotCount()); | 979 stack_shrink_slots -= OsrHelper(info()).UnoptimizedFrameSlots(); |
1009 stack_slots -= frame()->GetOsrStackSlotCount(); | |
1010 } | 980 } |
1011 | 981 |
1012 if (stack_slots > 0) { | 982 const RegList saves_fp = descriptor->CalleeSavedFPRegisters(); |
1013 __ sub(sp, sp, Operand(stack_slots * kPointerSize)); | 983 if (saves_fp != 0) { |
| 984 stack_shrink_slots += frame()->AlignSavedCalleeRegisterSlots(); |
| 985 } |
| 986 if (stack_shrink_slots > 0) { |
| 987 __ sub(sp, sp, Operand(stack_shrink_slots * kPointerSize)); |
| 988 } |
| 989 |
| 990 if (saves_fp != 0) { |
| 991 // Save callee-saved FP registers. |
| 992 STATIC_ASSERT(DwVfpRegister::kMaxNumRegisters == 32); |
| 993 uint32_t last = base::bits::CountLeadingZeros32(saves_fp) - 1; |
| 994 uint32_t first = base::bits::CountTrailingZeros32(saves_fp); |
| 995 DCHECK_EQ((last - first + 1), base::bits::CountPopulation32(saves_fp)); |
| 996 __ vstm(db_w, sp, DwVfpRegister::from_code(first), |
| 997 DwVfpRegister::from_code(last)); |
| 998 frame()->AllocateSavedCalleeRegisterSlots((last - first + 1) * |
| 999 (kDoubleSize / kPointerSize)); |
| 1000 } |
| 1001 const RegList saves = FLAG_enable_embedded_constant_pool |
| 1002 ? (descriptor->CalleeSavedRegisters() & ~pp.bit()) |
| 1003 : descriptor->CalleeSavedRegisters(); |
| 1004 if (saves != 0) { |
| 1005 // Save callee-saved registers. |
| 1006 __ stm(db_w, sp, saves); |
| 1007 frame()->AllocateSavedCalleeRegisterSlots( |
| 1008 base::bits::CountPopulation32(saves)); |
1014 } | 1009 } |
1015 } | 1010 } |
1016 | 1011 |
1017 | 1012 |
1018 void CodeGenerator::AssembleReturn() { | 1013 void CodeGenerator::AssembleReturn() { |
1019 CallDescriptor* descriptor = linkage()->GetIncomingDescriptor(); | 1014 CallDescriptor* descriptor = linkage()->GetIncomingDescriptor(); |
1020 int stack_slots = frame()->GetSpillSlotCount(); | |
1021 int pop_count = static_cast<int>(descriptor->StackParameterCount()); | 1015 int pop_count = static_cast<int>(descriptor->StackParameterCount()); |
| 1016 |
| 1017 // Restore registers. |
| 1018 const RegList saves = FLAG_enable_embedded_constant_pool |
| 1019 ? (descriptor->CalleeSavedRegisters() & ~pp.bit()) |
| 1020 : descriptor->CalleeSavedRegisters(); |
| 1021 if (saves != 0) { |
| 1022 __ ldm(ia_w, sp, saves); |
| 1023 } |
| 1024 |
| 1025 // Restore FP registers. |
| 1026 const RegList saves_fp = descriptor->CalleeSavedFPRegisters(); |
| 1027 if (saves_fp != 0) { |
| 1028 STATIC_ASSERT(DwVfpRegister::kMaxNumRegisters == 32); |
| 1029 uint32_t last = base::bits::CountLeadingZeros32(saves_fp) - 1; |
| 1030 uint32_t first = base::bits::CountTrailingZeros32(saves_fp); |
| 1031 __ vldm(ia_w, sp, DwVfpRegister::from_code(first), |
| 1032 DwVfpRegister::from_code(last)); |
| 1033 } |
| 1034 |
1022 if (descriptor->kind() == CallDescriptor::kCallAddress) { | 1035 if (descriptor->kind() == CallDescriptor::kCallAddress) { |
1023 if (frame()->GetRegisterSaveAreaSize() > 0) { | |
1024 // Remove this frame's spill slots first. | |
1025 if (stack_slots > 0) { | |
1026 __ add(sp, sp, Operand(stack_slots * kPointerSize)); | |
1027 } | |
1028 // Restore FP registers. | |
1029 const RegList saves_fp = descriptor->CalleeSavedFPRegisters(); | |
1030 if (saves_fp != 0) { | |
1031 STATIC_ASSERT(DwVfpRegister::kMaxNumRegisters == 32); | |
1032 uint32_t last = base::bits::CountLeadingZeros32(saves_fp) - 1; | |
1033 uint32_t first = base::bits::CountTrailingZeros32(saves_fp); | |
1034 __ vldm(ia_w, sp, DwVfpRegister::from_code(first), | |
1035 DwVfpRegister::from_code(last)); | |
1036 } | |
1037 // Restore registers. | |
1038 const RegList saves = descriptor->CalleeSavedRegisters(); | |
1039 if (saves != 0) { | |
1040 __ ldm(ia_w, sp, saves); | |
1041 } | |
1042 } | |
1043 __ LeaveFrame(StackFrame::MANUAL); | 1036 __ LeaveFrame(StackFrame::MANUAL); |
1044 } else if (descriptor->IsJSFunctionCall() || needs_frame_) { | 1037 } else if (descriptor->IsJSFunctionCall() || needs_frame_) { |
1045 // Canonicalize JSFunction return sites for now. | 1038 // Canonicalize JSFunction return sites for now. |
1046 if (return_label_.is_bound()) { | 1039 if (return_label_.is_bound()) { |
1047 __ b(&return_label_); | 1040 __ b(&return_label_); |
1048 return; | 1041 return; |
1049 } else { | 1042 } else { |
1050 __ bind(&return_label_); | 1043 __ bind(&return_label_); |
1051 __ LeaveFrame(StackFrame::MANUAL); | 1044 __ LeaveFrame(StackFrame::MANUAL); |
1052 } | 1045 } |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1258 } | 1251 } |
1259 } | 1252 } |
1260 } | 1253 } |
1261 } | 1254 } |
1262 | 1255 |
1263 #undef __ | 1256 #undef __ |
1264 | 1257 |
1265 } // namespace compiler | 1258 } // namespace compiler |
1266 } // namespace internal | 1259 } // namespace internal |
1267 } // namespace v8 | 1260 } // namespace v8 |
OLD | NEW |