blob: 332874f5b6c9fa3aa9115ab7a60b3eece420a991 [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
Nicolas Geoffrayae84bbd2008-04-16 20:10:13 +000017#include "X86.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;
Evan Chengc8c172e2006-05-30 21:45:53 +000027 class X86TargetMachine;
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,
Dan Gohman97d95d62008-10-21 03:29:32 +000049
50 // Artificial condition codes. These are used by AnalyzeBranch
51 // to indicate a block terminated with two conditional branches to
52 // the same location. This occurs in code using FCMP_OEQ or FCMP_UNE,
53 // which can't be represented on x86 with a single condition. These
54 // are never used in MachineInstrs.
55 COND_NE_OR_P,
56 COND_NP_OR_E,
57
Chris Lattnerc0fb5672006-10-20 17:42:20 +000058 COND_INVALID
59 };
Andrew Trick27c079e2011-03-05 06:31:54 +000060
Chris Lattnerc0fb5672006-10-20 17:42:20 +000061 // Turn condition code into conditional branch opcode.
62 unsigned GetCondBranchFromCond(CondCode CC);
Andrew Trick27c079e2011-03-05 06:31:54 +000063
Michael Liao32376622012-09-20 03:06:15 +000064 // Turn CMov opcode into condition code.
65 CondCode getCondFromCMovOpc(unsigned Opc);
66
Chris Lattner3a897f32006-10-21 05:52:40 +000067 /// GetOppositeBranchCondition - Return the inverse of the specified cond,
68 /// e.g. turning COND_E to COND_NE.
69 CondCode GetOppositeBranchCondition(X86::CondCode CC);
Evan Cheng7e763d82011-07-25 18:43:53 +000070} // end namespace X86;
Chris Lattner3a897f32006-10-21 05:52:40 +000071
Chris Lattner377f1d52009-07-10 06:06:17 +000072
Chris Lattnerca9d7842009-07-10 06:29:59 +000073/// isGlobalStubReference - Return true if the specified TargetFlag operand is
Chris Lattner377f1d52009-07-10 06:06:17 +000074/// a reference to a stub for a global, not the global itself.
Chris Lattnerca9d7842009-07-10 06:29:59 +000075inline static bool isGlobalStubReference(unsigned char TargetFlag) {
76 switch (TargetFlag) {
Chris Lattner377f1d52009-07-10 06:06:17 +000077 case X86II::MO_DLLIMPORT: // dllimport stub.
78 case X86II::MO_GOTPCREL: // rip-relative GOT reference.
79 case X86II::MO_GOT: // normal GOT reference.
80 case X86II::MO_DARWIN_NONLAZY_PIC_BASE: // Normal $non_lazy_ptr ref.
81 case X86II::MO_DARWIN_NONLAZY: // Normal $non_lazy_ptr ref.
82 case X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE: // Hidden $non_lazy_ptr ref.
Chris Lattner377f1d52009-07-10 06:06:17 +000083 return true;
84 default:
85 return false;
86 }
87}
Chris Lattnerd3f32c72009-07-10 07:33:30 +000088
89/// isGlobalRelativeToPICBase - Return true if the specified global value
90/// reference is relative to a 32-bit PIC base (X86ISD::GlobalBaseReg). If this
91/// is true, the addressing mode has the PIC base register added in (e.g. EBX).
92inline static bool isGlobalRelativeToPICBase(unsigned char TargetFlag) {
93 switch (TargetFlag) {
94 case X86II::MO_GOTOFF: // isPICStyleGOT: local global.
95 case X86II::MO_GOT: // isPICStyleGOT: other global.
96 case X86II::MO_PIC_BASE_OFFSET: // Darwin local global.
97 case X86II::MO_DARWIN_NONLAZY_PIC_BASE: // Darwin/32 external global.
98 case X86II::MO_DARWIN_HIDDEN_NONLAZY_PIC_BASE: // Darwin/32 hidden global.
Eric Christopherb0e1a452010-06-03 04:07:48 +000099 case X86II::MO_TLVP: // ??? Pretty sure..
Chris Lattnerd3f32c72009-07-10 07:33:30 +0000100 return true;
101 default:
102 return false;
103 }
104}
Andrew Trick27c079e2011-03-05 06:31:54 +0000105
Anton Korobeynikov4e9dfe82008-06-28 11:07:54 +0000106inline static bool isScale(const MachineOperand &MO) {
Dan Gohman0d1e9a82008-10-03 15:45:36 +0000107 return MO.isImm() &&
Anton Korobeynikov4e9dfe82008-06-28 11:07:54 +0000108 (MO.getImm() == 1 || MO.getImm() == 2 ||
109 MO.getImm() == 4 || MO.getImm() == 8);
110}
111
Rafael Espindola3b2df102009-04-08 21:14:34 +0000112inline static bool isLeaMem(const MachineInstr *MI, unsigned Op) {
Dan Gohman0d1e9a82008-10-03 15:45:36 +0000113 if (MI->getOperand(Op).isFI()) return true;
Anton Korobeynikov4e9dfe82008-06-28 11:07:54 +0000114 return Op+4 <= MI->getNumOperands() &&
Dan Gohman0d1e9a82008-10-03 15:45:36 +0000115 MI->getOperand(Op ).isReg() && isScale(MI->getOperand(Op+1)) &&
116 MI->getOperand(Op+2).isReg() &&
117 (MI->getOperand(Op+3).isImm() ||
118 MI->getOperand(Op+3).isGlobal() ||
119 MI->getOperand(Op+3).isCPI() ||
120 MI->getOperand(Op+3).isJTI());
Anton Korobeynikov4e9dfe82008-06-28 11:07:54 +0000121}
122
Rafael Espindola3b2df102009-04-08 21:14:34 +0000123inline static bool isMem(const MachineInstr *MI, unsigned Op) {
124 if (MI->getOperand(Op).isFI()) return true;
125 return Op+5 <= MI->getNumOperands() &&
126 MI->getOperand(Op+4).isReg() &&
127 isLeaMem(MI, Op);
128}
129
Evan Cheng703a0fb2011-07-01 17:57:27 +0000130class X86InstrInfo : public X86GenInstrInfo {
Evan Chengc8c172e2006-05-30 21:45:53 +0000131 X86TargetMachine &TM;
Chris Lattnerd92fb002002-10-25 22:55:53 +0000132 const X86RegisterInfo RI;
Andrew Trick27c079e2011-03-05 06:31:54 +0000133
Craig Topper9eadcfd2012-06-01 05:34:01 +0000134 /// RegOp2MemOpTable3Addr, RegOp2MemOpTable0, RegOp2MemOpTable1,
135 /// RegOp2MemOpTable2, RegOp2MemOpTable3 - Load / store folding opcode maps.
Owen Anderson2a3be7b2008-01-07 01:35:02 +0000136 ///
Bruno Cardoso Lopes23eb5262011-09-08 18:35:57 +0000137 typedef DenseMap<unsigned,
138 std::pair<unsigned, unsigned> > RegOp2MemOpTableType;
139 RegOp2MemOpTableType RegOp2MemOpTable2Addr;
140 RegOp2MemOpTableType RegOp2MemOpTable0;
141 RegOp2MemOpTableType RegOp2MemOpTable1;
142 RegOp2MemOpTableType RegOp2MemOpTable2;
Elena Demikhovsky602f3a22012-05-31 09:20:20 +0000143 RegOp2MemOpTableType RegOp2MemOpTable3;
Andrew Trick27c079e2011-03-05 06:31:54 +0000144
Owen Anderson2a3be7b2008-01-07 01:35:02 +0000145 /// MemOp2RegOpTable - Load / store unfolding opcode map.
146 ///
Bruno Cardoso Lopes23eb5262011-09-08 18:35:57 +0000147 typedef DenseMap<unsigned,
148 std::pair<unsigned, unsigned> > MemOp2RegOpTableType;
149 MemOp2RegOpTableType MemOp2RegOpTable;
150
Craig Topperd9c7d0d2012-06-23 04:58:41 +0000151 static void AddTableEntry(RegOp2MemOpTableType &R2MTable,
152 MemOp2RegOpTableType &M2RTable,
153 unsigned RegOp, unsigned MemOp, unsigned Flags);
Jakob Stoklund Olesen49e121d2010-03-25 17:25:00 +0000154
Chris Lattnerd92fb002002-10-25 22:55:53 +0000155public:
Dan Gohmanc60c67f2008-03-25 22:06:05 +0000156 explicit X86InstrInfo(X86TargetMachine &tm);
Chris Lattnerd92fb002002-10-25 22:55:53 +0000157
Chris Lattnerb4d58d72003-01-14 22:00:31 +0000158 /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As
Chris Lattnerd92fb002002-10-25 22:55:53 +0000159 /// such, whenever a client has an instance of instruction info, it should
160 /// always be able to get register info as well (through this method).
161 ///
Dan Gohmaneabd6472008-05-14 01:58:56 +0000162 virtual const X86RegisterInfo &getRegisterInfo() const { return RI; }
Chris Lattnerd92fb002002-10-25 22:55:53 +0000163
Evan Cheng30bebff2010-01-13 00:30:23 +0000164 /// isCoalescableExtInstr - Return true if the instruction is a "coalescable"
165 /// extension instruction. That is, it's like a copy where it's legal for the
166 /// source to overlap the destination. e.g. X86::MOVSX64rr32. If this returns
167 /// true, then it's expected the pre-extension value is available as a subreg
168 /// of the result register. This also returns the sub-register index in
169 /// SubIdx.
170 virtual bool isCoalescableExtInstr(const MachineInstr &MI,
171 unsigned &SrcReg, unsigned &DstReg,
172 unsigned &SubIdx) const;
Evan Cheng42166152010-01-12 00:09:37 +0000173
Dan Gohman0b273252008-11-18 19:49:32 +0000174 unsigned isLoadFromStackSlot(const MachineInstr *MI, int &FrameIndex) const;
David Greene2f4c3742009-11-13 00:29:53 +0000175 /// isLoadFromStackSlotPostFE - Check for post-frame ptr elimination
176 /// stack locations as well. This uses a heuristic so it isn't
177 /// reliable for correctness.
178 unsigned isLoadFromStackSlotPostFE(const MachineInstr *MI,
179 int &FrameIndex) const;
David Greene70fdd572009-11-12 20:55:29 +0000180
Dan Gohman0b273252008-11-18 19:49:32 +0000181 unsigned isStoreToStackSlot(const MachineInstr *MI, int &FrameIndex) const;
David Greene2f4c3742009-11-13 00:29:53 +0000182 /// isStoreToStackSlotPostFE - Check for post-frame ptr elimination
183 /// stack locations as well. This uses a heuristic so it isn't
184 /// reliable for correctness.
185 unsigned isStoreToStackSlotPostFE(const MachineInstr *MI,
186 int &FrameIndex) const;
Evan Chenged6e34f2008-03-31 20:40:39 +0000187
Dan Gohmane919de52009-10-10 00:34:18 +0000188 bool isReallyTriviallyReMaterializable(const MachineInstr *MI,
189 AliasAnalysis *AA) const;
Evan Chenged6e34f2008-03-31 20:40:39 +0000190 void reMaterialize(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
Evan Cheng84517442009-07-16 09:20:10 +0000191 unsigned DestReg, unsigned SubIdx,
Evan Cheng6ad7da92009-11-14 02:55:43 +0000192 const MachineInstr *Orig,
Jakob Stoklund Olesena8ad9772010-06-02 22:47:25 +0000193 const TargetRegisterInfo &TRI) const;
Evan Chenged6e34f2008-03-31 20:40:39 +0000194
Tim Northover6833e3f2013-06-10 20:43:49 +0000195 /// Given an operand within a MachineInstr, insert preceding code to put it
196 /// into the right format for a particular kind of LEA instruction. This may
197 /// involve using an appropriate super-register instead (with an implicit use
198 /// of the original) or creating a new virtual register and inserting COPY
199 /// instructions to get the data into the right class.
200 ///
201 /// Reference parameters are set to indicate how caller should add this
202 /// operand to the LEA instruction.
203 bool classifyLEAReg(MachineInstr *MI, const MachineOperand &Src,
204 unsigned LEAOpcode, bool AllowSP,
205 unsigned &NewSrc, bool &isKill,
206 bool &isUndef, MachineOperand &ImplicitOp) const;
207
Chris Lattnerb7782d72005-01-02 02:37:07 +0000208 /// convertToThreeAddress - This method must be implemented by targets that
209 /// set the M_CONVERTIBLE_TO_3_ADDR flag. When this flag is set, the target
210 /// may be able to convert a two-address instruction into a true
211 /// three-address instruction on demand. This allows the X86 target (for
212 /// example) to convert ADD and SHL instructions into LEA instructions if they
213 /// would require register copies due to two-addressness.
214 ///
215 /// This method returns a null pointer if the transformation cannot be
216 /// performed, otherwise it returns the new instruction.
217 ///
Evan Cheng67fc1412006-12-01 21:52:58 +0000218 virtual MachineInstr *convertToThreeAddress(MachineFunction::iterator &MFI,
219 MachineBasicBlock::iterator &MBBI,
Owen Anderson30cc0282008-07-02 23:41:07 +0000220 LiveVariables *LV) const;
Chris Lattnerb7782d72005-01-02 02:37:07 +0000221
Chris Lattner29478012005-01-19 07:11:01 +0000222 /// commuteInstruction - We have a few instructions that must be hacked on to
223 /// commute them.
224 ///
Evan Cheng03553bb2008-06-16 07:33:11 +0000225 virtual MachineInstr *commuteInstruction(MachineInstr *MI, bool NewMI) const;
Chris Lattner29478012005-01-19 07:11:01 +0000226
Chris Lattnerc0fb5672006-10-20 17:42:20 +0000227 // Branch analysis.
Dale Johannesen616627b2007-06-14 22:03:45 +0000228 virtual bool isUnpredicatedTerminator(const MachineInstr* MI) const;
Chris Lattnerc0fb5672006-10-20 17:42:20 +0000229 virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
230 MachineBasicBlock *&FBB,
Evan Cheng64dfcac2009-02-09 07:14:22 +0000231 SmallVectorImpl<MachineOperand> &Cond,
232 bool AllowModify) const;
Evan Chenge20dd922007-05-18 00:18:17 +0000233 virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
234 virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
235 MachineBasicBlock *FBB,
Stuart Hastings0125b642010-06-17 22:43:56 +0000236 const SmallVectorImpl<MachineOperand> &Cond,
237 DebugLoc DL) const;
Jakob Stoklund Olesen49e4d4b2012-07-04 00:09:58 +0000238 virtual bool canInsertSelect(const MachineBasicBlock&,
239 const SmallVectorImpl<MachineOperand> &Cond,
240 unsigned, unsigned, int&, int&, int&) const;
241 virtual void insertSelect(MachineBasicBlock &MBB,
242 MachineBasicBlock::iterator MI, DebugLoc DL,
243 unsigned DstReg,
244 const SmallVectorImpl<MachineOperand> &Cond,
245 unsigned TrueReg, unsigned FalseReg) const;
Jakob Stoklund Olesen930f8082010-07-08 19:46:25 +0000246 virtual void copyPhysReg(MachineBasicBlock &MBB,
247 MachineBasicBlock::iterator MI, DebugLoc DL,
248 unsigned DestReg, unsigned SrcReg,
249 bool KillSrc) const;
Owen Andersoneee14602008-01-01 21:11:32 +0000250 virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
251 MachineBasicBlock::iterator MI,
252 unsigned SrcReg, bool isKill, int FrameIndex,
Evan Chengefb126a2010-05-06 19:06:44 +0000253 const TargetRegisterClass *RC,
254 const TargetRegisterInfo *TRI) const;
Owen Andersoneee14602008-01-01 21:11:32 +0000255
256 virtual void storeRegToAddr(MachineFunction &MF, unsigned SrcReg, bool isKill,
257 SmallVectorImpl<MachineOperand> &Addr,
258 const TargetRegisterClass *RC,
Dan Gohmandd76bb22009-10-09 18:10:05 +0000259 MachineInstr::mmo_iterator MMOBegin,
260 MachineInstr::mmo_iterator MMOEnd,
Owen Andersoneee14602008-01-01 21:11:32 +0000261 SmallVectorImpl<MachineInstr*> &NewMIs) const;
262
263 virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
264 MachineBasicBlock::iterator MI,
265 unsigned DestReg, int FrameIndex,
Evan Chengefb126a2010-05-06 19:06:44 +0000266 const TargetRegisterClass *RC,
267 const TargetRegisterInfo *TRI) const;
Owen Andersoneee14602008-01-01 21:11:32 +0000268
269 virtual void loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
270 SmallVectorImpl<MachineOperand> &Addr,
271 const TargetRegisterClass *RC,
Dan Gohmandd76bb22009-10-09 18:10:05 +0000272 MachineInstr::mmo_iterator MMOBegin,
273 MachineInstr::mmo_iterator MMOEnd,
Owen Andersoneee14602008-01-01 21:11:32 +0000274 SmallVectorImpl<MachineInstr*> &NewMIs) const;
Jakob Stoklund Olesendd1904e2011-09-29 05:10:54 +0000275
276 virtual bool expandPostRAPseudo(MachineBasicBlock::iterator MI) const;
277
Evan Chenged69b382010-04-26 07:38:55 +0000278 virtual
279 MachineInstr *emitFrameIndexDebugValue(MachineFunction &MF,
Evan Cheng250e9172010-04-29 01:13:30 +0000280 int FrameIx, uint64_t Offset,
Evan Chenged69b382010-04-26 07:38:55 +0000281 const MDNode *MDPtr,
282 DebugLoc DL) const;
283
Owen Anderson2a3be7b2008-01-07 01:35:02 +0000284 /// foldMemoryOperand - If this target supports it, fold a load or store of
285 /// the specified stack slot into the specified machine instruction for the
286 /// specified operand(s). If this is possible, the target should perform the
287 /// folding and return true, otherwise it should return false. If it folds
288 /// the instruction, it is likely that the MachineInstruction the iterator
289 /// references has been changed.
Dan Gohman3f86b512008-12-03 18:43:12 +0000290 virtual MachineInstr* foldMemoryOperandImpl(MachineFunction &MF,
291 MachineInstr* MI,
292 const SmallVectorImpl<unsigned> &Ops,
293 int FrameIndex) const;
Owen Anderson2a3be7b2008-01-07 01:35:02 +0000294
295 /// foldMemoryOperand - Same as the previous version except it allows folding
296 /// of any load and store from / to any address, not just from a specific
297 /// stack slot.
Dan Gohman3f86b512008-12-03 18:43:12 +0000298 virtual MachineInstr* foldMemoryOperandImpl(MachineFunction &MF,
299 MachineInstr* MI,
300 const SmallVectorImpl<unsigned> &Ops,
301 MachineInstr* LoadMI) const;
Owen Anderson2a3be7b2008-01-07 01:35:02 +0000302
303 /// canFoldMemoryOperand - Returns true if the specified load / store is
304 /// folding is possible.
Dan Gohman33332bc2008-10-16 01:49:15 +0000305 virtual bool canFoldMemoryOperand(const MachineInstr*,
306 const SmallVectorImpl<unsigned> &) const;
Owen Anderson2a3be7b2008-01-07 01:35:02 +0000307
308 /// unfoldMemoryOperand - Separate a single instruction which folded a load or
309 /// a store or a load and a store into two or more instruction. If this is
310 /// possible, returns true as well as the new instructions by reference.
311 virtual bool unfoldMemoryOperand(MachineFunction &MF, MachineInstr *MI,
312 unsigned Reg, bool UnfoldLoad, bool UnfoldStore,
313 SmallVectorImpl<MachineInstr*> &NewMIs) const;
314
315 virtual bool unfoldMemoryOperand(SelectionDAG &DAG, SDNode *N,
316 SmallVectorImpl<SDNode*> &NewNodes) const;
317
318 /// getOpcodeAfterMemoryUnfold - Returns the opcode of the would be new
319 /// instruction after load / store are unfolded from an instruction of the
320 /// specified opcode. It returns zero if the specified unfolding is not
Dan Gohman49fa51d2009-10-30 22:18:41 +0000321 /// possible. If LoadRegIndex is non-null, it is filled in with the operand
322 /// index of the operand which will hold the register holding the loaded
323 /// value.
Owen Anderson2a3be7b2008-01-07 01:35:02 +0000324 virtual unsigned getOpcodeAfterMemoryUnfold(unsigned Opc,
Dan Gohman49fa51d2009-10-30 22:18:41 +0000325 bool UnfoldLoad, bool UnfoldStore,
326 unsigned *LoadRegIndex = 0) const;
Andrew Trick27c079e2011-03-05 06:31:54 +0000327
Evan Cheng4f026f32010-01-22 03:34:51 +0000328 /// areLoadsFromSameBasePtr - This is used by the pre-regalloc scheduler
329 /// to determine if two loads are loading from the same base address. It
330 /// should only return true if the base pointers are the same and the
331 /// only differences between the two addresses are the offset. It also returns
332 /// the offsets by reference.
333 virtual bool areLoadsFromSameBasePtr(SDNode *Load1, SDNode *Load2,
334 int64_t &Offset1, int64_t &Offset2) const;
335
336 /// shouldScheduleLoadsNear - This is a used by the pre-regalloc scheduler to
Chris Lattner0ab5e2c2011-04-15 05:18:47 +0000337 /// determine (in conjunction with areLoadsFromSameBasePtr) if two loads should
Evan Cheng4f026f32010-01-22 03:34:51 +0000338 /// be scheduled togther. On some targets if two loads are loading from
339 /// addresses in the same cache line, it's better if they are scheduled
340 /// together. This function takes two integers that represent the load offsets
341 /// from the common base address. It returns true if it decides it's desirable
342 /// to schedule the two loads together. "NumLoads" is the number of loads that
343 /// have already been scheduled after Load1.
344 virtual bool shouldScheduleLoadsNear(SDNode *Load1, SDNode *Load2,
345 int64_t Offset1, int64_t Offset2,
346 unsigned NumLoads) const;
347
Chris Lattner6a5e7062010-04-26 23:37:21 +0000348 virtual void getNoopForMachoTarget(MCInst &NopInst) const;
349
Owen Anderson4f6bf042008-08-14 22:49:33 +0000350 virtual
351 bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
Chris Lattner29478012005-01-19 07:11:01 +0000352
Evan Chengb5f0ec32009-02-06 17:17:30 +0000353 /// isSafeToMoveRegClassDefs - Return true if it's safe to move a machine
354 /// instruction that defines the specified register class.
355 bool isSafeToMoveRegClassDefs(const TargetRegisterClass *RC) const;
Evan Chengf7137222008-10-27 07:14:50 +0000356
Chris Lattner58827ff2010-02-05 22:10:22 +0000357 static bool isX86_64ExtendedReg(const MachineOperand &MO) {
358 if (!MO.isReg()) return false;
Evan Cheng7e763d82011-07-25 18:43:53 +0000359 return X86II::isX86_64ExtendedReg(MO.getReg());
Chris Lattner58827ff2010-02-05 22:10:22 +0000360 }
Nicolas Geoffrayae84bbd2008-04-16 20:10:13 +0000361
Dan Gohman6ebe7342008-09-30 00:58:23 +0000362 /// getGlobalBaseReg - Return a virtual register initialized with the
363 /// the global base register value. Output instructions required to
364 /// initialize the register in the function entry block, if necessary.
Dan Gohman24300732008-09-23 18:22:58 +0000365 ///
Dan Gohman6ebe7342008-09-30 00:58:23 +0000366 unsigned getGlobalBaseReg(MachineFunction *MF) const;
Dan Gohman24300732008-09-23 18:22:58 +0000367
Jakob Stoklund Olesenb48c9942011-09-27 22:57:18 +0000368 std::pair<uint16_t, uint16_t>
369 getExecutionDomain(const MachineInstr *MI) const;
Jakob Stoklund Olesenb551aa42010-03-29 23:24:21 +0000370
Jakob Stoklund Olesenb48c9942011-09-27 22:57:18 +0000371 void setExecutionDomain(MachineInstr *MI, unsigned Domain) const;
Jakob Stoklund Olesen49e121d2010-03-25 17:25:00 +0000372
Jakob Stoklund Olesenf8ad3362011-11-15 01:15:30 +0000373 unsigned getPartialRegUpdateClearance(const MachineInstr *MI, unsigned OpNum,
374 const TargetRegisterInfo *TRI) const;
375 void breakPartialRegDependency(MachineBasicBlock::iterator MI, unsigned OpNum,
376 const TargetRegisterInfo *TRI) const;
377
Chris Lattnereeba0c72010-09-05 02:18:34 +0000378 MachineInstr* foldMemoryOperandImpl(MachineFunction &MF,
379 MachineInstr* MI,
380 unsigned OpNum,
381 const SmallVectorImpl<MachineOperand> &MOs,
382 unsigned Size, unsigned Alignment) const;
Evan Cheng63c76082010-10-19 18:58:51 +0000383
Andrew Trick641e2d42011-03-05 08:00:22 +0000384 bool isHighLatencyDef(int opc) const;
385
Evan Cheng63c76082010-10-19 18:58:51 +0000386 bool hasHighOperandLatency(const InstrItineraryData *ItinData,
387 const MachineRegisterInfo *MRI,
388 const MachineInstr *DefMI, unsigned DefIdx,
389 const MachineInstr *UseMI, unsigned UseIdx) const;
Andrew Trick27c079e2011-03-05 06:31:54 +0000390
Manman Renc9656732012-07-06 17:36:20 +0000391 /// analyzeCompare - For a comparison instruction, return the source registers
392 /// in SrcReg and SrcReg2 if having two register operands, and the value it
393 /// compares against in CmpValue. Return true if the comparison instruction
394 /// can be analyzed.
395 virtual bool analyzeCompare(const MachineInstr *MI, unsigned &SrcReg,
396 unsigned &SrcReg2,
397 int &CmpMask, int &CmpValue) const;
398
399 /// optimizeCompareInstr - Check if there exists an earlier instruction that
400 /// operates on the same source operands and sets flags in the same way as
401 /// Compare; remove Compare if possible.
402 virtual bool optimizeCompareInstr(MachineInstr *CmpInstr, unsigned SrcReg,
403 unsigned SrcReg2, int CmpMask, int CmpValue,
404 const MachineRegisterInfo *MRI) const;
405
Manman Ren5759d012012-08-02 00:56:42 +0000406 /// optimizeLoadInstr - Try to remove the load by folding it to a register
407 /// operand at the use. We fold the load instructions if and only if the
Manman Renba8122c2012-08-02 19:37:32 +0000408 /// def and use are in the same BB. We only look at one load and see
409 /// whether it can be folded into MI. FoldAsLoadDefReg is the virtual register
410 /// defined by the load we are trying to fold. DefMI returns the machine
411 /// instruction that defines FoldAsLoadDefReg, and the function returns
412 /// the machine instruction generated due to folding.
Manman Ren5759d012012-08-02 00:56:42 +0000413 virtual MachineInstr* optimizeLoadInstr(MachineInstr *MI,
414 const MachineRegisterInfo *MRI,
415 unsigned &FoldAsLoadDefReg,
416 MachineInstr *&DefMI) const;
417
Owen Anderson2a3be7b2008-01-07 01:35:02 +0000418private:
Evan Cheng766a73f2009-12-11 06:01:48 +0000419 MachineInstr * convertToThreeAddressWithLEA(unsigned MIOpc,
420 MachineFunction::iterator &MFI,
421 MachineBasicBlock::iterator &MBBI,
422 LiveVariables *LV) const;
423
David Greene70fdd572009-11-12 20:55:29 +0000424 /// isFrameOperand - Return true and the FrameIndex if the specified
425 /// operand and follow operands form a reference to the stack frame.
426 bool isFrameOperand(const MachineInstr *MI, unsigned int Op,
427 int &FrameIndex) const;
Chris Lattnerd92fb002002-10-25 22:55:53 +0000428};
429
Brian Gaeke960707c2003-11-11 22:41:34 +0000430} // End llvm namespace
431
Chris Lattnerd92fb002002-10-25 22:55:53 +0000432#endif