[llvm-commits] [llvm] r135013 - /llvm/trunk/lib/Target/X86/X86FrameLowering.cpp

Bill Wendling isanbard at gmail.com
Tue Jul 12 17:16:14 PDT 2011


Author: void
Date: Tue Jul 12 19:16:14 2011
New Revision: 135013

URL: http://llvm.org/viewvc/llvm-project?rev=135013&view=rev
Log:
Clean up the handling of an EBP/RBP unwind frame pointer. In particular, don't
assert when the frame pointer is -1 (i.e., the function is "frameless").

Still to do: "frameless" unwind information.

Modified:
    llvm/trunk/lib/Target/X86/X86FrameLowering.cpp

Modified: llvm/trunk/lib/Target/X86/X86FrameLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86FrameLowering.cpp?rev=135013&r1=135012&r2=135013&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86FrameLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86FrameLowering.cpp Tue Jul 12 19:16:14 2011
@@ -1064,7 +1064,7 @@
         if (IsRelative)
           CFAOffset += Src.getOffset();
         else
-          CFAOffset = -Src.getOffset();
+          CFAOffset -= Src.getOffset();
       } // else DW_CFA_def_cfa
 
       continue;
@@ -1072,6 +1072,13 @@
 
     if (Src.isReg() && Src.getReg() == MachineLocation::VirtualFP) {
       // DW_CFA_def_cfa_register
+      assert(FramePointerReg != -1 && "Defining more than one frame pointer?");
+      if (TRI->getLLVMRegNum(FramePointerReg, IsEH) != X86::EBP &&
+          TRI->getLLVMRegNum(FramePointerReg, IsEH) != X86::RBP)
+        // The frame pointer isn't EBP/RBP. Cannot make unwind information
+        // compact.
+        return 0;
+
       FramePointerReg = Dst.getReg();
       continue;
     }
@@ -1088,7 +1095,9 @@
       return 0;
     } else if (Reg < 64) {
       // DW_CFA_offset + Reg
-      SavedRegs.push_back(Reg);
+      int CURegNum = TRI->getCompactUnwindRegNum(Reg, IsEH);
+      if (CURegNum == -1) return 0;
+      SavedRegs.push_back(CURegNum);
     } else {
       // FIXME: Handle?
       // DW_CFA_offset_extended
@@ -1096,33 +1105,27 @@
     }
   }
 
-  CFAOffset /= 4;
-
   // Check if the offset is too big.
+  CFAOffset /= 4;
   if ((CFAOffset & 0xFF) != CFAOffset)
     return 0;
+  Encoding |= (CFAOffset & 0xFF) << 16; // Size encoding.
 
-  // Bail if there are too many registers to encode.
-  unsigned NumRegsToEncode = SavedRegs.size() - (FramePointerReg != -1 ? 1 : 0);
-  if (NumRegsToEncode > 5) return 0;
-
-  if (TRI->getLLVMRegNum(FramePointerReg, IsEH) != X86::EBP &&
-      TRI->getLLVMRegNum(FramePointerReg, IsEH) != X86::RBP)
+  if (FramePointerReg != -1) {
+    // Bail if there are too many registers to encode.
+    if (SavedRegs.size() - 1 > 5) return 0;
+
+    Encoding |= 1 << 24;        // EBP/RBP Unwind Frame
+
+    unsigned Idx = 0;
+    for (SmallVectorImpl<unsigned>::iterator
+           I = SavedRegs.begin(), E = SavedRegs.end(); I != E; ++I) {
+      unsigned Reg = *I;
+      if (Reg == unsigned(FramePointerReg)) continue;
+      Encoding |= (Reg & 0x7) << (Idx++ * 3); // Register encoding
+    }
+  } else {
     // FIXME: Handle frameless version!
-    return 0;
-
-  Encoding |= 1 << 24;
-  Encoding |= (CFAOffset & 0xFF) << 16;
-
-  unsigned Idx = 0;
-  for (SmallVectorImpl<unsigned>::iterator
-         I = SavedRegs.begin(), E = SavedRegs.end(); I != E; ++I) {
-    if (*I == unsigned(FramePointerReg)) continue;
-
-    int CURegNum = TRI->getCompactUnwindRegNum(*I, IsEH);
-    if (CURegNum == -1) return 0;
-
-    Encoding |= (CURegNum & 0x7) << (Idx++ * 3);
   }
 
   return Encoding;





More information about the llvm-commits mailing list