1 //===-- DwarfException.h - Dwarf Exception Framework -----------*- C++ -*--===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains support for writing dwarf exception info into asm files.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CODEGEN_ASMPRINTER_DWARFEXCEPTION_H
15 #define LLVM_CODEGEN_ASMPRINTER_DWARFEXCEPTION_H
17 #include "llvm/ADT/DenseMap.h"
18 #include "llvm/CodeGen/AsmPrinter.h"
23 template <typename T> class SmallVectorImpl;
24 struct LandingPadInfo;
25 class MachineModuleInfo;
27 class MachineFunction;
34 //===----------------------------------------------------------------------===//
35 /// DwarfException - Emits Dwarf exception handling directives.
37 class DwarfException {
39 /// Asm - Target of Dwarf emission.
42 /// MMI - Collected machine module information.
43 MachineModuleInfo *MMI;
45 /// SharedTypeIds - How many leading type ids two landing pads have in common.
46 static unsigned SharedTypeIds(const LandingPadInfo *L,
47 const LandingPadInfo *R);
49 /// PadLT - Order landing pads lexicographically by type id.
50 static bool PadLT(const LandingPadInfo *L, const LandingPadInfo *R);
52 /// PadRange - Structure holding a try-range and the associated landing pad.
54 // The index of the landing pad.
56 // The index of the begin and end labels in the landing pad's label lists.
60 typedef DenseMap<MCSymbol *, PadRange> RangeMapType;
62 /// ActionEntry - Structure describing an entry in the actions table.
64 int ValueForTypeID; // The value to write - may not be equal to the type id.
69 /// CallSiteEntry - Structure describing an entry in the call-site table.
70 struct CallSiteEntry {
71 // The 'try-range' is BeginLabel .. EndLabel.
72 MCSymbol *BeginLabel; // zero indicates the start of the function.
73 MCSymbol *EndLabel; // zero indicates the end of the function.
75 // The landing pad starts at PadLabel.
76 MCSymbol *PadLabel; // zero indicates that there is no landing pad.
80 /// ComputeActionsTable - Compute the actions table and gather the first
81 /// action index for each landing pad site.
82 unsigned ComputeActionsTable(const SmallVectorImpl<const LandingPadInfo*>&LPs,
83 SmallVectorImpl<ActionEntry> &Actions,
84 SmallVectorImpl<unsigned> &FirstActions);
86 /// CallToNoUnwindFunction - Return `true' if this is a call to a function
87 /// marked `nounwind'. Return `false' otherwise.
88 bool CallToNoUnwindFunction(const MachineInstr *MI);
90 /// ComputeCallSiteTable - Compute the call-site table. The entry for an
91 /// invoke has a try-range containing the call, a non-zero landing pad and an
92 /// appropriate action. The entry for an ordinary call has a try-range
93 /// containing the call and zero for the landing pad and the action. Calls
94 /// marked 'nounwind' have no entry and must not be contained in the try-range
95 /// of any entry - they form gaps in the table. Entries must be ordered by
96 /// try-range address.
97 void ComputeCallSiteTable(SmallVectorImpl<CallSiteEntry> &CallSites,
98 const RangeMapType &PadMap,
99 const SmallVectorImpl<const LandingPadInfo *> &LPs,
100 const SmallVectorImpl<unsigned> &FirstActions);
102 /// EmitExceptionTable - Emit landing pads and actions.
104 /// The general organization of the table is complex, but the basic concepts
105 /// are easy. First there is a header which describes the location and
106 /// organization of the three components that follow.
107 /// 1. The landing pad site information describes the range of code covered
108 /// by the try. In our case it's an accumulation of the ranges covered
109 /// by the invokes in the try. There is also a reference to the landing
110 /// pad that handles the exception once processed. Finally an index into
111 /// the actions table.
112 /// 2. The action table, in our case, is composed of pairs of type ids
113 /// and next action offset. Starting with the action index from the
114 /// landing pad site, each type Id is checked for a match to the current
115 /// exception. If it matches then the exception and type id are passed
116 /// on to the landing pad. Otherwise the next action is looked up. This
117 /// chain is terminated with a next action of zero. If no type id is
118 /// found the frame is unwound and handling continues.
119 /// 3. Type id table contains references to all the C++ typeinfo for all
120 /// catches in the function. This tables is reversed indexed base 1.
121 void EmitExceptionTable();
123 virtual void EmitTypeInfos(unsigned TTypeEncoding);
126 //===--------------------------------------------------------------------===//
127 // Main entry points.
129 DwarfException(AsmPrinter *A);
130 virtual ~DwarfException();
132 /// EndModule - Emit all exception information that should come after the
134 virtual void EndModule();
136 /// BeginFunction - Gather pre-function exception information. Assumes being
137 /// emitted immediately after the function entry point.
138 virtual void BeginFunction(const MachineFunction *MF);
140 /// EndFunction - Gather and emit post-function exception information.
141 virtual void EndFunction();
144 class DwarfCFIException : public DwarfException {
145 /// shouldEmitPersonality - Per-function flag to indicate if .cfi_personality
146 /// should be emitted.
147 bool shouldEmitPersonality;
149 /// shouldEmitLSDA - Per-function flag to indicate if .cfi_lsda
150 /// should be emitted.
153 /// shouldEmitMoves - Per-function flag to indicate if frame moves info
154 /// should be emitted.
155 bool shouldEmitMoves;
157 AsmPrinter::CFIMoveType moveTypeModule;
160 //===--------------------------------------------------------------------===//
161 // Main entry points.
163 DwarfCFIException(AsmPrinter *A);
164 virtual ~DwarfCFIException();
166 /// EndModule - Emit all exception information that should come after the
168 virtual void EndModule();
170 /// BeginFunction - Gather pre-function exception information. Assumes being
171 /// emitted immediately after the function entry point.
172 virtual void BeginFunction(const MachineFunction *MF);
174 /// EndFunction - Gather and emit post-function exception information.
175 virtual void EndFunction();
178 class ARMException : public DwarfException {
179 void EmitTypeInfos(unsigned TTypeEncoding);
181 //===--------------------------------------------------------------------===//
182 // Main entry points.
184 ARMException(AsmPrinter *A);
185 virtual ~ARMException();
187 /// EndModule - Emit all exception information that should come after the
189 virtual void EndModule();
191 /// BeginFunction - Gather pre-function exception information. Assumes being
192 /// emitted immediately after the function entry point.
193 virtual void BeginFunction(const MachineFunction *MF);
195 /// EndFunction - Gather and emit post-function exception information.
196 virtual void EndFunction();
199 class Win64Exception : public DwarfException {
200 /// shouldEmitPersonality - Per-function flag to indicate if personality
201 /// info should be emitted.
202 bool shouldEmitPersonality;
204 /// shouldEmitLSDA - Per-function flag to indicate if the LSDA
205 /// should be emitted.
208 /// shouldEmitMoves - Per-function flag to indicate if frame moves info
209 /// should be emitted.
210 bool shouldEmitMoves;
213 //===--------------------------------------------------------------------===//
214 // Main entry points.
216 Win64Exception(AsmPrinter *A);
217 virtual ~Win64Exception();
219 /// EndModule - Emit all exception information that should come after the
221 virtual void EndModule();
223 /// BeginFunction - Gather pre-function exception information. Assumes being
224 /// emitted immediately after the function entry point.
225 virtual void BeginFunction(const MachineFunction *MF);
227 /// EndFunction - Gather and emit post-function exception information.
228 virtual void EndFunction();
231 } // End of namespace llvm