LostDebugLocObserver.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===----- llvm/CodeGen/GlobalISel/LostDebugLocObserver.h -------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. /// \file
  14. /// Tracks DebugLocs between checkpoints and verifies that they are transferred.
  15. ///
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_CODEGEN_GLOBALISEL_LOSTDEBUGLOCOBSERVER_H
  18. #define LLVM_CODEGEN_GLOBALISEL_LOSTDEBUGLOCOBSERVER_H
  19. #include "llvm/ADT/SmallSet.h"
  20. #include "llvm/CodeGen/GlobalISel/GISelChangeObserver.h"
  21. namespace llvm {
  22. class LostDebugLocObserver : public GISelChangeObserver {
  23. StringRef DebugType;
  24. SmallSet<DebugLoc, 4> LostDebugLocs;
  25. SmallPtrSet<MachineInstr *, 4> PotentialMIsForDebugLocs;
  26. unsigned NumLostDebugLocs = 0;
  27. public:
  28. LostDebugLocObserver(StringRef DebugType) : DebugType(DebugType) {}
  29. unsigned getNumLostDebugLocs() const { return NumLostDebugLocs; }
  30. /// Call this to indicate that it's a good point to assess whether locations
  31. /// have been lost. Typically this will be when a logical change has been
  32. /// completed such as the caller has finished replacing some instructions with
  33. /// alternatives. When CheckDebugLocs is true, the locations will be checked
  34. /// to see if any have been lost since the last checkpoint. When
  35. /// CheckDebugLocs is false, it will just reset ready for the next checkpoint
  36. /// without checking anything. This can be helpful to limit the detection to
  37. /// easy-to-fix portions of an algorithm before allowing more difficult ones.
  38. void checkpoint(bool CheckDebugLocs = true);
  39. void createdInstr(MachineInstr &MI) override;
  40. void erasingInstr(MachineInstr &MI) override;
  41. void changingInstr(MachineInstr &MI) override;
  42. void changedInstr(MachineInstr &MI) override;
  43. private:
  44. void analyzeDebugLocations();
  45. };
  46. } // namespace llvm
  47. #endif // LLVM_CODEGEN_GLOBALISEL_LOSTDEBUGLOCOBSERVER_H
  48. #ifdef __GNUC__
  49. #pragma GCC diagnostic pop
  50. #endif