blob: d76c52ce47df0da7b18a4578a5d570f9c787f455 [file] [log] [blame]
Jia Liub22310f2012-02-18 12:03:15 +00001//===-- X86InstrInfo.h - X86 Instruction Information ------------*- C++ -*-===//
Misha Brukmanc88330a2005-04-21 23:38:14 +00002//
John Criswell29265fe2003-10-21 15:17:13 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukmanc88330a2005-04-21 23:38:14 +00007//
John Criswell29265fe2003-10-21 15:17:13 +00008//===----------------------------------------------------------------------===//
Chris Lattnerd92fb002002-10-25 22:55:53 +00009//
Chris Lattnerb4d58d72003-01-14 22:00:31 +000010// This file contains the X86 implementation of the TargetInstrInfo class.
Chris Lattnerd92fb002002-10-25 22:55:53 +000011//
12//===----------------------------------------------------------------------===//
13
14#ifndef X86INSTRUCTIONINFO_H
15#define X86INSTRUCTIONINFO_H
16
Craig Topperc6d4efa2014-03-19 06:53:25 +000017#include "MCTargetDesc/X86BaseInfo.h"
Chris Lattnerd92fb002002-10-25 22:55:53 +000018#include "X86RegisterInfo.h"
Dan Gohman906152a2009-01-05 17:59:02 +000019#include "llvm/ADT/DenseMap.h"
Craig Topperb25fda92012-03-17 18:46:09 +000020#include "llvm/Target/TargetInstrInfo.h"
Chris Lattnerd92fb002002-10-25 22:55:53 +000021
Evan Cheng703a0fb2011-07-01 17:57:27 +000022#define GET_INSTRINFO_HEADER
23#include "X86GenInstrInfo.inc"
24
Brian Gaeke960707c2003-11-11 22:41:34 +000025namespace llvm {
Evan Cheng11b0a5d2006-09-08 06:48:29 +000026 class X86RegisterInfo;
Eric Christopher6c786a12014-06-10 22:34:31 +000027 class X86Subtarget;
Brian Gaeke960707c2003-11-11 22:41:34 +000028
Chris Lattnerc0fb5672006-10-20 17:42:20 +000029namespace X86 {
30 // X86 specific condition code. These correspond to X86_*_COND in
31 // X86InstrInfo.td. They must be kept in synch.
32 enum CondCode {
33 COND_A = 0,
34 COND_AE = 1,
35 COND_B = 2,
36 COND_BE = 3,
37 COND_E = 4,
38 COND_G = 5,
39 COND_GE = 6,
40 COND_L = 7,
41 COND_LE = 8,
42 COND_NE = 9,
43 COND_NO = 10,
44 COND_NP = 11,
45 COND_NS = 12,
Dan Gohman33e6fcd2009-01-07 00:15:08 +000046 COND_O = 13,
47 COND_P = 14,
48 COND_S = 15,
Juergen Ributzka2da1bbc2014-06-16 23:58:24 +000049 LAST_VALID_COND = COND_S,
Dan Gohman97d95d62008-10-21 03:29:32 +000050
51 // Artificial condition codes. These are used by AnalyzeBranch
52 // to indicate a block terminated with two conditional branches to
53 // the same location. This occurs in code using FCMP_OEQ or FCMP_UNE,
54 // which can't be represented on x86 with a single condition. These
55 // are never used in MachineInstrs.
56 COND_NE_OR_P,
57 COND_NP_OR_E,
58
Chris Lattnerc0fb5672006-10-20 17:42:20 +000059 COND_INVALID
60 };
Andrew Trick27c079e2011-03-05 06:31:54 +000061
Chris Lattnerc0fb5672006-10-20 17:42:20 +000062 // Turn condition code into conditional branch opcode.
63 unsigned GetCondBranchFromCond(CondCode CC);
Andrew Trick27c079e2011-03-05 06:31:54 +000064
Juergen Ributzka2da1bbc2014-06-16 23:58:24 +000065 /// \brief Return a set opcode for the given condition and whether it has
66 /// a memory operand.
67 unsigned getSETFromCond(CondCode CC, bool HasMemoryOperand = false);
68
Michael Liao32376622012-09-20 03:06:15 +000069 // Turn CMov opcode into condition code.
70 CondCode getCondFromCMovOpc(unsigned Opc);
71
Chris Lattner3a897f32006-10-21 05:52:40 +000072 /// GetOppositeBranchCondition - Return the inverse of the specified cond,
73 /// e.g. turning COND_E to COND_NE.
Juergen Ributzka2da1bbc2014-06-16 23:58:24 +000074 CondCode GetOppositeBranchCondition(CondCode CC);
Evan Cheng7e763d82011-07-25 18:43:53 +000075} // end namespace X86;
Chris Lattner3a897f32006-10-21 05:52:40 +000076
Chris Lattner377f1d52009-07-10 06:06:17 +000077
Chris Lattnerca9d7842009-07-10 06:29:59 +000078/// isGlobalStubReference - Return true if the specified TargetFlag operand is
Chris Lattner377f1d52009-07-10 06:06:17 +000079/// a reference to a stub for a global, not the global itself.
Chris Lattnerca9d7842009-07-10 06:29:59 +000080inline static bool isGlobalStubReference(unsigned char TargetFlag) {
81 switch (TargetFlag) {
Chris Lattner377f1d52009-07-10 06:06:17 +000082 case X86II::MO_DLLIMPORT: // dllimport stub.
83 case X86II::MO_GOTPCREL: // rip-relative GOT reference.
84 case X86II::MO_GOT: // normal GOT reference.
85 case X86II::MO_DARWIN_NONLAZY_PIC_BASE: // Normal $non_lazy_ptr ref.
86 case X86II::MO_DARWIN_NONLAZY: // Normal $non_lazy_ptr ref.
87 case X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE: // Hidden $non_lazy_ptr ref.
Chris Lattner377f1d52009-07-10 06:06:17 +000088 return true;
89 default:
90 return false;
91 }
92}
Chris Lattnerd3f32c72009-07-10 07:33:30 +000093
94/// isGlobalRelativeToPICBase - Return true if the specified global value
95/// reference is relative to a 32-bit PIC base (X86ISD::GlobalBaseReg). If this
96/// is true, the addressing mode has the PIC base register added in (e.g. EBX).
97inline static bool isGlobalRelativeToPICBase(unsigned char TargetFlag) {
98 switch (TargetFlag) {
99 case X86II::MO_GOTOFF: // isPICStyleGOT: local global.
100 case X86II::MO_GOT: // isPICStyleGOT: other global.
101 case X86II::MO_PIC_BASE_OFFSET: // Darwin local global.
102 case X86II::MO_DARWIN_NONLAZY_PIC_BASE: // Darwin/32 external global.
103 case X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE: // Darwin/32 hidden global.
Eric Christopherb0e1a452010-06-03 04:07:48 +0000104 case X86II::MO_TLVP: // ??? Pretty sure..
Chris Lattnerd3f32c72009-07-10 07:33:30 +0000105 return true;
106 default:
107 return false;
108 }
109}
Andrew Trick27c079e2011-03-05 06:31:54 +0000110
Anton Korobeynikov4e9dfe82008-06-28 11:07:54 +0000111inline static bool isScale(const MachineOperand &MO) {
Dan Gohman0d1e9a82008-10-03 15:45:36 +0000112 return MO.isImm() &&
Anton Korobeynikov4e9dfe82008-06-28 11:07:54 +0000113 (MO.getImm() == 1 || MO.getImm() == 2 ||
114 MO.getImm() == 4 || MO.getImm() == 8);
115}
116
Rafael Espindola3b2df102009-04-08 21:14:34 +0000117inline static bool isLeaMem(const MachineInstr *MI, unsigned Op) {
Dan Gohman0d1e9a82008-10-03 15:45:36 +0000118 if (MI->getOperand(Op).isFI()) return true;
Manuel Jacobdcb78db2014-03-18 16:14:11 +0000119 return Op+X86::AddrSegmentReg <= MI->getNumOperands() &&
120 MI->getOperand(Op+X86::AddrBaseReg).isReg() &&
121 isScale(MI->getOperand(Op+X86::AddrScaleAmt)) &&
122 MI->getOperand(Op+X86::AddrIndexReg).isReg() &&
123 (MI->getOperand(Op+X86::AddrDisp).isImm() ||
124 MI->getOperand(Op+X86::AddrDisp).isGlobal() ||
125 MI->getOperand(Op+X86::AddrDisp).isCPI() ||
126 MI->getOperand(Op+X86::AddrDisp).isJTI());
Anton Korobeynikov4e9dfe82008-06-28 11:07:54 +0000127}
128
Rafael Espindola3b2df102009-04-08 21:14:34 +0000129inline static bool isMem(const MachineInstr *MI, unsigned Op) {
130 if (MI->getOperand(Op).isFI()) return true;
Manuel Jacobdcb78db2014-03-18 16:14:11 +0000131 return Op+X86::AddrNumOperands <= MI->getNumOperands() &&
132 MI->getOperand(Op+X86::AddrSegmentReg).isReg() &&
Rafael Espindola3b2df102009-04-08 21:14:34 +0000133 isLeaMem(MI, Op);
134}
135
Craig Topperec828472014-03-31 06:53:13 +0000136class X86InstrInfo final : public X86GenInstrInfo {
Eric Christopher6c786a12014-06-10 22:34:31 +0000137 X86Subtarget &Subtarget;
Chris Lattnerd92fb002002-10-25 22:55:53 +0000138 const X86RegisterInfo RI;
Andrew Trick27c079e2011-03-05 06:31:54 +0000139
Craig Topper9eadcfd2012-06-01 05:34:01 +0000140 /// RegOp2MemOpTable3Addr, RegOp2MemOpTable0, RegOp2MemOpTable1,
141 /// RegOp2MemOpTable2, RegOp2MemOpTable3 - Load / store folding opcode maps.
Owen Anderson2a3be7b2008-01-07 01:35:02 +0000142 ///
Bruno Cardoso Lopes23eb5262011-09-08 18:35:57 +0000143 typedef DenseMap<unsigned,
144 std::pair<unsigned, unsigned> > RegOp2MemOpTableType;
145 RegOp2MemOpTableType RegOp2MemOpTable2Addr;
146 RegOp2MemOpTableType RegOp2MemOpTable0;
147 RegOp2MemOpTableType RegOp2MemOpTable1;
148 RegOp2MemOpTableType RegOp2MemOpTable2;
Elena Demikhovsky602f3a22012-05-31 09:20:20 +0000149 RegOp2MemOpTableType RegOp2MemOpTable3;
Andrew Trick27c079e2011-03-05 06:31:54 +0000150
Owen Anderson2a3be7b2008-01-07 01:35:02 +0000151 /// MemOp2RegOpTable - Load / store unfolding opcode map.
152 ///
Bruno Cardoso Lopes23eb5262011-09-08 18:35:57 +0000153 typedef DenseMap<unsigned,
154 std::pair<unsigned, unsigned> > MemOp2RegOpTableType;
155 MemOp2RegOpTableType MemOp2RegOpTable;
156
Craig Topperd9c7d0d2012-06-23 04:58:41 +0000157 static void AddTableEntry(RegOp2MemOpTableType &R2MTable,
158 MemOp2RegOpTableType &M2RTable,
159 unsigned RegOp, unsigned MemOp, unsigned Flags);
Jakob Stoklund Olesen49e121d2010-03-25 17:25:00 +0000160
Juergen Ributzkad12ccbd2013-11-19 00:57:56 +0000161 virtual void anchor();
162
Chris Lattnerd92fb002002-10-25 22:55:53 +0000163public:
Eric Christopher6c786a12014-06-10 22:34:31 +0000164 explicit X86InstrInfo(X86Subtarget &STI);
Chris Lattnerd92fb002002-10-25 22:55:53 +0000165
Chris Lattnerb4d58d72003-01-14 22:00:31 +0000166 /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As
Chris Lattnerd92fb002002-10-25 22:55:53 +0000167 /// such, whenever a client has an instance of instruction info, it should
168 /// always be able to get register info as well (through this method).
169 ///
Craig Topperf5e3b0b2014-03-09 07:58:15 +0000170 const X86RegisterInfo &getRegisterInfo() const { return RI; }
Chris Lattnerd92fb002002-10-25 22:55:53 +0000171
Evan Cheng30bebff2010-01-13 00:30:23 +0000172 /// isCoalescableExtInstr - Return true if the instruction is a "coalescable"
173 /// extension instruction. That is, it's like a copy where it's legal for the
174 /// source to overlap the destination. e.g. X86::MOVSX64rr32. If this returns
175 /// true, then it's expected the pre-extension value is available as a subreg
176 /// of the result register. This also returns the sub-register index in
177 /// SubIdx.
Craig Topper2d9361e2014-03-09 07:44:38 +0000178 bool isCoalescableExtInstr(const MachineInstr &MI,
179 unsigned &SrcReg, unsigned &DstReg,
180 unsigned &SubIdx) const override;
Evan Cheng42166152010-01-12 00:09:37 +0000181
Craig Topper2d9361e2014-03-09 07:44:38 +0000182 unsigned isLoadFromStackSlot(const MachineInstr *MI,
183 int &FrameIndex) const override;
David Greene2f4c3742009-11-13 00:29:53 +0000184 /// isLoadFromStackSlotPostFE - Check for post-frame ptr elimination
185 /// stack locations as well. This uses a heuristic so it isn't
186 /// reliable for correctness.
187 unsigned isLoadFromStackSlotPostFE(const MachineInstr *MI,
Craig Topper2d9361e2014-03-09 07:44:38 +0000188 int &FrameIndex) const override;
David Greene70fdd572009-11-12 20:55:29 +0000189
Craig Topper2d9361e2014-03-09 07:44:38 +0000190 unsigned isStoreToStackSlot(const MachineInstr *MI,
191 int &FrameIndex) const override;
David Greene2f4c3742009-11-13 00:29:53 +0000192 /// isStoreToStackSlotPostFE - Check for post-frame ptr elimination
193 /// stack locations as well. This uses a heuristic so it isn't
194 /// reliable for correctness.
195 unsigned isStoreToStackSlotPostFE(const MachineInstr *MI,
Craig Topper2d9361e2014-03-09 07:44:38 +0000196 int &FrameIndex) const override;
Evan Chenged6e34f2008-03-31 20:40:39 +0000197
Dan Gohmane919de52009-10-10 00:34:18 +0000198 bool isReallyTriviallyReMaterializable(const MachineInstr *MI,
Craig Topper2d9361e2014-03-09 07:44:38 +0000199 AliasAnalysis *AA) const override;
Evan Chenged6e34f2008-03-31 20:40:39 +0000200 void reMaterialize(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
Evan Cheng84517442009-07-16 09:20:10 +0000201 unsigned DestReg, unsigned SubIdx,
Evan Cheng6ad7da92009-11-14 02:55:43 +0000202 const MachineInstr *Orig,
Craig Topper2d9361e2014-03-09 07:44:38 +0000203 const TargetRegisterInfo &TRI) const override;
Evan Chenged6e34f2008-03-31 20:40:39 +0000204
Tim Northover6833e3f2013-06-10 20:43:49 +0000205 /// Given an operand within a MachineInstr, insert preceding code to put it
206 /// into the right format for a particular kind of LEA instruction. This may
207 /// involve using an appropriate super-register instead (with an implicit use
208 /// of the original) or creating a new virtual register and inserting COPY
209 /// instructions to get the data into the right class.
210 ///
211 /// Reference parameters are set to indicate how caller should add this
212 /// operand to the LEA instruction.
213 bool classifyLEAReg(MachineInstr *MI, const MachineOperand &Src,
214 unsigned LEAOpcode, bool AllowSP,
215 unsigned &NewSrc, bool &isKill,
216 bool &isUndef, MachineOperand &ImplicitOp) const;
217
Chris Lattnerb7782d72005-01-02 02:37:07 +0000218 /// convertToThreeAddress - This method must be implemented by targets that
219 /// set the M_CONVERTIBLE_TO_3_ADDR flag. When this flag is set, the target
220 /// may be able to convert a two-address instruction into a true
221 /// three-address instruction on demand. This allows the X86 target (for
222 /// example) to convert ADD and SHL instructions into LEA instructions if they
223 /// would require register copies due to two-addressness.
224 ///
225 /// This method returns a null pointer if the transformation cannot be
226 /// performed, otherwise it returns the new instruction.
227 ///
Craig Topper2d9361e2014-03-09 07:44:38 +0000228 MachineInstr *convertToThreeAddress(MachineFunction::iterator &MFI,
229 MachineBasicBlock::iterator &MBBI,
230 LiveVariables *LV) const override;
Chris Lattnerb7782d72005-01-02 02:37:07 +0000231
Chris Lattner29478012005-01-19 07:11:01 +0000232 /// commuteInstruction - We have a few instructions that must be hacked on to
233 /// commute them.
234 ///
Craig Topper2d9361e2014-03-09 07:44:38 +0000235 MachineInstr *commuteInstruction(MachineInstr *MI, bool NewMI) const override;
Chris Lattner29478012005-01-19 07:11:01 +0000236
Lang Hamesc59a2d02014-04-02 23:57:49 +0000237 bool findCommutedOpIndices(MachineInstr *MI, unsigned &SrcOpIdx1,
238 unsigned &SrcOpIdx2) const override;
239
Chris Lattnerc0fb5672006-10-20 17:42:20 +0000240 // Branch analysis.
Craig Topper2d9361e2014-03-09 07:44:38 +0000241 bool isUnpredicatedTerminator(const MachineInstr* MI) const override;
242 bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
243 MachineBasicBlock *&FBB,
244 SmallVectorImpl<MachineOperand> &Cond,
245 bool AllowModify) const override;
246 unsigned RemoveBranch(MachineBasicBlock &MBB) const override;
247 unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
248 MachineBasicBlock *FBB,
249 const SmallVectorImpl<MachineOperand> &Cond,
250 DebugLoc DL) const override;
251 bool canInsertSelect(const MachineBasicBlock&,
252 const SmallVectorImpl<MachineOperand> &Cond,
253 unsigned, unsigned, int&, int&, int&) const override;
254 void insertSelect(MachineBasicBlock &MBB,
255 MachineBasicBlock::iterator MI, DebugLoc DL,
256 unsigned DstReg,
257 const SmallVectorImpl<MachineOperand> &Cond,
258 unsigned TrueReg, unsigned FalseReg) const override;
259 void copyPhysReg(MachineBasicBlock &MBB,
260 MachineBasicBlock::iterator MI, DebugLoc DL,
261 unsigned DestReg, unsigned SrcReg,
262 bool KillSrc) const override;
263 void storeRegToStackSlot(MachineBasicBlock &MBB,
264 MachineBasicBlock::iterator MI,
265 unsigned SrcReg, bool isKill, int FrameIndex,
266 const TargetRegisterClass *RC,
267 const TargetRegisterInfo *TRI) const override;
Owen Andersoneee14602008-01-01 21:11:32 +0000268
Craig Topperf5e3b0b2014-03-09 07:58:15 +0000269 void storeRegToAddr(MachineFunction &MF, unsigned SrcReg, bool isKill,
270 SmallVectorImpl<MachineOperand> &Addr,
271 const TargetRegisterClass *RC,
272 MachineInstr::mmo_iterator MMOBegin,
273 MachineInstr::mmo_iterator MMOEnd,
274 SmallVectorImpl<MachineInstr*> &NewMIs) const;
Owen Andersoneee14602008-01-01 21:11:32 +0000275
Craig Topper2d9361e2014-03-09 07:44:38 +0000276 void loadRegFromStackSlot(MachineBasicBlock &MBB,
277 MachineBasicBlock::iterator MI,
278 unsigned DestReg, int FrameIndex,
279 const TargetRegisterClass *RC,
280 const TargetRegisterInfo *TRI) const override;
Owen Andersoneee14602008-01-01 21:11:32 +0000281
Craig Topperf5e3b0b2014-03-09 07:58:15 +0000282 void loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
283 SmallVectorImpl<MachineOperand> &Addr,
284 const TargetRegisterClass *RC,
285 MachineInstr::mmo_iterator MMOBegin,
286 MachineInstr::mmo_iterator MMOEnd,
287 SmallVectorImpl<MachineInstr*> &NewMIs) const;
Jakob Stoklund Olesendd1904e2011-09-29 05:10:54 +0000288
Craig Topper2d9361e2014-03-09 07:44:38 +0000289 bool expandPostRAPseudo(MachineBasicBlock::iterator MI) const override;
Jakob Stoklund Olesendd1904e2011-09-29 05:10:54 +0000290
Owen Anderson2a3be7b2008-01-07 01:35:02 +0000291 /// foldMemoryOperand - If this target supports it, fold a load or store of
292 /// the specified stack slot into the specified machine instruction for the
293 /// specified operand(s). If this is possible, the target should perform the
294 /// folding and return true, otherwise it should return false. If it folds
295 /// the instruction, it is likely that the MachineInstruction the iterator
296 /// references has been changed.
Craig Topper2d9361e2014-03-09 07:44:38 +0000297 MachineInstr* foldMemoryOperandImpl(MachineFunction &MF,
298 MachineInstr* MI,
299 const SmallVectorImpl<unsigned> &Ops,
300 int FrameIndex) const override;
Owen Anderson2a3be7b2008-01-07 01:35:02 +0000301
302 /// foldMemoryOperand - Same as the previous version except it allows folding
303 /// of any load and store from / to any address, not just from a specific
304 /// stack slot.
Craig Topper2d9361e2014-03-09 07:44:38 +0000305 MachineInstr* foldMemoryOperandImpl(MachineFunction &MF,
306 MachineInstr* MI,
307 const SmallVectorImpl<unsigned> &Ops,
308 MachineInstr* LoadMI) const override;
Owen Anderson2a3be7b2008-01-07 01:35:02 +0000309
310 /// canFoldMemoryOperand - Returns true if the specified load / store is
311 /// folding is possible.
Craig Topper2d9361e2014-03-09 07:44:38 +0000312 bool canFoldMemoryOperand(const MachineInstr*,
313 const SmallVectorImpl<unsigned> &) const override;
Owen Anderson2a3be7b2008-01-07 01:35:02 +0000314
315 /// unfoldMemoryOperand - Separate a single instruction which folded a load or
316 /// a store or a load and a store into two or more instruction. If this is
317 /// possible, returns true as well as the new instructions by reference.
Craig Topper2d9361e2014-03-09 07:44:38 +0000318 bool unfoldMemoryOperand(MachineFunction &MF, MachineInstr *MI,
319 unsigned Reg, bool UnfoldLoad, bool UnfoldStore,
320 SmallVectorImpl<MachineInstr*> &NewMIs) const override;
Owen Anderson2a3be7b2008-01-07 01:35:02 +0000321
Craig Topper2d9361e2014-03-09 07:44:38 +0000322 bool unfoldMemoryOperand(SelectionDAG &DAG, SDNode *N,
323 SmallVectorImpl<SDNode*> &NewNodes) const override;
Owen Anderson2a3be7b2008-01-07 01:35:02 +0000324
325 /// getOpcodeAfterMemoryUnfold - Returns the opcode of the would be new
326 /// instruction after load / store are unfolded from an instruction of the
327 /// specified opcode. It returns zero if the specified unfolding is not
Dan Gohman49fa51d2009-10-30 22:18:41 +0000328 /// possible. If LoadRegIndex is non-null, it is filled in with the operand
329 /// index of the operand which will hold the register holding the loaded
330 /// value.
Craig Topper2d9361e2014-03-09 07:44:38 +0000331 unsigned getOpcodeAfterMemoryUnfold(unsigned Opc,
332 bool UnfoldLoad, bool UnfoldStore,
Craig Toppere73658d2014-04-28 04:05:08 +0000333 unsigned *LoadRegIndex = nullptr) const override;
Andrew Trick27c079e2011-03-05 06:31:54 +0000334
Evan Cheng4f026f32010-01-22 03:34:51 +0000335 /// areLoadsFromSameBasePtr - This is used by the pre-regalloc scheduler
336 /// to determine if two loads are loading from the same base address. It
337 /// should only return true if the base pointers are the same and the
338 /// only differences between the two addresses are the offset. It also returns
339 /// the offsets by reference.
Craig Topper2d9361e2014-03-09 07:44:38 +0000340 bool areLoadsFromSameBasePtr(SDNode *Load1, SDNode *Load2, int64_t &Offset1,
341 int64_t &Offset2) const override;
Evan Cheng4f026f32010-01-22 03:34:51 +0000342
343 /// shouldScheduleLoadsNear - This is a used by the pre-regalloc scheduler to
Chris Lattner0ab5e2c2011-04-15 05:18:47 +0000344 /// determine (in conjunction with areLoadsFromSameBasePtr) if two loads should
Evan Cheng4f026f32010-01-22 03:34:51 +0000345 /// be scheduled togther. On some targets if two loads are loading from
346 /// addresses in the same cache line, it's better if they are scheduled
347 /// together. This function takes two integers that represent the load offsets
348 /// from the common base address. It returns true if it decides it's desirable
349 /// to schedule the two loads together. "NumLoads" is the number of loads that
350 /// have already been scheduled after Load1.
Craig Topper2d9361e2014-03-09 07:44:38 +0000351 bool shouldScheduleLoadsNear(SDNode *Load1, SDNode *Load2,
352 int64_t Offset1, int64_t Offset2,
353 unsigned NumLoads) const override;
Evan Cheng4f026f32010-01-22 03:34:51 +0000354
Craig Topper2d9361e2014-03-09 07:44:38 +0000355 bool shouldScheduleAdjacent(MachineInstr* First,
356 MachineInstr *Second) const override;
Andrew Trick47740de2013-06-23 09:00:28 +0000357
Craig Topper2d9361e2014-03-09 07:44:38 +0000358 void getNoopForMachoTarget(MCInst &NopInst) const override;
Chris Lattner6a5e7062010-04-26 23:37:21 +0000359
Craig Topper2d9361e2014-03-09 07:44:38 +0000360 bool
361 ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const override;
Chris Lattner29478012005-01-19 07:11:01 +0000362
Evan Chengb5f0ec32009-02-06 17:17:30 +0000363 /// isSafeToMoveRegClassDefs - Return true if it's safe to move a machine
364 /// instruction that defines the specified register class.
Craig Topper2d9361e2014-03-09 07:44:38 +0000365 bool isSafeToMoveRegClassDefs(const TargetRegisterClass *RC) const override;
Evan Chengf7137222008-10-27 07:14:50 +0000366
Alexey Volkov6226de62014-05-20 08:55:50 +0000367 /// isSafeToClobberEFLAGS - Return true if it's safe insert an instruction tha
368 /// would clobber the EFLAGS condition register. Note the result may be
369 /// conservative. If it cannot definitely determine the safety after visiting
370 /// a few instructions in each direction it assumes it's not safe.
371 bool isSafeToClobberEFLAGS(MachineBasicBlock &MBB,
372 MachineBasicBlock::iterator I) const;
373
Chris Lattner58827ff2010-02-05 22:10:22 +0000374 static bool isX86_64ExtendedReg(const MachineOperand &MO) {
375 if (!MO.isReg()) return false;
Evan Cheng7e763d82011-07-25 18:43:53 +0000376 return X86II::isX86_64ExtendedReg(MO.getReg());
Chris Lattner58827ff2010-02-05 22:10:22 +0000377 }
Nicolas Geoffrayae84bbd2008-04-16 20:10:13 +0000378
Dan Gohman6ebe7342008-09-30 00:58:23 +0000379 /// getGlobalBaseReg - Return a virtual register initialized with the
380 /// the global base register value. Output instructions required to
381 /// initialize the register in the function entry block, if necessary.
Dan Gohman24300732008-09-23 18:22:58 +0000382 ///
Dan Gohman6ebe7342008-09-30 00:58:23 +0000383 unsigned getGlobalBaseReg(MachineFunction *MF) const;
Dan Gohman24300732008-09-23 18:22:58 +0000384
Jakob Stoklund Olesenb48c9942011-09-27 22:57:18 +0000385 std::pair<uint16_t, uint16_t>
Craig Topper2d9361e2014-03-09 07:44:38 +0000386 getExecutionDomain(const MachineInstr *MI) const override;
Jakob Stoklund Olesenb551aa42010-03-29 23:24:21 +0000387
Craig Topper2d9361e2014-03-09 07:44:38 +0000388 void setExecutionDomain(MachineInstr *MI, unsigned Domain) const override;
Jakob Stoklund Olesen49e121d2010-03-25 17:25:00 +0000389
Craig Topper2d9361e2014-03-09 07:44:38 +0000390 unsigned
391 getPartialRegUpdateClearance(const MachineInstr *MI, unsigned OpNum,
392 const TargetRegisterInfo *TRI) const override;
Andrew Trickb6d56be2013-10-14 22:19:03 +0000393 unsigned getUndefRegClearance(const MachineInstr *MI, unsigned &OpNum,
Craig Topper2d9361e2014-03-09 07:44:38 +0000394 const TargetRegisterInfo *TRI) const override;
Jakob Stoklund Olesenf8ad3362011-11-15 01:15:30 +0000395 void breakPartialRegDependency(MachineBasicBlock::iterator MI, unsigned OpNum,
Craig Topper2d9361e2014-03-09 07:44:38 +0000396 const TargetRegisterInfo *TRI) const override;
Jakob Stoklund Olesenf8ad3362011-11-15 01:15:30 +0000397
Chris Lattnereeba0c72010-09-05 02:18:34 +0000398 MachineInstr* foldMemoryOperandImpl(MachineFunction &MF,
399 MachineInstr* MI,
400 unsigned OpNum,
401 const SmallVectorImpl<MachineOperand> &MOs,
402 unsigned Size, unsigned Alignment) const;
Evan Cheng63c76082010-10-19 18:58:51 +0000403
Tom Roeder44cb65f2014-06-05 19:29:43 +0000404 void
405 getUnconditionalBranch(MCInst &Branch,
406 const MCSymbolRefExpr *BranchTarget) const override;
407
408 void getTrap(MCInst &MI) const override;
409
Craig Topper2d9361e2014-03-09 07:44:38 +0000410 bool isHighLatencyDef(int opc) const override;
Andrew Trick641e2d42011-03-05 08:00:22 +0000411
Evan Cheng63c76082010-10-19 18:58:51 +0000412 bool hasHighOperandLatency(const InstrItineraryData *ItinData,
413 const MachineRegisterInfo *MRI,
414 const MachineInstr *DefMI, unsigned DefIdx,
Craig Topper2d9361e2014-03-09 07:44:38 +0000415 const MachineInstr *UseMI,
416 unsigned UseIdx) const override;
Andrew Trick27c079e2011-03-05 06:31:54 +0000417
Manman Renc9656732012-07-06 17:36:20 +0000418 /// analyzeCompare - For a comparison instruction, return the source registers
419 /// in SrcReg and SrcReg2 if having two register operands, and the value it
420 /// compares against in CmpValue. Return true if the comparison instruction
421 /// can be analyzed.
Craig Topper2d9361e2014-03-09 07:44:38 +0000422 bool analyzeCompare(const MachineInstr *MI, unsigned &SrcReg,
423 unsigned &SrcReg2, int &CmpMask,
424 int &CmpValue) const override;
Manman Renc9656732012-07-06 17:36:20 +0000425
426 /// optimizeCompareInstr - Check if there exists an earlier instruction that
427 /// operates on the same source operands and sets flags in the same way as
428 /// Compare; remove Compare if possible.
Craig Topper2d9361e2014-03-09 07:44:38 +0000429 bool optimizeCompareInstr(MachineInstr *CmpInstr, unsigned SrcReg,
430 unsigned SrcReg2, int CmpMask, int CmpValue,
431 const MachineRegisterInfo *MRI) const override;
Manman Renc9656732012-07-06 17:36:20 +0000432
Manman Ren5759d012012-08-02 00:56:42 +0000433 /// optimizeLoadInstr - Try to remove the load by folding it to a register
434 /// operand at the use. We fold the load instructions if and only if the
Manman Renba8122c2012-08-02 19:37:32 +0000435 /// def and use are in the same BB. We only look at one load and see
436 /// whether it can be folded into MI. FoldAsLoadDefReg is the virtual register
437 /// defined by the load we are trying to fold. DefMI returns the machine
438 /// instruction that defines FoldAsLoadDefReg, and the function returns
439 /// the machine instruction generated due to folding.
Craig Topper2d9361e2014-03-09 07:44:38 +0000440 MachineInstr* optimizeLoadInstr(MachineInstr *MI,
441 const MachineRegisterInfo *MRI,
442 unsigned &FoldAsLoadDefReg,
443 MachineInstr *&DefMI) const override;
Manman Ren5759d012012-08-02 00:56:42 +0000444
Owen Anderson2a3be7b2008-01-07 01:35:02 +0000445private:
Evan Cheng766a73f2009-12-11 06:01:48 +0000446 MachineInstr * convertToThreeAddressWithLEA(unsigned MIOpc,
447 MachineFunction::iterator &MFI,
448 MachineBasicBlock::iterator &MBBI,
449 LiveVariables *LV) const;
450
David Greene70fdd572009-11-12 20:55:29 +0000451 /// isFrameOperand - Return true and the FrameIndex if the specified
452 /// operand and follow operands form a reference to the stack frame.
453 bool isFrameOperand(const MachineInstr *MI, unsigned int Op,
454 int &FrameIndex) const;
Chris Lattnerd92fb002002-10-25 22:55:53 +0000455};
456
Brian Gaeke960707c2003-11-11 22:41:34 +0000457} // End llvm namespace
458
Chris Lattnerd92fb002002-10-25 22:55:53 +0000459#endif