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_MM ||
790 Opcode == Mips::TAILCALLREG_MM))
791 continue;
792 // Instructions LWP/SWP and MOVEP should not be in a delay slot as that
793 // results in unpredictable behaviour
794 if (InMicroMipsMode && (Opcode == Mips::LWP_MM || Opcode == Mips::SWP_MM ||
795 Opcode == Mips::MOVEP_MM))
796 continue;
797
798 Filler = CurrI;
799 LLVM_DEBUG(dbgs() << DEBUG_TYPE ": found instruction for delay slot: ";
800 CurrI->dump());
801
802 return true;
803 }
804
805 return false;
806}
807
808/// This function searches in the backward direction for an instruction that
809/// can be moved to the delay slot. Returns true on success.
811 const BranchInformation &BranchInfo) {
812 const MipsOptions &CLOpts =
813 MBB.getParent()->getSubtarget<MipsSubtarget>().getCLOpts();
814 if (CLOpts.disable_mips_df_backward_search)
815 return false;
816
817 auto *Fn = MBB.getParent();
818 RegDefsUses RegDU(*Fn->getSubtarget().getRegisterInfo());
819 MemDefsUses MemDU(&Fn->getFrameInfo());
820 ReverseIter Filler;
821
822 RegDU.init(Slot);
823
824 MachineBasicBlock::iterator SlotI = Slot;
825 if (!searchRange(MBB, ++SlotI.getReverse(), MBB.rend(), BranchInfo, RegDU,
826 MemDU, Slot, Filler)) {
827 LLVM_DEBUG(dbgs() << DEBUG_TYPE ": could not find instruction for delay "
828 "slot using backwards search.\n");
829 return false;
830 }
831
832 MBB.splice(std::next(SlotI), &MBB, Filler.getReverse());
833 MIBundleBuilder(MBB, SlotI, std::next(SlotI, 2));
834 ++UsefulSlots;
835 return true;
836}
837
838/// This function searches MBB in the forward direction for an instruction
839/// that can be moved to the delay slot. Returns true on success.
840static bool searchForward(MachineBasicBlock &MBB, Iter Slot,
841 const BranchInformation &BranchInfo) {
842 const MipsOptions &CLOpts =
843 MBB.getParent()->getSubtarget<MipsSubtarget>().getCLOpts();
844 // Can handle only calls.
845 if (CLOpts.disable_mips_df_forward_search || !Slot->isCall())
846 return false;
847
848 RegDefsUses RegDU(*MBB.getParent()->getSubtarget().getRegisterInfo());
849 NoMemInstr NM;
850 Iter Filler;
851
852 RegDU.setCallerSaved(*Slot);
853
854 if (!searchRange(MBB, std::next(Slot), MBB.end(), BranchInfo, RegDU, NM, Slot,
855 Filler)) {
856 LLVM_DEBUG(dbgs() << DEBUG_TYPE ": could not find instruction for delay "
857 "slot using forwards search.\n");
858 return false;
859 }
860
861 MBB.splice(std::next(Slot), &MBB, Filler);
862 MIBundleBuilder(MBB, Slot, std::next(Slot, 2));
863 ++UsefulSlots;
864 return true;
865}
866
867/// Pick a successor block of MBB. Return NULL if MBB doesn't have a
868/// successor block that is not a landing pad.
869static MachineBasicBlock *
872 if (B.succ_empty())
873 return nullptr;
874
875 // Select the successor with the larget edge weight.
876 MachineBranchProbabilityInfo &Prob = GetMBPI();
878 *llvm::max_element(B.successors(), [&](const MachineBasicBlock *Dst0,
879 const MachineBasicBlock *Dst1) {
880 return Prob.getEdgeProbability(&B, Dst0) <
881 Prob.getEdgeProbability(&B, Dst1);
882 });
883 return S->isEHPad() ? nullptr : S;
884}
885
886/// This function analyzes MBB and returns an instruction with an unoccupied
887/// slot that branches to Dst.
888static std::pair<MipsInstrInfo::BranchType, MachineInstr *>
890 const MipsInstrInfo *TII =
891 MBB.getParent()->getSubtarget<MipsSubtarget>().getInstrInfo();
892 MachineBasicBlock *TrueBB = nullptr, *FalseBB = nullptr;
895
897 TII->analyzeBranch(MBB, TrueBB, FalseBB, Cond, false, BranchInstrs);
898
900 return std::make_pair(R, nullptr);
901
903 if (!hasUnoccupiedSlot(BranchInstrs[0]))
904 return std::make_pair(MipsInstrInfo::BT_None, nullptr);
905
906 assert(((R != MipsInstrInfo::BT_Uncond) || (TrueBB == &Dst)));
907
908 return std::make_pair(R, BranchInstrs[0]);
909 }
910
911 assert((TrueBB == &Dst) || (FalseBB == &Dst));
912
913 // Examine the conditional branch. See if its slot is occupied.
914 if (hasUnoccupiedSlot(BranchInstrs[0]))
915 return std::make_pair(MipsInstrInfo::BT_Cond, BranchInstrs[0]);
916
917 // If that fails, try the unconditional branch.
918 if (hasUnoccupiedSlot(BranchInstrs[1]) && (FalseBB == &Dst))
919 return std::make_pair(MipsInstrInfo::BT_Uncond, BranchInstrs[1]);
920
921 return std::make_pair(MipsInstrInfo::BT_None, nullptr);
922}
923
924/// Examine Pred and see if it is possible to insert an instruction into
925/// one of its branches delay slot or its end.
927 RegDefsUses &RegDU, bool &HasMultipleSuccs,
928 BB2BrMap &BrMap) {
929 std::pair<MipsInstrInfo::BranchType, MachineInstr *> P =
930 getBranch(Pred, Succ);
931
932 // Return if either getBranch wasn't able to analyze the branches or there
933 // were no branches with unoccupied slots.
934 if (P.first == MipsInstrInfo::BT_None)
935 return false;
936
937 if ((P.first != MipsInstrInfo::BT_Uncond) &&
938 (P.first != MipsInstrInfo::BT_NoBranch)) {
939 HasMultipleSuccs = true;
940 RegDU.addLiveOut(Pred, Succ);
941 }
942
943 BrMap[&Pred] = P.second;
944 return true;
945}
946
947/// This function searches one of MBB's successor blocks for an instruction
948/// that can be moved to the delay slot and inserts clones of the
949/// instruction into the successor's predecessor blocks.
950static bool
952 const BranchInformation &BranchInfo,
954 const MipsOptions &CLOpts =
955 MBB.getParent()->getSubtarget<MipsSubtarget>().getCLOpts();
956 if (CLOpts.disable_mips_df_succbb_search)
957 return false;
958
959 MachineBasicBlock *SuccBB = selectSuccBB(MBB, GetMBPI);
960
961 if (!SuccBB)
962 return false;
963
964 RegDefsUses RegDU(*MBB.getParent()->getSubtarget().getRegisterInfo());
965 bool HasMultipleSuccs = false;
966 BB2BrMap BrMap;
967 std::unique_ptr<InspectMemInstr> IM;
968 Iter Filler;
969 auto *Fn = MBB.getParent();
970
971 // Iterate over SuccBB's predecessor list.
972 for (MachineBasicBlock *Pred : SuccBB->predecessors())
973 if (!examinePred(*Pred, *SuccBB, RegDU, HasMultipleSuccs, BrMap))
974 return false;
975
976 // Do not allow moving instructions which have unallocatable register operands
977 // across basic block boundaries.
978 RegDU.setUnallocatableRegs(*Fn);
979
980 // Only allow moving loads from stack or constants if any of the SuccBB's
981 // predecessors have multiple successors.
982 if (HasMultipleSuccs) {
983 IM.reset(new LoadFromStackOrConst());
984 } else {
985 const MachineFrameInfo &MFI = Fn->getFrameInfo();
986 IM.reset(new MemDefsUses(&MFI));
987 }
988
989 if (!searchRange(MBB, SuccBB->begin(), SuccBB->end(), BranchInfo, RegDU, *IM,
990 Slot, Filler))
991 return false;
992
993 insertDelayFiller(Filler, BrMap);
994 addLiveInRegs(Filler, *SuccBB);
995 Filler->eraseFromParent();
996
997 return true;
998}
999
1000/// runOnMachineBasicBlock - Fill in delay slots for the given basic block.
1001/// We assume there is only one delay slot per delayed instruction.
1002static bool
1005 const MipsOptions &CLOpts =
1006 MBB.getParent()->getSubtarget<MipsSubtarget>().getCLOpts();
1007 const TargetMachine &TM = MBB.getParent()->getTarget();
1008 bool Changed = false;
1009 const MipsSubtarget &STI = MBB.getParent()->getSubtarget<MipsSubtarget>();
1010 bool InMicroMipsMode = STI.inMicroMipsMode();
1011 const MipsInstrInfo *TII = STI.getInstrInfo();
1012
1013 for (Iter I = MBB.begin(); I != MBB.end(); ++I) {
1014 if (!hasUnoccupiedSlot(&*I))
1015 continue;
1016
1017 // R5900 short loop erratum fix: skip delay slot filling for short backward
1018 // loops to avoid triggering a hardware bug where short loops may exit
1019 // early. The fix can be controlled with -mfix-r5900 / -mno-fix-r5900.
1020 bool SkipForFixR5900 = false;
1021 if (STI.fixR5900() && isR5900ShortLoopBranch(&*I, MBB)) {
1022 LLVM_DEBUG(dbgs() << DEBUG_TYPE ": skipping delay slot fill for R5900 "
1023 "short loop branch.\n");
1024 ++R5900ShortLoopNops;
1025 SkipForFixR5900 = true;
1026 }
1027
1028 // Delay slot filling is disabled at -O0, in microMIPS32R6, or for R5900
1029 // short loop branches.
1030 if (!CLOpts.disable_mips_delay_filler &&
1032 !(InMicroMipsMode && STI.hasMips32r6()) && !SkipForFixR5900) {
1033
1034 bool Filled = false;
1035 const auto BranchInfo =
1036 BranchInformation(I, MBB.end(), FirstNextMBBInstr);
1037
1038 if (CLOpts.compact_branches != CompactBranchPolicy::Always ||
1039 !TII->getEquivalentCompactForm(I)) {
1040 if (searchBackward(MBB, *I, BranchInfo)) {
1041 LLVM_DEBUG(dbgs() << DEBUG_TYPE ": found instruction for delay slot"
1042 " in backwards search.\n");
1043 Filled = true;
1044 } else if (I->isTerminator()) {
1045 if (searchSuccBBs(MBB, I, BranchInfo, GetMBPI)) {
1046 Filled = true;
1047 LLVM_DEBUG(dbgs() << DEBUG_TYPE ": found instruction for delay slot"
1048 " in successor BB search.\n");
1049 }
1050 } else if (searchForward(MBB, I, BranchInfo)) {
1051 LLVM_DEBUG(dbgs() << DEBUG_TYPE ": found instruction for delay slot"
1052 " in forwards search.\n");
1053 Filled = true;
1054 }
1055 }
1056
1057 if (Filled) {
1058 // Get instruction with delay slot.
1059 MachineBasicBlock::instr_iterator DSI = I.getInstrIterator();
1060
1061 if (InMicroMipsMode && TII->getInstSizeInBytes(*std::next(DSI)) == 2 &&
1062 DSI->isCall()) {
1063 // If instruction in delay slot is 16b change opcode to
1064 // corresponding instruction with short delay slot.
1065
1066 // TODO: Implement an instruction mapping table of 16bit opcodes to
1067 // 32bit opcodes so that an instruction can be expanded. This would
1068 // save 16 bits as a TAILCALL_MM pseudo requires a fullsized nop.
1069 // TODO: Permit b16 when branching backwards to the same function
1070 // if it is in range.
1071 DSI->setDesc(TII->get(getEquivalentCallShort(DSI->getOpcode())));
1072 }
1073 ++FilledSlots;
1074 Changed = true;
1075 continue;
1076 }
1077 }
1078
1079 // For microMIPS if instruction is BEQ or BNE with one ZERO register, then
1080 // instead of adding NOP replace this instruction with the corresponding
1081 // compact branch instruction, i.e. BEQZC or BNEZC. Additionally
1082 // PseudoReturn and PseudoIndirectBranch are expanded to JR_MM, so they can
1083 // be replaced with JRC16_MM.
1084
1085 // For MIPSR6 attempt to produce the corresponding compact (no delay slot)
1086 // form of the CTI. For indirect jumps this will not require inserting a
1087 // NOP and for branches will hopefully avoid requiring a NOP.
1088 if ((InMicroMipsMode ||
1089 (STI.hasMips32r6() &&
1090 CLOpts.compact_branches != CompactBranchPolicy::Never)) &&
1091 TII->getEquivalentCompactForm(I)) {
1092 I = replaceWithCompactBranch(MBB, I, I->getDebugLoc());
1093 Changed = true;
1094 continue;
1095 }
1096
1097 // Bundle the NOP to the instruction with the delay slot.
1098 LLVM_DEBUG(dbgs() << DEBUG_TYPE << ": could not fill delay slot for ";
1099 I->dump());
1100 TII->insertNop(MBB, std::next(I), I->getDebugLoc());
1101 MIBundleBuilder(MBB, I, std::next(I, 2));
1102 ++FilledSlots;
1103 Changed = true;
1104 }
1105 return Changed;
1106}
1107
1108/// createMipsDelaySlotFillerPass - Returns a pass that fills in delay
1109/// slots in Mips MachineFunctions
1111 return new MipsDelaySlotFillerLegacy();
1112}
1113
1115 MachineFunction &MF,
1117 bool Changed = false;
1118 for (auto MBB = MF.begin(); MBB != MF.end();) {
1119 auto curMBB = MBB;
1120 MBB++;
1121
1123 *curMBB,
1124 // Skip debug instructions so -g does not change the decision.
1125 (MBB != MF.end() && MBB->getFirstNonDebugInstr() != MBB->end())
1126 ? &*MBB->getFirstNonDebugInstr()
1127 : nullptr,
1128 GetMBPI);
1129 }
1130
1131 // This pass invalidates liveness information when it reorders
1132 // instructions to fill delay slot. Without this, -verify-machineinstrs
1133 // will fail.
1134 if (Changed)
1136
1137 return Changed;
1138}
1139
1140bool MipsDelaySlotFillerLegacy::runOnMachineFunction(MachineFunction &MF) {
1142 MF, [&]() -> MachineBranchProbabilityInfo & {
1143 return getAnalysis<MachineBranchProbabilityInfoWrapperPass>().getMBPI();
1144 });
1145}
1146
1147PreservedAnalyses
SDValue Pred
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
aarch64 promote const
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
const HexagonInstrInfo * TII
#define _
IRTranslator LLVM IR MI
SmallVector< MachineOperand, 4 > Cond
#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)
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:170
#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:126
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:151
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.