[llvm] r189849 - WIP: Refactor some code so that it can be called by more than just one method. No functionality change.

Bill Wendling isanbard at gmail.com
Tue Sep 3 13:59:07 PDT 2013


Author: void
Date: Tue Sep  3 15:59:07 2013
New Revision: 189849

URL: http://llvm.org/viewvc/llvm-project?rev=189849&view=rev
Log:
WIP: Refactor some code so that it can be called by more than just one method. No functionality change.

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=189849&r1=189848&r2=189849&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86FrameLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86FrameLowering.cpp Tue Sep  3 15:59:07 2013
@@ -483,13 +483,78 @@ encodeCompactUnwindRegistersWithFrame(un
   return RegEnc;
 }
 
+static uint32_t
+doCompactUnwindEncoding(unsigned SavedRegs[CU_NUM_SAVED_REGS],
+                        unsigned StackSize, unsigned StackAdjust,
+                        unsigned SubtractInstrIdx, unsigned SavedRegIdx,
+                        bool Is64Bit, bool HasFP) {
+  // Encode that we are using EBP/RBP as the frame pointer.
+  unsigned StackDivide = (Is64Bit ? 8 : 4);
+  uint32_t CompactUnwindEncoding = 0;
+
+  StackAdjust /= StackDivide;
+
+  if (HasFP) {
+    if ((StackAdjust & 0xFF) != StackAdjust)
+      // Offset was too big for compact encoding.
+      return CU::UNWIND_MODE_DWARF;
+
+    // Get the encoding of the saved registers when we have a frame pointer.
+    uint32_t RegEnc = encodeCompactUnwindRegistersWithFrame(SavedRegs, Is64Bit);
+    if (RegEnc == ~0U) return CU::UNWIND_MODE_DWARF;
+
+    CompactUnwindEncoding |= CU::UNWIND_MODE_BP_FRAME;
+    CompactUnwindEncoding |= (StackAdjust & 0xFF) << 16;
+    CompactUnwindEncoding |= RegEnc & CU::UNWIND_BP_FRAME_REGISTERS;
+  } else {
+    ++StackAdjust;
+    uint32_t TotalStackSize = StackAdjust + StackSize;
+    if ((TotalStackSize & 0xFF) == TotalStackSize) {
+      // Frameless stack with a small stack size.
+      CompactUnwindEncoding |= CU::UNWIND_MODE_STACK_IMMD;
+
+      // Encode the stack size.
+      CompactUnwindEncoding |= (TotalStackSize & 0xFF) << 16;
+    } else {
+      if ((StackAdjust & 0x7) != StackAdjust)
+        // The extra stack adjustments are too big for us to handle.
+        return CU::UNWIND_MODE_DWARF;
+
+      // Frameless stack with an offset too large for us to encode compactly.
+      CompactUnwindEncoding |= CU::UNWIND_MODE_STACK_IND;
+
+      // Encode the offset to the nnnnnn value in the 'subl $nnnnnn, ESP'
+      // instruction.
+      CompactUnwindEncoding |= (SubtractInstrIdx & 0xFF) << 16;
+
+      // Encode any extra stack stack adjustments (done via push instructions).
+      CompactUnwindEncoding |= (StackAdjust & 0x7) << 13;
+    }
+
+    // Encode the number of registers saved.
+    CompactUnwindEncoding |= (SavedRegIdx & 0x7) << 10;
+
+    // Get the encoding of the saved registers when we don't have a frame
+    // pointer.
+    uint32_t RegEnc =
+      encodeCompactUnwindRegistersWithoutFrame(SavedRegs, SavedRegIdx,
+                                               Is64Bit);
+    if (RegEnc == ~0U) return CU::UNWIND_MODE_DWARF;
+
+    // Encode the register encoding.
+    CompactUnwindEncoding |=
+      RegEnc & CU::UNWIND_FRAMELESS_STACK_REG_PERMUTATION;
+  }
+
+  return CompactUnwindEncoding;
+}
+
 uint32_t X86FrameLowering::getCompactUnwindEncoding(MachineFunction &MF) const {
   const X86RegisterInfo *RegInfo = TM.getRegisterInfo();
   unsigned FramePtr = RegInfo->getFrameRegister(MF);
   unsigned StackPtr = RegInfo->getStackRegister();
 
   bool Is64Bit = STI.is64Bit();
-  bool HasFP = hasFP(MF);
 
   unsigned SavedRegs[CU_NUM_SAVED_REGS] = { 0, 0, 0, 0, 0, 0 };
   unsigned SavedRegIdx = 0;
@@ -508,10 +573,9 @@ uint32_t X86FrameLowering::getCompactUnw
   unsigned StackAdjust = 0;
   unsigned StackSize = 0;
 
-  MachineBasicBlock &MBB = MF.front(); // Prologue is in entry BB.
   bool ExpectEnd = false;
-  for (MachineBasicBlock::iterator
-         MBBI = MBB.begin(), MBBE = MBB.end(); MBBI != MBBE; ++MBBI) {
+  for (MachineBasicBlock::iterator MBBI = MF.front().begin(),
+         MBBE = MF.front().end(); MBBI != MBBE; ++MBBI) {
     MachineInstr &MI = *MBBI;
     unsigned Opc = MI.getOpcode();
     if (Opc == X86::PROLOG_LABEL) continue;
@@ -564,62 +628,9 @@ uint32_t X86FrameLowering::getCompactUnw
     }
   }
 
-  // Encode that we are using EBP/RBP as the frame pointer.
-  uint32_t CompactUnwindEncoding = 0;
-  StackAdjust /= StackDivide;
-  if (HasFP) {
-    if ((StackAdjust & 0xFF) != StackAdjust)
-      // Offset was too big for compact encoding.
-      return CU::UNWIND_MODE_DWARF;
-
-    // Get the encoding of the saved registers when we have a frame pointer.
-    uint32_t RegEnc = encodeCompactUnwindRegistersWithFrame(SavedRegs, Is64Bit);
-    if (RegEnc == ~0U) return CU::UNWIND_MODE_DWARF;
-
-    CompactUnwindEncoding |= CU::UNWIND_MODE_BP_FRAME;
-    CompactUnwindEncoding |= (StackAdjust & 0xFF) << 16;
-    CompactUnwindEncoding |= RegEnc & CU::UNWIND_BP_FRAME_REGISTERS;
-  } else {
-    ++StackAdjust;
-    uint32_t TotalStackSize = StackAdjust + StackSize;
-    if ((TotalStackSize & 0xFF) == TotalStackSize) {
-      // Frameless stack with a small stack size.
-      CompactUnwindEncoding |= CU::UNWIND_MODE_STACK_IMMD;
-
-      // Encode the stack size.
-      CompactUnwindEncoding |= (TotalStackSize & 0xFF) << 16;
-    } else {
-      if ((StackAdjust & 0x7) != StackAdjust)
-        // The extra stack adjustments are too big for us to handle.
-        return CU::UNWIND_MODE_DWARF;
-
-      // Frameless stack with an offset too large for us to encode compactly.
-      CompactUnwindEncoding |= CU::UNWIND_MODE_STACK_IND;
-
-      // Encode the offset to the nnnnnn value in the 'subl $nnnnnn, ESP'
-      // instruction.
-      CompactUnwindEncoding |= (SubtractInstrIdx & 0xFF) << 16;
-
-      // Encode any extra stack stack adjustments (done via push instructions).
-      CompactUnwindEncoding |= (StackAdjust & 0x7) << 13;
-    }
-
-    // Encode the number of registers saved.
-    CompactUnwindEncoding |= (SavedRegIdx & 0x7) << 10;
-
-    // Get the encoding of the saved registers when we don't have a frame
-    // pointer.
-    uint32_t RegEnc =
-      encodeCompactUnwindRegistersWithoutFrame(SavedRegs, SavedRegIdx,
-                                               Is64Bit);
-    if (RegEnc == ~0U) return CU::UNWIND_MODE_DWARF;
-
-    // Encode the register encoding.
-    CompactUnwindEncoding |=
-      RegEnc & CU::UNWIND_FRAMELESS_STACK_REG_PERMUTATION;
-  }
-
-  return CompactUnwindEncoding;
+  return doCompactUnwindEncoding(SavedRegs, StackSize, StackAdjust,
+                                 SubtractInstrIdx, SavedRegIdx,
+                                 Is64Bit, hasFP(MF));
 }
 
 /// usesTheStack - This function checks if any of the users of EFLAGS





More information about the llvm-commits mailing list