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