blob: 170041c9f5b8584beb49fb17f8271f43acbdc18e [file] [log] [blame]
Akira Hatanaka1083eb12013-02-14 23:20:15 +00001//===-- MipsDelaySlotFiller.cpp - Mips Delay Slot Filler ------------------===//
Bruno Cardoso Lopes0b97ce72007-08-18 01:50:47 +00002//
3// 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.
Bruno Cardoso Lopes0b97ce72007-08-18 01:50:47 +00007//
Akira Hatanakae2489122011-04-15 21:51:11 +00008//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes0b97ce72007-08-18 01:50:47 +00009//
Akira Hatanaka1083eb12013-02-14 23:20:15 +000010// Simple pass to fill delay slots with useful instructions.
Bruno Cardoso Lopes0b97ce72007-08-18 01:50:47 +000011//
Akira Hatanakae2489122011-04-15 21:51:11 +000012//===----------------------------------------------------------------------===//
Bruno Cardoso Lopes0b97ce72007-08-18 01:50:47 +000013
Sasa Stankovic5fddf612014-03-10 20:34:23 +000014#include "MCTargetDesc/MipsMCNaCl.h"
Bruno Cardoso Lopes0b97ce72007-08-18 01:50:47 +000015#include "Mips.h"
Akira Hatanaka8f7bfb32013-03-01 02:03:51 +000016#include "MipsInstrInfo.h"
Bruno Cardoso Lopes0b97ce72007-08-18 01:50:47 +000017#include "MipsTargetMachine.h"
Akira Hatanaka06bd1382013-02-14 23:40:57 +000018#include "llvm/ADT/BitVector.h"
Akira Hatanakaeb33ced2013-03-01 00:16:31 +000019#include "llvm/ADT/SmallPtrSet.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000020#include "llvm/ADT/Statistic.h"
Akira Hatanakaeb33ced2013-03-01 00:16:31 +000021#include "llvm/Analysis/AliasAnalysis.h"
22#include "llvm/Analysis/ValueTracking.h"
Akira Hatanaka8f7bfb32013-03-01 02:03:51 +000023#include "llvm/CodeGen/MachineBranchProbabilityInfo.h"
Bruno Cardoso Lopes0b97ce72007-08-18 01:50:47 +000024#include "llvm/CodeGen/MachineFunctionPass.h"
25#include "llvm/CodeGen/MachineInstrBuilder.h"
Daniel Sanders308181e2014-06-12 10:44:10 +000026#include "llvm/CodeGen/MachineRegisterInfo.h"
Akira Hatanakaeb33ced2013-03-01 00:16:31 +000027#include "llvm/CodeGen/PseudoSourceValue.h"
Akira Hatanakaf2619ee2011-09-29 23:52:13 +000028#include "llvm/Support/CommandLine.h"
Bruno Cardoso Lopes0b97ce72007-08-18 01:50:47 +000029#include "llvm/Target/TargetInstrInfo.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000030#include "llvm/Target/TargetMachine.h"
Akira Hatanakaf2619ee2011-09-29 23:52:13 +000031#include "llvm/Target/TargetRegisterInfo.h"
Bruno Cardoso Lopes0b97ce72007-08-18 01:50:47 +000032
33using namespace llvm;
34
Chandler Carruth84e68b22014-04-22 02:41:26 +000035#define DEBUG_TYPE "delay-slot-filler"
36
Bruno Cardoso Lopes0b97ce72007-08-18 01:50:47 +000037STATISTIC(FilledSlots, "Number of delay slots filled");
Akira Hatanaka9e603442011-10-05 01:19:13 +000038STATISTIC(UsefulSlots, "Number of delay slots filled with instructions that"
Akira Hatanaka02e760a2011-10-05 02:22:49 +000039 " are not NOP.");
Bruno Cardoso Lopes0b97ce72007-08-18 01:50:47 +000040
Akira Hatanaka9d957842012-08-22 02:51:28 +000041static cl::opt<bool> DisableDelaySlotFiller(
42 "disable-mips-delay-filler",
Akira Hatanakaf2619ee2011-09-29 23:52:13 +000043 cl::init(false),
Akira Hatanaka1083eb12013-02-14 23:20:15 +000044 cl::desc("Fill all delay slots with NOPs."),
Akira Hatanakaf2619ee2011-09-29 23:52:13 +000045 cl::Hidden);
46
Akira Hatanakae01ff9d2013-03-01 00:50:52 +000047static cl::opt<bool> DisableForwardSearch(
48 "disable-mips-df-forward-search",
49 cl::init(true),
50 cl::desc("Disallow MIPS delay filler to search forward."),
51 cl::Hidden);
52
Akira Hatanakae44e30c2013-03-01 01:02:36 +000053static cl::opt<bool> DisableSuccBBSearch(
54 "disable-mips-df-succbb-search",
55 cl::init(true),
56 cl::desc("Disallow MIPS delay filler to search successor basic blocks."),
57 cl::Hidden);
58
59static cl::opt<bool> DisableBackwardSearch(
60 "disable-mips-df-backward-search",
61 cl::init(false),
62 cl::desc("Disallow MIPS delay filler to search backward."),
63 cl::Hidden);
64
Bruno Cardoso Lopes0b97ce72007-08-18 01:50:47 +000065namespace {
Akira Hatanaka8f7bfb32013-03-01 02:03:51 +000066 typedef MachineBasicBlock::iterator Iter;
67 typedef MachineBasicBlock::reverse_iterator ReverseIter;
68 typedef SmallDenseMap<MachineBasicBlock*, MachineInstr*, 2> BB2BrMap;
69
Akira Hatanaka979899e2013-02-26 01:30:05 +000070 class RegDefsUses {
71 public:
Eric Christopher96e72c62015-01-29 23:27:36 +000072 RegDefsUses(const TargetRegisterInfo &TRI);
Akira Hatanaka979899e2013-02-26 01:30:05 +000073 void init(const MachineInstr &MI);
Akira Hatanakae01ff9d2013-03-01 00:50:52 +000074
75 /// This function sets all caller-saved registers in Defs.
76 void setCallerSaved(const MachineInstr &MI);
77
Akira Hatanaka8f7bfb32013-03-01 02:03:51 +000078 /// This function sets all unallocatable registers in Defs.
79 void setUnallocatableRegs(const MachineFunction &MF);
80
81 /// Set bits in Uses corresponding to MBB's live-out registers except for
82 /// the registers that are live-in to SuccBB.
83 void addLiveOut(const MachineBasicBlock &MBB,
84 const MachineBasicBlock &SuccBB);
85
Akira Hatanaka979899e2013-02-26 01:30:05 +000086 bool update(const MachineInstr &MI, unsigned Begin, unsigned End);
87
88 private:
89 bool checkRegDefsUses(BitVector &NewDefs, BitVector &NewUses, unsigned Reg,
90 bool IsDef) const;
91
92 /// Returns true if Reg or its alias is in RegSet.
93 bool isRegInSet(const BitVector &RegSet, unsigned Reg) const;
94
95 const TargetRegisterInfo &TRI;
96 BitVector Defs, Uses;
97 };
98
Akira Hatanakae01ff9d2013-03-01 00:50:52 +000099 /// Base class for inspecting loads and stores.
100 class InspectMemInstr {
101 public:
Akira Hatanaka8f7bfb32013-03-01 02:03:51 +0000102 InspectMemInstr(bool ForbidMemInstr_)
103 : OrigSeenLoad(false), OrigSeenStore(false), SeenLoad(false),
104 SeenStore(false), ForbidMemInstr(ForbidMemInstr_) {}
105
106 /// Return true if MI cannot be moved to delay slot.
107 bool hasHazard(const MachineInstr &MI);
108
Akira Hatanakae01ff9d2013-03-01 00:50:52 +0000109 virtual ~InspectMemInstr() {}
Akira Hatanaka8f7bfb32013-03-01 02:03:51 +0000110
111 protected:
112 /// Flags indicating whether loads or stores have been seen.
113 bool OrigSeenLoad, OrigSeenStore, SeenLoad, SeenStore;
114
115 /// Memory instructions are not allowed to move to delay slot if this flag
116 /// is true.
117 bool ForbidMemInstr;
118
119 private:
120 virtual bool hasHazard_(const MachineInstr &MI) = 0;
Akira Hatanakae01ff9d2013-03-01 00:50:52 +0000121 };
122
123 /// This subclass rejects any memory instructions.
124 class NoMemInstr : public InspectMemInstr {
125 public:
Akira Hatanaka8f7bfb32013-03-01 02:03:51 +0000126 NoMemInstr() : InspectMemInstr(true) {}
127 private:
Craig Topper56c590a2014-04-29 07:58:02 +0000128 bool hasHazard_(const MachineInstr &MI) override { return true; }
Akira Hatanaka8f7bfb32013-03-01 02:03:51 +0000129 };
130
131 /// This subclass accepts loads from stacks and constant loads.
132 class LoadFromStackOrConst : public InspectMemInstr {
133 public:
134 LoadFromStackOrConst() : InspectMemInstr(false) {}
135 private:
Craig Topper56c590a2014-04-29 07:58:02 +0000136 bool hasHazard_(const MachineInstr &MI) override;
Akira Hatanakae01ff9d2013-03-01 00:50:52 +0000137 };
138
139 /// This subclass uses memory dependence information to determine whether a
140 /// memory instruction can be moved to a delay slot.
141 class MemDefsUses : public InspectMemInstr {
Akira Hatanakaeb33ced2013-03-01 00:16:31 +0000142 public:
143 MemDefsUses(const MachineFrameInfo *MFI);
144
Akira Hatanakaeb33ced2013-03-01 00:16:31 +0000145 private:
Nick Lewyckyaad475b2014-04-15 07:22:52 +0000146 typedef PointerUnion<const Value *, const PseudoSourceValue *> ValueType;
147
Craig Topper56c590a2014-04-29 07:58:02 +0000148 bool hasHazard_(const MachineInstr &MI) override;
Akira Hatanaka8f7bfb32013-03-01 02:03:51 +0000149
Akira Hatanakaeb33ced2013-03-01 00:16:31 +0000150 /// Update Defs and Uses. Return true if there exist dependences that
Akira Hatanakae9e588d2013-03-01 02:17:02 +0000151 /// disqualify the delay slot candidate between V and values in Uses and
152 /// Defs.
Nick Lewyckyaad475b2014-04-15 07:22:52 +0000153 bool updateDefsUses(ValueType V, bool MayStore);
Akira Hatanakaeb33ced2013-03-01 00:16:31 +0000154
155 /// Get the list of underlying objects of MI's memory operand.
156 bool getUnderlyingObjects(const MachineInstr &MI,
Nick Lewyckyaad475b2014-04-15 07:22:52 +0000157 SmallVectorImpl<ValueType> &Objects) const;
Akira Hatanakaeb33ced2013-03-01 00:16:31 +0000158
159 const MachineFrameInfo *MFI;
Nick Lewyckyaad475b2014-04-15 07:22:52 +0000160 SmallPtrSet<ValueType, 4> Uses, Defs;
Akira Hatanakaeb33ced2013-03-01 00:16:31 +0000161
Akira Hatanakaeb33ced2013-03-01 00:16:31 +0000162 /// Flags indicating whether loads or stores with no underlying objects have
163 /// been seen.
164 bool SeenNoObjLoad, SeenNoObjStore;
Akira Hatanakaeb33ced2013-03-01 00:16:31 +0000165 };
166
Akira Hatanakaa0612812013-02-07 21:32:32 +0000167 class Filler : public MachineFunctionPass {
168 public:
Bruno Cardoso Lopesfde21cf2010-12-09 17:31:11 +0000169 Filler(TargetMachine &tm)
Bill Wendlingead89ef2013-06-07 07:04:14 +0000170 : MachineFunctionPass(ID), TM(tm) { }
Bruno Cardoso Lopes0b97ce72007-08-18 01:50:47 +0000171
Craig Topper56c590a2014-04-29 07:58:02 +0000172 const char *getPassName() const override {
Bruno Cardoso Lopes0b97ce72007-08-18 01:50:47 +0000173 return "Mips Delay Slot Filler";
174 }
175
Craig Topper56c590a2014-04-29 07:58:02 +0000176 bool runOnMachineFunction(MachineFunction &F) override {
Bruno Cardoso Lopes0b97ce72007-08-18 01:50:47 +0000177 bool Changed = false;
178 for (MachineFunction::iterator FI = F.begin(), FE = F.end();
179 FI != FE; ++FI)
180 Changed |= runOnMachineBasicBlock(*FI);
Daniel Sanders308181e2014-06-12 10:44:10 +0000181
182 // This pass invalidates liveness information when it reorders
183 // instructions to fill delay slot. Without this, -verify-machineinstrs
184 // will fail.
185 if (Changed)
186 F.getRegInfo().invalidateLiveness();
187
Bruno Cardoso Lopes0b97ce72007-08-18 01:50:47 +0000188 return Changed;
189 }
190
Craig Topper56c590a2014-04-29 07:58:02 +0000191 void getAnalysisUsage(AnalysisUsage &AU) const override {
Akira Hatanaka8f7bfb32013-03-01 02:03:51 +0000192 AU.addRequired<MachineBranchProbabilityInfo>();
193 MachineFunctionPass::getAnalysisUsage(AU);
194 }
Akira Hatanakaa0612812013-02-07 21:32:32 +0000195
Akira Hatanaka8f7bfb32013-03-01 02:03:51 +0000196 private:
Akira Hatanakaa0612812013-02-07 21:32:32 +0000197 bool runOnMachineBasicBlock(MachineBasicBlock &MBB);
198
Jozef Kolek3b8ddb62014-11-21 22:04:35 +0000199 Iter replaceWithCompactBranch(MachineBasicBlock &MBB,
200 Iter Branch, DebugLoc DL);
201
Jozef Kolek650a61a2015-02-13 17:51:27 +0000202 Iter replaceWithCompactJump(MachineBasicBlock &MBB,
203 Iter Jump, DebugLoc DL);
204
Akira Hatanaka06bd1382013-02-14 23:40:57 +0000205 /// This function checks if it is valid to move Candidate to the delay slot
Akira Hatanakaeb33ced2013-03-01 00:16:31 +0000206 /// and returns true if it isn't. It also updates memory and register
207 /// dependence information.
208 bool delayHasHazard(const MachineInstr &Candidate, RegDefsUses &RegDU,
Akira Hatanakae01ff9d2013-03-01 00:50:52 +0000209 InspectMemInstr &IM) const;
Akira Hatanakaf2619ee2011-09-29 23:52:13 +0000210
Akira Hatanakaf815db52013-03-01 00:26:14 +0000211 /// This function searches range [Begin, End) for an instruction that can be
212 /// moved to the delay slot. Returns true on success.
213 template<typename IterTy>
214 bool searchRange(MachineBasicBlock &MBB, IterTy Begin, IterTy End,
Vasileios Kalintiris87614902015-03-04 12:37:58 +0000215 RegDefsUses &RegDU, InspectMemInstr &IM, Iter Slot,
216 IterTy &Filler) const;
Akira Hatanakaf815db52013-03-01 00:26:14 +0000217
Akira Hatanakae01ff9d2013-03-01 00:50:52 +0000218 /// This function searches in the backward direction for an instruction that
219 /// can be moved to the delay slot. Returns true on success.
220 bool searchBackward(MachineBasicBlock &MBB, Iter Slot) const;
221
222 /// This function searches MBB in the forward direction for an instruction
223 /// that can be moved to the delay slot. Returns true on success.
224 bool searchForward(MachineBasicBlock &MBB, Iter Slot) const;
Akira Hatanakadfd2f242013-02-14 23:11:24 +0000225
Akira Hatanaka1ff803f2013-03-25 20:11:16 +0000226 /// This function searches one of MBB's successor blocks for an instruction
227 /// that can be moved to the delay slot and inserts clones of the
228 /// instruction into the successor's predecessor blocks.
Akira Hatanaka8f7bfb32013-03-01 02:03:51 +0000229 bool searchSuccBBs(MachineBasicBlock &MBB, Iter Slot) const;
230
Akira Hatanakae9e588d2013-03-01 02:17:02 +0000231 /// Pick a successor block of MBB. Return NULL if MBB doesn't have a
232 /// successor block that is not a landing pad.
Akira Hatanaka8f7bfb32013-03-01 02:03:51 +0000233 MachineBasicBlock *selectSuccBB(MachineBasicBlock &B) const;
234
235 /// This function analyzes MBB and returns an instruction with an unoccupied
236 /// slot that branches to Dst.
237 std::pair<MipsInstrInfo::BranchType, MachineInstr *>
238 getBranch(MachineBasicBlock &MBB, const MachineBasicBlock &Dst) const;
239
240 /// Examine Pred and see if it is possible to insert an instruction into
241 /// one of its branches delay slot or its end.
242 bool examinePred(MachineBasicBlock &Pred, const MachineBasicBlock &Succ,
243 RegDefsUses &RegDU, bool &HasMultipleSuccs,
244 BB2BrMap &BrMap) const;
245
Akira Hatanakadfd2f242013-02-14 23:11:24 +0000246 bool terminateSearch(const MachineInstr &Candidate) const;
Akira Hatanakaf2619ee2011-09-29 23:52:13 +0000247
Akira Hatanakaa0612812013-02-07 21:32:32 +0000248 TargetMachine &TM;
Akira Hatanakaf2619ee2011-09-29 23:52:13 +0000249
Akira Hatanakaa0612812013-02-07 21:32:32 +0000250 static char ID;
Bruno Cardoso Lopes0b97ce72007-08-18 01:50:47 +0000251 };
252 char Filler::ID = 0;
253} // end of anonymous namespace
254
Akira Hatanaka8f7bfb32013-03-01 02:03:51 +0000255static bool hasUnoccupiedSlot(const MachineInstr *MI) {
256 return MI->hasDelaySlot() && !MI->isBundledWithSucc();
257}
258
259/// This function inserts clones of Filler into predecessor blocks.
260static void insertDelayFiller(Iter Filler, const BB2BrMap &BrMap) {
261 MachineFunction *MF = Filler->getParent()->getParent();
262
263 for (BB2BrMap::const_iterator I = BrMap.begin(); I != BrMap.end(); ++I) {
264 if (I->second) {
265 MIBundleBuilder(I->second).append(MF->CloneMachineInstr(&*Filler));
266 ++UsefulSlots;
267 } else {
268 I->first->insert(I->first->end(), MF->CloneMachineInstr(&*Filler));
269 }
270 }
271}
272
273/// This function adds registers Filler defines to MBB's live-in register list.
274static void addLiveInRegs(Iter Filler, MachineBasicBlock &MBB) {
275 for (unsigned I = 0, E = Filler->getNumOperands(); I != E; ++I) {
276 const MachineOperand &MO = Filler->getOperand(I);
277 unsigned R;
278
279 if (!MO.isReg() || !MO.isDef() || !(R = MO.getReg()))
280 continue;
281
282#ifndef NDEBUG
283 const MachineFunction &MF = *MBB.getParent();
Eric Christopher96e72c62015-01-29 23:27:36 +0000284 assert(MF.getSubtarget().getRegisterInfo()->getAllocatableSet(MF).test(R) &&
Akira Hatanaka8f7bfb32013-03-01 02:03:51 +0000285 "Shouldn't move an instruction with unallocatable registers across "
286 "basic block boundaries.");
287#endif
288
289 if (!MBB.isLiveIn(R))
290 MBB.addLiveIn(R);
291 }
292}
293
Eric Christopher96e72c62015-01-29 23:27:36 +0000294RegDefsUses::RegDefsUses(const TargetRegisterInfo &TRI)
295 : TRI(TRI), Defs(TRI.getNumRegs(), false), Uses(TRI.getNumRegs(), false) {}
Akira Hatanaka979899e2013-02-26 01:30:05 +0000296
297void RegDefsUses::init(const MachineInstr &MI) {
298 // Add all register operands which are explicit and non-variadic.
299 update(MI, 0, MI.getDesc().getNumOperands());
300
301 // If MI is a call, add RA to Defs to prevent users of RA from going into
302 // delay slot.
303 if (MI.isCall())
304 Defs.set(Mips::RA);
305
306 // Add all implicit register operands of branch instructions except
307 // register AT.
308 if (MI.isBranch()) {
309 update(MI, MI.getDesc().getNumOperands(), MI.getNumOperands());
310 Defs.reset(Mips::AT);
311 }
312}
313
Akira Hatanakae01ff9d2013-03-01 00:50:52 +0000314void RegDefsUses::setCallerSaved(const MachineInstr &MI) {
315 assert(MI.isCall());
316
317 // If MI is a call, add all caller-saved registers to Defs.
318 BitVector CallerSavedRegs(TRI.getNumRegs(), true);
319
320 CallerSavedRegs.reset(Mips::ZERO);
321 CallerSavedRegs.reset(Mips::ZERO_64);
322
323 for (const MCPhysReg *R = TRI.getCalleeSavedRegs(); *R; ++R)
324 for (MCRegAliasIterator AI(*R, &TRI, true); AI.isValid(); ++AI)
325 CallerSavedRegs.reset(*AI);
326
327 Defs |= CallerSavedRegs;
328}
329
Akira Hatanaka8f7bfb32013-03-01 02:03:51 +0000330void RegDefsUses::setUnallocatableRegs(const MachineFunction &MF) {
331 BitVector AllocSet = TRI.getAllocatableSet(MF);
332
333 for (int R = AllocSet.find_first(); R != -1; R = AllocSet.find_next(R))
334 for (MCRegAliasIterator AI(R, &TRI, false); AI.isValid(); ++AI)
335 AllocSet.set(*AI);
336
337 AllocSet.set(Mips::ZERO);
338 AllocSet.set(Mips::ZERO_64);
339
340 Defs |= AllocSet.flip();
341}
342
343void RegDefsUses::addLiveOut(const MachineBasicBlock &MBB,
344 const MachineBasicBlock &SuccBB) {
345 for (MachineBasicBlock::const_succ_iterator SI = MBB.succ_begin(),
346 SE = MBB.succ_end(); SI != SE; ++SI)
347 if (*SI != &SuccBB)
348 for (MachineBasicBlock::livein_iterator LI = (*SI)->livein_begin(),
349 LE = (*SI)->livein_end(); LI != LE; ++LI)
350 Uses.set(*LI);
351}
352
Akira Hatanaka979899e2013-02-26 01:30:05 +0000353bool RegDefsUses::update(const MachineInstr &MI, unsigned Begin, unsigned End) {
354 BitVector NewDefs(TRI.getNumRegs()), NewUses(TRI.getNumRegs());
355 bool HasHazard = false;
356
357 for (unsigned I = Begin; I != End; ++I) {
358 const MachineOperand &MO = MI.getOperand(I);
359
360 if (MO.isReg() && MO.getReg())
361 HasHazard |= checkRegDefsUses(NewDefs, NewUses, MO.getReg(), MO.isDef());
362 }
363
364 Defs |= NewDefs;
365 Uses |= NewUses;
366
367 return HasHazard;
368}
369
370bool RegDefsUses::checkRegDefsUses(BitVector &NewDefs, BitVector &NewUses,
371 unsigned Reg, bool IsDef) const {
372 if (IsDef) {
373 NewDefs.set(Reg);
374 // check whether Reg has already been defined or used.
375 return (isRegInSet(Defs, Reg) || isRegInSet(Uses, Reg));
376 }
377
378 NewUses.set(Reg);
379 // check whether Reg has already been defined.
380 return isRegInSet(Defs, Reg);
381}
382
383bool RegDefsUses::isRegInSet(const BitVector &RegSet, unsigned Reg) const {
384 // Check Reg and all aliased Registers.
385 for (MCRegAliasIterator AI(Reg, &TRI, true); AI.isValid(); ++AI)
386 if (RegSet.test(*AI))
387 return true;
388 return false;
389}
390
Akira Hatanaka8f7bfb32013-03-01 02:03:51 +0000391bool InspectMemInstr::hasHazard(const MachineInstr &MI) {
Akira Hatanakaeb33ced2013-03-01 00:16:31 +0000392 if (!MI.mayStore() && !MI.mayLoad())
393 return false;
394
395 if (ForbidMemInstr)
396 return true;
397
Akira Hatanaka8f7bfb32013-03-01 02:03:51 +0000398 OrigSeenLoad = SeenLoad;
399 OrigSeenStore = SeenStore;
Akira Hatanakaeb33ced2013-03-01 00:16:31 +0000400 SeenLoad |= MI.mayLoad();
401 SeenStore |= MI.mayStore();
402
403 // If MI is an ordered or volatile memory reference, disallow moving
404 // subsequent loads and stores to delay slot.
405 if (MI.hasOrderedMemoryRef() && (OrigSeenLoad || OrigSeenStore)) {
406 ForbidMemInstr = true;
407 return true;
408 }
409
Akira Hatanaka8f7bfb32013-03-01 02:03:51 +0000410 return hasHazard_(MI);
411}
412
413bool LoadFromStackOrConst::hasHazard_(const MachineInstr &MI) {
414 if (MI.mayStore())
415 return true;
416
Nick Lewyckyaad475b2014-04-15 07:22:52 +0000417 if (!MI.hasOneMemOperand() || !(*MI.memoperands_begin())->getPseudoValue())
Akira Hatanaka8f7bfb32013-03-01 02:03:51 +0000418 return true;
419
Nick Lewyckyaad475b2014-04-15 07:22:52 +0000420 if (const PseudoSourceValue *PSV =
421 (*MI.memoperands_begin())->getPseudoValue()) {
422 if (isa<FixedStackPseudoSourceValue>(PSV))
423 return false;
Craig Topper062a2ba2014-04-25 05:30:21 +0000424 return !PSV->isConstant(nullptr) && PSV != PseudoSourceValue::getStack();
Nick Lewyckyaad475b2014-04-15 07:22:52 +0000425 }
Akira Hatanaka8f7bfb32013-03-01 02:03:51 +0000426
427 return true;
428}
429
430MemDefsUses::MemDefsUses(const MachineFrameInfo *MFI_)
431 : InspectMemInstr(false), MFI(MFI_), SeenNoObjLoad(false),
432 SeenNoObjStore(false) {}
433
434bool MemDefsUses::hasHazard_(const MachineInstr &MI) {
Akira Hatanakaeb33ced2013-03-01 00:16:31 +0000435 bool HasHazard = false;
Nick Lewyckyaad475b2014-04-15 07:22:52 +0000436 SmallVector<ValueType, 4> Objs;
Akira Hatanakaeb33ced2013-03-01 00:16:31 +0000437
438 // Check underlying object list.
439 if (getUnderlyingObjects(MI, Objs)) {
Nick Lewyckyaad475b2014-04-15 07:22:52 +0000440 for (SmallVectorImpl<ValueType>::const_iterator I = Objs.begin();
Akira Hatanakaeb33ced2013-03-01 00:16:31 +0000441 I != Objs.end(); ++I)
442 HasHazard |= updateDefsUses(*I, MI.mayStore());
443
444 return HasHazard;
445 }
446
447 // No underlying objects found.
448 HasHazard = MI.mayStore() && (OrigSeenLoad || OrigSeenStore);
449 HasHazard |= MI.mayLoad() || OrigSeenStore;
450
451 SeenNoObjLoad |= MI.mayLoad();
452 SeenNoObjStore |= MI.mayStore();
453
454 return HasHazard;
455}
456
Nick Lewyckyaad475b2014-04-15 07:22:52 +0000457bool MemDefsUses::updateDefsUses(ValueType V, bool MayStore) {
Akira Hatanakaeb33ced2013-03-01 00:16:31 +0000458 if (MayStore)
David Blaikie70573dc2014-11-19 07:49:26 +0000459 return !Defs.insert(V).second || Uses.count(V) || SeenNoObjStore ||
460 SeenNoObjLoad;
Akira Hatanakaeb33ced2013-03-01 00:16:31 +0000461
462 Uses.insert(V);
463 return Defs.count(V) || SeenNoObjStore;
464}
465
466bool MemDefsUses::
467getUnderlyingObjects(const MachineInstr &MI,
Nick Lewyckyaad475b2014-04-15 07:22:52 +0000468 SmallVectorImpl<ValueType> &Objects) const {
469 if (!MI.hasOneMemOperand() ||
470 (!(*MI.memoperands_begin())->getValue() &&
471 !(*MI.memoperands_begin())->getPseudoValue()))
Akira Hatanakaeb33ced2013-03-01 00:16:31 +0000472 return false;
473
Nick Lewyckyaad475b2014-04-15 07:22:52 +0000474 if (const PseudoSourceValue *PSV =
475 (*MI.memoperands_begin())->getPseudoValue()) {
476 if (!PSV->isAliased(MFI))
477 return false;
478 Objects.push_back(PSV);
479 return true;
480 }
481
Akira Hatanakaeb33ced2013-03-01 00:16:31 +0000482 const Value *V = (*MI.memoperands_begin())->getValue();
483
484 SmallVector<Value *, 4> Objs;
485 GetUnderlyingObjects(const_cast<Value *>(V), Objs);
486
Craig Topper31ee5862013-07-03 15:07:05 +0000487 for (SmallVectorImpl<Value *>::iterator I = Objs.begin(), E = Objs.end();
Akira Hatanakaeb33ced2013-03-01 00:16:31 +0000488 I != E; ++I) {
Nick Lewyckyaad475b2014-04-15 07:22:52 +0000489 if (!isIdentifiedObject(V))
Akira Hatanakaeb33ced2013-03-01 00:16:31 +0000490 return false;
491
492 Objects.push_back(*I);
493 }
494
495 return true;
496}
497
Jozef Kolek3b8ddb62014-11-21 22:04:35 +0000498// Replace Branch with the compact branch instruction.
499Iter Filler::replaceWithCompactBranch(MachineBasicBlock &MBB,
500 Iter Branch, DebugLoc DL) {
Eric Christopher6b6db772015-02-02 23:03:43 +0000501 const MipsInstrInfo *TII =
502 MBB.getParent()->getSubtarget<MipsSubtarget>().getInstrInfo();
Jozef Kolek3b8ddb62014-11-21 22:04:35 +0000503
504 unsigned NewOpcode =
505 (((unsigned) Branch->getOpcode()) == Mips::BEQ) ? Mips::BEQZC_MM
506 : Mips::BNEZC_MM;
507
508 const MCInstrDesc &NewDesc = TII->get(NewOpcode);
509 MachineInstrBuilder MIB = BuildMI(MBB, Branch, DL, NewDesc);
510
511 MIB.addReg(Branch->getOperand(0).getReg());
512 MIB.addMBB(Branch->getOperand(2).getMBB());
513
514 Iter tmpIter = Branch;
515 Branch = std::prev(Branch);
516 MBB.erase(tmpIter);
517
518 return Branch;
519}
520
Jozef Kolek650a61a2015-02-13 17:51:27 +0000521// Replace Jumps with the compact jump instruction.
522Iter Filler::replaceWithCompactJump(MachineBasicBlock &MBB,
523 Iter Jump, DebugLoc DL) {
524 const MipsInstrInfo *TII =
525 MBB.getParent()->getSubtarget<MipsSubtarget>().getInstrInfo();
526
527 const MCInstrDesc &NewDesc = TII->get(Mips::JRC16_MM);
528 MachineInstrBuilder MIB = BuildMI(MBB, Jump, DL, NewDesc);
529
530 MIB.addReg(Jump->getOperand(0).getReg());
531
532 Iter tmpIter = Jump;
533 Jump = std::prev(Jump);
534 MBB.erase(tmpIter);
535
536 return Jump;
537}
538
Zoran Jovanovicb554bba2014-11-25 10:50:00 +0000539// For given opcode returns opcode of corresponding instruction with short
540// delay slot.
541static int getEquivalentCallShort(int Opcode) {
542 switch (Opcode) {
543 case Mips::BGEZAL:
544 return Mips::BGEZALS_MM;
545 case Mips::BLTZAL:
546 return Mips::BLTZALS_MM;
547 case Mips::JAL:
548 return Mips::JALS_MM;
549 case Mips::JALR:
550 return Mips::JALRS_MM;
551 case Mips::JALR16_MM:
552 return Mips::JALRS16_MM;
553 default:
554 llvm_unreachable("Unexpected call instruction for microMIPS.");
555 }
556}
557
Bruno Cardoso Lopes0b97ce72007-08-18 01:50:47 +0000558/// runOnMachineBasicBlock - Fill in delay slots for the given basic block.
Akira Hatanakaf2619ee2011-09-29 23:52:13 +0000559/// We assume there is only one delay slot per delayed instruction.
Akira Hatanaka1083eb12013-02-14 23:20:15 +0000560bool Filler::runOnMachineBasicBlock(MachineBasicBlock &MBB) {
Bruno Cardoso Lopes0b97ce72007-08-18 01:50:47 +0000561 bool Changed = false;
Eric Christopher6b6db772015-02-02 23:03:43 +0000562 const MipsSubtarget &STI = MBB.getParent()->getSubtarget<MipsSubtarget>();
Eric Christopher96e72c62015-01-29 23:27:36 +0000563 bool InMicroMipsMode = STI.inMicroMipsMode();
564 const MipsInstrInfo *TII = STI.getInstrInfo();
Akira Hatanakae7b06972011-10-05 01:30:09 +0000565
Akira Hatanakadfd2f242013-02-14 23:11:24 +0000566 for (Iter I = MBB.begin(); I != MBB.end(); ++I) {
Akira Hatanaka8f7bfb32013-03-01 02:03:51 +0000567 if (!hasUnoccupiedSlot(&*I))
Akira Hatanakaa0612812013-02-07 21:32:32 +0000568 continue;
Akira Hatanaka5d4e4ea2011-10-05 01:23:39 +0000569
Zoran Jovanovicb554bba2014-11-25 10:50:00 +0000570 ++FilledSlots;
571 Changed = true;
Akira Hatanaka5d4e4ea2011-10-05 01:23:39 +0000572
Zoran Jovanovicb554bba2014-11-25 10:50:00 +0000573 // Delay slot filling is disabled at -O0.
574 if (!DisableDelaySlotFiller && (TM.getOptLevel() != CodeGenOpt::None)) {
575 bool Filled = false;
Zoran Jovanovic37bca102014-11-10 17:27:56 +0000576
Zoran Jovanovicb554bba2014-11-25 10:50:00 +0000577 if (searchBackward(MBB, I)) {
578 Filled = true;
579 } else if (I->isTerminator()) {
580 if (searchSuccBBs(MBB, I)) {
581 Filled = true;
Zoran Jovanovic37bca102014-11-10 17:27:56 +0000582 }
Zoran Jovanovicb554bba2014-11-25 10:50:00 +0000583 } else if (searchForward(MBB, I)) {
584 Filled = true;
585 }
586
587 if (Filled) {
588 // Get instruction with delay slot.
589 MachineBasicBlock::instr_iterator DSI(I);
590
591 if (InMicroMipsMode && TII->GetInstSizeInBytes(std::next(DSI)) == 2 &&
592 DSI->isCall()) {
593 // If instruction in delay slot is 16b change opcode to
594 // corresponding instruction with short delay slot.
595 DSI->setDesc(TII->get(getEquivalentCallShort(DSI->getOpcode())));
596 }
597
598 continue;
Akira Hatanaka8f7bfb32013-03-01 02:03:51 +0000599 }
600 }
Akira Hatanaka5ac78682012-06-13 23:25:52 +0000601
Jozef Kolek3b8ddb62014-11-21 22:04:35 +0000602 // If instruction is BEQ or BNE with one ZERO register, then instead of
603 // adding NOP replace this instruction with the corresponding compact
604 // branch instruction, i.e. BEQZC or BNEZC.
605 unsigned Opcode = I->getOpcode();
Jozef Kolek650a61a2015-02-13 17:51:27 +0000606 if (InMicroMipsMode) {
607 switch (Opcode) {
608 case Mips::BEQ:
609 case Mips::BNE:
610 if (((unsigned) I->getOperand(1).getReg()) == Mips::ZERO) {
611 I = replaceWithCompactBranch(MBB, I, I->getDebugLoc());
612 continue;
613 }
614 break;
615 case Mips::JR:
616 case Mips::PseudoReturn:
617 case Mips::PseudoIndirectBranch:
618 // For microMIPS the PseudoReturn and PseudoIndirectBranch are allways
619 // expanded to JR_MM, so they can be replaced with JRC16_MM.
620 I = replaceWithCompactJump(MBB, I, I->getDebugLoc());
621 continue;
622 default:
623 break;
624 }
Jozef Kolek3b8ddb62014-11-21 22:04:35 +0000625 }
Jozef Kolek650a61a2015-02-13 17:51:27 +0000626 // Bundle the NOP to the instruction with the delay slot.
627 BuildMI(MBB, std::next(I), I->getDebugLoc(), TII->get(Mips::NOP));
628 MIBundleBuilder(MBB, I, std::next(I, 2));
Akira Hatanakaa0612812013-02-07 21:32:32 +0000629 }
630
Bruno Cardoso Lopes0b97ce72007-08-18 01:50:47 +0000631 return Changed;
632}
633
634/// createMipsDelaySlotFillerPass - Returns a pass that fills in delay
635/// slots in Mips MachineFunctions
636FunctionPass *llvm::createMipsDelaySlotFillerPass(MipsTargetMachine &tm) {
637 return new Filler(tm);
638}
639
Akira Hatanakaf815db52013-03-01 00:26:14 +0000640template<typename IterTy>
641bool Filler::searchRange(MachineBasicBlock &MBB, IterTy Begin, IterTy End,
Vasileios Kalintiris87614902015-03-04 12:37:58 +0000642 RegDefsUses &RegDU, InspectMemInstr& IM, Iter Slot,
643 IterTy &Filler) const {
Akira Hatanakaf815db52013-03-01 00:26:14 +0000644 for (IterTy I = Begin; I != End; ++I) {
Akira Hatanakaf2619ee2011-09-29 23:52:13 +0000645 // skip debug value
646 if (I->isDebugValue())
647 continue;
648
Akira Hatanakadfd2f242013-02-14 23:11:24 +0000649 if (terminateSearch(*I))
Akira Hatanakaf2619ee2011-09-29 23:52:13 +0000650 break;
651
Akira Hatanakaeb33ced2013-03-01 00:16:31 +0000652 assert((!I->isCall() && !I->isReturn() && !I->isBranch()) &&
653 "Cannot put calls, returns or branches in delay slot.");
654
Akira Hatanakae01ff9d2013-03-01 00:50:52 +0000655 if (delayHasHazard(*I, RegDU, IM))
Akira Hatanakaf2619ee2011-09-29 23:52:13 +0000656 continue;
Akira Hatanakaf2619ee2011-09-29 23:52:13 +0000657
Eric Christopher6b6db772015-02-02 23:03:43 +0000658 const MipsSubtarget &STI = MBB.getParent()->getSubtarget<MipsSubtarget>();
659 if (STI.isTargetNaCl()) {
Sasa Stankovic5fddf612014-03-10 20:34:23 +0000660 // In NaCl, instructions that must be masked are forbidden in delay slots.
661 // We only check for loads, stores and SP changes. Calls, returns and
662 // branches are not checked because non-NaCl targets never put them in
663 // delay slots.
664 unsigned AddrIdx;
Eric Christopherd9134482014-08-04 21:25:23 +0000665 if ((isBasePlusOffsetMemoryAccess(I->getOpcode(), &AddrIdx) &&
666 baseRegNeedsLoadStoreMask(I->getOperand(AddrIdx).getReg())) ||
Eric Christopher6b6db772015-02-02 23:03:43 +0000667 I->modifiesRegister(Mips::SP, STI.getRegisterInfo()))
Sasa Stankovic5fddf612014-03-10 20:34:23 +0000668 continue;
669 }
670
Eric Christopher6b6db772015-02-02 23:03:43 +0000671 bool InMicroMipsMode = STI.inMicroMipsMode();
672 const MipsInstrInfo *TII = STI.getInstrInfo();
Jozef Koleke7cad7a2015-01-13 15:59:17 +0000673 unsigned Opcode = (*Slot).getOpcode();
674 if (InMicroMipsMode && TII->GetInstSizeInBytes(&(*I)) == 2 &&
675 (Opcode == Mips::JR || Opcode == Mips::PseudoIndirectBranch ||
676 Opcode == Mips::PseudoReturn))
677 continue;
678
Akira Hatanakaf815db52013-03-01 00:26:14 +0000679 Filler = I;
680 return true;
681 }
682
683 return false;
684}
685
Akira Hatanakae01ff9d2013-03-01 00:50:52 +0000686bool Filler::searchBackward(MachineBasicBlock &MBB, Iter Slot) const {
Akira Hatanaka8f7bfb32013-03-01 02:03:51 +0000687 if (DisableBackwardSearch)
688 return false;
689
Eric Christopher96e72c62015-01-29 23:27:36 +0000690 RegDefsUses RegDU(*MBB.getParent()->getSubtarget().getRegisterInfo());
Akira Hatanakaf815db52013-03-01 00:26:14 +0000691 MemDefsUses MemDU(MBB.getParent()->getFrameInfo());
Akira Hatanakae01ff9d2013-03-01 00:50:52 +0000692 ReverseIter Filler;
Akira Hatanakaf815db52013-03-01 00:26:14 +0000693
694 RegDU.init(*Slot);
695
Vasileios Kalintiris87614902015-03-04 12:37:58 +0000696 if (!searchRange(MBB, ReverseIter(Slot), MBB.rend(), RegDU, MemDU, Slot,
697 Filler))
Akira Hatanaka4c0a7122013-10-07 19:33:02 +0000698 return false;
Akira Hatanakae01ff9d2013-03-01 00:50:52 +0000699
Benjamin Kramerb6d0bd42014-03-02 12:27:27 +0000700 MBB.splice(std::next(Slot), &MBB, std::next(Filler).base());
701 MIBundleBuilder(MBB, Slot, std::next(Slot, 2));
Akira Hatanaka4c0a7122013-10-07 19:33:02 +0000702 ++UsefulSlots;
703 return true;
Akira Hatanakae01ff9d2013-03-01 00:50:52 +0000704}
705
706bool Filler::searchForward(MachineBasicBlock &MBB, Iter Slot) const {
707 // Can handle only calls.
Akira Hatanaka8f7bfb32013-03-01 02:03:51 +0000708 if (DisableForwardSearch || !Slot->isCall())
Akira Hatanakae01ff9d2013-03-01 00:50:52 +0000709 return false;
710
Eric Christopher96e72c62015-01-29 23:27:36 +0000711 RegDefsUses RegDU(*MBB.getParent()->getSubtarget().getRegisterInfo());
Akira Hatanakae01ff9d2013-03-01 00:50:52 +0000712 NoMemInstr NM;
713 Iter Filler;
714
715 RegDU.setCallerSaved(*Slot);
716
Vasileios Kalintiris87614902015-03-04 12:37:58 +0000717 if (!searchRange(MBB, std::next(Slot), MBB.end(), RegDU, NM, Slot, Filler))
Akira Hatanaka4c0a7122013-10-07 19:33:02 +0000718 return false;
Akira Hatanaka5d4e4ea2011-10-05 01:23:39 +0000719
Benjamin Kramerb6d0bd42014-03-02 12:27:27 +0000720 MBB.splice(std::next(Slot), &MBB, Filler);
721 MIBundleBuilder(MBB, Slot, std::next(Slot, 2));
Akira Hatanaka4c0a7122013-10-07 19:33:02 +0000722 ++UsefulSlots;
723 return true;
Akira Hatanakaf2619ee2011-09-29 23:52:13 +0000724}
725
Akira Hatanaka8f7bfb32013-03-01 02:03:51 +0000726bool Filler::searchSuccBBs(MachineBasicBlock &MBB, Iter Slot) const {
727 if (DisableSuccBBSearch)
728 return false;
729
730 MachineBasicBlock *SuccBB = selectSuccBB(MBB);
731
732 if (!SuccBB)
733 return false;
734
Eric Christopher96e72c62015-01-29 23:27:36 +0000735 RegDefsUses RegDU(*MBB.getParent()->getSubtarget().getRegisterInfo());
Akira Hatanaka8f7bfb32013-03-01 02:03:51 +0000736 bool HasMultipleSuccs = false;
737 BB2BrMap BrMap;
Benjamin Kramerd2da7202014-04-21 09:34:48 +0000738 std::unique_ptr<InspectMemInstr> IM;
Akira Hatanaka8f7bfb32013-03-01 02:03:51 +0000739 Iter Filler;
740
741 // Iterate over SuccBB's predecessor list.
742 for (MachineBasicBlock::pred_iterator PI = SuccBB->pred_begin(),
743 PE = SuccBB->pred_end(); PI != PE; ++PI)
744 if (!examinePred(**PI, *SuccBB, RegDU, HasMultipleSuccs, BrMap))
745 return false;
746
747 // Do not allow moving instructions which have unallocatable register operands
748 // across basic block boundaries.
749 RegDU.setUnallocatableRegs(*MBB.getParent());
750
751 // Only allow moving loads from stack or constants if any of the SuccBB's
752 // predecessors have multiple successors.
753 if (HasMultipleSuccs) {
754 IM.reset(new LoadFromStackOrConst());
755 } else {
756 const MachineFrameInfo *MFI = MBB.getParent()->getFrameInfo();
757 IM.reset(new MemDefsUses(MFI));
758 }
759
Vasileios Kalintiris87614902015-03-04 12:37:58 +0000760 if (!searchRange(MBB, SuccBB->begin(), SuccBB->end(), RegDU, *IM, Slot,
761 Filler))
Akira Hatanaka8f7bfb32013-03-01 02:03:51 +0000762 return false;
763
764 insertDelayFiller(Filler, BrMap);
765 addLiveInRegs(Filler, *SuccBB);
766 Filler->eraseFromParent();
767
768 return true;
769}
770
771MachineBasicBlock *Filler::selectSuccBB(MachineBasicBlock &B) const {
772 if (B.succ_empty())
Craig Topper062a2ba2014-04-25 05:30:21 +0000773 return nullptr;
Akira Hatanaka8f7bfb32013-03-01 02:03:51 +0000774
775 // Select the successor with the larget edge weight.
Benjamin Kramer3a377bc2014-03-01 11:47:00 +0000776 auto &Prob = getAnalysis<MachineBranchProbabilityInfo>();
777 MachineBasicBlock *S = *std::max_element(B.succ_begin(), B.succ_end(),
778 [&](const MachineBasicBlock *Dst0,
779 const MachineBasicBlock *Dst1) {
780 return Prob.getEdgeWeight(&B, Dst0) < Prob.getEdgeWeight(&B, Dst1);
781 });
Craig Topper062a2ba2014-04-25 05:30:21 +0000782 return S->isLandingPad() ? nullptr : S;
Akira Hatanaka8f7bfb32013-03-01 02:03:51 +0000783}
784
785std::pair<MipsInstrInfo::BranchType, MachineInstr *>
786Filler::getBranch(MachineBasicBlock &MBB, const MachineBasicBlock &Dst) const {
Eric Christopher6b6db772015-02-02 23:03:43 +0000787 const MipsInstrInfo *TII =
788 MBB.getParent()->getSubtarget<MipsSubtarget>().getInstrInfo();
Craig Topper062a2ba2014-04-25 05:30:21 +0000789 MachineBasicBlock *TrueBB = nullptr, *FalseBB = nullptr;
Akira Hatanaka8f7bfb32013-03-01 02:03:51 +0000790 SmallVector<MachineInstr*, 2> BranchInstrs;
791 SmallVector<MachineOperand, 2> Cond;
792
793 MipsInstrInfo::BranchType R =
794 TII->AnalyzeBranch(MBB, TrueBB, FalseBB, Cond, false, BranchInstrs);
795
796 if ((R == MipsInstrInfo::BT_None) || (R == MipsInstrInfo::BT_NoBranch))
Craig Topper062a2ba2014-04-25 05:30:21 +0000797 return std::make_pair(R, nullptr);
Akira Hatanaka8f7bfb32013-03-01 02:03:51 +0000798
799 if (R != MipsInstrInfo::BT_CondUncond) {
800 if (!hasUnoccupiedSlot(BranchInstrs[0]))
Craig Topper062a2ba2014-04-25 05:30:21 +0000801 return std::make_pair(MipsInstrInfo::BT_None, nullptr);
Akira Hatanaka8f7bfb32013-03-01 02:03:51 +0000802
803 assert(((R != MipsInstrInfo::BT_Uncond) || (TrueBB == &Dst)));
804
805 return std::make_pair(R, BranchInstrs[0]);
806 }
807
808 assert((TrueBB == &Dst) || (FalseBB == &Dst));
809
810 // Examine the conditional branch. See if its slot is occupied.
811 if (hasUnoccupiedSlot(BranchInstrs[0]))
812 return std::make_pair(MipsInstrInfo::BT_Cond, BranchInstrs[0]);
813
814 // If that fails, try the unconditional branch.
815 if (hasUnoccupiedSlot(BranchInstrs[1]) && (FalseBB == &Dst))
816 return std::make_pair(MipsInstrInfo::BT_Uncond, BranchInstrs[1]);
817
Craig Topper062a2ba2014-04-25 05:30:21 +0000818 return std::make_pair(MipsInstrInfo::BT_None, nullptr);
Akira Hatanaka8f7bfb32013-03-01 02:03:51 +0000819}
820
821bool Filler::examinePred(MachineBasicBlock &Pred, const MachineBasicBlock &Succ,
822 RegDefsUses &RegDU, bool &HasMultipleSuccs,
823 BB2BrMap &BrMap) const {
824 std::pair<MipsInstrInfo::BranchType, MachineInstr *> P =
825 getBranch(Pred, Succ);
826
827 // Return if either getBranch wasn't able to analyze the branches or there
828 // were no branches with unoccupied slots.
829 if (P.first == MipsInstrInfo::BT_None)
830 return false;
831
832 if ((P.first != MipsInstrInfo::BT_Uncond) &&
833 (P.first != MipsInstrInfo::BT_NoBranch)) {
834 HasMultipleSuccs = true;
835 RegDU.addLiveOut(Pred, Succ);
836 }
837
838 BrMap[&Pred] = P.second;
839 return true;
840}
841
Akira Hatanakaeb33ced2013-03-01 00:16:31 +0000842bool Filler::delayHasHazard(const MachineInstr &Candidate, RegDefsUses &RegDU,
Akira Hatanakae01ff9d2013-03-01 00:50:52 +0000843 InspectMemInstr &IM) const {
Akira Hatanaka06bd1382013-02-14 23:40:57 +0000844 bool HasHazard = (Candidate.isImplicitDef() || Candidate.isKill());
Akira Hatanakaf2619ee2011-09-29 23:52:13 +0000845
Akira Hatanakae01ff9d2013-03-01 00:50:52 +0000846 HasHazard |= IM.hasHazard(Candidate);
Akira Hatanaka979899e2013-02-26 01:30:05 +0000847 HasHazard |= RegDU.update(Candidate, 0, Candidate.getNumOperands());
Akira Hatanakaf2619ee2011-09-29 23:52:13 +0000848
Akira Hatanaka06bd1382013-02-14 23:40:57 +0000849 return HasHazard;
Akira Hatanakaf2619ee2011-09-29 23:52:13 +0000850}
851
Akira Hatanakadfd2f242013-02-14 23:11:24 +0000852bool Filler::terminateSearch(const MachineInstr &Candidate) const {
853 return (Candidate.isTerminator() || Candidate.isCall() ||
Rafael Espindolab1f25f12014-03-07 06:08:31 +0000854 Candidate.isPosition() || Candidate.isInlineAsm() ||
Akira Hatanakadfd2f242013-02-14 23:11:24 +0000855 Candidate.hasUnmodeledSideEffects());
856}