[llvm] [NFC][Cloning] Simplify the flow in FindDebugInfoToIdentityMap (PR #129144)

Artem Pianykh via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 9 08:49:17 PDT 2025


https://github.com/artempyanykh updated https://github.com/llvm/llvm-project/pull/129144

>From 36480c7bb8d3d8583a9ef9fd1975d51c8064f398 Mon Sep 17 00:00:00 2001
From: Artem Pianykh <arr at fb.com>
Date: Tue, 25 Feb 2025 10:29:56 -0800
Subject: [PATCH] [NFC][Cloning] Simplify the flow in
 FindDebugInfoToIdentityMap

Summary:
The new flow should make it more clear what is happening in cases of
Different of Cloned modules.

Test Plan:
ninja check-llvm-unit check-llvm

stack-info: PR: https://github.com/llvm/llvm-project/pull/129144, branch: users/artempyanykh/fast-coro-upstream-part2-take2/2
---
 llvm/lib/Transforms/Utils/CloneFunction.cpp | 34 ++++++++++-----------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/llvm/lib/Transforms/Utils/CloneFunction.cpp b/llvm/lib/Transforms/Utils/CloneFunction.cpp
index 9267930027c04..7a309f7390c77 100644
--- a/llvm/lib/Transforms/Utils/CloneFunction.cpp
+++ b/llvm/lib/Transforms/Utils/CloneFunction.cpp
@@ -160,32 +160,32 @@ MetadataSetTy
 llvm::FindDebugInfoToIdentityMap(CloneFunctionChangeType Changes,
                                  DebugInfoFinder &DIFinder,
                                  DISubprogram *SPClonedWithinModule) {
+  if (Changes >= CloneFunctionChangeType::DifferentModule)
+    return {};
+
+  if (DIFinder.subprogram_count() == 0)
+    assert(!SPClonedWithinModule &&
+           "Subprogram should be in DIFinder->subprogram_count()...");
+
   MetadataSetTy MD;
 
-  if (Changes < CloneFunctionChangeType::DifferentModule &&
-      DIFinder.subprogram_count() > 0) {
-    // Avoid cloning types, compile units, and (other) subprograms.
-    for (DISubprogram *ISP : DIFinder.subprograms()) {
-      if (ISP != SPClonedWithinModule)
-        MD.insert(ISP);
-    }
+  // Avoid cloning types, compile units, and (other) subprograms.
+  for (DISubprogram *ISP : DIFinder.subprograms())
+    if (ISP != SPClonedWithinModule)
+      MD.insert(ISP);
 
-    // If a subprogram isn't going to be cloned skip its lexical blocks as well.
-    for (DIScope *S : DIFinder.scopes()) {
-      auto *LScope = dyn_cast<DILocalScope>(S);
-      if (LScope && LScope->getSubprogram() != SPClonedWithinModule)
-        MD.insert(S);
-    }
+  // If a subprogram isn't going to be cloned skip its lexical blocks as well.
+  for (DIScope *S : DIFinder.scopes()) {
+    auto *LScope = dyn_cast<DILocalScope>(S);
+    if (LScope && LScope->getSubprogram() != SPClonedWithinModule)
+      MD.insert(S);
+  }
 
     for (DICompileUnit *CU : DIFinder.compile_units())
       MD.insert(CU);
 
     for (DIType *Type : DIFinder.types())
       MD.insert(Type);
-  } else {
-    assert(!SPClonedWithinModule &&
-           "Subprogram should be in DIFinder->subprogram_count()...");
-  }
 
   return MD;
 }



More information about the llvm-commits mailing list