1 //===- LiveDebugVariables.h - Tracking debug info variables -----*- 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 // This file provides the interface to the LiveDebugVariables analysis. 10 // 11 // The analysis removes DBG_VALUE instructions for virtual registers and tracks 12 // live user variables in a data structure that can be updated during register 13 // allocation. 14 // 15 // After register allocation new DBG_VALUE instructions are emitted to reflect 16 // the new locations of user variables. 17 // 18 //===----------------------------------------------------------------------===// 19 20 #ifndef LLVM_CODEGEN_LIVEDEBUGVARIABLES_H 21 #define LLVM_CODEGEN_LIVEDEBUGVARIABLES_H 22 23 #include "llvm/CodeGen/MachineFunctionPass.h" 24 #include "llvm/IR/PassManager.h" 25 #include "llvm/Support/Compiler.h" 26 #include "llvm/Support/raw_ostream.h" 27 #include <memory> 28 29 namespace llvm { 30 31 template <typename T> class ArrayRef; 32 class LiveIntervals; 33 class VirtRegMap; 34 35 class LiveDebugVariables { 36 37 public: 38 class LDVImpl; 39 LiveDebugVariables(); 40 ~LiveDebugVariables(); 41 LiveDebugVariables(LiveDebugVariables &&); 42 43 void analyze(MachineFunction &MF, LiveIntervals *LIS); 44 /// splitRegister - Move any user variables in OldReg to the live ranges in 45 /// NewRegs where they are live. Mark the values as unavailable where no new 46 /// register is live. 47 void splitRegister(Register OldReg, ArrayRef<Register> NewRegs, 48 LiveIntervals &LIS); 49 50 /// emitDebugValues - Emit new DBG_VALUE instructions reflecting the changes 51 /// that happened during register allocation. 52 /// @param VRM Rename virtual registers according to map. 53 void emitDebugValues(VirtRegMap *VRM); 54 55 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 56 /// dump - Print data structures to dbgs(). 57 void dump() const; 58 #endif 59 60 void print(raw_ostream &OS) const; 61 62 void releaseMemory(); 63 64 bool invalidate(MachineFunction &MF, const PreservedAnalyses &PA, 65 MachineFunctionAnalysisManager::Invalidator &Inv); 66 67 private: 68 std::unique_ptr<LDVImpl> PImpl; 69 }; 70 71 class LiveDebugVariablesWrapperLegacy : public MachineFunctionPass { 72 std::unique_ptr<LiveDebugVariables> Impl; 73 74 public: 75 static char ID; // Pass identification, replacement for typeid 76 77 LiveDebugVariablesWrapperLegacy(); 78 79 bool runOnMachineFunction(MachineFunction &) override; 80 81 LiveDebugVariables &getLDV() { return *Impl; } 82 const LiveDebugVariables &getLDV() const { return *Impl; } 83 84 void releaseMemory() override { 85 if (Impl) 86 Impl->releaseMemory(); 87 } 88 void getAnalysisUsage(AnalysisUsage &) const override; 89 90 MachineFunctionProperties getSetProperties() const override { 91 return MachineFunctionProperties().set( 92 MachineFunctionProperties::Property::TracksDebugUserValues); 93 } 94 }; 95 96 class LiveDebugVariablesAnalysis 97 : public AnalysisInfoMixin<LiveDebugVariablesAnalysis> { 98 friend AnalysisInfoMixin<LiveDebugVariablesAnalysis>; 99 static AnalysisKey Key; 100 101 public: 102 using Result = LiveDebugVariables; 103 104 MachineFunctionProperties getSetProperties() const { 105 return MachineFunctionProperties().set( 106 MachineFunctionProperties::Property::TracksDebugUserValues); 107 } 108 109 Result run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM); 110 }; 111 112 class LiveDebugVariablesPrinterPass 113 : public PassInfoMixin<LiveDebugVariablesPrinterPass> { 114 raw_ostream &OS; 115 116 public: 117 LiveDebugVariablesPrinterPass(raw_ostream &OS) : OS(OS) {} 118 119 PreservedAnalyses run(MachineFunction &MF, 120 MachineFunctionAnalysisManager &MFAM); 121 }; 122 } // end namespace llvm 123 124 #endif // LLVM_CODEGEN_LIVEDEBUGVARIABLES_H 125