diff options
| author | Amara Emerson <amara.emerson@arm.com> | 2016-11-08 11:18:59 +0000 |
|---|---|---|
| committer | Amara Emerson <amara.emerson@arm.com> | 2016-11-08 11:18:59 +0000 |
| commit | 0b40201e13996273490dcc7e95fd09dd74f4f903 (patch) | |
| tree | 22ba98438fe00b6d34b1d420503b4378c2efc523 /llvm/lib/Analysis/LoopInfo.cpp | |
| parent | c5079dc3cce447e39603ca2139eb030cad7d770a (diff) | |
| download | bcm5719-llvm-0b40201e13996273490dcc7e95fd09dd74f4f903.tar.gz bcm5719-llvm-0b40201e13996273490dcc7e95fd09dd74f4f903.zip | |
Adds the loop end location to the loop metadata.
This additional information can be used to improve the locations when generating remarks for loops.
Patch by Florian Hahn.
Differential Revision: https://reviews.llvm.org/D25763
llvm-svn: 286227
Diffstat (limited to 'llvm/lib/Analysis/LoopInfo.cpp')
| -rw-r--r-- | llvm/lib/Analysis/LoopInfo.cpp | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/llvm/lib/Analysis/LoopInfo.cpp b/llvm/lib/Analysis/LoopInfo.cpp index d37443cbdbe..d8b8c89cb8d 100644 --- a/llvm/lib/Analysis/LoopInfo.cpp +++ b/llvm/lib/Analysis/LoopInfo.cpp @@ -305,23 +305,40 @@ bool Loop::isAnnotatedParallel() const { } DebugLoc Loop::getStartLoc() const { + return getLocRange().getStart(); +} + +Loop::LocRange Loop::getLocRange() const { // If we have a debug location in the loop ID, then use it. - if (MDNode *LoopID = getLoopID()) - for (unsigned i = 1, ie = LoopID->getNumOperands(); i < ie; ++i) - if (DILocation *L = dyn_cast<DILocation>(LoopID->getOperand(i))) - return DebugLoc(L); + if (MDNode *LoopID = getLoopID()) { + DebugLoc Start; + // We use the first DebugLoc in the header as the start location of the loop + // and if there is a second DebugLoc in the header we use it as end location + // of the loop. + for (unsigned i = 1, ie = LoopID->getNumOperands(); i < ie; ++i) { + if (DILocation *L = dyn_cast<DILocation>(LoopID->getOperand(i))) { + if (!Start) + Start = DebugLoc(L); + else + return LocRange(Start, DebugLoc(L)); + } + } + + if (Start) + return LocRange(Start); + } // Try the pre-header first. if (BasicBlock *PHeadBB = getLoopPreheader()) if (DebugLoc DL = PHeadBB->getTerminator()->getDebugLoc()) - return DL; + return LocRange(DL); // If we have no pre-header or there are no instructions with debug // info in it, try the header. if (BasicBlock *HeadBB = getHeader()) - return HeadBB->getTerminator()->getDebugLoc(); + return LocRange(HeadBB->getTerminator()->getDebugLoc()); - return DebugLoc(); + return LocRange(); } bool Loop::hasDedicatedExits() const { |

