Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 1 | //===-- 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 Lattner | 6f37f8f | 2009-07-17 20:32:07 +0000 | [diff] [blame] | 14 | #ifndef LLVM_CODEGEN_ASMPRINTER_DWARFEXCEPTION_H |
| 15 | #define LLVM_CODEGEN_ASMPRINTER_DWARFEXCEPTION_H |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 16 | |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/DenseMap.h" |
Rafael Espindola | e29887b | 2011-05-10 18:39:09 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/AsmPrinter.h" |
Chris Lattner | 6d73378 | 2010-04-05 05:28:23 +0000 | [diff] [blame] | 19 | #include <vector> |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 20 | |
| 21 | namespace llvm { |
| 22 | |
Chris Lattner | 6d73378 | 2010-04-05 05:28:23 +0000 | [diff] [blame] | 23 | template <typename T> class SmallVectorImpl; |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 24 | struct LandingPadInfo; |
| 25 | class MachineModuleInfo; |
Chris Lattner | 6d73378 | 2010-04-05 05:28:23 +0000 | [diff] [blame] | 26 | class MachineMove; |
| 27 | class MachineInstr; |
| 28 | class MachineFunction; |
Chris Lattner | af76e59 | 2009-08-22 20:48:53 +0000 | [diff] [blame] | 29 | class MCAsmInfo; |
Bill Wendling | 7378b1b | 2009-11-17 01:23:53 +0000 | [diff] [blame] | 30 | class MCExpr; |
Chris Lattner | 6d73378 | 2010-04-05 05:28:23 +0000 | [diff] [blame] | 31 | class MCSymbol; |
Chris Lattner | 6d73378 | 2010-04-05 05:28:23 +0000 | [diff] [blame] | 32 | class Function; |
| 33 | class AsmPrinter; |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 34 | |
| 35 | //===----------------------------------------------------------------------===// |
| 36 | /// DwarfException - Emits Dwarf exception handling directives. |
| 37 | /// |
Chris Lattner | 84ac8b7 | 2010-04-05 00:26:50 +0000 | [diff] [blame] | 38 | class DwarfException { |
Anton Korobeynikov | d7e8ddc | 2011-01-14 21:57:45 +0000 | [diff] [blame] | 39 | protected: |
Chris Lattner | 84ac8b7 | 2010-04-05 00:26:50 +0000 | [diff] [blame] | 40 | /// Asm - Target of Dwarf emission. |
| 41 | AsmPrinter *Asm; |
Chris Lattner | 105d697 | 2010-04-05 05:31:04 +0000 | [diff] [blame] | 42 | |
Chris Lattner | 84ac8b7 | 2010-04-05 00:26:50 +0000 | [diff] [blame] | 43 | /// MMI - Collected machine module information. |
| 44 | MachineModuleInfo *MMI; |
Chris Lattner | 84ac8b7 | 2010-04-05 00:26:50 +0000 | [diff] [blame] | 45 | |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 46 | /// EmitExceptionTable - Emit landing pads and actions. |
| 47 | /// |
| 48 | /// The general organization of the table is complex, but the basic concepts |
| 49 | /// are easy. First there is a header which describes the location and |
| 50 | /// organization of the three components that follow. |
| 51 | /// 1. The landing pad site information describes the range of code covered |
| 52 | /// by the try. In our case it's an accumulation of the ranges covered |
| 53 | /// by the invokes in the try. There is also a reference to the landing |
| 54 | /// pad that handles the exception once processed. Finally an index into |
| 55 | /// the actions table. |
| 56 | /// 2. The action table, in our case, is composed of pairs of type ids |
| 57 | /// and next action offset. Starting with the action index from the |
| 58 | /// landing pad site, each type Id is checked for a match to the current |
| 59 | /// exception. If it matches then the exception and type id are passed |
| 60 | /// on to the landing pad. Otherwise the next action is looked up. This |
| 61 | /// chain is terminated with a next action of zero. If no type id is |
Dan Gohman | f451cb8 | 2010-02-10 16:03:48 +0000 | [diff] [blame] | 62 | /// found the frame is unwound and handling continues. |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 63 | /// 3. Type id table contains references to all the C++ typeinfo for all |
| 64 | /// catches in the function. This tables is reversed indexed base 1. |
| 65 | |
| 66 | /// SharedTypeIds - How many leading type ids two landing pads have in common. |
| 67 | static unsigned SharedTypeIds(const LandingPadInfo *L, |
| 68 | const LandingPadInfo *R); |
| 69 | |
| 70 | /// PadLT - Order landing pads lexicographically by type id. |
| 71 | static bool PadLT(const LandingPadInfo *L, const LandingPadInfo *R); |
| 72 | |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 73 | /// PadRange - Structure holding a try-range and the associated landing pad. |
| 74 | struct PadRange { |
| 75 | // The index of the landing pad. |
| 76 | unsigned PadIndex; |
| 77 | // The index of the begin and end labels in the landing pad's label lists. |
| 78 | unsigned RangeIndex; |
| 79 | }; |
| 80 | |
Chris Lattner | 1611273 | 2010-03-14 01:41:15 +0000 | [diff] [blame] | 81 | typedef DenseMap<MCSymbol *, PadRange> RangeMapType; |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 82 | |
Bill Wendling | 5e953dd | 2009-07-28 23:22:13 +0000 | [diff] [blame] | 83 | /// ActionEntry - Structure describing an entry in the actions table. |
| 84 | struct ActionEntry { |
| 85 | int ValueForTypeID; // The value to write - may not be equal to the type id. |
| 86 | int NextAction; |
Bill Wendling | 0a9abcb | 2010-02-10 21:41:57 +0000 | [diff] [blame] | 87 | unsigned Previous; |
Bill Wendling | 5e953dd | 2009-07-28 23:22:13 +0000 | [diff] [blame] | 88 | }; |
| 89 | |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 90 | /// CallSiteEntry - Structure describing an entry in the call-site table. |
| 91 | struct CallSiteEntry { |
| 92 | // The 'try-range' is BeginLabel .. EndLabel. |
Chris Lattner | 1611273 | 2010-03-14 01:41:15 +0000 | [diff] [blame] | 93 | MCSymbol *BeginLabel; // zero indicates the start of the function. |
| 94 | MCSymbol *EndLabel; // zero indicates the end of the function. |
Bill Wendling | 5e953dd | 2009-07-28 23:22:13 +0000 | [diff] [blame] | 95 | |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 96 | // The landing pad starts at PadLabel. |
Chris Lattner | 1611273 | 2010-03-14 01:41:15 +0000 | [diff] [blame] | 97 | MCSymbol *PadLabel; // zero indicates that there is no landing pad. |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 98 | unsigned Action; |
| 99 | }; |
| 100 | |
Bill Wendling | d460962 | 2009-07-28 23:23:00 +0000 | [diff] [blame] | 101 | /// ComputeActionsTable - Compute the actions table and gather the first |
| 102 | /// action index for each landing pad site. |
Bill Wendling | ade025c | 2009-07-29 00:31:35 +0000 | [diff] [blame] | 103 | unsigned ComputeActionsTable(const SmallVectorImpl<const LandingPadInfo*>&LPs, |
Bill Wendling | 5e953dd | 2009-07-28 23:22:13 +0000 | [diff] [blame] | 104 | SmallVectorImpl<ActionEntry> &Actions, |
| 105 | SmallVectorImpl<unsigned> &FirstActions); |
Bill Wendling | ade025c | 2009-07-29 00:31:35 +0000 | [diff] [blame] | 106 | |
Bill Wendling | ed060dc | 2009-11-12 21:59:20 +0000 | [diff] [blame] | 107 | /// CallToNoUnwindFunction - Return `true' if this is a call to a function |
| 108 | /// marked `nounwind'. Return `false' otherwise. |
| 109 | bool CallToNoUnwindFunction(const MachineInstr *MI); |
| 110 | |
Bill Wendling | ade025c | 2009-07-29 00:31:35 +0000 | [diff] [blame] | 111 | /// ComputeCallSiteTable - Compute the call-site table. The entry for an |
| 112 | /// invoke has a try-range containing the call, a non-zero landing pad and an |
| 113 | /// appropriate action. The entry for an ordinary call has a try-range |
| 114 | /// containing the call and zero for the landing pad and the action. Calls |
| 115 | /// marked 'nounwind' have no entry and must not be contained in the try-range |
| 116 | /// of any entry - they form gaps in the table. Entries must be ordered by |
| 117 | /// try-range address. |
| 118 | void ComputeCallSiteTable(SmallVectorImpl<CallSiteEntry> &CallSites, |
| 119 | const RangeMapType &PadMap, |
| 120 | const SmallVectorImpl<const LandingPadInfo *> &LPs, |
| 121 | const SmallVectorImpl<unsigned> &FirstActions); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 122 | void EmitExceptionTable(); |
| 123 | |
| 124 | public: |
| 125 | //===--------------------------------------------------------------------===// |
| 126 | // Main entry points. |
| 127 | // |
Chris Lattner | 75f5072 | 2010-04-04 07:48:20 +0000 | [diff] [blame] | 128 | DwarfException(AsmPrinter *A); |
Anton Korobeynikov | d7e8ddc | 2011-01-14 21:57:45 +0000 | [diff] [blame] | 129 | virtual ~DwarfException(); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 130 | |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 131 | /// EndModule - Emit all exception information that should come after the |
| 132 | /// content. |
Anton Korobeynikov | d7e8ddc | 2011-01-14 21:57:45 +0000 | [diff] [blame] | 133 | virtual void EndModule(); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 134 | |
| 135 | /// BeginFunction - Gather pre-function exception information. Assumes being |
| 136 | /// emitted immediately after the function entry point. |
Anton Korobeynikov | d7e8ddc | 2011-01-14 21:57:45 +0000 | [diff] [blame] | 137 | virtual void BeginFunction(const MachineFunction *MF); |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 138 | |
| 139 | /// EndFunction - Gather and emit post-function exception information. |
Anton Korobeynikov | d7e8ddc | 2011-01-14 21:57:45 +0000 | [diff] [blame] | 140 | virtual void EndFunction(); |
| 141 | }; |
| 142 | |
Anton Korobeynikov | 9a1ef4e | 2011-01-14 21:57:53 +0000 | [diff] [blame] | 143 | class DwarfCFIException : public DwarfException { |
Rafael Espindola | 7b11a4c | 2011-04-29 14:48:51 +0000 | [diff] [blame] | 144 | /// shouldEmitPersonality - Per-function flag to indicate if .cfi_personality |
| 145 | /// should be emitted. |
| 146 | bool shouldEmitPersonality; |
| 147 | |
| 148 | /// shouldEmitLSDA - Per-function flag to indicate if .cfi_lsda |
| 149 | /// should be emitted. |
| 150 | bool shouldEmitLSDA; |
Anton Korobeynikov | 9a1ef4e | 2011-01-14 21:57:53 +0000 | [diff] [blame] | 151 | |
| 152 | /// shouldEmitMoves - Per-function flag to indicate if frame moves info |
| 153 | /// should be emitted. |
| 154 | bool shouldEmitMoves; |
| 155 | |
Rafael Espindola | e29887b | 2011-05-10 18:39:09 +0000 | [diff] [blame] | 156 | AsmPrinter::CFIMoveType moveTypeModule; |
| 157 | |
Anton Korobeynikov | 9a1ef4e | 2011-01-14 21:57:53 +0000 | [diff] [blame] | 158 | public: |
| 159 | //===--------------------------------------------------------------------===// |
| 160 | // Main entry points. |
| 161 | // |
| 162 | DwarfCFIException(AsmPrinter *A); |
| 163 | virtual ~DwarfCFIException(); |
| 164 | |
| 165 | /// EndModule - Emit all exception information that should come after the |
| 166 | /// content. |
| 167 | virtual void EndModule(); |
| 168 | |
| 169 | /// BeginFunction - Gather pre-function exception information. Assumes being |
| 170 | /// emitted immediately after the function entry point. |
| 171 | virtual void BeginFunction(const MachineFunction *MF); |
| 172 | |
| 173 | /// EndFunction - Gather and emit post-function exception information. |
| 174 | virtual void EndFunction(); |
| 175 | }; |
| 176 | |
Anton Korobeynikov | b5e16af | 2011-03-05 18:43:15 +0000 | [diff] [blame] | 177 | class ARMException : public DwarfException { |
| 178 | /// shouldEmitTable - Per-function flag to indicate if EH tables should |
| 179 | /// be emitted. |
| 180 | bool shouldEmitTable; |
| 181 | |
| 182 | /// shouldEmitMoves - Per-function flag to indicate if frame moves info |
| 183 | /// should be emitted. |
| 184 | bool shouldEmitMoves; |
| 185 | |
| 186 | /// shouldEmitTableModule - Per-module flag to indicate if EH tables |
| 187 | /// should be emitted. |
| 188 | bool shouldEmitTableModule; |
| 189 | public: |
| 190 | //===--------------------------------------------------------------------===// |
| 191 | // Main entry points. |
| 192 | // |
| 193 | ARMException(AsmPrinter *A); |
| 194 | virtual ~ARMException(); |
| 195 | |
| 196 | /// EndModule - Emit all exception information that should come after the |
| 197 | /// content. |
| 198 | virtual void EndModule(); |
| 199 | |
| 200 | /// BeginFunction - Gather pre-function exception information. Assumes being |
| 201 | /// emitted immediately after the function entry point. |
| 202 | virtual void BeginFunction(const MachineFunction *MF); |
| 203 | |
| 204 | /// EndFunction - Gather and emit post-function exception information. |
| 205 | virtual void EndFunction(); |
| 206 | }; |
| 207 | |
Charles Davis | d652b13 | 2011-05-27 23:47:32 +0000 | [diff] [blame] | 208 | class Win64Exception : public DwarfException { |
| 209 | /// shouldEmitPersonality - Per-function flag to indicate if personality |
| 210 | /// info should be emitted. |
| 211 | bool shouldEmitPersonality; |
| 212 | |
| 213 | /// shouldEmitLSDA - Per-function flag to indicate if the LSDA |
| 214 | /// should be emitted. |
| 215 | bool shouldEmitLSDA; |
| 216 | |
| 217 | /// shouldEmitMoves - Per-function flag to indicate if frame moves info |
| 218 | /// should be emitted. |
| 219 | bool shouldEmitMoves; |
| 220 | |
| 221 | public: |
| 222 | //===--------------------------------------------------------------------===// |
| 223 | // Main entry points. |
| 224 | // |
| 225 | Win64Exception(AsmPrinter *A); |
| 226 | virtual ~Win64Exception(); |
| 227 | |
| 228 | /// EndModule - Emit all exception information that should come after the |
| 229 | /// content. |
| 230 | virtual void EndModule(); |
| 231 | |
| 232 | /// BeginFunction - Gather pre-function exception information. Assumes being |
| 233 | /// emitted immediately after the function entry point. |
| 234 | virtual void BeginFunction(const MachineFunction *MF); |
| 235 | |
| 236 | /// EndFunction - Gather and emit post-function exception information. |
| 237 | virtual void EndFunction(); |
| 238 | }; |
| 239 | |
Bill Wendling | eb90721 | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 240 | } // End of namespace llvm |
| 241 | |
| 242 | #endif |