DebugInfo: Fix and test a regression caused by r207263 causing the DW_AT_object_point...
[oota-llvm.git] / lib / CodeGen / AsmPrinter / DwarfException.h
1 //===-- DwarfException.h - Dwarf Exception Framework -----------*- 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 // This file contains support for writing dwarf exception info into asm files.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_CODEGEN_ASMPRINTER_DWARFEXCEPTION_H
15 #define LLVM_CODEGEN_ASMPRINTER_DWARFEXCEPTION_H
16
17 #include "AsmPrinterHandler.h"
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/CodeGen/AsmPrinter.h"
20 #include <vector>
21
22 namespace llvm {
23
24 template <typename T> class SmallVectorImpl;
25 struct LandingPadInfo;
26 class MachineModuleInfo;
27 class MachineInstr;
28 class MachineFunction;
29 class MCAsmInfo;
30 class MCExpr;
31 class MCSymbol;
32 class Function;
33 class ARMTargetStreamer;
34 class AsmPrinter;
35
36 //===----------------------------------------------------------------------===//
37 /// DwarfException - Emits Dwarf exception handling directives.
38 ///
39 class DwarfException : public AsmPrinterHandler {
40 protected:
41   /// Asm - Target of Dwarf emission.
42   AsmPrinter *Asm;
43
44   /// MMI - Collected machine module information.
45   MachineModuleInfo *MMI;
46
47   /// SharedTypeIds - How many leading type ids two landing pads have in common.
48   static unsigned SharedTypeIds(const LandingPadInfo *L,
49                                 const LandingPadInfo *R);
50
51   /// PadRange - Structure holding a try-range and the associated landing pad.
52   struct PadRange {
53     // The index of the landing pad.
54     unsigned PadIndex;
55     // The index of the begin and end labels in the landing pad's label lists.
56     unsigned RangeIndex;
57   };
58
59   typedef DenseMap<MCSymbol *, PadRange> RangeMapType;
60
61   /// ActionEntry - Structure describing an entry in the actions table.
62   struct ActionEntry {
63     int ValueForTypeID; // The value to write - may not be equal to the type id.
64     int NextAction;
65     unsigned Previous;
66   };
67
68   /// CallSiteEntry - Structure describing an entry in the call-site table.
69   struct CallSiteEntry {
70     // The 'try-range' is BeginLabel .. EndLabel.
71     MCSymbol *BeginLabel; // zero indicates the start of the function.
72     MCSymbol *EndLabel;   // zero indicates the end of the function.
73
74     // The landing pad starts at PadLabel.
75     MCSymbol *PadLabel;   // zero indicates that there is no landing pad.
76     unsigned Action;
77   };
78
79   /// ComputeActionsTable - Compute the actions table and gather the first
80   /// action index for each landing pad site.
81   unsigned ComputeActionsTable(const SmallVectorImpl<const LandingPadInfo*>&LPs,
82                                SmallVectorImpl<ActionEntry> &Actions,
83                                SmallVectorImpl<unsigned> &FirstActions);
84
85   /// CallToNoUnwindFunction - Return `true' if this is a call to a function
86   /// marked `nounwind'. Return `false' otherwise.
87   bool CallToNoUnwindFunction(const MachineInstr *MI);
88
89   /// ComputeCallSiteTable - Compute the call-site table.  The entry for an
90   /// invoke has a try-range containing the call, a non-zero landing pad and an
91   /// appropriate action.  The entry for an ordinary call has a try-range
92   /// containing the call and zero for the landing pad and the action.  Calls
93   /// marked 'nounwind' have no entry and must not be contained in the try-range
94   /// of any entry - they form gaps in the table.  Entries must be ordered by
95   /// try-range address.
96   void ComputeCallSiteTable(SmallVectorImpl<CallSiteEntry> &CallSites,
97                             const RangeMapType &PadMap,
98                             const SmallVectorImpl<const LandingPadInfo *> &LPs,
99                             const SmallVectorImpl<unsigned> &FirstActions);
100
101   /// EmitExceptionTable - Emit landing pads and actions.
102   ///
103   /// The general organization of the table is complex, but the basic concepts
104   /// are easy.  First there is a header which describes the location and
105   /// organization of the three components that follow.
106   ///  1. The landing pad site information describes the range of code covered
107   ///     by the try.  In our case it's an accumulation of the ranges covered
108   ///     by the invokes in the try.  There is also a reference to the landing
109   ///     pad that handles the exception once processed.  Finally an index into
110   ///     the actions table.
111   ///  2. The action table, in our case, is composed of pairs of type ids
112   ///     and next action offset.  Starting with the action index from the
113   ///     landing pad site, each type Id is checked for a match to the current
114   ///     exception.  If it matches then the exception and type id are passed
115   ///     on to the landing pad.  Otherwise the next action is looked up.  This
116   ///     chain is terminated with a next action of zero.  If no type id is
117   ///     found the frame is unwound and handling continues.
118   ///  3. Type id table contains references to all the C++ typeinfo for all
119   ///     catches in the function.  This tables is reversed indexed base 1.
120   void EmitExceptionTable();
121
122   virtual void EmitTypeInfos(unsigned TTypeEncoding);
123
124 public:
125   //===--------------------------------------------------------------------===//
126   // Main entry points.
127   //
128   DwarfException(AsmPrinter *A);
129   virtual ~DwarfException();
130
131   /// endModule - Emit all exception information that should come after the
132   /// content.
133   void endModule() override;
134
135   /// beginFunction - Gather pre-function exception information.  Assumes being
136   /// emitted immediately after the function entry point.
137   void beginFunction(const MachineFunction *MF) override;
138
139   /// endFunction - Gather and emit post-function exception information.
140   void endFunction(const MachineFunction *) override;
141
142   // We don't need these.
143   void setSymbolSize(const MCSymbol *Sym, uint64_t Size) override {}
144   void beginInstruction(const MachineInstr *MI) override {}
145   void endInstruction() override {}
146 };
147
148 class DwarfCFIException : public DwarfException {
149   /// shouldEmitPersonality - Per-function flag to indicate if .cfi_personality
150   /// should be emitted.
151   bool shouldEmitPersonality;
152
153   /// shouldEmitLSDA - Per-function flag to indicate if .cfi_lsda
154   /// should be emitted.
155   bool shouldEmitLSDA;
156
157   /// shouldEmitMoves - Per-function flag to indicate if frame moves info
158   /// should be emitted.
159   bool shouldEmitMoves;
160
161   AsmPrinter::CFIMoveType moveTypeModule;
162
163 public:
164   //===--------------------------------------------------------------------===//
165   // Main entry points.
166   //
167   DwarfCFIException(AsmPrinter *A);
168   virtual ~DwarfCFIException();
169
170   /// endModule - Emit all exception information that should come after the
171   /// content.
172   void endModule() override;
173
174   /// beginFunction - Gather pre-function exception information.  Assumes being
175   /// emitted immediately after the function entry point.
176   void beginFunction(const MachineFunction *MF) override;
177
178   /// endFunction - Gather and emit post-function exception information.
179   void endFunction(const MachineFunction *) override;
180 };
181
182 class ARMException : public DwarfException {
183   void EmitTypeInfos(unsigned TTypeEncoding) override;
184   ARMTargetStreamer &getTargetStreamer();
185
186   /// shouldEmitCFI - Per-function flag to indicate if frame CFI info
187   /// should be emitted.
188   bool shouldEmitCFI;
189
190 public:
191   //===--------------------------------------------------------------------===//
192   // Main entry points.
193   //
194   ARMException(AsmPrinter *A);
195   virtual ~ARMException();
196
197   /// endModule - Emit all exception information that should come after the
198   /// content.
199   void endModule() override;
200
201   /// beginFunction - Gather pre-function exception information.  Assumes being
202   /// emitted immediately after the function entry point.
203   void beginFunction(const MachineFunction *MF) override;
204
205   /// endFunction - Gather and emit post-function exception information.
206   void endFunction(const MachineFunction *) override;
207 };
208
209 class Win64Exception : public DwarfException {
210   /// shouldEmitPersonality - Per-function flag to indicate if personality
211   /// info should be emitted.
212   bool shouldEmitPersonality;
213
214   /// shouldEmitLSDA - Per-function flag to indicate if the LSDA
215   /// should be emitted.
216   bool shouldEmitLSDA;
217
218   /// shouldEmitMoves - Per-function flag to indicate if frame moves info
219   /// should be emitted.
220   bool shouldEmitMoves;
221
222 public:
223   //===--------------------------------------------------------------------===//
224   // Main entry points.
225   //
226   Win64Exception(AsmPrinter *A);
227   virtual ~Win64Exception();
228
229   /// endModule - Emit all exception information that should come after the
230   /// content.
231   void endModule() override;
232
233   /// beginFunction - Gather pre-function exception information.  Assumes being
234   /// emitted immediately after the function entry point.
235   void beginFunction(const MachineFunction *MF) override;
236
237   /// endFunction - Gather and emit post-function exception information.
238   void endFunction(const MachineFunction *) override;
239 };
240
241 } // End of namespace llvm
242
243 #endif