LLVM 24.0.0git
PHIElimination.cpp
Go to the documentation of this file.
1//===- PhiElimination.cpp - Eliminate PHI nodes by inserting copies -------===//
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// This pass eliminates machine instruction PHI nodes by inserting copy
10// instructions. This destroys SSA information, but is the desired input for
11// some register allocators.
12//
13//===----------------------------------------------------------------------===//
14
16#include "PHIEliminationUtils.h"
17#include "llvm/ADT/DenseMap.h"
19#include "llvm/ADT/SmallSet.h"
20#include "llvm/ADT/Statistic.h"
45#include "llvm/Pass.h"
47#include "llvm/Support/Debug.h"
49#include <cassert>
50#include <iterator>
51#include <utility>
52
53using namespace llvm;
54
55#define DEBUG_TYPE "phi-node-elimination"
56
57static cl::opt<bool>
58 DisableEdgeSplitting("disable-phi-elim-edge-splitting", cl::init(false),
60 cl::desc("Disable critical edge splitting "
61 "during PHI elimination"));
62
63static cl::opt<bool>
64 SplitAllCriticalEdges("phi-elim-split-all-critical-edges", cl::init(false),
66 cl::desc("Split all critical edges during "
67 "PHI elimination"));
68
70 "no-phi-elim-live-out-early-exit", cl::init(false), cl::Hidden,
71 cl::desc("Do not use an early exit if isLiveOutPastPHIs returns true."));
72
73namespace {
74
75class PHIEliminationImpl {
76 MachineRegisterInfo *MRI = nullptr; // Machine register information
77 LiveVariables *LV = nullptr;
78 SlotIndexes *SI = nullptr;
79 LiveIntervals *LIS = nullptr;
80 MachineLoopInfo *MLI = nullptr;
81 MachineDominatorTree *MDT = nullptr;
82 MachinePostDominatorTree *PDT = nullptr;
83 const MachineBranchProbabilityInfo *MBPI = nullptr;
84 MachineBlockFrequencyInfo *MBFI = nullptr;
85
86 /// EliminatePHINodes - Eliminate phi nodes by inserting copy instructions
87 /// in predecessor basic blocks.
88 bool EliminatePHINodes(MachineFunction &MF, MachineBasicBlock &MBB);
89
90 void LowerPHINode(MachineBasicBlock &MBB,
92 bool AllEdgesCritical);
93
94 /// analyzePHINodes - Gather information about the PHI nodes in
95 /// here. In particular, we want to map the number of uses of a virtual
96 /// register which is used in a PHI node. We map that to the BB the
97 /// vreg is coming from. This is used later to determine when the vreg
98 /// is killed in the BB.
99 void analyzePHINodes(const MachineFunction &MF);
100
101 /// Split critical edges where necessary for good coalescer performance.
102 bool SplitPHIEdges(MachineFunction &MF, MachineBasicBlock &MBB,
103 MachineLoopInfo *MLI,
104 std::vector<SparseBitVector<>> *LiveInSets,
106
107 // These functions are temporary abstractions around LiveVariables and
108 // LiveIntervals, so they can go away when LiveVariables does.
109 bool isLiveIn(Register Reg, const MachineBasicBlock *MBB);
110 bool isLiveOutPastPHIs(Register Reg, const MachineBasicBlock *MBB);
111
112 using BBVRegPair = std::pair<unsigned, Register>;
113 using VRegPHIUse = DenseMap<BBVRegPair, unsigned>;
114
115 // Count the number of non-undef PHI uses of each register in each BB.
116 VRegPHIUse VRegPHIUseCount;
117
118 // PHI source registers whose subranges must be shrunk to their own uses once
119 // all PHIs are gone.
120 SmallSet<Register, 8> PHISrcRegsToShrink;
121
122 // Defs of PHI sources which are implicit_def.
124
125 // Map reusable lowered PHI node -> incoming join register.
126 using LoweredPHIMap =
128 LoweredPHIMap LoweredPHIs;
129
130 MachineFunctionPass *P = nullptr;
131 MachineFunctionAnalysisManager *MFAM = nullptr;
132
133public:
134 PHIEliminationImpl(MachineFunctionPass *P) : P(P) {
135 auto *LVWrapper = P->getAnalysisIfAvailable<LiveVariablesWrapperPass>();
136 auto *SIWrapper = P->getAnalysisIfAvailable<SlotIndexesWrapperPass>();
137 auto *LISWrapper = P->getAnalysisIfAvailable<LiveIntervalsWrapperPass>();
138 auto *MLIWrapper = P->getAnalysisIfAvailable<MachineLoopInfoWrapperPass>();
139 auto *MDTWrapper =
140 P->getAnalysisIfAvailable<MachineDominatorTreeWrapperPass>();
141 auto *PDTWrapper =
142 P->getAnalysisIfAvailable<MachinePostDominatorTreeWrapperPass>();
143 auto *MBPIWrapper =
144 P->getAnalysisIfAvailable<MachineBranchProbabilityInfoWrapperPass>();
145 auto *MBFIWrapper =
146 P->getAnalysisIfAvailable<MachineBlockFrequencyInfoWrapperPass>();
147
148 LV = LVWrapper ? &LVWrapper->getLV() : nullptr;
149 SI = SIWrapper ? &SIWrapper->getSI() : nullptr;
150 LIS = LISWrapper ? &LISWrapper->getLIS() : nullptr;
151 MLI = MLIWrapper ? &MLIWrapper->getLI() : nullptr;
152 MDT = MDTWrapper ? &MDTWrapper->getDomTree() : nullptr;
153 PDT = PDTWrapper ? &PDTWrapper->getPostDomTree() : nullptr;
154 MBPI = MBPIWrapper ? &MBPIWrapper->getMBPI() : nullptr;
155 MBFI = MBFIWrapper ? &MBFIWrapper->getMBFI() : nullptr;
156 }
157
158 PHIEliminationImpl(MachineFunction &MF, MachineFunctionAnalysisManager &AM)
159 : LV(AM.getCachedResult<LiveVariablesAnalysis>(MF)),
160 SI(AM.getCachedResult<SlotIndexesAnalysis>(MF)),
161 LIS(AM.getCachedResult<LiveIntervalsAnalysis>(MF)),
162 MLI(AM.getCachedResult<MachineLoopAnalysis>(MF)),
163 MDT(AM.getCachedResult<MachineDominatorTreeAnalysis>(MF)),
164 PDT(AM.getCachedResult<MachinePostDominatorTreeAnalysis>(MF)),
165 MBPI(AM.getCachedResult<MachineBranchProbabilityAnalysis>(MF)),
166 MBFI(AM.getCachedResult<MachineBlockFrequencyAnalysis>(MF)), MFAM(&AM) {
167 }
168
169 bool run(MachineFunction &MF);
170};
171
172class PHIElimination : public MachineFunctionPass {
173public:
174 static char ID; // Pass identification, replacement for typeid
175
176 PHIElimination() : MachineFunctionPass(ID) {}
177
178 bool runOnMachineFunction(MachineFunction &MF) override {
179 PHIEliminationImpl Impl(this);
180 return Impl.run(MF);
181 }
182
183 MachineFunctionProperties getSetProperties() const override {
184 return MachineFunctionProperties().setNoPHIs();
185 }
186
187 void getAnalysisUsage(AnalysisUsage &AU) const override;
188};
189
190} // end anonymous namespace
191
195 PHIEliminationImpl Impl(MF, MFAM);
196 bool Changed = Impl.run(MF);
197 if (!Changed)
198 return PreservedAnalyses::all();
200 PA.preserve<LiveIntervalsAnalysis>();
201 PA.preserve<LiveVariablesAnalysis>();
202 PA.preserve<SlotIndexesAnalysis>();
203 PA.preserve<MachineDominatorTreeAnalysis>();
205 PA.preserve<MachineLoopAnalysis>();
206 PA.preserve<MachineBlockFrequencyAnalysis>();
207 return PA;
208}
209
210STATISTIC(NumLowered, "Number of phis lowered");
211STATISTIC(NumCriticalEdgesSplit, "Number of critical edges split");
212STATISTIC(NumReused, "Number of reused lowered phis");
213
214char PHIElimination::ID = 0;
215
216char &llvm::PHIEliminationID = PHIElimination::ID;
217
219 "Eliminate PHI nodes for register allocation", false,
220 false)
225 "Eliminate PHI nodes for register allocation", false, false)
226
227void PHIElimination::getAnalysisUsage(AnalysisUsage &AU) const {
228 AU.addUsedIfAvailable<LiveVariablesWrapperPass>();
229 AU.addUsedIfAvailable<MachineLoopInfoWrapperPass>();
230 AU.addPreserved<LiveVariablesWrapperPass>();
231 AU.addPreserved<SlotIndexesWrapperPass>();
232 AU.addPreserved<LiveIntervalsWrapperPass>();
233 AU.addPreserved<MachineDominatorTreeWrapperPass>();
234 AU.addPreserved<MachinePostDominatorTreeWrapperPass>();
235 AU.addPreserved<MachineLoopInfoWrapperPass>();
236 AU.addPreserved<MachineBlockFrequencyInfoWrapperPass>();
237 AU.addPreserved<MachineRegisterClassInfoWrapperPass>();
239}
240
241bool PHIEliminationImpl::run(MachineFunction &MF) {
242 MRI = &MF.getRegInfo();
243
244 MachineDomTreeUpdater MDTU(MDT, PDT,
245 MachineDomTreeUpdater::UpdateStrategy::Lazy);
246
247 bool Changed = false;
248
249 // Split critical edges to help the coalescer.
250 if (!DisableEdgeSplitting && (LV || LIS)) {
251 // A set of live-in regs for each MBB which is used to update LV
252 // efficiently also with large functions.
253 std::vector<SparseBitVector<>> LiveInSets;
254 if (LV) {
255 LiveInSets.resize(MF.size());
256 for (unsigned Index = 0, e = MRI->getNumVirtRegs(); Index != e; ++Index) {
257 // Set the bit for this register for each MBB where it is
258 // live-through or live-in (killed).
259 Register VirtReg = Register::index2VirtReg(Index);
260 MachineInstr *DefMI = MRI->getVRegDef(VirtReg);
261 if (!DefMI)
262 continue;
263 LiveVariables::VarInfo &VI = LV->getVarInfo(VirtReg);
264 SparseBitVector<>::iterator AliveBlockItr = VI.AliveBlocks.begin();
265 SparseBitVector<>::iterator EndItr = VI.AliveBlocks.end();
266 while (AliveBlockItr != EndItr) {
267 unsigned BlockNum = *(AliveBlockItr++);
268 LiveInSets[BlockNum].set(Index);
269 }
270 // The register is live into an MBB in which it is killed but not
271 // defined. See comment for VarInfo in LiveVariables.h.
272 MachineBasicBlock *DefMBB = DefMI->getParent();
273 if (VI.Kills.size() > 1 ||
274 (!VI.Kills.empty() && VI.Kills.front()->getParent() != DefMBB))
275 for (auto *MI : VI.Kills)
276 LiveInSets[MI->getParent()->getNumber()].set(Index);
277 }
278 }
279
280 for (auto &MBB : MF)
281 Changed |=
282 SplitPHIEdges(MF, MBB, MLI, (LV ? &LiveInSets : nullptr), MDTU);
283 }
284
285 // This pass takes the function out of SSA form.
286 MRI->leaveSSA();
287
288 // Populate VRegPHIUseCount
289 if (LV || LIS)
290 analyzePHINodes(MF);
291
292 // Eliminate PHI instructions by inserting copies into predecessor blocks.
293 for (auto &MBB : MF)
294 Changed |= EliminatePHINodes(MF, MBB);
295
296 // Remove dead IMPLICIT_DEF instructions.
297 for (MachineInstr *DefMI : ImpDefs) {
298 Register DefReg = DefMI->getOperand(0).getReg();
299 if (MRI->use_nodbg_empty(DefReg)) {
300 if (SI)
301 SI->removeMachineInstrFromMaps(*DefMI);
303 }
304 }
305
306 // Clean up the lowered PHI instructions.
307 for (auto &I : LoweredPHIs) {
308 if (SI)
309 SI->removeMachineInstrFromMaps(*I.first);
310 MF.deleteMachineInstr(I.first);
311 }
312
313 LoweredPHIs.clear();
314
315 // Different lanes may be used by different PHI source copies, or may already
316 // be dead in a predecessor. The main range's last use is therefore not a
317 // valid endpoint for every subrange. Wait until all PHIs have been removed
318 // before shrinking subranges to their remaining lane-specific uses.
319 for (Register Reg : PHISrcRegsToShrink) {
320 LiveInterval &LI = LIS->getInterval(Reg);
321 for (LiveInterval::SubRange &SR : LI.subranges())
322 LIS->shrinkToUses(SR, Reg);
323 }
324 PHISrcRegsToShrink.clear();
325
326 ImpDefs.clear();
327 VRegPHIUseCount.clear();
328
329 MF.getProperties().setNoPHIs();
330
331 return Changed;
332}
333
334/// EliminatePHINodes - Eliminate phi nodes by inserting copy instructions in
335/// predecessor basic blocks.
336bool PHIEliminationImpl::EliminatePHINodes(MachineFunction &MF,
338 if (MBB.empty() || !MBB.front().isPHI())
339 return false; // Quick exit for basic blocks without PHIs.
340
341 // Get an iterator to the last PHI node.
343 std::prev(MBB.SkipPHIsAndLabels(MBB.begin()));
344
345 // If all incoming edges are critical, we try to deduplicate identical PHIs so
346 // that we generate fewer copies. If at any edge is non-critical, we either
347 // have less than two predecessors (=> no PHIs) or a predecessor has only us
348 // as a successor (=> identical PHI node can't occur in different block).
349 bool AllEdgesCritical = MBB.pred_size() >= 2;
350 for (MachineBasicBlock *Pred : MBB.predecessors()) {
351 if (Pred->succ_size() < 2) {
352 AllEdgesCritical = false;
353 break;
354 }
355 }
356
357 while (MBB.front().isPHI())
358 LowerPHINode(MBB, LastPHIIt, AllEdgesCritical);
359
360 return true;
361}
362
363/// Return true if all defs of VirtReg are implicit-defs.
364/// This includes registers with no defs.
365static bool isImplicitlyDefined(Register VirtReg,
366 const MachineRegisterInfo &MRI) {
367 for (MachineInstr &DI : MRI.def_instructions(VirtReg))
368 if (!DI.isImplicitDef())
369 return false;
370 return true;
371}
372
373/// Return true if all sources of the phi node are implicit_def's, or undef's.
374static bool allPhiOperandsUndefined(const MachineInstr &MPhi,
375 const MachineRegisterInfo &MRI) {
376 for (unsigned I = 1, E = MPhi.getNumOperands(); I != E; I += 2) {
377 const MachineOperand &MO = MPhi.getOperand(I);
378 if (!isImplicitlyDefined(MO.getReg(), MRI) && !MO.isUndef())
379 return false;
380 }
381 return true;
382}
383/// LowerPHINode - Lower the PHI node at the top of the specified block.
384void PHIEliminationImpl::LowerPHINode(MachineBasicBlock &MBB,
386 bool AllEdgesCritical) {
387 ++NumLowered;
388
389 MachineBasicBlock::iterator AfterPHIsIt = std::next(LastPHIIt);
390
391 // Unlink the PHI node from the basic block, but don't delete the PHI yet.
392 MachineInstr *MPhi = MBB.remove(&*MBB.begin());
393
394 unsigned NumSrcs = (MPhi->getNumOperands() - 1) / 2;
395 Register DestReg = MPhi->getOperand(0).getReg();
396 assert(MPhi->getOperand(0).getSubReg() == 0 && "Can't handle sub-reg PHIs");
397 bool isDead = MPhi->getOperand(0).isDead();
398
399 // Create a new register for the incoming PHI arguments.
401 Register IncomingReg;
402 bool EliminateNow = true; // delay elimination of nodes in LoweredPHIs
403 bool reusedIncoming = false; // Is IncomingReg reused from an earlier PHI?
404
405 // Insert a register to register copy at the top of the current block (but
406 // after any remaining phi nodes) which copies the new incoming register
407 // into the phi node destination.
408 MachineInstr *PHICopy = nullptr;
410 if (allPhiOperandsUndefined(*MPhi, *MRI))
411 // If all sources of a PHI node are implicit_def or undef uses, just emit an
412 // implicit_def instead of a copy.
413 PHICopy = BuildMI(MBB, AfterPHIsIt, MPhi->getDebugLoc(),
414 TII->get(TargetOpcode::IMPLICIT_DEF), DestReg);
415 else {
416 // Can we reuse an earlier PHI node? This only happens for critical edges,
417 // typically those created by tail duplication. Typically, an identical PHI
418 // node can't occur, so avoid hashing/storing such PHIs, which is somewhat
419 // expensive.
420 Register *Entry = nullptr;
421 if (AllEdgesCritical)
422 Entry = &LoweredPHIs[MPhi];
423 if (Entry && *Entry) {
424 // An identical PHI node was already lowered. Reuse the incoming register.
425 IncomingReg = *Entry;
426 reusedIncoming = true;
427 ++NumReused;
428 LLVM_DEBUG(dbgs() << "Reusing " << printReg(IncomingReg) << " for "
429 << *MPhi);
430 } else {
431 const TargetRegisterClass *RC = MF.getRegInfo().getRegClass(DestReg);
432 IncomingReg = MF.getRegInfo().createVirtualRegister(RC);
433 if (Entry) {
434 EliminateNow = false;
435 *Entry = IncomingReg;
436 }
437 }
438
439 // Give the target possiblity to handle special cases fallthrough otherwise
440 PHICopy = TII->createPHIDestinationCopy(
441 MBB, AfterPHIsIt, MPhi->getDebugLoc(), IncomingReg, DestReg);
442 }
443
444 if (MPhi->peekDebugInstrNum() && IncomingReg) {
445 // If referred to by debug-info, store where this PHI was.
447 unsigned ID = MPhi->peekDebugInstrNum();
448 auto P = MachineFunction::DebugPHIRegallocPos(&MBB, IncomingReg, 0);
449 auto Res = MF->DebugPHIPositions.insert({ID, P});
450 assert(Res.second);
451 (void)Res;
452 }
453
454 // Update live variable information if there is any.
455 if (LV) {
456 if (IncomingReg) {
457 LiveVariables::VarInfo &VI = LV->getVarInfo(IncomingReg);
458
459 MachineInstr *OldKill = nullptr;
460 bool IsPHICopyAfterOldKill = false;
461
462 if (reusedIncoming && (OldKill = VI.findKill(&MBB))) {
463 // Calculate whether the PHICopy is after the OldKill.
464 // In general, the PHICopy is inserted as the first non-phi instruction
465 // by default, so it's before the OldKill. But some Target hooks for
466 // createPHIDestinationCopy() may modify the default insert position of
467 // PHICopy.
468 for (auto I = MBB.SkipPHIsAndLabels(MBB.begin()), E = MBB.end(); I != E;
469 ++I) {
470 if (I == PHICopy)
471 break;
472
473 if (I == OldKill) {
474 IsPHICopyAfterOldKill = true;
475 break;
476 }
477 }
478 }
479
480 // When we are reusing the incoming register and it has been marked killed
481 // by OldKill, if the PHICopy is after the OldKill, we should remove the
482 // killed flag from OldKill.
483 if (IsPHICopyAfterOldKill) {
484 LLVM_DEBUG(dbgs() << "Remove old kill from " << *OldKill);
485 LV->removeVirtualRegisterKilled(IncomingReg, *OldKill);
487 }
488
489 // Add information to LiveVariables to know that the first used incoming
490 // value or the resued incoming value whose PHICopy is after the OldKIll
491 // is killed. Note that because the value is defined in several places
492 // (once each for each incoming block), the "def" block and instruction
493 // fields for the VarInfo is not filled in.
494 if (!OldKill || IsPHICopyAfterOldKill)
495 LV->addVirtualRegisterKilled(IncomingReg, *PHICopy);
496 }
497
498 // Since we are going to be deleting the PHI node, if it is the last use of
499 // any registers, or if the value itself is dead, we need to move this
500 // information over to the new copy we just inserted.
502
503 // If the result is dead, update LV.
504 if (isDead) {
505 LV->addVirtualRegisterDead(DestReg, *PHICopy);
506 LV->removeVirtualRegisterDead(DestReg, *MPhi);
507 }
508 }
509
510 // Update LiveIntervals for the new copy or implicit def.
511 SlotIndex DestCopyIndex;
512 if (SI)
513 DestCopyIndex = SI->insertMachineInstrInMaps(*PHICopy);
514
515 if (LIS) {
516 assert(DestCopyIndex.isValid() &&
517 "Expected a valid SlotIndex if LIS is available.");
518 SlotIndex MBBStartIndex = LIS->getMBBStartIdx(&MBB);
519 if (IncomingReg) {
520 // Add the region from the beginning of MBB to the copy instruction to
521 // IncomingReg's live interval.
522 LiveInterval &IncomingLI = LIS->getOrCreateEmptyInterval(IncomingReg);
523 VNInfo *IncomingVNI = IncomingLI.getVNInfoAt(MBBStartIndex);
524 if (!IncomingVNI)
525 IncomingVNI =
526 IncomingLI.getNextValue(MBBStartIndex, LIS->getVNInfoAllocator());
528 MBBStartIndex, DestCopyIndex.getRegSlot(), IncomingVNI));
529 }
530
531 LiveInterval &DestLI = LIS->getInterval(DestReg);
532 assert(!DestLI.empty() && "PHIs should have non-empty LiveIntervals.");
533
534 // Make sure the instruction's dead flag matches the dead range created
535 // below.
536 if (DestLI.endIndex().isDead())
537 PHICopy->getOperand(0).setIsDead();
538
539 SlotIndex NewStart = DestCopyIndex.getRegSlot();
540
541 SmallVector<LiveRange *> ToUpdate({&DestLI});
542 for (auto &SR : DestLI.subranges())
543 ToUpdate.push_back(&SR);
544
545 for (auto LR : ToUpdate) {
546 auto DestSegment = LR->find(MBBStartIndex);
547 assert(DestSegment != LR->end() &&
548 "PHI destination must be live in block");
549
550 if (LR->endIndex().isDead()) {
551 // A dead PHI's live range begins and ends at the start of the MBB, but
552 // the lowered copy, which will still be dead, needs to begin and end at
553 // the copy instruction.
554 VNInfo *OrigDestVNI = LR->getVNInfoAt(DestSegment->start);
555 assert(OrigDestVNI && "PHI destination should be live at block entry.");
556 LR->removeSegment(DestSegment->start, DestSegment->start.getDeadSlot());
557 LR->createDeadDef(NewStart, LIS->getVNInfoAllocator());
558 LR->removeValNo(OrigDestVNI);
559 continue;
560 }
561
562 // Destination copies are not inserted in the same order as the PHI nodes
563 // they replace. Hence the start of the live range may need to be adjusted
564 // to match the actual slot index of the copy.
565 if (DestSegment->start > NewStart) {
566 VNInfo *VNI = LR->getVNInfoAt(DestSegment->start);
567 assert(VNI && "value should be defined for known segment");
568 LR->addSegment(
569 LiveInterval::Segment(NewStart, DestSegment->start, VNI));
570 } else if (DestSegment->start < NewStart) {
571 assert(DestSegment->start >= MBBStartIndex);
572 assert(DestSegment->end >= DestCopyIndex.getRegSlot());
573 LR->removeSegment(DestSegment->start, NewStart);
574 }
575 VNInfo *DestVNI = LR->getVNInfoAt(NewStart);
576 assert(DestVNI && "PHI destination should be live at its definition.");
577 DestVNI->def = NewStart;
578 }
579 }
580
581 // Adjust the VRegPHIUseCount map to account for the removal of this PHI node.
582 if (LV || LIS) {
583 for (unsigned i = 1; i != MPhi->getNumOperands(); i += 2) {
584 if (!MPhi->getOperand(i).isUndef()) {
585 --VRegPHIUseCount[BBVRegPair(
586 MPhi->getOperand(i + 1).getMBB()->getNumber(),
587 MPhi->getOperand(i).getReg())];
588 }
589 }
590 }
591
592 // Now loop over all of the incoming arguments, changing them to copy into the
593 // IncomingReg register in the corresponding predecessor basic block.
595 for (int i = NumSrcs - 1; i >= 0; --i) {
596 Register SrcReg = MPhi->getOperand(i * 2 + 1).getReg();
597 unsigned SrcSubReg = MPhi->getOperand(i * 2 + 1).getSubReg();
598 bool SrcUndef = MPhi->getOperand(i * 2 + 1).isUndef() ||
599 isImplicitlyDefined(SrcReg, *MRI);
600 assert(SrcReg.isVirtual() &&
601 "Machine PHI Operands must all be virtual registers!");
602
603 // Get the MachineBasicBlock equivalent of the BasicBlock that is the source
604 // path the PHI.
605 MachineBasicBlock &opBlock = *MPhi->getOperand(i * 2 + 2).getMBB();
606
607 // Check to make sure we haven't already emitted the copy for this block.
608 // This can happen because PHI nodes may have multiple entries for the same
609 // basic block.
610 if (!MBBsInsertedInto.insert(&opBlock).second)
611 continue; // If the copy has already been emitted, we're done.
612
613 MachineInstr *SrcRegDef = MRI->getVRegDef(SrcReg);
614 if (SrcRegDef && TII->isUnspillableTerminator(SrcRegDef)) {
615 assert(SrcRegDef->getOperand(0).isReg() &&
616 SrcRegDef->getOperand(0).isDef() &&
617 "Expected operand 0 to be a reg def!");
618 // Now that the PHI's use has been removed (as the instruction was
619 // removed) there should be no other uses of the SrcReg.
620 assert(MRI->use_empty(SrcReg) &&
621 "Expected a single use from UnspillableTerminator");
622 SrcRegDef->getOperand(0).setReg(IncomingReg);
623
624 // Update LiveVariables.
625 if (LV) {
626 LiveVariables::VarInfo &SrcVI = LV->getVarInfo(SrcReg);
627 LiveVariables::VarInfo &IncomingVI = LV->getVarInfo(IncomingReg);
628 IncomingVI.AliveBlocks = std::move(SrcVI.AliveBlocks);
629 SrcVI.AliveBlocks.clear();
630 }
631
632 continue;
633 }
634
635 // Find a safe location to insert the copy, this may be the first terminator
636 // in the block (or end()).
638 findPHICopyInsertPoint(&opBlock, &MBB, SrcReg);
639
640 // Insert the copy.
641 MachineInstr *NewSrcInstr = nullptr;
642 if (!reusedIncoming && IncomingReg) {
643 if (SrcUndef) {
644 // The source register is undefined, so there is no need for a real
645 // COPY, but we still need to ensure joint dominance by defs.
646 // Insert an IMPLICIT_DEF instruction.
647 NewSrcInstr =
648 BuildMI(opBlock, InsertPos, MPhi->getDebugLoc(),
649 TII->get(TargetOpcode::IMPLICIT_DEF), IncomingReg);
650
651 // Clean up the old implicit-def, if there even was one.
652 if (MachineInstr *DefMI = MRI->getVRegDef(SrcReg))
653 if (DefMI->isImplicitDef())
654 ImpDefs.insert(DefMI);
655 } else {
656 // Delete the debug location, since the copy is inserted into a
657 // different basic block.
658 NewSrcInstr = TII->createPHISourceCopy(opBlock, InsertPos, nullptr,
659 SrcReg, SrcSubReg, IncomingReg);
660 }
661 }
662
663 // We only need to update the LiveVariables kill of SrcReg if this was the
664 // last PHI use of SrcReg to be lowered on this CFG edge and it is not live
665 // out of the predecessor. We can also ignore undef sources.
666 if (LV && !SrcUndef &&
667 !VRegPHIUseCount[BBVRegPair(opBlock.getNumber(), SrcReg)] &&
668 !LV->isLiveOut(SrcReg, opBlock)) {
669 // We want to be able to insert a kill of the register if this PHI (aka,
670 // the copy we just inserted) is the last use of the source value. Live
671 // variable analysis conservatively handles this by saying that the value
672 // is live until the end of the block the PHI entry lives in. If the value
673 // really is dead at the PHI copy, there will be no successor blocks which
674 // have the value live-in.
675
676 // Okay, if we now know that the value is not live out of the block, we
677 // can add a kill marker in this block saying that it kills the incoming
678 // value!
679
680 // In our final twist, we have to decide which instruction kills the
681 // register. In most cases this is the copy, however, terminator
682 // instructions at the end of the block may also use the value. In this
683 // case, we should mark the last such terminator as being the killing
684 // block, not the copy.
685 MachineBasicBlock::iterator KillInst = opBlock.end();
686 for (MachineBasicBlock::iterator Term = InsertPos; Term != opBlock.end();
687 ++Term) {
688 if (Term->readsRegister(SrcReg, /*TRI=*/nullptr))
689 KillInst = Term;
690 }
691
692 if (KillInst == opBlock.end()) {
693 // No terminator uses the register.
694
695 if (reusedIncoming || !IncomingReg) {
696 // We may have to rewind a bit if we didn't insert a copy this time.
697 KillInst = InsertPos;
698 while (KillInst != opBlock.begin()) {
699 --KillInst;
700 if (KillInst->isDebugInstr())
701 continue;
702 if (KillInst->readsRegister(SrcReg, /*TRI=*/nullptr))
703 break;
704 }
705 } else {
706 // We just inserted this copy.
707 KillInst = NewSrcInstr;
708 }
709 }
710 assert(KillInst->readsRegister(SrcReg, /*TRI=*/nullptr) &&
711 "Cannot find kill instruction");
712
713 // Finally, mark it killed.
714 LV->addVirtualRegisterKilled(SrcReg, *KillInst);
715
716 // This vreg no longer lives all of the way through opBlock.
717 unsigned opBlockNum = opBlock.getNumber();
718 LV->getVarInfo(SrcReg).AliveBlocks.reset(opBlockNum);
719 } else if (LV && SrcUndef &&
720 !VRegPHIUseCount[BBVRegPair(opBlock.getNumber(), SrcReg)] &&
721 !LV->isLiveOut(SrcReg, opBlock)) {
722 // For undef sources we don't need a kill marker, but the register may
723 // no longer be live through intermediate blocks after the PHI use is
724 // removed. Recompute its LiveVariables info to clear stale AliveBlocks.
725 if (MRI->getVRegDef(SrcReg))
727 }
728
729 if (SI && NewSrcInstr)
730 SI->insertMachineInstrInMaps(*NewSrcInstr);
731
732 if (LIS) {
733 if (NewSrcInstr) {
734 assert(
735 SI &&
736 "Expected SI to be available to insert new MI if LIS is available");
737 LIS->addSegmentToEndOfBlock(IncomingReg, *NewSrcInstr);
738 }
739
740 if (!SrcUndef &&
741 !VRegPHIUseCount[BBVRegPair(opBlock.getNumber(), SrcReg)]) {
742 LiveInterval &SrcLI = LIS->getInterval(SrcReg);
743 if (SrcLI.hasSubRanges())
744 PHISrcRegsToShrink.insert(SrcReg);
745
746 bool isLiveOut = false;
747 for (MachineBasicBlock *Succ : opBlock.successors()) {
748 SlotIndex startIdx = LIS->getMBBStartIdx(Succ);
749 VNInfo *VNI = SrcLI.getVNInfoAt(startIdx);
750
751 // Definitions by other PHIs are not truly live-in for our purposes.
752 if (VNI && VNI->def != startIdx) {
753 isLiveOut = true;
754 break;
755 }
756 }
757
758 if (!isLiveOut) {
759 MachineBasicBlock::iterator KillInst = opBlock.end();
760 for (MachineBasicBlock::iterator Term = InsertPos;
761 Term != opBlock.end(); ++Term) {
762 if (Term->readsRegister(SrcReg, /*TRI=*/nullptr))
763 KillInst = Term;
764 }
765
766 if (KillInst == opBlock.end()) {
767 // No terminator uses the register.
768
769 if (reusedIncoming || !IncomingReg) {
770 // We may have to rewind a bit if we didn't just insert a copy.
771 KillInst = InsertPos;
772 while (KillInst != opBlock.begin()) {
773 --KillInst;
774 if (KillInst->isDebugInstr())
775 continue;
776 if (KillInst->readsRegister(SrcReg, /*TRI=*/nullptr))
777 break;
778 }
779 } else {
780 // We just inserted this copy.
781 KillInst = std::prev(InsertPos);
782 }
783 }
784 assert(KillInst->readsRegister(SrcReg, /*TRI=*/nullptr) &&
785 "Cannot find kill instruction");
786
787 SlotIndex LastUseIndex = LIS->getInstructionIndex(*KillInst);
788 SrcLI.removeSegment(LastUseIndex.getRegSlot(),
789 LIS->getMBBEndIdx(&opBlock));
790 }
791 }
792 }
793 }
794
795 // Really delete the PHI instruction now, if it is not in the LoweredPHIs map.
796 if (EliminateNow) {
797 if (SI)
798 SI->removeMachineInstrFromMaps(*MPhi);
799 MF.deleteMachineInstr(MPhi);
800 }
801}
802
803/// analyzePHINodes - Gather information about the PHI nodes in here. In
804/// particular, we want to map the number of uses of a virtual register which is
805/// used in a PHI node. We map that to the BB the vreg is coming from. This is
806/// used later to determine when the vreg is killed in the BB.
807void PHIEliminationImpl::analyzePHINodes(const MachineFunction &MF) {
808 for (const auto &MBB : MF) {
809 for (const auto &BBI : MBB) {
810 if (!BBI.isPHI())
811 break;
812 for (unsigned i = 1, e = BBI.getNumOperands(); i != e; i += 2) {
813 if (!BBI.getOperand(i).isUndef()) {
814 ++VRegPHIUseCount[BBVRegPair(
815 BBI.getOperand(i + 1).getMBB()->getNumber(),
816 BBI.getOperand(i).getReg())];
817 }
818 }
819 }
820 }
821}
822
823bool PHIEliminationImpl::SplitPHIEdges(
825 std::vector<SparseBitVector<>> *LiveInSets, MachineDomTreeUpdater &MDTU) {
826 if (MBB.empty() || !MBB.front().isPHI() || MBB.isEHPad())
827 return false; // Quick exit for basic blocks without PHIs.
828
829 const MachineLoop *CurLoop = MLI ? MLI->getLoopFor(&MBB) : nullptr;
830 bool IsLoopHeader = CurLoop && &MBB == CurLoop->getHeader();
831
832 bool Changed = false;
833 for (MachineBasicBlock::iterator BBI = MBB.begin(), BBE = MBB.end();
834 BBI != BBE && BBI->isPHI(); ++BBI) {
835 for (unsigned i = 1, e = BBI->getNumOperands(); i != e; i += 2) {
836 Register Reg = BBI->getOperand(i).getReg();
837 MachineBasicBlock *PreMBB = BBI->getOperand(i + 1).getMBB();
838 // Is there a critical edge from PreMBB to MBB?
839 if (PreMBB->succ_size() == 1)
840 continue;
841
842 // Avoid splitting backedges of loops. It would introduce small
843 // out-of-line blocks into the loop which is very bad for code placement.
844 if (PreMBB == &MBB && !SplitAllCriticalEdges)
845 continue;
846 const MachineLoop *PreLoop = MLI ? MLI->getLoopFor(PreMBB) : nullptr;
847 if (IsLoopHeader && PreLoop == CurLoop && !SplitAllCriticalEdges)
848 continue;
849
850 // LV doesn't consider a phi use live-out, so isLiveOut only returns true
851 // when the source register is live-out for some other reason than a phi
852 // use. That means the copy we will insert in PreMBB won't be a kill, and
853 // there is a risk it may not be coalesced away.
854 //
855 // If the copy would be a kill, there is no need to split the edge.
856 bool ShouldSplit = isLiveOutPastPHIs(Reg, PreMBB);
857 if (!ShouldSplit && !NoPhiElimLiveOutEarlyExit)
858 continue;
859 if (ShouldSplit) {
860 LLVM_DEBUG(dbgs() << printReg(Reg) << " live-out before critical edge "
861 << printMBBReference(*PreMBB) << " -> "
862 << printMBBReference(MBB) << ": " << *BBI);
863 }
864
865 // If Reg is not live-in to MBB, it means it must be live-in to some
866 // other PreMBB successor, and we can avoid the interference by splitting
867 // the edge.
868 //
869 // If Reg *is* live-in to MBB, the interference is inevitable and a copy
870 // is likely to be left after coalescing. If we are looking at a loop
871 // exiting edge, split it so we won't insert code in the loop, otherwise
872 // don't bother.
873 ShouldSplit = ShouldSplit && !isLiveIn(Reg, &MBB);
874
875 // Check for a loop exiting edge.
876 if (!ShouldSplit && CurLoop != PreLoop) {
877 LLVM_DEBUG({
878 dbgs() << "Split wouldn't help, maybe avoid loop copies?\n";
879 if (PreLoop)
880 dbgs() << "PreLoop: " << *PreLoop;
881 if (CurLoop)
882 dbgs() << "CurLoop: " << *CurLoop;
883 });
884 // This edge could be entering a loop, exiting a loop, or it could be
885 // both: Jumping directly form one loop to the header of a sibling
886 // loop.
887 // Split unless this edge is entering CurLoop from an outer loop.
888 ShouldSplit = PreLoop && !PreLoop->contains(CurLoop);
889 }
890 if (!ShouldSplit && !SplitAllCriticalEdges)
891 continue;
892 MachineBasicBlock *NewBB;
893 if (P)
894 NewBB = PreMBB->SplitCriticalEdge(&MBB, *P, LiveInSets, &MDTU);
895 else
896 NewBB = PreMBB->SplitCriticalEdge(&MBB, *MFAM, LiveInSets, &MDTU);
897 if (!NewBB) {
898 LLVM_DEBUG(dbgs() << "Failed to split critical edge.\n");
899 continue;
900 }
901
902 // Patch up MBFI after split if it is available.
903 if (MBFI) {
904 assert(MBPI);
905 MBFI->onEdgeSplit(*PreMBB, *NewBB, *MBPI);
906 }
907
908 Changed = true;
909 ++NumCriticalEdgesSplit;
910 }
911 }
912 return Changed;
913}
914
915bool PHIEliminationImpl::isLiveIn(Register Reg, const MachineBasicBlock *MBB) {
916 assert((LV || LIS) &&
917 "isLiveIn() requires either LiveVariables or LiveIntervals");
918 if (LIS)
919 return LIS->isLiveInToMBB(LIS->getInterval(Reg), MBB);
920 else
921 return LV->isLiveIn(Reg, *MBB);
922}
923
924bool PHIEliminationImpl::isLiveOutPastPHIs(Register Reg,
925 const MachineBasicBlock *MBB) {
926 assert((LV || LIS) &&
927 "isLiveOutPastPHIs() requires either LiveVariables or LiveIntervals");
928 // LiveVariables considers uses in PHIs to be in the predecessor basic block,
929 // so that a register used only in a PHI is not live out of the block. In
930 // contrast, LiveIntervals considers uses in PHIs to be on the edge rather
931 // than in the predecessor basic block, so that a register used only in a PHI
932 // is live out of the block.
933 if (LIS) {
934 const LiveInterval &LI = LIS->getInterval(Reg);
935 for (const MachineBasicBlock *SI : MBB->successors())
936 if (LI.liveAt(LIS->getMBBStartIdx(SI)))
937 return true;
938 return false;
939 } else {
940 return LV->isLiveOut(Reg, *MBB);
941 }
942}
MachineInstrBuilder MachineInstrBuilder & DefMI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock & MBB
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file defines the DenseMap class.
#define DEBUG_TYPE
const HexagonInstrInfo * TII
IRTranslator LLVM IR MI
#define I(x, y, z)
Definition MD5.cpp:57
Register Reg
#define P(N)
static bool allPhiOperandsUndefined(const MachineInstr &MPhi, const MachineRegisterInfo &MRI)
Return true if all sources of the phi node are implicit_def's, or undef's.
static cl::opt< bool > NoPhiElimLiveOutEarlyExit("no-phi-elim-live-out-early-exit", cl::init(false), cl::Hidden, cl::desc("Do not use an early exit if isLiveOutPastPHIs returns true."))
static bool isImplicitlyDefined(Register VirtReg, const MachineRegisterInfo &MRI)
Return true if all defs of VirtReg are implicit-defs.
static cl::opt< bool > DisableEdgeSplitting("disable-phi-elim-edge-splitting", cl::init(false), cl::Hidden, cl::desc("Disable critical edge splitting " "during PHI elimination"))
static cl::opt< bool > SplitAllCriticalEdges("phi-elim-split-all-critical-edges", cl::init(false), cl::Hidden, cl::desc("Split all critical edges during " "PHI elimination"))
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition PassSupport.h:42
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition PassSupport.h:44
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
Definition PassSupport.h:39
static bool isLiveOut(const MachineBasicBlock &MBB, unsigned Reg)
bool isDead(const MachineInstr &MI, const MachineRegisterInfo &MRI)
This file defines the SmallPtrSet class.
This file defines the SmallSet class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Definition Statistic.h:171
#define LLVM_DEBUG(...)
Definition Debug.h:119
Represent the analysis usage information of a pass.
A live range for subregisters.
LiveInterval - This class represents the liveness of a register, or stack slot.
bool hasSubRanges() const
Returns true if subregister liveness information is available.
iterator_range< subrange_iterator > subranges()
SlotIndex getMBBStartIdx(const MachineBasicBlock *mbb) const
Return the first index in the given basic block.
LiveInterval & getOrCreateEmptyInterval(Register Reg)
Return an existing interval for Reg.
SlotIndex getInstructionIndex(const MachineInstr &Instr) const
Returns the base index of the given instruction.
VNInfo::Allocator & getVNInfoAllocator()
SlotIndex getMBBEndIdx(const MachineBasicBlock *mbb) const
Return the last index in the given basic block.
LiveInterval & getInterval(Register Reg)
LLVM_ABI LiveInterval::Segment addSegmentToEndOfBlock(Register Reg, MachineInstr &startInst)
Given a register and an instruction, adds a live segment from that instruction to the end of its MBB.
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.
bool isLiveInToMBB(const LiveRange &LR, const MachineBasicBlock *mbb) const
LLVM_ABI iterator addSegment(Segment S)
Add the specified Segment to this range, merging segments as appropriate.
bool liveAt(SlotIndex index) const
bool empty() const
SlotIndex endIndex() const
endNumber - return the maximum point of the range of the whole, exclusive.
VNInfo * getNextValue(SlotIndex Def, VNInfo::Allocator &VNInfoAllocator)
getNextValue - Create a new value number and return it.
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.
bool removeVirtualRegisterDead(Register Reg, MachineInstr &MI)
removeVirtualRegisterDead - Remove the specified kill of the virtual register from the live variable ...
bool removeVirtualRegisterKilled(Register Reg, MachineInstr &MI)
removeVirtualRegisterKilled - Remove the specified kill of the virtual register from the live variabl...
LLVM_ABI void removeVirtualRegistersKilled(MachineInstr &MI)
removeVirtualRegistersKilled - Remove all killed info for the specified instruction.
void addVirtualRegisterDead(Register IncomingReg, MachineInstr &MI, bool AddIfNotFound=false)
addVirtualRegisterDead - Add information about the fact that the specified register is dead after bei...
LLVM_ABI bool isLiveOut(Register Reg, const MachineBasicBlock &MBB)
isLiveOut - Determine if Reg is live out from MBB, when not considering PHI nodes.
bool isLiveIn(Register Reg, const MachineBasicBlock &MBB)
LLVM_ABI void recomputeForSingleDefVirtReg(Register Reg)
Recompute liveness from scratch for a virtual register Reg that is known to have a single def that do...
void addVirtualRegisterKilled(Register IncomingReg, MachineInstr &MI, bool AddIfNotFound=false)
addVirtualRegisterKilled - Add information about the fact that the specified register is killed after...
LLVM_ABI VarInfo & getVarInfo(Register Reg)
getVarInfo - Return the VarInfo structure for the specified VIRTUAL register.
bool contains(const LoopT *L) const
Return true if the specified loop is contained within this loop.
BlockT * getHeader() const
LoopT * getLoopFor(const BlockT *BB) const
Return the inner most loop that BB lives in.
const MachineBlockFrequencyInfo & getMBFI() const
Definition MBFIWrapper.h:37
bool isEHPad() const
Returns true if the block is a landing pad.
MachineBasicBlock * SplitCriticalEdge(MachineBasicBlock *Succ, Pass &P, std::vector< SparseBitVector<> > *LiveInSets=nullptr, MachineDomTreeUpdater *MDTU=nullptr)
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
LLVM_ABI iterator SkipPHIsAndLabels(iterator I)
Return the first instruction in MBB after I that is not a PHI or a label.
MachineInstr * remove(MachineInstr *I)
Remove the unbundled instruction from the instruction list without deleting it.
LLVM_ABI void dump() const
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
iterator_range< succ_iterator > successors()
iterator_range< pred_iterator > predecessors()
MachineInstrBundleIterator< MachineInstr > iterator
MachineBlockFrequencyInfo pass uses BlockFrequencyInfoImpl implementation to estimate machine basic b...
LLVM_ABI void onEdgeSplit(const MachineBasicBlock &NewPredecessor, const MachineBasicBlock &NewSuccessor, const MachineBranchProbabilityInfo &MBPI)
incrementally calculate block frequencies when we split edges, to avoid full CFG traversal.
Analysis pass which computes a MachineDominatorTree.
Analysis pass which computes a MachineDominatorTree.
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
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.
Location of a PHI instruction that is also a debug-info variable value, for the duration of register ...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
DenseMap< unsigned, DebugPHIRegallocPos > DebugPHIPositions
Map of debug instruction numbers to the position of their PHI instructions during register allocation...
Representation of each machine instruction.
bool isImplicitDef() const
const MachineBasicBlock * getParent() const
unsigned getNumOperands() const
Retuns the total number of operands.
unsigned peekDebugInstrNum() const
Examine the instruction number of this MachineInstr.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
const MachineOperand & getOperand(unsigned i) const
LLVM_ABI MachineInstrBundleIterator< MachineInstr > eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
Analysis pass that exposes the MachineLoopInfo for a machine function.
MachineOperand class - Representation of each machine instruction operand.
unsigned getSubReg() const
bool isReg() const
isReg - Tests if this is a MO_Register operand.
MachineBasicBlock * getMBB() const
void setIsDead(bool Val=true)
LLVM_ABI void setReg(Register Reg)
Change the register this operand corresponds to.
Register getReg() const
getReg - Returns the register number.
MachinePostDominatorTree - an analysis pass wrapper for DominatorTree used to compute the post-domina...
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.
LLVM_ABI LLVM_READONLY MachineInstr * getVRegDef(Register Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
iterator_range< def_instr_iterator > def_instructions(Register Reg) const
bool use_nodbg_empty(Register RegNo) const
use_nodbg_empty - Return true if there are no non-Debug instructions using the specified register.
LLVM_ABI Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
unsigned getNumVirtRegs() const
getNumVirtRegs - Return the number of virtual registers created.
bool use_empty(Register RegNo) const
use_empty - Return true if there are no instructions using the specified register.
LLVM_ABI PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
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
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
Definition Register.h:79
SlotIndex - An opaque wrapper around machine indexes.
Definition SlotIndexes.h:66
bool isValid() const
Returns true if this is a valid index.
SlotIndex getRegSlot(bool EC=false) const
Returns the register use/def slot in the current instruction for a normal or early-clobber def.
bool isDead() const
isDead - Returns true if this is a dead def kill slot.
SlotIndexes pass.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
Definition SmallSet.h:134
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
void reset(unsigned Idx)
SparseBitVectorIterator iterator
TargetInstrInfo - Interface to description of machine instruction set.
virtual const TargetInstrInfo * getInstrInfo() const
VNInfo - Value Number Information.
SlotIndex def
The index of the defining instruction.
Changed
@ Entry
Definition COFF.h:862
initializer< Ty > init(const Ty &Val)
PointerTypeMap run(const Module &M)
Compute the PointerTypeMap for the module M.
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.
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
MachineBasicBlock::iterator findPHICopyInsertPoint(MachineBasicBlock *MBB, MachineBasicBlock *SuccMBB, Register SrcReg)
findPHICopyInsertPoint - Find a safe place in MBB to insert a copy from SrcReg when following the CFG...
LLVM_ABI unsigned SplitAllCriticalEdges(Function &F, const CriticalEdgeSplittingOptions &Options=CriticalEdgeSplittingOptions())
Loop over all of the edges in the CFG, breaking critical edges as they are found.
LLVM_ABI char & PHIEliminationID
PHIElimination - This pass eliminates machine instruction PHI nodes by inserting copy instructions.
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.
LLVM_ABI Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
MCRegisterClass TargetRegisterClass
Definition FastISel.h:58
This represents a simple continuous liveness interval for a value.
VarInfo - This represents the regions where a virtual register is live in the program.
SparseBitVector AliveBlocks
AliveBlocks - Set of blocks in which this value is alive completely through.