1 //===- llvm/CodeGen/AsmPrinter/DbgEntityHistoryCalculator.h -----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DBGVALUEHISTORYCALCULATOR_H
11 #define LLVM_LIB_CODEGEN_ASMPRINTER_DBGVALUEHISTORYCALCULATOR_H
13 #include "llvm/ADT/MapVector.h"
14 #include "llvm/ADT/SmallVector.h"
15 #include "llvm/IR/DebugInfoMetadata.h"
20 class DILocalVariable;
21 class MachineFunction;
23 class TargetRegisterInfo;
25 // For each user variable, keep a list of instruction ranges where this variable
26 // is accessible. The variables are listed in order of appearance.
27 class DbgValueHistoryMap {
28 // Each instruction range starts with a DBG_VALUE instruction, specifying the
29 // location of a variable, which is assumed to be valid until the end of the
30 // range. If end is not specified, location is valid until the start
31 // instruction of the next instruction range, or until the end of the
34 using InstrRange = std::pair<const MachineInstr *, const MachineInstr *>;
35 using InstrRanges = SmallVector<InstrRange, 4>;
36 using InlinedVariable =
37 std::pair<const DILocalVariable *, const DILocation *>;
38 using InstrRangesMap = MapVector<InlinedVariable, InstrRanges>;
41 InstrRangesMap VarInstrRanges;
44 void startInstrRange(InlinedVariable Var, const MachineInstr &MI);
45 void endInstrRange(InlinedVariable Var, const MachineInstr &MI);
47 // Returns register currently describing @Var. If @Var is currently
48 // unaccessible or is not described by a register, returns 0.
49 unsigned getRegisterForVar(InlinedVariable Var) const;
51 bool empty() const { return VarInstrRanges.empty(); }
52 void clear() { VarInstrRanges.clear(); }
53 InstrRangesMap::const_iterator begin() const { return VarInstrRanges.begin(); }
54 InstrRangesMap::const_iterator end() const { return VarInstrRanges.end(); }
56 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
57 LLVM_DUMP_METHOD void dump() const;
61 /// For each inlined instance of a source-level label, keep the corresponding
62 /// DBG_LABEL instruction. The DBG_LABEL instruction could be used to generate
63 /// a temporary (assembler) label before it.
64 class DbgLabelInstrMap {
66 using InlinedLabel = std::pair<const DILabel *, const DILocation *>;
67 using InstrMap = MapVector<InlinedLabel, const MachineInstr *>;
73 void addInstr(InlinedLabel Label, const MachineInstr &MI);
75 bool empty() const { return LabelInstr.empty(); }
76 void clear() { LabelInstr.clear(); }
77 InstrMap::const_iterator begin() const { return LabelInstr.begin(); }
78 InstrMap::const_iterator end() const { return LabelInstr.end(); }
81 void calculateDbgEntityHistory(const MachineFunction *MF,
82 const TargetRegisterInfo *TRI,
83 DbgValueHistoryMap &DbgValues,
84 DbgLabelInstrMap &DbgLabels);
86 } // end namespace llvm
88 #endif // LLVM_LIB_CODEGEN_ASMPRINTER_DBGVALUEHISTORYCALCULATOR_H