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