ScopLocation.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. //
  13. #include "polly/Support/ScopLocation.h"
  14. #include "llvm/Analysis/RegionInfo.h"
  15. #include "llvm/IR/DebugInfoMetadata.h"
  16. using namespace llvm;
  17. namespace polly {
  18. void getDebugLocation(const Region *R, unsigned &LineBegin, unsigned &LineEnd,
  19. std::string &FileName) {
  20. LineBegin = -1;
  21. LineEnd = 0;
  22. for (const BasicBlock *BB : R->blocks())
  23. for (const Instruction &Inst : *BB) {
  24. DebugLoc DL = Inst.getDebugLoc();
  25. if (!DL)
  26. continue;
  27. auto *Scope = cast<DIScope>(DL.getScope());
  28. if (FileName.empty())
  29. FileName = Scope->getFilename().str();
  30. unsigned NewLine = DL.getLine();
  31. LineBegin = std::min(LineBegin, NewLine);
  32. LineEnd = std::max(LineEnd, NewLine);
  33. }
  34. }
  35. } // namespace polly