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
18 #include "DwarfPrinter.h"
19 #include "llvm/CodeGen/AsmPrinter.h"
20 #include "llvm/ADT/DenseMap.h"
25 struct LandingPadInfo
;
26 class MachineModuleInfo
;
31 //===----------------------------------------------------------------------===//
32 /// DwarfException - Emits Dwarf exception handling directives.
34 class VISIBILITY_HIDDEN DwarfException
: public Dwarf
{
35 struct FunctionEHFrameInfo
{
38 unsigned PersonalityIndex
;
41 std::vector
<MachineMove
> Moves
;
42 const Function
* function
;
44 FunctionEHFrameInfo(const std::string
&FN
, unsigned Num
, unsigned P
,
46 const std::vector
<MachineMove
> &M
,
48 FnName(FN
), Number(Num
), PersonalityIndex(P
),
49 hasCalls(hC
), hasLandingPads(hL
), Moves(M
), function (f
) { }
52 std::vector
<FunctionEHFrameInfo
> EHFrames
;
54 /// shouldEmitTable - Per-function flag to indicate if EH tables should
58 /// shouldEmitMoves - Per-function flag to indicate if frame moves info
59 /// should be emitted.
62 /// shouldEmitTableModule - Per-module flag to indicate if EH tables
63 /// should be emitted.
64 bool shouldEmitTableModule
;
66 /// shouldEmitFrameModule - Per-module flag to indicate if frame moves
67 /// should be emitted.
68 bool shouldEmitMovesModule
;
70 /// ExceptionTimer - Timer for the Dwarf exception writer.
71 Timer
*ExceptionTimer
;
73 /// EmitCIE - Emit a Common Information Entry (CIE). This holds information
74 /// that is shared among many Frame Description Entries. There is at least
75 /// one CIE in every non-empty .debug_frame section.
76 void EmitCIE(const Function
*Personality
, unsigned Index
);
78 /// EmitFDE - Emit the Frame Description Entry (FDE) for the function.
79 void EmitFDE(const FunctionEHFrameInfo
&EHFrameInfo
);
81 /// EmitExceptionTable - Emit landing pads and actions.
83 /// The general organization of the table is complex, but the basic concepts
84 /// are easy. First there is a header which describes the location and
85 /// organization of the three components that follow.
86 /// 1. The landing pad site information describes the range of code covered
87 /// by the try. In our case it's an accumulation of the ranges covered
88 /// by the invokes in the try. There is also a reference to the landing
89 /// pad that handles the exception once processed. Finally an index into
90 /// the actions table.
91 /// 2. The action table, in our case, is composed of pairs of type ids
92 /// and next action offset. Starting with the action index from the
93 /// landing pad site, each type Id is checked for a match to the current
94 /// exception. If it matches then the exception and type id are passed
95 /// on to the landing pad. Otherwise the next action is looked up. This
96 /// chain is terminated with a next action of zero. If no type id is
97 /// found the the frame is unwound and handling continues.
98 /// 3. Type id table contains references to all the C++ typeinfo for all
99 /// catches in the function. This tables is reversed indexed base 1.
101 /// SharedTypeIds - How many leading type ids two landing pads have in common.
102 static unsigned SharedTypeIds(const LandingPadInfo
*L
,
103 const LandingPadInfo
*R
);
105 /// PadLT - Order landing pads lexicographically by type id.
106 static bool PadLT(const LandingPadInfo
*L
, const LandingPadInfo
*R
);
109 static inline unsigned getEmptyKey() { return -1U; }
110 static inline unsigned getTombstoneKey() { return -2U; }
111 static unsigned getHashValue(const unsigned &Key
) { return Key
; }
112 static bool isEqual(unsigned LHS
, unsigned RHS
) { return LHS
== RHS
; }
113 static bool isPod() { return true; }
116 /// PadRange - Structure holding a try-range and the associated landing pad.
118 // The index of the landing pad.
120 // The index of the begin and end labels in the landing pad's label lists.
124 typedef DenseMap
<unsigned, PadRange
, KeyInfo
> RangeMapType
;
126 /// ActionEntry - Structure describing an entry in the actions table.
128 int ValueForTypeID
; // The value to write - may not be equal to the type id.
130 struct ActionEntry
*Previous
;
133 /// CallSiteEntry - Structure describing an entry in the call-site table.
134 struct CallSiteEntry
{
135 // The 'try-range' is BeginLabel .. EndLabel.
136 unsigned BeginLabel
; // zero indicates the start of the function.
137 unsigned EndLabel
; // zero indicates the end of the function.
139 // The landing pad starts at PadLabel.
140 unsigned PadLabel
; // zero indicates that there is no landing pad.
144 /// ComputeActionsTable - Compute the actions table and gather the first
145 /// action index for each landing pad site.
146 unsigned ComputeActionsTable(const SmallVectorImpl
<const LandingPadInfo
*>&LPs
,
147 SmallVectorImpl
<ActionEntry
> &Actions
,
148 SmallVectorImpl
<unsigned> &FirstActions
);
150 /// ComputeCallSiteTable - Compute the call-site table. The entry for an
151 /// invoke has a try-range containing the call, a non-zero landing pad and an
152 /// appropriate action. The entry for an ordinary call has a try-range
153 /// containing the call and zero for the landing pad and the action. Calls
154 /// marked 'nounwind' have no entry and must not be contained in the try-range
155 /// of any entry - they form gaps in the table. Entries must be ordered by
156 /// try-range address.
157 void ComputeCallSiteTable(SmallVectorImpl
<CallSiteEntry
> &CallSites
,
158 const RangeMapType
&PadMap
,
159 const SmallVectorImpl
<const LandingPadInfo
*> &LPs
,
160 const SmallVectorImpl
<unsigned> &FirstActions
);
161 void EmitExceptionTable();
164 //===--------------------------------------------------------------------===//
165 // Main entry points.
167 DwarfException(raw_ostream
&OS
, AsmPrinter
*A
, const MCAsmInfo
*T
);
168 virtual ~DwarfException();
170 /// BeginModule - Emit all exception information that should come prior to the
172 void BeginModule(Module
*m
, MachineModuleInfo
*mmi
) {
177 /// EndModule - Emit all exception information that should come after the
181 /// BeginFunction - Gather pre-function exception information. Assumes being
182 /// emitted immediately after the function entry point.
183 void BeginFunction(MachineFunction
*MF
);
185 /// EndFunction - Gather and emit post-function exception information.
189 } // End of namespace llvm