blob: 13c4c31d93cd29c9fef2c90722c23dff01fd0e20 [file] [log] [blame]
Michael Kupersteine86aa9a2015-02-01 16:15:07 +00001//===-- 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
19namespace llvm {
20
Reid Kleckner3854f7b2015-06-18 18:03:25 +000021class MCCFIInstruction;
Reid Klecknerf9977bf2015-06-17 21:50:02 +000022class X86Subtarget;
23class X86RegisterInfo;
24
Michael Kupersteine86aa9a2015-02-01 16:15:07 +000025class X86FrameLowering : public TargetFrameLowering {
26public:
Reid Klecknerf9977bf2015-06-17 21:50:02 +000027 X86FrameLowering(const X86Subtarget &STI, unsigned StackAlignOverride);
28
29 // Cached subtarget predicates.
30
31 const X86Subtarget &STI;
32 const TargetInstrInfo &TII;
33 const X86RegisterInfo *RegInfo;
34
35 unsigned SlotSize;
36
37 /// Is64Bit implies that x86_64 instructions are available.
38 bool Is64Bit;
39
40 bool IsLP64;
41
42 /// True if the 64-bit frame or stack pointer should be used. True for most
43 /// 64-bit targets with the exception of x32. If this is false, 32-bit
44 /// instruction operands should be used to manipulate StackPtr and FramePtr.
45 bool Uses64BitFramePtr;
Michael Kupersteine86aa9a2015-02-01 16:15:07 +000046
Reid Kleckner3854f7b2015-06-18 18:03:25 +000047 unsigned StackPtr;
48
Michael Kupersteine86aa9a2015-02-01 16:15:07 +000049 /// Emit a call to the target's stack probe function. This is required for all
50 /// large stack allocations on Windows. The caller is required to materialize
51 /// the number of bytes to probe in RAX/EAX.
Reid Klecknerf9977bf2015-06-17 21:50:02 +000052 void emitStackProbeCall(MachineFunction &MF, MachineBasicBlock &MBB,
53 MachineBasicBlock::iterator MBBI, DebugLoc DL) const;
Michael Kupersteine86aa9a2015-02-01 16:15:07 +000054
55 void emitCalleeSavedFrameMoves(MachineBasicBlock &MBB,
56 MachineBasicBlock::iterator MBBI,
57 DebugLoc DL) const;
58
59 /// emitProlog/emitEpilog - These methods insert prolog and epilog code into
60 /// the function.
Quentin Colombet61b305e2015-05-05 17:38:16 +000061 void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
Michael Kupersteine86aa9a2015-02-01 16:15:07 +000062 void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
63
Quentin Colombet61b305e2015-05-05 17:38:16 +000064 void adjustForSegmentedStacks(MachineFunction &MF,
65 MachineBasicBlock &PrologueMBB) const override;
Michael Kupersteine86aa9a2015-02-01 16:15:07 +000066
Quentin Colombet61b305e2015-05-05 17:38:16 +000067 void adjustForHiPEPrologue(MachineFunction &MF,
68 MachineBasicBlock &PrologueMBB) const override;
Michael Kupersteine86aa9a2015-02-01 16:15:07 +000069
70 void processFunctionBeforeCalleeSavedScan(MachineFunction &MF,
71 RegScavenger *RS = nullptr) const override;
72
73 bool
74 assignCalleeSavedSpillSlots(MachineFunction &MF,
75 const TargetRegisterInfo *TRI,
76 std::vector<CalleeSavedInfo> &CSI) const override;
77
78 bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
79 MachineBasicBlock::iterator MI,
80 const std::vector<CalleeSavedInfo> &CSI,
81 const TargetRegisterInfo *TRI) const override;
82
83 bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
84 MachineBasicBlock::iterator MI,
85 const std::vector<CalleeSavedInfo> &CSI,
86 const TargetRegisterInfo *TRI) const override;
87
88 bool hasFP(const MachineFunction &MF) const override;
89 bool hasReservedCallFrame(const MachineFunction &MF) const override;
Michael Kuperstein13fbd452015-02-01 16:56:04 +000090 bool canSimplifyCallFramePseudos(const MachineFunction &MF) const override;
91 bool needsFrameIndexResolution(const MachineFunction &MF) const override;
Michael Kupersteine86aa9a2015-02-01 16:15:07 +000092
93 int getFrameIndexOffset(const MachineFunction &MF, int FI) const override;
94 int getFrameIndexReference(const MachineFunction &MF, int FI,
95 unsigned &FrameReg) const override;
96
97 int getFrameIndexOffsetFromSP(const MachineFunction &MF, int FI) const;
98 int getFrameIndexReferenceFromSP(const MachineFunction &MF, int FI,
99 unsigned &FrameReg) const override;
100
101 void eliminateCallFramePseudoInstr(MachineFunction &MF,
102 MachineBasicBlock &MBB,
103 MachineBasicBlock::iterator MI) const override;
104
Quentin Colombet494eb602015-05-22 18:10:47 +0000105 /// Check the instruction before/after the passed instruction. If
106 /// it is an ADD/SUB/LEA instruction it is deleted argument and the
107 /// stack adjustment is returned as a positive value for ADD/LEA and
108 /// a negative for SUB.
Reid Klecknerf9977bf2015-06-17 21:50:02 +0000109 int mergeSPUpdates(MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI,
Reid Kleckner3854f7b2015-06-18 18:03:25 +0000110 bool doMergeWithPrevious) const;
Quentin Colombet494eb602015-05-22 18:10:47 +0000111
112 /// Emit a series of instructions to increment / decrement the stack
113 /// pointer by a constant value.
Reid Klecknerf9977bf2015-06-17 21:50:02 +0000114 void emitSPUpdate(MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI,
Reid Kleckner3854f7b2015-06-18 18:03:25 +0000115 int64_t NumBytes, bool UseLEA) const;
Quentin Colombet494eb602015-05-22 18:10:47 +0000116
Quentin Colombetaa8020752015-05-27 06:28:41 +0000117 /// 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 Colombet494eb602015-05-22 18:10:47 +0000126
Michael Kupersteine86aa9a2015-02-01 16:15:07 +0000127private:
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 Klecknerf9977bf2015-06-17 21:50:02 +0000136
137 uint64_t calculateMaxStackAlign(const MachineFunction &MF) const;
Reid Kleckner3854f7b2015-06-18 18:03:25 +0000138
139 /// Wraps up getting a CFI index and building a MachineInstr for it.
140 void BuildCFI(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
141 DebugLoc DL, MCCFIInstruction CFIInst) const;
142
143 /// Aligns the stack pointer by ANDing it with -MaxAlign.
144 void BuildStackAlignAND(MachineBasicBlock &MBB,
145 MachineBasicBlock::iterator MBBI, DebugLoc DL,
146 uint64_t MaxAlign) const;
Michael Kupersteine86aa9a2015-02-01 16:15:07 +0000147};
148
149} // End llvm namespace
150
151#endif