-
Notifications
You must be signed in to change notification settings - Fork 14.6k
[CodeExtractor][NFC] Refactor-out applyFirstDebugLoc. #115358
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
[CodeExtractor][NFC] Refactor-out applyFirstDebugLoc. #115358
Conversation
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.
LGTM. Thanks Michael.
GitHub CI failure unrelated:
|
@llvm/pr-subscribers-llvm-transforms Author: Michael Kruse (Meinersbur) ChangesSplit-off from #114419 Full diff: https://github.com/llvm/llvm-project/pull/115358.diff 1 Files Affected:
diff --git a/llvm/lib/Transforms/Utils/CodeExtractor.cpp b/llvm/lib/Transforms/Utils/CodeExtractor.cpp
index fa467cc72bd020..ccca88d6c8e7d3 100644
--- a/llvm/lib/Transforms/Utils/CodeExtractor.cpp
+++ b/llvm/lib/Transforms/Utils/CodeExtractor.cpp
@@ -1080,6 +1080,29 @@ Function *CodeExtractor::constructFunction(const ValueSet &inputs,
return newFunction;
}
+/// If the original function has debug info, we have to add a debug location
+/// to the new branch instruction from the artificial entry block.
+/// We use the debug location of the first instruction in the extracted
+/// blocks, as there is no other equivalent line in the source code.
+static void applyFirstDebugLoc(Function *oldFunction,
+ ArrayRef<BasicBlock *> Blocks,
+ Instruction *BranchI) {
+ if (oldFunction->getSubprogram()) {
+ any_of(Blocks, [&BranchI](const BasicBlock *BB) {
+ return any_of(*BB, [&BranchI](const Instruction &I) {
+ if (!I.getDebugLoc())
+ return false;
+ // Don't use source locations attached to debug-intrinsics: they could
+ // be from completely unrelated scopes.
+ if (isa<DbgInfoIntrinsic>(I))
+ return false;
+ BranchI->setDebugLoc(I.getDebugLoc());
+ return true;
+ });
+ });
+ }
+}
+
/// Erase lifetime.start markers which reference inputs to the extraction
/// region, and insert the referenced memory into \p LifetimesStart.
///
@@ -1792,24 +1815,7 @@ CodeExtractor::extractCodeRegion(const CodeExtractorAnalysisCache &CEAC,
newFuncRoot->IsNewDbgInfoFormat = oldFunction->IsNewDbgInfoFormat;
auto *BranchI = BranchInst::Create(header);
- // If the original function has debug info, we have to add a debug location
- // to the new branch instruction from the artificial entry block.
- // We use the debug location of the first instruction in the extracted
- // blocks, as there is no other equivalent line in the source code.
- if (oldFunction->getSubprogram()) {
- any_of(Blocks, [&BranchI](const BasicBlock *BB) {
- return any_of(*BB, [&BranchI](const Instruction &I) {
- if (!I.getDebugLoc())
- return false;
- // Don't use source locations attached to debug-intrinsics: they could
- // be from completely unrelated scopes.
- if (isa<DbgInfoIntrinsic>(I))
- return false;
- BranchI->setDebugLoc(I.getDebugLoc());
- return true;
- });
- });
- }
+ applyFirstDebugLoc(oldFunction, Blocks.getArrayRef(), BranchI);
BranchI->insertInto(newFuncRoot, newFuncRoot->end());
ValueSet SinkingCands, HoistingCands;
|
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.
Thanks! LGTM
Split-off from #114419