blob: 6c9d3c34b0818b3467a65c2a6c561434b824560f [file] [log] [blame]
Reid Klecknerf9c275f2016-02-10 20:55:49 +00001//===-- llvm/lib/CodeGen/AsmPrinter/DebugHandlerBase.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//
10// Common functionality for different debug information format backends.
11// LLVM currently supports DWARF and CodeView.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DEBUGHANDLERBASE_H
16#define LLVM_LIB_CODEGEN_ASMPRINTER_DEBUGHANDLERBASE_H
17
18#include "AsmPrinterHandler.h"
19#include "DbgValueHistoryCalculator.h"
20#include "llvm/CodeGen/LexicalScopes.h"
21
22namespace llvm {
23
24class AsmPrinter;
25class MachineModuleInfo;
26
27/// Base class for debug information backends. Common functionality related to
28/// tracking which variables and scopes are alive at a given PC live here.
Benjamin Kramere3b963d2016-02-11 15:41:56 +000029class DebugHandlerBase : public AsmPrinterHandler {
Reid Klecknerf9c275f2016-02-10 20:55:49 +000030protected:
31 DebugHandlerBase(AsmPrinter *A);
32
33 /// Target of debug info emission.
34 AsmPrinter *Asm;
35
36 /// Collected machine module information.
37 MachineModuleInfo *MMI;
38
39 /// Previous instruction's location information. This is used to
40 /// determine label location to indicate scope boundries in dwarf
41 /// debug info.
42 DebugLoc PrevInstLoc;
43 MCSymbol *PrevLabel = nullptr;
44
45 /// This location indicates end of function prologue and beginning of
46 /// function body.
47 DebugLoc PrologEndLoc;
48
49 /// If nonnull, stores the current machine instruction we're processing.
50 const MachineInstr *CurMI = nullptr;
51
52 LexicalScopes LScopes;
53
54 /// History of DBG_VALUE and clobber instructions for each user
55 /// variable. Variables are listed in order of appearance.
56 DbgValueHistoryMap DbgValues;
57
58 /// Maps instruction with label emitted before instruction.
59 /// FIXME: Make this private from DwarfDebug, we have the necessary accessors
60 /// for it.
61 DenseMap<const MachineInstr *, MCSymbol *> LabelsBeforeInsn;
62
63 /// Maps instruction with label emitted after instruction.
64 DenseMap<const MachineInstr *, MCSymbol *> LabelsAfterInsn;
65
66 /// Indentify instructions that are marking the beginning of or
67 /// ending of a scope.
68 void identifyScopeMarkers();
69
70 /// Ensure that a label will be emitted before MI.
71 void requestLabelBeforeInsn(const MachineInstr *MI) {
72 LabelsBeforeInsn.insert(std::make_pair(MI, nullptr));
73 }
74
75 /// Ensure that a label will be emitted after MI.
76 void requestLabelAfterInsn(const MachineInstr *MI) {
77 LabelsAfterInsn.insert(std::make_pair(MI, nullptr));
78 }
79
80 // AsmPrinterHandler overrides.
81public:
82 void beginInstruction(const MachineInstr *MI) override;
83 void endInstruction() override;
84
85 void beginFunction(const MachineFunction *MF) override;
86 void endFunction(const MachineFunction *MF) override;
87
88 /// Return Label preceding the instruction.
89 MCSymbol *getLabelBeforeInsn(const MachineInstr *MI);
90
91 /// Return Label immediately following the instruction.
92 MCSymbol *getLabelAfterInsn(const MachineInstr *MI);
93
94 /// Determine the relative position of the pieces described by P1 and P2.
95 /// Returns -1 if P1 is entirely before P2, 0 if P1 and P2 overlap,
96 /// 1 if P1 is entirely after P2.
97 static int pieceCmp(const DIExpression *P1, const DIExpression *P2);
98
99 /// Determine whether two variable pieces overlap.
100 static bool piecesOverlap(const DIExpression *P1, const DIExpression *P2);
101};
102
103}
104
105#endif