blob: 5b1d5a62ffbb07dfe8a5e5b2a2abcd9c617c7773 [file] [log] [blame]
Chris Lattner64105522008-01-01 01:03:04 +00001//===-- TargetInstrInfoImpl.cpp - Target Instruction Information ----------===//
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 file implements the TargetInstrInfoImpl class, it just provides default
11// implementations of various methods.
12//
13//===----------------------------------------------------------------------===//
14
15#include "llvm/Target/TargetInstrInfo.h"
Evan Cheng86050dc2010-06-18 23:09:54 +000016#include "llvm/Target/TargetLowering.h"
Dan Gohmana70dca12009-10-09 23:27:56 +000017#include "llvm/Target/TargetMachine.h"
18#include "llvm/Target/TargetRegisterInfo.h"
Owen Anderson44eb65c2008-08-14 22:49:33 +000019#include "llvm/ADT/SmallVector.h"
Dan Gohmanc54baa22008-12-03 18:43:12 +000020#include "llvm/CodeGen/MachineFrameInfo.h"
Chris Lattner64105522008-01-01 01:03:04 +000021#include "llvm/CodeGen/MachineInstr.h"
Evan Cheng58dcb0e2008-06-16 07:33:11 +000022#include "llvm/CodeGen/MachineInstrBuilder.h"
Dan Gohmanc76909a2009-09-25 20:36:54 +000023#include "llvm/CodeGen/MachineMemOperand.h"
Dan Gohmana70dca12009-10-09 23:27:56 +000024#include "llvm/CodeGen/MachineRegisterInfo.h"
Evan Cheng774bc882010-06-14 21:06:53 +000025#include "llvm/CodeGen/PostRAHazardRecognizer.h"
Dan Gohmanc54baa22008-12-03 18:43:12 +000026#include "llvm/CodeGen/PseudoSourceValue.h"
Evan Cheng34c75092009-07-10 23:26:12 +000027#include "llvm/Support/ErrorHandling.h"
28#include "llvm/Support/raw_ostream.h"
Chris Lattner64105522008-01-01 01:03:04 +000029using namespace llvm;
30
Evan Cheng4d54e5b2010-06-22 01:18:16 +000031/// ReplaceTailWithBranchTo - Delete the instruction OldInst and everything
32/// after it, replacing it with an unconditional branch to NewDest.
Evan Cheng86050dc2010-06-18 23:09:54 +000033void
34TargetInstrInfoImpl::ReplaceTailWithBranchTo(MachineBasicBlock::iterator Tail,
35 MachineBasicBlock *NewDest) const {
36 MachineBasicBlock *MBB = Tail->getParent();
37
38 // Remove all the old successors of MBB from the CFG.
39 while (!MBB->succ_empty())
40 MBB->removeSuccessor(MBB->succ_begin());
41
42 // Remove all the dead instructions from the end of MBB.
43 MBB->erase(Tail, MBB->end());
44
45 // If MBB isn't immediately before MBB, insert a branch to it.
46 if (++MachineFunction::iterator(MBB) != MachineFunction::iterator(NewDest))
47 InsertBranch(*MBB, NewDest, 0, SmallVector<MachineOperand, 0>(),
48 Tail->getDebugLoc());
49 MBB->addSuccessor(NewDest);
50}
51
Chris Lattner64105522008-01-01 01:03:04 +000052// commuteInstruction - The default implementation of this method just exchanges
Evan Cheng34c75092009-07-10 23:26:12 +000053// the two operands returned by findCommutedOpIndices.
Evan Cheng58dcb0e2008-06-16 07:33:11 +000054MachineInstr *TargetInstrInfoImpl::commuteInstruction(MachineInstr *MI,
55 bool NewMI) const {
Evan Cheng498c2902009-07-01 08:29:08 +000056 const TargetInstrDesc &TID = MI->getDesc();
57 bool HasDef = TID.getNumDefs();
Evan Cheng34c75092009-07-10 23:26:12 +000058 if (HasDef && !MI->getOperand(0).isReg())
59 // No idea how to commute this instruction. Target should implement its own.
60 return 0;
61 unsigned Idx1, Idx2;
62 if (!findCommutedOpIndices(MI, Idx1, Idx2)) {
63 std::string msg;
64 raw_string_ostream Msg(msg);
65 Msg << "Don't know how to commute: " << *MI;
Chris Lattner75361b62010-04-07 22:58:41 +000066 report_fatal_error(Msg.str());
Evan Cheng34c75092009-07-10 23:26:12 +000067 }
Evan Cheng498c2902009-07-01 08:29:08 +000068
69 assert(MI->getOperand(Idx1).isReg() && MI->getOperand(Idx2).isReg() &&
Chris Lattner64105522008-01-01 01:03:04 +000070 "This only knows how to commute register operands so far");
Evan Cheng498c2902009-07-01 08:29:08 +000071 unsigned Reg1 = MI->getOperand(Idx1).getReg();
72 unsigned Reg2 = MI->getOperand(Idx2).getReg();
73 bool Reg1IsKill = MI->getOperand(Idx1).isKill();
74 bool Reg2IsKill = MI->getOperand(Idx2).isKill();
Evan Cheng58dcb0e2008-06-16 07:33:11 +000075 bool ChangeReg0 = false;
Evan Cheng498c2902009-07-01 08:29:08 +000076 if (HasDef && MI->getOperand(0).getReg() == Reg1) {
Evan Chenga4d16a12008-02-13 02:46:49 +000077 // Must be two address instruction!
78 assert(MI->getDesc().getOperandConstraint(0, TOI::TIED_TO) &&
79 "Expecting a two-address instruction!");
80 Reg2IsKill = false;
Evan Cheng58dcb0e2008-06-16 07:33:11 +000081 ChangeReg0 = true;
Evan Chenga4d16a12008-02-13 02:46:49 +000082 }
Evan Cheng58dcb0e2008-06-16 07:33:11 +000083
84 if (NewMI) {
85 // Create a new instruction.
Evan Cheng498c2902009-07-01 08:29:08 +000086 unsigned Reg0 = HasDef
87 ? (ChangeReg0 ? Reg2 : MI->getOperand(0).getReg()) : 0;
88 bool Reg0IsDead = HasDef ? MI->getOperand(0).isDead() : false;
Dan Gohman8e5f2c62008-07-07 23:14:23 +000089 MachineFunction &MF = *MI->getParent()->getParent();
Evan Cheng498c2902009-07-01 08:29:08 +000090 if (HasDef)
91 return BuildMI(MF, MI->getDebugLoc(), MI->getDesc())
92 .addReg(Reg0, RegState::Define | getDeadRegState(Reg0IsDead))
93 .addReg(Reg2, getKillRegState(Reg2IsKill))
94 .addReg(Reg1, getKillRegState(Reg2IsKill));
95 else
96 return BuildMI(MF, MI->getDebugLoc(), MI->getDesc())
97 .addReg(Reg2, getKillRegState(Reg2IsKill))
98 .addReg(Reg1, getKillRegState(Reg2IsKill));
Evan Cheng58dcb0e2008-06-16 07:33:11 +000099 }
100
101 if (ChangeReg0)
102 MI->getOperand(0).setReg(Reg2);
Evan Cheng498c2902009-07-01 08:29:08 +0000103 MI->getOperand(Idx2).setReg(Reg1);
104 MI->getOperand(Idx1).setReg(Reg2);
105 MI->getOperand(Idx2).setIsKill(Reg1IsKill);
106 MI->getOperand(Idx1).setIsKill(Reg2IsKill);
Chris Lattner64105522008-01-01 01:03:04 +0000107 return MI;
108}
109
Evan Cheng261ce1d2009-07-10 19:15:51 +0000110/// findCommutedOpIndices - If specified MI is commutable, return the two
111/// operand indices that would swap value. Return true if the instruction
112/// is not in a form which this routine understands.
113bool TargetInstrInfoImpl::findCommutedOpIndices(MachineInstr *MI,
114 unsigned &SrcOpIdx1,
115 unsigned &SrcOpIdx2) const {
Evan Cheng498c2902009-07-01 08:29:08 +0000116 const TargetInstrDesc &TID = MI->getDesc();
Evan Cheng261ce1d2009-07-10 19:15:51 +0000117 if (!TID.isCommutable())
Evan Cheng498c2902009-07-01 08:29:08 +0000118 return false;
Evan Cheng261ce1d2009-07-10 19:15:51 +0000119 // This assumes v0 = op v1, v2 and commuting would swap v1 and v2. If this
120 // is not true, then the target must implement this.
121 SrcOpIdx1 = TID.getNumDefs();
122 SrcOpIdx2 = SrcOpIdx1 + 1;
123 if (!MI->getOperand(SrcOpIdx1).isReg() ||
124 !MI->getOperand(SrcOpIdx2).isReg())
125 // No idea.
126 return false;
127 return true;
Evan Chengf20db152008-02-15 18:21:33 +0000128}
129
130
Chris Lattner64105522008-01-01 01:03:04 +0000131bool TargetInstrInfoImpl::PredicateInstruction(MachineInstr *MI,
Owen Anderson44eb65c2008-08-14 22:49:33 +0000132 const SmallVectorImpl<MachineOperand> &Pred) const {
Chris Lattner64105522008-01-01 01:03:04 +0000133 bool MadeChange = false;
Chris Lattner749c6f62008-01-07 07:27:27 +0000134 const TargetInstrDesc &TID = MI->getDesc();
135 if (!TID.isPredicable())
136 return false;
137
138 for (unsigned j = 0, i = 0, e = MI->getNumOperands(); i != e; ++i) {
139 if (TID.OpInfo[i].isPredicate()) {
140 MachineOperand &MO = MI->getOperand(i);
Dan Gohmand735b802008-10-03 15:45:36 +0000141 if (MO.isReg()) {
Chris Lattner749c6f62008-01-07 07:27:27 +0000142 MO.setReg(Pred[j].getReg());
143 MadeChange = true;
Dan Gohmand735b802008-10-03 15:45:36 +0000144 } else if (MO.isImm()) {
Chris Lattner749c6f62008-01-07 07:27:27 +0000145 MO.setImm(Pred[j].getImm());
146 MadeChange = true;
Dan Gohmand735b802008-10-03 15:45:36 +0000147 } else if (MO.isMBB()) {
Chris Lattner749c6f62008-01-07 07:27:27 +0000148 MO.setMBB(Pred[j].getMBB());
149 MadeChange = true;
Chris Lattner64105522008-01-01 01:03:04 +0000150 }
Chris Lattner749c6f62008-01-07 07:27:27 +0000151 ++j;
Chris Lattner64105522008-01-01 01:03:04 +0000152 }
153 }
154 return MadeChange;
155}
Evan Chengca1267c2008-03-31 20:40:39 +0000156
157void TargetInstrInfoImpl::reMaterialize(MachineBasicBlock &MBB,
158 MachineBasicBlock::iterator I,
159 unsigned DestReg,
Evan Cheng37844532009-07-16 09:20:10 +0000160 unsigned SubIdx,
Evan Chengd57cdd52009-11-14 02:55:43 +0000161 const MachineInstr *Orig,
Jakob Stoklund Olesen9edf7de2010-06-02 22:47:25 +0000162 const TargetRegisterInfo &TRI) const {
Dan Gohman8e5f2c62008-07-07 23:14:23 +0000163 MachineInstr *MI = MBB.getParent()->CloneMachineInstr(Orig);
Jakob Stoklund Olesen9edf7de2010-06-02 22:47:25 +0000164 MI->substituteRegister(MI->getOperand(0).getReg(), DestReg, SubIdx, TRI);
Evan Chengca1267c2008-03-31 20:40:39 +0000165 MBB.insert(I, MI);
166}
167
Evan Cheng506049f2010-03-03 01:44:33 +0000168bool TargetInstrInfoImpl::produceSameValue(const MachineInstr *MI0,
169 const MachineInstr *MI1) const {
170 return MI0->isIdenticalTo(MI1, MachineInstr::IgnoreVRegDefs);
171}
172
Jakob Stoklund Olesen30ac0462010-01-06 23:47:07 +0000173MachineInstr *TargetInstrInfoImpl::duplicate(MachineInstr *Orig,
174 MachineFunction &MF) const {
175 assert(!Orig->getDesc().isNotDuplicable() &&
176 "Instruction cannot be duplicated");
177 return MF.CloneMachineInstr(Orig);
178}
179
Nicolas Geoffray52e724a2008-04-16 20:10:13 +0000180unsigned
181TargetInstrInfoImpl::GetFunctionSizeInBytes(const MachineFunction &MF) const {
182 unsigned FnSize = 0;
183 for (MachineFunction::const_iterator MBBI = MF.begin(), E = MF.end();
184 MBBI != E; ++MBBI) {
185 const MachineBasicBlock &MBB = *MBBI;
Evan Cheng38855782008-09-11 05:58:06 +0000186 for (MachineBasicBlock::const_iterator I = MBB.begin(),E = MBB.end();
187 I != E; ++I)
Nicolas Geoffray52e724a2008-04-16 20:10:13 +0000188 FnSize += GetInstSizeInBytes(I);
189 }
190 return FnSize;
191}
Dan Gohmanc54baa22008-12-03 18:43:12 +0000192
Jakob Stoklund Olesen1f323402010-07-09 20:43:13 +0000193// If the COPY instruction in MI can be folded to a stack operation, return
194// the register class to use.
195static const TargetRegisterClass *canFoldCopy(const MachineInstr *MI,
196 unsigned FoldIdx) {
197 assert(MI->isCopy() && "MI must be a COPY instruction");
198 if (MI->getNumOperands() != 2)
199 return 0;
200 assert(FoldIdx<2 && "FoldIdx refers no nonexistent operand");
201
202 const MachineOperand &FoldOp = MI->getOperand(FoldIdx);
203 const MachineOperand &LiveOp = MI->getOperand(1-FoldIdx);
204
205 if (FoldOp.getSubReg() || LiveOp.getSubReg())
206 return 0;
207
208 unsigned FoldReg = FoldOp.getReg();
209 unsigned LiveReg = LiveOp.getReg();
210
211 assert(TargetRegisterInfo::isVirtualRegister(FoldReg) &&
212 "Cannot fold physregs");
213
214 const MachineRegisterInfo &MRI = MI->getParent()->getParent()->getRegInfo();
215 const TargetRegisterClass *RC = MRI.getRegClass(FoldReg);
216
217 if (TargetRegisterInfo::isPhysicalRegister(LiveOp.getReg()))
218 return RC->contains(LiveOp.getReg()) ? RC : 0;
219
220 const TargetRegisterClass *LiveRC = MRI.getRegClass(LiveReg);
221 if (RC == LiveRC || RC->hasSubClass(LiveRC))
222 return RC;
223
224 // FIXME: Allow folding when register classes are memory compatible.
225 return 0;
226}
227
228bool TargetInstrInfoImpl::
229canFoldMemoryOperand(const MachineInstr *MI,
230 const SmallVectorImpl<unsigned> &Ops) const {
231 return MI->isCopy() && Ops.size() == 1 && canFoldCopy(MI, Ops[0]);
232}
233
Dan Gohmanc54baa22008-12-03 18:43:12 +0000234/// foldMemoryOperand - Attempt to fold a load or store of the specified stack
235/// slot into the specified machine instruction for the specified operand(s).
236/// If this is possible, a new instruction is returned with the specified
237/// operand folded, otherwise NULL is returned. The client is responsible for
238/// removing the old instruction and adding the new one in the instruction
239/// stream.
240MachineInstr*
Jakob Stoklund Olesene05442d2010-07-09 17:29:08 +0000241TargetInstrInfo::foldMemoryOperand(MachineBasicBlock::iterator MI,
Dan Gohmanc54baa22008-12-03 18:43:12 +0000242 const SmallVectorImpl<unsigned> &Ops,
Jakob Stoklund Olesen1f323402010-07-09 20:43:13 +0000243 int FI) const {
Dan Gohmanc54baa22008-12-03 18:43:12 +0000244 unsigned Flags = 0;
245 for (unsigned i = 0, e = Ops.size(); i != e; ++i)
246 if (MI->getOperand(Ops[i]).isDef())
247 Flags |= MachineMemOperand::MOStore;
248 else
249 Flags |= MachineMemOperand::MOLoad;
250
Jakob Stoklund Olesen1f323402010-07-09 20:43:13 +0000251 MachineBasicBlock *MBB = MI->getParent();
252 assert(MBB && "foldMemoryOperand needs an inserted instruction");
253 MachineFunction &MF = *MBB->getParent();
Jakob Stoklund Olesene05442d2010-07-09 17:29:08 +0000254
Dan Gohmanc54baa22008-12-03 18:43:12 +0000255 // Ask the target to do the actual folding.
Jakob Stoklund Olesen1f323402010-07-09 20:43:13 +0000256 MachineInstr *NewMI = foldMemoryOperandImpl(MF, MI, Ops, FI);
257
258 // Straight COPY may fold as load/store.
259 if (!NewMI) {
260 if (!MI->isCopy() || Ops.size() != 1)
261 return 0;
262
263 const TargetRegisterClass *RC = canFoldCopy(MI, Ops[0]);
264 if (!RC)
265 return 0;
266
267 const MachineOperand &MO = MI->getOperand(1-Ops[0]);
268 MachineBasicBlock::iterator Pos = MI;
269 const TargetRegisterInfo *TRI = MF.getTarget().getRegisterInfo();
270
271 if (Flags == MachineMemOperand::MOStore)
272 storeRegToStackSlot(*MBB, Pos, MO.getReg(), MO.isKill(), FI, RC, TRI);
273 else
274 loadRegFromStackSlot(*MBB, Pos, MO.getReg(), FI, RC, TRI);
275
276 NewMI = --Pos;
277 } else {
278 // FIXME: change foldMemoryOperandImpl semantics to also insert NewMI.
279 NewMI = MBB->insert(MI, NewMI);
280 }
281
Dan Gohmanc54baa22008-12-03 18:43:12 +0000282 if (!NewMI) return 0;
283
Jakob Stoklund Olesene05442d2010-07-09 17:29:08 +0000284
Dan Gohmanc54baa22008-12-03 18:43:12 +0000285 assert((!(Flags & MachineMemOperand::MOStore) ||
286 NewMI->getDesc().mayStore()) &&
287 "Folded a def to a non-store!");
288 assert((!(Flags & MachineMemOperand::MOLoad) ||
289 NewMI->getDesc().mayLoad()) &&
290 "Folded a use to a non-load!");
291 const MachineFrameInfo &MFI = *MF.getFrameInfo();
Jakob Stoklund Olesen1f323402010-07-09 20:43:13 +0000292 assert(MFI.getObjectOffset(FI) != -1);
Dan Gohmanc76909a2009-09-25 20:36:54 +0000293 MachineMemOperand *MMO =
Jakob Stoklund Olesen1f323402010-07-09 20:43:13 +0000294 MF.getMachineMemOperand(PseudoSourceValue::getFixedStack(FI),
Dan Gohmanc76909a2009-09-25 20:36:54 +0000295 Flags, /*Offset=*/0,
Jakob Stoklund Olesen1f323402010-07-09 20:43:13 +0000296 MFI.getObjectSize(FI),
297 MFI.getObjectAlignment(FI));
Dan Gohmanc54baa22008-12-03 18:43:12 +0000298 NewMI->addMemOperand(MF, MMO);
299
300 return NewMI;
301}
302
303/// foldMemoryOperand - Same as the previous version except it allows folding
304/// of any load and store from / to any address, not just from a specific
305/// stack slot.
306MachineInstr*
Jakob Stoklund Olesene05442d2010-07-09 17:29:08 +0000307TargetInstrInfo::foldMemoryOperand(MachineBasicBlock::iterator MI,
Dan Gohmanc54baa22008-12-03 18:43:12 +0000308 const SmallVectorImpl<unsigned> &Ops,
309 MachineInstr* LoadMI) const {
310 assert(LoadMI->getDesc().canFoldAsLoad() && "LoadMI isn't foldable!");
311#ifndef NDEBUG
312 for (unsigned i = 0, e = Ops.size(); i != e; ++i)
313 assert(MI->getOperand(Ops[i]).isUse() && "Folding load into def!");
314#endif
Jakob Stoklund Olesene05442d2010-07-09 17:29:08 +0000315 MachineBasicBlock &MBB = *MI->getParent();
316 MachineFunction &MF = *MBB.getParent();
Dan Gohmanc54baa22008-12-03 18:43:12 +0000317
318 // Ask the target to do the actual folding.
319 MachineInstr *NewMI = foldMemoryOperandImpl(MF, MI, Ops, LoadMI);
320 if (!NewMI) return 0;
321
Jakob Stoklund Olesene05442d2010-07-09 17:29:08 +0000322 NewMI = MBB.insert(MI, NewMI);
323
Dan Gohmanc54baa22008-12-03 18:43:12 +0000324 // Copy the memoperands from the load to the folded instruction.
Dan Gohmanc76909a2009-09-25 20:36:54 +0000325 NewMI->setMemRefs(LoadMI->memoperands_begin(),
326 LoadMI->memoperands_end());
Dan Gohmanc54baa22008-12-03 18:43:12 +0000327
328 return NewMI;
329}
Dan Gohmana70dca12009-10-09 23:27:56 +0000330
Evan Cheng44acc242010-06-12 00:11:53 +0000331bool TargetInstrInfo::
332isReallyTriviallyReMaterializableGeneric(const MachineInstr *MI,
333 AliasAnalysis *AA) const {
Dan Gohmana70dca12009-10-09 23:27:56 +0000334 const MachineFunction &MF = *MI->getParent()->getParent();
335 const MachineRegisterInfo &MRI = MF.getRegInfo();
336 const TargetMachine &TM = MF.getTarget();
337 const TargetInstrInfo &TII = *TM.getInstrInfo();
338 const TargetRegisterInfo &TRI = *TM.getRegisterInfo();
339
340 // A load from a fixed stack slot can be rematerialized. This may be
341 // redundant with subsequent checks, but it's target-independent,
342 // simple, and a common case.
343 int FrameIdx = 0;
344 if (TII.isLoadFromStackSlot(MI, FrameIdx) &&
345 MF.getFrameInfo()->isImmutableObjectIndex(FrameIdx))
346 return true;
347
348 const TargetInstrDesc &TID = MI->getDesc();
349
350 // Avoid instructions obviously unsafe for remat.
351 if (TID.hasUnmodeledSideEffects() || TID.isNotDuplicable() ||
352 TID.mayStore())
353 return false;
354
355 // Avoid instructions which load from potentially varying memory.
356 if (TID.mayLoad() && !MI->isInvariantLoad(AA))
357 return false;
358
359 // If any of the registers accessed are non-constant, conservatively assume
360 // the instruction is not rematerializable.
361 for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
362 const MachineOperand &MO = MI->getOperand(i);
363 if (!MO.isReg()) continue;
364 unsigned Reg = MO.getReg();
365 if (Reg == 0)
366 continue;
367
368 // Check for a well-behaved physical register.
369 if (TargetRegisterInfo::isPhysicalRegister(Reg)) {
370 if (MO.isUse()) {
371 // If the physreg has no defs anywhere, it's just an ambient register
372 // and we can freely move its uses. Alternatively, if it's allocatable,
373 // it could get allocated to something with a def during allocation.
374 if (!MRI.def_empty(Reg))
375 return false;
376 BitVector AllocatableRegs = TRI.getAllocatableSet(MF, 0);
377 if (AllocatableRegs.test(Reg))
378 return false;
379 // Check for a def among the register's aliases too.
380 for (const unsigned *Alias = TRI.getAliasSet(Reg); *Alias; ++Alias) {
381 unsigned AliasReg = *Alias;
382 if (!MRI.def_empty(AliasReg))
383 return false;
384 if (AllocatableRegs.test(AliasReg))
385 return false;
386 }
387 } else {
388 // A physreg def. We can't remat it.
389 return false;
390 }
391 continue;
392 }
393
394 // Only allow one virtual-register def, and that in the first operand.
395 if (MO.isDef() != (i == 0))
396 return false;
397
398 // For the def, it should be the only def of that register.
Chris Lattner7896c9f2009-12-03 00:50:42 +0000399 if (MO.isDef() && (llvm::next(MRI.def_begin(Reg)) != MRI.def_end() ||
Dan Gohmana70dca12009-10-09 23:27:56 +0000400 MRI.isLiveIn(Reg)))
401 return false;
402
403 // Don't allow any virtual-register uses. Rematting an instruction with
404 // virtual register uses would length the live ranges of the uses, which
405 // is not necessarily a good idea, certainly not "trivial".
406 if (MO.isUse())
407 return false;
408 }
409
410 // Everything checked out.
411 return true;
412}
Evan Cheng774bc882010-06-14 21:06:53 +0000413
Evan Cheng86050dc2010-06-18 23:09:54 +0000414/// isSchedulingBoundary - Test if the given instruction should be
415/// considered a scheduling boundary. This primarily includes labels
416/// and terminators.
417bool TargetInstrInfoImpl::isSchedulingBoundary(const MachineInstr *MI,
418 const MachineBasicBlock *MBB,
419 const MachineFunction &MF) const{
420 // Terminators and labels can't be scheduled around.
421 if (MI->getDesc().isTerminator() || MI->isLabel())
422 return true;
423
424 // Don't attempt to schedule around any instruction that defines
425 // a stack-oriented pointer, as it's unlikely to be profitable. This
426 // saves compile time, because it doesn't require every single
427 // stack slot reference to depend on the instruction that does the
428 // modification.
429 const TargetLowering &TLI = *MF.getTarget().getTargetLowering();
430 if (MI->definesRegister(TLI.getStackPointerRegisterToSaveRestore()))
431 return true;
432
433 return false;
434}
435
Evan Cheng774bc882010-06-14 21:06:53 +0000436// Default implementation of CreateTargetPostRAHazardRecognizer.
437ScheduleHazardRecognizer *TargetInstrInfoImpl::
438CreateTargetPostRAHazardRecognizer(const InstrItineraryData &II) const {
439 return (ScheduleHazardRecognizer *)new PostRAHazardRecognizer(II);
440}