LLVM  8.0.1
VirtRegMap.cpp
Go to the documentation of this file.
1 //===- llvm/CodeGen/VirtRegMap.cpp - Virtual Register Map -----------------===//
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 // This file implements the VirtRegMap class.
11 //
12 // It also contains implementations of the Spiller interface, which, given a
13 // virtual register map and a machine function, eliminates all virtual
14 // references by replacing them with physical register references - adding spill
15 // code as necessary.
16 //
17 //===----------------------------------------------------------------------===//
18 
20 #include "LiveDebugVariables.h"
21 #include "llvm/ADT/SmallVector.h"
22 #include "llvm/ADT/Statistic.h"
38 #include "llvm/Config/llvm-config.h"
39 #include "llvm/MC/LaneBitmask.h"
40 #include "llvm/Pass.h"
41 #include "llvm/Support/Compiler.h"
42 #include "llvm/Support/Debug.h"
44 #include <cassert>
45 #include <iterator>
46 #include <utility>
47 
48 using namespace llvm;
49 
50 #define DEBUG_TYPE "regalloc"
51 
52 STATISTIC(NumSpillSlots, "Number of spill slots allocated");
53 STATISTIC(NumIdCopies, "Number of identity moves eliminated after rewriting");
54 
55 //===----------------------------------------------------------------------===//
56 // VirtRegMap implementation
57 //===----------------------------------------------------------------------===//
58 
59 char VirtRegMap::ID = 0;
60 
61 INITIALIZE_PASS(VirtRegMap, "virtregmap", "Virtual Register Map", false, false)
62 
63 bool VirtRegMap::runOnMachineFunction(MachineFunction &mf) {
64  MRI = &mf.getRegInfo();
65  TII = mf.getSubtarget().getInstrInfo();
66  TRI = mf.getSubtarget().getRegisterInfo();
67  MF = &mf;
68 
69  Virt2PhysMap.clear();
70  Virt2StackSlotMap.clear();
71  Virt2SplitMap.clear();
72 
73  grow();
74  return false;
75 }
76 
78  unsigned NumRegs = MF->getRegInfo().getNumVirtRegs();
79  Virt2PhysMap.resize(NumRegs);
80  Virt2StackSlotMap.resize(NumRegs);
81  Virt2SplitMap.resize(NumRegs);
82 }
83 
84 void VirtRegMap::assignVirt2Phys(unsigned virtReg, MCPhysReg physReg) {
87  assert(Virt2PhysMap[virtReg] == NO_PHYS_REG &&
88  "attempt to assign physical register to already mapped "
89  "virtual register");
90  assert(!getRegInfo().isReserved(physReg) &&
91  "Attempt to map virtReg to a reserved physReg");
92  Virt2PhysMap[virtReg] = physReg;
93 }
94 
95 unsigned VirtRegMap::createSpillSlot(const TargetRegisterClass *RC) {
96  unsigned Size = TRI->getSpillSize(*RC);
97  unsigned Align = TRI->getSpillAlignment(*RC);
98  int SS = MF->getFrameInfo().CreateSpillStackObject(Size, Align);
99  ++NumSpillSlots;
100  return SS;
101 }
102 
103 bool VirtRegMap::hasPreferredPhys(unsigned VirtReg) {
104  unsigned Hint = MRI->getSimpleHint(VirtReg);
105  if (!Hint)
106  return false;
108  Hint = getPhys(Hint);
109  return getPhys(VirtReg) == Hint;
110 }
111 
112 bool VirtRegMap::hasKnownPreference(unsigned VirtReg) {
113  std::pair<unsigned, unsigned> Hint = MRI->getRegAllocationHint(VirtReg);
115  return true;
116  if (TargetRegisterInfo::isVirtualRegister(Hint.second))
117  return hasPhys(Hint.second);
118  return false;
119 }
120 
121 int VirtRegMap::assignVirt2StackSlot(unsigned virtReg) {
123  assert(Virt2StackSlotMap[virtReg] == NO_STACK_SLOT &&
124  "attempt to assign stack slot to already spilled register");
125  const TargetRegisterClass* RC = MF->getRegInfo().getRegClass(virtReg);
126  return Virt2StackSlotMap[virtReg] = createSpillSlot(RC);
127 }
128 
129 void VirtRegMap::assignVirt2StackSlot(unsigned virtReg, int SS) {
131  assert(Virt2StackSlotMap[virtReg] == NO_STACK_SLOT &&
132  "attempt to assign stack slot to already spilled register");
133  assert((SS >= 0 ||
134  (SS >= MF->getFrameInfo().getObjectIndexBegin())) &&
135  "illegal fixed frame index");
136  Virt2StackSlotMap[virtReg] = SS;
137 }
138 
139 void VirtRegMap::print(raw_ostream &OS, const Module*) const {
140  OS << "********** REGISTER MAP **********\n";
141  for (unsigned i = 0, e = MRI->getNumVirtRegs(); i != e; ++i) {
143  if (Virt2PhysMap[Reg] != (unsigned)VirtRegMap::NO_PHYS_REG) {
144  OS << '[' << printReg(Reg, TRI) << " -> "
145  << printReg(Virt2PhysMap[Reg], TRI) << "] "
146  << TRI->getRegClassName(MRI->getRegClass(Reg)) << "\n";
147  }
148  }
149 
150  for (unsigned i = 0, e = MRI->getNumVirtRegs(); i != e; ++i) {
152  if (Virt2StackSlotMap[Reg] != VirtRegMap::NO_STACK_SLOT) {
153  OS << '[' << printReg(Reg, TRI) << " -> fi#" << Virt2StackSlotMap[Reg]
154  << "] " << TRI->getRegClassName(MRI->getRegClass(Reg)) << "\n";
155  }
156  }
157  OS << '\n';
158 }
159 
160 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
162  print(dbgs());
163 }
164 #endif
165 
166 //===----------------------------------------------------------------------===//
167 // VirtRegRewriter
168 //===----------------------------------------------------------------------===//
169 //
170 // The VirtRegRewriter is the last of the register allocator passes.
171 // It rewrites virtual registers to physical registers as specified in the
172 // VirtRegMap analysis. It also updates live-in information on basic blocks
173 // according to LiveIntervals.
174 //
175 namespace {
176 
177 class VirtRegRewriter : public MachineFunctionPass {
178  MachineFunction *MF;
179  const TargetRegisterInfo *TRI;
180  const TargetInstrInfo *TII;
182  SlotIndexes *Indexes;
183  LiveIntervals *LIS;
184  VirtRegMap *VRM;
185 
186  void rewrite();
187  void addMBBLiveIns();
188  bool readsUndefSubreg(const MachineOperand &MO) const;
189  void addLiveInsForSubRanges(const LiveInterval &LI, unsigned PhysReg) const;
190  void handleIdentityCopy(MachineInstr &MI) const;
191  void expandCopyBundle(MachineInstr &MI) const;
192  bool subRegLiveThrough(const MachineInstr &MI, unsigned SuperPhysReg) const;
193 
194 public:
195  static char ID;
196 
197  VirtRegRewriter() : MachineFunctionPass(ID) {}
198 
199  void getAnalysisUsage(AnalysisUsage &AU) const override;
200 
201  bool runOnMachineFunction(MachineFunction&) override;
202 
206  }
207 };
208 
209 } // end anonymous namespace
210 
211 char VirtRegRewriter::ID = 0;
212 
214 
215 INITIALIZE_PASS_BEGIN(VirtRegRewriter, "virtregrewriter",
216  "Virtual Register Rewriter", false, false)
223  "Virtual Register Rewriter", false, false)
224 
225 void VirtRegRewriter::getAnalysisUsage(AnalysisUsage &AU) const {
226  AU.setPreservesCFG();
227  AU.addRequired<LiveIntervals>();
228  AU.addRequired<SlotIndexes>();
229  AU.addPreserved<SlotIndexes>();
230  AU.addRequired<LiveDebugVariables>();
231  AU.addRequired<LiveStacks>();
232  AU.addPreserved<LiveStacks>();
233  AU.addRequired<VirtRegMap>();
235 }
236 
237 bool VirtRegRewriter::runOnMachineFunction(MachineFunction &fn) {
238  MF = &fn;
239  TRI = MF->getSubtarget().getRegisterInfo();
240  TII = MF->getSubtarget().getInstrInfo();
241  MRI = &MF->getRegInfo();
242  Indexes = &getAnalysis<SlotIndexes>();
243  LIS = &getAnalysis<LiveIntervals>();
244  VRM = &getAnalysis<VirtRegMap>();
245  LLVM_DEBUG(dbgs() << "********** REWRITE VIRTUAL REGISTERS **********\n"
246  << "********** Function: " << MF->getName() << '\n');
247  LLVM_DEBUG(VRM->dump());
248 
249  // Add kill flags while we still have virtual registers.
250  LIS->addKillFlags(VRM);
251 
252  // Live-in lists on basic blocks are required for physregs.
253  addMBBLiveIns();
254 
255  // Rewrite virtual registers.
256  rewrite();
257 
258  // Write out new DBG_VALUE instructions.
259  getAnalysis<LiveDebugVariables>().emitDebugValues(VRM);
260 
261  // All machine operands and other references to virtual registers have been
262  // replaced. Remove the virtual registers and release all the transient data.
263  VRM->clearAllVirt();
264  MRI->clearVirtRegs();
265  return true;
266 }
267 
268 void VirtRegRewriter::addLiveInsForSubRanges(const LiveInterval &LI,
269  unsigned PhysReg) const {
270  assert(!LI.empty());
271  assert(LI.hasSubRanges());
272 
273  using SubRangeIteratorPair =
274  std::pair<const LiveInterval::SubRange *, LiveInterval::const_iterator>;
275 
277  SlotIndex First;
278  SlotIndex Last;
279  for (const LiveInterval::SubRange &SR : LI.subranges()) {
280  SubRanges.push_back(std::make_pair(&SR, SR.begin()));
281  if (!First.isValid() || SR.segments.front().start < First)
282  First = SR.segments.front().start;
283  if (!Last.isValid() || SR.segments.back().end > Last)
284  Last = SR.segments.back().end;
285  }
286 
287  // Check all mbb start positions between First and Last while
288  // simulatenously advancing an iterator for each subrange.
289  for (SlotIndexes::MBBIndexIterator MBBI = Indexes->findMBBIndex(First);
290  MBBI != Indexes->MBBIndexEnd() && MBBI->first <= Last; ++MBBI) {
291  SlotIndex MBBBegin = MBBI->first;
292  // Advance all subrange iterators so that their end position is just
293  // behind MBBBegin (or the iterator is at the end).
294  LaneBitmask LaneMask;
295  for (auto &RangeIterPair : SubRanges) {
296  const LiveInterval::SubRange *SR = RangeIterPair.first;
297  LiveInterval::const_iterator &SRI = RangeIterPair.second;
298  while (SRI != SR->end() && SRI->end <= MBBBegin)
299  ++SRI;
300  if (SRI == SR->end())
301  continue;
302  if (SRI->start <= MBBBegin)
303  LaneMask |= SR->LaneMask;
304  }
305  if (LaneMask.none())
306  continue;
307  MachineBasicBlock *MBB = MBBI->second;
308  MBB->addLiveIn(PhysReg, LaneMask);
309  }
310 }
311 
312 // Compute MBB live-in lists from virtual register live ranges and their
313 // assignments.
314 void VirtRegRewriter::addMBBLiveIns() {
315  for (unsigned Idx = 0, IdxE = MRI->getNumVirtRegs(); Idx != IdxE; ++Idx) {
316  unsigned VirtReg = TargetRegisterInfo::index2VirtReg(Idx);
317  if (MRI->reg_nodbg_empty(VirtReg))
318  continue;
319  LiveInterval &LI = LIS->getInterval(VirtReg);
320  if (LI.empty() || LIS->intervalIsInOneMBB(LI))
321  continue;
322  // This is a virtual register that is live across basic blocks. Its
323  // assigned PhysReg must be marked as live-in to those blocks.
324  unsigned PhysReg = VRM->getPhys(VirtReg);
325  assert(PhysReg != VirtRegMap::NO_PHYS_REG && "Unmapped virtual register.");
326 
327  if (LI.hasSubRanges()) {
328  addLiveInsForSubRanges(LI, PhysReg);
329  } else {
330  // Go over MBB begin positions and see if we have segments covering them.
331  // The following works because segments and the MBBIndex list are both
332  // sorted by slot indexes.
333  SlotIndexes::MBBIndexIterator I = Indexes->MBBIndexBegin();
334  for (const auto &Seg : LI) {
335  I = Indexes->advanceMBBIndex(I, Seg.start);
336  for (; I != Indexes->MBBIndexEnd() && I->first < Seg.end; ++I) {
337  MachineBasicBlock *MBB = I->second;
338  MBB->addLiveIn(PhysReg);
339  }
340  }
341  }
342  }
343 
344  // Sort and unique MBB LiveIns as we've not checked if SubReg/PhysReg were in
345  // each MBB's LiveIns set before calling addLiveIn on them.
346  for (MachineBasicBlock &MBB : *MF)
347  MBB.sortUniqueLiveIns();
348 }
349 
350 /// Returns true if the given machine operand \p MO only reads undefined lanes.
351 /// The function only works for use operands with a subregister set.
352 bool VirtRegRewriter::readsUndefSubreg(const MachineOperand &MO) const {
353  // Shortcut if the operand is already marked undef.
354  if (MO.isUndef())
355  return true;
356 
357  unsigned Reg = MO.getReg();
358  const LiveInterval &LI = LIS->getInterval(Reg);
359  const MachineInstr &MI = *MO.getParent();
360  SlotIndex BaseIndex = LIS->getInstructionIndex(MI);
361  // This code is only meant to handle reading undefined subregisters which
362  // we couldn't properly detect before.
363  assert(LI.liveAt(BaseIndex) &&
364  "Reads of completely dead register should be marked undef already");
365  unsigned SubRegIdx = MO.getSubReg();
366  assert(SubRegIdx != 0 && LI.hasSubRanges());
367  LaneBitmask UseMask = TRI->getSubRegIndexLaneMask(SubRegIdx);
368  // See if any of the relevant subregister liveranges is defined at this point.
369  for (const LiveInterval::SubRange &SR : LI.subranges()) {
370  if ((SR.LaneMask & UseMask).any() && SR.liveAt(BaseIndex))
371  return false;
372  }
373  return true;
374 }
375 
376 void VirtRegRewriter::handleIdentityCopy(MachineInstr &MI) const {
377  if (!MI.isIdentityCopy())
378  return;
379  LLVM_DEBUG(dbgs() << "Identity copy: " << MI);
380  ++NumIdCopies;
381 
382  // Copies like:
383  // %r0 = COPY undef %r0
384  // %al = COPY %al, implicit-def %eax
385  // give us additional liveness information: The target (super-)register
386  // must not be valid before this point. Replace the COPY with a KILL
387  // instruction to maintain this information.
388  if (MI.getOperand(0).isUndef() || MI.getNumOperands() > 2) {
389  MI.setDesc(TII->get(TargetOpcode::KILL));
390  LLVM_DEBUG(dbgs() << " replace by: " << MI);
391  return;
392  }
393 
394  if (Indexes)
395  Indexes->removeSingleMachineInstrFromMaps(MI);
396  MI.eraseFromBundle();
397  LLVM_DEBUG(dbgs() << " deleted.\n");
398 }
399 
400 /// The liverange splitting logic sometimes produces bundles of copies when
401 /// subregisters are involved. Expand these into a sequence of copy instructions
402 /// after processing the last in the bundle. Does not update LiveIntervals
403 /// which we shouldn't need for this instruction anymore.
404 void VirtRegRewriter::expandCopyBundle(MachineInstr &MI) const {
405  if (!MI.isCopy())
406  return;
407 
408  if (MI.isBundledWithPred() && !MI.isBundledWithSucc()) {
410 
411  // Only do this when the complete bundle is made out of COPYs.
412  MachineBasicBlock &MBB = *MI.getParent();
414  std::next(MI.getReverseIterator()), E = MBB.instr_rend();
415  I != E && I->isBundledWithSucc(); ++I) {
416  if (!I->isCopy())
417  return;
418  MIs.push_back(&*I);
419  }
420  MachineInstr *FirstMI = MIs.back();
421 
422  auto anyRegsAlias = [](const MachineInstr *Dst,
424  const TargetRegisterInfo *TRI) {
425  for (const MachineInstr *Src : Srcs)
426  if (Src != Dst)
427  if (TRI->regsOverlap(Dst->getOperand(0).getReg(),
428  Src->getOperand(1).getReg()))
429  return true;
430  return false;
431  };
432 
433  // If any of the destination registers in the bundle of copies alias any of
434  // the source registers, try to schedule the instructions to avoid any
435  // clobbering.
436  for (int E = MIs.size(), PrevE = E; E > 1; PrevE = E) {
437  for (int I = E; I--; )
438  if (!anyRegsAlias(MIs[I], makeArrayRef(MIs).take_front(E), TRI)) {
439  if (I + 1 != E)
440  std::swap(MIs[I], MIs[E - 1]);
441  --E;
442  }
443  if (PrevE == E) {
444  MF->getFunction().getContext().emitError(
445  "register rewriting failed: cycle in copy bundle");
446  break;
447  }
448  }
449 
450  MachineInstr *BundleStart = FirstMI;
451  for (MachineInstr *BundledMI : llvm::reverse(MIs)) {
452  // If instruction is in the middle of the bundle, move it before the
453  // bundle starts, otherwise, just unbundle it. When we get to the last
454  // instruction, the bundle will have been completely undone.
455  if (BundledMI != BundleStart) {
456  BundledMI->removeFromBundle();
457  MBB.insert(FirstMI, BundledMI);
458  } else if (BundledMI->isBundledWithSucc()) {
459  BundledMI->unbundleFromSucc();
460  BundleStart = &*std::next(BundledMI->getIterator());
461  }
462 
463  if (Indexes && BundledMI != FirstMI)
464  Indexes->insertMachineInstrInMaps(*BundledMI);
465  }
466  }
467 }
468 
469 /// Check whether (part of) \p SuperPhysReg is live through \p MI.
470 /// \pre \p MI defines a subregister of a virtual register that
471 /// has been assigned to \p SuperPhysReg.
472 bool VirtRegRewriter::subRegLiveThrough(const MachineInstr &MI,
473  unsigned SuperPhysReg) const {
474  SlotIndex MIIndex = LIS->getInstructionIndex(MI);
475  SlotIndex BeforeMIUses = MIIndex.getBaseIndex();
476  SlotIndex AfterMIDefs = MIIndex.getBoundaryIndex();
477  for (MCRegUnitIterator Unit(SuperPhysReg, TRI); Unit.isValid(); ++Unit) {
478  const LiveRange &UnitRange = LIS->getRegUnit(*Unit);
479  // If the regunit is live both before and after MI,
480  // we assume it is live through.
481  // Generally speaking, this is not true, because something like
482  // "RU = op RU" would match that description.
483  // However, we know that we are trying to assess whether
484  // a def of a virtual reg, vreg, is live at the same time of RU.
485  // If we are in the "RU = op RU" situation, that means that vreg
486  // is defined at the same time as RU (i.e., "vreg, RU = op RU").
487  // Thus, vreg and RU interferes and vreg cannot be assigned to
488  // SuperPhysReg. Therefore, this situation cannot happen.
489  if (UnitRange.liveAt(AfterMIDefs) && UnitRange.liveAt(BeforeMIUses))
490  return true;
491  }
492  return false;
493 }
494 
495 void VirtRegRewriter::rewrite() {
496  bool NoSubRegLiveness = !MRI->subRegLivenessEnabled();
497  SmallVector<unsigned, 8> SuperDeads;
498  SmallVector<unsigned, 8> SuperDefs;
499  SmallVector<unsigned, 8> SuperKills;
500 
501  for (MachineFunction::iterator MBBI = MF->begin(), MBBE = MF->end();
502  MBBI != MBBE; ++MBBI) {
503  LLVM_DEBUG(MBBI->print(dbgs(), Indexes));
505  MII = MBBI->instr_begin(), MIE = MBBI->instr_end(); MII != MIE;) {
506  MachineInstr *MI = &*MII;
507  ++MII;
508 
510  MOE = MI->operands_end(); MOI != MOE; ++MOI) {
511  MachineOperand &MO = *MOI;
512 
513  // Make sure MRI knows about registers clobbered by regmasks.
514  if (MO.isRegMask())
515  MRI->addPhysRegsUsedFromRegMask(MO.getRegMask());
516 
518  continue;
519  unsigned VirtReg = MO.getReg();
520  unsigned PhysReg = VRM->getPhys(VirtReg);
521  assert(PhysReg != VirtRegMap::NO_PHYS_REG &&
522  "Instruction uses unmapped VirtReg");
523  assert(!MRI->isReserved(PhysReg) && "Reserved register assignment");
524 
525  // Preserve semantics of sub-register operands.
526  unsigned SubReg = MO.getSubReg();
527  if (SubReg != 0) {
528  if (NoSubRegLiveness || !MRI->shouldTrackSubRegLiveness(VirtReg)) {
529  // A virtual register kill refers to the whole register, so we may
530  // have to add implicit killed operands for the super-register. A
531  // partial redef always kills and redefines the super-register.
532  if ((MO.readsReg() && (MO.isDef() || MO.isKill())) ||
533  (MO.isDef() && subRegLiveThrough(*MI, PhysReg)))
534  SuperKills.push_back(PhysReg);
535 
536  if (MO.isDef()) {
537  // Also add implicit defs for the super-register.
538  if (MO.isDead())
539  SuperDeads.push_back(PhysReg);
540  else
541  SuperDefs.push_back(PhysReg);
542  }
543  } else {
544  if (MO.isUse()) {
545  if (readsUndefSubreg(MO))
546  // We need to add an <undef> flag if the subregister is
547  // completely undefined (and we are not adding super-register
548  // defs).
549  MO.setIsUndef(true);
550  } else if (!MO.isDead()) {
551  assert(MO.isDef());
552  }
553  }
554 
555  // The def undef and def internal flags only make sense for
556  // sub-register defs, and we are substituting a full physreg. An
557  // implicit killed operand from the SuperKills list will represent the
558  // partial read of the super-register.
559  if (MO.isDef()) {
560  MO.setIsUndef(false);
561  MO.setIsInternalRead(false);
562  }
563 
564  // PhysReg operands cannot have subregister indexes.
565  PhysReg = TRI->getSubReg(PhysReg, SubReg);
566  assert(PhysReg && "Invalid SubReg for physical register");
567  MO.setSubReg(0);
568  }
569  // Rewrite. Note we could have used MachineOperand::substPhysReg(), but
570  // we need the inlining here.
571  MO.setReg(PhysReg);
572  MO.setIsRenamable(true);
573  }
574 
575  // Add any missing super-register kills after rewriting the whole
576  // instruction.
577  while (!SuperKills.empty())
578  MI->addRegisterKilled(SuperKills.pop_back_val(), TRI, true);
579 
580  while (!SuperDeads.empty())
581  MI->addRegisterDead(SuperDeads.pop_back_val(), TRI, true);
582 
583  while (!SuperDefs.empty())
584  MI->addRegisterDefined(SuperDefs.pop_back_val(), TRI);
585 
586  LLVM_DEBUG(dbgs() << "> " << *MI);
587 
588  expandCopyBundle(*MI);
589 
590  // We can remove identity copies right now.
591  handleIdentityCopy(*MI);
592  }
593  }
594 }
bool isRegMask() const
isRegMask - Tests if this is a MO_RegisterMask operand.
bool empty() const
Definition: LiveInterval.h:370
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
mop_iterator operands_end()
Definition: MachineInstr.h:454
A common definition of LaneBitmask for use in TableGen and CodeGen.
MachineInstr * getParent()
getParent - Return the instruction that this operand belongs to.
const TargetRegisterClass * getRegClass(unsigned Reg) const
Return the register class of the specified virtual register.
SlotIndex getBaseIndex() const
Returns the base index for associated with this index.
Definition: SlotIndexes.h:242
This class represents lattice values for constants.
Definition: AllocatorList.h:24
static unsigned index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:65
bool addRegisterDead(unsigned Reg, const TargetRegisterInfo *RegInfo, bool AddIfNotFound=false)
We have determined MI defined a register without a use.
bool isBundledWithPred() const
Return true if this instruction is part of a bundle, and it is not the first instruction in the bundl...
Definition: MachineInstr.h:362
LiveInterval - This class represents the liveness of a register, or stack slot.
Definition: LiveInterval.h:638
unsigned getReg() const
getReg - Returns the register number.
void setIsUndef(bool Val=true)
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
unsigned Reg
unsigned getSubReg() const
void print(raw_ostream &OS, const Module *M=nullptr) const override
print - Print out the internal state of the pass.
Definition: VirtRegMap.cpp:139
A live range for subregisters.
Definition: LiveInterval.h:645
bool isValid() const
Returns true if this is a valid index.
Definition: SlotIndexes.h:152
STATISTIC(NumFunctions, "Total number of functions")
unsigned const TargetRegisterInfo * TRI
void setIsRenamable(bool Val=true)
void dump() const
Definition: VirtRegMap.cpp:161
unsigned getSpillSize(const TargetRegisterClass &RC) const
Return the size in bytes of the stack slot allocated to hold a spilled copy of a register from class ...
This class represents the liveness of a register, stack slot, etc.
Definition: LiveInterval.h:157
const char * getRegClassName(const TargetRegisterClass *Class) const
Returns the name of the register class.
unsigned getSpillAlignment(const TargetRegisterClass &RC) const
Return the minimum required alignment in bytes for a spill slot for a register of this class...
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition: PassSupport.h:51
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
const HexagonInstrInfo * TII
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:451
unsigned getNumOperands() const
Retuns the total number of operands.
Definition: MachineInstr.h:412
Printable printReg(unsigned Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
bool isBundledWithSucc() const
Return true if this instruction is part of a bundle, and it is not the last instruction in the bundle...
Definition: MachineInstr.h:366
iterator end()
Definition: LiveInterval.h:212
iterator_range< subrange_iterator > subranges()
Definition: LiveInterval.h:723
unsigned SubReg
bool hasSubRanges() const
Returns true if subregister liveness information is available.
Definition: LiveInterval.h:751
SmallVectorImpl< IdxMBBPair >::const_iterator MBBIndexIterator
Iterator over the idx2MBBMap (sorted pairs of slot index of basic block begin and basic block) ...
Definition: SlotIndexes.h:514
#define LLVM_DUMP_METHOD
Definition: Compiler.h:74
auto reverse(ContainerTy &&C, typename std::enable_if< has_rbegin< ContainerTy >::value >::type *=nullptr) -> decltype(make_range(C.rbegin(), C.rend()))
Definition: STLExtras.h:267
bool readsReg() const
readsReg - Returns true if this operand reads the previous value of its register. ...
SlotIndexes pass.
Definition: SlotIndexes.h:331
bool isIdentityCopy() const
Return true is the instruction is an identity copy.
int getObjectIndexBegin() const
Return the minimum frame object index.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
TargetInstrInfo - Interface to description of machine instruction set.
void addLiveIn(MCPhysReg PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
unsigned const MachineRegisterInfo * MRI
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
bool liveAt(SlotIndex index) const
Definition: LiveInterval.h:389
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
MachineRegisterInfo & getRegInfo() const
Definition: VirtRegMap.h:88
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
struct UnitT Unit
bool hasPreferredPhys(unsigned VirtReg)
returns true if VirtReg is assigned to its preferred physreg.
Definition: VirtRegMap.cpp:103
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
Definition: VirtRegMap.cpp:63
Represent the analysis usage information of a pass.
constexpr bool none() const
Definition: LaneBitmask.h:52
void setIsInternalRead(bool Val=true)
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Definition: VirtRegMap.h:78
unsigned getNumVirtRegs() const
getNumVirtRegs - Return the number of virtual registers created.
bool hasKnownPreference(unsigned VirtReg)
returns true if VirtReg has a known preferred register.
Definition: VirtRegMap.cpp:112
bool isCopy() const
int CreateSpillStackObject(uint64_t Size, unsigned Alignment)
Create a new statically sized stack object that represents a spill slot, returning a nonnegative iden...
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
void eraseFromBundle()
Unlink &#39;this&#39; form its basic block and delete it.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:34
MachineInstr * removeFromBundle()
Unlink this instruction from its basic block and return it without deleting it.
Iterator for intrusive lists based on ilist_node.
void setDesc(const MCInstrDesc &tid)
Replace the instruction descriptor (thus opcode) of the current instruction with a new one...
void assignVirt2Phys(unsigned virtReg, MCPhysReg physReg)
creates a mapping for the specified virtual register to the specified physical register ...
Definition: VirtRegMap.cpp:84
Segments::const_iterator const_iterator
Definition: LiveInterval.h:209
MachineOperand class - Representation of each machine instruction operand.
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:847
Promote Memory to Register
Definition: Mem2Reg.cpp:110
LLVM_NODISCARD T pop_back_val()
Definition: SmallVector.h:381
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:133
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition: BitVector.h:941
void addRegisterDefined(unsigned Reg, const TargetRegisterInfo *RegInfo=nullptr)
We have determined MI defines a register.
const uint32_t * getRegMask() const
getRegMask - Returns a bit mask of registers preserved by this RegMask operand.
virtregrewriter
Definition: VirtRegMap.cpp:222
iterator insert(iterator I, T &&Elt)
Definition: SmallVector.h:478
const MachineBasicBlock * getParent() const
Definition: MachineInstr.h:254
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
MachineFunctionProperties & set(Property P)
Virtual Register Rewriter
Definition: VirtRegMap.cpp:222
Representation of each machine instruction.
Definition: MachineInstr.h:64
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
static char ID
Definition: VirtRegMap.h:69
std::pair< unsigned, unsigned > getRegAllocationHint(unsigned VReg) const
getRegAllocationHint - Return the register allocation hint for the specified virtual register...
reverse_self_iterator getReverseIterator()
Definition: ilist_node.h:85
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
LLVM_NODISCARD bool empty() const
Definition: SmallVector.h:56
void setReg(unsigned Reg)
Change the register this operand corresponds to.
void push_back(MachineInstr *MI)
#define I(x, y, z)
Definition: MD5.cpp:58
void setSubReg(unsigned subReg)
bool hasPhys(unsigned virtReg) const
returns true if the specified virtual register is mapped to a physical register
Definition: VirtRegMap.h:95
virtual MachineFunctionProperties getSetProperties() const
uint32_t Size
Definition: Profile.cpp:47
unsigned getPhys(unsigned virtReg) const
returns the physical register mapped to the specified virtual register
Definition: VirtRegMap.h:101
bool isReg() const
isReg - Tests if this is a MO_Register operand.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
mop_iterator operands_begin()
Definition: MachineInstr.h:453
char & VirtRegRewriterID
VirtRegRewriter pass.
Definition: VirtRegMap.cpp:213
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
int assignVirt2StackSlot(unsigned virtReg)
create a mapping for the specifed virtual register to the next available stack slot ...
Definition: VirtRegMap.cpp:121
bool addRegisterKilled(unsigned IncomingReg, const TargetRegisterInfo *RegInfo, bool AddIfNotFound=false)
We have determined MI kills a register.
IRTranslator LLVM IR MI
unsigned getSimpleHint(unsigned VReg) const
getSimpleHint - same as getRegAllocationHint except it will only return a target independent hint...
#define LLVM_DEBUG(X)
Definition: Debug.h:123
const MachineOperand & getOperand(unsigned i) const
Definition: MachineInstr.h:414
SlotIndex - An opaque wrapper around machine indexes.
Definition: SlotIndexes.h:84
SlotIndex getBoundaryIndex() const
Returns the boundary index for associated with this index.
Definition: SlotIndexes.h:249
Properties which a MachineFunction may have at a given point in time.
INITIALIZE_PASS_BEGIN(VirtRegRewriter, "virtregrewriter", "Virtual Register Rewriter", false, false) INITIALIZE_PASS_END(VirtRegRewriter