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 #include "llvm/Analysis/RegionInfo.h" 16 #include "llvm/IR/BasicBlock.h" 17 #include "llvm/IR/DebugInfo.h" 18 #include "llvm/IR/DebugLoc.h" 19 20 using namespace llvm; 21 22 namespace polly { 23 24 void getDebugLocation(const Region *R, unsigned &LineBegin, unsigned &LineEnd, 25 std::string &FileName) { 26 LineBegin = -1; 27 LineEnd = 0; 28 29 for (const BasicBlock *BB : R->blocks()) 30 for (const Instruction &Inst : *BB) { 31 DebugLoc DL = Inst.getDebugLoc(); 32 if (!DL) 33 continue; 34 35 auto *Scope = cast<DIScope>(DL.getScope()); 36 37 if (FileName.empty()) 38 FileName = Scope->getFilename(); 39 40 unsigned NewLine = DL.getLine(); 41 42 LineBegin = std::min(LineBegin, NewLine); 43 LineEnd = std::max(LineEnd, NewLine); 44 } 45 } 46 } // namespace polly 47