[PATCH] D92069: [NFC] [TargetRegisterInfo] add one use check to lookThruCopyLike.

ChenZheng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 24 19:44:30 PST 2020


shchenz created this revision.
shchenz added reviewers: eli.friedman, jsji, steven.zhang, nemanjai, qcolombet, PowerPC.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
shchenz requested review of this revision.

add one use check to `lookThruCopyLike`.

The root node is safe to be deleted if we are sure that every definition in the copy chain only has one use.

I will post another patch which uses this modified function later


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D92069

Files:
  llvm/include/llvm/CodeGen/TargetRegisterInfo.h
  llvm/lib/CodeGen/TargetRegisterInfo.cpp


Index: llvm/lib/CodeGen/TargetRegisterInfo.cpp
===================================================================
--- llvm/lib/CodeGen/TargetRegisterInfo.cpp
+++ llvm/lib/CodeGen/TargetRegisterInfo.cpp
@@ -511,11 +511,18 @@
 
 Register
 TargetRegisterInfo::lookThruCopyLike(Register SrcReg,
-                                     const MachineRegisterInfo *MRI) const {
+                                     const MachineRegisterInfo *MRI,
+                                     bool *AllDefHaveOneUser) const {
+  if (AllDefHaveOneUser)
+    *AllDefHaveOneUser = true;
+
   while (true) {
     const MachineInstr *MI = MRI->getVRegDef(SrcReg);
-    if (!MI->isCopyLike())
+    if (!MI->isCopyLike()) {
+      if (AllDefHaveOneUser && !MRI->hasOneNonDBGUse(SrcReg))
+        *AllDefHaveOneUser = false;
       return SrcReg;
+    }
 
     Register CopySrcReg;
     if (MI->isCopy())
@@ -525,8 +532,11 @@
       CopySrcReg = MI->getOperand(2).getReg();
     }
 
-    if (!CopySrcReg.isVirtual())
+    if (!CopySrcReg.isVirtual()) {
+      if (AllDefHaveOneUser)
+        *AllDefHaveOneUser = false;
       return CopySrcReg;
+    }
 
     SrcReg = CopySrcReg;
   }
Index: llvm/include/llvm/CodeGen/TargetRegisterInfo.h
===================================================================
--- llvm/include/llvm/CodeGen/TargetRegisterInfo.h
+++ llvm/include/llvm/CodeGen/TargetRegisterInfo.h
@@ -409,10 +409,13 @@
 
   /// Returns the original SrcReg unless it is the target of a copy-like
   /// operation, in which case we chain backwards through all such operations
-  /// to the ultimate source register.  If a physical register is encountered,
+  /// to the ultimate source register. If a physical register is encountered,
   /// we stop the search.
+  /// If one definition in the copy chain has multiple uses, set \p
+  /// AllDefHaveOneUser to false, otherwise set it to true.
   virtual Register lookThruCopyLike(Register SrcReg,
-                                    const MachineRegisterInfo *MRI) const;
+                                    const MachineRegisterInfo *MRI,
+                                    bool *AllDefHaveOneUser = nullptr) const;
 
   /// Return a null-terminated list of all of the callee-saved registers on
   /// this target. The register should be in the order of desired callee-save


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92069.307502.patch
Type: text/x-patch
Size: 2316 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201125/08ef19ee/attachment.bin>


More information about the llvm-commits mailing list