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;
28 class MachineFunction;
35 //===----------------------------------------------------------------------===//
36 /// DwarfException - Emits Dwarf exception handling directives.
38 class DwarfException {
40 /// Asm - Target of Dwarf emission.
43 /// MMI - Collected machine module information.
44 MachineModuleInfo *MMI;
46 /// SharedTypeIds - How many leading type ids two landing pads have in common.
47 static unsigned SharedTypeIds(const LandingPadInfo *L,
48 const LandingPadInfo *R);
50 /// PadLT - Order landing pads lexicographically by type id.
51 static bool PadLT(const LandingPadInfo *L, const LandingPadInfo *R);
53 /// PadRange - Structure holding a try-range and the associated landing pad.
55 // The index of the landing pad.
57 // The index of the begin and end labels in the landing pad's label lists.
61 typedef DenseMap<MCSymbol *, PadRange> RangeMapType;
63 /// ActionEntry - Structure describing an entry in the actions table.
65 int ValueForTypeID; // The value to write - may not be equal to the type id.
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.
76 // The landing pad starts at PadLabel.
77 MCSymbol *PadLabel; // zero indicates that there is no landing pad.
81 /// ComputeActionsTable - Compute the actions table and gather the first
82 /// action index for each landing pad site.
83 unsigned ComputeActionsTable(const SmallVectorImpl<const LandingPadInfo*>&LPs,
84 SmallVectorImpl<ActionEntry> &Actions,
85 SmallVectorImpl<unsigned> &FirstActions);
87 /// CallToNoUnwindFunction - Return `true' if this is a call to a function
88 /// marked `nounwind'. Return `false' otherwise.
89 bool CallToNoUnwindFunction(const MachineInstr *MI);
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.
98 void ComputeCallSiteTable(SmallVectorImpl<CallSiteEntry> &CallSites,
99 const RangeMapType &PadMap,
100 const SmallVectorImpl<const LandingPadInfo *> &LPs,
101 const SmallVectorImpl<unsigned> &FirstActions);
103 /// EmitExceptionTable - Emit landing pads and actions.
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();
125 //===--------------------------------------------------------------------===//
126 // Main entry points.
128 DwarfException(AsmPrinter *A);
129 virtual ~DwarfException();
131 /// EndModule - Emit all exception information that should come after the
133 virtual void EndModule();
135 /// BeginFunction - Gather pre-function exception information. Assumes being
136 /// emitted immediately after the function entry point.
137 virtual void BeginFunction(const MachineFunction *MF);
139 /// EndFunction - Gather and emit post-function exception information.
140 virtual void EndFunction();
143 class DwarfCFIException : public DwarfException {
144 /// shouldEmitPersonality - Per-function flag to indicate if .cfi_personality
145 /// should be emitted.
146 bool shouldEmitPersonality;
148 /// shouldEmitLSDA - Per-function flag to indicate if .cfi_lsda
149 /// should be emitted.
152 /// shouldEmitMoves - Per-function flag to indicate if frame moves info
153 /// should be emitted.
154 bool shouldEmitMoves;
156 AsmPrinter::CFIMoveType moveTypeModule;
159 //===--------------------------------------------------------------------===//
160 // Main entry points.
162 DwarfCFIException(AsmPrinter *A);
163 virtual ~DwarfCFIException();
165 /// EndModule - Emit all exception information that should come after the
167 virtual void EndModule();
169 /// BeginFunction - Gather pre-function exception information. Assumes being
170 /// emitted immediately after the function entry point.
171 virtual void BeginFunction(const MachineFunction *MF);
173 /// EndFunction - Gather and emit post-function exception information.
174 virtual void EndFunction();
177 class ARMException : public DwarfException {
179 //===--------------------------------------------------------------------===//
180 // Main entry points.
182 ARMException(AsmPrinter *A);
183 virtual ~ARMException();
185 /// EndModule - Emit all exception information that should come after the
187 virtual void EndModule();
189 /// BeginFunction - Gather pre-function exception information. Assumes being
190 /// emitted immediately after the function entry point.
191 virtual void BeginFunction(const MachineFunction *MF);
193 /// EndFunction - Gather and emit post-function exception information.
194 virtual void EndFunction();
197 class Win64Exception : public DwarfException {
198 /// shouldEmitPersonality - Per-function flag to indicate if personality
199 /// info should be emitted.
200 bool shouldEmitPersonality;
202 /// shouldEmitLSDA - Per-function flag to indicate if the LSDA
203 /// should be emitted.
206 /// shouldEmitMoves - Per-function flag to indicate if frame moves info
207 /// should be emitted.
208 bool shouldEmitMoves;
211 //===--------------------------------------------------------------------===//
212 // Main entry points.
214 Win64Exception(AsmPrinter *A);
215 virtual ~Win64Exception();
217 /// EndModule - Emit all exception information that should come after the
219 virtual void EndModule();
221 /// BeginFunction - Gather pre-function exception information. Assumes being
222 /// emitted immediately after the function entry point.
223 virtual void BeginFunction(const MachineFunction *MF);
225 /// EndFunction - Gather and emit post-function exception information.
226 virtual void EndFunction();
229 } // End of namespace llvm