LLVM  5.0.0
DetectDeadLanes.cpp
Go to the documentation of this file.
1 //===- DetectDeadLanes.cpp - SubRegister Lane Usage Analysis --*- C++ -*---===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 /// \file
11 /// Analysis that tracks defined/used subregister lanes across COPY instructions
12 /// and instructions that get lowered to a COPY (PHI, REG_SEQUENCE,
13 /// INSERT_SUBREG, EXTRACT_SUBREG).
14 /// The information is used to detect dead definitions and the usage of
15 /// (completely) undefined values and mark the operands as such.
16 /// This pass is necessary because the dead/undef status is not obvious anymore
17 /// when subregisters are involved.
18 ///
19 /// Example:
20 /// %vreg0 = some definition
21 /// %vreg1 = IMPLICIT_DEF
22 /// %vreg2 = REG_SEQUENCE %vreg0, sub0, %vreg1, sub1
23 /// %vreg3 = EXTRACT_SUBREG %vreg2, sub1
24 /// = use %vreg3
25 /// The %vreg0 definition is dead and %vreg3 contains an undefined value.
26 //
27 //===----------------------------------------------------------------------===//
28 
29 #include <deque>
30 #include <vector>
31 
32 #include "llvm/ADT/BitVector.h"
33 #include "llvm/ADT/SetVector.h"
36 #include "llvm/CodeGen/Passes.h"
37 #include "llvm/InitializePasses.h"
38 #include "llvm/Pass.h"
39 #include "llvm/PassRegistry.h"
40 #include "llvm/Support/Debug.h"
45 
46 using namespace llvm;
47 
48 #define DEBUG_TYPE "detect-dead-lanes"
49 
50 namespace {
51 
52 /// Contains a bitmask of which lanes of a given virtual register are
53 /// defined and which ones are actually used.
54 struct VRegInfo {
55  LaneBitmask UsedLanes;
56  LaneBitmask DefinedLanes;
57 };
58 
59 class DetectDeadLanes : public MachineFunctionPass {
60 public:
61  bool runOnMachineFunction(MachineFunction &MF) override;
62 
63  static char ID;
64  DetectDeadLanes() : MachineFunctionPass(ID) {}
65 
66  StringRef getPassName() const override { return "Detect Dead Lanes"; }
67 
68  void getAnalysisUsage(AnalysisUsage &AU) const override {
69  AU.setPreservesCFG();
71  }
72 
73 private:
74  /// Add used lane bits on the register used by operand \p MO. This translates
75  /// the bitmask based on the operands subregister, and puts the register into
76  /// the worklist if any new bits were added.
77  void addUsedLanesOnOperand(const MachineOperand &MO, LaneBitmask UsedLanes);
78 
79  /// Given a bitmask \p UsedLanes for the used lanes on a def output of a
80  /// COPY-like instruction determine the lanes used on the use operands
81  /// and call addUsedLanesOnOperand() for them.
82  void transferUsedLanesStep(const MachineInstr &MI, LaneBitmask UsedLanes);
83 
84  /// Given a use regiser operand \p Use and a mask of defined lanes, check
85  /// if the operand belongs to a lowersToCopies() instruction, transfer the
86  /// mask to the def and put the instruction into the worklist.
87  void transferDefinedLanesStep(const MachineOperand &Use,
88  LaneBitmask DefinedLanes);
89 
90  /// Given a mask \p DefinedLanes of lanes defined at operand \p OpNum
91  /// of COPY-like instruction, determine which lanes are defined at the output
92  /// operand \p Def.
93  LaneBitmask transferDefinedLanes(const MachineOperand &Def, unsigned OpNum,
94  LaneBitmask DefinedLanes) const;
95 
96  /// Given a mask \p UsedLanes used from the output of instruction \p MI
97  /// determine which lanes are used from operand \p MO of this instruction.
98  LaneBitmask transferUsedLanes(const MachineInstr &MI, LaneBitmask UsedLanes,
99  const MachineOperand &MO) const;
100 
101  bool runOnce(MachineFunction &MF);
102 
103  LaneBitmask determineInitialDefinedLanes(unsigned Reg);
104  LaneBitmask determineInitialUsedLanes(unsigned Reg);
105 
106  bool isUndefRegAtInput(const MachineOperand &MO,
107  const VRegInfo &RegInfo) const;
108 
109  bool isUndefInput(const MachineOperand &MO, bool *CrossCopy) const;
110 
111  const MachineRegisterInfo *MRI;
112  const TargetRegisterInfo *TRI;
113 
114  void PutInWorklist(unsigned RegIdx) {
115  if (WorklistMembers.test(RegIdx))
116  return;
117  WorklistMembers.set(RegIdx);
118  Worklist.push_back(RegIdx);
119  }
120 
121  VRegInfo *VRegInfos;
122  /// Worklist containing virtreg indexes.
123  std::deque<unsigned> Worklist;
124  BitVector WorklistMembers;
125  /// This bitvector is set for each vreg index where the vreg is defined
126  /// by an instruction where lowersToCopies()==true.
127  BitVector DefinedByCopy;
128 };
129 
130 } // end anonymous namespace
131 
132 char DetectDeadLanes::ID = 0;
134 
135 INITIALIZE_PASS(DetectDeadLanes, DEBUG_TYPE, "Detect Dead Lanes", false, false)
136 
137 /// Returns true if \p MI will get lowered to a series of COPY instructions.
138 /// We call this a COPY-like instruction.
140  // Note: We could support instructions with MCInstrDesc::isRegSequenceLike(),
141  // isExtractSubRegLike(), isInsertSubregLike() in the future even though they
142  // are not lowered to a COPY.
143  switch (MI.getOpcode()) {
144  case TargetOpcode::COPY:
145  case TargetOpcode::PHI:
146  case TargetOpcode::INSERT_SUBREG:
147  case TargetOpcode::REG_SEQUENCE:
148  case TargetOpcode::EXTRACT_SUBREG:
149  return true;
150  }
151  return false;
152 }
153 
155  const MachineInstr &MI,
156  const TargetRegisterClass *DstRC,
157  const MachineOperand &MO) {
158  assert(lowersToCopies(MI));
159  unsigned SrcReg = MO.getReg();
160  const TargetRegisterClass *SrcRC = MRI.getRegClass(SrcReg);
161  if (DstRC == SrcRC)
162  return false;
163 
164  unsigned SrcSubIdx = MO.getSubReg();
165 
166  const TargetRegisterInfo &TRI = *MRI.getTargetRegisterInfo();
167  unsigned DstSubIdx = 0;
168  switch (MI.getOpcode()) {
169  case TargetOpcode::INSERT_SUBREG:
170  if (MI.getOperandNo(&MO) == 2)
171  DstSubIdx = MI.getOperand(3).getImm();
172  break;
173  case TargetOpcode::REG_SEQUENCE: {
174  unsigned OpNum = MI.getOperandNo(&MO);
175  DstSubIdx = MI.getOperand(OpNum+1).getImm();
176  break;
177  }
178  case TargetOpcode::EXTRACT_SUBREG: {
179  unsigned SubReg = MI.getOperand(2).getImm();
180  SrcSubIdx = TRI.composeSubRegIndices(SubReg, SrcSubIdx);
181  }
182  }
183 
184  unsigned PreA, PreB; // Unused.
185  if (SrcSubIdx && DstSubIdx)
186  return !TRI.getCommonSuperRegClass(SrcRC, SrcSubIdx, DstRC, DstSubIdx, PreA,
187  PreB);
188  if (SrcSubIdx)
189  return !TRI.getMatchingSuperRegClass(SrcRC, DstRC, SrcSubIdx);
190  if (DstSubIdx)
191  return !TRI.getMatchingSuperRegClass(DstRC, SrcRC, DstSubIdx);
192  return !TRI.getCommonSubClass(SrcRC, DstRC);
193 }
194 
195 void DetectDeadLanes::addUsedLanesOnOperand(const MachineOperand &MO,
196  LaneBitmask UsedLanes) {
197  if (!MO.readsReg())
198  return;
199  unsigned MOReg = MO.getReg();
201  return;
202 
203  unsigned MOSubReg = MO.getSubReg();
204  if (MOSubReg != 0)
205  UsedLanes = TRI->composeSubRegIndexLaneMask(MOSubReg, UsedLanes);
206  UsedLanes &= MRI->getMaxLaneMaskForVReg(MOReg);
207 
208  unsigned MORegIdx = TargetRegisterInfo::virtReg2Index(MOReg);
209  VRegInfo &MORegInfo = VRegInfos[MORegIdx];
210  LaneBitmask PrevUsedLanes = MORegInfo.UsedLanes;
211  // Any change at all?
212  if ((UsedLanes & ~PrevUsedLanes).none())
213  return;
214 
215  // Set UsedLanes and remember instruction for further propagation.
216  MORegInfo.UsedLanes = PrevUsedLanes | UsedLanes;
217  if (DefinedByCopy.test(MORegIdx))
218  PutInWorklist(MORegIdx);
219 }
220 
221 void DetectDeadLanes::transferUsedLanesStep(const MachineInstr &MI,
222  LaneBitmask UsedLanes) {
223  for (const MachineOperand &MO : MI.uses()) {
225  continue;
226  LaneBitmask UsedOnMO = transferUsedLanes(MI, UsedLanes, MO);
227  addUsedLanesOnOperand(MO, UsedOnMO);
228  }
229 }
230 
231 LaneBitmask DetectDeadLanes::transferUsedLanes(const MachineInstr &MI,
232  LaneBitmask UsedLanes,
233  const MachineOperand &MO) const {
234  unsigned OpNum = MI.getOperandNo(&MO);
235  assert(lowersToCopies(MI) && DefinedByCopy[
237 
238  switch (MI.getOpcode()) {
239  case TargetOpcode::COPY:
240  case TargetOpcode::PHI:
241  return UsedLanes;
242  case TargetOpcode::REG_SEQUENCE: {
243  assert(OpNum % 2 == 1);
244  unsigned SubIdx = MI.getOperand(OpNum + 1).getImm();
245  return TRI->reverseComposeSubRegIndexLaneMask(SubIdx, UsedLanes);
246  }
247  case TargetOpcode::INSERT_SUBREG: {
248  unsigned SubIdx = MI.getOperand(3).getImm();
249  LaneBitmask MO2UsedLanes =
250  TRI->reverseComposeSubRegIndexLaneMask(SubIdx, UsedLanes);
251  if (OpNum == 2)
252  return MO2UsedLanes;
253 
254  const MachineOperand &Def = MI.getOperand(0);
255  unsigned DefReg = Def.getReg();
256  const TargetRegisterClass *RC = MRI->getRegClass(DefReg);
257  LaneBitmask MO1UsedLanes;
258  if (RC->CoveredBySubRegs)
259  MO1UsedLanes = UsedLanes & ~TRI->getSubRegIndexLaneMask(SubIdx);
260  else
261  MO1UsedLanes = RC->LaneMask;
262 
263  assert(OpNum == 1);
264  return MO1UsedLanes;
265  }
266  case TargetOpcode::EXTRACT_SUBREG: {
267  assert(OpNum == 1);
268  unsigned SubIdx = MI.getOperand(2).getImm();
269  return TRI->composeSubRegIndexLaneMask(SubIdx, UsedLanes);
270  }
271  default:
272  llvm_unreachable("function must be called with COPY-like instruction");
273  }
274 }
275 
276 void DetectDeadLanes::transferDefinedLanesStep(const MachineOperand &Use,
277  LaneBitmask DefinedLanes) {
278  if (!Use.readsReg())
279  return;
280  // Check whether the operand writes a vreg and is part of a COPY-like
281  // instruction.
282  const MachineInstr &MI = *Use.getParent();
283  if (MI.getDesc().getNumDefs() != 1)
284  return;
285  // FIXME: PATCHPOINT instructions announce a Def that does not always exist,
286  // they really need to be modeled differently!
287  if (MI.getOpcode() == TargetOpcode::PATCHPOINT)
288  return;
289  const MachineOperand &Def = *MI.defs().begin();
290  unsigned DefReg = Def.getReg();
292  return;
293  unsigned DefRegIdx = TargetRegisterInfo::virtReg2Index(DefReg);
294  if (!DefinedByCopy.test(DefRegIdx))
295  return;
296 
297  unsigned OpNum = MI.getOperandNo(&Use);
298  DefinedLanes =
299  TRI->reverseComposeSubRegIndexLaneMask(Use.getSubReg(), DefinedLanes);
300  DefinedLanes = transferDefinedLanes(Def, OpNum, DefinedLanes);
301 
302  VRegInfo &RegInfo = VRegInfos[DefRegIdx];
303  LaneBitmask PrevDefinedLanes = RegInfo.DefinedLanes;
304  // Any change at all?
305  if ((DefinedLanes & ~PrevDefinedLanes).none())
306  return;
307 
308  RegInfo.DefinedLanes = PrevDefinedLanes | DefinedLanes;
309  PutInWorklist(DefRegIdx);
310 }
311 
312 LaneBitmask DetectDeadLanes::transferDefinedLanes(const MachineOperand &Def,
313  unsigned OpNum, LaneBitmask DefinedLanes) const {
314  const MachineInstr &MI = *Def.getParent();
315  // Translate DefinedLanes if necessary.
316  switch (MI.getOpcode()) {
317  case TargetOpcode::REG_SEQUENCE: {
318  unsigned SubIdx = MI.getOperand(OpNum + 1).getImm();
319  DefinedLanes = TRI->composeSubRegIndexLaneMask(SubIdx, DefinedLanes);
320  DefinedLanes &= TRI->getSubRegIndexLaneMask(SubIdx);
321  break;
322  }
323  case TargetOpcode::INSERT_SUBREG: {
324  unsigned SubIdx = MI.getOperand(3).getImm();
325  if (OpNum == 2) {
326  DefinedLanes = TRI->composeSubRegIndexLaneMask(SubIdx, DefinedLanes);
327  DefinedLanes &= TRI->getSubRegIndexLaneMask(SubIdx);
328  } else {
329  assert(OpNum == 1 && "INSERT_SUBREG must have two operands");
330  // Ignore lanes defined by operand 2.
331  DefinedLanes &= ~TRI->getSubRegIndexLaneMask(SubIdx);
332  }
333  break;
334  }
335  case TargetOpcode::EXTRACT_SUBREG: {
336  unsigned SubIdx = MI.getOperand(2).getImm();
337  assert(OpNum == 1 && "EXTRACT_SUBREG must have one register operand only");
338  DefinedLanes = TRI->reverseComposeSubRegIndexLaneMask(SubIdx, DefinedLanes);
339  break;
340  }
341  case TargetOpcode::COPY:
342  case TargetOpcode::PHI:
343  break;
344  default:
345  llvm_unreachable("function must be called with COPY-like instruction");
346  }
347 
348  assert(Def.getSubReg() == 0 &&
349  "Should not have subregister defs in machine SSA phase");
350  DefinedLanes &= MRI->getMaxLaneMaskForVReg(Def.getReg());
351  return DefinedLanes;
352 }
353 
354 LaneBitmask DetectDeadLanes::determineInitialDefinedLanes(unsigned Reg) {
355  // Live-In or unused registers have no definition but are considered fully
356  // defined.
357  if (!MRI->hasOneDef(Reg))
358  return LaneBitmask::getAll();
359 
360  const MachineOperand &Def = *MRI->def_begin(Reg);
361  const MachineInstr &DefMI = *Def.getParent();
362  if (lowersToCopies(DefMI)) {
363  // Start optimisatically with no used or defined lanes for copy
364  // instructions. The following dataflow analysis will add more bits.
365  unsigned RegIdx = TargetRegisterInfo::virtReg2Index(Reg);
366  DefinedByCopy.set(RegIdx);
367  PutInWorklist(RegIdx);
368 
369  if (Def.isDead())
370  return LaneBitmask::getNone();
371 
372  // COPY/PHI can copy across unrelated register classes (example: float/int)
373  // with incompatible subregister structure. Do not include these in the
374  // dataflow analysis since we cannot transfer lanemasks in a meaningful way.
375  const TargetRegisterClass *DefRC = MRI->getRegClass(Reg);
376 
377  // Determine initially DefinedLanes.
378  LaneBitmask DefinedLanes;
379  for (const MachineOperand &MO : DefMI.uses()) {
380  if (!MO.isReg() || !MO.readsReg())
381  continue;
382  unsigned MOReg = MO.getReg();
383  if (!MOReg)
384  continue;
385 
386  LaneBitmask MODefinedLanes;
388  MODefinedLanes = LaneBitmask::getAll();
389  } else if (isCrossCopy(*MRI, DefMI, DefRC, MO)) {
390  MODefinedLanes = LaneBitmask::getAll();
391  } else {
393  if (MRI->hasOneDef(MOReg)) {
394  const MachineOperand &MODef = *MRI->def_begin(MOReg);
395  const MachineInstr &MODefMI = *MODef.getParent();
396  // Bits from copy-like operations will be added later.
397  if (lowersToCopies(MODefMI) || MODefMI.isImplicitDef())
398  continue;
399  }
400  unsigned MOSubReg = MO.getSubReg();
401  MODefinedLanes = MRI->getMaxLaneMaskForVReg(MOReg);
402  MODefinedLanes = TRI->reverseComposeSubRegIndexLaneMask(
403  MOSubReg, MODefinedLanes);
404  }
405 
406  unsigned OpNum = DefMI.getOperandNo(&MO);
407  DefinedLanes |= transferDefinedLanes(Def, OpNum, MODefinedLanes);
408  }
409  return DefinedLanes;
410  }
411  if (DefMI.isImplicitDef() || Def.isDead())
412  return LaneBitmask::getNone();
413 
414  assert(Def.getSubReg() == 0 &&
415  "Should not have subregister defs in machine SSA phase");
416  return MRI->getMaxLaneMaskForVReg(Reg);
417 }
418 
419 LaneBitmask DetectDeadLanes::determineInitialUsedLanes(unsigned Reg) {
420  LaneBitmask UsedLanes = LaneBitmask::getNone();
421  for (const MachineOperand &MO : MRI->use_nodbg_operands(Reg)) {
422  if (!MO.readsReg())
423  continue;
424 
425  const MachineInstr &UseMI = *MO.getParent();
426  if (UseMI.isKill())
427  continue;
428 
429  unsigned SubReg = MO.getSubReg();
430  if (lowersToCopies(UseMI)) {
431  assert(UseMI.getDesc().getNumDefs() == 1);
432  const MachineOperand &Def = *UseMI.defs().begin();
433  unsigned DefReg = Def.getReg();
434  // The used lanes of COPY-like instruction operands are determined by the
435  // following dataflow analysis.
437  // But ignore copies across incompatible register classes.
438  bool CrossCopy = false;
439  if (lowersToCopies(UseMI)) {
440  const TargetRegisterClass *DstRC = MRI->getRegClass(DefReg);
441  CrossCopy = isCrossCopy(*MRI, UseMI, DstRC, MO);
442  if (CrossCopy)
443  DEBUG(dbgs() << "Copy across incompatible classes: " << UseMI);
444  }
445 
446  if (!CrossCopy)
447  continue;
448  }
449  }
450 
451  // Shortcut: All lanes are used.
452  if (SubReg == 0)
453  return MRI->getMaxLaneMaskForVReg(Reg);
454 
455  UsedLanes |= TRI->getSubRegIndexLaneMask(SubReg);
456  }
457  return UsedLanes;
458 }
459 
460 bool DetectDeadLanes::isUndefRegAtInput(const MachineOperand &MO,
461  const VRegInfo &RegInfo) const {
462  unsigned SubReg = MO.getSubReg();
463  LaneBitmask Mask = TRI->getSubRegIndexLaneMask(SubReg);
464  return (RegInfo.DefinedLanes & RegInfo.UsedLanes & Mask).none();
465 }
466 
467 bool DetectDeadLanes::isUndefInput(const MachineOperand &MO,
468  bool *CrossCopy) const {
469  if (!MO.isUse())
470  return false;
471  const MachineInstr &MI = *MO.getParent();
472  if (!lowersToCopies(MI))
473  return false;
474  const MachineOperand &Def = MI.getOperand(0);
475  unsigned DefReg = Def.getReg();
477  return false;
478  unsigned DefRegIdx = TargetRegisterInfo::virtReg2Index(DefReg);
479  if (!DefinedByCopy.test(DefRegIdx))
480  return false;
481 
482  const VRegInfo &DefRegInfo = VRegInfos[DefRegIdx];
483  LaneBitmask UsedLanes = transferUsedLanes(MI, DefRegInfo.UsedLanes, MO);
484  if (UsedLanes.any())
485  return false;
486 
487  unsigned MOReg = MO.getReg();
489  const TargetRegisterClass *DstRC = MRI->getRegClass(DefReg);
490  *CrossCopy = isCrossCopy(*MRI, MI, DstRC, MO);
491  }
492  return true;
493 }
494 
495 bool DetectDeadLanes::runOnce(MachineFunction &MF) {
496  // First pass: Populate defs/uses of vregs with initial values
497  unsigned NumVirtRegs = MRI->getNumVirtRegs();
498  for (unsigned RegIdx = 0; RegIdx < NumVirtRegs; ++RegIdx) {
499  unsigned Reg = TargetRegisterInfo::index2VirtReg(RegIdx);
500 
501  // Determine used/defined lanes and add copy instructions to worklist.
502  VRegInfo &Info = VRegInfos[RegIdx];
503  Info.DefinedLanes = determineInitialDefinedLanes(Reg);
504  Info.UsedLanes = determineInitialUsedLanes(Reg);
505  }
506 
507  // Iterate as long as defined lanes/used lanes keep changing.
508  while (!Worklist.empty()) {
509  unsigned RegIdx = Worklist.front();
510  Worklist.pop_front();
511  WorklistMembers.reset(RegIdx);
512  VRegInfo &Info = VRegInfos[RegIdx];
513  unsigned Reg = TargetRegisterInfo::index2VirtReg(RegIdx);
514 
515  // Transfer UsedLanes to operands of DefMI (backwards dataflow).
516  MachineOperand &Def = *MRI->def_begin(Reg);
517  const MachineInstr &MI = *Def.getParent();
518  transferUsedLanesStep(MI, Info.UsedLanes);
519  // Transfer DefinedLanes to users of Reg (forward dataflow).
520  for (const MachineOperand &MO : MRI->use_nodbg_operands(Reg))
521  transferDefinedLanesStep(MO, Info.DefinedLanes);
522  }
523 
524  DEBUG(
525  dbgs() << "Defined/Used lanes:\n";
526  for (unsigned RegIdx = 0; RegIdx < NumVirtRegs; ++RegIdx) {
527  unsigned Reg = TargetRegisterInfo::index2VirtReg(RegIdx);
528  const VRegInfo &Info = VRegInfos[RegIdx];
529  dbgs() << PrintReg(Reg, nullptr)
530  << " Used: " << PrintLaneMask(Info.UsedLanes)
531  << " Def: " << PrintLaneMask(Info.DefinedLanes) << '\n';
532  }
533  dbgs() << "\n";
534  );
535 
536  bool Again = false;
537  // Mark operands as dead/unused.
538  for (MachineBasicBlock &MBB : MF) {
539  for (MachineInstr &MI : MBB) {
540  for (MachineOperand &MO : MI.operands()) {
541  if (!MO.isReg())
542  continue;
543  unsigned Reg = MO.getReg();
545  continue;
546  unsigned RegIdx = TargetRegisterInfo::virtReg2Index(Reg);
547  const VRegInfo &RegInfo = VRegInfos[RegIdx];
548  if (MO.isDef() && !MO.isDead() && RegInfo.UsedLanes.none()) {
549  DEBUG(dbgs() << "Marking operand '" << MO << "' as dead in " << MI);
550  MO.setIsDead();
551  }
552  if (MO.readsReg()) {
553  bool CrossCopy = false;
554  if (isUndefRegAtInput(MO, RegInfo)) {
555  DEBUG(dbgs() << "Marking operand '" << MO << "' as undef in "
556  << MI);
557  MO.setIsUndef();
558  } else if (isUndefInput(MO, &CrossCopy)) {
559  DEBUG(dbgs() << "Marking operand '" << MO << "' as undef in "
560  << MI);
561  MO.setIsUndef();
562  if (CrossCopy)
563  Again = true;
564  }
565  }
566  }
567  }
568  }
569 
570  return Again;
571 }
572 
573 bool DetectDeadLanes::runOnMachineFunction(MachineFunction &MF) {
574  // Don't bother if we won't track subregister liveness later. This pass is
575  // required for correctness if subregister liveness is enabled because the
576  // register coalescer cannot deal with hidden dead defs. However without
577  // subregister liveness enabled, the expected benefits of this pass are small
578  // so we safe the compile time.
579  MRI = &MF.getRegInfo();
580  if (!MRI->subRegLivenessEnabled()) {
581  DEBUG(dbgs() << "Skipping Detect dead lanes pass\n");
582  return false;
583  }
584 
585  TRI = MRI->getTargetRegisterInfo();
586 
587  unsigned NumVirtRegs = MRI->getNumVirtRegs();
588  VRegInfos = new VRegInfo[NumVirtRegs];
589  WorklistMembers.resize(NumVirtRegs);
590  DefinedByCopy.resize(NumVirtRegs);
591 
592  bool Again;
593  do {
594  Again = runOnce(MF);
595  } while(Again);
596 
597  DefinedByCopy.clear();
598  WorklistMembers.clear();
599  delete[] VRegInfos;
600  return true;
601 }
MachineInstr * getParent()
getParent - Return the instruction that this operand belongs to.
static unsigned virtReg2Index(unsigned Reg)
Convert a virtual register number to a 0-based index.
iterator_range< mop_iterator > uses()
Returns a range that includes all operands that are register uses.
Definition: MachineInstr.h:339
static unsigned index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
unsigned getNumDefs() const
Return the number of MachineOperands that are register definitions.
Definition: MCInstrDesc.h:225
static LaneBitmask getAll()
Definition: LaneBitmask.h:77
void setIsUndef(bool Val=true)
bool isDead() const
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
unsigned getOperandNo(const_mop_iterator I) const
Returns the number of the operand iterator I points to.
Definition: MachineInstr.h:358
const MCInstrDesc & getDesc() const
Returns the target instruction descriptor of this MachineInstr.
Definition: MachineInstr.h:276
#define DEBUG_TYPE
void setIsDead(bool Val=true)
iterator_range< mop_iterator > operands()
Definition: MachineInstr.h:306
char & DetectDeadLanesID
This pass adds dead/undef flags after analyzing subregister lanes.
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const TargetRegisterInfo * getTargetRegisterInfo() const
A Use represents the edge between a Value definition and its users.
Definition: Use.h:56
bool isReg() const
isReg - Tests if this is a MO_Register operand.
unsigned SubReg
const TargetRegisterClass * getRegClass(unsigned Reg) const
Return the register class of the specified virtual register.
Reg
All possible values of the reg field in the ModR/M byte.
constexpr bool any() const
Definition: LaneBitmask.h:53
virtual const TargetRegisterClass * getMatchingSuperRegClass(const TargetRegisterClass *A, const TargetRegisterClass *B, unsigned Idx) const
Return a subclass of the specified register class A so that each register in it has a sub-register of...
int64_t getImm() const
Printable PrintReg(unsigned Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubRegIdx=0)
Prints virtual and physical registers with or without a TRI instance.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Definition: MachineInstr.h:279
bool isImplicitDef() const
Definition: MachineInstr.h:797
const TargetRegisterClass * getCommonSuperRegClass(const TargetRegisterClass *RCA, unsigned SubA, const TargetRegisterClass *RCB, unsigned SubB, unsigned &PreA, unsigned &PreB) const
Find a common super-register class if it exists.
unsigned const MachineRegisterInfo * MRI
MachineInstrBuilder & UseMI
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:284
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
static bool lowersToCopies(const MachineInstr &MI)
Returns true if MI will get lowered to a series of COPY instructions.
Represent the analysis usage information of a pass.
iterator_range< mop_iterator > defs()
Returns a range over all explicit operands that are register definitions.
Definition: MachineInstr.h:328
unsigned getSubReg() const
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:34
static bool isCrossCopy(const MachineRegisterInfo &MRI, const MachineInstr &MI, const TargetRegisterClass *DstRC, const MachineOperand &MO)
MachineOperand class - Representation of each machine instruction operand.
static LaneBitmask getNone()
Definition: LaneBitmask.h:76
bool isKill() const
Definition: MachineInstr.h:796
void setPreservesCFG()
This function should be called by the pass, iff they do not:
Definition: Pass.cpp:278
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
llvm_unreachable("Unknown RegBank!")
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
Representation of each machine instruction.
Definition: MachineInstr.h:59
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
const TargetRegisterClass * getCommonSubClass(const TargetRegisterClass *A, const TargetRegisterClass *B, const MVT::SimpleValueType SVT=MVT::SimpleValueType::Any) const
Find the largest common subclass of A and B.
const bool CoveredBySubRegs
Whether a combination of subregisters can cover every register in the class.
unsigned getReg() const
getReg - Returns the register number.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
aarch64 promote const
static LLVM_ATTRIBUTE_UNUSED Printable PrintLaneMask(LaneBitmask LaneMask)
Create Printable object to print LaneBitmasks on a raw_ostream.
Definition: LaneBitmask.h:87
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
Definition: BitmaskEnum.h:81
#define DEBUG(X)
Definition: Debug.h:118
IRTranslator LLVM IR MI
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
unsigned composeSubRegIndices(unsigned a, unsigned b) const
Return the subregister index you get from composing two subregister indices.
bool readsReg() const
readsReg - Returns true if this operand reads the previous value of its register. ...