1a63b7ceeSTobias Grosser //=== ScopLocation.cpp - Debug location for ScopDetection ----- -*- C++ -*-===// 2a63b7ceeSTobias Grosser // 32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6a63b7ceeSTobias Grosser // 7a63b7ceeSTobias Grosser //===----------------------------------------------------------------------===// 8a63b7ceeSTobias Grosser // 9a63b7ceeSTobias Grosser // Helper function for extracting region debug information. 10a63b7ceeSTobias Grosser // 11a63b7ceeSTobias Grosser //===----------------------------------------------------------------------===// 12a63b7ceeSTobias Grosser // 13a63b7ceeSTobias Grosser #include "polly/Support/ScopLocation.h" 14ba0d0922STobias Grosser #include "llvm/Analysis/RegionInfo.h" 15031bb165SMichael Kruse #include "llvm/IR/DebugInfoMetadata.h" 16a63b7ceeSTobias Grosser 17a63b7ceeSTobias Grosser using namespace llvm; 18a63b7ceeSTobias Grosser 19a63b7ceeSTobias Grosser namespace polly { 20a63b7ceeSTobias Grosser getDebugLocation(const Region * R,unsigned & LineBegin,unsigned & LineEnd,std::string & FileName)21a63b7ceeSTobias Grosservoid getDebugLocation(const Region *R, unsigned &LineBegin, unsigned &LineEnd, 22a63b7ceeSTobias Grosser std::string &FileName) { 23a63b7ceeSTobias Grosser LineBegin = -1; 24a63b7ceeSTobias Grosser LineEnd = 0; 25a63b7ceeSTobias Grosser 26a63b7ceeSTobias Grosser for (const BasicBlock *BB : R->blocks()) 27a63b7ceeSTobias Grosser for (const Instruction &Inst : *BB) { 28*b5a273a1SStephen Tozer DebugLoc DL = Inst.getStableDebugLoc(); 29a63b7ceeSTobias Grosser if (!DL) 30a63b7ceeSTobias Grosser continue; 31a63b7ceeSTobias Grosser 32a63b7ceeSTobias Grosser auto *Scope = cast<DIScope>(DL.getScope()); 33a63b7ceeSTobias Grosser 34a63b7ceeSTobias Grosser if (FileName.empty()) 350257a921SEli Friedman FileName = Scope->getFilename().str(); 36a63b7ceeSTobias Grosser 37a63b7ceeSTobias Grosser unsigned NewLine = DL.getLine(); 38a63b7ceeSTobias Grosser 39a63b7ceeSTobias Grosser LineBegin = std::min(LineBegin, NewLine); 40a63b7ceeSTobias Grosser LineEnd = std::max(LineEnd, NewLine); 41a63b7ceeSTobias Grosser } 42a63b7ceeSTobias Grosser } 43522478d2STobias Grosser } // namespace polly 44