blob: c25aaffd2d1c8fa80a491fffbfeef789d714f65f [file] [log] [blame]
Alexey Samsonov414b6fb2014-04-30 21:34:11 +00001//===-- llvm/CodeGen/AsmPrinter/DbgValueHistoryCalculator.h ----*- C++ -*--===//
2//
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"
15
16namespace llvm {
17
18class MachineFunction;
19class MachineInstr;
Duncan P. N. Exon Smith62e0f452015-04-15 22:29:27 +000020class MDLocalVariable;
21class MDLocation;
Alexey Samsonov414b6fb2014-04-30 21:34:11 +000022class TargetRegisterInfo;
23
Alexey Samsonovbb2990d2014-05-27 23:09:50 +000024// For each user variable, keep a list of instruction ranges where this variable
25// is accessible. The variables are listed in order of appearance.
26class 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.
Adrian Prantlb1416832014-08-01 22:11:58 +000032public:
Alexey Samsonovbb2990d2014-05-27 23:09:50 +000033 typedef std::pair<const MachineInstr *, const MachineInstr *> InstrRange;
34 typedef SmallVector<InstrRange, 4> InstrRanges;
Duncan P. N. Exon Smith62e0f452015-04-15 22:29:27 +000035 typedef std::pair<const MDLocalVariable *, const MDLocation *>
36 InlinedVariable;
37 typedef MapVector<InlinedVariable, InstrRanges> InstrRangesMap;
38
Adrian Prantlb1416832014-08-01 22:11:58 +000039private:
Alexey Samsonovbb2990d2014-05-27 23:09:50 +000040 InstrRangesMap VarInstrRanges;
41
42public:
Duncan P. N. Exon Smith62e0f452015-04-15 22:29:27 +000043 void startInstrRange(InlinedVariable Var, const MachineInstr &MI);
44 void endInstrRange(InlinedVariable Var, const MachineInstr &MI);
Alexey Samsonovbb2990d2014-05-27 23:09:50 +000045 // Returns register currently describing @Var. If @Var is currently
46 // unaccessible or is not described by a register, returns 0.
Duncan P. N. Exon Smith62e0f452015-04-15 22:29:27 +000047 unsigned getRegisterForVar(InlinedVariable Var) const;
Alexey Samsonovbb2990d2014-05-27 23:09:50 +000048
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(); }
53};
Alexey Samsonov414b6fb2014-04-30 21:34:11 +000054
55void calculateDbgValueHistory(const MachineFunction *MF,
56 const TargetRegisterInfo *TRI,
57 DbgValueHistoryMap &Result);
58}
59
60#endif