LLVM 24.0.0git
DetectDeadLanes.cpp
Go to the documentation of this file.
1//===- DetectDeadLanes.cpp - SubRegister Lane Usage Analysis --*- C++ -*---===//
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/// \file
10/// Analysis that tracks defined/used subregister lanes across COPY instructions
11/// and instructions that get lowered to a COPY (PHI, REG_SEQUENCE,
12/// INSERT_SUBREG, EXTRACT_SUBREG).
13/// The information is used to detect dead definitions and the usage of
14/// (completely) undefined values and mark the operands as such.
15/// This pass is necessary because the dead/undef status is not obvious anymore
16/// when subregisters are involved.
17///
18/// Example:
19/// %0 = some definition
20/// %1 = IMPLICIT_DEF
21/// %2 = REG_SEQUENCE %0, sub0, %1, sub1
22/// %3 = EXTRACT_SUBREG %2, sub1
23/// = use %3
24/// The %0 definition is dead and %3 contains an undefined value.
25//
26//===----------------------------------------------------------------------===//
27
34#include "llvm/Pass.h"
35#include "llvm/Support/Debug.h"
37
38using namespace llvm;
39
40#define DEBUG_TYPE "detect-dead-lanes"
41
43 const TargetRegisterInfo *TRI)
44 : MRI(MRI), TRI(TRI) {
45 unsigned NumVirtRegs = MRI->getNumVirtRegs();
46 VRegInfos = std::unique_ptr<VRegInfo[]>(new VRegInfo[NumVirtRegs]);
47 WorklistMembers.resize(NumVirtRegs);
48 DefinedByCopy.resize(NumVirtRegs);
49}
50
51/// Returns true if \p MI will get lowered to a series of COPY instructions.
52/// We call this a COPY-like instruction.
53static bool lowersToCopies(const MachineInstr &MI) {
54 // Note: We could support instructions with MCInstrDesc::isRegSequenceLike(),
55 // isExtractSubRegLike(), isInsertSubregLike() in the future even though they
56 // are not lowered to a COPY.
57 switch (MI.getOpcode()) {
58 case TargetOpcode::COPY:
59 case TargetOpcode::PHI:
60 case TargetOpcode::INSERT_SUBREG:
61 case TargetOpcode::REG_SEQUENCE:
62 case TargetOpcode::EXTRACT_SUBREG:
63 return true;
64 }
65 return false;
66}
67
68static bool isCrossCopy(const MachineRegisterInfo &MRI,
69 const MachineInstr &MI,
70 const TargetRegisterClass *DstRC,
71 const MachineOperand &MO) {
73 Register SrcReg = MO.getReg();
74 const TargetRegisterClass *SrcRC = MRI.getRegClass(SrcReg);
75 if (DstRC == SrcRC)
76 return false;
77
78 unsigned SrcSubIdx = MO.getSubReg();
79
81 unsigned DstSubIdx = 0;
82 switch (MI.getOpcode()) {
83 case TargetOpcode::INSERT_SUBREG:
84 if (MO.getOperandNo() == 2)
85 DstSubIdx = MI.getOperand(3).getImm();
86 break;
87 case TargetOpcode::REG_SEQUENCE: {
88 unsigned OpNum = MO.getOperandNo();
89 DstSubIdx = MI.getOperand(OpNum+1).getImm();
90 break;
91 }
92 case TargetOpcode::EXTRACT_SUBREG: {
93 unsigned SubReg = MI.getOperand(2).getImm();
94 SrcSubIdx = TRI.composeSubRegIndices(SubReg, SrcSubIdx);
95 }
96 }
97
98 return !TRI.findCommonRegClass(SrcRC, SrcSubIdx, DstRC, DstSubIdx);
99}
100
101void DeadLaneDetector::addUsedLanesOnOperand(const MachineOperand &MO,
102 LaneBitmask UsedLanes) {
103 if (!MO.readsReg())
104 return;
105 Register MOReg = MO.getReg();
106 if (!MOReg.isVirtual())
107 return;
108
109 unsigned MOSubReg = MO.getSubReg();
110 if (MOSubReg != 0)
111 UsedLanes = TRI->composeSubRegIndexLaneMask(MOSubReg, UsedLanes);
112 UsedLanes &= MRI->getMaxLaneMaskForVReg(MOReg);
113
114 unsigned MORegIdx = MOReg.virtRegIndex();
115 DeadLaneDetector::VRegInfo &MORegInfo = VRegInfos[MORegIdx];
116 LaneBitmask PrevUsedLanes = MORegInfo.UsedLanes;
117 // Any change at all?
118 if ((UsedLanes & ~PrevUsedLanes).none())
119 return;
120
121 // Set UsedLanes and remember instruction for further propagation.
122 MORegInfo.UsedLanes = PrevUsedLanes | UsedLanes;
123 if (DefinedByCopy.test(MORegIdx))
124 PutInWorklist(MORegIdx);
125}
126
127void DeadLaneDetector::transferUsedLanesStep(const MachineInstr &MI,
128 LaneBitmask UsedLanes) {
129 for (const MachineOperand &MO : MI.uses()) {
130 if (!MO.isReg() || !MO.getReg().isVirtual())
131 continue;
132 LaneBitmask UsedOnMO = transferUsedLanes(MI, UsedLanes, MO);
133 addUsedLanesOnOperand(MO, UsedOnMO);
134 }
135}
136
139 LaneBitmask UsedLanes,
140 const MachineOperand &MO) const {
141 unsigned OpNum = MO.getOperandNo();
143 DefinedByCopy[MI.getOperand(0).getReg().virtRegIndex()]);
144
145 switch (MI.getOpcode()) {
146 case TargetOpcode::COPY:
147 case TargetOpcode::PHI:
148 return UsedLanes;
149 case TargetOpcode::REG_SEQUENCE: {
150 assert(OpNum % 2 == 1);
151 unsigned SubIdx = MI.getOperand(OpNum + 1).getImm();
152 return TRI->reverseComposeSubRegIndexLaneMask(SubIdx, UsedLanes);
153 }
154 case TargetOpcode::INSERT_SUBREG: {
155 unsigned SubIdx = MI.getOperand(3).getImm();
156 LaneBitmask MO2UsedLanes =
157 TRI->reverseComposeSubRegIndexLaneMask(SubIdx, UsedLanes);
158 if (OpNum == 2)
159 return MO2UsedLanes;
160
161 const MachineOperand &Def = MI.getOperand(0);
162 Register DefReg = Def.getReg();
163 const TargetRegisterClass *RC = MRI->getRegClass(DefReg);
164 LaneBitmask MO1UsedLanes;
165 if (RC->CoveredBySubRegs)
166 MO1UsedLanes = UsedLanes & ~TRI->getSubRegIndexLaneMask(SubIdx);
167 else
168 MO1UsedLanes = RC->LaneMask;
169
170 assert(OpNum == 1);
171 return MO1UsedLanes;
172 }
173 case TargetOpcode::EXTRACT_SUBREG: {
174 assert(OpNum == 1);
175 unsigned SubIdx = MI.getOperand(2).getImm();
176 return TRI->composeSubRegIndexLaneMask(SubIdx, UsedLanes);
177 }
178 default:
179 llvm_unreachable("function must be called with COPY-like instruction");
180 }
181}
182
183void DeadLaneDetector::transferDefinedLanesStep(const MachineOperand &Use,
184 LaneBitmask DefinedLanes) {
185 if (!Use.readsReg())
186 return;
187 // Check whether the operand writes a vreg and is part of a COPY-like
188 // instruction.
189 const MachineInstr &MI = *Use.getParent();
190 if (MI.getDesc().getNumDefs() != 1)
191 return;
192 // FIXME: PATCHPOINT instructions announce a Def that does not always exist,
193 // they really need to be modeled differently!
194 if (MI.getOpcode() == TargetOpcode::PATCHPOINT)
195 return;
196 const MachineOperand &Def = *MI.defs().begin();
197 Register DefReg = Def.getReg();
198 if (!DefReg.isVirtual())
199 return;
200 unsigned DefRegIdx = DefReg.virtRegIndex();
201 if (!DefinedByCopy.test(DefRegIdx))
202 return;
203
204 unsigned OpNum = Use.getOperandNo();
205 DefinedLanes =
206 TRI->reverseComposeSubRegIndexLaneMask(Use.getSubReg(), DefinedLanes);
207 DefinedLanes = transferDefinedLanes(Def, OpNum, DefinedLanes);
208
209 VRegInfo &RegInfo = VRegInfos[DefRegIdx];
210 LaneBitmask PrevDefinedLanes = RegInfo.DefinedLanes;
211 // Any change at all?
212 if ((DefinedLanes & ~PrevDefinedLanes).none())
213 return;
214
215 RegInfo.DefinedLanes = PrevDefinedLanes | DefinedLanes;
216 PutInWorklist(DefRegIdx);
217}
218
220 const MachineOperand &Def, unsigned OpNum, LaneBitmask DefinedLanes) const {
221 const MachineInstr &MI = *Def.getParent();
222 // Translate DefinedLanes if necessary.
223 switch (MI.getOpcode()) {
224 case TargetOpcode::REG_SEQUENCE: {
225 unsigned SubIdx = MI.getOperand(OpNum + 1).getImm();
226 DefinedLanes = TRI->composeSubRegIndexLaneMask(SubIdx, DefinedLanes);
227 DefinedLanes &= TRI->getSubRegIndexLaneMask(SubIdx);
228 break;
229 }
230 case TargetOpcode::INSERT_SUBREG: {
231 unsigned SubIdx = MI.getOperand(3).getImm();
232 if (OpNum == 2) {
233 DefinedLanes = TRI->composeSubRegIndexLaneMask(SubIdx, DefinedLanes);
234 DefinedLanes &= TRI->getSubRegIndexLaneMask(SubIdx);
235 } else {
236 assert(OpNum == 1 && "INSERT_SUBREG must have two operands");
237 // Ignore lanes defined by operand 2.
238 DefinedLanes &= ~TRI->getSubRegIndexLaneMask(SubIdx);
239 }
240 break;
241 }
242 case TargetOpcode::EXTRACT_SUBREG: {
243 unsigned SubIdx = MI.getOperand(2).getImm();
244 assert(OpNum == 1 && "EXTRACT_SUBREG must have one register operand only");
245 DefinedLanes = TRI->reverseComposeSubRegIndexLaneMask(SubIdx, DefinedLanes);
246 break;
247 }
248 case TargetOpcode::COPY:
249 case TargetOpcode::PHI:
250 break;
251 default:
252 llvm_unreachable("function must be called with COPY-like instruction");
253 }
254
255 assert(Def.getSubReg() == 0 &&
256 "Should not have subregister defs in machine SSA phase");
257 DefinedLanes &= MRI->getMaxLaneMaskForVReg(Def.getReg());
258 return DefinedLanes;
259}
260
261LaneBitmask DeadLaneDetector::determineInitialDefinedLanes(Register Reg) {
262 // Live-In or unused registers have no definition but are considered fully
263 // defined.
264 if (!MRI->hasOneDef(Reg))
265 return LaneBitmask::getAll();
266
267 const MachineOperand &Def = *MRI->def_begin(Reg);
268 const MachineInstr &DefMI = *Def.getParent();
269 if (lowersToCopies(DefMI)) {
270 // Start optimisatically with no used or defined lanes for copy
271 // instructions. The following dataflow analysis will add more bits.
272 unsigned RegIdx = Register(Reg).virtRegIndex();
273 DefinedByCopy.set(RegIdx);
274 PutInWorklist(RegIdx);
275
276 if (Def.isDead())
277 return LaneBitmask::getNone();
278
279 // COPY/PHI can copy across unrelated register classes (example: float/int)
280 // with incompatible subregister structure. Do not include these in the
281 // dataflow analysis since we cannot transfer lanemasks in a meaningful way.
282 const TargetRegisterClass *DefRC = MRI->getRegClass(Reg);
283
284 // Determine initially DefinedLanes.
285 LaneBitmask DefinedLanes;
286 for (const MachineOperand &MO : DefMI.uses()) {
287 if (!MO.isReg() || !MO.readsReg())
288 continue;
289 Register MOReg = MO.getReg();
290 if (!MOReg)
291 continue;
292
293 LaneBitmask MODefinedLanes;
294 if (MOReg.isPhysical()) {
295 MODefinedLanes = LaneBitmask::getAll();
296 } else if (isCrossCopy(*MRI, DefMI, DefRC, MO)) {
297 MODefinedLanes = LaneBitmask::getAll();
298 } else {
299 assert(MOReg.isVirtual());
300 if (MRI->hasOneDef(MOReg)) {
301 const MachineOperand &MODef = *MRI->def_begin(MOReg);
302 const MachineInstr &MODefMI = *MODef.getParent();
303 // Bits from copy-like operations will be added later.
304 if (lowersToCopies(MODefMI) || MODefMI.isImplicitDef())
305 continue;
306 }
307 unsigned MOSubReg = MO.getSubReg();
308 MODefinedLanes = MRI->getMaxLaneMaskForVReg(MOReg);
309 MODefinedLanes = TRI->reverseComposeSubRegIndexLaneMask(
310 MOSubReg, MODefinedLanes);
311 }
312
313 unsigned OpNum = MO.getOperandNo();
314 DefinedLanes |= transferDefinedLanes(Def, OpNum, MODefinedLanes);
315 }
316 return DefinedLanes;
317 }
318 if (DefMI.isImplicitDef() || Def.isDead())
319 return LaneBitmask::getNone();
320
321 assert(Def.getSubReg() == 0 &&
322 "Should not have subregister defs in machine SSA phase");
323 return MRI->getMaxLaneMaskForVReg(Reg);
324}
325
326LaneBitmask DeadLaneDetector::determineInitialUsedLanes(Register Reg) {
327 LaneBitmask UsedLanes = LaneBitmask::getNone();
328 for (const MachineOperand &MO : MRI->use_nodbg_operands(Reg)) {
329 if (!MO.readsReg())
330 continue;
331
332 const MachineInstr &UseMI = *MO.getParent();
333 if (UseMI.isKill())
334 continue;
335
336 unsigned SubReg = MO.getSubReg();
337 if (lowersToCopies(UseMI)) {
338 assert(UseMI.getDesc().getNumDefs() == 1);
339 const MachineOperand &Def = *UseMI.defs().begin();
340 Register DefReg = Def.getReg();
341 // The used lanes of COPY-like instruction operands are determined by the
342 // following dataflow analysis.
343 if (DefReg.isVirtual()) {
344 // But ignore copies across incompatible register classes.
345 bool CrossCopy = false;
346 if (lowersToCopies(UseMI)) {
347 const TargetRegisterClass *DstRC = MRI->getRegClass(DefReg);
348 CrossCopy = isCrossCopy(*MRI, UseMI, DstRC, MO);
349 if (CrossCopy)
350 LLVM_DEBUG(dbgs() << "Copy across incompatible classes: " << UseMI);
351 }
352
353 if (!CrossCopy)
354 continue;
355 }
356 }
357
358 // Shortcut: All lanes are used.
359 if (SubReg == 0)
360 return MRI->getMaxLaneMaskForVReg(Reg);
361
362 UsedLanes |= TRI->getSubRegIndexLaneMask(SubReg);
363 }
364 return UsedLanes;
365}
366
367namespace {
368
369class DetectDeadLanes {
370public:
371 bool run(MachineFunction &MF);
372
373private:
374 /// update the operand status.
375 /// The first return value shows whether MF been changed.
376 /// The second return value indicates we need to call
377 /// DeadLaneDetector::computeSubRegisterLaneBitInfo and this function again
378 /// to propagate changes.
379 std::pair<bool, bool>
380 modifySubRegisterOperandStatus(const DeadLaneDetector &DLD,
381 MachineFunction &MF);
382
383 bool isUndefRegAtInput(const MachineOperand &MO,
384 const DeadLaneDetector::VRegInfo &RegInfo) const;
385
386 bool isUndefInput(const DeadLaneDetector &DLD, const MachineOperand &MO,
387 bool *CrossCopy) const;
388
389 const MachineRegisterInfo *MRI = nullptr;
390 const TargetRegisterInfo *TRI = nullptr;
391};
392
393struct DetectDeadLanesLegacy : public MachineFunctionPass {
394 static char ID;
395 DetectDeadLanesLegacy() : MachineFunctionPass(ID) {}
396
397 StringRef getPassName() const override { return "Detect Dead Lanes"; }
398
399 void getAnalysisUsage(AnalysisUsage &AU) const override {
400 AU.setPreservesCFG();
401 AU.addPreserved<MachineRegisterClassInfoWrapperPass>();
403 }
404
405 bool runOnMachineFunction(MachineFunction &MF) override {
406 return DetectDeadLanes().run(MF);
407 }
408};
409
410} // end anonymous namespace
411
412char DetectDeadLanesLegacy::ID = 0;
413char &llvm::DetectDeadLanesID = DetectDeadLanesLegacy::ID;
414
415INITIALIZE_PASS(DetectDeadLanesLegacy, DEBUG_TYPE, "Detect Dead Lanes", false,
416 false)
417
418bool DetectDeadLanes::isUndefRegAtInput(
420 unsigned SubReg = MO.getSubReg();
421 LaneBitmask Mask = TRI->getSubRegIndexLaneMask(SubReg);
422 return (RegInfo.DefinedLanes & RegInfo.UsedLanes & Mask).none();
423}
424
425bool DetectDeadLanes::isUndefInput(const DeadLaneDetector &DLD,
426 const MachineOperand &MO,
427 bool *CrossCopy) const {
428 if (!MO.isUse())
429 return false;
430 const MachineInstr &MI = *MO.getParent();
431 if (!lowersToCopies(MI))
432 return false;
433 const MachineOperand &Def = MI.getOperand(0);
434 Register DefReg = Def.getReg();
435 if (!DefReg.isVirtual())
436 return false;
437 unsigned DefRegIdx = DefReg.virtRegIndex();
438 if (!DLD.isDefinedByCopy(DefRegIdx))
439 return false;
440
441 const DeadLaneDetector::VRegInfo &DefRegInfo = DLD.getVRegInfo(DefRegIdx);
442 LaneBitmask UsedLanes = DLD.transferUsedLanes(MI, DefRegInfo.UsedLanes, MO);
443 if (UsedLanes.any())
444 return false;
445
446 Register MOReg = MO.getReg();
447 if (MOReg.isVirtual()) {
448 const TargetRegisterClass *DstRC = MRI->getRegClass(DefReg);
449 *CrossCopy = isCrossCopy(*MRI, MI, DstRC, MO);
450 }
451 return true;
452}
453
455 // First pass: Populate defs/uses of vregs with initial values
456 unsigned NumVirtRegs = MRI->getNumVirtRegs();
457 for (unsigned RegIdx = 0; RegIdx < NumVirtRegs; ++RegIdx) {
459
460 // Determine used/defined lanes and add copy instructions to worklist.
461 VRegInfo &Info = VRegInfos[RegIdx];
462 Info.DefinedLanes = determineInitialDefinedLanes(Reg);
463 Info.UsedLanes = determineInitialUsedLanes(Reg);
464 }
465
466 // Iterate as long as defined lanes/used lanes keep changing.
467 while (!Worklist.empty()) {
468 unsigned RegIdx = Worklist.front();
469 Worklist.pop_front();
470 WorklistMembers.reset(RegIdx);
471 VRegInfo &Info = VRegInfos[RegIdx];
473
474 // Transfer UsedLanes to operands of DefMI (backwards dataflow).
475 MachineOperand &Def = *MRI->def_begin(Reg);
476 const MachineInstr &MI = *Def.getParent();
477 transferUsedLanesStep(MI, Info.UsedLanes);
478 // Transfer DefinedLanes to users of Reg (forward dataflow).
479 for (const MachineOperand &MO : MRI->use_nodbg_operands(Reg))
480 transferDefinedLanesStep(MO, Info.DefinedLanes);
481 }
482
483 LLVM_DEBUG({
484 dbgs() << "Defined/Used lanes:\n";
485 for (unsigned RegIdx = 0; RegIdx < NumVirtRegs; ++RegIdx) {
487 const VRegInfo &Info = VRegInfos[RegIdx];
488 dbgs() << printReg(Reg, nullptr)
489 << " Used: " << PrintLaneMask(Info.UsedLanes)
490 << " Def: " << PrintLaneMask(Info.DefinedLanes) << '\n';
491 }
492 dbgs() << "\n";
493 });
494}
495
496std::pair<bool, bool>
497DetectDeadLanes::modifySubRegisterOperandStatus(const DeadLaneDetector &DLD,
498 MachineFunction &MF) {
499 bool Changed = false;
500 bool Again = false;
501 // Mark operands as dead/unused.
502 for (MachineBasicBlock &MBB : MF) {
503 for (MachineInstr &MI : MBB) {
504 for (MachineOperand &MO : MI.operands()) {
505 if (!MO.isReg())
506 continue;
507 Register Reg = MO.getReg();
508 if (!Reg.isVirtual())
509 continue;
510 unsigned RegIdx = Reg.virtRegIndex();
511 const DeadLaneDetector::VRegInfo &RegInfo = DLD.getVRegInfo(RegIdx);
512 if (MO.isDef() && !MO.isDead() && RegInfo.UsedLanes.none()) {
514 << "Marking operand '" << MO << "' as dead in " << MI);
515 MO.setIsDead();
516 Changed = true;
517 }
518 if (MO.readsReg()) {
519 bool CrossCopy = false;
520 if (isUndefRegAtInput(MO, RegInfo)) {
522 << "Marking operand '" << MO << "' as undef in " << MI);
523 MO.setIsUndef();
524 Changed = true;
525 } else if (isUndefInput(DLD, MO, &CrossCopy)) {
527 << "Marking operand '" << MO << "' as undef in " << MI);
528 MO.setIsUndef();
529 Changed = true;
530 if (CrossCopy)
531 Again = true;
532 }
533 }
534 }
535 }
536 }
537
538 return std::make_pair(Changed, Again);
539}
540
544 if (!DetectDeadLanes().run(MF))
545 return PreservedAnalyses::all();
547 PA.preserveSet<CFGAnalyses>();
548 return PA;
549}
550
551bool DetectDeadLanes::run(MachineFunction &MF) {
552 // Don't bother if we won't track subregister liveness later. This pass is
553 // required for correctness if subregister liveness is enabled because the
554 // register coalescer cannot deal with hidden dead defs. However without
555 // subregister liveness enabled, the expected benefits of this pass are small
556 // so we safe the compile time.
557 MRI = &MF.getRegInfo();
558 if (!MRI->subRegLivenessEnabled()) {
559 LLVM_DEBUG(dbgs() << "Skipping Detect dead lanes pass\n");
560 return false;
561 }
562
563 TRI = MRI->getTargetRegisterInfo();
564
565 DeadLaneDetector DLD(MRI, TRI);
566
567 bool Changed = false;
568 bool Again;
569 do {
571 bool LocalChanged;
572 std::tie(LocalChanged, Again) = modifySubRegisterOperandStatus(DLD, MF);
573 Changed |= LocalChanged;
574 } while (Again);
575
576 return Changed;
577}
MachineInstrBuilder & UseMI
MachineInstrBuilder MachineInstrBuilder & DefMI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
aarch64 promote const
MachineBasicBlock & MBB
static bool isCrossCopy(const MachineRegisterInfo &MRI, const MachineInstr &MI, const TargetRegisterClass *DstRC, const MachineOperand &MO)
static bool lowersToCopies(const MachineInstr &MI)
Returns true if MI will get lowered to a series of COPY instructions.
Analysis that tracks defined/used subregister lanes across COPY instructions and instructions that ge...
#define DEBUG_TYPE
IRTranslator LLVM IR MI
Register Reg
Register const TargetRegisterInfo * TRI
Promote Memory to Register
Definition Mem2Reg.cpp:110
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition PassSupport.h:56
#define LLVM_DEBUG(...)
Definition Debug.h:119
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:
Definition Pass.cpp:275
bool test(unsigned Idx) const
Returns true if bit Idx is set.
Definition BitVector.h:482
BitVector & set()
Set all bits in the bitvector.
Definition BitVector.h:366
Represents analyses that only rely on functions' control flow.
Definition Analysis.h:73
LLVM_ABI LaneBitmask transferUsedLanes(const MachineInstr &MI, LaneBitmask UsedLanes, const MachineOperand &MO) const
Given a mask UsedLanes used from the output of instruction MI determine which lanes are used from ope...
LLVM_ABI DeadLaneDetector(const MachineRegisterInfo *MRI, const TargetRegisterInfo *TRI)
bool isDefinedByCopy(unsigned RegIdx) const
LLVM_ABI LaneBitmask transferDefinedLanes(const MachineOperand &Def, unsigned OpNum, LaneBitmask DefinedLanes) const
Given a mask DefinedLanes of lanes defined at operand OpNum of COPY-like instruction,...
LLVM_ABI void computeSubRegisterLaneBitInfo()
Update the DefinedLanes and the UsedLanes for all virtual registers.
const VRegInfo & getVRegInfo(unsigned RegIdx) const
LLVM_ABI PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
const bool CoveredBySubRegs
Whether a combination of subregisters can cover every register in the class.
const LaneBitmask LaneMask
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.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Representation of each machine instruction.
bool isImplicitDef() const
MachineOperand class - Representation of each machine instruction operand.
unsigned getSubReg() const
LLVM_ABI unsigned getOperandNo() const
Returns the index of this operand in the instruction that it belongs to.
bool readsReg() const
readsReg - Returns true if this operand reads the previous value of its register.
bool isReg() const
isReg - Tests if this is a MO_Register operand.
void setIsDead(bool Val=true)
MachineInstr * getParent()
getParent - Return the instruction that this operand belongs to.
void setIsUndef(bool Val=true)
Register getReg() const
getReg - Returns the register number.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
def_iterator def_begin(Register RegNo) const
bool hasOneDef(Register RegNo) const
Return true if there is exactly one operand defining the specified register.
const TargetRegisterInfo * getTargetRegisterInfo() const
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
Wrapper class representing virtual and physical registers.
Definition Register.h:20
static Register index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
Definition Register.h:72
unsigned virtRegIndex() const
Convert a virtual register number to a 0-based index.
Definition Register.h:87
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
Definition Register.h:79
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
Definition Register.h:83
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
A Use represents the edge between a Value definition and its users.
Definition Use.h:35
LLVM_ABI unsigned getOperandNo() const
Return the operand # of this use in its User.
Definition Use.cpp:36
Changed
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
DXILDebugInfoMap run(Module &M)
NodeAddr< DefNode * > Def
Definition RDFGraph.h:384
This is an optimization pass for GlobalISel generic memory operations.
Printable PrintLaneMask(LaneBitmask LaneMask)
Create Printable object to print LaneBitmasks on a raw_ostream.
Definition LaneBitmask.h:92
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
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
LLVM_ABI char & DetectDeadLanesID
This pass adds dead/undef flags after analyzing subregister lanes.
LLVM_ABI Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
MCRegisterClass TargetRegisterClass
Definition FastISel.h:58
Contains a bitmask of which lanes of a given virtual register are defined and which ones are actually...
static constexpr LaneBitmask getAll()
Definition LaneBitmask.h:82
constexpr bool none() const
Definition LaneBitmask.h:52
constexpr bool any() const
Definition LaneBitmask.h:53
static constexpr LaneBitmask getNone()
Definition LaneBitmask.h:81