blob: 49a85d81b4e2793aef16bbeab83bea13c5ae48df [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"
Rafael Espindolae29887b2011-05-10 18:39:09 +000018#include "llvm/CodeGen/AsmPrinter.h"
Chris Lattner6d733782010-04-05 05:28:23 +000019#include <vector>
Bill Wendlingeb907212009-05-15 01:12:28 +000020
21namespace llvm {
22
Chris Lattner6d733782010-04-05 05:28:23 +000023template <typename T> class SmallVectorImpl;
Bill Wendlingeb907212009-05-15 01:12:28 +000024struct LandingPadInfo;
25class MachineModuleInfo;
Chris Lattner6d733782010-04-05 05:28:23 +000026class 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 /// SharedTypeIds - How many leading type ids two landing pads have in common.
46 static unsigned SharedTypeIds(const LandingPadInfo *L,
47 const LandingPadInfo *R);
48
49 /// PadLT - Order landing pads lexicographically by type id.
50 static bool PadLT(const LandingPadInfo *L, const LandingPadInfo *R);
51
Bill Wendlingeb907212009-05-15 01:12:28 +000052 /// PadRange - Structure holding a try-range and the associated landing pad.
53 struct PadRange {
54 // The index of the landing pad.
55 unsigned PadIndex;
56 // The index of the begin and end labels in the landing pad's label lists.
57 unsigned RangeIndex;
58 };
59
Chris Lattner16112732010-03-14 01:41:15 +000060 typedef DenseMap<MCSymbol *, PadRange> RangeMapType;
Bill Wendlingeb907212009-05-15 01:12:28 +000061
Bill Wendling5e953dd2009-07-28 23:22:13 +000062 /// ActionEntry - Structure describing an entry in the actions table.
63 struct ActionEntry {
64 int ValueForTypeID; // The value to write - may not be equal to the type id.
65 int NextAction;
Bill Wendling0a9abcb2010-02-10 21:41:57 +000066 unsigned Previous;
Bill Wendling5e953dd2009-07-28 23:22:13 +000067 };
68
Bill Wendlingeb907212009-05-15 01:12:28 +000069 /// CallSiteEntry - Structure describing an entry in the call-site table.
70 struct CallSiteEntry {
71 // The 'try-range' is BeginLabel .. EndLabel.
Chris Lattner16112732010-03-14 01:41:15 +000072 MCSymbol *BeginLabel; // zero indicates the start of the function.
73 MCSymbol *EndLabel; // zero indicates the end of the function.
Bill Wendling5e953dd2009-07-28 23:22:13 +000074
Bill Wendlingeb907212009-05-15 01:12:28 +000075 // The landing pad starts at PadLabel.
Chris Lattner16112732010-03-14 01:41:15 +000076 MCSymbol *PadLabel; // zero indicates that there is no landing pad.
Bill Wendlingeb907212009-05-15 01:12:28 +000077 unsigned Action;
78 };
79
Bill Wendlingd4609622009-07-28 23:23:00 +000080 /// ComputeActionsTable - Compute the actions table and gather the first
81 /// action index for each landing pad site.
Bill Wendlingade025c2009-07-29 00:31:35 +000082 unsigned ComputeActionsTable(const SmallVectorImpl<const LandingPadInfo*>&LPs,
Bill Wendling5e953dd2009-07-28 23:22:13 +000083 SmallVectorImpl<ActionEntry> &Actions,
84 SmallVectorImpl<unsigned> &FirstActions);
Bill Wendlingade025c2009-07-29 00:31:35 +000085
Bill Wendlinged060dc2009-11-12 21:59:20 +000086 /// CallToNoUnwindFunction - Return `true' if this is a call to a function
87 /// marked `nounwind'. Return `false' otherwise.
88 bool CallToNoUnwindFunction(const MachineInstr *MI);
89
Bill Wendlingade025c2009-07-29 00:31:35 +000090 /// 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);
Logan Chienec90cc82012-09-05 06:28:26 +0000101
102 /// EmitExceptionTable - Emit landing pads and actions.
103 ///
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.
Bill Wendlingeb907212009-05-15 01:12:28 +0000121 void EmitExceptionTable();
122
Anton Korobeynikov2386fc82012-11-19 21:06:26 +0000123 virtual void EmitTypeInfos(unsigned TTypeEncoding);
124
Bill Wendlingeb907212009-05-15 01:12:28 +0000125public:
126 //===--------------------------------------------------------------------===//
127 // Main entry points.
128 //
Chris Lattner75f50722010-04-04 07:48:20 +0000129 DwarfException(AsmPrinter *A);
Anton Korobeynikovd7e8ddc2011-01-14 21:57:45 +0000130 virtual ~DwarfException();
Bill Wendlingeb907212009-05-15 01:12:28 +0000131
Bill Wendlingeb907212009-05-15 01:12:28 +0000132 /// EndModule - Emit all exception information that should come after the
133 /// content.
Anton Korobeynikovd7e8ddc2011-01-14 21:57:45 +0000134 virtual void EndModule();
Bill Wendlingeb907212009-05-15 01:12:28 +0000135
136 /// BeginFunction - Gather pre-function exception information. Assumes being
137 /// emitted immediately after the function entry point.
Anton Korobeynikovd7e8ddc2011-01-14 21:57:45 +0000138 virtual void BeginFunction(const MachineFunction *MF);
Bill Wendlingeb907212009-05-15 01:12:28 +0000139
140 /// EndFunction - Gather and emit post-function exception information.
Anton Korobeynikovd7e8ddc2011-01-14 21:57:45 +0000141 virtual void EndFunction();
142};
143
Anton Korobeynikov9a1ef4e2011-01-14 21:57:53 +0000144class DwarfCFIException : public DwarfException {
Rafael Espindola7b11a4c2011-04-29 14:48:51 +0000145 /// shouldEmitPersonality - Per-function flag to indicate if .cfi_personality
146 /// should be emitted.
147 bool shouldEmitPersonality;
148
149 /// shouldEmitLSDA - Per-function flag to indicate if .cfi_lsda
150 /// should be emitted.
151 bool shouldEmitLSDA;
Anton Korobeynikov9a1ef4e2011-01-14 21:57:53 +0000152
153 /// shouldEmitMoves - Per-function flag to indicate if frame moves info
154 /// should be emitted.
155 bool shouldEmitMoves;
156
Rafael Espindolae29887b2011-05-10 18:39:09 +0000157 AsmPrinter::CFIMoveType moveTypeModule;
158
Anton Korobeynikov9a1ef4e2011-01-14 21:57:53 +0000159public:
160 //===--------------------------------------------------------------------===//
161 // Main entry points.
162 //
163 DwarfCFIException(AsmPrinter *A);
164 virtual ~DwarfCFIException();
165
166 /// EndModule - Emit all exception information that should come after the
167 /// content.
168 virtual void EndModule();
169
170 /// BeginFunction - Gather pre-function exception information. Assumes being
171 /// emitted immediately after the function entry point.
172 virtual void BeginFunction(const MachineFunction *MF);
173
174 /// EndFunction - Gather and emit post-function exception information.
175 virtual void EndFunction();
176};
177
Anton Korobeynikovb5e16af2011-03-05 18:43:15 +0000178class ARMException : public DwarfException {
Anton Korobeynikov2386fc82012-11-19 21:06:26 +0000179 void EmitTypeInfos(unsigned TTypeEncoding);
Anton Korobeynikovb5e16af2011-03-05 18:43:15 +0000180public:
181 //===--------------------------------------------------------------------===//
182 // Main entry points.
183 //
184 ARMException(AsmPrinter *A);
185 virtual ~ARMException();
186
187 /// EndModule - Emit all exception information that should come after the
188 /// content.
189 virtual void EndModule();
190
191 /// BeginFunction - Gather pre-function exception information. Assumes being
192 /// emitted immediately after the function entry point.
193 virtual void BeginFunction(const MachineFunction *MF);
194
195 /// EndFunction - Gather and emit post-function exception information.
196 virtual void EndFunction();
197};
198
Charles Davisd652b132011-05-27 23:47:32 +0000199class Win64Exception : public DwarfException {
200 /// shouldEmitPersonality - Per-function flag to indicate if personality
201 /// info should be emitted.
202 bool shouldEmitPersonality;
203
204 /// shouldEmitLSDA - Per-function flag to indicate if the LSDA
205 /// should be emitted.
206 bool shouldEmitLSDA;
207
208 /// shouldEmitMoves - Per-function flag to indicate if frame moves info
209 /// should be emitted.
210 bool shouldEmitMoves;
211
212public:
213 //===--------------------------------------------------------------------===//
214 // Main entry points.
215 //
216 Win64Exception(AsmPrinter *A);
217 virtual ~Win64Exception();
218
219 /// EndModule - Emit all exception information that should come after the
220 /// content.
221 virtual void EndModule();
222
223 /// BeginFunction - Gather pre-function exception information. Assumes being
224 /// emitted immediately after the function entry point.
225 virtual void BeginFunction(const MachineFunction *MF);
226
227 /// EndFunction - Gather and emit post-function exception information.
228 virtual void EndFunction();
229};
230
Bill Wendlingeb907212009-05-15 01:12:28 +0000231} // End of namespace llvm
232
233#endif