OLD | NEW |
1 //===- subzero/src/IceTargetLoweringX8632.cpp - x86-32 lowering -----------===// | 1 //===- subzero/src/IceTargetLoweringX8632.cpp - x86-32 lowering -----------===// |
2 // | 2 // |
3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 /// | 9 /// |
10 /// \file | 10 /// \file |
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 | 499 |
500 // Align esp if necessary. | 500 // Align esp if necessary. |
501 if (NeedsStackAlignment) { | 501 if (NeedsStackAlignment) { |
502 uint32_t StackOffset = | 502 uint32_t StackOffset = |
503 Traits::X86_RET_IP_SIZE_BYTES + PreservedRegsSizeBytes; | 503 Traits::X86_RET_IP_SIZE_BYTES + PreservedRegsSizeBytes; |
504 uint32_t StackSize = | 504 uint32_t StackSize = |
505 Traits::applyStackAlignment(StackOffset + SpillAreaSizeBytes); | 505 Traits::applyStackAlignment(StackOffset + SpillAreaSizeBytes); |
506 SpillAreaSizeBytes = StackSize - StackOffset; | 506 SpillAreaSizeBytes = StackSize - StackOffset; |
507 } | 507 } |
508 | 508 |
509 // Generate "sub esp, SpillAreaSizeBytes" | 509 // Combine fixed allocations into SpillAreaSizeBytes if we are emitting the |
510 if (SpillAreaSizeBytes) | 510 // fixed allocations in the prolog. |
| 511 if (PrologEmitsFixedAllocas) |
| 512 SpillAreaSizeBytes += FixedAllocaSizeBytes; |
| 513 if (SpillAreaSizeBytes) { |
| 514 // Generate "sub esp, SpillAreaSizeBytes" |
511 _sub(getPhysicalRegister(Traits::RegisterSet::Reg_esp), | 515 _sub(getPhysicalRegister(Traits::RegisterSet::Reg_esp), |
512 Ctx->getConstantInt32(SpillAreaSizeBytes)); | 516 Ctx->getConstantInt32(SpillAreaSizeBytes)); |
| 517 // If the fixed allocas are aligned more than the stack frame, align the |
| 518 // stack pointer accordingly. |
| 519 if (PrologEmitsFixedAllocas && |
| 520 FixedAllocaAlignBytes > Traits::X86_STACK_ALIGNMENT_BYTES) { |
| 521 assert(IsEbpBasedFrame); |
| 522 _and(getPhysicalRegister(Traits::RegisterSet::Reg_esp), |
| 523 Ctx->getConstantInt32(-FixedAllocaAlignBytes)); |
| 524 } |
| 525 } |
513 | 526 |
514 // Account for alloca instructions with known frame offsets. | 527 // Account for known-frame-offset alloca instructions that were not already |
515 SpillAreaSizeBytes += FixedAllocaSizeBytes; | 528 // combined into the prolog. |
| 529 if (!PrologEmitsFixedAllocas) |
| 530 SpillAreaSizeBytes += FixedAllocaSizeBytes; |
516 | 531 |
517 Ctx->statsUpdateFrameBytes(SpillAreaSizeBytes); | 532 Ctx->statsUpdateFrameBytes(SpillAreaSizeBytes); |
518 | 533 |
519 // Initialize the stack adjustment so that after all the known-frame-offset | 534 // Initialize the stack adjustment so that after all the known-frame-offset |
520 // alloca instructions are emitted, the stack adjustment will reach zero. | 535 // alloca instructions are emitted, the stack adjustment will reach zero. |
521 resetStackAdjustment(); | 536 resetStackAdjustment(); |
522 updateStackAdjustment(-FixedAllocaSizeBytes); | 537 if (!PrologEmitsFixedAllocas) |
| 538 updateStackAdjustment(-FixedAllocaSizeBytes); |
523 | 539 |
524 // Fill in stack offsets for stack args, and copy args into registers for | 540 // Fill in stack offsets for stack args, and copy args into registers for |
525 // those that were register-allocated. Args are pushed right to left, so | 541 // those that were register-allocated. Args are pushed right to left, so |
526 // Arg[0] is closest to the stack/frame pointer. | 542 // Arg[0] is closest to the stack/frame pointer. |
527 Variable *FramePtr = getPhysicalRegister(getFrameOrStackReg()); | 543 Variable *FramePtr = getPhysicalRegister(getFrameOrStackReg()); |
528 size_t BasicFrameOffset = | 544 size_t BasicFrameOffset = |
529 PreservedRegsSizeBytes + Traits::X86_RET_IP_SIZE_BYTES; | 545 PreservedRegsSizeBytes + Traits::X86_RET_IP_SIZE_BYTES; |
530 if (!IsEbpBasedFrame) | 546 if (!IsEbpBasedFrame) |
531 BasicFrameOffset += SpillAreaSizeBytes; | 547 BasicFrameOffset += SpillAreaSizeBytes; |
532 | 548 |
533 const VarList &Args = Func->getArgs(); | 549 const VarList &Args = Func->getArgs(); |
534 size_t InArgsSizeBytes = 0; | 550 size_t InArgsSizeBytes = 0; |
535 unsigned NumXmmArgs = 0; | 551 unsigned NumXmmArgs = 0; |
536 for (Variable *Arg : Args) { | 552 for (Variable *Arg : Args) { |
537 // Skip arguments passed in registers. | 553 // Skip arguments passed in registers. |
538 if (isVectorType(Arg->getType()) && NumXmmArgs < Traits::X86_MAX_XMM_ARGS) { | 554 if (isVectorType(Arg->getType()) && NumXmmArgs < Traits::X86_MAX_XMM_ARGS) { |
539 ++NumXmmArgs; | 555 ++NumXmmArgs; |
540 continue; | 556 continue; |
541 } | 557 } |
542 // For esp-based frames, the esp value may not stabilize to its home value | 558 // For esp-based frames where the allocas are done outside the prolog, the |
543 // until after all the fixed-size alloca instructions have executed. In | 559 // esp value may not stabilize to its home value until after all the |
544 // this case, a stack adjustment is needed when accessing in-args in order | 560 // fixed-size alloca instructions have executed. In this case, a stack |
545 // to copy them into registers. | 561 // adjustment is needed when accessing in-args in order to copy them into |
546 size_t StackAdjBytes = IsEbpBasedFrame ? 0 : -FixedAllocaSizeBytes; | 562 // registers. |
| 563 size_t StackAdjBytes = 0; |
| 564 if (!IsEbpBasedFrame && !PrologEmitsFixedAllocas) |
| 565 StackAdjBytes -= FixedAllocaSizeBytes; |
547 finishArgumentLowering(Arg, FramePtr, BasicFrameOffset, StackAdjBytes, | 566 finishArgumentLowering(Arg, FramePtr, BasicFrameOffset, StackAdjBytes, |
548 InArgsSizeBytes); | 567 InArgsSizeBytes); |
549 } | 568 } |
550 | 569 |
551 // Fill in stack offsets for locals. | 570 // Fill in stack offsets for locals. |
552 assignVarStackSlots(SortedSpilledVariables, SpillAreaPaddingBytes, | 571 assignVarStackSlots(SortedSpilledVariables, SpillAreaPaddingBytes, |
553 SpillAreaSizeBytes, GlobalsAndSubsequentPaddingSize, | 572 SpillAreaSizeBytes, GlobalsAndSubsequentPaddingSize, |
554 IsEbpBasedFrame); | 573 IsEbpBasedFrame); |
555 // Assign stack offsets to variables that have been linked to spilled | 574 // Assign stack offsets to variables that have been linked to spilled |
556 // variables. | 575 // variables. |
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
975 // case the high-level table has extra entries. | 994 // case the high-level table has extra entries. |
976 #define X(tag, sizeLog2, align, elts, elty, str) \ | 995 #define X(tag, sizeLog2, align, elts, elty, str) \ |
977 static_assert(_table1_##tag == _table2_##tag, \ | 996 static_assert(_table1_##tag == _table2_##tag, \ |
978 "Inconsistency between ICETYPEX8632_TABLE and ICETYPE_TABLE"); | 997 "Inconsistency between ICETYPEX8632_TABLE and ICETYPE_TABLE"); |
979 ICETYPE_TABLE | 998 ICETYPE_TABLE |
980 #undef X | 999 #undef X |
981 } // end of namespace dummy3 | 1000 } // end of namespace dummy3 |
982 } // end of anonymous namespace | 1001 } // end of anonymous namespace |
983 | 1002 |
984 } // end of namespace Ice | 1003 } // end of namespace Ice |
OLD | NEW |