blob: 74b1b13367a21a714f57bfff9364f506f8702318 [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 MachineMove;
27class MachineInstr;
28class MachineFunction;
Chris Lattneraf76e592009-08-22 20:48:53 +000029class MCAsmInfo;
Bill Wendling7378b1b2009-11-17 01:23:53 +000030class MCExpr;
Chris Lattner6d733782010-04-05 05:28:23 +000031class MCSymbol;
Chris Lattner6d733782010-04-05 05:28:23 +000032class Function;
33class AsmPrinter;
Bill Wendlingeb907212009-05-15 01:12:28 +000034
35//===----------------------------------------------------------------------===//
36/// DwarfException - Emits Dwarf exception handling directives.
37///
Chris Lattner84ac8b72010-04-05 00:26:50 +000038class DwarfException {
Anton Korobeynikovd7e8ddc2011-01-14 21:57:45 +000039protected:
Chris Lattner84ac8b72010-04-05 00:26:50 +000040 /// Asm - Target of Dwarf emission.
41 AsmPrinter *Asm;
Chris Lattner105d6972010-04-05 05:31:04 +000042
Chris Lattner84ac8b72010-04-05 00:26:50 +000043 /// MMI - Collected machine module information.
44 MachineModuleInfo *MMI;
Chris Lattner84ac8b72010-04-05 00:26:50 +000045
Bill Wendlingeb907212009-05-15 01:12:28 +000046 /// 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
Bill Wendlingeb907212009-05-15 01:12:28 +000053 /// 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
Chris Lattner16112732010-03-14 01:41:15 +000061 typedef DenseMap<MCSymbol *, PadRange> RangeMapType;
Bill Wendlingeb907212009-05-15 01:12:28 +000062
Bill Wendling5e953dd2009-07-28 23:22:13 +000063 /// 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.
66 int NextAction;
Bill Wendling0a9abcb2010-02-10 21:41:57 +000067 unsigned Previous;
Bill Wendling5e953dd2009-07-28 23:22:13 +000068 };
69
Bill Wendlingeb907212009-05-15 01:12:28 +000070 /// CallSiteEntry - Structure describing an entry in the call-site table.
71 struct CallSiteEntry {
72 // The 'try-range' is BeginLabel .. EndLabel.
Chris Lattner16112732010-03-14 01:41:15 +000073 MCSymbol *BeginLabel; // zero indicates the start of the function.
74 MCSymbol *EndLabel; // zero indicates the end of the function.
Bill Wendling5e953dd2009-07-28 23:22:13 +000075
Bill Wendlingeb907212009-05-15 01:12:28 +000076 // The landing pad starts at PadLabel.
Chris Lattner16112732010-03-14 01:41:15 +000077 MCSymbol *PadLabel; // zero indicates that there is no landing pad.
Bill Wendlingeb907212009-05-15 01:12:28 +000078 unsigned Action;
79 };
80
Bill Wendlingd4609622009-07-28 23:23:00 +000081 /// ComputeActionsTable - Compute the actions table and gather the first
82 /// action index for each landing pad site.
Bill Wendlingade025c2009-07-29 00:31:35 +000083 unsigned ComputeActionsTable(const SmallVectorImpl<const LandingPadInfo*>&LPs,
Bill Wendling5e953dd2009-07-28 23:22:13 +000084 SmallVectorImpl<ActionEntry> &Actions,
85 SmallVectorImpl<unsigned> &FirstActions);
Bill Wendlingade025c2009-07-29 00:31:35 +000086
Bill Wendlinged060dc2009-11-12 21:59:20 +000087 /// CallToNoUnwindFunction - Return `true' if this is a call to a function
88 /// marked `nounwind'. Return `false' otherwise.
89 bool CallToNoUnwindFunction(const MachineInstr *MI);
90
Bill Wendlingade025c2009-07-29 00:31:35 +000091 /// 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);
Logan Chienec90cc82012-09-05 06:28:26 +0000102
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.
Bill Wendlingeb907212009-05-15 01:12:28 +0000122 void EmitExceptionTable();
123
Anton Korobeynikov2386fc82012-11-19 21:06:26 +0000124 virtual void EmitTypeInfos(unsigned TTypeEncoding);
125
Bill Wendlingeb907212009-05-15 01:12:28 +0000126public:
127 //===--------------------------------------------------------------------===//
128 // Main entry points.
129 //
Chris Lattner75f50722010-04-04 07:48:20 +0000130 DwarfException(AsmPrinter *A);
Anton Korobeynikovd7e8ddc2011-01-14 21:57:45 +0000131 virtual ~DwarfException();
Bill Wendlingeb907212009-05-15 01:12:28 +0000132
Bill Wendlingeb907212009-05-15 01:12:28 +0000133 /// EndModule - Emit all exception information that should come after the
134 /// content.
Anton Korobeynikovd7e8ddc2011-01-14 21:57:45 +0000135 virtual void EndModule();
Bill Wendlingeb907212009-05-15 01:12:28 +0000136
137 /// BeginFunction - Gather pre-function exception information. Assumes being
138 /// emitted immediately after the function entry point.
Anton Korobeynikovd7e8ddc2011-01-14 21:57:45 +0000139 virtual void BeginFunction(const MachineFunction *MF);
Bill Wendlingeb907212009-05-15 01:12:28 +0000140
141 /// EndFunction - Gather and emit post-function exception information.
Anton Korobeynikovd7e8ddc2011-01-14 21:57:45 +0000142 virtual void EndFunction();
143};
144
Anton Korobeynikov9a1ef4e2011-01-14 21:57:53 +0000145class DwarfCFIException : public DwarfException {
Rafael Espindola7b11a4c2011-04-29 14:48:51 +0000146 /// 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;
Anton Korobeynikov9a1ef4e2011-01-14 21:57:53 +0000153
154 /// shouldEmitMoves - Per-function flag to indicate if frame moves info
155 /// should be emitted.
156 bool shouldEmitMoves;
157
Rafael Espindolae29887b2011-05-10 18:39:09 +0000158 AsmPrinter::CFIMoveType moveTypeModule;
159
Anton Korobeynikov9a1ef4e2011-01-14 21:57:53 +0000160public:
161 //===--------------------------------------------------------------------===//
162 // Main entry points.
163 //
164 DwarfCFIException(AsmPrinter *A);
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
Anton Korobeynikovb5e16af2011-03-05 18:43:15 +0000179class ARMException : public DwarfException {
Anton Korobeynikov2386fc82012-11-19 21:06:26 +0000180 void EmitTypeInfos(unsigned TTypeEncoding);
Anton Korobeynikovb5e16af2011-03-05 18:43:15 +0000181public:
182 //===--------------------------------------------------------------------===//
183 // Main entry points.
184 //
185 ARMException(AsmPrinter *A);
186 virtual ~ARMException();
187
188 /// EndModule - Emit all exception information that should come after the
189 /// content.
190 virtual void EndModule();
191
192 /// BeginFunction - Gather pre-function exception information. Assumes being
193 /// emitted immediately after the function entry point.
194 virtual void BeginFunction(const MachineFunction *MF);
195
196 /// EndFunction - Gather and emit post-function exception information.
197 virtual void EndFunction();
198};
199
Charles Davisd652b132011-05-27 23:47:32 +0000200class Win64Exception : public DwarfException {
201 /// shouldEmitPersonality - Per-function flag to indicate if personality
202 /// info should be emitted.
203 bool shouldEmitPersonality;
204
205 /// shouldEmitLSDA - Per-function flag to indicate if the LSDA
206 /// should be emitted.
207 bool shouldEmitLSDA;
208
209 /// shouldEmitMoves - Per-function flag to indicate if frame moves info
210 /// should be emitted.
211 bool shouldEmitMoves;
212
213public:
214 //===--------------------------------------------------------------------===//
215 // Main entry points.
216 //
217 Win64Exception(AsmPrinter *A);
218 virtual ~Win64Exception();
219
220 /// EndModule - Emit all exception information that should come after the
221 /// content.
222 virtual void EndModule();
223
224 /// BeginFunction - Gather pre-function exception information. Assumes being
225 /// emitted immediately after the function entry point.
226 virtual void BeginFunction(const MachineFunction *MF);
227
228 /// EndFunction - Gather and emit post-function exception information.
229 virtual void EndFunction();
230};
231
Bill Wendlingeb907212009-05-15 01:12:28 +0000232} // End of namespace llvm
233
234#endif