34#define DEBUG_TYPE "si-pre-emit-peephole"
37 "Number of redundant mode register writes removed");
43struct ModeFieldState {
44 std::optional<int64_t>
Value;
45 std::optional<int64_t> ValueBeforePendingWrite;
48 bool isTracked()
const {
return PendingWrite ||
Value; }
51class SIPreEmitPeephole {
53 const SIInstrInfo *TII =
nullptr;
54 const SIRegisterInfo *TRI =
nullptr;
55 MachineLoopInfo *MLI =
nullptr;
57 bool optimizeVccBranch(MachineInstr &
MI)
const;
58 void updateMLIBeforeRemovingEdge(MachineBasicBlock *From,
59 MachineBasicBlock *To)
const;
60 bool optimizeSetGPR(MachineInstr &
First, MachineInstr &
MI)
const;
61 bool getBlockDestinations(MachineBasicBlock &SrcMBB,
62 MachineBasicBlock *&TrueMBB,
63 MachineBasicBlock *&FalseMBB,
64 SmallVectorImpl<MachineOperand> &
Cond);
65 bool mustRetainExeczBranch(
const MachineInstr &Branch,
66 const MachineBasicBlock &From,
67 const MachineBasicBlock &To)
const;
68 bool removeExeczBranch(MachineInstr &
MI, MachineBasicBlock &SrcMBB);
69 bool removeRedundantModeWrites(MachineBasicBlock &SrcMBB)
const;
72 void collectUnpackingCandidates(MachineInstr &BeginMI,
73 SetVector<MachineInstr *> &InstrsToUnpack,
74 uint16_t NumMFMACycles);
82 bool canUnpackingClobberRegister(
const MachineInstr &
MI);
86 void performF32Unpacking(MachineInstr &
I);
88 uint32_t mapToUnpackedOpcode(MachineInstr &
I);
92 MachineInstrBuilder createUnpackedMI(MachineInstr &
I, uint32_t UnpackedOpcode,
96 void addOperandAndMods(MachineInstrBuilder &NewMI,
unsigned SrcMods,
97 bool IsHiBits,
const MachineOperand &SrcMO);
107 SIPreEmitPeepholeLegacy() : MachineFunctionPass(ID) {}
109 void getAnalysisUsage(AnalysisUsage &AU)
const override {
116 auto *MLIWrapper = getAnalysisIfAvailable<MachineLoopInfoWrapperPass>();
117 MachineLoopInfo *MLI = MLIWrapper ? &MLIWrapper->getLI() :
nullptr;
118 return SIPreEmitPeephole().run(MF, MLI);
125 "SI peephole optimizations",
false,
false)
127char SIPreEmitPeepholeLegacy::ID = 0;
131void SIPreEmitPeephole::updateMLIBeforeRemovingEdge(
142 unsigned BackEdgeCount = 0;
144 if (Loop->contains(Pred))
148 if (BackEdgeCount > 1)
155 if (MLI->getLoopFor(BB) == Loop)
156 MLI->changeLoopFor(BB, ParentLoop);
161 MachineLoop *Child = Loop->removeChildLoop(std::prev(Loop->end()));
163 ParentLoop->addChildLoop(Child);
165 MLI->addTopLevelLoop(Child);
176bool SIPreEmitPeephole::optimizeVccBranch(
MachineInstr &
MI)
const {
198 const bool IsWave32 =
ST.isWave32();
199 const unsigned CondReg =
TRI->getVCC();
200 const unsigned ExecReg = IsWave32 ? AMDGPU::EXEC_LO : AMDGPU::EXEC;
201 const unsigned And = IsWave32 ? AMDGPU::S_AND_B32 : AMDGPU::S_AND_B64;
202 const unsigned AndN2 = IsWave32 ? AMDGPU::S_ANDN2_B32 : AMDGPU::S_ANDN2_B64;
203 const unsigned Mov = IsWave32 ? AMDGPU::S_MOV_B32 : AMDGPU::S_MOV_B64;
207 bool ReadsCond =
false;
208 unsigned Threshold = 5;
209 for (++
A;
A !=
E; ++
A) {
212 if (
A->modifiesRegister(ExecReg,
TRI))
214 if (
A->modifiesRegister(CondReg,
TRI)) {
215 if (!
A->definesRegister(CondReg,
TRI) ||
216 (
A->getOpcode() !=
And &&
A->getOpcode() != AndN2))
220 ReadsCond |=
A->readsRegister(CondReg,
TRI);
225 MachineOperand &Op1 =
A->getOperand(1);
226 MachineOperand &Op2 =
A->getOperand(2);
228 Op2.
getReg() == ExecReg) {
229 TII->commuteInstruction(*
A);
237 int64_t MaskValue = 0;
241 auto M = std::next(
A);
242 bool ReadsSreg =
false;
243 bool ModifiesExec =
false;
244 for (;
M !=
E; ++
M) {
245 if (
M->definesRegister(SReg,
TRI))
247 if (
M->modifiesRegister(SReg,
TRI))
249 ReadsSreg |=
M->readsRegister(SReg,
TRI);
250 ModifiesExec |=
M->modifiesRegister(ExecReg,
TRI);
259 if (
A->getOpcode() ==
And && SReg == CondReg && !ModifiesExec &&
260 TII->isVOPC(*M) &&
A->allImplicitDefsAreDead()) {
261 A->eraseFromParent();
265 if (!
M->isMoveImmediate() || !
M->getOperand(1).isImm() ||
266 (
M->getOperand(1).getImm() != -1 &&
M->getOperand(1).getImm() != 0))
268 MaskValue =
M->getOperand(1).getImm();
271 if (!ReadsSreg && Op2.
isKill()) {
272 A->getOperand(2).ChangeToImmediate(MaskValue);
273 M->eraseFromParent();
275 }
else if (Op2.
isImm()) {
282 assert(MaskValue == 0 || MaskValue == -1);
283 if (
A->getOpcode() == AndN2)
284 MaskValue = ~MaskValue;
286 if (!ReadsCond &&
A->registerDefIsDead(AMDGPU::SCC,
nullptr)) {
287 if (!
MI.killsRegister(CondReg,
TRI)) {
289 if (MaskValue == 0) {
290 BuildMI(*
A->getParent(), *
A,
A->getDebugLoc(),
TII->get(Mov), CondReg)
293 BuildMI(*
A->getParent(), *
A,
A->getDebugLoc(),
TII->get(Mov), CondReg)
298 A->eraseFromParent();
301 bool IsVCCZ =
MI.getOpcode() == AMDGPU::S_CBRANCH_VCCZ;
302 if (SReg == ExecReg) {
305 MI.eraseFromParent();
308 MI.setDesc(
TII->get(AMDGPU::S_BRANCH));
309 }
else if (IsVCCZ && MaskValue == 0) {
312 MachineBasicBlock *Parent =
MI.getParent();
313 SmallVector<MachineInstr *, 4>
ToRemove;
320 Found =
Term.isIdenticalTo(
MI);
323 assert(Found &&
"conditional branch is not terminator");
325 MachineOperand &Dst = BranchMI->getOperand(0);
326 assert(Dst.isMBB() &&
"destination is not basic block");
327 updateMLIBeforeRemovingEdge(Parent, Dst.getMBB());
329 BranchMI->eraseFromParent();
333 updateMLIBeforeRemovingEdge(Parent, Succ);
338 MI.setDesc(
TII->get(AMDGPU::S_BRANCH));
339 }
else if (!IsVCCZ && MaskValue == 0) {
341 MachineOperand &Dst =
MI.getOperand(0);
342 assert(Dst.isMBB() &&
"destination is not basic block");
344 updateMLIBeforeRemovingEdge(Parent, Dst.getMBB());
346 MI.eraseFromParent();
348 }
else if (MaskValue == -1) {
351 TII->get(IsVCCZ ? AMDGPU::S_CBRANCH_EXECZ : AMDGPU::S_CBRANCH_EXECNZ));
354 MI.removeOperand(
MI.findRegisterUseOperandIdx(CondReg,
TRI,
false ));
360bool SIPreEmitPeephole::optimizeSetGPR(MachineInstr &
First,
361 MachineInstr &
MI)
const {
364 const MachineRegisterInfo &MRI = MF.
getRegInfo();
365 MachineOperand *Idx =
TII->getNamedOperand(
MI, AMDGPU::OpName::src0);
367 SmallVector<MachineInstr *, 4>
ToRemove;
375 E =
MI.getIterator();
377 if (
I->isBundle() ||
I->isDebugInstr())
379 switch (
I->getOpcode()) {
380 case AMDGPU::S_SET_GPR_IDX_MODE:
382 case AMDGPU::S_SET_GPR_IDX_OFF:
387 if (
I->modifiesRegister(AMDGPU::M0,
TRI))
389 if (IdxReg &&
I->modifiesRegister(IdxReg,
TRI))
391 if (
llvm::any_of(
I->operands(), [&MRI,
this](
const MachineOperand &MO) {
392 return MO.isReg() && TRI->isVectorRegister(MRI, MO.getReg());
396 if (!IdxOn || !(
I->getOpcode() == AMDGPU::V_MOV_B32_indirect_write ||
397 I->getOpcode() == AMDGPU::V_MOV_B32_indirect_read))
403 MI.eraseFromBundle();
405 RI->eraseFromBundle();
409bool SIPreEmitPeephole::getBlockDestinations(
410 MachineBasicBlock &SrcMBB, MachineBasicBlock *&TrueMBB,
411 MachineBasicBlock *&FalseMBB, SmallVectorImpl<MachineOperand> &
Cond) {
422class BranchWeightCostModel {
423 const SIInstrInfo &
TII;
424 const TargetSchedModel &SchedModel;
425 BranchProbability BranchProb;
426 static constexpr uint64_t BranchNotTakenCost = 1;
431 BranchWeightCostModel(
const SIInstrInfo &
TII,
const MachineInstr &Branch,
432 const MachineBasicBlock &Succ)
433 :
TII(
TII), SchedModel(
TII.getSchedModel()) {
434 const MachineBasicBlock &Head = *
Branch.getParent();
441 BranchTakenCost = SchedModel.computeInstrLatency(&Branch);
445 if (
TII.isWaitcnt(
MI.getOpcode()))
448 ThenCyclesCost += SchedModel.computeInstrLatency(&
MI);
460 return (Denominator - Numerator) * ThenCyclesCost <=
461 ((Denominator - Numerator) * BranchTakenCost +
462 Numerator * BranchNotTakenCost);
466bool SIPreEmitPeephole::mustRetainExeczBranch(
467 const MachineInstr &Branch,
const MachineBasicBlock &From,
468 const MachineBasicBlock &To)
const {
470 BranchWeightCostModel CostModel{*
TII,
Branch, From};
475 const MachineBasicBlock &
MBB = *
MBBI;
477 for (
const MachineInstr &
MI :
MBB) {
481 if (
MI.isConditionalBranch())
484 if (
MI.isUnconditionalBranch() &&
488 if (
MI.isMetaInstruction())
491 if (
TII->hasUnwantedEffectsWhenEXECEmpty(
MI))
494 if (!CostModel.isProfitable(
MI))
504bool SIPreEmitPeephole::removeExeczBranch(MachineInstr &
MI,
505 MachineBasicBlock &SrcMBB) {
507 if (!
TII->getSchedModel().hasInstrSchedModel())
510 MachineBasicBlock *TrueMBB =
nullptr;
511 MachineBasicBlock *FalseMBB =
nullptr;
514 if (!getBlockDestinations(SrcMBB, TrueMBB, FalseMBB,
Cond))
522 if (mustRetainExeczBranch(
MI, *FalseMBB, *TrueMBB))
526 MI.eraseFromParent();
543bool SIPreEmitPeephole::removeRedundantModeWrites(
544 MachineBasicBlock &SrcMBB)
const {
546 ModeFieldState DenormMode;
547 ModeFieldState RoundMode;
550 if (
MI.isDebugInstr())
553 unsigned Opc =
MI.getOpcode();
554 if (
Opc == AMDGPU::S_DENORM_MODE ||
Opc == AMDGPU::S_ROUND_MODE) {
555 ModeFieldState &
Field =
556 Opc == AMDGPU::S_DENORM_MODE ? DenormMode : RoundMode;
557 int64_t NewValue =
MI.getOperand(0).getImm();
559 if (
Field.PendingWrite) {
561 << *
Field.PendingWrite);
562 Field.PendingWrite->eraseFromParent();
563 ++NumModeWritesRemoved;
565 Field.PendingWrite =
nullptr;
569 if (
Field.Value == NewValue) {
571 MI.eraseFromParent();
572 ++NumModeWritesRemoved;
579 Field.Value = NewValue;
584 if (!DenormMode.isTracked() && !RoundMode.isTracked())
588 if (
MI.isInlineAsm() ||
MI.modifiesRegister(AMDGPU::MODE,
TRI)) {
589 DenormMode = ModeFieldState();
590 RoundMode = ModeFieldState();
594 if (
MI.readsRegister(AMDGPU::MODE,
TRI) ||
MI.hasUnmodeledSideEffects()) {
595 DenormMode.PendingWrite =
nullptr;
596 RoundMode.PendingWrite =
nullptr;
602bool SIPreEmitPeephole::canUnpackingClobberRegister(
const MachineInstr &
MI) {
612 Register UnpackedDstReg =
TRI->getSubReg(DstReg, AMDGPU::sub0);
614 const MachineOperand *Src0MO =
TII->getNamedOperand(
MI, AMDGPU::OpName::src0);
615 if (Src0MO && Src0MO->
isReg()) {
618 TII->getNamedOperand(
MI, AMDGPU::OpName::src0_modifiers)->getImm();
620 ?
TRI->getSubReg(SrcReg0, AMDGPU::sub1)
621 :
TRI->getSubReg(SrcReg0, AMDGPU::sub0);
624 if (
TRI->regsOverlap(UnpackedDstReg, HiSrc0Reg))
628 const MachineOperand *Src1MO =
TII->getNamedOperand(
MI, AMDGPU::OpName::src1);
629 if (Src1MO && Src1MO->
isReg()) {
632 TII->getNamedOperand(
MI, AMDGPU::OpName::src1_modifiers)->getImm();
634 ?
TRI->getSubReg(SrcReg1, AMDGPU::sub1)
635 :
TRI->getSubReg(SrcReg1, AMDGPU::sub0);
636 if (
TRI->regsOverlap(UnpackedDstReg, HiSrc1Reg))
643 const MachineOperand *Src2MO =
644 TII->getNamedOperand(
MI, AMDGPU::OpName::src2);
645 if (Src2MO && Src2MO->
isReg()) {
648 TII->getNamedOperand(
MI, AMDGPU::OpName::src2_modifiers)->getImm();
650 ?
TRI->getSubReg(SrcReg2, AMDGPU::sub1)
651 :
TRI->getSubReg(SrcReg2, AMDGPU::sub0);
652 if (
TRI->regsOverlap(UnpackedDstReg, HiSrc2Reg))
659uint32_t SIPreEmitPeephole::mapToUnpackedOpcode(MachineInstr &
I) {
660 unsigned Opcode =
I.getOpcode();
665 case AMDGPU::V_PK_ADD_F32:
666 case AMDGPU::V_PK_ADD_F32_gfx1250:
667 return AMDGPU::V_ADD_F32_e64;
668 case AMDGPU::V_PK_MUL_F32:
669 case AMDGPU::V_PK_MUL_F32_gfx1250:
670 return AMDGPU::V_MUL_F32_e64;
671 case AMDGPU::V_PK_FMA_F32:
672 case AMDGPU::V_PK_FMA_F32_gfx1250:
673 return AMDGPU::V_FMA_F32_e64;
675 return std::numeric_limits<uint32_t>::max();
680void SIPreEmitPeephole::addOperandAndMods(MachineInstrBuilder &NewMI,
681 unsigned SrcMods,
bool IsHiBits,
682 const MachineOperand &SrcMO) {
683 unsigned NewSrcMods = 0;
695 if (SrcMods & NegModifier)
706 Register UnpackedSrcReg = (SrcMods & OpSelModifier)
707 ?
TRI->getSubReg(SrcMO.
getReg(), AMDGPU::sub1)
708 :
TRI->getSubReg(SrcMO.
getReg(), AMDGPU::sub0);
710 MachineOperand UnpackedSrcMO =
727 bool KillState =
true;
728 if ((OpSel == OpSelHi) && !IsHiBits)
732 NewMI.
add(UnpackedSrcMO);
735void SIPreEmitPeephole::collectUnpackingCandidates(
736 MachineInstr &BeginMI, SetVector<MachineInstr *> &InstrsToUnpack,
737 uint16_t NumMFMACycles) {
740 int TotalCyclesBetweenCandidates = 0;
741 auto SchedModel =
TII->getSchedModel();
746 uint32_t UnpackedOpCode = mapToUnpackedOpcode(Instr);
748 !(UnpackedOpCode == std::numeric_limits<uint32_t>::max());
749 if (
Instr.isMetaInstruction())
751 if ((
Instr.isTerminator()) ||
752 (
TII->isNeverCoissue(Instr) && !IsUnpackable) ||
754 Instr.modifiesRegister(AMDGPU::EXEC,
TRI)))
757 const MCSchedClassDesc *InstrSchedClassDesc =
761 TotalCyclesBetweenCandidates +=
Latency;
763 if (TotalCyclesBetweenCandidates >= NumMFMACycles - 1)
770 for (
const MachineOperand &InstrMO :
Instr.operands()) {
771 if (!InstrMO.isReg() || !InstrMO.getReg().isValid())
773 if (
TRI->regsOverlap(MFMADef, InstrMO.getReg()))
779 if (canUnpackingClobberRegister(Instr))
784 TotalCyclesBetweenCandidates -=
Latency;
786 TotalCyclesBetweenCandidates += 2;
788 if (TotalCyclesBetweenCandidates < NumMFMACycles - 1)
789 InstrsToUnpack.
insert(&Instr);
793void SIPreEmitPeephole::performF32Unpacking(MachineInstr &
I) {
794 const MachineOperand &DstOp =
I.getOperand(0);
796 uint32_t UnpackedOpcode = mapToUnpackedOpcode(
I);
797 assert(UnpackedOpcode != std::numeric_limits<uint32_t>::max() &&
798 "Unsupported Opcode");
800 MachineInstrBuilder Op0LOp1L =
801 createUnpackedMI(
I, UnpackedOpcode,
false);
802 MachineOperand LoDstOp = Op0LOp1L->
getOperand(0);
806 MachineInstrBuilder Op0HOp1H =
807 createUnpackedMI(
I, UnpackedOpcode,
true);
808 MachineOperand HiDstOp = Op0HOp1H->
getOperand(0);
810 uint32_t
IFlags =
I.getFlags();
819MachineInstrBuilder SIPreEmitPeephole::createUnpackedMI(MachineInstr &
I,
820 uint32_t UnpackedOpcode,
824 const MachineOperand *SrcMO0 =
TII->getNamedOperand(
I, AMDGPU::OpName::src0);
825 const MachineOperand *SrcMO1 =
TII->getNamedOperand(
I, AMDGPU::OpName::src1);
826 Register DstReg =
I.getOperand(0).getReg();
827 unsigned OpCode =
I.getOpcode();
828 Register UnpackedDstReg = IsHiBits ?
TRI->getSubReg(DstReg, AMDGPU::sub1)
829 :
TRI->getSubReg(DstReg, AMDGPU::sub0);
831 int64_t ClampVal =
TII->getNamedOperand(
I, AMDGPU::OpName::clamp)->getImm();
833 TII->getNamedOperand(
I, AMDGPU::OpName::src0_modifiers)->getImm();
835 TII->getNamedOperand(
I, AMDGPU::OpName::src1_modifiers)->getImm();
838 NewMI.
addDef(UnpackedDstReg);
839 addOperandAndMods(NewMI, Src0Mods, IsHiBits, *SrcMO0);
840 addOperandAndMods(NewMI, Src1Mods, IsHiBits, *SrcMO1);
843 const MachineOperand *SrcMO2 =
844 TII->getNamedOperand(
I, AMDGPU::OpName::src2);
846 TII->getNamedOperand(
I, AMDGPU::OpName::src2_modifiers)->getImm();
847 addOperandAndMods(NewMI, Src2Mods, IsHiBits, *SrcMO2);
860 SIPreEmitPeephole Impl;
862 if (Impl.run(MF, MLI)) {
873 TII = ST.getInstrInfo();
874 TRI = &
TII->getRegisterInfo();
885 if (TermI !=
MBB.end()) {
887 switch (
MI.getOpcode()) {
888 case AMDGPU::S_CBRANCH_VCCZ:
889 case AMDGPU::S_CBRANCH_VCCNZ:
892 case AMDGPU::S_CBRANCH_EXECZ:
898 if (!
ST.hasVGPRIndexMode())
901 MachineInstr *SetGPRMI =
nullptr;
902 const unsigned Threshold = 20;
910 if (
Count == Threshold)
915 if (
MI.getOpcode() != AMDGPU::S_SET_GPR_IDX_ON)
924 if (optimizeSetGPR(*SetGPRMI,
MI))
935 if (!
ST.hasGFX940Insts())
937 for (MachineBasicBlock &
MBB : MF) {
940 auto SchedModel =
TII->getSchedModel();
941 SetVector<MachineInstr *> InstrsToUnpack;
945 const MCSchedClassDesc *SchedClassDesc =
947 uint16_t NumMFMACycles =
949 collectUnpackingCandidates(
MI, InstrsToUnpack, NumMFMACycles);
951 for (MachineInstr *
MI : InstrsToUnpack) {
952 performF32Unpacking(*
MI);
for(const MachineOperand &MO :llvm::drop_begin(OldMI.operands(), Desc.getNumOperands()))
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Provides AMDGPU specific target descriptions.
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)
const SmallVectorImpl< MachineOperand > & Cond
This file implements a set that has insertion order iteration characteristics.
static bool isProfitable(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()
iterator_range< pred_iterator > predecessors()
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.
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(uint64_t Opcode, OpName NamedIdx)
DXILDebugInfoMap run(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.
uint16_t ReleaseAtCycle
Cycle at which the resource will be released by an instruction, relatively to the cycle in which the ...