Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NFC][Cloning] Simplify the flow in FindDebugInfoToIdentityMap #129144

Open
wants to merge 1 commit into
base: users/artempyanykh/fast-coro-upstream-part2-take2/1
Choose a base branch
from

Conversation

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: #129144, branch: users/artempyanykh/fast-coro-upstream-part2-take2/2
@llvmbot
Copy link
Member

llvmbot commented Feb 27, 2025

@llvm/pr-subscribers-llvm-transforms

Author: Artem Pianykh (artempyanykh)

Changes

[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


Full diff: https://github.com/llvm/llvm-project/pull/129144.diff

1 Files Affected:

  • (modified) llvm/lib/Transforms/Utils/CloneFunction.cpp (+16-16)
diff --git a/llvm/lib/Transforms/Utils/CloneFunction.cpp b/llvm/lib/Transforms/Utils/CloneFunction.cpp
index 9267930027c04..5a5b84c8e0a3c 100644
--- a/llvm/lib/Transforms/Utils/CloneFunction.cpp
+++ b/llvm/lib/Transforms/Utils/CloneFunction.cpp
@@ -160,21 +160,25 @@ 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())
@@ -182,10 +186,6 @@ llvm::FindDebugInfoToIdentityMap(CloneFunctionChangeType Changes,
 
     for (DIType *Type : DIFinder.types())
       MD.insert(Type);
-  } else {
-    assert(!SPClonedWithinModule &&
-           "Subprogram should be in DIFinder->subprogram_count()...");
-  }
 
   return MD;
 }

Copy link

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff 25c46523123edfc7f65f37a286fb3d2b7ac0c864 eefce0296241b86dfa6c6e177c6098dda6296bf3 --extensions cpp -- llvm/lib/Transforms/Utils/CloneFunction.cpp
View the diff from clang-format here.
diff --git a/llvm/lib/Transforms/Utils/CloneFunction.cpp b/llvm/lib/Transforms/Utils/CloneFunction.cpp
index 5a5b84c8e0..7a309f7390 100644
--- a/llvm/lib/Transforms/Utils/CloneFunction.cpp
+++ b/llvm/lib/Transforms/Utils/CloneFunction.cpp
@@ -179,7 +179,7 @@ llvm::FindDebugInfoToIdentityMap(CloneFunctionChangeType Changes,
     auto *LScope = dyn_cast<DILocalScope>(S);
     if (LScope && LScope->getSubprogram() != SPClonedWithinModule)
       MD.insert(S);
-    }
+  }
 
     for (DICompileUnit *CU : DIFinder.compile_units())
       MD.insert(CU);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants