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"
22 template <typename T> class SmallVectorImpl;
23 struct LandingPadInfo;
24 class MachineModuleInfo;
27 class MachineFunction;
34 //===----------------------------------------------------------------------===//
35 /// DwarfException - Emits Dwarf exception handling directives.
37 class DwarfException {
38 /// Asm - Target of Dwarf emission.
41 /// MMI - Collected machine module information.
42 MachineModuleInfo *MMI;
44 struct FunctionEHFrameInfo {
45 MCSymbol *FunctionEHSym; // L_foo.eh
47 unsigned PersonalityIndex;
50 std::vector<MachineMove> Moves;
51 const Function *function;
53 FunctionEHFrameInfo(MCSymbol *EHSym, unsigned Num, unsigned P,
55 const std::vector<MachineMove> &M,
57 FunctionEHSym(EHSym), Number(Num), PersonalityIndex(P),
58 hasCalls(hC), hasLandingPads(hL), Moves(M), function (f) { }
61 std::vector<FunctionEHFrameInfo> EHFrames;
63 /// UsesLSDA - Indicates whether an FDE that uses the CIE at the given index
64 /// uses an LSDA. If so, then we need to encode that information in the CIE's
66 DenseMap<unsigned, bool> UsesLSDA;
68 /// shouldEmitTable - Per-function flag to indicate if EH tables should
72 /// shouldEmitMoves - Per-function flag to indicate if frame moves info
73 /// should be emitted.
76 /// shouldEmitTableModule - Per-module flag to indicate if EH tables
77 /// should be emitted.
78 bool shouldEmitTableModule;
80 /// shouldEmitFrameModule - Per-module flag to indicate if frame moves
81 /// should be emitted.
82 bool shouldEmitMovesModule;
84 /// EmitCIE - Emit a Common Information Entry (CIE). This holds information
85 /// that is shared among many Frame Description Entries. There is at least
86 /// one CIE in every non-empty .debug_frame section.
87 void EmitCIE(const Function *Personality, unsigned Index);
89 /// EmitFDE - Emit the Frame Description Entry (FDE) for the function.
90 void EmitFDE(const FunctionEHFrameInfo &EHFrameInfo);
92 /// EmitExceptionTable - Emit landing pads and actions.
94 /// The general organization of the table is complex, but the basic concepts
95 /// are easy. First there is a header which describes the location and
96 /// organization of the three components that follow.
97 /// 1. The landing pad site information describes the range of code covered
98 /// by the try. In our case it's an accumulation of the ranges covered
99 /// by the invokes in the try. There is also a reference to the landing
100 /// pad that handles the exception once processed. Finally an index into
101 /// the actions table.
102 /// 2. The action table, in our case, is composed of pairs of type ids
103 /// and next action offset. Starting with the action index from the
104 /// landing pad site, each type Id is checked for a match to the current
105 /// exception. If it matches then the exception and type id are passed
106 /// on to the landing pad. Otherwise the next action is looked up. This
107 /// chain is terminated with a next action of zero. If no type id is
108 /// found the frame is unwound and handling continues.
109 /// 3. Type id table contains references to all the C++ typeinfo for all
110 /// catches in the function. This tables is reversed indexed base 1.
112 /// SharedTypeIds - How many leading type ids two landing pads have in common.
113 static unsigned SharedTypeIds(const LandingPadInfo *L,
114 const LandingPadInfo *R);
116 /// PadLT - Order landing pads lexicographically by type id.
117 static bool PadLT(const LandingPadInfo *L, const LandingPadInfo *R);
119 /// PadRange - Structure holding a try-range and the associated landing pad.
121 // The index of the landing pad.
123 // The index of the begin and end labels in the landing pad's label lists.
127 typedef DenseMap<MCSymbol *, PadRange> RangeMapType;
129 /// ActionEntry - Structure describing an entry in the actions table.
131 int ValueForTypeID; // The value to write - may not be equal to the type id.
136 /// CallSiteEntry - Structure describing an entry in the call-site table.
137 struct CallSiteEntry {
138 // The 'try-range' is BeginLabel .. EndLabel.
139 MCSymbol *BeginLabel; // zero indicates the start of the function.
140 MCSymbol *EndLabel; // zero indicates the end of the function.
142 // The landing pad starts at PadLabel.
143 MCSymbol *PadLabel; // zero indicates that there is no landing pad.
147 /// ComputeActionsTable - Compute the actions table and gather the first
148 /// action index for each landing pad site.
149 unsigned ComputeActionsTable(const SmallVectorImpl<const LandingPadInfo*>&LPs,
150 SmallVectorImpl<ActionEntry> &Actions,
151 SmallVectorImpl<unsigned> &FirstActions);
153 /// CallToNoUnwindFunction - Return `true' if this is a call to a function
154 /// marked `nounwind'. Return `false' otherwise.
155 bool CallToNoUnwindFunction(const MachineInstr *MI);
157 /// ComputeCallSiteTable - Compute the call-site table. The entry for an
158 /// invoke has a try-range containing the call, a non-zero landing pad and an
159 /// appropriate action. The entry for an ordinary call has a try-range
160 /// containing the call and zero for the landing pad and the action. Calls
161 /// marked 'nounwind' have no entry and must not be contained in the try-range
162 /// of any entry - they form gaps in the table. Entries must be ordered by
163 /// try-range address.
164 void ComputeCallSiteTable(SmallVectorImpl<CallSiteEntry> &CallSites,
165 const RangeMapType &PadMap,
166 const SmallVectorImpl<const LandingPadInfo *> &LPs,
167 const SmallVectorImpl<unsigned> &FirstActions);
168 void EmitExceptionTable();
171 //===--------------------------------------------------------------------===//
172 // Main entry points.
174 DwarfException(AsmPrinter *A);
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(const MachineFunction *MF);
185 /// EndFunction - Gather and emit post-function exception information.
189 } // End of namespace llvm