Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:29

0001 //===- LiveDebugVariables.h - Tracking debug info variables -----*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file provides the interface to the LiveDebugVariables analysis.
0010 //
0011 // The analysis removes DBG_VALUE instructions for virtual registers and tracks
0012 // live user variables in a data structure that can be updated during register
0013 // allocation.
0014 //
0015 // After register allocation new DBG_VALUE instructions are emitted to reflect
0016 // the new locations of user variables.
0017 //
0018 //===----------------------------------------------------------------------===//
0019 
0020 #ifndef LLVM_CODEGEN_LIVEDEBUGVARIABLES_H
0021 #define LLVM_CODEGEN_LIVEDEBUGVARIABLES_H
0022 
0023 #include "llvm/CodeGen/MachineFunctionPass.h"
0024 #include "llvm/IR/PassManager.h"
0025 #include "llvm/Support/Compiler.h"
0026 #include "llvm/Support/raw_ostream.h"
0027 #include <memory>
0028 
0029 namespace llvm {
0030 
0031 template <typename T> class ArrayRef;
0032 class LiveIntervals;
0033 class VirtRegMap;
0034 
0035 class LiveDebugVariables {
0036 
0037 public:
0038   class LDVImpl;
0039   LiveDebugVariables();
0040   ~LiveDebugVariables();
0041   LiveDebugVariables(LiveDebugVariables &&);
0042 
0043   void analyze(MachineFunction &MF, LiveIntervals *LIS);
0044   /// splitRegister - Move any user variables in OldReg to the live ranges in
0045   /// NewRegs where they are live. Mark the values as unavailable where no new
0046   /// register is live.
0047   void splitRegister(Register OldReg, ArrayRef<Register> NewRegs,
0048                      LiveIntervals &LIS);
0049 
0050   /// emitDebugValues - Emit new DBG_VALUE instructions reflecting the changes
0051   /// that happened during register allocation.
0052   /// @param VRM Rename virtual registers according to map.
0053   void emitDebugValues(VirtRegMap *VRM);
0054 
0055 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
0056   /// dump - Print data structures to dbgs().
0057   void dump() const;
0058 #endif
0059 
0060   void print(raw_ostream &OS) const;
0061 
0062   void releaseMemory();
0063 
0064   bool invalidate(MachineFunction &MF, const PreservedAnalyses &PA,
0065                   MachineFunctionAnalysisManager::Invalidator &Inv);
0066 
0067 private:
0068   std::unique_ptr<LDVImpl> PImpl;
0069 };
0070 
0071 class LiveDebugVariablesWrapperLegacy : public MachineFunctionPass {
0072   std::unique_ptr<LiveDebugVariables> Impl;
0073 
0074 public:
0075   static char ID; // Pass identification, replacement for typeid
0076 
0077   LiveDebugVariablesWrapperLegacy();
0078 
0079   bool runOnMachineFunction(MachineFunction &) override;
0080 
0081   LiveDebugVariables &getLDV() { return *Impl; }
0082   const LiveDebugVariables &getLDV() const { return *Impl; }
0083 
0084   void releaseMemory() override {
0085     if (Impl)
0086       Impl->releaseMemory();
0087   }
0088   void getAnalysisUsage(AnalysisUsage &) const override;
0089 
0090   MachineFunctionProperties getSetProperties() const override {
0091     return MachineFunctionProperties().set(
0092         MachineFunctionProperties::Property::TracksDebugUserValues);
0093   }
0094 };
0095 
0096 class LiveDebugVariablesAnalysis
0097     : public AnalysisInfoMixin<LiveDebugVariablesAnalysis> {
0098   friend AnalysisInfoMixin<LiveDebugVariablesAnalysis>;
0099   static AnalysisKey Key;
0100 
0101 public:
0102   using Result = LiveDebugVariables;
0103 
0104   MachineFunctionProperties getSetProperties() const {
0105     return MachineFunctionProperties().set(
0106         MachineFunctionProperties::Property::TracksDebugUserValues);
0107   }
0108 
0109   Result run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM);
0110 };
0111 
0112 class LiveDebugVariablesPrinterPass
0113     : public PassInfoMixin<LiveDebugVariablesPrinterPass> {
0114   raw_ostream &OS;
0115 
0116 public:
0117   LiveDebugVariablesPrinterPass(raw_ostream &OS) : OS(OS) {}
0118 
0119   PreservedAnalyses run(MachineFunction &MF,
0120                         MachineFunctionAnalysisManager &MFAM);
0121 };
0122 } // end namespace llvm
0123 
0124 #endif // LLVM_CODEGEN_LIVEDEBUGVARIABLES_H