Skip to content

[NFC][Cloning] Make DifferentModule case more obvious in CollectDebugInfoForCloning #129146

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

Merged

Conversation

…InfoForCloning

Summary:
This should be behaviorally equivalent. DIFinder is only used when
cloning into a DifferentModule as part of llvm.dbg.cu update in
CloneFunctionInto.

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

stack-info: PR: #129146, branch: users/artempyanykh/fast-coro-upstream-part2-take2/4
@llvmbot
Copy link
Member

llvmbot commented Feb 27, 2025

@llvm/pr-subscribers-llvm-transforms

Author: Artem Pianykh (artempyanykh)

Changes

[NFC][Cloning] Make DifferentModule case more obvious in CollectDebugInfoForCloning

Summary:
This should be behaviorally equivalent. DIFinder is only used when
cloning into a DifferentModule as part of llvm.dbg.cu update in
CloneFunctionInto.

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


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

1 Files Affected:

  • (modified) llvm/lib/Transforms/Utils/CloneFunction.cpp (+8-2)
diff --git a/llvm/lib/Transforms/Utils/CloneFunction.cpp b/llvm/lib/Transforms/Utils/CloneFunction.cpp
index 9ea4e64671c7e..6b6315d698c9a 100644
--- a/llvm/lib/Transforms/Utils/CloneFunction.cpp
+++ b/llvm/lib/Transforms/Utils/CloneFunction.cpp
@@ -147,8 +147,10 @@ void llvm::CloneFunctionAttributesInto(Function *NewFunc,
 DISubprogram *llvm::CollectDebugInfoForCloning(const Function &F,
                                                CloneFunctionChangeType Changes,
                                                DebugInfoFinder &DIFinder) {
-  // CloneModule takes care of cloning debug info.
-  if (Changes == CloneFunctionChangeType::ClonedModule)
+  // CloneModule takes care of cloning debug info for ClonedModule. Cloning into
+  // DifferentModule is taken care of separately in ClonedFunctionInto as part
+  // of llvm.dbg.cu update.
+  if (Changes >= CloneFunctionChangeType::DifferentModule)
     return nullptr;
 
   DISubprogram *SPClonedWithinModule = nullptr;
@@ -362,6 +364,10 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
   SmallPtrSet<const void *, 8> Visited;
   for (auto *Operand : NMD->operands())
     Visited.insert(Operand);
+
+  // Collect and clone all the compile units referenced from the instructions in
+  // the function (e.g. as a scope).
+  collectDebugInfoFromInstructions(*OldFunc, DIFinder);
   for (auto *Unit : DIFinder.compile_units()) {
     MDNode *MappedUnit =
         MapMetadata(Unit, VMap, RF_None, TypeMapper, Materializer);

@artempyanykh artempyanykh force-pushed the users/artempyanykh/fast-coro-upstream-part2-take2/3 branch from 36b445a to dd91189 Compare February 27, 2025 23:35
@artempyanykh artempyanykh force-pushed the users/artempyanykh/fast-coro-upstream-part2-take2/4 branch from 90deeb1 to d02c645 Compare February 27, 2025 23:35
jollaitbot pushed a commit to sailfishos-mirror/llvm-project that referenced this pull request Feb 28, 2025
…InfoForCloning

Summary:
This should be behaviorally equivalent. DIFinder is only used when
cloning into a DifferentModule as part of llvm.dbg.cu update in
CloneFunctionInto.

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

stack-info: PR: llvm/llvm-project#129146, branch: users/artempyanykh/fast-coro-upstream-part2-take2/4
// CloneModule takes care of cloning debug info for ClonedModule. Cloning into
// DifferentModule is taken care of separately in ClonedFunctionInto as part
// of llvm.dbg.cu update.
if (Changes >= CloneFunctionChangeType::DifferentModule)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI the check in CloneFunctionInto is:

  if (Changes != CloneFunctionChangeType::DifferentModule)
    return;

Should we make it < instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@felipepiovezan sorry I didn't get that. Could you elaborate please?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that FindDebugInfoToIdentityMap and CollectDebugInfoForCloning get removed later in the stack, I'm going to go ahead and merge this. Please, let me know if I missed something important and I'll fix it on top.

@artempyanykh artempyanykh changed the base branch from users/artempyanykh/fast-coro-upstream-part2-take2/3 to main March 9, 2025 14:29
@artempyanykh artempyanykh force-pushed the users/artempyanykh/fast-coro-upstream-part2-take2/4 branch from d02c645 to 6e8df0d Compare March 9, 2025 14:30
@artempyanykh artempyanykh changed the base branch from main to users/artempyanykh/fast-coro-upstream-part2-take2/3 March 9, 2025 14:30
@artempyanykh artempyanykh changed the base branch from users/artempyanykh/fast-coro-upstream-part2-take2/3 to main March 9, 2025 14:32
@artempyanykh artempyanykh changed the base branch from main to users/artempyanykh/fast-coro-upstream-part2-take2/3 March 9, 2025 14:32
@artempyanykh artempyanykh force-pushed the users/artempyanykh/fast-coro-upstream-part2-take2/3 branch from 33b79c9 to 181b126 Compare March 9, 2025 15:49
artempyanykh added a commit that referenced this pull request Mar 9, 2025
…InfoForCloning

Summary:
This should be behaviorally equivalent. DIFinder is only used when
cloning into a DifferentModule as part of llvm.dbg.cu update in
CloneFunctionInto.

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

stack-info: PR: #129146, branch: users/artempyanykh/fast-coro-upstream-part2-take2/4
@artempyanykh artempyanykh force-pushed the users/artempyanykh/fast-coro-upstream-part2-take2/4 branch from 6e8df0d to 7344ea1 Compare March 9, 2025 15:49
@artempyanykh artempyanykh force-pushed the users/artempyanykh/fast-coro-upstream-part2-take2/3 branch from 181b126 to e370743 Compare March 9, 2025 17:49
artempyanykh added a commit that referenced this pull request Mar 9, 2025
…InfoForCloning

Summary:
This should be behaviorally equivalent. DIFinder is only used when
cloning into a DifferentModule as part of llvm.dbg.cu update in
CloneFunctionInto.

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

stack-info: PR: #129146, branch: users/artempyanykh/fast-coro-upstream-part2-take2/4
@artempyanykh artempyanykh force-pushed the users/artempyanykh/fast-coro-upstream-part2-take2/4 branch from 7344ea1 to 52f4ec3 Compare March 9, 2025 17:49
Base automatically changed from users/artempyanykh/fast-coro-upstream-part2-take2/3 to main March 9, 2025 18:35
@artempyanykh artempyanykh force-pushed the users/artempyanykh/fast-coro-upstream-part2-take2/4 branch from 52f4ec3 to 46dfb15 Compare March 9, 2025 18:35
@artempyanykh artempyanykh merged commit 30fa7a2 into main Mar 12, 2025
11 checks passed
@artempyanykh artempyanykh deleted the users/artempyanykh/fast-coro-upstream-part2-take2/4 branch March 12, 2025 11:19
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.

3 participants