xref: /llvm-project/llvm/lib/CodeGen/MachineCopyPropagation.cpp (revision db02d3d4b38e513593dbe562f94ecb6fad345314)
1 //===- MachineCopyPropagation.cpp - Machine Copy Propagation Pass ---------===//
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 is an extremely simple MachineInstr-level copy propagation pass.
11 //
12 // This pass forwards the source of COPYs to the users of their destinations
13 // when doing so is legal.  For example:
14 //
15 //   %reg1 = COPY %reg0
16 //   ...
17 //   ... = OP %reg1
18 //
19 // If
20 //   - %reg0 has not been clobbered by the time of the use of %reg1
21 //   - the register class constraints are satisfied
22 //   - the COPY def is the only value that reaches OP
23 // then this pass replaces the above with:
24 //
25 //   %reg1 = COPY %reg0
26 //   ...
27 //   ... = OP %reg0
28 //
29 // This pass also removes some redundant COPYs.  For example:
30 //
31 //    %R1 = COPY %R0
32 //    ... // No clobber of %R1
33 //    %R0 = COPY %R1 <<< Removed
34 //
35 // or
36 //
37 //    %R1 = COPY %R0
38 //    ... // No clobber of %R0
39 //    %R1 = COPY %R0 <<< Removed
40 //
41 //===----------------------------------------------------------------------===//
42 
43 #include "llvm/ADT/DenseMap.h"
44 #include "llvm/ADT/STLExtras.h"
45 #include "llvm/ADT/SetVector.h"
46 #include "llvm/ADT/SmallVector.h"
47 #include "llvm/ADT/Statistic.h"
48 #include "llvm/ADT/iterator_range.h"
49 #include "llvm/CodeGen/MachineBasicBlock.h"
50 #include "llvm/CodeGen/MachineFunction.h"
51 #include "llvm/CodeGen/MachineFunctionPass.h"
52 #include "llvm/CodeGen/MachineInstr.h"
53 #include "llvm/CodeGen/MachineOperand.h"
54 #include "llvm/CodeGen/MachineRegisterInfo.h"
55 #include "llvm/CodeGen/TargetInstrInfo.h"
56 #include "llvm/CodeGen/TargetRegisterInfo.h"
57 #include "llvm/CodeGen/TargetSubtargetInfo.h"
58 #include "llvm/MC/MCRegisterInfo.h"
59 #include "llvm/Pass.h"
60 #include "llvm/Support/Debug.h"
61 #include "llvm/Support/DebugCounter.h"
62 #include "llvm/Support/raw_ostream.h"
63 #include <cassert>
64 #include <iterator>
65 
66 using namespace llvm;
67 
68 #define DEBUG_TYPE "machine-cp"
69 
70 STATISTIC(NumDeletes, "Number of dead copies deleted");
71 STATISTIC(NumCopyForwards, "Number of copy uses forwarded");
72 DEBUG_COUNTER(FwdCounter, "machine-cp-fwd",
73               "Controls which register COPYs are forwarded");
74 
75 namespace {
76 
77 class CopyTracker {
78   using RegList = SmallVector<unsigned, 4>;
79   using SourceMap = DenseMap<unsigned, RegList>;
80   using Reg2MIMap = DenseMap<unsigned, MachineInstr *>;
81 
82   /// Def -> available copies map.
83   Reg2MIMap AvailCopyMap;
84 
85   /// Def -> copies map.
86   Reg2MIMap CopyMap;
87 
88   /// Src -> Def map
89   SourceMap SrcMap;
90 
91 public:
92   /// Mark all of the given registers and their subregisters as unavailable for
93   /// copying.
94   void markRegsUnavailable(const RegList &Regs, const TargetRegisterInfo &TRI) {
95     for (unsigned Reg : Regs) {
96       // Source of copy is no longer available for propagation.
97       for (MCSubRegIterator SR(Reg, &TRI, true); SR.isValid(); ++SR)
98         AvailCopyMap.erase(*SR);
99     }
100   }
101 
102   /// Clobber a single register, removing it from the tracker's copy maps.
103   void clobberRegister(unsigned Reg, const TargetRegisterInfo &TRI) {
104     for (MCRegAliasIterator AI(Reg, &TRI, true); AI.isValid(); ++AI) {
105       CopyMap.erase(*AI);
106       AvailCopyMap.erase(*AI);
107 
108       SourceMap::iterator SI = SrcMap.find(*AI);
109       if (SI != SrcMap.end()) {
110         markRegsUnavailable(SI->second, TRI);
111         SrcMap.erase(SI);
112       }
113     }
114   }
115 
116   /// Add this copy's registers into the tracker's copy maps.
117   void trackCopy(MachineInstr *Copy, const TargetRegisterInfo &TRI) {
118     assert(Copy->isCopy() && "Tracking non-copy?");
119 
120     unsigned Def = Copy->getOperand(0).getReg();
121     unsigned Src = Copy->getOperand(1).getReg();
122 
123     // Remember Def is defined by the copy.
124     for (MCSubRegIterator SR(Def, &TRI, /*IncludeSelf=*/true); SR.isValid();
125          ++SR) {
126       CopyMap[*SR] = Copy;
127       AvailCopyMap[*SR] = Copy;
128     }
129 
130     // Remember source that's copied to Def. Once it's clobbered, then
131     // it's no longer available for copy propagation.
132     RegList &DestList = SrcMap[Src];
133     if (!is_contained(DestList, Def))
134       DestList.push_back(Def);
135   }
136 
137   bool hasAvailableCopies() { return !AvailCopyMap.empty(); }
138 
139   MachineInstr *findAvailCopy(MachineInstr &DestCopy, unsigned Reg) {
140     auto CI = AvailCopyMap.find(Reg);
141     if (CI == AvailCopyMap.end())
142       return nullptr;
143     MachineInstr &AvailCopy = *CI->second;
144 
145     // Check that the available copy isn't clobbered by any regmasks between
146     // itself and the destination.
147     unsigned AvailSrc = AvailCopy.getOperand(1).getReg();
148     unsigned AvailDef = AvailCopy.getOperand(0).getReg();
149     for (const MachineInstr &MI :
150          make_range(AvailCopy.getIterator(), DestCopy.getIterator()))
151       for (const MachineOperand &MO : MI.operands())
152         if (MO.isRegMask())
153           if (MO.clobbersPhysReg(AvailSrc) || MO.clobbersPhysReg(AvailDef))
154             return nullptr;
155 
156     return &AvailCopy;
157   }
158 
159   MachineInstr *findCopy(unsigned Reg) {
160     auto CI = CopyMap.find(Reg);
161     if (CI != CopyMap.end())
162       return CI->second;
163     return nullptr;
164   }
165 
166   void clear() {
167     AvailCopyMap.clear();
168     CopyMap.clear();
169     SrcMap.clear();
170   }
171 };
172 
173 class MachineCopyPropagation : public MachineFunctionPass {
174   const TargetRegisterInfo *TRI;
175   const TargetInstrInfo *TII;
176   const MachineRegisterInfo *MRI;
177 
178 public:
179   static char ID; // Pass identification, replacement for typeid
180 
181   MachineCopyPropagation() : MachineFunctionPass(ID) {
182     initializeMachineCopyPropagationPass(*PassRegistry::getPassRegistry());
183   }
184 
185   void getAnalysisUsage(AnalysisUsage &AU) const override {
186     AU.setPreservesCFG();
187     MachineFunctionPass::getAnalysisUsage(AU);
188   }
189 
190   bool runOnMachineFunction(MachineFunction &MF) override;
191 
192   MachineFunctionProperties getRequiredProperties() const override {
193     return MachineFunctionProperties().set(
194         MachineFunctionProperties::Property::NoVRegs);
195   }
196 
197 private:
198   void ClobberRegister(unsigned Reg);
199   void ReadRegister(unsigned Reg);
200   void CopyPropagateBlock(MachineBasicBlock &MBB);
201   bool eraseIfRedundant(MachineInstr &Copy, unsigned Src, unsigned Def);
202   void forwardUses(MachineInstr &MI);
203   bool isForwardableRegClassCopy(const MachineInstr &Copy,
204                                  const MachineInstr &UseI, unsigned UseIdx);
205   bool hasImplicitOverlap(const MachineInstr &MI, const MachineOperand &Use);
206 
207   /// Candidates for deletion.
208   SmallSetVector<MachineInstr *, 8> MaybeDeadCopies;
209 
210   CopyTracker Tracker;
211 
212   bool Changed;
213 };
214 
215 } // end anonymous namespace
216 
217 char MachineCopyPropagation::ID = 0;
218 
219 char &llvm::MachineCopyPropagationID = MachineCopyPropagation::ID;
220 
221 INITIALIZE_PASS(MachineCopyPropagation, DEBUG_TYPE,
222                 "Machine Copy Propagation Pass", false, false)
223 
224 void MachineCopyPropagation::ReadRegister(unsigned Reg) {
225   // If 'Reg' is defined by a copy, the copy is no longer a candidate
226   // for elimination.
227   for (MCRegAliasIterator AI(Reg, TRI, true); AI.isValid(); ++AI) {
228     if (MachineInstr *Copy = Tracker.findCopy(*AI)) {
229       LLVM_DEBUG(dbgs() << "MCP: Copy is used - not dead: "; Copy->dump());
230       MaybeDeadCopies.remove(Copy);
231     }
232   }
233 }
234 
235 /// Return true if \p PreviousCopy did copy register \p Src to register \p Def.
236 /// This fact may have been obscured by sub register usage or may not be true at
237 /// all even though Src and Def are subregisters of the registers used in
238 /// PreviousCopy. e.g.
239 /// isNopCopy("ecx = COPY eax", AX, CX) == true
240 /// isNopCopy("ecx = COPY eax", AH, CL) == false
241 static bool isNopCopy(const MachineInstr &PreviousCopy, unsigned Src,
242                       unsigned Def, const TargetRegisterInfo *TRI) {
243   unsigned PreviousSrc = PreviousCopy.getOperand(1).getReg();
244   unsigned PreviousDef = PreviousCopy.getOperand(0).getReg();
245   if (Src == PreviousSrc) {
246     assert(Def == PreviousDef);
247     return true;
248   }
249   if (!TRI->isSubRegister(PreviousSrc, Src))
250     return false;
251   unsigned SubIdx = TRI->getSubRegIndex(PreviousSrc, Src);
252   return SubIdx == TRI->getSubRegIndex(PreviousDef, Def);
253 }
254 
255 /// Remove instruction \p Copy if there exists a previous copy that copies the
256 /// register \p Src to the register \p Def; This may happen indirectly by
257 /// copying the super registers.
258 bool MachineCopyPropagation::eraseIfRedundant(MachineInstr &Copy, unsigned Src,
259                                               unsigned Def) {
260   // Avoid eliminating a copy from/to a reserved registers as we cannot predict
261   // the value (Example: The sparc zero register is writable but stays zero).
262   if (MRI->isReserved(Src) || MRI->isReserved(Def))
263     return false;
264 
265   // Search for an existing copy.
266   MachineInstr *PrevCopy = Tracker.findAvailCopy(Copy, Def);
267   if (!PrevCopy)
268     return false;
269 
270   // Check that the existing copy uses the correct sub registers.
271   if (PrevCopy->getOperand(0).isDead())
272     return false;
273   if (!isNopCopy(*PrevCopy, Src, Def, TRI))
274     return false;
275 
276   LLVM_DEBUG(dbgs() << "MCP: copy is a NOP, removing: "; Copy.dump());
277 
278   // Copy was redundantly redefining either Src or Def. Remove earlier kill
279   // flags between Copy and PrevCopy because the value will be reused now.
280   assert(Copy.isCopy());
281   unsigned CopyDef = Copy.getOperand(0).getReg();
282   assert(CopyDef == Src || CopyDef == Def);
283   for (MachineInstr &MI :
284        make_range(PrevCopy->getIterator(), Copy.getIterator()))
285     MI.clearRegisterKills(CopyDef, TRI);
286 
287   Copy.eraseFromParent();
288   Changed = true;
289   ++NumDeletes;
290   return true;
291 }
292 
293 /// Decide whether we should forward the source of \param Copy to its use in
294 /// \param UseI based on the physical register class constraints of the opcode
295 /// and avoiding introducing more cross-class COPYs.
296 bool MachineCopyPropagation::isForwardableRegClassCopy(const MachineInstr &Copy,
297                                                        const MachineInstr &UseI,
298                                                        unsigned UseIdx) {
299 
300   unsigned CopySrcReg = Copy.getOperand(1).getReg();
301 
302   // If the new register meets the opcode register constraints, then allow
303   // forwarding.
304   if (const TargetRegisterClass *URC =
305           UseI.getRegClassConstraint(UseIdx, TII, TRI))
306     return URC->contains(CopySrcReg);
307 
308   if (!UseI.isCopy())
309     return false;
310 
311   /// COPYs don't have register class constraints, so if the user instruction
312   /// is a COPY, we just try to avoid introducing additional cross-class
313   /// COPYs.  For example:
314   ///
315   ///   RegClassA = COPY RegClassB  // Copy parameter
316   ///   ...
317   ///   RegClassB = COPY RegClassA  // UseI parameter
318   ///
319   /// which after forwarding becomes
320   ///
321   ///   RegClassA = COPY RegClassB
322   ///   ...
323   ///   RegClassB = COPY RegClassB
324   ///
325   /// so we have reduced the number of cross-class COPYs and potentially
326   /// introduced a nop COPY that can be removed.
327   const TargetRegisterClass *UseDstRC =
328       TRI->getMinimalPhysRegClass(UseI.getOperand(0).getReg());
329 
330   const TargetRegisterClass *SuperRC = UseDstRC;
331   for (TargetRegisterClass::sc_iterator SuperRCI = UseDstRC->getSuperClasses();
332        SuperRC; SuperRC = *SuperRCI++)
333     if (SuperRC->contains(CopySrcReg))
334       return true;
335 
336   return false;
337 }
338 
339 /// Check that \p MI does not have implicit uses that overlap with it's \p Use
340 /// operand (the register being replaced), since these can sometimes be
341 /// implicitly tied to other operands.  For example, on AMDGPU:
342 ///
343 /// V_MOVRELS_B32_e32 %VGPR2, %M0<imp-use>, %EXEC<imp-use>, %VGPR2_VGPR3_VGPR4_VGPR5<imp-use>
344 ///
345 /// the %VGPR2 is implicitly tied to the larger reg operand, but we have no
346 /// way of knowing we need to update the latter when updating the former.
347 bool MachineCopyPropagation::hasImplicitOverlap(const MachineInstr &MI,
348                                                 const MachineOperand &Use) {
349   for (const MachineOperand &MIUse : MI.uses())
350     if (&MIUse != &Use && MIUse.isReg() && MIUse.isImplicit() &&
351         MIUse.isUse() && TRI->regsOverlap(Use.getReg(), MIUse.getReg()))
352       return true;
353 
354   return false;
355 }
356 
357 /// Look for available copies whose destination register is used by \p MI and
358 /// replace the use in \p MI with the copy's source register.
359 void MachineCopyPropagation::forwardUses(MachineInstr &MI) {
360   if (!Tracker.hasAvailableCopies())
361     return;
362 
363   // Look for non-tied explicit vreg uses that have an active COPY
364   // instruction that defines the physical register allocated to them.
365   // Replace the vreg with the source of the active COPY.
366   for (unsigned OpIdx = 0, OpEnd = MI.getNumOperands(); OpIdx < OpEnd;
367        ++OpIdx) {
368     MachineOperand &MOUse = MI.getOperand(OpIdx);
369     // Don't forward into undef use operands since doing so can cause problems
370     // with the machine verifier, since it doesn't treat undef reads as reads,
371     // so we can end up with a live range that ends on an undef read, leading to
372     // an error that the live range doesn't end on a read of the live range
373     // register.
374     if (!MOUse.isReg() || MOUse.isTied() || MOUse.isUndef() || MOUse.isDef() ||
375         MOUse.isImplicit())
376       continue;
377 
378     if (!MOUse.getReg())
379       continue;
380 
381     // Check that the register is marked 'renamable' so we know it is safe to
382     // rename it without violating any constraints that aren't expressed in the
383     // IR (e.g. ABI or opcode requirements).
384     if (!MOUse.isRenamable())
385       continue;
386 
387     MachineInstr *Copy = Tracker.findAvailCopy(MI, MOUse.getReg());
388     if (!Copy)
389       continue;
390 
391     unsigned CopyDstReg = Copy->getOperand(0).getReg();
392     const MachineOperand &CopySrc = Copy->getOperand(1);
393     unsigned CopySrcReg = CopySrc.getReg();
394 
395     // FIXME: Don't handle partial uses of wider COPYs yet.
396     if (MOUse.getReg() != CopyDstReg) {
397       LLVM_DEBUG(
398           dbgs() << "MCP: FIXME! Not forwarding COPY to sub-register use:\n  "
399                  << MI);
400       continue;
401     }
402 
403     // Don't forward COPYs of reserved regs unless they are constant.
404     if (MRI->isReserved(CopySrcReg) && !MRI->isConstantPhysReg(CopySrcReg))
405       continue;
406 
407     if (!isForwardableRegClassCopy(*Copy, MI, OpIdx))
408       continue;
409 
410     if (hasImplicitOverlap(MI, MOUse))
411       continue;
412 
413     if (!DebugCounter::shouldExecute(FwdCounter)) {
414       LLVM_DEBUG(dbgs() << "MCP: Skipping forwarding due to debug counter:\n  "
415                         << MI);
416       continue;
417     }
418 
419     LLVM_DEBUG(dbgs() << "MCP: Replacing " << printReg(MOUse.getReg(), TRI)
420                       << "\n     with " << printReg(CopySrcReg, TRI)
421                       << "\n     in " << MI << "     from " << *Copy);
422 
423     MOUse.setReg(CopySrcReg);
424     if (!CopySrc.isRenamable())
425       MOUse.setIsRenamable(false);
426 
427     LLVM_DEBUG(dbgs() << "MCP: After replacement: " << MI << "\n");
428 
429     // Clear kill markers that may have been invalidated.
430     for (MachineInstr &KMI :
431          make_range(Copy->getIterator(), std::next(MI.getIterator())))
432       KMI.clearRegisterKills(CopySrcReg, TRI);
433 
434     ++NumCopyForwards;
435     Changed = true;
436   }
437 }
438 
439 void MachineCopyPropagation::CopyPropagateBlock(MachineBasicBlock &MBB) {
440   LLVM_DEBUG(dbgs() << "MCP: CopyPropagateBlock " << MBB.getName() << "\n");
441 
442   for (MachineBasicBlock::iterator I = MBB.begin(), E = MBB.end(); I != E; ) {
443     MachineInstr *MI = &*I;
444     ++I;
445 
446     // Analyze copies (which don't overlap themselves).
447     if (MI->isCopy() && !TRI->regsOverlap(MI->getOperand(0).getReg(),
448                                           MI->getOperand(1).getReg())) {
449       unsigned Def = MI->getOperand(0).getReg();
450       unsigned Src = MI->getOperand(1).getReg();
451 
452       assert(!TargetRegisterInfo::isVirtualRegister(Def) &&
453              !TargetRegisterInfo::isVirtualRegister(Src) &&
454              "MachineCopyPropagation should be run after register allocation!");
455 
456       // The two copies cancel out and the source of the first copy
457       // hasn't been overridden, eliminate the second one. e.g.
458       //  %ecx = COPY %eax
459       //  ... nothing clobbered eax.
460       //  %eax = COPY %ecx
461       // =>
462       //  %ecx = COPY %eax
463       //
464       // or
465       //
466       //  %ecx = COPY %eax
467       //  ... nothing clobbered eax.
468       //  %ecx = COPY %eax
469       // =>
470       //  %ecx = COPY %eax
471       if (eraseIfRedundant(*MI, Def, Src) || eraseIfRedundant(*MI, Src, Def))
472         continue;
473 
474       forwardUses(*MI);
475 
476       // Src may have been changed by forwardUses()
477       Src = MI->getOperand(1).getReg();
478 
479       // If Src is defined by a previous copy, the previous copy cannot be
480       // eliminated.
481       ReadRegister(Src);
482       for (const MachineOperand &MO : MI->implicit_operands()) {
483         if (!MO.isReg() || !MO.readsReg())
484           continue;
485         unsigned Reg = MO.getReg();
486         if (!Reg)
487           continue;
488         ReadRegister(Reg);
489       }
490 
491       LLVM_DEBUG(dbgs() << "MCP: Copy is a deletion candidate: "; MI->dump());
492 
493       // Copy is now a candidate for deletion.
494       if (!MRI->isReserved(Def))
495         MaybeDeadCopies.insert(MI);
496 
497       // If 'Def' is previously source of another copy, then this earlier copy's
498       // source is no longer available. e.g.
499       // %xmm9 = copy %xmm2
500       // ...
501       // %xmm2 = copy %xmm0
502       // ...
503       // %xmm2 = copy %xmm9
504       Tracker.clobberRegister(Def, *TRI);
505       for (const MachineOperand &MO : MI->implicit_operands()) {
506         if (!MO.isReg() || !MO.isDef())
507           continue;
508         unsigned Reg = MO.getReg();
509         if (!Reg)
510           continue;
511         Tracker.clobberRegister(Reg, *TRI);
512       }
513 
514       Tracker.trackCopy(MI, *TRI);
515 
516       continue;
517     }
518 
519     // Clobber any earlyclobber regs first.
520     for (const MachineOperand &MO : MI->operands())
521       if (MO.isReg() && MO.isEarlyClobber()) {
522         unsigned Reg = MO.getReg();
523         // If we have a tied earlyclobber, that means it is also read by this
524         // instruction, so we need to make sure we don't remove it as dead
525         // later.
526         if (MO.isTied())
527           ReadRegister(Reg);
528         Tracker.clobberRegister(Reg, *TRI);
529       }
530 
531     forwardUses(*MI);
532 
533     // Not a copy.
534     SmallVector<unsigned, 2> Defs;
535     const MachineOperand *RegMask = nullptr;
536     for (const MachineOperand &MO : MI->operands()) {
537       if (MO.isRegMask())
538         RegMask = &MO;
539       if (!MO.isReg())
540         continue;
541       unsigned Reg = MO.getReg();
542       if (!Reg)
543         continue;
544 
545       assert(!TargetRegisterInfo::isVirtualRegister(Reg) &&
546              "MachineCopyPropagation should be run after register allocation!");
547 
548       if (MO.isDef() && !MO.isEarlyClobber()) {
549         Defs.push_back(Reg);
550         continue;
551       } else if (!MO.isDebug() && MO.readsReg())
552         ReadRegister(Reg);
553     }
554 
555     // The instruction has a register mask operand which means that it clobbers
556     // a large set of registers.  Treat clobbered registers the same way as
557     // defined registers.
558     if (RegMask) {
559       // Erase any MaybeDeadCopies whose destination register is clobbered.
560       for (SmallSetVector<MachineInstr *, 8>::iterator DI =
561                MaybeDeadCopies.begin();
562            DI != MaybeDeadCopies.end();) {
563         MachineInstr *MaybeDead = *DI;
564         unsigned Reg = MaybeDead->getOperand(0).getReg();
565         assert(!MRI->isReserved(Reg));
566 
567         if (!RegMask->clobbersPhysReg(Reg)) {
568           ++DI;
569           continue;
570         }
571 
572         LLVM_DEBUG(dbgs() << "MCP: Removing copy due to regmask clobbering: ";
573                    MaybeDead->dump());
574 
575         // Make sure we invalidate any entries in the copy maps before erasing
576         // the instruction.
577         Tracker.clobberRegister(Reg, *TRI);
578 
579         // erase() will return the next valid iterator pointing to the next
580         // element after the erased one.
581         DI = MaybeDeadCopies.erase(DI);
582         MaybeDead->eraseFromParent();
583         Changed = true;
584         ++NumDeletes;
585       }
586     }
587 
588     // Any previous copy definition or reading the Defs is no longer available.
589     for (unsigned Reg : Defs)
590       Tracker.clobberRegister(Reg, *TRI);
591   }
592 
593   // If MBB doesn't have successors, delete the copies whose defs are not used.
594   // If MBB does have successors, then conservative assume the defs are live-out
595   // since we don't want to trust live-in lists.
596   if (MBB.succ_empty()) {
597     for (MachineInstr *MaybeDead : MaybeDeadCopies) {
598       LLVM_DEBUG(dbgs() << "MCP: Removing copy due to no live-out succ: ";
599                  MaybeDead->dump());
600       assert(!MRI->isReserved(MaybeDead->getOperand(0).getReg()));
601       MaybeDead->eraseFromParent();
602       Changed = true;
603       ++NumDeletes;
604     }
605   }
606 
607   MaybeDeadCopies.clear();
608   Tracker.clear();
609 }
610 
611 bool MachineCopyPropagation::runOnMachineFunction(MachineFunction &MF) {
612   if (skipFunction(MF.getFunction()))
613     return false;
614 
615   Changed = false;
616 
617   TRI = MF.getSubtarget().getRegisterInfo();
618   TII = MF.getSubtarget().getInstrInfo();
619   MRI = &MF.getRegInfo();
620 
621   for (MachineBasicBlock &MBB : MF)
622     CopyPropagateBlock(MBB);
623 
624   return Changed;
625 }
626