llvm.org GIT mirror llvm / 5e73d5b
Repair debug frames as a prelude to eh_frames. Switched to using MachineMoves by value so that clean up is less confusing (these vectors tend to be small.) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33488 91177308-0d34-0410-b5e6-96231b3b80d8 Jim Laskey 13 years ago
8 changed file(s) with 89 addition(s) and 43 deletion(s). Raw diff Collapse all Expand all
984984
985985 // FrameMoves - List of moves done by a function's prolog. Used to construct
986986 // frame maps by debug consumers.
987 std::vector *> FrameMoves;
987 std::vector> FrameMoves;
988988
989989 public:
990990 MachineDebugInfo();
11441144
11451145 /// getFrameMoves - Returns a reference to a list of moves done in the current
11461146 /// function's prologue. Used to construct frame maps for debug comsumers.
1147 std::vector *> &getFrameMoves() { return FrameMoves; }
1147 std::vector> &getFrameMoves() { return FrameMoves; }
11481148
11491149 }; // End class MachineDebugInfo
11501150
7878 unsigned LabelID; // Label ID number for post-instruction
7979 // address when result of move takes
8080 // effect.
81 const MachineLocation Destination; // Move to location.
82 const MachineLocation Source; // Move from location.
81 MachineLocation Destination; // Move to location.
82 MachineLocation Source; // Move from location.
8383
8484 public:
85 MachineMove()
86 : LabelID(0)
87 , Destination()
88 , Source()
89 {}
90
8591 MachineMove(unsigned ID, MachineLocation &D, MachineLocation &S)
8692 : LabelID(ID)
8793 , Destination(D)
455455 /// getInitialFrameState - Returns a list of machine moves that are assumed
456456 /// on entry to all functions. Note that LabelID is ignored (assumed to be
457457 /// the beginning of the function.)
458 virtual void getInitialFrameState(std::vector *> &Moves) const;
458 virtual void getInitialFrameState(std::vector> &Moves) const;
459459 };
460460
461461 // This is useful when building DenseMaps keyed on virtual registers
21112111 /// EmitFrameMoves - Emit frame instructions to describe the layout of the
21122112 /// frame.
21132113 void EmitFrameMoves(const char *BaseLabel, unsigned BaseLabelID,
2114 std::vector *> &Moves) {
2114 std::vector> &Moves) {
2115 int stackGrowth =
2116 Asm->TM.getFrameInfo()->getStackGrowthDirection() ==
2117 TargetFrameInfo::StackGrowsUp ?
2118 TAI->getAddressSize() : -TAI->getAddressSize();
2119
21152120 for (unsigned i = 0, N = Moves.size(); i < N; ++i) {
2116 MachineMove *Move = Moves[i];
2117 unsigned LabelID = DebugInfo->MappedLabel(Move->getLabelID());
2118
2119 // Throw out move if the label is invalid.
2120 if (!LabelID) continue;
2121
2122 const MachineLocation &Dst = Move->getDestination();
2123 const MachineLocation &Src = Move->getSource();
2121 MachineMove &Move = Moves[i];
2122 unsigned LabelID = Move.getLabelID();
2123
2124 if (LabelID) {
2125 LabelID = DebugInfo->MappedLabel(LabelID);
2126
2127 // Throw out move if the label is invalid.
2128 if (!LabelID) continue;
2129 }
2130
2131 const MachineLocation &Dst = Move.getDestination();
2132 const MachineLocation &Src = Move.getSource();
21242133
21252134 // Advance row if new location.
21262135 if (BaseLabel && LabelID && BaseLabelID != LabelID) {
21332142 BaseLabel = "loc";
21342143 }
21352144
2136 int stackGrowth =
2137 Asm->TM.getFrameInfo()->getStackGrowthDirection() ==
2138 TargetFrameInfo::StackGrowsUp ?
2139 TAI->getAddressSize() : -TAI->getAddressSize();
2140
21412145 // If advancing cfa.
21422146 if (Dst.isRegister() && Dst.getRegister() == MachineLocation::VirtualFP) {
21432147 if (!Src.isRegister()) {
21552159
21562160 EmitULEB128Bytes(Offset);
21572161 EOL("Offset");
2162 } else {
2163 assert(0 && "Machine move no supported yet.");
2164 }
2165 } else if (Src.isRegister() &&
2166 Src.getRegister() == MachineLocation::VirtualFP) {
2167 if (Dst.isRegister()) {
2168 EmitInt8(DW_CFA_def_cfa_register);
2169 EOL("DW_CFA_def_cfa_register");
2170 EmitULEB128Bytes(RI->getDwarfRegNum(Dst.getRegister()));
2171 EOL("Register");
21582172 } else {
21592173 assert(0 && "Machine move no supported yet.");
21602174 }
24322446 EmitSLEB128Bytes(stackGrowth); EOL("CIE Data Alignment Factor");
24332447 EmitInt8(RI->getDwarfRegNum(RI->getRARegister())); EOL("CIE RA Column");
24342448
2435 std::vector *> Moves;
2449 std::vector> Moves;
24362450 RI->getInitialFrameState(Moves);
24372451 EmitFrameMoves(NULL, 0, Moves);
2438 for (unsigned i = 0, N = Moves.size(); i < N; ++i) delete Moves[i];
24392452
24402453 Asm->EmitAlignment(2);
24412454 EmitLabel("frame_common_end", 0);
24662479 "func_begin", SubprogramCount);
24672480 EOL("FDE address range");
24682481
2469 std::vector *> &Moves = DebugInfo->getFrameMoves();
2482 std::vector> &Moves = DebugInfo->getFrameMoves();
24702483
24712484 EmitFrameMoves("func_begin", SubprogramCount, Moves);
24722485
15041504 }
15051505
15061506 // Clean up frame info.
1507 for (unsigned i = 0, N = FrameMoves.size(); i < N; ++i) delete FrameMoves[i];
15081507 FrameMoves.clear();
15091508 }
15101509
6363 /// getInitialFrameState - Returns a list of machine moves that are assumed
6464 /// on entry to a function.
6565 void
66 MRegisterInfo::getInitialFrameState(std::vector *> &Moves) const {
66 MRegisterInfo::getInitialFrameState(std::vector> &Moves) const {
6767 // Default is to do nothing.
6868 }
6969
761761 MachineFrameInfo *MFI = MF.getFrameInfo();
762762 MachineDebugInfo *DebugInfo = MFI->getMachineDebugInfo();
763763
764 // Prepare for debug frame info.
765 bool hasInfo = DebugInfo && DebugInfo->hasInfo();
766 unsigned FrameLabelId = 0;
767
764768 // Scan the prolog, looking for an UPDATE_VRSAVE instruction. If we find it,
765769 // process it.
766770 for (unsigned i = 0; MBBI != MBB.end(); ++i, ++MBBI) {
820824 unsigned TargetAlign = MF.getTarget().getFrameInfo()->getStackAlignment();
821825 unsigned MaxAlign = MFI->getMaxAlignment();
822826
827 if (hasInfo) {
828 // Mark effective beginning of when frame pointer becomes valid.
829 FrameLabelId = DebugInfo->NextLabelID();
830 BuildMI(MBB, MBBI, TII.get(PPC::DWARF_LABEL)).addImm(FrameLabelId);
831 }
832
823833 // Adjust stack pointer: r1 += NegFrameSize.
824834 // If there is a preferred stack alignment, align R1 now
825835 if (!IsPPC64) {
865875 }
866876 }
867877
868 if (DebugInfo && DebugInfo->hasInfo()) {
869 std::vector &Moves = DebugInfo->getFrameMoves();
870 unsigned LabelID = DebugInfo->NextLabelID();
871
872 // Mark effective beginning of when frame pointer becomes valid.
873 BuildMI(MBB, MBBI, TII.get(PPC::DWARF_LABEL)).addImm(LabelID);
874
875 // Show update of SP.
876 MachineLocation SPDst(MachineLocation::VirtualFP);
877 MachineLocation SPSrc(MachineLocation::VirtualFP, NegFrameSize);
878 Moves.push_back(new MachineMove(LabelID, SPDst, SPSrc));
878 if (hasInfo) {
879 std::vector &Moves = DebugInfo->getFrameMoves();
880
881 if (NegFrameSize) {
882 // Show update of SP.
883 MachineLocation SPDst(MachineLocation::VirtualFP);
884 MachineLocation SPSrc(MachineLocation::VirtualFP, NegFrameSize);
885 Moves.push_back(MachineMove(FrameLabelId, SPDst, SPSrc));
886 } else {
887 MachineLocation SP(IsPPC64 ? PPC::X31 : PPC::R31);
888 Moves.push_back(MachineMove(FrameLabelId, SP, SP));
889 }
890
891 if (HasFP) {
892 MachineLocation FPDst(MachineLocation::VirtualFP, FPOffset);
893 MachineLocation FPSrc(IsPPC64 ? PPC::X31 : PPC::R31);
894 Moves.push_back(MachineMove(FrameLabelId, FPDst, FPSrc));
895 }
879896
880897 // Add callee saved registers to move list.
881898 const std::vector &CSI = MFI->getCalleeSavedInfo();
882899 for (unsigned I = 0, E = CSI.size(); I != E; ++I) {
883 MachineLocation CSDst(MachineLocation::VirtualFP,
884 MFI->getObjectOffset(CSI[I].getFrameIdx()));
885 MachineLocation CSSrc(CSI[I].getReg());
886 Moves.push_back(new MachineMove(LabelID, CSDst, CSSrc));
887 }
900 int Offset = MFI->getObjectOffset(CSI[I].getFrameIdx());
901 unsigned Reg = CSI[I].getReg();
902 if (Reg == PPC::LR || Reg == PPC::LR8) continue;
903 MachineLocation CSDst(MachineLocation::VirtualFP, Offset);
904 MachineLocation CSSrc(Reg);
905 Moves.push_back(MachineMove(FrameLabelId, CSDst, CSSrc));
906 }
907
908 // Mark effective beginning of when frame pointer is ready.
909 unsigned ReadyLabelId = DebugInfo->NextLabelID();
910 BuildMI(MBB, MBBI, TII.get(PPC::DWARF_LABEL)).addImm(ReadyLabelId);
911
912 MachineLocation FPDst(HasFP ? (IsPPC64 ? PPC::X31 : PPC::R31) :
913 (IsPPC64 ? PPC::X1 : PPC::R1));
914 MachineLocation FPSrc(MachineLocation::VirtualFP);
915 Moves.push_back(MachineMove(ReadyLabelId, FPDst, FPSrc));
888916 }
889917
890918 // If there is a frame pointer, copy R1 into R31
9821010 return hasFP(MF) ? PPC::X31 : PPC::X1;
9831011 }
9841012
985 void PPCRegisterInfo::getInitialFrameState(std::vector *> &Moves)
1013 void PPCRegisterInfo::getInitialFrameState(std::vector> &Moves)
9861014 const {
9871015 // Initial state of the frame pointer is R1.
9881016 MachineLocation Dst(MachineLocation::VirtualFP);
9891017 MachineLocation Src(PPC::R1, 0);
990 Moves.push_back(new MachineMove(0, Dst, Src));
1018 Moves.push_back(MachineMove(0, Dst, Src));
9911019 }
9921020
9931021 #include "PPCGenRegisterInfo.inc"
8080 // Debug information queries.
8181 unsigned getRARegister() const;
8282 unsigned getFrameRegister(MachineFunction &MF) const;
83 void getInitialFrameState(std::vector *> &Moves) const;
83 void getInitialFrameState(std::vector> &Moves) const;
8484 };
8585
8686 } // end namespace llvm