[clang-repl] [codegen] Reduce the state in TBAA. NFC for static compilation. (#98138)
[llvm-project.git] / polly / lib / Support / ScopLocation.cpp
blob9f9941d57ad26a9dd8cb25e7b13e4da875dafff1
1 //=== ScopLocation.cpp - Debug location for ScopDetection ----- -*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Helper function for extracting region debug information.
11 //===----------------------------------------------------------------------===//
13 #include "polly/Support/ScopLocation.h"
14 #include "llvm/Analysis/RegionInfo.h"
15 #include "llvm/IR/DebugInfoMetadata.h"
17 using namespace llvm;
19 namespace polly {
21 void getDebugLocation(const Region *R, unsigned &LineBegin, unsigned &LineEnd,
22 std::string &FileName) {
23 LineBegin = -1;
24 LineEnd = 0;
26 for (const BasicBlock *BB : R->blocks())
27 for (const Instruction &Inst : *BB) {
28 DebugLoc DL = Inst.getStableDebugLoc();
29 if (!DL)
30 continue;
32 auto *Scope = cast<DIScope>(DL.getScope());
34 if (FileName.empty())
35 FileName = Scope->getFilename().str();
37 unsigned NewLine = DL.getLine();
39 LineBegin = std::min(LineBegin, NewLine);
40 LineEnd = std::max(LineEnd, NewLine);
43 } // namespace polly