xref: /llvm-project/polly/lib/Support/ScopLocation.cpp (revision a63b7cee66ff16485a8927d0fe86bd1ab0e21f4d)
1 //=== ScopLocation.cpp - Debug location for ScopDetection ----- -*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Helper function for extracting region debug information.
11 //
12 //===----------------------------------------------------------------------===//
13 //
14 #include "polly/Support/ScopLocation.h"
15 
16 #include "llvm/IR/BasicBlock.h"
17 #include "llvm/IR/DebugInfo.h"
18 #include "llvm/IR/DebugLoc.h"
19 #include "llvm/Analysis/RegionInfo.h"
20 
21 using namespace llvm;
22 
23 namespace polly {
24 
25 void getDebugLocation(const Region *R, unsigned &LineBegin, unsigned &LineEnd,
26                       std::string &FileName) {
27   LineBegin = -1;
28   LineEnd = 0;
29 
30   for (const BasicBlock *BB : R->blocks())
31     for (const Instruction &Inst : *BB) {
32       DebugLoc DL = Inst.getDebugLoc();
33       if (!DL)
34         continue;
35 
36       auto *Scope = cast<DIScope>(DL.getScope());
37 
38       if (FileName.empty())
39         FileName = Scope->getFilename();
40 
41       unsigned NewLine = DL.getLine();
42 
43       LineBegin = std::min(LineBegin, NewLine);
44       LineEnd = std::max(LineEnd, NewLine);
45     }
46 }
47 }
48