Home | History | Annotate | Download | only in X86
      1 //===-- X86TargetFrameLowering.h - Define frame lowering for X86 -*- C++ -*-==//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 // This class implements X86-specific bits of TargetFrameLowering class.
     11 //
     12 //===----------------------------------------------------------------------===//
     13 
     14 #ifndef X86_FRAMELOWERING_H
     15 #define X86_FRAMELOWERING_H
     16 
     17 #include "X86Subtarget.h"
     18 #include "llvm/MC/MCDwarf.h"
     19 #include "llvm/Target/TargetFrameLowering.h"
     20 
     21 namespace llvm {
     22 
     23 namespace CU {
     24 
     25   /// Compact unwind encoding values.
     26   enum CompactUnwindEncodings {
     27     /// [RE]BP based frame where [RE]BP is pused on the stack immediately after
     28     /// the return address, then [RE]SP is moved to [RE]BP.
     29     UNWIND_MODE_BP_FRAME                   = 0x01000000,
     30 
     31     /// A frameless function with a small constant stack size.
     32     UNWIND_MODE_STACK_IMMD                 = 0x02000000,
     33 
     34     /// A frameless function with a large constant stack size.
     35     UNWIND_MODE_STACK_IND                  = 0x03000000,
     36 
     37     /// No compact unwind encoding is available.
     38     UNWIND_MODE_DWARF                      = 0x04000000,
     39 
     40     /// Mask for encoding the frame registers.
     41     UNWIND_BP_FRAME_REGISTERS              = 0x00007FFF,
     42 
     43     /// Mask for encoding the frameless registers.
     44     UNWIND_FRAMELESS_STACK_REG_PERMUTATION = 0x000003FF
     45   };
     46 
     47 } // end CU namespace
     48 
     49 class MCSymbol;
     50 class X86TargetMachine;
     51 
     52 class X86FrameLowering : public TargetFrameLowering {
     53   const X86TargetMachine &TM;
     54   const X86Subtarget &STI;
     55 public:
     56   explicit X86FrameLowering(const X86TargetMachine &tm, const X86Subtarget &sti)
     57     : TargetFrameLowering(StackGrowsDown,
     58                           sti.getStackAlignment(),
     59                           (sti.is64Bit() ? -8 : -4)),
     60       TM(tm), STI(sti) {
     61   }
     62 
     63   void emitCalleeSavedFrameMoves(MachineFunction &MF, MCSymbol *Label,
     64                                  unsigned FramePtr) const;
     65 
     66   /// emitProlog/emitEpilog - These methods insert prolog and epilog code into
     67   /// the function.
     68   void emitPrologue(MachineFunction &MF) const;
     69   void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const;
     70 
     71   void adjustForSegmentedStacks(MachineFunction &MF) const;
     72 
     73   void adjustForHiPEPrologue(MachineFunction &MF) const;
     74 
     75   void processFunctionBeforeCalleeSavedScan(MachineFunction &MF,
     76                                             RegScavenger *RS = NULL) const;
     77 
     78   bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
     79                                  MachineBasicBlock::iterator MI,
     80                                  const std::vector<CalleeSavedInfo> &CSI,
     81                                  const TargetRegisterInfo *TRI) const;
     82 
     83   bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
     84                                    MachineBasicBlock::iterator MI,
     85                                    const std::vector<CalleeSavedInfo> &CSI,
     86                                    const TargetRegisterInfo *TRI) const;
     87 
     88   bool hasFP(const MachineFunction &MF) const;
     89   bool hasReservedCallFrame(const MachineFunction &MF) const;
     90 
     91   int getFrameIndexOffset(const MachineFunction &MF, int FI) const;
     92   int getFrameIndexReference(const MachineFunction &MF, int FI,
     93                              unsigned &FrameReg) const;
     94   uint32_t getCompactUnwindEncoding(MachineFunction &MF) const;
     95 
     96   void eliminateCallFramePseudoInstr(MachineFunction &MF,
     97                                      MachineBasicBlock &MBB,
     98                                      MachineBasicBlock::iterator MI) const;
     99 };
    100 
    101 } // End llvm namespace
    102 
    103 #endif
    104