-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[NFC][Cloning] Replace DIFinder usage in CloneFunctionInto with a MetadataPredicate #129148
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] Replace DIFinder usage in CloneFunctionInto with a MetadataPredicate #129148
Conversation
c24bd57
to
9675cd2
Compare
4cb677e
to
2773399
Compare
@llvm/pr-subscribers-debuginfo @llvm/pr-subscribers-llvm-transforms Author: Artem Pianykh (artempyanykh) ChangesStacked PRs:
[NFC][Cloning] Replace DIFinder usage in CloneFunctionInto with a MetadataPredicateSummary: In the old code when cloning within the module:
This looks equivalent to just doing step 3 with identity mapping based Test Plan: Full diff: https://github.com/llvm/llvm-project/pull/129148.diff 1 Files Affected:
diff --git a/llvm/lib/Transforms/Utils/CloneFunction.cpp b/llvm/lib/Transforms/Utils/CloneFunction.cpp
index 8e2a02d49d35c..17c14c09082b0 100644
--- a/llvm/lib/Transforms/Utils/CloneFunction.cpp
+++ b/llvm/lib/Transforms/Utils/CloneFunction.cpp
@@ -50,6 +50,30 @@ void collectDebugInfoFromInstructions(const Function &F,
DIFinder.processInstruction(*M, I);
}
}
+
+// Create a predicate that matches the metadata that should be identity mapped
+// during function cloning.
+MetadataPredicate createIdentityMDPredicate(const Function &F,
+ CloneFunctionChangeType Changes) {
+ if (Changes >= CloneFunctionChangeType::DifferentModule)
+ return [](const Metadata *MD) { return false; };
+
+ DISubprogram *SPClonedWithinModule = F.getSubprogram();
+ return [=](const Metadata *MD) {
+ // Avoid cloning types, compile units, and (other) subprograms.
+ if (isa<DICompileUnit>(MD) || isa<DIType>(MD))
+ return true;
+
+ if (auto *SP = dyn_cast<DISubprogram>(MD); SP)
+ return SP != SPClonedWithinModule;
+
+ // If a subprogram isn't going to be cloned skip its lexical blocks as well.
+ if (auto *LScope = dyn_cast<DILocalScope>(MD); LScope)
+ return LScope->getSubprogram() != SPClonedWithinModule;
+
+ return false;
+ };
+}
} // namespace
/// See comments in Cloning.h.
@@ -325,13 +349,7 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
}
}
- DISubprogram *SPClonedWithinModule =
- CollectDebugInfoForCloning(*OldFunc, Changes, DIFinder);
-
- MetadataPredicate IdentityMD =
- [MDSet =
- FindDebugInfoToIdentityMap(Changes, DIFinder, SPClonedWithinModule)](
- const Metadata *MD) { return MDSet.contains(MD); };
+ MetadataPredicate IdentityMD = createIdentityMDPredicate(*OldFunc, Changes);
// Cloning is always a Module level operation, since Metadata needs to be
// cloned.
|
…adataPredicate Summary: The new code should be functionally identical to the old one (but faster). The reasoning is as follows. In the old code when cloning within the module: 1. DIFinder traverses and collects *all* debug info reachable from a function, its instructions, and its owning compile unit. 2. Then "compile units, types, other subprograms, and lexical blocks of other subprograms" are saved in a set. 3. Then when we MapMetadata, we traverse the function's debug info _again_ and those nodes that are in the set from p.2 are identity mapped. This looks equivalent to just doing step 3 with identity mapping based on a predicate that says to identity map "compile units, types, other subprograms, and lexical blocks of other subprograms" (same as in step 2). This is what the new code does. Test Plan: ninja check-all There's a bunch of tests around cloning and all of them pass. stack-info: PR: llvm/llvm-project#129148, branch: users/artempyanykh/fast-coro-upstream-part2-take2/6
if (isa<DICompileUnit>(MD) || isa<DIType>(MD)) | ||
return true; | ||
|
||
if (auto *SP = dyn_cast<DISubprogram>(MD); SP) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: the ; SP
is redundant here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same with ; LScope
below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is pretty neat!
2773399
to
a73e948
Compare
b5f28bb
to
ca21a68
Compare
…adataPredicate Summary: The new code should be functionally identical to the old one (but faster). The reasoning is as follows. In the old code when cloning within the module: 1. DIFinder traverses and collects *all* debug info reachable from a function, its instructions, and its owning compile unit. 2. Then "compile units, types, other subprograms, and lexical blocks of other subprograms" are saved in a set. 3. Then when we MapMetadata, we traverse the function's debug info _again_ and those nodes that are in the set from p.2 are identity mapped. This looks equivalent to just doing step 3 with identity mapping based on a predicate that says to identity map "compile units, types, other subprograms, and lexical blocks of other subprograms" (same as in step 2). This is what the new code does. Test Plan: ninja check-all There's a bunch of tests around cloning and all of them pass. stack-info: PR: #129148, branch: users/artempyanykh/fast-coro-upstream-part2-take2/6
a73e948
to
0f7fb67
Compare
ca21a68
to
f847bc6
Compare
…adataPredicate Summary: The new code should be functionally identical to the old one (but faster). The reasoning is as follows. In the old code when cloning within the module: 1. DIFinder traverses and collects *all* debug info reachable from a function, its instructions, and its owning compile unit. 2. Then "compile units, types, other subprograms, and lexical blocks of other subprograms" are saved in a set. 3. Then when we MapMetadata, we traverse the function's debug info _again_ and those nodes that are in the set from p.2 are identity mapped. This looks equivalent to just doing step 3 with identity mapping based on a predicate that says to identity map "compile units, types, other subprograms, and lexical blocks of other subprograms" (same as in step 2). This is what the new code does. Test Plan: ninja check-all There's a bunch of tests around cloning and all of them pass. stack-info: PR: #129148, branch: users/artempyanykh/fast-coro-upstream-part2-take2/6
0f7fb67
to
66695d8
Compare
f847bc6
to
17728dd
Compare
…adataPredicate Summary: The new code should be functionally identical to the old one (but faster). The reasoning is as follows. In the old code when cloning within the module: 1. DIFinder traverses and collects *all* debug info reachable from a function, its instructions, and its owning compile unit. 2. Then "compile units, types, other subprograms, and lexical blocks of other subprograms" are saved in a set. 3. Then when we MapMetadata, we traverse the function's debug info _again_ and those nodes that are in the set from p.2 are identity mapped. This looks equivalent to just doing step 3 with identity mapping based on a predicate that says to identity map "compile units, types, other subprograms, and lexical blocks of other subprograms" (same as in step 2). This is what the new code does. Test Plan: ninja check-all There's a bunch of tests around cloning and all of them pass. stack-info: PR: #129148, branch: users/artempyanykh/fast-coro-upstream-part2-take2/6
66695d8
to
7801cdf
Compare
17728dd
to
34baefc
Compare
…adataPredicate Summary: The new code should be functionally identical to the old one (but faster). The reasoning is as follows. In the old code when cloning within the module: 1. DIFinder traverses and collects *all* debug info reachable from a function, its instructions, and its owning compile unit. 2. Then "compile units, types, other subprograms, and lexical blocks of other subprograms" are saved in a set. 3. Then when we MapMetadata, we traverse the function's debug info _again_ and those nodes that are in the set from p.2 are identity mapped. This looks equivalent to just doing step 3 with identity mapping based on a predicate that says to identity map "compile units, types, other subprograms, and lexical blocks of other subprograms" (same as in step 2). This is what the new code does. Test Plan: ninja check-all There's a bunch of tests around cloning and all of them pass. stack-info: PR: #129148, branch: users/artempyanykh/fast-coro-upstream-part2-take2/6
7801cdf
to
df8853d
Compare
…adataPredicate Summary: The new code should be functionally identical to the old one (but faster). The reasoning is as follows. In the old code when cloning within the module: 1. DIFinder traverses and collects *all* debug info reachable from a function, its instructions, and its owning compile unit. 2. Then "compile units, types, other subprograms, and lexical blocks of other subprograms" are saved in a set. 3. Then when we MapMetadata, we traverse the function's debug info _again_ and those nodes that are in the set from p.2 are identity mapped. This looks equivalent to just doing step 3 with identity mapping based on a predicate that says to identity map "compile units, types, other subprograms, and lexical blocks of other subprograms" (same as in step 2). This is what the new code does. Test Plan: ninja check-all There's a bunch of tests around cloning and all of them pass. stack-info: PR: #129148, branch: users/artempyanykh/fast-coro-upstream-part2-take2/6
df8853d
to
ce2bad5
Compare
…adataPredicate Summary: The new code should be functionally identical to the old one (but faster). The reasoning is as follows. In the old code when cloning within the module: 1. DIFinder traverses and collects *all* debug info reachable from a function, its instructions, and its owning compile unit. 2. Then "compile units, types, other subprograms, and lexical blocks of other subprograms" are saved in a set. 3. Then when we MapMetadata, we traverse the function's debug info _again_ and those nodes that are in the set from p.2 are identity mapped. This looks equivalent to just doing step 3 with identity mapping based on a predicate that says to identity map "compile units, types, other subprograms, and lexical blocks of other subprograms" (same as in step 2). This is what the new code does. Test Plan: ninja check-all There's a bunch of tests around cloning and all of them pass. stack-info: PR: #129148, branch: users/artempyanykh/fast-coro-upstream-part2-take2/6
ce2bad5
to
f235ccf
Compare
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/175/builds/14880 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/137/builds/15049 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/10/builds/1268 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/190/builds/16315 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/60/builds/21971 Here is the relevant piece of the build log for the reference
|
…adataPredicate (llvm#129148) Summary: The new code should be functionally identical to the old one (but faster). The reasoning is as follows. In the old code when cloning within the module: 1. DIFinder traverses and collects *all* debug info reachable from a function, its instructions, and its owning compile unit. 2. Then "compile units, types, other subprograms, and lexical blocks of other subprograms" are saved in a set. 3. Then when we MapMetadata, we traverse the function's debug info _again_ and those nodes that are in the set from p.2 are identity mapped. This looks equivalent to just doing step 3 with identity mapping based on a predicate that says to identity map "compile units, types, other subprograms, and lexical blocks of other subprograms" (same as in step 2). This is what the new code does. Test Plan: ninja check-all There's a bunch of tests around cloning and all of them pass.
Stacked PRs:
[NFC][Cloning] Replace DIFinder usage in CloneFunctionInto with a MetadataPredicate
Summary:
The new code should be functionally identical to the old one (but
faster). The reasoning is as follows.
In the old code when cloning within the module:
function, its instructions, and its owning compile unit.
other subprograms" are saved in a set.
again and those nodes that are in the set from p.2 are identity
mapped.
This looks equivalent to just doing step 3 with identity mapping based
on a predicate that says to identity map "compile units, types, other
subprograms, and lexical blocks of other subprograms" (same as in step
2). This is what the new code does.
Test Plan:
ninja check-all
There's a bunch of tests around cloning and all of them pass.