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