LLVM API Documentation

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