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 "AsmPrinterHandler.h"
18 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/CodeGen/AsmPrinter.h"
24 template <typename T> class SmallVectorImpl;
25 struct LandingPadInfo;
26 class MachineModuleInfo;
28 class MachineFunction;
33 class ARMTargetStreamer;
36 //===----------------------------------------------------------------------===//
37 /// DwarfException - Emits Dwarf exception handling directives.
39 class DwarfException : public AsmPrinterHandler {
41 /// Asm - Target of Dwarf emission.
44 /// MMI - Collected machine module information.
45 MachineModuleInfo *MMI;
47 /// SharedTypeIds - How many leading type ids two landing pads have in common.
48 static unsigned SharedTypeIds(const LandingPadInfo *L,
49 const LandingPadInfo *R);
51 /// PadRange - Structure holding a try-range and the associated landing pad.
53 // The index of the landing pad.
55 // The index of the begin and end labels in the landing pad's label lists.
59 typedef DenseMap<MCSymbol *, PadRange> RangeMapType;
61 /// ActionEntry - Structure describing an entry in the actions table.
63 int ValueForTypeID; // The value to write - may not be equal to the type id.
68 /// CallSiteEntry - Structure describing an entry in the call-site table.
69 struct CallSiteEntry {
70 // The 'try-range' is BeginLabel .. EndLabel.
71 MCSymbol *BeginLabel; // zero indicates the start of the function.
72 MCSymbol *EndLabel; // zero indicates the end of the function.
74 // The landing pad starts at PadLabel.
75 MCSymbol *PadLabel; // zero indicates that there is no landing pad.
79 /// ComputeActionsTable - Compute the actions table and gather the first
80 /// action index for each landing pad site.
81 unsigned ComputeActionsTable(const SmallVectorImpl<const LandingPadInfo*>&LPs,
82 SmallVectorImpl<ActionEntry> &Actions,
83 SmallVectorImpl<unsigned> &FirstActions);
85 /// CallToNoUnwindFunction - Return `true' if this is a call to a function
86 /// marked `nounwind'. Return `false' otherwise.
87 bool CallToNoUnwindFunction(const MachineInstr *MI);
89 /// ComputeCallSiteTable - Compute the call-site table. The entry for an
90 /// invoke has a try-range containing the call, a non-zero landing pad and an
91 /// appropriate action. The entry for an ordinary call has a try-range
92 /// containing the call and zero for the landing pad and the action. Calls
93 /// marked 'nounwind' have no entry and must not be contained in the try-range
94 /// of any entry - they form gaps in the table. Entries must be ordered by
95 /// try-range address.
96 void ComputeCallSiteTable(SmallVectorImpl<CallSiteEntry> &CallSites,
97 const RangeMapType &PadMap,
98 const SmallVectorImpl<const LandingPadInfo *> &LPs,
99 const SmallVectorImpl<unsigned> &FirstActions);
101 /// EmitExceptionTable - Emit landing pads and actions.
103 /// The general organization of the table is complex, but the basic concepts
104 /// are easy. First there is a header which describes the location and
105 /// organization of the three components that follow.
106 /// 1. The landing pad site information describes the range of code covered
107 /// by the try. In our case it's an accumulation of the ranges covered
108 /// by the invokes in the try. There is also a reference to the landing
109 /// pad that handles the exception once processed. Finally an index into
110 /// the actions table.
111 /// 2. The action table, in our case, is composed of pairs of type ids
112 /// and next action offset. Starting with the action index from the
113 /// landing pad site, each type Id is checked for a match to the current
114 /// exception. If it matches then the exception and type id are passed
115 /// on to the landing pad. Otherwise the next action is looked up. This
116 /// chain is terminated with a next action of zero. If no type id is
117 /// found the frame is unwound and handling continues.
118 /// 3. Type id table contains references to all the C++ typeinfo for all
119 /// catches in the function. This tables is reversed indexed base 1.
120 void EmitExceptionTable();
122 virtual void EmitTypeInfos(unsigned TTypeEncoding);
125 //===--------------------------------------------------------------------===//
126 // Main entry points.
128 DwarfException(AsmPrinter *A);
129 virtual ~DwarfException();
131 /// endModule - Emit all exception information that should come after the
133 void endModule() override;
135 /// beginFunction - Gather pre-function exception information. Assumes being
136 /// emitted immediately after the function entry point.
137 void beginFunction(const MachineFunction *MF) override;
139 /// endFunction - Gather and emit post-function exception information.
140 void endFunction(const MachineFunction *) override;
142 // We don't need these.
143 void setSymbolSize(const MCSymbol *Sym, uint64_t Size) override {}
144 void beginInstruction(const MachineInstr *MI) override {}
145 void endInstruction() override {}
148 class DwarfCFIException : public DwarfException {
149 /// shouldEmitPersonality - Per-function flag to indicate if .cfi_personality
150 /// should be emitted.
151 bool shouldEmitPersonality;
153 /// shouldEmitLSDA - Per-function flag to indicate if .cfi_lsda
154 /// should be emitted.
157 /// shouldEmitMoves - Per-function flag to indicate if frame moves info
158 /// should be emitted.
159 bool shouldEmitMoves;
161 AsmPrinter::CFIMoveType moveTypeModule;
164 //===--------------------------------------------------------------------===//
165 // Main entry points.
167 DwarfCFIException(AsmPrinter *A);
168 virtual ~DwarfCFIException();
170 /// endModule - Emit all exception information that should come after the
172 void endModule() override;
174 /// beginFunction - Gather pre-function exception information. Assumes being
175 /// emitted immediately after the function entry point.
176 void beginFunction(const MachineFunction *MF) override;
178 /// endFunction - Gather and emit post-function exception information.
179 void endFunction(const MachineFunction *) override;
182 class ARMException : public DwarfException {
183 void EmitTypeInfos(unsigned TTypeEncoding) override;
184 ARMTargetStreamer &getTargetStreamer();
186 /// shouldEmitCFI - Per-function flag to indicate if frame CFI info
187 /// should be emitted.
191 //===--------------------------------------------------------------------===//
192 // Main entry points.
194 ARMException(AsmPrinter *A);
195 virtual ~ARMException();
197 /// endModule - Emit all exception information that should come after the
199 void endModule() override;
201 /// beginFunction - Gather pre-function exception information. Assumes being
202 /// emitted immediately after the function entry point.
203 void beginFunction(const MachineFunction *MF) override;
205 /// endFunction - Gather and emit post-function exception information.
206 void endFunction(const MachineFunction *) override;
209 class Win64Exception : public DwarfException {
210 /// shouldEmitPersonality - Per-function flag to indicate if personality
211 /// info should be emitted.
212 bool shouldEmitPersonality;
214 /// shouldEmitLSDA - Per-function flag to indicate if the LSDA
215 /// should be emitted.
218 /// shouldEmitMoves - Per-function flag to indicate if frame moves info
219 /// should be emitted.
220 bool shouldEmitMoves;
223 //===--------------------------------------------------------------------===//
224 // Main entry points.
226 Win64Exception(AsmPrinter *A);
227 virtual ~Win64Exception();
229 /// endModule - Emit all exception information that should come after the
231 void endModule() override;
233 /// beginFunction - Gather pre-function exception information. Assumes being
234 /// emitted immediately after the function entry point.
235 void beginFunction(const MachineFunction *MF) override;
237 /// endFunction - Gather and emit post-function exception information.
238 void endFunction(const MachineFunction *) override;
241 } // End of namespace llvm