Michael Kuperstein | e86aa9a | 2015-02-01 16:15:07 +0000 | [diff] [blame] | 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 LLVM_LIB_TARGET_X86_X86FRAMELOWERING_H |
| 15 | #define LLVM_LIB_TARGET_X86_X86FRAMELOWERING_H |
| 16 | |
| 17 | #include "llvm/Target/TargetFrameLowering.h" |
| 18 | |
| 19 | namespace llvm { |
| 20 | |
Michael Kuperstein | e86aa9a | 2015-02-01 16:15:07 +0000 | [diff] [blame] | 21 | class X86FrameLowering : public TargetFrameLowering { |
| 22 | public: |
| 23 | explicit X86FrameLowering(StackDirection D, unsigned StackAl, int LAO) |
| 24 | : TargetFrameLowering(StackGrowsDown, StackAl, LAO) {} |
| 25 | |
| 26 | /// Emit a call to the target's stack probe function. This is required for all |
| 27 | /// large stack allocations on Windows. The caller is required to materialize |
| 28 | /// the number of bytes to probe in RAX/EAX. |
| 29 | static void emitStackProbeCall(MachineFunction &MF, MachineBasicBlock &MBB, |
| 30 | MachineBasicBlock::iterator MBBI, DebugLoc DL); |
| 31 | |
| 32 | void emitCalleeSavedFrameMoves(MachineBasicBlock &MBB, |
| 33 | MachineBasicBlock::iterator MBBI, |
| 34 | DebugLoc DL) const; |
| 35 | |
| 36 | /// emitProlog/emitEpilog - These methods insert prolog and epilog code into |
| 37 | /// the function. |
Quentin Colombet | 61b305e | 2015-05-05 17:38:16 +0000 | [diff] [blame] | 38 | void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override; |
Michael Kuperstein | e86aa9a | 2015-02-01 16:15:07 +0000 | [diff] [blame] | 39 | void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override; |
| 40 | |
Quentin Colombet | 61b305e | 2015-05-05 17:38:16 +0000 | [diff] [blame] | 41 | void adjustForSegmentedStacks(MachineFunction &MF, |
| 42 | MachineBasicBlock &PrologueMBB) const override; |
Michael Kuperstein | e86aa9a | 2015-02-01 16:15:07 +0000 | [diff] [blame] | 43 | |
Quentin Colombet | 61b305e | 2015-05-05 17:38:16 +0000 | [diff] [blame] | 44 | void adjustForHiPEPrologue(MachineFunction &MF, |
| 45 | MachineBasicBlock &PrologueMBB) const override; |
Michael Kuperstein | e86aa9a | 2015-02-01 16:15:07 +0000 | [diff] [blame] | 46 | |
| 47 | void processFunctionBeforeCalleeSavedScan(MachineFunction &MF, |
| 48 | RegScavenger *RS = nullptr) const override; |
| 49 | |
| 50 | bool |
| 51 | assignCalleeSavedSpillSlots(MachineFunction &MF, |
| 52 | const TargetRegisterInfo *TRI, |
| 53 | std::vector<CalleeSavedInfo> &CSI) const override; |
| 54 | |
| 55 | bool spillCalleeSavedRegisters(MachineBasicBlock &MBB, |
| 56 | MachineBasicBlock::iterator MI, |
| 57 | const std::vector<CalleeSavedInfo> &CSI, |
| 58 | const TargetRegisterInfo *TRI) const override; |
| 59 | |
| 60 | bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB, |
| 61 | MachineBasicBlock::iterator MI, |
| 62 | const std::vector<CalleeSavedInfo> &CSI, |
| 63 | const TargetRegisterInfo *TRI) const override; |
| 64 | |
| 65 | bool hasFP(const MachineFunction &MF) const override; |
| 66 | bool hasReservedCallFrame(const MachineFunction &MF) const override; |
Michael Kuperstein | 13fbd45 | 2015-02-01 16:56:04 +0000 | [diff] [blame] | 67 | bool canSimplifyCallFramePseudos(const MachineFunction &MF) const override; |
| 68 | bool needsFrameIndexResolution(const MachineFunction &MF) const override; |
Michael Kuperstein | e86aa9a | 2015-02-01 16:15:07 +0000 | [diff] [blame] | 69 | |
| 70 | int getFrameIndexOffset(const MachineFunction &MF, int FI) const override; |
| 71 | int getFrameIndexReference(const MachineFunction &MF, int FI, |
| 72 | unsigned &FrameReg) const override; |
| 73 | |
| 74 | int getFrameIndexOffsetFromSP(const MachineFunction &MF, int FI) const; |
| 75 | int getFrameIndexReferenceFromSP(const MachineFunction &MF, int FI, |
| 76 | unsigned &FrameReg) const override; |
| 77 | |
| 78 | void eliminateCallFramePseudoInstr(MachineFunction &MF, |
| 79 | MachineBasicBlock &MBB, |
| 80 | MachineBasicBlock::iterator MI) const override; |
| 81 | |
Quentin Colombet | 494eb60 | 2015-05-22 18:10:47 +0000 | [diff] [blame] | 82 | /// Check the instruction before/after the passed instruction. If |
| 83 | /// it is an ADD/SUB/LEA instruction it is deleted argument and the |
| 84 | /// stack adjustment is returned as a positive value for ADD/LEA and |
| 85 | /// a negative for SUB. |
| 86 | static int mergeSPUpdates(MachineBasicBlock &MBB, |
| 87 | MachineBasicBlock::iterator &MBBI, |
| 88 | unsigned StackPtr, bool doMergeWithPrevious); |
| 89 | |
| 90 | /// Emit a series of instructions to increment / decrement the stack |
| 91 | /// pointer by a constant value. |
| 92 | static void emitSPUpdate(MachineBasicBlock &MBB, |
| 93 | MachineBasicBlock::iterator &MBBI, unsigned StackPtr, |
| 94 | int64_t NumBytes, bool Is64BitTarget, |
| 95 | bool Is64BitStackPtr, bool UseLEA, |
| 96 | const TargetInstrInfo &TII, |
| 97 | const TargetRegisterInfo &TRI); |
| 98 | |
Quentin Colombet | aa802075 | 2015-05-27 06:28:41 +0000 | [diff] [blame^] | 99 | /// Check that LEA can be used on SP in an epilogue sequence for \p MF. |
| 100 | bool canUseLEAForSPInEpilogue(const MachineFunction &MF) const; |
| 101 | |
| 102 | /// Check whether or not the given \p MBB can be used as a epilogue |
| 103 | /// for the target. |
| 104 | /// The epilogue will be inserted before the first terminator of that block. |
| 105 | /// This method is used by the shrink-wrapping pass to decide if |
| 106 | /// \p MBB will be correctly handled by the target. |
| 107 | bool canUseAsEpilogue(const MachineBasicBlock &MBB) const override; |
Quentin Colombet | 494eb60 | 2015-05-22 18:10:47 +0000 | [diff] [blame] | 108 | |
Michael Kuperstein | e86aa9a | 2015-02-01 16:15:07 +0000 | [diff] [blame] | 109 | private: |
| 110 | /// convertArgMovsToPushes - This method tries to convert a call sequence |
| 111 | /// that uses sub and mov instructions to put the argument onto the stack |
| 112 | /// into a series of pushes. |
| 113 | /// Returns true if the transformation succeeded, false if not. |
| 114 | bool convertArgMovsToPushes(MachineFunction &MF, |
| 115 | MachineBasicBlock &MBB, |
| 116 | MachineBasicBlock::iterator I, |
| 117 | uint64_t Amount) const; |
| 118 | }; |
| 119 | |
| 120 | } // End llvm namespace |
| 121 | |
| 122 | #endif |