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 #include "src/compiler/code-generator-impl.h" | 6 #include "src/compiler/code-generator-impl.h" |
7 #include "src/compiler/gap-resolver.h" | 7 #include "src/compiler/gap-resolver.h" |
8 #include "src/compiler/node-matchers.h" | 8 #include "src/compiler/node-matchers.h" |
| 9 #include "src/compiler/osr.h" |
9 #include "src/mips/macro-assembler-mips.h" | 10 #include "src/mips/macro-assembler-mips.h" |
10 #include "src/scopes.h" | 11 #include "src/scopes.h" |
11 | 12 |
12 namespace v8 { | 13 namespace v8 { |
13 namespace internal { | 14 namespace internal { |
14 namespace compiler { | 15 namespace compiler { |
15 | 16 |
16 #define __ masm()-> | 17 #define __ masm()-> |
17 | 18 |
18 | 19 |
(...skipping 1118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1137 void CodeGenerator::AssembleDeoptimizerCall( | 1138 void CodeGenerator::AssembleDeoptimizerCall( |
1138 int deoptimization_id, Deoptimizer::BailoutType bailout_type) { | 1139 int deoptimization_id, Deoptimizer::BailoutType bailout_type) { |
1139 Address deopt_entry = Deoptimizer::GetDeoptimizationEntry( | 1140 Address deopt_entry = Deoptimizer::GetDeoptimizationEntry( |
1140 isolate(), deoptimization_id, bailout_type); | 1141 isolate(), deoptimization_id, bailout_type); |
1141 __ Call(deopt_entry, RelocInfo::RUNTIME_ENTRY); | 1142 __ Call(deopt_entry, RelocInfo::RUNTIME_ENTRY); |
1142 } | 1143 } |
1143 | 1144 |
1144 | 1145 |
1145 void CodeGenerator::AssemblePrologue() { | 1146 void CodeGenerator::AssemblePrologue() { |
1146 CallDescriptor* descriptor = linkage()->GetIncomingDescriptor(); | 1147 CallDescriptor* descriptor = linkage()->GetIncomingDescriptor(); |
1147 int stack_slots = frame()->GetSpillSlotCount(); | |
1148 if (descriptor->kind() == CallDescriptor::kCallAddress) { | 1148 if (descriptor->kind() == CallDescriptor::kCallAddress) { |
1149 __ Push(ra, fp); | 1149 __ Push(ra, fp); |
1150 __ mov(fp, sp); | 1150 __ mov(fp, sp); |
1151 | |
1152 const RegList saves = descriptor->CalleeSavedRegisters(); | |
1153 // Save callee-saved registers. | |
1154 __ MultiPush(saves); | |
1155 // kNumCalleeSaved includes the fp register, but the fp register | |
1156 // is saved separately in TF. | |
1157 DCHECK(kNumCalleeSaved == base::bits::CountPopulation32(saves) + 1); | |
1158 int register_save_area_size = | |
1159 base::bits::CountPopulation32(saves) * kPointerSize; | |
1160 | |
1161 const RegList saves_fpu = descriptor->CalleeSavedFPRegisters(); | |
1162 // Save callee-saved FPU registers. | |
1163 __ MultiPushFPU(saves_fpu); | |
1164 DCHECK(kNumCalleeSavedFPU == base::bits::CountPopulation32(saves_fpu)); | |
1165 register_save_area_size += kNumCalleeSavedFPU * kDoubleSize; | |
1166 | |
1167 frame()->SetRegisterSaveAreaSize(register_save_area_size); | |
1168 } else if (descriptor->IsJSFunctionCall()) { | 1151 } else if (descriptor->IsJSFunctionCall()) { |
1169 CompilationInfo* info = this->info(); | 1152 CompilationInfo* info = this->info(); |
1170 __ Prologue(info->IsCodePreAgingActive()); | 1153 __ Prologue(info->IsCodePreAgingActive()); |
1171 frame()->SetRegisterSaveAreaSize( | |
1172 StandardFrameConstants::kFixedFrameSizeFromFp); | |
1173 } else if (needs_frame_) { | 1154 } else if (needs_frame_) { |
1174 __ StubPrologue(); | 1155 __ StubPrologue(); |
1175 frame()->SetRegisterSaveAreaSize( | |
1176 StandardFrameConstants::kFixedFrameSizeFromFp); | |
1177 } else { | 1156 } else { |
1178 frame()->SetPCOnStack(false); | 1157 frame()->SetElidedFrameSizeInSlots(0); |
1179 } | 1158 } |
1180 | 1159 |
| 1160 int stack_shrink_slots = frame()->GetSpillSlotCount(); |
1181 if (info()->is_osr()) { | 1161 if (info()->is_osr()) { |
1182 // TurboFan OSR-compiled functions cannot be entered directly. | 1162 // TurboFan OSR-compiled functions cannot be entered directly. |
1183 __ Abort(kShouldNotDirectlyEnterOsrFunction); | 1163 __ Abort(kShouldNotDirectlyEnterOsrFunction); |
1184 | 1164 |
1185 // Unoptimized code jumps directly to this entrypoint while the unoptimized | 1165 // Unoptimized code jumps directly to this entrypoint while the unoptimized |
1186 // frame is still on the stack. Optimized code uses OSR values directly from | 1166 // frame is still on the stack. Optimized code uses OSR values directly from |
1187 // the unoptimized frame. Thus, all that needs to be done is to allocate the | 1167 // the unoptimized frame. Thus, all that needs to be done is to allocate the |
1188 // remaining stack slots. | 1168 // remaining stack slots. |
1189 if (FLAG_code_comments) __ RecordComment("-- OSR entrypoint --"); | 1169 if (FLAG_code_comments) __ RecordComment("-- OSR entrypoint --"); |
1190 osr_pc_offset_ = __ pc_offset(); | 1170 osr_pc_offset_ = __ pc_offset(); |
1191 // TODO(titzer): cannot address target function == local #-1 | 1171 // TODO(titzer): cannot address target function == local #-1 |
1192 __ ld(a1, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); | 1172 __ ld(a1, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset)); |
1193 DCHECK(stack_slots >= frame()->GetOsrStackSlotCount()); | 1173 stack_shrink_slots -= OsrHelper(info()).UnoptimizedFrameSlots(); |
1194 stack_slots -= frame()->GetOsrStackSlotCount(); | |
1195 } | 1174 } |
1196 | 1175 |
1197 if (stack_slots > 0) { | 1176 if (stack_shrink_slots > 0) { |
1198 __ Dsubu(sp, sp, Operand(stack_slots * kPointerSize)); | 1177 __ Dsubu(sp, sp, Operand(stack_shrink_slots * kPointerSize)); |
| 1178 } |
| 1179 |
| 1180 const RegList saves_fpu = descriptor->CalleeSavedFPRegisters(); |
| 1181 if (saves_fpu != 0) { |
| 1182 // Save callee-saved FPU registers. |
| 1183 __ MultiPushFPU(saves_fpu); |
| 1184 int count = base::bits::CountPopulation32(saves_fpu); |
| 1185 DCHECK(kNumCalleeSavedFPU == count); |
| 1186 frame()->AllocateSavedCalleeRegisterSlots(count * |
| 1187 (kDoubleSize / kPointerSize)); |
| 1188 } |
| 1189 |
| 1190 const RegList saves = descriptor->CalleeSavedRegisters(); |
| 1191 if (saves != 0) { |
| 1192 // Save callee-saved registers. |
| 1193 __ MultiPush(saves); |
| 1194 // kNumCalleeSaved includes the fp register, but the fp register |
| 1195 // is saved separately in TF. |
| 1196 int count = base::bits::CountPopulation32(saves); |
| 1197 DCHECK(kNumCalleeSaved == count + 1); |
| 1198 frame()->AllocateSavedCalleeRegisterSlots(count); |
1199 } | 1199 } |
1200 } | 1200 } |
1201 | 1201 |
1202 | 1202 |
1203 void CodeGenerator::AssembleReturn() { | 1203 void CodeGenerator::AssembleReturn() { |
1204 CallDescriptor* descriptor = linkage()->GetIncomingDescriptor(); | 1204 CallDescriptor* descriptor = linkage()->GetIncomingDescriptor(); |
1205 int stack_slots = frame()->GetSpillSlotCount(); | 1205 |
1206 int pop_count = static_cast<int>(descriptor->StackParameterCount()); | 1206 // Restore GP registers. |
| 1207 const RegList saves = descriptor->CalleeSavedRegisters(); |
| 1208 if (saves != 0) { |
| 1209 __ MultiPop(saves); |
| 1210 } |
| 1211 |
| 1212 // Restore FPU registers. |
| 1213 const RegList saves_fpu = descriptor->CalleeSavedFPRegisters(); |
| 1214 if (saves_fpu != 0) { |
| 1215 __ MultiPopFPU(saves_fpu); |
| 1216 } |
| 1217 |
1207 if (descriptor->kind() == CallDescriptor::kCallAddress) { | 1218 if (descriptor->kind() == CallDescriptor::kCallAddress) { |
1208 if (frame()->GetRegisterSaveAreaSize() > 0) { | |
1209 // Remove this frame's spill slots first. | |
1210 if (stack_slots > 0) { | |
1211 __ Daddu(sp, sp, Operand(stack_slots * kPointerSize)); | |
1212 } | |
1213 // Restore FPU registers. | |
1214 const RegList saves_fpu = descriptor->CalleeSavedFPRegisters(); | |
1215 __ MultiPopFPU(saves_fpu); | |
1216 | |
1217 // Restore GP registers. | |
1218 const RegList saves = descriptor->CalleeSavedRegisters(); | |
1219 __ MultiPop(saves); | |
1220 } | |
1221 __ mov(sp, fp); | 1219 __ mov(sp, fp); |
1222 __ Pop(ra, fp); | 1220 __ Pop(ra, fp); |
1223 } else if (descriptor->IsJSFunctionCall() || needs_frame_) { | 1221 } else if (descriptor->IsJSFunctionCall() || needs_frame_) { |
1224 // Canonicalize JSFunction return sites for now. | 1222 // Canonicalize JSFunction return sites for now. |
1225 if (return_label_.is_bound()) { | 1223 if (return_label_.is_bound()) { |
1226 __ Branch(&return_label_); | 1224 __ Branch(&return_label_); |
1227 return; | 1225 return; |
1228 } else { | 1226 } else { |
1229 __ bind(&return_label_); | 1227 __ bind(&return_label_); |
1230 __ mov(sp, fp); | 1228 __ mov(sp, fp); |
1231 __ Pop(ra, fp); | 1229 __ Pop(ra, fp); |
1232 } | 1230 } |
1233 } | 1231 } |
| 1232 int pop_count = static_cast<int>(descriptor->StackParameterCount()); |
1234 if (pop_count != 0) { | 1233 if (pop_count != 0) { |
1235 __ DropAndRet(pop_count); | 1234 __ DropAndRet(pop_count); |
1236 } else { | 1235 } else { |
1237 __ Ret(); | 1236 __ Ret(); |
1238 } | 1237 } |
1239 } | 1238 } |
1240 | 1239 |
1241 | 1240 |
1242 void CodeGenerator::AssembleMove(InstructionOperand* source, | 1241 void CodeGenerator::AssembleMove(InstructionOperand* source, |
1243 InstructionOperand* destination) { | 1242 InstructionOperand* destination) { |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1443 } | 1442 } |
1444 } | 1443 } |
1445 } | 1444 } |
1446 } | 1445 } |
1447 | 1446 |
1448 #undef __ | 1447 #undef __ |
1449 | 1448 |
1450 } // namespace compiler | 1449 } // namespace compiler |
1451 } // namespace internal | 1450 } // namespace internal |
1452 } // namespace v8 | 1451 } // namespace v8 |
OLD | NEW |