blob: de5fc90cd3b52465666631a8c8716b649e617386 [file] [log] [blame]
Bill Wendlingeb907212009-05-15 01:12:28 +00001//===-- 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
Chris Lattner6f37f8f2009-07-17 20:32:07 +000014#ifndef LLVM_CODEGEN_ASMPRINTER_DWARFEXCEPTION_H
15#define LLVM_CODEGEN_ASMPRINTER_DWARFEXCEPTION_H
Bill Wendlingeb907212009-05-15 01:12:28 +000016
Bill Wendlingeb907212009-05-15 01:12:28 +000017#include "llvm/ADT/DenseMap.h"
Chris Lattner6d733782010-04-05 05:28:23 +000018#include <vector>
Bill Wendlingeb907212009-05-15 01:12:28 +000019
20namespace llvm {
21
Chris Lattner6d733782010-04-05 05:28:23 +000022template <typename T> class SmallVectorImpl;
Bill Wendlingeb907212009-05-15 01:12:28 +000023struct LandingPadInfo;
24class MachineModuleInfo;
Chris Lattner6d733782010-04-05 05:28:23 +000025class MachineMove;
26class MachineInstr;
27class MachineFunction;
Chris Lattneraf76e592009-08-22 20:48:53 +000028class MCAsmInfo;
Bill Wendling7378b1b2009-11-17 01:23:53 +000029class MCExpr;
Chris Lattner6d733782010-04-05 05:28:23 +000030class MCSymbol;
Chris Lattner6d733782010-04-05 05:28:23 +000031class Function;
32class AsmPrinter;
Bill Wendlingeb907212009-05-15 01:12:28 +000033
34//===----------------------------------------------------------------------===//
35/// DwarfException - Emits Dwarf exception handling directives.
36///
Chris Lattner84ac8b72010-04-05 00:26:50 +000037class DwarfException {
Anton Korobeynikovd7e8ddc2011-01-14 21:57:45 +000038protected:
Chris Lattner84ac8b72010-04-05 00:26:50 +000039 /// Asm - Target of Dwarf emission.
40 AsmPrinter *Asm;
Chris Lattner105d6972010-04-05 05:31:04 +000041
Chris Lattner84ac8b72010-04-05 00:26:50 +000042 /// MMI - Collected machine module information.
43 MachineModuleInfo *MMI;
Chris Lattner84ac8b72010-04-05 00:26:50 +000044
Bill Wendlingeb907212009-05-15 01:12:28 +000045 /// EmitExceptionTable - Emit landing pads and actions.
46 ///
47 /// The general organization of the table is complex, but the basic concepts
48 /// are easy. First there is a header which describes the location and
49 /// organization of the three components that follow.
50 /// 1. The landing pad site information describes the range of code covered
51 /// by the try. In our case it's an accumulation of the ranges covered
52 /// by the invokes in the try. There is also a reference to the landing
53 /// pad that handles the exception once processed. Finally an index into
54 /// the actions table.
55 /// 2. The action table, in our case, is composed of pairs of type ids
56 /// and next action offset. Starting with the action index from the
57 /// landing pad site, each type Id is checked for a match to the current
58 /// exception. If it matches then the exception and type id are passed
59 /// on to the landing pad. Otherwise the next action is looked up. This
60 /// chain is terminated with a next action of zero. If no type id is
Dan Gohmanf451cb82010-02-10 16:03:48 +000061 /// found the frame is unwound and handling continues.
Bill Wendlingeb907212009-05-15 01:12:28 +000062 /// 3. Type id table contains references to all the C++ typeinfo for all
63 /// catches in the function. This tables is reversed indexed base 1.
64
65 /// SharedTypeIds - How many leading type ids two landing pads have in common.
66 static unsigned SharedTypeIds(const LandingPadInfo *L,
67 const LandingPadInfo *R);
68
69 /// PadLT - Order landing pads lexicographically by type id.
70 static bool PadLT(const LandingPadInfo *L, const LandingPadInfo *R);
71
Bill Wendlingeb907212009-05-15 01:12:28 +000072 /// PadRange - Structure holding a try-range and the associated landing pad.
73 struct PadRange {
74 // The index of the landing pad.
75 unsigned PadIndex;
76 // The index of the begin and end labels in the landing pad's label lists.
77 unsigned RangeIndex;
78 };
79
Chris Lattner16112732010-03-14 01:41:15 +000080 typedef DenseMap<MCSymbol *, PadRange> RangeMapType;
Bill Wendlingeb907212009-05-15 01:12:28 +000081
Bill Wendling5e953dd2009-07-28 23:22:13 +000082 /// ActionEntry - Structure describing an entry in the actions table.
83 struct ActionEntry {
84 int ValueForTypeID; // The value to write - may not be equal to the type id.
85 int NextAction;
Bill Wendling0a9abcb2010-02-10 21:41:57 +000086 unsigned Previous;
Bill Wendling5e953dd2009-07-28 23:22:13 +000087 };
88
Bill Wendlingeb907212009-05-15 01:12:28 +000089 /// CallSiteEntry - Structure describing an entry in the call-site table.
90 struct CallSiteEntry {
91 // The 'try-range' is BeginLabel .. EndLabel.
Chris Lattner16112732010-03-14 01:41:15 +000092 MCSymbol *BeginLabel; // zero indicates the start of the function.
93 MCSymbol *EndLabel; // zero indicates the end of the function.
Bill Wendling5e953dd2009-07-28 23:22:13 +000094
Bill Wendlingeb907212009-05-15 01:12:28 +000095 // The landing pad starts at PadLabel.
Chris Lattner16112732010-03-14 01:41:15 +000096 MCSymbol *PadLabel; // zero indicates that there is no landing pad.
Bill Wendlingeb907212009-05-15 01:12:28 +000097 unsigned Action;
98 };
99
Bill Wendlingd4609622009-07-28 23:23:00 +0000100 /// ComputeActionsTable - Compute the actions table and gather the first
101 /// action index for each landing pad site.
Bill Wendlingade025c2009-07-29 00:31:35 +0000102 unsigned ComputeActionsTable(const SmallVectorImpl<const LandingPadInfo*>&LPs,
Bill Wendling5e953dd2009-07-28 23:22:13 +0000103 SmallVectorImpl<ActionEntry> &Actions,
104 SmallVectorImpl<unsigned> &FirstActions);
Bill Wendlingade025c2009-07-29 00:31:35 +0000105
Bill Wendlinged060dc2009-11-12 21:59:20 +0000106 /// CallToNoUnwindFunction - Return `true' if this is a call to a function
107 /// marked `nounwind'. Return `false' otherwise.
108 bool CallToNoUnwindFunction(const MachineInstr *MI);
109
Bill Wendlingade025c2009-07-29 00:31:35 +0000110 /// ComputeCallSiteTable - Compute the call-site table. The entry for an
111 /// invoke has a try-range containing the call, a non-zero landing pad and an
112 /// appropriate action. The entry for an ordinary call has a try-range
113 /// containing the call and zero for the landing pad and the action. Calls
114 /// marked 'nounwind' have no entry and must not be contained in the try-range
115 /// of any entry - they form gaps in the table. Entries must be ordered by
116 /// try-range address.
117 void ComputeCallSiteTable(SmallVectorImpl<CallSiteEntry> &CallSites,
118 const RangeMapType &PadMap,
119 const SmallVectorImpl<const LandingPadInfo *> &LPs,
120 const SmallVectorImpl<unsigned> &FirstActions);
Bill Wendlingeb907212009-05-15 01:12:28 +0000121 void EmitExceptionTable();
122
123public:
124 //===--------------------------------------------------------------------===//
125 // Main entry points.
126 //
Chris Lattner75f50722010-04-04 07:48:20 +0000127 DwarfException(AsmPrinter *A);
Anton Korobeynikovd7e8ddc2011-01-14 21:57:45 +0000128 virtual ~DwarfException();
Bill Wendlingeb907212009-05-15 01:12:28 +0000129
Bill Wendlingeb907212009-05-15 01:12:28 +0000130 /// EndModule - Emit all exception information that should come after the
131 /// content.
Anton Korobeynikovd7e8ddc2011-01-14 21:57:45 +0000132 virtual void EndModule();
Bill Wendlingeb907212009-05-15 01:12:28 +0000133
134 /// BeginFunction - Gather pre-function exception information. Assumes being
135 /// emitted immediately after the function entry point.
Anton Korobeynikovd7e8ddc2011-01-14 21:57:45 +0000136 virtual void BeginFunction(const MachineFunction *MF);
Bill Wendlingeb907212009-05-15 01:12:28 +0000137
138 /// EndFunction - Gather and emit post-function exception information.
Anton Korobeynikovd7e8ddc2011-01-14 21:57:45 +0000139 virtual void EndFunction();
140};
141
Anton Korobeynikov9a1ef4e2011-01-14 21:57:53 +0000142class DwarfCFIException : public DwarfException {
Rafael Espindola7b11a4c2011-04-29 14:48:51 +0000143 /// shouldEmitPersonality - Per-function flag to indicate if .cfi_personality
144 /// should be emitted.
145 bool shouldEmitPersonality;
146
147 /// shouldEmitLSDA - Per-function flag to indicate if .cfi_lsda
148 /// should be emitted.
149 bool shouldEmitLSDA;
Anton Korobeynikov9a1ef4e2011-01-14 21:57:53 +0000150
151 /// shouldEmitMoves - Per-function flag to indicate if frame moves info
152 /// should be emitted.
153 bool shouldEmitMoves;
154
Anton Korobeynikov9a1ef4e2011-01-14 21:57:53 +0000155public:
156 //===--------------------------------------------------------------------===//
157 // Main entry points.
158 //
159 DwarfCFIException(AsmPrinter *A);
160 virtual ~DwarfCFIException();
161
162 /// EndModule - Emit all exception information that should come after the
163 /// content.
164 virtual void EndModule();
165
166 /// BeginFunction - Gather pre-function exception information. Assumes being
167 /// emitted immediately after the function entry point.
168 virtual void BeginFunction(const MachineFunction *MF);
169
170 /// EndFunction - Gather and emit post-function exception information.
171 virtual void EndFunction();
172};
173
Rafael Espindolaecf58b92011-05-05 20:48:31 +0000174class DwarfSjLjException : public DwarfException {
175public:
176 //===--------------------------------------------------------------------===//
177 // Main entry points.
178 //
179 DwarfSjLjException(AsmPrinter *A);
180 virtual ~DwarfSjLjException();
181
182 /// EndModule - Emit all exception information that should come after the
183 /// content.
184 virtual void EndModule();
185
186 /// BeginFunction - Gather pre-function exception information. Assumes being
187 /// emitted immediately after the function entry point.
188 virtual void BeginFunction(const MachineFunction *MF);
189
190 /// EndFunction - Gather and emit post-function exception information.
191 virtual void EndFunction();
192};
Anton Korobeynikovb5e16af2011-03-05 18:43:15 +0000193
194class ARMException : public DwarfException {
195 /// shouldEmitTable - Per-function flag to indicate if EH tables should
196 /// be emitted.
197 bool shouldEmitTable;
198
199 /// shouldEmitMoves - Per-function flag to indicate if frame moves info
200 /// should be emitted.
201 bool shouldEmitMoves;
202
203 /// shouldEmitTableModule - Per-module flag to indicate if EH tables
204 /// should be emitted.
205 bool shouldEmitTableModule;
206public:
207 //===--------------------------------------------------------------------===//
208 // Main entry points.
209 //
210 ARMException(AsmPrinter *A);
211 virtual ~ARMException();
212
213 /// EndModule - Emit all exception information that should come after the
214 /// content.
215 virtual void EndModule();
216
217 /// BeginFunction - Gather pre-function exception information. Assumes being
218 /// emitted immediately after the function entry point.
219 virtual void BeginFunction(const MachineFunction *MF);
220
221 /// EndFunction - Gather and emit post-function exception information.
222 virtual void EndFunction();
223};
224
Bill Wendlingeb907212009-05-15 01:12:28 +0000225} // End of namespace llvm
226
227#endif