diff options
author | Bill Wendling <isanbard@gmail.com> | 2013-09-03 20:59:07 +0000 |
---|---|---|
committer | Bill Wendling <isanbard@gmail.com> | 2013-09-03 20:59:07 +0000 |
commit | b9daaa02a24afb2027dc999258dcdb6ec4fbbc9a (patch) | |
tree | 27f17846ad1fbd74f83a4b2d71b30641e6973e7c | |
parent | 9f59ffcb54aa6050f16d0edfb96c7679379e812d (diff) | |
download | external_llvm-b9daaa02a24afb2027dc999258dcdb6ec4fbbc9a.zip external_llvm-b9daaa02a24afb2027dc999258dcdb6ec4fbbc9a.tar.gz external_llvm-b9daaa02a24afb2027dc999258dcdb6ec4fbbc9a.tar.bz2 |
WIP: Refactor some code so that it can be called by more than just one method. No functionality change.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@189849 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Target/X86/X86FrameLowering.cpp | 131 |
1 files changed, 71 insertions, 60 deletions
diff --git a/lib/Target/X86/X86FrameLowering.cpp b/lib/Target/X86/X86FrameLowering.cpp index ecf7b73..f44a893 100644 --- a/lib/Target/X86/X86FrameLowering.cpp +++ b/lib/Target/X86/X86FrameLowering.cpp @@ -483,13 +483,78 @@ encodeCompactUnwindRegistersWithFrame(unsigned SavedRegs[CU_NUM_SAVED_REGS], 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::getCompactUnwindEncoding(MachineFunction &MF) const { 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::getCompactUnwindEncoding(MachineFunction &MF) const { } } - // 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 |