blob: a7b0562e81024106243dc41a1536be14dff8fb24 [file] [log] [blame]
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +00001//===- llvm/CodeGen/AsmPrinter/DbgValueHistoryCalculator.h ------*- C++ -*-===//
Alexey Samsonov414b6fb2014-04-30 21:34:11 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000010#ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DBGVALUEHISTORYCALCULATOR_H
11#define LLVM_LIB_CODEGEN_ASMPRINTER_DBGVALUEHISTORYCALCULATOR_H
Alexey Samsonov414b6fb2014-04-30 21:34:11 +000012
Alexey Samsonov0436caa2014-04-30 23:02:40 +000013#include "llvm/ADT/MapVector.h"
Alexey Samsonov414b6fb2014-04-30 21:34:11 +000014#include "llvm/ADT/SmallVector.h"
David Blaikie8699f712017-10-27 22:12:46 +000015#include "llvm/IR/DebugInfoMetadata.h"
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +000016#include <utility>
Alexey Samsonov414b6fb2014-04-30 21:34:11 +000017
18namespace llvm {
19
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +000020class DILocalVariable;
Alexey Samsonov414b6fb2014-04-30 21:34:11 +000021class MachineFunction;
22class MachineInstr;
Alexey Samsonov414b6fb2014-04-30 21:34:11 +000023class TargetRegisterInfo;
24
Alexey Samsonovbb2990d2014-05-27 23:09:50 +000025// For each user variable, keep a list of instruction ranges where this variable
26// is accessible. The variables are listed in order of appearance.
27class 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
32 // function.
Adrian Prantlb1416832014-08-01 22:11:58 +000033public:
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +000034 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>;
Duncan P. N. Exon Smith62e0f452015-04-15 22:29:27 +000039
Adrian Prantlb1416832014-08-01 22:11:58 +000040private:
Alexey Samsonovbb2990d2014-05-27 23:09:50 +000041 InstrRangesMap VarInstrRanges;
42
43public:
Duncan P. N. Exon Smith62e0f452015-04-15 22:29:27 +000044 void startInstrRange(InlinedVariable Var, const MachineInstr &MI);
45 void endInstrRange(InlinedVariable Var, const MachineInstr &MI);
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +000046
Alexey Samsonovbb2990d2014-05-27 23:09:50 +000047 // Returns register currently describing @Var. If @Var is currently
48 // unaccessible or is not described by a register, returns 0.
Duncan P. N. Exon Smith62e0f452015-04-15 22:29:27 +000049 unsigned getRegisterForVar(InlinedVariable Var) const;
Alexey Samsonovbb2990d2014-05-27 23:09:50 +000050
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(); }
55};
Alexey Samsonov414b6fb2014-04-30 21:34:11 +000056
57void calculateDbgValueHistory(const MachineFunction *MF,
58 const TargetRegisterInfo *TRI,
59 DbgValueHistoryMap &Result);
Alexey Samsonov414b6fb2014-04-30 21:34:11 +000060
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +000061} // end namespace llvm
62
63#endif // LLVM_LIB_CODEGEN_ASMPRINTER_DBGVALUEHISTORYCALCULATOR_H