[llvm] r286227 - Adds the loop end location to the loop metadata.
Amara Emerson via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 8 03:18:59 PST 2016
Author: aemerson
Date: Tue Nov 8 05:18:59 2016
New Revision: 286227
URL: http://llvm.org/viewvc/llvm-project?rev=286227&view=rev
Log:
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
Modified:
llvm/trunk/include/llvm/Analysis/LoopInfo.h
llvm/trunk/lib/Analysis/LoopInfo.cpp
Modified: llvm/trunk/include/llvm/Analysis/LoopInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/LoopInfo.h?rev=286227&r1=286226&r2=286227&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Analysis/LoopInfo.h (original)
+++ llvm/trunk/include/llvm/Analysis/LoopInfo.h Tue Nov 8 05:18:59 2016
@@ -367,6 +367,27 @@ extern template class LoopBase<BasicBloc
/// in the CFG are neccessarily loops.
class Loop : public LoopBase<BasicBlock, Loop> {
public:
+ /// \brief A range representing the start and end location of a loop.
+ class LocRange {
+ DebugLoc Start;
+ DebugLoc End;
+
+ public:
+ LocRange() {}
+ LocRange(DebugLoc Start) : Start(std::move(Start)), End(std::move(Start)) {}
+ LocRange(DebugLoc Start, DebugLoc End) : Start(std::move(Start)),
+ End(std::move(End)) {}
+
+ const DebugLoc &getStart() const { return Start; }
+ const DebugLoc &getEnd() const { return End; }
+
+ /// \brief Check for null.
+ ///
+ explicit operator bool() const {
+ return Start && End;
+ }
+ };
+
Loop() {}
/// Return true if the specified value is loop invariant.
@@ -474,6 +495,9 @@ public:
/// it returns an unknown location.
DebugLoc getStartLoc() const;
+ /// Return the source code span of the loop.
+ LocRange getLocRange() const;
+
StringRef getName() const {
if (BasicBlock *Header = getHeader())
if (Header->hasName())
Modified: llvm/trunk/lib/Analysis/LoopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/LoopInfo.cpp?rev=286227&r1=286226&r2=286227&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/LoopInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/LoopInfo.cpp Tue Nov 8 05:18:59 2016
@@ -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 {
More information about the llvm-commits
mailing list