LLVM  6.0.0svn
DebugHandlerBase.h
Go to the documentation of this file.
1 //===-- 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"
20 #include "llvm/ADT/Optional.h"
24 
25 namespace llvm {
26 
27 class AsmPrinter;
28 class MachineInstr;
29 class MachineModuleInfo;
30 
31 /// Represents the location at which a variable is stored.
33  /// Base register.
34  unsigned Register;
35 
36  /// Chain of offsetted loads necessary to load the value if it lives in
37  /// memory. Every load except for the last is pointer-sized.
39 
40  /// Present if the location is part of a larger variable.
42 
43  /// Extract a VariableLocation from a MachineInstr.
44  /// This will only work if Instruction is a debug value instruction
45  /// and the associated DIExpression is in one of the supported forms.
46  /// If these requirements are not met, the returned Optional will not
47  /// have a value.
50 };
51 
52 /// Base class for debug information backends. Common functionality related to
53 /// tracking which variables and scopes are alive at a given PC live here.
55 protected:
57 
58  /// Target of debug info emission.
60 
61  /// Collected machine module information.
63 
64  /// Previous instruction's location information. This is used to
65  /// determine label location to indicate scope boundaries in debug info.
66  /// We track the previous instruction's source location (if not line 0),
67  /// whether it was a label, and its parent BB.
69  MCSymbol *PrevLabel = nullptr;
70  const MachineBasicBlock *PrevInstBB = nullptr;
71 
72  /// This location indicates end of function prologue and beginning of
73  /// function body.
75 
76  /// If nonnull, stores the current machine instruction we're processing.
77  const MachineInstr *CurMI = nullptr;
78 
80 
81  /// History of DBG_VALUE and clobber instructions for each user
82  /// variable. Variables are listed in order of appearance.
84 
85  /// Maps instruction with label emitted before instruction.
86  /// FIXME: Make this private from DwarfDebug, we have the necessary accessors
87  /// for it.
89 
90  /// Maps instruction with label emitted after instruction.
92 
93  /// Indentify instructions that are marking the beginning of or
94  /// ending of a scope.
95  void identifyScopeMarkers();
96 
97  /// Ensure that a label will be emitted before MI.
99  LabelsBeforeInsn.insert(std::make_pair(MI, nullptr));
100  }
101 
102  /// Ensure that a label will be emitted after MI.
104  LabelsAfterInsn.insert(std::make_pair(MI, nullptr));
105  }
106 
107  virtual void beginFunctionImpl(const MachineFunction *MF) = 0;
108  virtual void endFunctionImpl(const MachineFunction *MF) = 0;
109  virtual void skippedNonDebugFunction() {}
110 
111  // AsmPrinterHandler overrides.
112 public:
113  void beginInstruction(const MachineInstr *MI) override;
114  void endInstruction() override;
115 
116  void beginFunction(const MachineFunction *MF) override;
117  void endFunction(const MachineFunction *MF) override;
118 
119  /// Return Label preceding the instruction.
120  MCSymbol *getLabelBeforeInsn(const MachineInstr *MI);
121 
122  /// Return Label immediately following the instruction.
123  MCSymbol *getLabelAfterInsn(const MachineInstr *MI);
124 
125  /// Determine the relative position of the fragments described by P1 and P2.
126  /// Returns -1 if P1 is entirely before P2, 0 if P1 and P2 overlap, 1 if P1 is
127  /// entirely after P2.
128  static int fragmentCmp(const DIExpression *P1, const DIExpression *P2);
129 
130  /// Determine whether two variable fragments overlap.
131  static bool fragmentsOverlap(const DIExpression *P1, const DIExpression *P2);
132 
133  /// If this type is derived from a base type then return base type size.
134  static uint64_t getBaseTypeSize(const DITypeRef TyRef);
135 };
136 
137 }
138 
139 #endif
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
Collects and handles AsmPrinter objects required to build debug or EH information.
A debug info location.
Definition: DebugLoc.h:34
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: DenseMap.h:191
DebugLoc PrevInstLoc
Previous instruction&#39;s location information.
DbgValueHistoryMap DbgValues
History of DBG_VALUE and clobber instructions for each user variable.
Holds a subclass of DINode.
DenseMap< const MachineInstr *, MCSymbol * > LabelsAfterInsn
Maps instruction with label emitted after instruction.
void requestLabelBeforeInsn(const MachineInstr *MI)
Ensure that a label will be emitted before MI.
AsmPrinter * Asm
Target of debug info emission.
llvm::Optional< llvm::DIExpression::FragmentInfo > FragmentInfo
Present if the location is part of a larger variable.
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:77
DenseMap< const MachineInstr *, MCSymbol * > LabelsBeforeInsn
Maps instruction with label emitted before instruction.
virtual void skippedNonDebugFunction()
Represents the location at which a variable is stored.
static Optional< DbgVariableLocation > extractFromMachineInstruction(const MachineInstr &Instruction)
Extract a VariableLocation from a MachineInstr.
DWARF expression.
DebugLoc PrologEndLoc
This location indicates end of function prologue and beginning of function body.
void requestLabelAfterInsn(const MachineInstr *MI)
Ensure that a label will be emitted after MI.
Representation of each machine instruction.
Definition: MachineInstr.h:59
LexicalScopes - This class provides interface to collect and use lexical scoping information from mac...
Base class for debug information backends.
SmallVector< int64_t, 1 > LoadChain
Chain of offsetted loads necessary to load the value if it lives in memory.
MachineModuleInfo * MMI
Collected machine module information.
IRTranslator LLVM IR MI
unsigned Register
Base register.
This class contains meta information specific to a module.