1 //===----- llvm/CodeGen/GlobalISel/LostDebugLocObserver.h -------*- 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 /// \file 9 /// Tracks DebugLocs between checkpoints and verifies that they are transferred. 10 /// 11 //===----------------------------------------------------------------------===// 12 #ifndef LLVM_CODEGEN_GLOBALISEL_LOSTDEBUGLOCOBSERVER_H 13 #define LLVM_CODEGEN_GLOBALISEL_LOSTDEBUGLOCOBSERVER_H 14 15 #include "llvm/ADT/SmallSet.h" 16 #include "llvm/CodeGen/GlobalISel/GISelChangeObserver.h" 17 #include "llvm/Support/Compiler.h" 18 19 namespace llvm { 20 class LLVM_ABI LostDebugLocObserver : public GISelChangeObserver { 21 StringRef DebugType; 22 SmallSet<DebugLoc, 4> LostDebugLocs; 23 SmallPtrSet<MachineInstr *, 4> PotentialMIsForDebugLocs; 24 unsigned NumLostDebugLocs = 0; 25 26 public: LostDebugLocObserver(StringRef DebugType)27 LostDebugLocObserver(StringRef DebugType) : DebugType(DebugType) {} 28 getNumLostDebugLocs()29 unsigned getNumLostDebugLocs() const { return NumLostDebugLocs; } 30 31 /// Call this to indicate that it's a good point to assess whether locations 32 /// have been lost. Typically this will be when a logical change has been 33 /// completed such as the caller has finished replacing some instructions with 34 /// alternatives. When CheckDebugLocs is true, the locations will be checked 35 /// to see if any have been lost since the last checkpoint. When 36 /// CheckDebugLocs is false, it will just reset ready for the next checkpoint 37 /// without checking anything. This can be helpful to limit the detection to 38 /// easy-to-fix portions of an algorithm before allowing more difficult ones. 39 void checkpoint(bool CheckDebugLocs = true); 40 41 void createdInstr(MachineInstr &MI) override; 42 void erasingInstr(MachineInstr &MI) override; 43 void changingInstr(MachineInstr &MI) override; 44 void changedInstr(MachineInstr &MI) override; 45 46 private: 47 void analyzeDebugLocations(); 48 }; 49 50 } // namespace llvm 51 #endif // LLVM_CODEGEN_GLOBALISEL_LOSTDEBUGLOCOBSERVER_H 52