44#define DEBUG_TYPE "riscv-insert-vsetvli"
45#define RISCV_INSERT_VSETVLI_NAME "RISC-V Insert VSETVLI pass"
47STATISTIC(NumInsertedVSETVL,
"Number of VSETVL inst inserted");
48STATISTIC(NumCoalescedVSETVL,
"Number of VSETVL inst coalesced");
62 return LI.getVNInfoBefore(
SI);
93 RISCVInsertVSETVLILegacy() : MachineFunctionPass(ID) {}
96 void getAnalysisUsage(AnalysisUsage &AU)
const override {
111class RISCVInsertVSETVLIImpl {
112 const RISCVSubtarget *ST;
113 const TargetInstrInfo *TII;
114 MachineRegisterInfo *MRI;
117 RISCVVSETVLIInfoAnalysis VIA;
119 std::vector<BlockData> BlockInfo;
120 std::queue<const MachineBasicBlock *> WorkList;
122 bool needVSETVLI(
const DemandedFields &Used,
const VSETVLIInfo &Require,
123 const VSETVLIInfo &CurInfo)
const;
124 bool needVSETVLIPHI(
const VSETVLIInfo &Require,
125 const MachineBasicBlock &
MBB)
const;
126 void insertVSETVLI(MachineBasicBlock &
MBB,
128 const VSETVLIInfo &Info,
const VSETVLIInfo &PrevInfo);
130 void transferBefore(VSETVLIInfo &Info,
const MachineInstr &
MI)
const;
131 void transferAfter(VSETVLIInfo &Info,
const MachineInstr &
MI)
const;
132 bool computeVLVTYPEChanges(
const MachineBasicBlock &
MBB,
133 VSETVLIInfo &Info)
const;
134 void computeIncomingVLVTYPE(
const MachineBasicBlock &
MBB);
135 void emitVSETVLIs(MachineBasicBlock &
MBB);
136 void doPRE(MachineBasicBlock &
MBB);
137 void insertReadVL(MachineBasicBlock &
MBB);
139 bool canMutatePriorConfig(
const MachineInstr &PrevMI,
const MachineInstr &
MI,
140 const DemandedFields &Used,
141 MachineInstr *&AVLDefToMove)
const;
142 void coalesceVSETVLIs(MachineBasicBlock &
MBB)
const;
143 bool canMutatePriorConfigWithTWiden(
const MachineInstr &PrevMI,
144 const MachineInstr &
MI)
const;
145 void coalesceVSETVLIsForTWiden(MachineBasicBlock &
MBB)
const;
146 bool insertVSETMTK(MachineBasicBlock &
MBB, TKTMMode
Mode)
const;
149 bool runOnMachineFunction(
MachineFunction &MF, LiveIntervals *LISToUpdate);
154char RISCVInsertVSETVLILegacy::ID = 0;
166 if (PrevInfo.isKnown()) {
169 if (Info.hasSameAVL(PrevInfo) && Info.hasSameVLMAX(PrevInfo)) {
170 auto MI = BuildMI(MBB, InsertPt, DL,
171 TII->get(Info.getTWiden() ? RISCV::PseudoSF_VSETTNTX0X0
172 : RISCV::PseudoVSETVLIX0X0))
173 .addDef(RISCV::X0, RegState::Dead)
174 .addReg(RISCV::X0, RegState::Kill)
175 .addImm(Info.encodeVTYPE())
176 .addReg(RISCV::VL, RegState::Implicit);
178 LIS->InsertMachineInstrInMaps(*MI);
185 if (Info.hasSameVLMAX(PrevInfo) && Info.hasAVLReg()) {
186 if (const MachineInstr *DefMI = Info.getAVLDefMI(LIS);
187 DefMI && RISCVInstrInfo::isVectorConfigInstr(*DefMI)) {
188 VSETVLIInfo DefInfo = VIA.getInfoForVSETVLI(*DefMI);
189 if (DefInfo.hasSameAVL(PrevInfo) && DefInfo.hasSameVLMAX(PrevInfo)) {
191 BuildMI(MBB, InsertPt, DL,
192 TII->get(Info.getTWiden() ? RISCV::PseudoSF_VSETTNTX0X0
193 : RISCV::PseudoVSETVLIX0X0))
194 .addDef(RISCV::X0, RegState::Dead)
195 .addReg(RISCV::X0, RegState::Kill)
196 .addImm(Info.encodeVTYPE())
197 .addReg(RISCV::VL, RegState::Implicit);
199 LIS->InsertMachineInstrInMaps(*MI);
206 if (Info.hasAVLImm()) {
207 auto MI = BuildMI(MBB, InsertPt, DL, TII->get(RISCV::PseudoVSETIVLI))
208 .addDef(RISCV::X0, RegState::Dead)
209 .addImm(Info.getAVLImm())
210 .addImm(Info.encodeVTYPE());
212 LIS->InsertMachineInstrInMaps(*MI);
216 if (Info.hasAVLVLMAX()) {
217 Register DestReg = MRI->createVirtualRegister(&RISCV::GPRNoX0RegClass);
218 auto MI = BuildMI(MBB, InsertPt, DL,
219 TII->get(Info.getTWiden() ? RISCV::PseudoSF_VSETTNTX0
220 : RISCV::PseudoVSETVLIX0))
221 .addDef(DestReg, RegState::Dead)
222 .addReg(RISCV::X0, RegState::Kill)
223 .addImm(Info.encodeVTYPE());
225 LIS->InsertMachineInstrInMaps(*MI);
226 LIS->createAndComputeVirtRegInterval(DestReg);
232 MRI->constrainRegClass(AVLReg, &RISCV::GPRNoX0RegClass);
234 TII->get(Info.getTWiden() ? RISCV::PseudoSF_VSETTNT
235 : RISCV::PseudoVSETVLI))
238 .
addImm(Info.encodeVTYPE());
243 const VNInfo *CurVNI = Info.getAVLVNInfo();
251 MRI->createVirtualRegister(&RISCV::GPRNoX0RegClass);
255 II =
MBB->getFirstNonPHI();
264 MI->getOperand(1).setReg(AVLCopyReg);
273bool RISCVInsertVSETVLIImpl::needVSETVLI(
const DemandedFields &Used,
296 Info.setVLMul(*NewVLMul);
306void RISCVInsertVSETVLIImpl::transferBefore(VSETVLIInfo &Info,
307 const MachineInstr &
MI)
const {
308 if (ST->
getCLOpts().insert_vsetvli_whole_vector_register_move_valid_vtype &&
310 (!
Info.isKnown() ||
Info.hasSEWLMULRatioOnly())) {
328 if (
Info.isValid() && !needVSETVLI(Demanded, NewInfo, Info))
331 const VSETVLIInfo PrevInfo =
Info;
335 const VSETVLIInfo IncomingInfo =
adjustIncoming(PrevInfo, NewInfo, Demanded);
347 Info.setAVL(IncomingInfo);
350 if (
Info.hasSEWLMULRatioOnly()) {
351 VSETVLIInfo RatiolessInfo = IncomingInfo;
352 RatiolessInfo.
setAVL(Info);
353 Info = RatiolessInfo;
364 (Demanded.
TailPolicy ? IncomingInfo : Info).getTailAgnostic() ||
366 (Demanded.
MaskPolicy ? IncomingInfo : Info).getMaskAgnostic() ||
369 (Demanded.
AltFmt ? IncomingInfo : Info).getAltFmt() && SEW < 32,
377void RISCVInsertVSETVLIImpl::transferAfter(VSETVLIInfo &Info,
378 const MachineInstr &
MI)
const {
379 if (RISCVInstrInfo::isVectorConfigInstr(
MI)) {
387 if (RISCVInstrInfo::isXSfmmVectorConfigTMTKInstr(
MI))
390 if (RISCVInstrInfo::isFaultOnlyFirstLoad(
MI)) {
392 assert(
MI.getOperand(1).getReg().isVirtual());
398 Info.setAVLRegDef(VNI,
MI.getOperand(1).getReg());
400 Info.setAVLRegDef(
nullptr,
MI.getOperand(1).getReg());
406 if (
MI.isCall() ||
MI.isInlineAsm() ||
407 MI.modifiesRegister(RISCV::VL,
nullptr) ||
408 MI.modifiesRegister(RISCV::VTYPE,
nullptr))
412bool RISCVInsertVSETVLIImpl::computeVLVTYPEChanges(
const MachineBasicBlock &
MBB,
413 VSETVLIInfo &Info)
const {
414 bool HadVectorOp =
false;
417 for (
const MachineInstr &
MI :
MBB) {
418 transferBefore(Info,
MI);
420 if (RISCVInstrInfo::isVectorConfigInstr(
MI) ||
423 RISCVInstrInfo::isXSfmmVectorConfigInstr(
MI))
426 transferAfter(Info,
MI);
432void RISCVInsertVSETVLIImpl::computeIncomingVLVTYPE(
433 const MachineBasicBlock &
MBB) {
437 BBInfo.InQueue =
false;
441 VSETVLIInfo InInfo = BBInfo.
Pred;
447 InInfo = InInfo.
intersect(BlockInfo[
P->getNumber()].Exit);
455 if (InInfo == BBInfo.
Pred)
458 BBInfo.
Pred = InInfo;
460 <<
" changed to " << BBInfo.
Pred <<
"\n");
466 VSETVLIInfo TmpStatus;
467 computeVLVTYPEChanges(
MBB, TmpStatus);
471 if (BBInfo.
Exit == TmpStatus)
474 BBInfo.
Exit = TmpStatus;
476 <<
" changed to " << BBInfo.
Exit <<
"\n");
481 if (!BlockInfo[S->getNumber()].InQueue) {
482 BlockInfo[S->getNumber()].InQueue =
true;
490bool RISCVInsertVSETVLIImpl::needVSETVLIPHI(
491 const VSETVLIInfo &Require,
const MachineBasicBlock &
MBB)
const {
506 const VSETVLIInfo &PBBExit = BlockInfo[PBB->getNumber()].Exit;
513 if (!
DefMI || !RISCVInstrInfo::isVectorConfigInstr(*
DefMI))
519 if (DefInfo != PBBExit)
534void RISCVInsertVSETVLIImpl::emitVSETVLIs(MachineBasicBlock &
MBB) {
538 bool PrefixTransparent =
true;
539 for (MachineInstr &
MI :
MBB) {
540 const VSETVLIInfo PrevInfo = CurInfo;
541 transferBefore(CurInfo,
MI);
544 if (RISCVInstrInfo::isVectorConfigInstr(
MI)) {
546 assert(
MI.getOperand(3).getReg() == RISCV::VL &&
547 MI.getOperand(4).getReg() == RISCV::VTYPE &&
548 "Unexpected operands where VL and VTYPE should be");
553 if (
MI.getOperand(3).isDead())
555 if (
MI.getOperand(4).isDead())
559 MI.getOperand(3).setIsDead(
false);
560 MI.getOperand(4).setIsDead(
false);
561 PrefixTransparent =
false;
564 if (ST->
getCLOpts().insert_vsetvli_whole_vector_register_move_valid_vtype &&
567 insertVSETVLI(
MBB,
MI,
MI.getDebugLoc(), CurInfo, PrevInfo);
568 PrefixTransparent =
false;
584 if (!PrefixTransparent || needVSETVLIPHI(CurInfo,
MBB))
585 insertVSETVLI(
MBB,
MI,
MI.getDebugLoc(), CurInfo, PrevInfo);
586 PrefixTransparent =
false;
610 for (MachineInstr *DeadMI : DeadMIs) {
611 if (!
TII->isAddImmediate(*DeadMI,
Reg))
614 Register AddReg = DeadMI->getOperand(1).getReg();
615 DeadMI->eraseFromParent();
628 if (
MI.isInlineAsm()) {
629 MI.addRegisterDefined(RISCV::VL,
nullptr);
630 MI.addRegisterDefined(RISCV::VTYPE,
nullptr);
633 if (
MI.isCall() ||
MI.isInlineAsm() ||
634 MI.modifiesRegister(RISCV::VL,
nullptr) ||
635 MI.modifiesRegister(RISCV::VTYPE,
nullptr))
636 PrefixTransparent =
false;
638 transferAfter(CurInfo,
MI);
642 if (CurInfo !=
Info.Exit) {
648 assert(CurInfo ==
Info.Exit &&
"InsertVSETVLI dataflow invariant violated");
656void RISCVInsertVSETVLIImpl::doPRE(MachineBasicBlock &
MBB) {
660 MachineBasicBlock *UnavailablePred =
nullptr;
661 VSETVLIInfo AvailableInfo;
663 const VSETVLIInfo &PredInfo = BlockInfo[
P->getNumber()].Exit;
668 }
else if (!AvailableInfo.
isValid()) {
669 AvailableInfo = PredInfo;
670 }
else if (AvailableInfo != PredInfo) {
677 if (!UnavailablePred || !AvailableInfo.
isValid())
715 VSETVLIInfo CurInfo = AvailableInfo;
716 int TransitionsRemoved = 0;
717 for (
const MachineInstr &
MI :
MBB) {
718 const VSETVLIInfo LastInfo = CurInfo;
719 const VSETVLIInfo LastOldInfo = OldInfo;
720 transferBefore(CurInfo,
MI);
721 transferBefore(OldInfo,
MI);
722 if (CurInfo == LastInfo)
723 TransitionsRemoved++;
724 if (LastOldInfo == OldInfo)
725 TransitionsRemoved--;
726 transferAfter(CurInfo,
MI);
727 transferAfter(OldInfo,
MI);
728 if (CurInfo == OldInfo)
732 if (CurInfo != OldInfo || TransitionsRemoved <= 0)
739 auto OldExit = BlockInfo[UnavailablePred->
getNumber()].Exit;
741 << UnavailablePred->
getName() <<
" with state "
742 << AvailableInfo <<
"\n");
743 BlockInfo[UnavailablePred->
getNumber()].Exit = AvailableInfo;
749 insertVSETVLI(*UnavailablePred, InsertPt,
751 AvailableInfo, OldExit);
758bool RISCVInsertVSETVLIImpl::canMutatePriorConfig(
759 const MachineInstr &PrevMI,
const MachineInstr &
MI,
760 const DemandedFields &Used, MachineInstr *&AVLDefToMove)
const {
761 AVLDefToMove =
nullptr;
765 if (!RISCVInstrInfo::isVLPreservingConfig(
MI)) {
769 if (
Used.VLZeroness) {
770 if (RISCVInstrInfo::isVLPreservingConfig(PrevMI))
777 auto &AVL =
MI.getOperand(1);
781 if (AVL.isReg() && AVL.getReg() != RISCV::X0) {
784 if (!VNI || !PrevVNI || VNI != PrevVNI) {
791 if (!AVL.getReg().isVirtual())
795 if (!
DefMI || !RISCVInstrInfo::isLoadImmediate(*
DefMI) ||
800 AVLDefToMove =
DefMI;
815 auto VType =
MI.getOperand(2).getImm();
819void RISCVInsertVSETVLIImpl::coalesceVSETVLIs(MachineBasicBlock &
MBB)
const {
820 MachineInstr *NextMI =
nullptr;
828 auto dropAVLUse = [&](MachineOperand &MO) {
829 if (!MO.isReg() || !MO.getReg().isVirtual())
838 if (VLOpDef &&
TII->isAddImmediate(*VLOpDef, OldVLReg) &&
846 RISCVInstrInfo::isXSfmmVectorConfigInstr(
MI)) {
851 if (!RISCVInstrInfo::isVectorConfigInstr(
MI)) {
853 if (
MI.isCall() ||
MI.isInlineAsm() ||
854 MI.modifiesRegister(RISCV::VL,
nullptr) ||
855 MI.modifiesRegister(RISCV::VTYPE,
nullptr))
860 if (!
MI.getOperand(0).isDead())
864 if (!
Used.usedVL() && !
Used.usedVTYPE()) {
865 dropAVLUse(
MI.getOperand(1));
868 MI.eraseFromParent();
869 NumCoalescedVSETVL++;
874 MachineInstr *AVLDefToMove =
nullptr;
875 if (canMutatePriorConfig(
MI, *NextMI, Used, AVLDefToMove)) {
876 if (!RISCVInstrInfo::isVLPreservingConfig(*NextMI)) {
879 MI.getOperand(0).setReg(DefReg);
880 MI.getOperand(0).setIsDead(
false);
883 dropAVLUse(
MI.getOperand(1));
905 SlotIndex NextMISlot =
908 LiveInterval::Segment S(MISlot, NextMISlot, DefVNI);
910 DefVNI->
def = MISlot;
927 NumCoalescedVSETVL++;
937 for (
auto *
MI : ToDelete) {
938 assert(
MI->getOpcode() == RISCV::ADDI);
944 MI->eraseFromParent();
972bool RISCVInsertVSETVLIImpl::canMutatePriorConfigWithTWiden(
973 const MachineInstr &PrevMI,
const MachineInstr &
MI)
const {
975 if (PrevMI.
getOpcode() != RISCV::PseudoVSETVLI)
978 if (
MI.getOpcode() != RISCV::PseudoSF_VSETTNT)
984 assert(CurrInfo.hasAVLReg() &&
"Invalid PseudoSF_VSETTNT without an AVLReg.");
986 auto AVLReg = CurrInfo.getAVLReg();
993 if (!RISCVInstrInfo::isXSfmmVectorConfigTMTKInstr(*AVLRegDefMI))
997 if (AVLRegDefMIInfo.getTWiden() != CurrInfo.getTWiden())
1000 if (AVLRegDefMIInfo.getSEW() != PrevInfo.
getSEW())
1010 if (PrevInfo.
getSEW() != CurrInfo.getSEW())
1013 if (PrevInfo.
getAltFmt() != CurrInfo.getAltFmt())
1020 unsigned KMAX = (CurrInfo.getSEW() >= 32) ? 1 : (32 / CurrInfo.getSEW());
1022 if (Fractional || LMul < (8 / KMAX))
1028void RISCVInsertVSETVLIImpl::coalesceVSETVLIsForTWiden(
1029 MachineBasicBlock &
MBB)
const {
1030 MachineInstr *NextMI =
nullptr;
1034 if (!RISCVInstrInfo::isVectorConfigInstr(
MI))
1039 if (canMutatePriorConfigWithTWiden(
MI, *NextMI)) {
1042 MI.getOperand(2).setImm(NextInfo.encodeVTYPE());
1053void RISCVInsertVSETVLIImpl::insertReadVL(MachineBasicBlock &
MBB) {
1055 MachineInstr &
MI = *
I++;
1056 if (RISCVInstrInfo::isFaultOnlyFirstLoad(
MI)) {
1057 Register VLOutput =
MI.getOperand(1).getReg();
1059 if (!
MI.getOperand(1).isDead()) {
1061 TII->get(RISCV::PseudoReadVL), VLOutput);
1064 SlotIndex NewDefSI =
1070 DefVNI->
def = NewDefSI;
1074 MI.getOperand(1).setReg(RISCV::X0);
1080bool RISCVInsertVSETVLIImpl::insertVSETMTK(MachineBasicBlock &
MBB,
1081 TKTMMode
Mode)
const {
1084 for (
auto &
MI :
MBB) {
1086 if (RISCVInstrInfo::isXSfmmVectorConfigTMTKInstr(
MI) ||
1092 unsigned Opcode = 0, OpNum = 0;
1098 Opcode = RISCV::PseudoSF_VSETTK;
1104 Opcode = RISCV::PseudoSF_VSETTM;
1108 assert(OpNum && Opcode &&
"Invalid OpNum or Opcode");
1110 MachineOperand &
Op =
MI.getOperand(OpNum);
1113 .
addDef(RISCV::X0, RegState::Dead)
1121 Op.setIsKill(
false);
1137 LiveIntervals *LISToUpdate) {
1148 VIA = RISCVVSETVLIInfoAnalysis(ST, LIS);
1150 assert(BlockInfo.empty() &&
"Expect empty block infos");
1153 bool HaveVectorOp =
false;
1156 for (
const MachineBasicBlock &
MBB : MF) {
1157 VSETVLIInfo TmpStatus;
1158 HaveVectorOp |= computeVLVTYPEChanges(
MBB, TmpStatus);
1161 BBInfo.
Exit = TmpStatus;
1163 <<
" is " << BBInfo.
Exit <<
"\n");
1168 if (!HaveVectorOp) {
1176 for (
const MachineBasicBlock &
MBB : MF) {
1177 WorkList.push(&
MBB);
1180 while (!WorkList.empty()) {
1181 const MachineBasicBlock &
MBB = *WorkList.front();
1183 computeIncomingVLVTYPE(
MBB);
1187 for (MachineBasicBlock &
MBB : MF)
1194 for (MachineBasicBlock &
MBB : MF)
1207 coalesceVSETVLIs(*
MBB);
1209 if (ST->hasVendorXSfmmbase()) {
1210 for (MachineBasicBlock &
MBB : MF)
1211 coalesceVSETVLIsForTWiden(
MBB);
1216 for (MachineBasicBlock &
MBB : MF)
1219 if (ST->hasVendorXSfmmbase()) {
1220 for (MachineBasicBlock &
MBB : MF) {
1221 insertVSETMTK(
MBB, VSETTM);
1222 insertVSETMTK(
MBB, VSETTK);
1227 return HaveVectorOp;
1232 return new RISCVInsertVSETVLILegacy();
1235bool RISCVInsertVSETVLILegacy::runOnMachineFunction(
MachineFunction &MF) {
1236 RISCVInsertVSETVLIImpl Impl;
1237 auto *LISWrapper = getAnalysisIfAvailable<LiveIntervalsWrapperPass>();
1238 LiveIntervals *LIS = LISWrapper ? &LISWrapper->getLIS() :
nullptr;
1239 return Impl.runOnMachineFunction(MF, LIS);
1245 RISCVInsertVSETVLIImpl Impl;
1247 bool Changed = Impl.runOnMachineFunction(MF, LIS);
1252 .preserve<LiveIntervalsAnalysis>()
1254 .preserve<LiveDebugVariablesAnalysis>()
MachineInstrBuilder MachineInstrBuilder & DefMI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
const HexagonInstrInfo * TII
Promote Memory to Register
uint64_t IntrinsicInst * II
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
This file builds on the ADT/GraphTraits.h file to build a generic graph post order iterator.
static VSETVLIInfo adjustIncoming(const VSETVLIInfo &PrevInfo, const VSETVLIInfo &NewInfo, DemandedFields &Demanded)
#define RISCV_INSERT_VSETVLI_NAME
MachineRegisterInfo & MRI
static cl::opt< RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode > Mode("regalloc-enable-advisor", cl::Hidden, cl::init(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default), cl::desc("Enable regalloc advisor mode"), cl::values(clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Default, "default", "Default"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Release, "release", "precompiled"), clEnumValN(RegAllocEvictionAdvisorAnalysisLegacy::AdvisorMode::Development, "development", "for training")))
SI Optimize VGPR LiveRange
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.
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
Represents analyses that only rely on functions' control flow.
FunctionPass class - This class is used to implement most global optimizations.
LiveInterval - This class represents the liveness of a register, or stack slot.
void setWeight(float Value)
void removeAllRegUnitsForPhysReg(MCRegister Reg)
Remove associated live ranges for the register units associated with Reg.
MachineInstr * getInstructionFromIndex(SlotIndex index) const
Returns the instruction associated with the given index.
SlotIndex InsertMachineInstrInMaps(MachineInstr &MI)
LLVM_ABI void handleMove(MachineInstr &MI, bool UpdateFlags=false)
Call this method to notify LiveIntervals that instruction MI has been moved within a basic block.
SlotIndexes * getSlotIndexes() const
SlotIndex getInstructionIndex(const MachineInstr &Instr) const
Returns the base index of the given instruction.
void RemoveMachineInstrFromMaps(MachineInstr &MI)
SlotIndex getMBBEndIdx(const MachineBasicBlock *mbb) const
Return the last index in the given basic block.
LiveInterval & getInterval(Register Reg)
void removeInterval(Register Reg)
Interval removal.
LLVM_ABI bool shrinkToUses(LiveInterval *li, SmallVectorImpl< MachineInstr * > *dead=nullptr)
After removing some uses of a register, shrink its live range to just the remaining uses.
LLVM_ABI void extendToIndices(LiveRange &LR, ArrayRef< SlotIndex > Indices, ArrayRef< SlotIndex > Undefs)
Extend the live range LR to reach all points in Indices.
LLVM_ABI void splitSeparateComponents(LiveInterval &LI, SmallVectorImpl< LiveInterval * > &SplitLIs)
Split separate components in LiveInterval LI into separate intervals.
MachineBasicBlock * getMBBFromIndex(SlotIndex index) const
LiveInterval & createAndComputeVirtRegInterval(Register Reg)
LLVM_ABI iterator addSegment(Segment S)
Add the specified Segment to this range, merging segments as appropriate.
const Segment * getSegmentContaining(SlotIndex Idx) const
Return the segment that contains the specified index, or null if there is none.
bool liveAt(SlotIndex index) const
bool overlaps(const LiveRange &other) const
overlaps - Return true if the intersection of the two live ranges is not empty.
VNInfo * getVNInfoBefore(SlotIndex Idx) const
getVNInfoBefore - Return the VNInfo that is live up to but not necessarily including Idx,...
bool containsOneValue() const
LLVM_ABI void removeSegment(SlotIndex Start, SlotIndex End, bool RemoveDeadValNo=false)
Remove the specified interval from this live range.
VNInfo * getVNInfoAt(SlotIndex Idx) const
getVNInfoAt - Return the VNInfo that is live at Idx, or NULL.
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
LLVM_ABI iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
unsigned succ_size() const
LLVM_ABI DebugLoc findDebugLoc(instr_iterator MBBI)
Find the next valid DebugLoc starting at MBBI, skipping any debug instructions.
iterator_range< iterator > terminators()
iterator_range< succ_iterator > successors()
LLVM_ABI instr_iterator getFirstInstrTerminator()
Same getFirstTerminator but it ignores bundles and return an instr_iterator instead.
iterator_range< pred_iterator > predecessors()
MachineInstrBundleIterator< MachineInstr > iterator
LLVM_ABI StringRef getName() const
Return the name of the corresponding LLVM basic block, or an empty string.
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.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
unsigned getNumBlockIDs() const
getNumBlockIDs - Return the number of MBB ID's allocated.
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 & addDef(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a virtual register definition operand.
Representation of each machine instruction.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const MachineBasicBlock * getParent() const
const MCInstrDesc & getDesc() const
Returns the target instruction descriptor of this MachineInstr.
const MachineOperand & getOperand(unsigned i) const
LLVM_ABI MachineInstrBundleIterator< MachineInstr > eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
LLVM_ABI void moveBefore(MachineInstr *MovePos)
Move the instruction before MovePos.
MachineOperand class - Representation of each machine instruction operand.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
LLVM_ABI void setReg(Register Reg)
Change the register this operand corresponds to.
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
void setIsKill(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)
bool use_nodbg_empty(Register RegNo) const
use_nodbg_empty - Return true if there are no non-Debug instructions using the specified register.
const TargetRegisterInfo * getTargetRegisterInfo() const
LLVM_ABI LLVM_READONLY MachineInstr * getUniqueVRegDef(Register Reg) const
getUniqueVRegDef - Return the unique machine instr that defines the specified virtual register or nul...
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
const RISCVOptions & getCLOpts() const
bool hasVInstructions() const
const RISCVRegisterInfo * getRegisterInfo() const override
const RISCVInstrInfo * getInstrInfo() const override
VSETVLIInfo getInfoForVSETVLI(const MachineInstr &MI) const
VSETVLIInfo computeInfoForInstr(const MachineInstr &MI) const
Defines the abstract state with which the forward dataflow models the values of the VL and VTYPE regi...
bool hasSameVTYPE(const VSETVLIInfo &Other) const
unsigned getTWiden() const
bool getMaskAgnostic() const
VSETVLIInfo intersect(const VSETVLIInfo &Other) const
void setAVLImm(unsigned Imm)
unsigned getSEWLMULRatio() const
void setVTYPE(unsigned VType)
Register getAVLReg() const
bool getTailAgnostic() const
bool hasSameVLMAX(const VSETVLIInfo &Other) const
bool isCompatible(const DemandedFields &Used, const VSETVLIInfo &Require, const LiveIntervals *LIS) const
bool hasSameAVL(const VSETVLIInfo &Other) const
const VNInfo * getAVLVNInfo() const
bool hasSEWLMULRatioOnly() const
RISCVVType::VLMUL getVLMUL() const
bool hasEquallyZeroAVL(const VSETVLIInfo &Other, const LiveIntervals *LIS) const
static VSETVLIInfo getUnknown()
void setAVL(const VSETVLIInfo &Info)
Wrapper class representing virtual and physical registers.
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
SlotIndex - An opaque wrapper around machine indexes.
SlotIndex getRegSlot(bool EC=false) const
Returns the register use/def slot in the current instruction for a normal or early-clobber def.
SlotIndex getInstructionIndex(const MachineInstr &MI, bool IgnoreBundle=false) const
Returns the base index for the given instruction.
void push_back(const T &Elt)
VNInfo - Value Number Information.
SlotIndex def
The index of the defining instruction.
bool isPHIDef() const
Returns true if this value is defined by a PHI instruction (or was, PHI instructions may have been el...
Pass manager infrastructure for declaring and invalidating analyses.
static unsigned getTMOpNum(const MCInstrDesc &Desc)
static bool hasTWidenOp(uint64_t TSFlags)
static unsigned getTKOpNum(const MCInstrDesc &Desc)
static unsigned getVLOpNum(const MCInstrDesc &Desc)
static bool hasTKOp(uint64_t TSFlags)
static bool hasVLOp(uint64_t TSFlags)
static bool hasTMOp(uint64_t TSFlags)
static bool hasSEWOp(uint64_t TSFlags)
LLVM_ABI std::optional< VLMUL > getSameRatioLMUL(unsigned Ratio, unsigned EEW)
LLVM_ABI std::pair< unsigned, bool > decodeVLMUL(VLMUL VLMul)
static const MachineOperand & getVLOp(const MachineInstr &MI)
DemandedFields getDemanded(const MachineInstr &MI, const RISCVSubtarget *ST)
Return the fields and properties demanded by the provided instruction.
bool areCompatibleVTYPEs(uint64_t CurVType, uint64_t NewVType, const DemandedFields &Used)
Return true if moving from CurVType to NewVType is indistinguishable from the perspective of an instr...
static VNInfo * getVNInfoFromReg(Register Reg, const MachineInstr &MI, const LiveIntervals *LIS)
Given a virtual register Reg, return the corresponding VNInfo for it.
bool isVectorCopy(const TargetRegisterInfo *TRI, const MachineInstr &MI)
Return true if MI is a copy that will be lowered to one or more vmvNr.vs.
This is an optimization pass for GlobalISel generic memory operations.
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
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
unsigned Log2_32(uint32_t Value)
Return the floor log base 2 of the specified value, -1 if the value is zero.
auto reverse(ContainerTy &&C)
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...
auto post_order(const T &G)
Post-order traversal of a graph.
DWARFExpression::Operation Op
char & RISCVInsertVSETVLILegacyID
FunctionPass * createRISCVInsertVSETVLILegacyPass()
Returns an instance of the Insert VSETVLI pass.
LLVM_ABI Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
Which subfields of VL or VTYPE have values we need to preserve?
static DemandedFields all()
enum llvm::RISCV::DemandedFields::@326061152055210015167034143142117063364004052074 SEW
enum llvm::RISCV::DemandedFields::@201276154261047021277240313173154105356124146047 LMUL