31#define DEBUG_TYPE "si-pre-emit-peephole"
34 "Number of redundant mode register writes removed");
40struct ModeFieldState {
41 std::optional<int64_t>
Value;
42 std::optional<int64_t> ValueBeforePendingWrite;
45 bool isTracked()
const {
return PendingWrite ||
Value; }
48class SIPreEmitPeephole {
50 const SIInstrInfo *TII =
nullptr;
51 const SIRegisterInfo *TRI =
nullptr;
52 MachineLoopInfo *MLI =
nullptr;
54 std::optional<int64_t> matchVccMask(MachineInstr &
A,
Register &SReg,
56 bool optimizeVccBranch(MachineInstr &
MI)
const;
57 void updateMLIBeforeRemovingEdge(MachineBasicBlock *From,
58 MachineBasicBlock *To)
const;
59 bool optimizeSetGPR(MachineInstr &
First, MachineInstr &
MI)
const;
60 bool getBlockDestinations(MachineBasicBlock &SrcMBB,
61 MachineBasicBlock *&TrueMBB,
62 MachineBasicBlock *&FalseMBB,
63 SmallVectorImpl<MachineOperand> &
Cond);
64 bool mustRetainExeczBranch(
const MachineInstr &Branch,
65 const MachineBasicBlock &From,
66 const MachineBasicBlock &To)
const;
67 bool removeExeczBranch(MachineInstr &
MI, MachineBasicBlock &SrcMBB);
68 bool removeRedundantModeWrites(MachineBasicBlock &SrcMBB)
const;
71 void collectUnpackingCandidates(MachineInstr &BeginMI,
72 SetVector<MachineInstr *> &InstrsToUnpack,
73 uint16_t NumMFMACycles);
81 bool canUnpackingClobberRegister(
const MachineInstr &
MI);
85 void performF32Unpacking(MachineInstr &
I);
87 uint32_t mapToUnpackedOpcode(MachineInstr &
I);
91 MachineInstrBuilder createUnpackedMI(MachineInstr &
I, uint32_t UnpackedOpcode,
95 void addOperandAndMods(MachineInstrBuilder &NewMI,
unsigned SrcMods,
96 bool IsHiBits,
const MachineOperand &SrcMO);
106 SIPreEmitPeepholeLegacy() : MachineFunctionPass(ID) {}
108 void getAnalysisUsage(AnalysisUsage &AU)
const override {
115 auto *MLIWrapper = getAnalysisIfAvailable<MachineLoopInfoWrapperPass>();
116 MachineLoopInfo *MLI = MLIWrapper ? &MLIWrapper->getLI() :
nullptr;
117 return SIPreEmitPeephole().run(MF, MLI);
124 "SI peephole optimizations",
false,
false)
126char SIPreEmitPeepholeLegacy::ID = 0;
130void SIPreEmitPeephole::updateMLIBeforeRemovingEdge(
141 unsigned BackEdgeCount = 0;
143 if (Loop->contains(Pred))
147 if (BackEdgeCount > 1)
154 if (MLI->getLoopFor(BB) == Loop)
155 MLI->changeLoopFor(BB, ParentLoop);
160 MachineLoop *Child = Loop->removeChildLoop(std::prev(Loop->end()));
162 ParentLoop->addChildLoop(Child);
164 MLI->addTopLevelLoop(Child);
178std::optional<int64_t> SIPreEmitPeephole::matchVccMask(
MachineInstr &
A,
181 const GCNSubtarget &
ST =
A.getMF()->getSubtarget<GCNSubtarget>();
182 const bool IsWave32 =
ST.isWave32();
183 const unsigned ExecReg = IsWave32 ? AMDGPU::EXEC_LO : AMDGPU::EXEC;
184 const unsigned AndN2 = IsWave32 ? AMDGPU::S_ANDN2_B32 : AMDGPU::S_ANDN2_B64;
185 const unsigned Mov = IsWave32 ? AMDGPU::S_MOV_B32 : AMDGPU::S_MOV_B64;
187 const unsigned Opc =
A.getOpcode();
188 if (
Opc == Mov ||
Opc == AMDGPU::COPY) {
189 const MachineOperand &Src =
A.getOperand(1);
190 if (Src.isImm() && Src.getImm() == 0)
192 if (Src.isReg() && Src.getReg() == ExecReg)
197 MachineOperand &Op1 =
A.getOperand(1);
198 MachineOperand &Op2 =
A.getOperand(2);
200 Op2.
getReg() == ExecReg) {
201 TII->commuteInstruction(
A);
209 int64_t MaskValue = 0;
215 bool ReadsSreg =
false;
216 for (;
M !=
E; ++
M) {
217 if (
M->definesRegister(SReg,
TRI))
219 if (
M->modifiesRegister(SReg,
TRI))
221 ReadsSreg |=
M->readsRegister(SReg,
TRI);
226 if (!
M->isMoveImmediate() || !
M->getOperand(1).isImm() ||
227 (
M->getOperand(1).getImm() != -1 &&
M->getOperand(1).getImm() != 0))
229 MaskValue =
M->getOperand(1).getImm();
232 if (!ReadsSreg && Op2.
isKill()) {
233 A.getOperand(2).ChangeToImmediate(MaskValue);
234 M->eraseFromParent();
236 }
else if (Op2.
isImm()) {
243 assert(MaskValue == 0 || MaskValue == -1);
245 MaskValue = ~MaskValue;
249bool SIPreEmitPeephole::optimizeVccBranch(MachineInstr &
MI)
const {
259 const bool IsWave32 =
ST.isWave32();
260 const unsigned CondReg =
TRI->getVCC();
261 const unsigned ExecReg = IsWave32 ? AMDGPU::EXEC_LO : AMDGPU::EXEC;
262 const unsigned And = IsWave32 ? AMDGPU::S_AND_B32 : AMDGPU::S_AND_B64;
263 const unsigned AndN2 = IsWave32 ? AMDGPU::S_ANDN2_B32 : AMDGPU::S_ANDN2_B64;
264 const unsigned Mov = IsWave32 ? AMDGPU::S_MOV_B32 : AMDGPU::S_MOV_B64;
268 bool ReadsCond =
false;
269 unsigned Threshold = 5;
270 for (++
A;
A !=
E; ++
A) {
273 if (
A->modifiesRegister(ExecReg,
TRI))
275 if (
A->modifiesRegister(CondReg,
TRI)) {
276 unsigned Opc =
A->getOpcode();
277 if (!
A->definesRegister(CondReg,
TRI) ||
282 ReadsCond |=
A->readsRegister(CondReg,
TRI);
288 std::optional<int64_t> Match = matchVccMask(*
A, SReg,
Changed);
291 int64_t MaskValue = *Match;
293 const bool IsAnd =
A->getOpcode() ==
And ||
A->getOpcode() == AndN2;
295 (!IsAnd ||
A->registerDefIsDead(AMDGPU::SCC,
nullptr))) {
296 const bool KillsCond =
MI.killsRegister(CondReg,
TRI);
297 if (IsAnd && !KillsCond) {
299 if (MaskValue == 0) {
300 BuildMI(*
A->getParent(), *
A,
A->getDebugLoc(),
TII->get(Mov), CondReg)
303 BuildMI(*
A->getParent(), *
A,
A->getDebugLoc(),
TII->get(Mov), CondReg)
307 if (IsAnd || KillsCond)
308 A->eraseFromParent();
311 bool IsVCCZ =
MI.getOpcode() == AMDGPU::S_CBRANCH_VCCZ;
312 if (SReg == ExecReg) {
315 MI.eraseFromParent();
318 MI.setDesc(
TII->get(AMDGPU::S_BRANCH));
319 }
else if (IsVCCZ && MaskValue == 0) {
322 MachineBasicBlock *Parent =
MI.getParent();
323 SmallVector<MachineInstr *, 4>
ToRemove;
330 Found =
Term.isIdenticalTo(
MI);
333 assert(Found &&
"conditional branch is not terminator");
335 MachineOperand &Dst = BranchMI->getOperand(0);
336 assert(Dst.isMBB() &&
"destination is not basic block");
337 updateMLIBeforeRemovingEdge(Parent, Dst.getMBB());
339 BranchMI->eraseFromParent();
343 updateMLIBeforeRemovingEdge(Parent, Succ);
348 MI.setDesc(
TII->get(AMDGPU::S_BRANCH));
349 }
else if (!IsVCCZ && MaskValue == 0) {
351 MachineOperand &Dst =
MI.getOperand(0);
352 assert(Dst.isMBB() &&
"destination is not basic block");
354 updateMLIBeforeRemovingEdge(Parent, Dst.getMBB());
356 MI.eraseFromParent();
358 }
else if (MaskValue == -1) {
361 TII->get(IsVCCZ ? AMDGPU::S_CBRANCH_EXECZ : AMDGPU::S_CBRANCH_EXECNZ));
364 MI.removeOperand(
MI.findRegisterUseOperandIdx(CondReg,
TRI,
false ));
370bool SIPreEmitPeephole::optimizeSetGPR(MachineInstr &
First,
371 MachineInstr &
MI)
const {
375 MachineOperand *
Idx =
TII->getNamedOperand(
MI, AMDGPU::OpName::src0);
377 SmallVector<MachineInstr *, 4>
ToRemove;
385 E =
MI.getIterator();
387 if (
I->isBundle() ||
I->isDebugInstr())
389 switch (
I->getOpcode()) {
390 case AMDGPU::S_SET_GPR_IDX_MODE:
392 case AMDGPU::S_SET_GPR_IDX_OFF:
397 if (
I->modifiesRegister(AMDGPU::M0,
TRI))
399 if (IdxReg &&
I->modifiesRegister(IdxReg,
TRI))
402 return MO.isReg() && TRI->isVectorRegister(MRI, MO.getReg());
406 if (!IdxOn || !(
I->getOpcode() == AMDGPU::V_MOV_B32_indirect_write ||
407 I->getOpcode() == AMDGPU::V_MOV_B32_indirect_read))
413 MI.eraseFromBundle();
415 RI->eraseFromBundle();
419bool SIPreEmitPeephole::getBlockDestinations(
420 MachineBasicBlock &SrcMBB, MachineBasicBlock *&TrueMBB,
421 MachineBasicBlock *&FalseMBB, SmallVectorImpl<MachineOperand> &
Cond) {
432class BranchWeightCostModel {
433 const SIInstrInfo &
TII;
434 const TargetSchedModel &SchedModel;
435 BranchProbability BranchProb;
436 static constexpr uint64_t BranchNotTakenCost = 1;
441 BranchWeightCostModel(
const SIInstrInfo &
TII,
const MachineInstr &Branch,
442 const MachineBasicBlock &Succ)
443 :
TII(
TII), SchedModel(
TII.getSchedModel()) {
444 const MachineBasicBlock &Head = *
Branch.getParent();
451 BranchTakenCost = SchedModel.computeInstrLatency(&Branch);
455 if (
TII.isWaitcnt(
MI.getOpcode()))
458 ThenCyclesCost += SchedModel.computeInstrLatency(&
MI);
470 return (Denominator - Numerator) * ThenCyclesCost <=
471 ((Denominator - Numerator) * BranchTakenCost +
472 Numerator * BranchNotTakenCost);
476bool SIPreEmitPeephole::mustRetainExeczBranch(
477 const MachineInstr &Branch,
const MachineBasicBlock &From,
478 const MachineBasicBlock &To)
const {
480 BranchWeightCostModel CostModel{*
TII,
Branch, From};
485 const MachineBasicBlock &
MBB = *
MBBI;
487 for (
const MachineInstr &
MI :
MBB) {
491 if (
MI.isConditionalBranch())
494 if (
MI.isUnconditionalBranch() &&
498 if (
MI.isMetaInstruction())
501 if (
TII->hasUnwantedEffectsWhenEXECEmpty(
MI))
504 if (!CostModel.isProfitable(
MI))
514bool SIPreEmitPeephole::removeExeczBranch(MachineInstr &
MI,
515 MachineBasicBlock &SrcMBB) {
517 if (!
TII->getSchedModel().hasInstrSchedModel())
520 MachineBasicBlock *TrueMBB =
nullptr;
521 MachineBasicBlock *FalseMBB =
nullptr;
524 if (!getBlockDestinations(SrcMBB, TrueMBB, FalseMBB,
Cond))
532 if (mustRetainExeczBranch(
MI, *FalseMBB, *TrueMBB))
536 MI.eraseFromParent();
553bool SIPreEmitPeephole::removeRedundantModeWrites(
554 MachineBasicBlock &SrcMBB)
const {
556 ModeFieldState DenormMode;
557 ModeFieldState RoundMode;
560 if (
MI.isDebugInstr())
563 unsigned Opc =
MI.getOpcode();
564 if (
Opc == AMDGPU::S_DENORM_MODE ||
Opc == AMDGPU::S_ROUND_MODE) {
565 ModeFieldState &
Field =
566 Opc == AMDGPU::S_DENORM_MODE ? DenormMode : RoundMode;
567 int64_t NewValue =
MI.getOperand(0).getImm();
569 if (
Field.PendingWrite) {
571 << *
Field.PendingWrite);
572 Field.PendingWrite->eraseFromParent();
573 ++NumModeWritesRemoved;
575 Field.PendingWrite =
nullptr;
579 if (
Field.Value == NewValue) {
581 MI.eraseFromParent();
582 ++NumModeWritesRemoved;
589 Field.Value = NewValue;
594 if (!DenormMode.isTracked() && !RoundMode.isTracked())
598 if (
MI.isInlineAsm() ||
MI.modifiesRegister(AMDGPU::MODE,
TRI)) {
599 DenormMode = ModeFieldState();
600 RoundMode = ModeFieldState();
604 if (
MI.readsRegister(AMDGPU::MODE,
TRI) ||
MI.hasUnmodeledSideEffects()) {
605 DenormMode.PendingWrite =
nullptr;
606 RoundMode.PendingWrite =
nullptr;
612bool SIPreEmitPeephole::canUnpackingClobberRegister(
const MachineInstr &
MI) {
622 Register UnpackedDstReg =
TRI->getSubReg(DstReg, AMDGPU::sub0);
624 const MachineOperand *Src0MO =
TII->getNamedOperand(
MI, AMDGPU::OpName::src0);
625 if (Src0MO && Src0MO->
isReg()) {
628 TII->getNamedOperand(
MI, AMDGPU::OpName::src0_modifiers)->getImm();
630 ?
TRI->getSubReg(SrcReg0, AMDGPU::sub1)
631 :
TRI->getSubReg(SrcReg0, AMDGPU::sub0);
634 if (
TRI->regsOverlap(UnpackedDstReg, HiSrc0Reg))
638 const MachineOperand *Src1MO =
TII->getNamedOperand(
MI, AMDGPU::OpName::src1);
639 if (Src1MO && Src1MO->
isReg()) {
642 TII->getNamedOperand(
MI, AMDGPU::OpName::src1_modifiers)->getImm();
644 ?
TRI->getSubReg(SrcReg1, AMDGPU::sub1)
645 :
TRI->getSubReg(SrcReg1, AMDGPU::sub0);
646 if (
TRI->regsOverlap(UnpackedDstReg, HiSrc1Reg))
653 const MachineOperand *Src2MO =
654 TII->getNamedOperand(
MI, AMDGPU::OpName::src2);
655 if (Src2MO && Src2MO->
isReg()) {
658 TII->getNamedOperand(
MI, AMDGPU::OpName::src2_modifiers)->getImm();
660 ?
TRI->getSubReg(SrcReg2, AMDGPU::sub1)
661 :
TRI->getSubReg(SrcReg2, AMDGPU::sub0);
662 if (
TRI->regsOverlap(UnpackedDstReg, HiSrc2Reg))
669uint32_t SIPreEmitPeephole::mapToUnpackedOpcode(MachineInstr &
I) {
670 unsigned Opcode =
I.getOpcode();
675 case AMDGPU::V_PK_ADD_F32:
676 case AMDGPU::V_PK_ADD_F32_gfx1250:
677 return AMDGPU::V_ADD_F32_e64;
678 case AMDGPU::V_PK_MUL_F32:
679 case AMDGPU::V_PK_MUL_F32_gfx1250:
680 return AMDGPU::V_MUL_F32_e64;
681 case AMDGPU::V_PK_FMA_F32:
682 case AMDGPU::V_PK_FMA_F32_gfx1250:
683 return AMDGPU::V_FMA_F32_e64;
685 return std::numeric_limits<uint32_t>::max();
690void SIPreEmitPeephole::addOperandAndMods(MachineInstrBuilder &NewMI,
691 unsigned SrcMods,
bool IsHiBits,
692 const MachineOperand &SrcMO) {
693 unsigned NewSrcMods = 0;
705 if (SrcMods & NegModifier)
716 Register UnpackedSrcReg = (SrcMods & OpSelModifier)
717 ?
TRI->getSubReg(SrcMO.
getReg(), AMDGPU::sub1)
718 :
TRI->getSubReg(SrcMO.
getReg(), AMDGPU::sub0);
720 MachineOperand UnpackedSrcMO =
737 bool KillState =
true;
738 if ((OpSel == OpSelHi) && !IsHiBits)
742 NewMI.
add(UnpackedSrcMO);
745void SIPreEmitPeephole::collectUnpackingCandidates(
746 MachineInstr &BeginMI, SetVector<MachineInstr *> &InstrsToUnpack,
747 uint16_t NumMFMACycles) {
750 int TotalCyclesBetweenCandidates = 0;
751 const TargetSchedModel &SchedModel =
TII->getSchedModel();
756 uint32_t UnpackedOpCode = mapToUnpackedOpcode(Instr);
758 !(UnpackedOpCode == std::numeric_limits<uint32_t>::max());
759 if (
Instr.isMetaInstruction())
761 if ((
Instr.isTerminator()) ||
762 (
TII->isNeverCoissue(Instr) && !IsUnpackable) ||
764 Instr.modifiesRegister(AMDGPU::EXEC,
TRI)))
767 const MCSchedClassDesc *InstrSchedClassDesc =
771 TotalCyclesBetweenCandidates +=
Latency;
773 if (TotalCyclesBetweenCandidates >= NumMFMACycles - 1)
780 for (
const MachineOperand &InstrMO :
Instr.operands()) {
781 if (!InstrMO.isReg() || !InstrMO.getReg().isValid())
783 if (
TRI->regsOverlap(MFMADef, InstrMO.getReg()))
789 if (canUnpackingClobberRegister(Instr))
794 TotalCyclesBetweenCandidates -=
Latency;
796 TotalCyclesBetweenCandidates += 2;
798 if (TotalCyclesBetweenCandidates < NumMFMACycles - 1)
799 InstrsToUnpack.
insert(&Instr);
803void SIPreEmitPeephole::performF32Unpacking(MachineInstr &
I) {
804 const MachineOperand &DstOp =
I.getOperand(0);
806 uint32_t UnpackedOpcode = mapToUnpackedOpcode(
I);
807 assert(UnpackedOpcode != std::numeric_limits<uint32_t>::max() &&
808 "Unsupported Opcode");
810 MachineInstrBuilder Op0LOp1L =
811 createUnpackedMI(
I, UnpackedOpcode,
false);
812 MachineOperand &LoDstOp = Op0LOp1L->
getOperand(0);
816 MachineInstrBuilder Op0HOp1H =
817 createUnpackedMI(
I, UnpackedOpcode,
true);
818 MachineOperand &HiDstOp = Op0HOp1H->
getOperand(0);
820 uint32_t
IFlags =
I.getFlags();
829MachineInstrBuilder SIPreEmitPeephole::createUnpackedMI(MachineInstr &
I,
830 uint32_t UnpackedOpcode,
834 const MachineOperand *SrcMO0 =
TII->getNamedOperand(
I, AMDGPU::OpName::src0);
835 const MachineOperand *SrcMO1 =
TII->getNamedOperand(
I, AMDGPU::OpName::src1);
836 Register DstReg =
I.getOperand(0).getReg();
837 unsigned OpCode =
I.getOpcode();
838 Register UnpackedDstReg = IsHiBits ?
TRI->getSubReg(DstReg, AMDGPU::sub1)
839 :
TRI->getSubReg(DstReg, AMDGPU::sub0);
841 int64_t ClampVal =
TII->getNamedOperand(
I, AMDGPU::OpName::clamp)->getImm();
843 TII->getNamedOperand(
I, AMDGPU::OpName::src0_modifiers)->getImm();
845 TII->getNamedOperand(
I, AMDGPU::OpName::src1_modifiers)->getImm();
848 NewMI.
addDef(UnpackedDstReg);
849 addOperandAndMods(NewMI, Src0Mods, IsHiBits, *SrcMO0);
850 addOperandAndMods(NewMI, Src1Mods, IsHiBits, *SrcMO1);
853 const MachineOperand *SrcMO2 =
854 TII->getNamedOperand(
I, AMDGPU::OpName::src2);
856 TII->getNamedOperand(
I, AMDGPU::OpName::src2_modifiers)->getImm();
857 addOperandAndMods(NewMI, Src2Mods, IsHiBits, *SrcMO2);
870 SIPreEmitPeephole Impl;
872 if (Impl.run(MF, MLI)) {
883 TII = ST.getInstrInfo();
884 TRI = &
TII->getRegisterInfo();
895 if (TermI !=
MBB.end()) {
897 switch (
MI.getOpcode()) {
898 case AMDGPU::S_CBRANCH_VCCZ:
899 case AMDGPU::S_CBRANCH_VCCNZ:
902 case AMDGPU::S_CBRANCH_EXECZ:
908 if (!
ST.hasVGPRIndexMode())
911 MachineInstr *SetGPRMI =
nullptr;
912 const unsigned Threshold = 20;
920 if (
Count == Threshold)
925 if (
MI.getOpcode() != AMDGPU::S_SET_GPR_IDX_ON)
934 if (optimizeSetGPR(*SetGPRMI,
MI))
945 if (!
ST.hasGFX940Insts())
947 for (MachineBasicBlock &
MBB : MF) {
950 const TargetSchedModel &SchedModel =
TII->getSchedModel();
951 SetVector<MachineInstr *> InstrsToUnpack;
955 const MCSchedClassDesc *SchedClassDesc =
957 uint16_t NumMFMACycles =
959 collectUnpackingCandidates(
MI, InstrsToUnpack, NumMFMACycles);
961 for (MachineInstr *
MI : InstrsToUnpack) {
962 performF32Unpacking(*
MI);
964 if (!InstrsToUnpack.empty())
for(const MachineOperand &MO :llvm::drop_begin(OldMI.operands(), Desc.getNumOperands()))
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
ReachingDefInfo InstSet & ToRemove
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
AMD GCN specific subclass of TargetSubtarget.
const HexagonInstrInfo * TII
Register const TargetRegisterInfo * TRI
Promote Memory to Register
OptimizedStructLayoutField Field
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
SmallVector< MachineOperand, 4 > Cond
while(!MBB.succ_empty()) MBB.removeSuccessor(MBB.succ_end() - 1)
MachineRegisterInfo & MRI
static bool isProfitable(const CGDataOptions &Opts, const StableFunctionMap::StableFunctionEntries &SFS)
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
PassT::Result * getCachedResult(IRUnitT &IR) const
Get the cached result of an analysis pass for a given IR unit.
AnalysisUsage & addUsedIfAvailable()
Add the specified Pass class to the set of analyses used by this pass.
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
static uint32_t getDenominator()
static constexpr BranchProbability getZero()
uint32_t getNumerator() const
bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, MachineBasicBlock *&FBB, SmallVectorImpl< MachineOperand > &Cond, bool AllowModify) const override
Analyze the branching code at the end of MBB, returning true if it cannot be understood (e....
bool contains(const LoopT *L) const
Return true if the specified loop is contained within this loop.
bool isInnermost() const
Return true if the loop does not contain any (natural) loops.
BlockT * getHeader() const
iterator_range< block_iterator > blocks() const
LoopT * getParentLoop() const
Return the parent loop if it exists or nullptr for top level loops.
LoopT * removeChildLoop(iterator I)
This removes the specified child from being a subloop of this loop.
Represents a single loop in the control flow graph.
LLVM_ABI MachineBasicBlock * getFallThrough(bool JumpToFallThrough=true)
Return the fallthrough block if the block can implicitly transfer control to the block after it by fa...
LLVM_ABI BranchProbability getSuccProbability(const_succ_iterator Succ) const
Return probability of the edge from this block to MBB.
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
LLVM_ABI void removeSuccessor(MachineBasicBlock *Succ, bool NormalizeSuccProbs=false)
Remove successor from the successors list of this MachineBasicBlock.
Instructions::iterator instr_iterator
MachineInstrBundleIterator< MachineInstr, true > reverse_iterator
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
iterator_range< iterator > terminators()
iterator_range< succ_iterator > successors()
MachineInstrBundleIterator< MachineInstr > iterator
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.
void RenumberBlocks(MachineBasicBlock *MBBFrom=nullptr)
RenumberBlocks - This discards all of the MachineBasicBlock numbers and recomputes them.
BasicBlockListType::const_iterator const_iterator
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & add(const MachineOperand &MO) const
const MachineInstrBuilder & addDef(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a virtual register definition operand.
Representation of each machine instruction.
const MachineBasicBlock * getParent() const
void setFlags(unsigned flags)
const MachineOperand & getOperand(unsigned i) const
Analysis pass that exposes the MachineLoopInfo for a machine function.
LLVM_ABI void setIsRenamable(bool Val=true)
bool isReg() const
isReg - Tests if this is a MO_Register operand.
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
void setIsKill(bool Val=true)
LLVM_ABI bool isRenamable() const
isRenamable - Returns true if this register may be renamed, i.e.
void setIsUndef(bool Val=true)
Register getReg() const
getReg - Returns the register number.
static MachineOperand CreateReg(Register Reg, bool isDef, bool isImp=false, bool isKill=false, bool isDead=false, bool isUndef=false, bool isEarlyClobber=false, unsigned SubReg=0, bool isDebug=false, bool isInternalRead=false, bool isRenamable=false)
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Wrapper class representing virtual and physical registers.
static bool isMFMA(const MachineInstr &MI)
static bool modifiesModeRegister(const MachineInstr &MI)
Return true if the instruction modifies the mode register.q.
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
bool insert(const value_type &X)
Insert a new element into the SetVector.
LLVM_ABI const MCSchedClassDesc * resolveSchedClass(const MachineInstr *MI) const
Return the MCSchedClassDesc for this instruction.
ProcResIter getWriteProcResBegin(const MCSchedClassDesc *SC) const
LLVM Value Representation.
self_iterator getIterator()
NodeTy * getNextNode()
Get the next node, or nullptr for the list tail.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
LLVM_READONLY bool hasNamedOperand(uint32_t Opcode, OpName NamedIdx)
PointerTypeMap run(const Module &M)
Compute the PointerTypeMap for the module M.
NodeAddr< InstrNode * > Instr
This is an optimization pass for GlobalISel generic memory operations.
auto find(R &&Range, const T &Val)
Provide wrappers to std::find which take ranges instead of having to pass begin/end explicitly.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
char & SIPreEmitPeepholeID
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
@ And
Bitwise or logical AND of integers.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
@ End
Run the machine verifier once, at the end of the pipeline.
uint16_t ReleaseAtCycle
Cycle at which the resource will be released by an instruction, relatively to the cycle in which the ...