Recommit [NFC] Better encapsulation of llvm::Optional Storage
[llvm-complete.git] / include / llvm / CodeGen / DbgEntityHistoryCalculator.h
blobb5374d89d7e3b9873da326138f66d3b617600145
1 //===- llvm/CodeGen/DbgEntityHistoryCalculator.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 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CODEGEN_DBGVALUEHISTORYCALCULATOR_H
10 #define LLVM_CODEGEN_DBGVALUEHISTORYCALCULATOR_H
12 #include "llvm/ADT/MapVector.h"
13 #include "llvm/ADT/SmallVector.h"
14 #include "llvm/IR/DebugInfoMetadata.h"
15 #include <utility>
17 namespace llvm {
19 class DILocalVariable;
20 class MachineFunction;
21 class MachineInstr;
22 class TargetRegisterInfo;
24 // For each user variable, keep a list of instruction ranges where this variable
25 // is accessible. The variables are listed in order of appearance.
26 class DbgValueHistoryMap {
27 // Each instruction range starts with a DBG_VALUE instruction, specifying the
28 // location of a variable, which is assumed to be valid until the end of the
29 // range. If end is not specified, location is valid until the start
30 // instruction of the next instruction range, or until the end of the
31 // function.
32 public:
33 using InstrRange = std::pair<const MachineInstr *, const MachineInstr *>;
34 using InstrRanges = SmallVector<InstrRange, 4>;
35 using InlinedEntity = std::pair<const DINode *, const DILocation *>;
36 using InstrRangesMap = MapVector<InlinedEntity, InstrRanges>;
38 private:
39 InstrRangesMap VarInstrRanges;
41 public:
42 void startInstrRange(InlinedEntity Var, const MachineInstr &MI);
43 void endInstrRange(InlinedEntity Var, const MachineInstr &MI);
45 // Returns register currently describing @Var. If @Var is currently
46 // unaccessible or is not described by a register, returns 0.
47 unsigned getRegisterForVar(InlinedEntity Var) const;
49 bool empty() const { return VarInstrRanges.empty(); }
50 void clear() { VarInstrRanges.clear(); }
51 InstrRangesMap::const_iterator begin() const { return VarInstrRanges.begin(); }
52 InstrRangesMap::const_iterator end() const { return VarInstrRanges.end(); }
54 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
55 LLVM_DUMP_METHOD void dump() const;
56 #endif
59 /// For each inlined instance of a source-level label, keep the corresponding
60 /// DBG_LABEL instruction. The DBG_LABEL instruction could be used to generate
61 /// a temporary (assembler) label before it.
62 class DbgLabelInstrMap {
63 public:
64 using InlinedEntity = std::pair<const DINode *, const DILocation *>;
65 using InstrMap = MapVector<InlinedEntity, const MachineInstr *>;
67 private:
68 InstrMap LabelInstr;
70 public:
71 void addInstr(InlinedEntity Label, const MachineInstr &MI);
73 bool empty() const { return LabelInstr.empty(); }
74 void clear() { LabelInstr.clear(); }
75 InstrMap::const_iterator begin() const { return LabelInstr.begin(); }
76 InstrMap::const_iterator end() const { return LabelInstr.end(); }
79 void calculateDbgEntityHistory(const MachineFunction *MF,
80 const TargetRegisterInfo *TRI,
81 DbgValueHistoryMap &DbgValues,
82 DbgLabelInstrMap &DbgLabels);
84 } // end namespace llvm
86 #endif // LLVM_CODEGEN_DBGVALUEHISTORYCALCULATOR_H