LLVM 24.0.0git
MipsDelaySlotFiller.cpp
Go to the documentation of this file.
1//===- MipsDelaySlotFiller.cpp - Mips Delay Slot Filler -------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Simple pass to fill delay slots with useful instructions.
10//
11//===----------------------------------------------------------------------===//
12
13#include "Mips.h"
14#include "MipsInstrInfo.h"
15#include "MipsSubtarget.h"
16#include "llvm/ADT/BitVector.h"
17#include "llvm/ADT/DenseMap.h"
19#include "llvm/ADT/STLExtras.h"
22#include "llvm/ADT/Statistic.h"
23#include "llvm/ADT/StringRef.h"
39#include "llvm/IR/Analysis.h"
40#include "llvm/MC/MCInstrDesc.h"
47#include <cassert>
48#include <iterator>
49#include <memory>
50#include <utility>
51
52using namespace llvm;
53
54#define DEBUG_TYPE "mips-delay-slot-filler"
55
56STATISTIC(FilledSlots, "Number of delay slots filled");
57STATISTIC(UsefulSlots, "Number of delay slots filled with instructions that"
58 " are not NOP.");
59STATISTIC(R5900ShortLoopNops, "Number of delay slots left as NOP for R5900 "
60 "short loop fix");
61
62namespace {
63
64 using Iter = MachineBasicBlock::iterator;
65 using ReverseIter = MachineBasicBlock::reverse_iterator;
67
68 // Holds information about one branch instruction
69 // This is used by the MIPS1 target to easily find all paths of a branch to
70 // then check the first instruction for possible load delay hazards
71 class BranchInformation {
72 private:
73 // The pointer to the actual branch instruction
74 const MachineInstr *BranchInstr = nullptr;
75 // The pointer to the instruction after the branch (= the `else` case)
76 const MachineInstr *ElseBranchInstr = nullptr;
77
78 // Check if `Adr` is a pseudo instruction and if so, then treat it as non
79 // existing
80 static const MachineInstr *filterPseudoInstr(const MachineInstr *Adr) {
81 if (Adr && !Adr->isPseudo()) {
82 return Adr;
83 }
84 return nullptr;
85 }
86
87 public:
88 // Creates a new `BranchInformation` from the branch candidate `CurrentSlot`
89 // together with the end (`MBBEnd`) of the current MBB and the first
90 // instruction of the next MBB `NextMBBInstr`
91 BranchInformation(MachineInstrBundleIterator<MachineInstr> CurrentSlot,
92 MachineInstrBundleIterator<MachineInstr> MBBEnd,
93 const MachineInstr *NextMBBInstr)
94 : BranchInstr(
95 CurrentSlot->isBranch()
96 ? BranchInformation::filterPseudoInstr(&(*CurrentSlot))
97 : nullptr),
98 ElseBranchInstr(
99 (++CurrentSlot) == MBBEnd
100 ? BranchInformation::filterPseudoInstr(NextMBBInstr)
101 : BranchInformation::filterPseudoInstr(&(*CurrentSlot))) {}
102
103 // Checks if we have a branch
104 constexpr bool hasBranchInstr() const { return this->BranchInstr; }
105
106 // Checks if we have an else branch
107 constexpr bool hasBranchElseInstr() const { return this->ElseBranchInstr; }
108
109 // Checks if we have an indirect branch
110 constexpr bool isIndirectBranch() const {
111 if (this->BranchInstr) {
112 return this->BranchInstr->isIndirectBranch();
113 }
114 return false;
115 }
116
117 // Checks if we have an unconditional branch
118 constexpr bool isUnconditionalBranch() const {
119 if (this->BranchInstr) {
120 return this->BranchInstr->isUnconditionalBranch();
121 }
122 return false;
123 }
124
125 // Accesses the branch instruction
126 const MachineInstr *getBranchInstr() const { return this->BranchInstr; }
127
128 // Accesses the instruction after the branch
129 const MachineInstr *getBranchElseInstr() const {
130 return this->ElseBranchInstr;
131 }
132
133 // Gets the target of the branch
134 const MachineBasicBlock *getBranchTarget() const {
135 if (this->isIndirectBranch() || !this->hasBranchInstr()) {
136 // Indirect branch has no known target
137 return nullptr;
138 }
139
140 for (const MachineOperand &MO : this->BranchInstr->operands()) {
141 if (MO.isMBB()) {
142 return MO.getMBB();
143 }
144 }
145 return nullptr;
146 }
147 };
148
149 class RegDefsUses {
150 public:
151 RegDefsUses(const TargetRegisterInfo &TRI);
152
153 void init(const MachineInstr &MI);
154
155 /// This function sets all caller-saved registers in Defs.
156 void setCallerSaved(const MachineInstr &MI);
157
158 /// This function sets all unallocatable registers in Defs.
159 void setUnallocatableRegs(const MachineFunction &MF);
160
161 /// Set bits in Uses corresponding to MBB's live-out registers except for
162 /// the registers that are live-in to SuccBB.
163 void addLiveOut(const MachineBasicBlock &MBB,
164 const MachineBasicBlock &SuccBB);
165
166 bool update(const MachineInstr &MI, unsigned Begin, unsigned End);
167
168 private:
169 bool checkRegDefsUses(BitVector &NewDefs, BitVector &NewUses, unsigned Reg,
170 bool IsDef) const;
171
172 /// Returns true if Reg or its alias is in RegSet.
173 bool isRegInSet(const BitVector &RegSet, unsigned Reg) const;
174
175 const TargetRegisterInfo &TRI;
176 BitVector Defs, Uses;
177 };
178
179 /// Base class for inspecting loads and stores.
180 class InspectMemInstr {
181 public:
182 InspectMemInstr(bool ForbidMemInstr_) : ForbidMemInstr(ForbidMemInstr_) {}
183 virtual ~InspectMemInstr() = default;
184
185 /// Return true if MI cannot be moved to delay slot.
186 bool hasHazard(const MachineInstr &MI);
187
188 protected:
189 /// Flags indicating whether loads or stores have been seen.
190 bool OrigSeenLoad = false;
191 bool OrigSeenStore = false;
192 bool SeenLoad = false;
193 bool SeenStore = false;
194
195 /// Memory instructions are not allowed to move to delay slot if this flag
196 /// is true.
197 bool ForbidMemInstr;
198
199 private:
200 virtual bool hasHazard_(const MachineInstr &MI) = 0;
201 };
202
203 /// This subclass rejects any memory instructions.
204 class NoMemInstr : public InspectMemInstr {
205 public:
206 NoMemInstr() : InspectMemInstr(true) {}
207
208 private:
209 bool hasHazard_(const MachineInstr &MI) override { return true; }
210 };
211
212 /// This subclass accepts loads from stacks and constant loads.
213 class LoadFromStackOrConst : public InspectMemInstr {
214 public:
215 LoadFromStackOrConst() : InspectMemInstr(false) {}
216
217 private:
218 bool hasHazard_(const MachineInstr &MI) override;
219 };
220
221 /// This subclass uses memory dependence information to determine whether a
222 /// memory instruction can be moved to a delay slot.
223 class MemDefsUses : public InspectMemInstr {
224 public:
225 explicit MemDefsUses(const MachineFrameInfo *MFI);
226
227 private:
228 using ValueType = PointerUnion<const Value *, const PseudoSourceValue *>;
229
230 bool hasHazard_(const MachineInstr &MI) override;
231
232 /// Update Defs and Uses. Return true if there exist dependences that
233 /// disqualify the delay slot candidate between V and values in Uses and
234 /// Defs.
235 bool updateDefsUses(ValueType V, bool MayStore);
236
237 /// Get the list of underlying objects of MI's memory operand.
238 bool getUnderlyingObjects(const MachineInstr &MI,
239 SmallVectorImpl<ValueType> &Objects) const;
240
241 const MachineFrameInfo *MFI;
242 SmallPtrSet<ValueType, 4> Uses, Defs;
243
244 /// Flags indicating whether loads or stores with no underlying objects have
245 /// been seen.
246 bool SeenNoObjLoad = false;
247 bool SeenNoObjStore = false;
248 };
249
250 class MipsDelaySlotFillerLegacy : public MachineFunctionPass {
251 public:
252 MipsDelaySlotFillerLegacy() : MachineFunctionPass(ID) {}
253
254 StringRef getPassName() const override { return "Mips Delay Slot Filler"; }
255
256 bool runOnMachineFunction(MachineFunction &F) override;
257
258 MachineFunctionProperties getRequiredProperties() const override {
259 return MachineFunctionProperties().setNoVRegs();
260 }
261
262 void getAnalysisUsage(AnalysisUsage &AU) const override {
263 AU.addRequired<MachineBranchProbabilityInfoWrapperPass>();
264 AU.setPreservesCFG();
266 }
267
268 static char ID;
269 };
270
271} // end anonymous namespace
272
273char MipsDelaySlotFillerLegacy::ID = 0;
274
275static bool hasUnoccupiedSlot(const MachineInstr *MI) {
276 return MI->hasDelaySlot() && !MI->isBundledWithSucc();
277}
278
279/// Check if a branch is a short backward loop that triggers the R5900 erratum.
280/// Quote from binutils-gdb/gas/config/tc-mips.c:
281///
282/// On the R5900 short loops need to be fixed by inserting a NOP in the
283/// branch delay slot.
284///
285/// The short loop bug under certain conditions causes loops to execute
286/// only once or twice. We must ensure that the assembler never
287/// generates loops that satisfy all of the following conditions:
288///
289/// - a loop consists of less than or equal to six instructions
290/// (including the branch delay slot);
291/// - a loop contains only one conditional branch instruction at the end
292/// of the loop;
293/// - a loop does not contain any other branch or jump instructions;
294/// - a branch delay slot of the loop is not NOP (EE 2.9 or later).
295///
296/// We need to do this because of a hardware bug in the R5900 chip.
298 const MachineBasicBlock &MBB) {
299 // Must be a conditional branch (not jump or indirect branch)
300 if (!MI->isBranch() || MI->isIndirectBranch())
301 return false;
302
303 // Check if this is a conditional branch by looking for an MBB operand
304 const MachineBasicBlock *TargetMBB = nullptr;
305 for (const MachineOperand &MO : MI->operands()) {
306 if (MO.isMBB()) {
307 TargetMBB = MO.getMBB();
308 break;
309 }
310 }
311
312 // Must have a target and must target the same basic block (backward branch)
313 if (!TargetMBB || TargetMBB != &MBB)
314 return false;
315
316 // Count instructions from the beginning of the block to the branch
317 // A short loop is 6 instructions or fewer (including branch + delay slot)
318 // The delay slot adds 1 more, so we check if instructions before branch <= 5
319 unsigned InstrCount = 0;
320 bool HasOtherBranch = false;
321
322 for (const MachineInstr &Instr : MBB) {
323 if (&Instr == MI)
324 break;
325
326 // Skip debug and pseudo instructions
327 if (Instr.isDebugInstr() || Instr.isTransient())
328 continue;
329
330 ++InstrCount;
331
332 // If there's another branch in the loop, the erratum doesn't apply
333 if (Instr.isBranch() || Instr.isCall()) {
334 HasOtherBranch = true;
335 break;
336 }
337 }
338
339 // If there's another branch/call in the loop, erratum doesn't apply
340 if (HasOtherBranch)
341 return false;
342
343 // Add 1 for the branch itself, +1 for delay slot = InstrCount + 2
344 // Erratum triggers when total <= 6, so InstrCount + 2 <= 6 => InstrCount <= 4
345 // But we're conservative: if InstrCount <= 5 (total <= 7), skip filling
346 // to match the exact condition from r5900check: offset -5 to -1 (2-6 instrs)
347 return InstrCount <= 5;
348}
349
350INITIALIZE_PASS(MipsDelaySlotFillerLegacy, DEBUG_TYPE,
351 "Fill delay slot for MIPS", false, false)
352
353/// This function inserts clones of Filler into predecessor blocks.
354static void insertDelayFiller(Iter Filler, const BB2BrMap &BrMap) {
355 MachineFunction *MF = Filler->getParent()->getParent();
356
357 for (const auto &I : BrMap) {
358 if (I.second) {
359 MIBundleBuilder(I.second).append(MF->CloneMachineInstr(&*Filler));
360 ++UsefulSlots;
361 } else {
362 I.first->push_back(MF->CloneMachineInstr(&*Filler));
363 }
364 }
365}
366
367/// This function adds registers Filler defines to MBB's live-in register list.
368static void addLiveInRegs(Iter Filler, MachineBasicBlock &MBB) {
369 for (const MachineOperand &MO : Filler->operands()) {
370 unsigned R;
371
372 if (!MO.isReg() || !MO.isDef() || !(R = MO.getReg()))
373 continue;
374
375#ifndef NDEBUG
376 const MachineFunction &MF = *MBB.getParent();
378 "Shouldn't move an instruction with unallocatable registers across "
379 "basic block boundaries.");
380#endif
381
382 if (!MBB.isLiveIn(R))
383 MBB.addLiveIn(R);
384 }
385}
386
387RegDefsUses::RegDefsUses(const TargetRegisterInfo &TRI)
388 : TRI(TRI), Defs(TRI.getNumRegs(), false), Uses(TRI.getNumRegs(), false) {}
389
390void RegDefsUses::init(const MachineInstr &MI) {
391 // Add all register operands which are explicit and non-variadic.
392 update(MI, 0, MI.getDesc().getNumOperands());
393
394 // If MI is a call, add RA to Defs to prevent users of RA from going into
395 // delay slot.
396 if (MI.isCall())
397 Defs.set(Mips::RA);
398
399 // Add all implicit register operands of branch instructions except
400 // register AT.
401 if (MI.isBranch()) {
402 update(MI, MI.getDesc().getNumOperands(), MI.getNumOperands());
403 Defs.reset(Mips::R1);
404 }
405}
406
407void RegDefsUses::setCallerSaved(const MachineInstr &MI) {
408 assert(MI.isCall());
409
410 // Add RA/RA_64 to Defs to prevent users of RA/RA_64 from going into
411 // the delay slot. The reason is that RA/RA_64 must not be changed
412 // in the delay slot so that the callee can return to the caller.
413 if (MI.definesRegister(Mips::RA, /*TRI=*/nullptr) ||
414 MI.definesRegister(Mips::RA_64, /*TRI=*/nullptr)) {
415 Defs.set(Mips::RA);
416 Defs.set(Mips::RA_64);
417 }
418
419 // If MI is a call, add all caller-saved registers to Defs.
420 BitVector CallerSavedRegs(TRI.getNumRegs(), true);
421
422 CallerSavedRegs.reset(Mips::R0);
423 CallerSavedRegs.reset(Mips::R0_64);
424
425 for (const MCPhysReg *R = TRI.getCalleeSavedRegs(MI.getParent()->getParent());
426 *R; ++R)
427 for (MCRegAliasIterator AI(*R, &TRI, true); AI.isValid(); ++AI)
428 CallerSavedRegs.reset(*AI);
429
430 Defs |= CallerSavedRegs;
431}
432
433void RegDefsUses::setUnallocatableRegs(const MachineFunction &MF) {
434 BitVector AllocSet = TRI.getAllocatableSet(MF);
435
436 for (unsigned R : AllocSet.set_bits())
437 for (MCRegAliasIterator AI(R, &TRI, false); AI.isValid(); ++AI)
438 AllocSet.set(*AI);
439
440 AllocSet.set(Mips::R0);
441 AllocSet.set(Mips::R0_64);
442
443 Defs |= AllocSet.flip();
444}
445
446void RegDefsUses::addLiveOut(const MachineBasicBlock &MBB,
447 const MachineBasicBlock &SuccBB) {
448 for (const MachineBasicBlock *S : MBB.successors())
449 if (S != &SuccBB)
450 for (const auto &LI : S->liveins())
451 Uses.set(LI.PhysReg.id());
452}
453
454bool RegDefsUses::update(const MachineInstr &MI, unsigned Begin, unsigned End) {
455 BitVector NewDefs(TRI.getNumRegs()), NewUses(TRI.getNumRegs());
456 bool HasHazard = false;
457
458 for (unsigned I = Begin; I != End; ++I) {
459 const MachineOperand &MO = MI.getOperand(I);
460
461 if (MO.isReg() && MO.getReg()) {
462 if (checkRegDefsUses(NewDefs, NewUses, MO.getReg(), MO.isDef())) {
463 LLVM_DEBUG(dbgs() << DEBUG_TYPE ": found register hazard for operand "
464 << I << ": ";
465 MO.dump());
466 HasHazard = true;
467 }
468 }
469 }
470
471 Defs |= NewDefs;
472 Uses |= NewUses;
473
474 return HasHazard;
475}
476
477bool RegDefsUses::checkRegDefsUses(BitVector &NewDefs, BitVector &NewUses,
478 unsigned Reg, bool IsDef) const {
479 if (IsDef) {
480 NewDefs.set(Reg);
481 // check whether Reg has already been defined or used.
482 return (isRegInSet(Defs, Reg) || isRegInSet(Uses, Reg));
483 }
484
485 NewUses.set(Reg);
486 // check whether Reg has already been defined.
487 return isRegInSet(Defs, Reg);
488}
489
490bool RegDefsUses::isRegInSet(const BitVector &RegSet, unsigned Reg) const {
491 // Check Reg and all aliased Registers.
492 for (MCRegAliasIterator AI(Reg, &TRI, true); AI.isValid(); ++AI)
493 if (RegSet.test(*AI))
494 return true;
495 return false;
496}
497
498bool InspectMemInstr::hasHazard(const MachineInstr &MI) {
499 if (!MI.mayStore() && !MI.mayLoad())
500 return false;
501
502 if (ForbidMemInstr)
503 return true;
504
505 OrigSeenLoad = SeenLoad;
506 OrigSeenStore = SeenStore;
507 SeenLoad |= MI.mayLoad();
508 SeenStore |= MI.mayStore();
509
510 // If MI is an ordered or volatile memory reference, disallow moving
511 // subsequent loads and stores to delay slot.
512 if (MI.hasOrderedMemoryRef() && (OrigSeenLoad || OrigSeenStore)) {
513 ForbidMemInstr = true;
514 return true;
515 }
516
517 return hasHazard_(MI);
518}
519
520bool LoadFromStackOrConst::hasHazard_(const MachineInstr &MI) {
521 if (MI.mayStore())
522 return true;
523
524 if (!MI.hasOneMemOperand() || !(*MI.memoperands_begin())->getPseudoValue())
525 return true;
526
527 if (const PseudoSourceValue *PSV =
528 (*MI.memoperands_begin())->getPseudoValue()) {
530 return false;
531 return !PSV->isConstant(nullptr) && !PSV->isStack();
532 }
533
534 return true;
535}
536
537MemDefsUses::MemDefsUses(const MachineFrameInfo *MFI_)
538 : InspectMemInstr(false), MFI(MFI_) {}
539
540bool MemDefsUses::hasHazard_(const MachineInstr &MI) {
541 bool HasHazard = false;
542
543 // Check underlying object list.
544 SmallVector<ValueType, 4> Objs;
545 if (getUnderlyingObjects(MI, Objs)) {
546 for (ValueType VT : Objs)
547 HasHazard |= updateDefsUses(VT, MI.mayStore());
548 return HasHazard;
549 }
550
551 // No underlying objects found.
552 HasHazard = MI.mayStore() && (OrigSeenLoad || OrigSeenStore);
553 HasHazard |= MI.mayLoad() || OrigSeenStore;
554
555 SeenNoObjLoad |= MI.mayLoad();
556 SeenNoObjStore |= MI.mayStore();
557
558 return HasHazard;
559}
560
561bool MemDefsUses::updateDefsUses(ValueType V, bool MayStore) {
562 if (MayStore)
563 return !Defs.insert(V).second || Uses.count(V) || SeenNoObjStore ||
564 SeenNoObjLoad;
565
566 Uses.insert(V);
567 return Defs.count(V) || SeenNoObjStore;
568}
569
570bool MemDefsUses::
571getUnderlyingObjects(const MachineInstr &MI,
572 SmallVectorImpl<ValueType> &Objects) const {
573 if (!MI.hasOneMemOperand())
574 return false;
575
576 auto & MMO = **MI.memoperands_begin();
577
578 if (const PseudoSourceValue *PSV = MMO.getPseudoValue()) {
579 if (!PSV->isAliased(MFI))
580 return false;
581 Objects.push_back(PSV);
582 return true;
583 }
584
585 if (const Value *V = MMO.getValue()) {
588
589 for (const Value *UValue : Objs) {
590 if (!isIdentifiedObject(V))
591 return false;
592
593 Objects.push_back(UValue);
594 }
595 return true;
596 }
597
598 return false;
599}
600
601// Replace Branch with the compact branch instruction.
603 const DebugLoc &DL) {
604 const MipsSubtarget &STI = MBB.getParent()->getSubtarget<MipsSubtarget>();
605 const MipsInstrInfo *TII = STI.getInstrInfo();
606
607 unsigned NewOpcode = TII->getEquivalentCompactForm(Branch);
608 Branch = TII->genInstrWithNewOpc(NewOpcode, Branch);
609
610 auto *ToErase = cast<MachineInstr>(&*std::next(Branch));
611 // Update call info for the Branch.
612 if (ToErase->shouldUpdateAdditionalCallInfo())
613 ToErase->getMF()->moveAdditionalCallInfo(ToErase,
614 cast<MachineInstr>(&*Branch));
615 ToErase->eraseFromParent();
616 return Branch;
617}
618
619// For given opcode returns opcode of corresponding instruction with short
620// delay slot.
621// For the pseudo TAILCALL*_MM instructions return the short delay slot
622// form. Unfortunately, TAILCALL<->b16 is denied as b16 has a limited range
623// that is too short to make use of for tail calls.
624static int getEquivalentCallShort(int Opcode) {
625 switch (Opcode) {
626 case Mips::BGEZAL:
627 return Mips::BGEZALS_MM;
628 case Mips::BLTZAL:
629 return Mips::BLTZALS_MM;
630 case Mips::JAL:
631 case Mips::JAL_MM:
632 return Mips::JALS_MM;
633 case Mips::JALR:
634 return Mips::JALRS_MM;
635 case Mips::JALR16_MM:
636 return Mips::JALRS16_MM;
637 case Mips::TAILCALL_MM:
638 llvm_unreachable("Attempting to shorten the TAILCALL_MM pseudo!");
639 case Mips::TAILCALLREG:
640 return Mips::JR16_MM;
641 default:
642 llvm_unreachable("Unexpected call instruction for microMIPS.");
643 }
644}
645
646static bool terminateSearch(const MachineInstr &Candidate) {
647 return (Candidate.isTerminator() || Candidate.isCall() ||
648 Candidate.isPosition() || Candidate.isInlineAsm() ||
649 Candidate.hasUnmodeledSideEffects());
650}
651
652/// Returns true if putting the candidate in the delay slot could let the
653/// branch target, or the instruction after the slot, read its result too
654/// early, or if those cannot be determined.
656 const BranchInformation &BranchInfo, const MachineInstr &Candidate,
657 function_ref<bool(const MachineInstr &, const MachineInstr &)> IsSafe) {
658 // With no branch, or a branch whose target we cannot see, we do not know
659 // which instruction executes next. Assume the worst.
660 if (!BranchInfo.hasBranchInstr() || BranchInfo.isIndirectBranch())
661 return true;
662
663 // Look at the first real instruction of the target. Skipping debug
664 // instructions keeps the decision the same with and without -g.
665 const MachineBasicBlock *TargetMBB = BranchInfo.getBranchTarget();
666 if (!TargetMBB)
667 return true;
670 if (TargetMI == TargetMBB->instr_end())
671 return true;
672
673 bool Exposed = !IsSafe(*TargetMI, Candidate);
674
675 // A conditional branch also falls through, so the instruction after the
676 // delay slot can be the one that reads the result.
677 if (!BranchInfo.isUnconditionalBranch()) {
678 if (!BranchInfo.hasBranchElseInstr())
679 return true;
680 Exposed |= !IsSafe(*BranchInfo.getBranchElseInstr(), Candidate);
681 }
682
683 return Exposed;
684}
685
686/// This function checks if it is valid to move Candidate to the delay slot
687/// and returns true if it isn't. It also updates memory and register
688/// dependence information.
689static bool delayHasHazard(const MipsSubtarget &STI,
690 const MachineInstr &Candidate,
691 const BranchInformation &BranchInfo,
692 RegDefsUses &RegDU, InspectMemInstr &IM) {
693 assert(!Candidate.isKill() &&
694 "KILL instructions should have been eliminated at this point.");
695
696 bool HasHazard = Candidate.isImplicitDef();
697
698 HasHazard |= IM.hasHazard(Candidate);
699 HasHazard |= RegDU.update(Candidate, 0, Candidate.getNumOperands());
700
701 if (!HasHazard) {
702 const MipsInstrInfo *TII = STI.getInstrInfo();
703
704 // MIPS-I has no load-use interlock: the instruction executed after a load
705 // must not read the loaded register.
706 if (STI.hasMips1() && !STI.hasMips2() && TII->HasLoadDelaySlot(Candidate))
707 return delayExposesHazard(
708 BranchInfo, Candidate,
709 [TII](const MachineInstr &InShadow, const MachineInstr &Cand) {
710 return TII->SafeInLoadDelaySlot(InShadow, Cand);
711 });
712
713 // MIPS-I through MIPS-III have the same problem when a value is moved
714 // out of the floating point unit:
715 if (!STI.hasMips32() && !STI.hasMips4() && TII->HasFPUDelaySlot(Candidate))
716 return delayExposesHazard(
717 BranchInfo, Candidate,
718 [TII](const MachineInstr &InShadow, const MachineInstr &Cand) {
719 return TII->SafeInFPUDelaySlot(InShadow, Cand);
720 });
721 }
722
723 return HasHazard;
724}
725
726/// This function searches range [Begin, End) for an instruction that can be
727/// moved to the delay slot. Returns true on success.
728template <typename IterTy>
729static bool searchRange(MachineBasicBlock &MBB, IterTy Begin, IterTy End,
730 const BranchInformation &BranchInfo, RegDefsUses &RegDU,
731 InspectMemInstr &IM, Iter Slot, IterTy &Filler) {
732 for (IterTy I = Begin; I != End;) {
733 IterTy CurrI = I;
734 ++I;
735 LLVM_DEBUG(dbgs() << DEBUG_TYPE ": checking instruction: "; CurrI->dump());
736
737 if (terminateSearch(*CurrI)) {
738 LLVM_DEBUG(dbgs() << DEBUG_TYPE ": should terminate search: ";
739 CurrI->dump());
740 break;
741 }
742 // Skip debug and pseudo instructions.
743 // Instruction TargetOpcode::JUMP_TABLE_DEBUG_INFO is only used to note
744 // jump table debug info.
745 if (CurrI->isDebugInstr() || CurrI->isJumpTableDebugInfo() ||
746 CurrI->isMetaInstruction()) {
747 LLVM_DEBUG(dbgs() << DEBUG_TYPE ": ignoring debug instruction: ";
748 CurrI->dump());
749 continue;
750 }
751
752 if (CurrI->isBundle()) {
753 LLVM_DEBUG(dbgs() << DEBUG_TYPE ": ignoring BUNDLE instruction: ";
754 CurrI->dump());
755 // However, we still need to update the register def-use information.
756 RegDU.update(*CurrI, 0, CurrI->getNumOperands());
757 continue;
758 }
759
760 assert((!CurrI->isCall() && !CurrI->isReturn() && !CurrI->isBranch()) &&
761 "Cannot put calls, returns or branches in delay slot.");
762
763 if (CurrI->isKill()) {
764 CurrI->eraseFromParent();
765 continue;
766 }
767
768 const MipsSubtarget &STI = MBB.getParent()->getSubtarget<MipsSubtarget>();
769 if (delayHasHazard(STI, *CurrI, BranchInfo, RegDU, IM))
770 continue;
771
772 bool InMicroMipsMode = STI.inMicroMipsMode();
773 const MipsInstrInfo *TII = STI.getInstrInfo();
774 unsigned Opcode = (*Slot).getOpcode();
775
776 // In mips1-4, should not put mflo into the delay slot for the return.
777 if ((IsMFLOMFHI(CurrI->getOpcode())) &&
778 (!STI.hasMips32() && !STI.hasMips5()))
779 continue;
780
781 // This is complicated by the tail call optimization. For non-PIC code
782 // there is only a 32bit sized unconditional branch which can be assumed
783 // to be able to reach the target. b16 only has a range of +/- 1 KB.
784 // It's entirely possible that the target function is reachable with b16
785 // but we don't have enough information to make that decision.
786 if (InMicroMipsMode && TII->getInstSizeInBytes(*CurrI) == 2 &&
787 (Opcode == Mips::JR || Opcode == Mips::PseudoIndirectBranch ||
788 Opcode == Mips::PseudoIndirectBranch_MM ||
789 Opcode == Mips::PseudoReturn || Opcode == Mips::TAILCALL))
790 continue;
791 // Instructions LWP/SWP and MOVEP should not be in a delay slot as that
792 // results in unpredictable behaviour
793 if (InMicroMipsMode && (Opcode == Mips::LWP_MM || Opcode == Mips::SWP_MM ||
794 Opcode == Mips::MOVEP_MM))
795 continue;
796
797 Filler = CurrI;
798 LLVM_DEBUG(dbgs() << DEBUG_TYPE ": found instruction for delay slot: ";
799 CurrI->dump());
800
801 return true;
802 }
803
804 return false;
805}
806
807/// This function searches in the backward direction for an instruction that
808/// can be moved to the delay slot. Returns true on success.
810 const BranchInformation &BranchInfo) {
811 const MipsOptions &CLOpts =
812 MBB.getParent()->getSubtarget<MipsSubtarget>().getCLOpts();
813 if (CLOpts.disable_mips_df_backward_search)
814 return false;
815
816 auto *Fn = MBB.getParent();
817 RegDefsUses RegDU(*Fn->getSubtarget().getRegisterInfo());
818 MemDefsUses MemDU(&Fn->getFrameInfo());
819 ReverseIter Filler;
820
821 RegDU.init(Slot);
822
823 MachineBasicBlock::iterator SlotI = Slot;
824 if (!searchRange(MBB, ++SlotI.getReverse(), MBB.rend(), BranchInfo, RegDU,
825 MemDU, Slot, Filler)) {
826 LLVM_DEBUG(dbgs() << DEBUG_TYPE ": could not find instruction for delay "
827 "slot using backwards search.\n");
828 return false;
829 }
830
831 MBB.splice(std::next(SlotI), &MBB, Filler.getReverse());
832 MIBundleBuilder(MBB, SlotI, std::next(SlotI, 2));
833 ++UsefulSlots;
834 return true;
835}
836
837/// This function searches MBB in the forward direction for an instruction
838/// that can be moved to the delay slot. Returns true on success.
839static bool searchForward(MachineBasicBlock &MBB, Iter Slot,
840 const BranchInformation &BranchInfo) {
841 const MipsOptions &CLOpts =
842 MBB.getParent()->getSubtarget<MipsSubtarget>().getCLOpts();
843 // Can handle only calls.
844 if (CLOpts.disable_mips_df_forward_search || !Slot->isCall())
845 return false;
846
847 RegDefsUses RegDU(*MBB.getParent()->getSubtarget().getRegisterInfo());
848 NoMemInstr NM;
849 Iter Filler;
850
851 RegDU.setCallerSaved(*Slot);
852
853 if (!searchRange(MBB, std::next(Slot), MBB.end(), BranchInfo, RegDU, NM, Slot,
854 Filler)) {
855 LLVM_DEBUG(dbgs() << DEBUG_TYPE ": could not find instruction for delay "
856 "slot using forwards search.\n");
857 return false;
858 }
859
860 MBB.splice(std::next(Slot), &MBB, Filler);
861 MIBundleBuilder(MBB, Slot, std::next(Slot, 2));
862 ++UsefulSlots;
863 return true;
864}
865
866/// Pick a successor block of MBB. Return NULL if MBB doesn't have a
867/// successor block that is not a landing pad.
868static MachineBasicBlock *
871 if (B.succ_empty())
872 return nullptr;
873
874 // Select the successor with the larget edge weight.
875 MachineBranchProbabilityInfo &Prob = GetMBPI();
877 *llvm::max_element(B.successors(), [&](const MachineBasicBlock *Dst0,
878 const MachineBasicBlock *Dst1) {
879 return Prob.getEdgeProbability(&B, Dst0) <
880 Prob.getEdgeProbability(&B, Dst1);
881 });
882 return S->isEHPad() ? nullptr : S;
883}
884
885/// This function analyzes MBB and returns an instruction with an unoccupied
886/// slot that branches to Dst.
887static std::pair<MipsInstrInfo::BranchType, MachineInstr *>
889 const MipsInstrInfo *TII =
890 MBB.getParent()->getSubtarget<MipsSubtarget>().getInstrInfo();
891 MachineBasicBlock *TrueBB = nullptr, *FalseBB = nullptr;
894
896 TII->analyzeBranch(MBB, TrueBB, FalseBB, Cond, false, BranchInstrs);
897
899 return std::make_pair(R, nullptr);
900
902 if (!hasUnoccupiedSlot(BranchInstrs[0]))
903 return std::make_pair(MipsInstrInfo::BT_None, nullptr);
904
905 assert(((R != MipsInstrInfo::BT_Uncond) || (TrueBB == &Dst)));
906
907 return std::make_pair(R, BranchInstrs[0]);
908 }
909
910 assert((TrueBB == &Dst) || (FalseBB == &Dst));
911
912 // Examine the conditional branch. See if its slot is occupied.
913 if (hasUnoccupiedSlot(BranchInstrs[0]))
914 return std::make_pair(MipsInstrInfo::BT_Cond, BranchInstrs[0]);
915
916 // If that fails, try the unconditional branch.
917 if (hasUnoccupiedSlot(BranchInstrs[1]) && (FalseBB == &Dst))
918 return std::make_pair(MipsInstrInfo::BT_Uncond, BranchInstrs[1]);
919
920 return std::make_pair(MipsInstrInfo::BT_None, nullptr);
921}
922
923/// Examine Pred and see if it is possible to insert an instruction into
924/// one of its branches delay slot or its end.
926 RegDefsUses &RegDU, bool &HasMultipleSuccs,
927 BB2BrMap &BrMap) {
928 std::pair<MipsInstrInfo::BranchType, MachineInstr *> P =
929 getBranch(Pred, Succ);
930
931 // Return if either getBranch wasn't able to analyze the branches or there
932 // were no branches with unoccupied slots.
933 if (P.first == MipsInstrInfo::BT_None)
934 return false;
935
936 if ((P.first != MipsInstrInfo::BT_Uncond) &&
937 (P.first != MipsInstrInfo::BT_NoBranch)) {
938 HasMultipleSuccs = true;
939 RegDU.addLiveOut(Pred, Succ);
940 }
941
942 BrMap[&Pred] = P.second;
943 return true;
944}
945
946/// This function searches one of MBB's successor blocks for an instruction
947/// that can be moved to the delay slot and inserts clones of the
948/// instruction into the successor's predecessor blocks.
949static bool
951 const BranchInformation &BranchInfo,
953 const MipsOptions &CLOpts =
954 MBB.getParent()->getSubtarget<MipsSubtarget>().getCLOpts();
955 if (CLOpts.disable_mips_df_succbb_search)
956 return false;
957
958 MachineBasicBlock *SuccBB = selectSuccBB(MBB, GetMBPI);
959
960 if (!SuccBB)
961 return false;
962
963 RegDefsUses RegDU(*MBB.getParent()->getSubtarget().getRegisterInfo());
964 bool HasMultipleSuccs = false;
965 BB2BrMap BrMap;
966 std::unique_ptr<InspectMemInstr> IM;
967 Iter Filler;
968 auto *Fn = MBB.getParent();
969
970 // Iterate over SuccBB's predecessor list.
971 for (MachineBasicBlock *Pred : SuccBB->predecessors())
972 if (!examinePred(*Pred, *SuccBB, RegDU, HasMultipleSuccs, BrMap))
973 return false;
974
975 // Do not allow moving instructions which have unallocatable register operands
976 // across basic block boundaries.
977 RegDU.setUnallocatableRegs(*Fn);
978
979 // Only allow moving loads from stack or constants if any of the SuccBB's
980 // predecessors have multiple successors.
981 if (HasMultipleSuccs) {
982 IM.reset(new LoadFromStackOrConst());
983 } else {
984 const MachineFrameInfo &MFI = Fn->getFrameInfo();
985 IM.reset(new MemDefsUses(&MFI));
986 }
987
988 if (!searchRange(MBB, SuccBB->begin(), SuccBB->end(), BranchInfo, RegDU, *IM,
989 Slot, Filler))
990 return false;
991
992 insertDelayFiller(Filler, BrMap);
993 addLiveInRegs(Filler, *SuccBB);
994 Filler->eraseFromParent();
995
996 return true;
997}
998
999/// runOnMachineBasicBlock - Fill in delay slots for the given basic block.
1000/// We assume there is only one delay slot per delayed instruction.
1001static bool
1004 const MipsOptions &CLOpts =
1005 MBB.getParent()->getSubtarget<MipsSubtarget>().getCLOpts();
1006 const TargetMachine &TM = MBB.getParent()->getTarget();
1007 bool Changed = false;
1008 const MipsSubtarget &STI = MBB.getParent()->getSubtarget<MipsSubtarget>();
1009 bool InMicroMipsMode = STI.inMicroMipsMode();
1010 const MipsInstrInfo *TII = STI.getInstrInfo();
1011
1012 for (Iter I = MBB.begin(); I != MBB.end(); ++I) {
1013 if (!hasUnoccupiedSlot(&*I))
1014 continue;
1015
1016 // R5900 short loop erratum fix: skip delay slot filling for short backward
1017 // loops to avoid triggering a hardware bug where short loops may exit
1018 // early. The fix can be controlled with -mfix-r5900 / -mno-fix-r5900.
1019 bool SkipForFixR5900 = false;
1020 if (STI.fixR5900() && isR5900ShortLoopBranch(&*I, MBB)) {
1021 LLVM_DEBUG(dbgs() << DEBUG_TYPE ": skipping delay slot fill for R5900 "
1022 "short loop branch.\n");
1023 ++R5900ShortLoopNops;
1024 SkipForFixR5900 = true;
1025 }
1026
1027 // Delay slot filling is disabled at -O0, in microMIPS32R6, or for R5900
1028 // short loop branches.
1029 if (!CLOpts.disable_mips_delay_filler &&
1031 !(InMicroMipsMode && STI.hasMips32r6()) && !SkipForFixR5900) {
1032
1033 bool Filled = false;
1034 const auto BranchInfo =
1035 BranchInformation(I, MBB.end(), FirstNextMBBInstr);
1036
1037 if (CLOpts.compact_branches != CompactBranchPolicy::Always ||
1038 !TII->getEquivalentCompactForm(I)) {
1039 if (searchBackward(MBB, *I, BranchInfo)) {
1040 LLVM_DEBUG(dbgs() << DEBUG_TYPE ": found instruction for delay slot"
1041 " in backwards search.\n");
1042 Filled = true;
1043 } else if (I->isTerminator()) {
1044 if (searchSuccBBs(MBB, I, BranchInfo, GetMBPI)) {
1045 Filled = true;
1046 LLVM_DEBUG(dbgs() << DEBUG_TYPE ": found instruction for delay slot"
1047 " in successor BB search.\n");
1048 }
1049 } else if (searchForward(MBB, I, BranchInfo)) {
1050 LLVM_DEBUG(dbgs() << DEBUG_TYPE ": found instruction for delay slot"
1051 " in forwards search.\n");
1052 Filled = true;
1053 }
1054 }
1055
1056 if (Filled) {
1057 // Get instruction with delay slot.
1058 MachineBasicBlock::instr_iterator DSI = I.getInstrIterator();
1059
1060 if (InMicroMipsMode && TII->getInstSizeInBytes(*std::next(DSI)) == 2 &&
1061 DSI->isCall()) {
1062 // If instruction in delay slot is 16b change opcode to
1063 // corresponding instruction with short delay slot.
1064
1065 // TODO: Implement an instruction mapping table of 16bit opcodes to
1066 // 32bit opcodes so that an instruction can be expanded. This would
1067 // save 16 bits as a TAILCALL_MM pseudo requires a fullsized nop.
1068 // TODO: Permit b16 when branching backwards to the same function
1069 // if it is in range.
1070 DSI->setDesc(TII->get(getEquivalentCallShort(DSI->getOpcode())));
1071 }
1072 ++FilledSlots;
1073 Changed = true;
1074 continue;
1075 }
1076 }
1077
1078 // For microMIPS if instruction is BEQ or BNE with one ZERO register, then
1079 // instead of adding NOP replace this instruction with the corresponding
1080 // compact branch instruction, i.e. BEQZC or BNEZC. Additionally
1081 // PseudoReturn and PseudoIndirectBranch are expanded to JR_MM, so they can
1082 // be replaced with JRC16_MM.
1083
1084 // For MIPSR6 attempt to produce the corresponding compact (no delay slot)
1085 // form of the CTI. For indirect jumps this will not require inserting a
1086 // NOP and for branches will hopefully avoid requiring a NOP.
1087 if ((InMicroMipsMode ||
1088 (STI.hasMips32r6() &&
1089 CLOpts.compact_branches != CompactBranchPolicy::Never)) &&
1090 TII->getEquivalentCompactForm(I)) {
1091 I = replaceWithCompactBranch(MBB, I, I->getDebugLoc());
1092 Changed = true;
1093 continue;
1094 }
1095
1096 // Bundle the NOP to the instruction with the delay slot.
1097 LLVM_DEBUG(dbgs() << DEBUG_TYPE << ": could not fill delay slot for ";
1098 I->dump());
1099 TII->insertNop(MBB, std::next(I), I->getDebugLoc());
1100 MIBundleBuilder(MBB, I, std::next(I, 2));
1101 ++FilledSlots;
1102 Changed = true;
1103 }
1104 return Changed;
1105}
1106
1107/// createMipsDelaySlotFillerPass - Returns a pass that fills in delay
1108/// slots in Mips MachineFunctions
1110 return new MipsDelaySlotFillerLegacy();
1111}
1112
1114 MachineFunction &MF,
1116 bool Changed = false;
1117 for (auto MBB = MF.begin(); MBB != MF.end();) {
1118 auto curMBB = MBB;
1119 MBB++;
1120
1122 *curMBB,
1123 // Skip debug instructions so -g does not change the decision.
1124 (MBB != MF.end() && MBB->getFirstNonDebugInstr() != MBB->end())
1125 ? &*MBB->getFirstNonDebugInstr()
1126 : nullptr,
1127 GetMBPI);
1128 }
1129
1130 // This pass invalidates liveness information when it reorders
1131 // instructions to fill delay slot. Without this, -verify-machineinstrs
1132 // will fail.
1133 if (Changed)
1135
1136 return Changed;
1137}
1138
1139bool MipsDelaySlotFillerLegacy::runOnMachineFunction(MachineFunction &MF) {
1141 MF, [&]() -> MachineBranchProbabilityInfo & {
1142 return getAnalysis<MachineBranchProbabilityInfoWrapperPass>().getMBPI();
1143 });
1144}
1145
1146PreservedAnalyses
SDValue Pred
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
aarch64 promote const
const AArch64InstrInfo & TII
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Function Alias Analysis false
static const Function * getParent(const Value *V)
basic Basic Alias true
This file implements the BitVector class.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static unsigned InstrCount
This file defines the DenseMap class.
static bool hasHazard(StateT InitialState, function_ref< HazardFnResult(StateT &, const MachineInstr &)> IsHazard, function_ref< void(StateT &, const MachineInstr &)> UpdateState, const MachineBasicBlock *InitialMBB, MachineBasicBlock::const_reverse_instr_iterator InitialI)
#define DEBUG_TYPE
#define _
IRTranslator LLVM IR MI
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
Register Reg
Register const TargetRegisterInfo * TRI
static bool hasUnoccupiedSlot(const MachineInstr *MI)
static bool runOnMachineBasicBlock(MachineBasicBlock &MBB, MachineInstr *FirstNextMBBInstr, function_ref< MachineBranchProbabilityInfo &()> GetMBPI)
runOnMachineBasicBlock - Fill in delay slots for the given basic block.
static void addLiveInRegs(Iter Filler, MachineBasicBlock &MBB)
This function adds registers Filler defines to MBB's live-in register list.
static bool isR5900ShortLoopBranch(const MachineInstr *MI, const MachineBasicBlock &MBB)
Check if a branch is a short backward loop that triggers the R5900 erratum.
static std::pair< MipsInstrInfo::BranchType, MachineInstr * > getBranch(MachineBasicBlock &MBB, const MachineBasicBlock &Dst)
This function analyzes MBB and returns an instruction with an unoccupied slot that branches to Dst.
const BB2BrMap & BrMap
static MachineBasicBlock * selectSuccBB(MachineBasicBlock &B, function_ref< MachineBranchProbabilityInfo &()> GetMBPI)
Pick a successor block of MBB.
static bool delayHasHazard(const MipsSubtarget &STI, const MachineInstr &Candidate, const BranchInformation &BranchInfo, RegDefsUses &RegDU, InspectMemInstr &IM)
This function checks if it is valid to move Candidate to the delay slot and returns true if it isn't.
static bool searchSuccBBs(MachineBasicBlock &MBB, Iter Slot, const BranchInformation &BranchInfo, function_ref< MachineBranchProbabilityInfo &()> GetMBPI)
This function searches one of MBB's successor blocks for an instruction that can be moved to the dela...
static bool runDelaySlotFillerOnFunction(MachineFunction &MF, function_ref< MachineBranchProbabilityInfo &()> GetMBPI)
static bool terminateSearch(const MachineInstr &Candidate)
static Iter replaceWithCompactBranch(MachineBasicBlock &MBB, Iter Branch, const DebugLoc &DL)
static bool searchRange(MachineBasicBlock &MBB, IterTy Begin, IterTy End, const BranchInformation &BranchInfo, RegDefsUses &RegDU, InspectMemInstr &IM, Iter Slot, IterTy &Filler)
This function searches range [Begin, End) for an instruction that can be moved to the delay slot.
static bool searchBackward(MachineBasicBlock &MBB, MachineInstr &Slot, const BranchInformation &BranchInfo)
This function searches in the backward direction for an instruction that can be moved to the delay sl...
static int getEquivalentCallShort(int Opcode)
static bool examinePred(MachineBasicBlock &Pred, const MachineBasicBlock &Succ, RegDefsUses &RegDU, bool &HasMultipleSuccs, BB2BrMap &BrMap)
Examine Pred and see if it is possible to insert an instruction into one of its branches delay slot o...
static bool delayExposesHazard(const BranchInformation &BranchInfo, const MachineInstr &Candidate, function_ref< bool(const MachineInstr &, const MachineInstr &)> IsSafe)
Returns true if putting the candidate in the delay slot could let the branch target,...
static bool searchForward(MachineBasicBlock &MBB, Iter Slot, const BranchInformation &BranchInfo)
This function searches MBB in the forward direction for an instruction that can be moved to the delay...
#define IsMFLOMFHI(instr)
Definition Mips.h:26
#define P(N)
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition PassSupport.h:56
This file defines the PointerUnion class, which is a discriminated union of pointer types.
static bool isBranch(unsigned Opcode)
SmallVector< MachineOperand, 4 > Cond
Remove Loads Into Fake Uses
This file contains some templates that are useful if you are working with the STL at all.
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Definition Statistic.h:171
#define LLVM_DEBUG(...)
Definition Debug.h:119
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
AnalysisUsage & addRequired()
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
Definition Pass.cpp:280
bool test(unsigned Idx) const
Returns true if bit Idx is set.
Definition BitVector.h:483
BitVector & reset()
Reset all bits in the bitvector.
Definition BitVector.h:410
BitVector & set()
Set all bits in the bitvector.
Definition BitVector.h:367
BitVector & flip()
Flip all bits in the bitvector.
Definition BitVector.h:451
iterator_range< const_set_bits_iterator > set_bits() const
Definition BitVector.h:160
Represents analyses that only rely on functions' control flow.
Definition Analysis.h:73
A debug info location.
Definition DebugLoc.h:127
FunctionPass class - This class is used to implement most global optimizations.
Definition Pass.h:312
An RAII based helper class to modify MachineFunctionProperties when running pass.
Helper class for constructing bundles of MachineInstrs.
MIBundleBuilder & append(MachineInstr *MI)
Insert MI into MBB by appending it to the instructions in the bundle.
bool isEHPad() const
Returns true if the block is a landing pad.
LLVM_ABI iterator getFirstNonDebugInstr(bool SkipPseudoOp=true)
Returns an iterator to the first non-debug instruction in the basic block, or end().
Instructions::iterator instr_iterator
MachineInstrBundleIterator< MachineInstr, true > reverse_iterator
Instructions::const_iterator const_instr_iterator
iterator_range< succ_iterator > successors()
iterator_range< pred_iterator > predecessors()
MachineInstrBundleIterator< MachineInstr > iterator
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
reverse_iterator getReverse() const
Get a reverse iterator to the same node.
Representation of each machine instruction.
bool isPosition() const
bool isTerminator(QueryType Type=AnyInBundle) const
Returns true if this instruction part of the terminator for a basic block.
bool isImplicitDef() const
bool isCall(QueryType Type=AnyInBundle) const
unsigned getNumOperands() const
Retuns the total number of operands.
bool isInlineAsm() const
LLVM_ABI bool hasUnmodeledSideEffects() const
Return true if this instruction has side effects that are not modeled by mayLoad / mayStore,...
bool isPseudo(QueryType Type=IgnoreBundle) const
Return true if this is a pseudo instruction that doesn't correspond to a real machine instruction.
bool isKill() const
MachineOperand class - Representation of each machine instruction operand.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
LLVM_ABI void dump() const
Register getReg() const
getReg - Returns the register number.
void invalidateLiveness()
invalidateLiveness - Indicates that register liveness is no longer being tracked accurately.
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
bool hasMips32r6() const
bool hasMips4() const
bool inMicroMipsMode() const
const MipsInstrInfo * getInstrInfo() const override
bool fixR5900() const
bool hasMips5() const
bool hasMips32() const
bool hasMips1() const
bool hasMips2() const
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
Definition Analysis.h:152
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Primary interface to the complete machine description for the target machine.
CodeGenOptLevel getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
BitVector getAllocatableSet(const MachineFunction &MF, const TargetRegisterClass *RC=nullptr) const
Returns a bitset indexed by register number indicating if a register is allocatable or not.
virtual const TargetRegisterInfo * getRegisterInfo() const =0
Return the target's register information.
An efficient, type-erasing, non-owning reference to a callable.
Pass manager infrastructure for declaring and invalidating analyses.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr MCPhysReg RA_64
constexpr MCPhysReg RA
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
Definition InstrProf.h:143
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:209
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
@ Always
'always' may in some circumstances may not be absolutely adhered to, there may not be a corresponding...
@ Never
The policy 'never' may in some circumstances or for some ISAs not be absolutely adhered to.
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
Definition MCRegister.h:21
auto max_element(R &&Range)
Provide wrappers to std::max_element which take ranges instead of having to pass begin/end explicitly...
Definition STLExtras.h:2104
FunctionPass * createMipsDelaySlotFillerLegacyPass()
createMipsDelaySlotFillerPass - Returns a pass that fills in delay slots in Mips MachineFunctions
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
PointerUnion< const Value *, const PseudoSourceValue * > ValueType
@ End
Run the machine verifier once, at the end of the pipeline.
Definition CodeGen.h:320
LLVM_ABI void getUnderlyingObjects(const Value *V, SmallVectorImpl< const Value * > &Objects, const LoopInfo *LI=nullptr, unsigned MaxLookup=MaxLookupSearchDepth)
This method is similar to getUnderlyingObject except that it can look through phi and select instruct...
LLVM_ABI bool isIdentifiedObject(const Value *V)
Return true if this pointer refers to a distinct and identifiable object.