Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: src/compiler/ia32/code-generator-ia32.cc

Issue 1108563002: Detect simple tail calls (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fixed index type Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/compiler/code-generator.h ('k') | src/compiler/ia32/instruction-selector-ia32.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/ia32/assembler-ia32.h" 10 #include "src/ia32/assembler-ia32.h"
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 __ j(above_equal, &done, Label::kNear); \ 277 __ j(above_equal, &done, Label::kNear); \
278 if (instr->InputAt(2)->IsRegister()) { \ 278 if (instr->InputAt(2)->IsRegister()) { \
279 __ asm_instr(i.MemoryOperand(3), i.InputRegister(2)); \ 279 __ asm_instr(i.MemoryOperand(3), i.InputRegister(2)); \
280 } else { \ 280 } else { \
281 __ asm_instr(i.MemoryOperand(3), i.InputImmediate(2)); \ 281 __ asm_instr(i.MemoryOperand(3), i.InputImmediate(2)); \
282 } \ 282 } \
283 __ bind(&done); \ 283 __ bind(&done); \
284 } while (false) 284 } while (false)
285 285
286 286
287 void CodeGenerator::AssembleDeconstructActivationRecord() {
288 CallDescriptor* descriptor = linkage()->GetIncomingDescriptor();
289 int stack_slots = frame()->GetSpillSlotCount();
290 if (descriptor->IsJSFunctionCall() || stack_slots > 0) {
291 __ mov(esp, ebp);
292 __ pop(ebp);
293 int32_t bytes_to_pop =
294 descriptor->IsJSFunctionCall()
295 ? static_cast<int32_t>(descriptor->JSParameterCount() *
296 kPointerSize)
297 : 0;
298 __ pop(Operand(esp, bytes_to_pop));
299 __ add(esp, Immediate(bytes_to_pop));
300 }
301 }
302
303
287 // Assembles an instruction after register allocation, producing machine code. 304 // Assembles an instruction after register allocation, producing machine code.
288 void CodeGenerator::AssembleArchInstruction(Instruction* instr) { 305 void CodeGenerator::AssembleArchInstruction(Instruction* instr) {
289 IA32OperandConverter i(this, instr); 306 IA32OperandConverter i(this, instr);
290 307
291 switch (ArchOpcodeField::decode(instr->opcode())) { 308 switch (ArchOpcodeField::decode(instr->opcode())) {
292 case kArchCallCodeObject: { 309 case kArchCallCodeObject: {
293 EnsureSpaceForLazyDeopt(); 310 EnsureSpaceForLazyDeopt();
294 if (HasImmediateInput(instr, 0)) { 311 if (HasImmediateInput(instr, 0)) {
295 Handle<Code> code = Handle<Code>::cast(i.InputHeapObject(0)); 312 Handle<Code> code = Handle<Code>::cast(i.InputHeapObject(0));
296 __ call(code, RelocInfo::CODE_TARGET); 313 __ call(code, RelocInfo::CODE_TARGET);
297 } else { 314 } else {
298 Register reg = i.InputRegister(0); 315 Register reg = i.InputRegister(0);
299 __ call(Operand(reg, Code::kHeaderSize - kHeapObjectTag)); 316 __ call(Operand(reg, Code::kHeaderSize - kHeapObjectTag));
300 } 317 }
301 RecordCallPosition(instr); 318 RecordCallPosition(instr);
302 break; 319 break;
303 } 320 }
321 case kArchTailCallCodeObject: {
322 AssembleDeconstructActivationRecord();
323 if (HasImmediateInput(instr, 0)) {
324 Handle<Code> code = Handle<Code>::cast(i.InputHeapObject(0));
325 __ jmp(code, RelocInfo::CODE_TARGET);
326 } else {
327 Register reg = i.InputRegister(0);
328 __ jmp(Operand(reg, Code::kHeaderSize - kHeapObjectTag));
329 }
330 break;
331 }
304 case kArchCallJSFunction: { 332 case kArchCallJSFunction: {
305 EnsureSpaceForLazyDeopt(); 333 EnsureSpaceForLazyDeopt();
306 Register func = i.InputRegister(0); 334 Register func = i.InputRegister(0);
307 if (FLAG_debug_code) { 335 if (FLAG_debug_code) {
308 // Check the function's context matches the context argument. 336 // Check the function's context matches the context argument.
309 __ cmp(esi, FieldOperand(func, JSFunction::kContextOffset)); 337 __ cmp(esi, FieldOperand(func, JSFunction::kContextOffset));
310 __ Assert(equal, kWrongFunctionContext); 338 __ Assert(equal, kWrongFunctionContext);
311 } 339 }
312 __ call(FieldOperand(func, JSFunction::kCodeEntryOffset)); 340 __ call(FieldOperand(func, JSFunction::kCodeEntryOffset));
313 RecordCallPosition(instr); 341 RecordCallPosition(instr);
314 break; 342 break;
315 } 343 }
344 case kArchTailCallJSFunction: {
345 Register func = i.InputRegister(0);
346 if (FLAG_debug_code) {
347 // Check the function's context matches the context argument.
348 __ cmp(esi, FieldOperand(func, JSFunction::kContextOffset));
349 __ Assert(equal, kWrongFunctionContext);
350 }
351 AssembleDeconstructActivationRecord();
352 __ jmp(FieldOperand(func, JSFunction::kCodeEntryOffset));
353 break;
354 }
316 case kArchJmp: 355 case kArchJmp:
317 AssembleArchJump(i.InputRpo(0)); 356 AssembleArchJump(i.InputRpo(0));
318 break; 357 break;
319 case kArchLookupSwitch: 358 case kArchLookupSwitch:
320 AssembleArchLookupSwitch(instr); 359 AssembleArchLookupSwitch(instr);
321 break; 360 break;
322 case kArchTableSwitch: 361 case kArchTableSwitch:
323 AssembleArchTableSwitch(instr); 362 AssembleArchTableSwitch(instr);
324 break; 363 break;
325 case kArchNop: 364 case kArchNop:
(...skipping 1144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1470 } 1509 }
1471 } 1510 }
1472 MarkLazyDeoptSite(); 1511 MarkLazyDeoptSite();
1473 } 1512 }
1474 1513
1475 #undef __ 1514 #undef __
1476 1515
1477 } // namespace compiler 1516 } // namespace compiler
1478 } // namespace internal 1517 } // namespace internal
1479 } // namespace v8 1518 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/code-generator.h ('k') | src/compiler/ia32/instruction-selector-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698