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
diff --git a/lib/CodeGen/DwarfWriter.cpp b/lib/CodeGen/DwarfWriter.cpp
index bdf91fd..5d9720b 100644
--- a/lib/CodeGen/DwarfWriter.cpp
+++ b/lib/CodeGen/DwarfWriter.cpp
@@ -2112,16 +2112,25 @@
   /// EmitFrameMoves - Emit frame instructions to describe the layout of the
   /// frame.
   void EmitFrameMoves(const char *BaseLabel, unsigned BaseLabelID,
-                                   std::vector<MachineMove *> &Moves) {
+                                   std::vector<MachineMove> &Moves) {
+    int stackGrowth =
+        Asm->TM.getFrameInfo()->getStackGrowthDirection() ==
+          TargetFrameInfo::StackGrowsUp ?
+            TAI->getAddressSize() : -TAI->getAddressSize();
+
     for (unsigned i = 0, N = Moves.size(); i < N; ++i) {
-      MachineMove *Move = Moves[i];
-      unsigned LabelID = DebugInfo->MappedLabel(Move->getLabelID());
+      MachineMove &Move = Moves[i];
+      unsigned LabelID = Move.getLabelID();
       
-      // Throw out move if the label is invalid.
-      if (!LabelID) continue;
+      if (LabelID) {
+        LabelID = DebugInfo->MappedLabel(LabelID);
       
-      const MachineLocation &Dst = Move->getDestination();
-      const MachineLocation &Src = Move->getSource();
+        // Throw out move if the label is invalid.
+        if (!LabelID) continue;
+      }
+      
+      const MachineLocation &Dst = Move.getDestination();
+      const MachineLocation &Src = Move.getSource();
       
       // Advance row if new location.
       if (BaseLabel && LabelID && BaseLabelID != LabelID) {
@@ -2134,11 +2143,6 @@
         BaseLabel = "loc";
       }
       
-      int stackGrowth =
-          Asm->TM.getFrameInfo()->getStackGrowthDirection() ==
-            TargetFrameInfo::StackGrowsUp ?
-              TAI->getAddressSize() : -TAI->getAddressSize();
-
       // If advancing cfa.
       if (Dst.isRegister() && Dst.getRegister() == MachineLocation::VirtualFP) {
         if (!Src.isRegister()) {
@@ -2159,6 +2163,16 @@
         } else {
           assert(0 && "Machine move no supported yet.");
         }
+      } else if (Src.isRegister() &&
+        Src.getRegister() == MachineLocation::VirtualFP) {
+        if (Dst.isRegister()) {
+          EmitInt8(DW_CFA_def_cfa_register);
+          EOL("DW_CFA_def_cfa_register");
+          EmitULEB128Bytes(RI->getDwarfRegNum(Dst.getRegister()));
+          EOL("Register");
+        } else {
+          assert(0 && "Machine move no supported yet.");
+        }
       } else {
         unsigned Reg = RI->getDwarfRegNum(Src.getRegister());
         int Offset = Dst.getOffset() / stackGrowth;
@@ -2433,10 +2447,9 @@
     EmitSLEB128Bytes(stackGrowth); EOL("CIE Data Alignment Factor");   
     EmitInt8(RI->getDwarfRegNum(RI->getRARegister())); EOL("CIE RA Column");
     
-    std::vector<MachineMove *> Moves;
+    std::vector<MachineMove> Moves;
     RI->getInitialFrameState(Moves);
     EmitFrameMoves(NULL, 0, Moves);
-    for (unsigned i = 0, N = Moves.size(); i < N; ++i) delete Moves[i];
 
     Asm->EmitAlignment(2);
     EmitLabel("frame_common_end", 0);
@@ -2467,7 +2480,7 @@
                    "func_begin", SubprogramCount);
     EOL("FDE address range");
     
-    std::vector<MachineMove *> &Moves = DebugInfo->getFrameMoves();
+    std::vector<MachineMove> &Moves = DebugInfo->getFrameMoves();
     
     EmitFrameMoves("func_begin", SubprogramCount, Moves);