[llvm] [MCP] Enhance MCP copy Instruction removal for special case (PR #70778)

via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 6 03:05:51 PST 2023


================
@@ -184,6 +184,58 @@ class CopyTracker {
     }
   }
 
+  /// Clobber \p Reg first, and then remove the corresponding COPY
+  /// record pair from the tracker's copy maps. We need to locate and remove
+  /// the COPY instruction that defines \p Reg, as well as the
+  /// record that make src defines \p Reg.
+  void eraseRegMIPair(MCRegister Reg, const TargetRegisterInfo &TRI,
+                      const TargetInstrInfo &TII, bool UseCopyInstr) {
+    for (MCRegUnit Unit : TRI.regunits(Reg)) {
+      auto I = Copies.find(Unit);
+
+      if (I != Copies.end()) {
+        // When we clobber the source of a copy, we need to clobber everything
+        // it defined.
+        markRegsUnavailable(I->second.DefRegs, TRI);
+        // When we clobber the destination of a copy, we need to clobber the
+        // whole register it defined.
+        if (MachineInstr *MI = I->second.MI) {
+          std::optional<DestSourcePair> CopyOperands =
+              isCopyInstr(*MI, TII, UseCopyInstr);
+
+          MCRegister Src = CopyOperands->Source->getReg().asMCReg();
+          MCRegister Def = CopyOperands->Destination->getReg().asMCReg();
+
+          markRegsUnavailable(Def, TRI);
+
+          // At this point, we need to locate the record in copy maps that use
+          // Src to define Def, and remove them from Tracker.
+          for (MCRegUnit SrcUnit : TRI.regunits(Src)) {
----------------
qcolombet wrote:

Would it make sense to always do that loop in `clobberRegister` instead of having two, very similar implementations?

https://github.com/llvm/llvm-project/pull/70778


More information about the llvm-commits mailing list