llvm.org GIT mirror llvm / 9bbbea5
Provide convenient helpers for some operations git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@50153 91177308-0d34-0410-b5e6-96231b3b80d8 Anton Korobeynikov 12 years ago
2 changed file(s) with 88 addition(s) and 64 deletion(s). Raw diff Collapse all Expand all
257257 MachineModuleInfo *MMI = MFI->getMachineModuleInfo();
258258
259259 return (NoFramePointerElim ||
260 needsStackRealignment(MF) ||
260261 MFI->hasVarSizedObjects() ||
261262 MF.getInfo()->getForceFramePointer() ||
262263 (MMI && MMI->callsUnwindInit()));
264 }
265
266 bool X86RegisterInfo::needsStackRealignment(const MachineFunction &MF) const {
267 MachineFrameInfo *MFI = MF.getFrameInfo();;
268
269 return (MFI->getMaxAlignment() > StackAlign);
263270 }
264271
265272 bool X86RegisterInfo::hasReservedCallFrame(MachineFunction &MF) const {
494501
495502 return Offset;
496503 }
504
505 void X86RegisterInfo::emitFrameMoves(MachineFunction &MF,
506 unsigned FrameLabelId,
507 unsigned ReadyLabelId) const {
508 MachineFrameInfo *MFI = MF.getFrameInfo();
509 MachineModuleInfo *MMI = MFI->getMachineModuleInfo();
510 if (!MMI)
511 return;
512
513 uint64_t StackSize = MFI->getStackSize();
514 std::vector &Moves = MMI->getFrameMoves();
515 const TargetData *TD = MF.getTarget().getTargetData();
516
517 // Calculate amount of bytes used for return address storing
518 int stackGrowth =
519 (MF.getTarget().getFrameInfo()->getStackGrowthDirection() ==
520 TargetFrameInfo::StackGrowsUp ?
521 TD->getPointerSize() : -TD->getPointerSize());
522
523 if (StackSize) {
524 // Show update of SP.
525 if (hasFP(MF)) {
526 // Adjust SP
527 MachineLocation SPDst(MachineLocation::VirtualFP);
528 MachineLocation SPSrc(MachineLocation::VirtualFP, 2*stackGrowth);
529 Moves.push_back(MachineMove(FrameLabelId, SPDst, SPSrc));
530 } else {
531 MachineLocation SPDst(MachineLocation::VirtualFP);
532 MachineLocation SPSrc(MachineLocation::VirtualFP,
533 -StackSize+stackGrowth);
534 Moves.push_back(MachineMove(FrameLabelId, SPDst, SPSrc));
535 }
536 } else {
537 //FIXME: Verify & implement for FP
538 MachineLocation SPDst(StackPtr);
539 MachineLocation SPSrc(StackPtr, stackGrowth);
540 Moves.push_back(MachineMove(FrameLabelId, SPDst, SPSrc));
541 }
542
543 // Add callee saved registers to move list.
544 const std::vector &CSI = MFI->getCalleeSavedInfo();
545
546 // FIXME: This is dirty hack. The code itself is pretty mess right now.
547 // It should be rewritten from scratch and generalized sometimes.
548
549 // Determine maximum offset (minumum due to stack growth)
550 int64_t MaxOffset = 0;
551 for (unsigned I = 0, E = CSI.size(); I!=E; ++I)
552 MaxOffset = std::min(MaxOffset,
553 MFI->getObjectOffset(CSI[I].getFrameIdx()));
554
555 // Calculate offsets
556 int64_t saveAreaOffset = (hasFP(MF) ? 3 : 2)*stackGrowth;
557 for (unsigned I = 0, E = CSI.size(); I!=E; ++I) {
558 int64_t Offset = MFI->getObjectOffset(CSI[I].getFrameIdx());
559 unsigned Reg = CSI[I].getReg();
560 Offset = (MaxOffset-Offset+saveAreaOffset);
561 MachineLocation CSDst(MachineLocation::VirtualFP, Offset);
562 MachineLocation CSSrc(Reg);
563 Moves.push_back(MachineMove(FrameLabelId, CSDst, CSSrc));
564 }
565
566 if (hasFP(MF)) {
567 // Save FP
568 MachineLocation FPDst(MachineLocation::VirtualFP, 2*stackGrowth);
569 MachineLocation FPSrc(FramePtr);
570 Moves.push_back(MachineMove(ReadyLabelId, FPDst, FPSrc));
571 }
572
573 MachineLocation FPDst(hasFP(MF) ? FramePtr : StackPtr);
574 MachineLocation FPSrc(MachineLocation::VirtualFP);
575 Moves.push_back(MachineMove(ReadyLabelId, FPDst, FPSrc));
576 }
577
497578
498579 void X86RegisterInfo::emitPrologue(MachineFunction &MF) const {
499580 MachineBasicBlock &MBB = MF.front(); // Prolog goes in entry BB
608689 }
609690 }
610691
611 if (needsFrameMoves) {
612 std::vector &Moves = MMI->getFrameMoves();
613 const TargetData *TD = MF.getTarget().getTargetData();
614
615 // Calculate amount of bytes used for return address storing
616 int stackGrowth =
617 (MF.getTarget().getFrameInfo()->getStackGrowthDirection() ==
618 TargetFrameInfo::StackGrowsUp ?
619 TD->getPointerSize() : -TD->getPointerSize());
620
621 if (StackSize) {
622 // Show update of SP.
623 if (hasFP(MF)) {
624 // Adjust SP
625 MachineLocation SPDst(MachineLocation::VirtualFP);
626 MachineLocation SPSrc(MachineLocation::VirtualFP, 2*stackGrowth);
627 Moves.push_back(MachineMove(FrameLabelId, SPDst, SPSrc));
628 } else {
629 MachineLocation SPDst(MachineLocation::VirtualFP);
630 MachineLocation SPSrc(MachineLocation::VirtualFP,
631 -StackSize+stackGrowth);
632 Moves.push_back(MachineMove(FrameLabelId, SPDst, SPSrc));
633 }
634 } else {
635 //FIXME: Verify & implement for FP
636 MachineLocation SPDst(StackPtr);
637 MachineLocation SPSrc(StackPtr, stackGrowth);
638 Moves.push_back(MachineMove(FrameLabelId, SPDst, SPSrc));
639 }
640
641 // Add callee saved registers to move list.
642 const std::vector &CSI = MFI->getCalleeSavedInfo();
643
644 // FIXME: This is dirty hack. The code itself is pretty mess right now.
645 // It should be rewritten from scratch and generalized sometimes.
646
647 // Determine maximum offset (minumum due to stack growth)
648 int64_t MaxOffset = 0;
649 for (unsigned I = 0, E = CSI.size(); I!=E; ++I)
650 MaxOffset = std::min(MaxOffset,
651 MFI->getObjectOffset(CSI[I].getFrameIdx()));
652
653 // Calculate offsets
654 int64_t saveAreaOffset = (hasFP(MF) ? 3 : 2)*stackGrowth;
655 for (unsigned I = 0, E = CSI.size(); I!=E; ++I) {
656 int64_t Offset = MFI->getObjectOffset(CSI[I].getFrameIdx());
657 unsigned Reg = CSI[I].getReg();
658 Offset = (MaxOffset-Offset+saveAreaOffset);
659 MachineLocation CSDst(MachineLocation::VirtualFP, Offset);
660 MachineLocation CSSrc(Reg);
661 Moves.push_back(MachineMove(FrameLabelId, CSDst, CSSrc));
662 }
663
664 if (hasFP(MF)) {
665 // Save FP
666 MachineLocation FPDst(MachineLocation::VirtualFP, 2*stackGrowth);
667 MachineLocation FPSrc(FramePtr);
668 Moves.push_back(MachineMove(ReadyLabelId, FPDst, FPSrc));
669 }
670
671 MachineLocation FPDst(hasFP(MF) ? FramePtr : StackPtr);
672 MachineLocation FPSrc(MachineLocation::VirtualFP);
673 Moves.push_back(MachineMove(ReadyLabelId, FPDst, FPSrc));
674 }
692 if (needsFrameMoves)
693 emitFrameMoves(MF, FrameLabelId, ReadyLabelId);
675694
676695 // If it's main() on Cygwin\Mingw32 we should align stack as well
677696 if (Fn->hasExternalLinkage() && Fn->getName() == "main" &&
114114
115115 bool hasFP(const MachineFunction &MF) const;
116116
117 bool needsStackRealignment(const MachineFunction &MF) const;
118
117119 bool hasReservedCallFrame(MachineFunction &MF) const;
118120
119121 void eliminateCallFramePseudoInstr(MachineFunction &MF,
127129
128130 void emitPrologue(MachineFunction &MF) const;
129131 void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const;
132
133 void emitFrameMoves(MachineFunction &MF,
134 unsigned FrameLabelId, unsigned ReadyLabelId) const;
130135
131136 // Debug information queries.
132137 unsigned getRARegister() const;