aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/InlineFunction.cpp
diff options
context:
space:
mode:
authorVedant Kumar <vsk@apple.com>2020-01-15 11:22:06 -0800
committerVedant Kumar <vsk@apple.com>2020-01-15 13:02:36 -0800
commita2cc80bc95703b99afefddb1d9d545c639ac4ff5 (patch)
tree9d1567f6cbbb5a247288796afe9c68529f2f6959 /llvm/lib/Transforms/Utils/InlineFunction.cpp
parentf0120556c7e2ef14ff3da5bd7d5717cedf94b767 (diff)
downloadllvm-a2cc80bc95703b99afefddb1d9d545c639ac4ff5.zip
llvm-a2cc80bc95703b99afefddb1d9d545c639ac4ff5.tar.gz
llvm-a2cc80bc95703b99afefddb1d9d545c639ac4ff5.tar.bz2
DebugInfo: Factor out logic to update locations in MD_loop metadata, NFC
Factor out the logic needed to update debug locations contained within MD_loop metadata. This refactor is preparation for a future change that also needs to rewrite MD_loop metadata. rdar://45507940
Diffstat (limited to 'llvm/lib/Transforms/Utils/InlineFunction.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/InlineFunction.cpp38
1 files changed, 5 insertions, 33 deletions
diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp
index 6da612e..59eb286 100644
--- a/llvm/lib/Transforms/Utils/InlineFunction.cpp
+++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp
@@ -1356,34 +1356,6 @@ static DebugLoc inlineDebugLoc(DebugLoc OrigDL, DILocation *InlinedAt,
IA);
}
-/// Returns the LoopID for a loop which has has been cloned from another
-/// function for inlining with the new inlined-at start and end locs.
-static MDNode *inlineLoopID(const MDNode *OrigLoopId, DILocation *InlinedAt,
- LLVMContext &Ctx,
- DenseMap<const MDNode *, MDNode *> &IANodes) {
- assert(OrigLoopId && OrigLoopId->getNumOperands() > 0 &&
- "Loop ID needs at least one operand");
- assert(OrigLoopId && OrigLoopId->getOperand(0).get() == OrigLoopId &&
- "Loop ID should refer to itself");
-
- // Save space for the self-referential LoopID.
- SmallVector<Metadata *, 4> MDs = {nullptr};
-
- for (unsigned i = 1; i < OrigLoopId->getNumOperands(); ++i) {
- Metadata *MD = OrigLoopId->getOperand(i);
- // Update the DILocations to encode the inlined-at metadata.
- if (DILocation *DL = dyn_cast<DILocation>(MD))
- MDs.push_back(inlineDebugLoc(DL, InlinedAt, Ctx, IANodes));
- else
- MDs.push_back(MD);
- }
-
- MDNode *NewLoopID = MDNode::getDistinct(Ctx, MDs);
- // Insert the self-referential LoopID.
- NewLoopID->replaceOperandWith(0, NewLoopID);
- return NewLoopID;
-}
-
/// Update inlined instructions' line numbers to
/// to encode location where these instructions are inlined.
static void fixupLineNumbers(Function *Fn, Function::iterator FI,
@@ -1415,11 +1387,11 @@ static void fixupLineNumbers(Function *Fn, Function::iterator FI,
BI != BE; ++BI) {
// Loop metadata needs to be updated so that the start and end locs
// reference inlined-at locations.
- if (MDNode *LoopID = BI->getMetadata(LLVMContext::MD_loop)) {
- MDNode *NewLoopID =
- inlineLoopID(LoopID, InlinedAtNode, BI->getContext(), IANodes);
- BI->setMetadata(LLVMContext::MD_loop, NewLoopID);
- }
+ auto updateLoopInfoLoc = [&Ctx, &InlinedAtNode, &IANodes](
+ const DILocation &Loc) -> DILocation * {
+ return inlineDebugLoc(&Loc, InlinedAtNode, Ctx, IANodes).get();
+ };
+ updateLoopMetadataDebugLocations(*BI, updateLoopInfoLoc);
if (!NoInlineLineTables)
if (DebugLoc DL = BI->getDebugLoc()) {