DwarfException.h revision eb9072195ca7d777a71194dcaaaa369d82f24f53
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 14#ifndef DWARFEXCEPTION_H__ 15#define DWARFEXCEPTION_H__ 16 17#include "DIE.h" 18#include "DwarfPrinter.h" 19#include "llvm/CodeGen/AsmPrinter.h" 20#include "llvm/ADT/DenseMap.h" 21#include <string> 22 23namespace llvm { 24 25struct LandingPadInfo; 26class MachineModuleInfo; 27class TargetAsmInfo; 28class Timer; 29class raw_ostream; 30 31//===----------------------------------------------------------------------===// 32/// DwarfException - Emits Dwarf exception handling directives. 33/// 34class VISIBILITY_HIDDEN DwarfException : public Dwarf { 35 struct FunctionEHFrameInfo { 36 std::string FnName; 37 unsigned Number; 38 unsigned PersonalityIndex; 39 bool hasCalls; 40 bool hasLandingPads; 41 std::vector<MachineMove> Moves; 42 const Function * function; 43 44 FunctionEHFrameInfo(const std::string &FN, unsigned Num, unsigned P, 45 bool hC, bool hL, 46 const std::vector<MachineMove> &M, 47 const Function *f): 48 FnName(FN), Number(Num), PersonalityIndex(P), 49 hasCalls(hC), hasLandingPads(hL), Moves(M), function (f) { } 50 }; 51 52 std::vector<FunctionEHFrameInfo> EHFrames; 53 54 /// shouldEmitTable - Per-function flag to indicate if EH tables should 55 /// be emitted. 56 bool shouldEmitTable; 57 58 /// shouldEmitMoves - Per-function flag to indicate if frame moves info 59 /// should be emitted. 60 bool shouldEmitMoves; 61 62 /// shouldEmitTableModule - Per-module flag to indicate if EH tables 63 /// should be emitted. 64 bool shouldEmitTableModule; 65 66 /// shouldEmitFrameModule - Per-module flag to indicate if frame moves 67 /// should be emitted. 68 bool shouldEmitMovesModule; 69 70 /// ExceptionTimer - Timer for the Dwarf exception writer. 71 Timer *ExceptionTimer; 72 73 /// EmitCommonEHFrame - Emit the common eh unwind frame. 74 /// 75 void EmitCommonEHFrame(const Function *Personality, unsigned Index); 76 77 /// EmitEHFrame - Emit function exception frame information. 78 /// 79 void EmitEHFrame(const FunctionEHFrameInfo &EHFrameInfo); 80 81 /// EmitExceptionTable - Emit landing pads and actions. 82 /// 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. 100 101 /// SharedTypeIds - How many leading type ids two landing pads have in common. 102 static unsigned SharedTypeIds(const LandingPadInfo *L, 103 const LandingPadInfo *R); 104 105 /// PadLT - Order landing pads lexicographically by type id. 106 static bool PadLT(const LandingPadInfo *L, const LandingPadInfo *R); 107 108 struct KeyInfo { 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; } 114 }; 115 116 /// ActionEntry - Structure describing an entry in the actions table. 117 struct ActionEntry { 118 int ValueForTypeID; // The value to write - may not be equal to the type id. 119 int NextAction; 120 struct ActionEntry *Previous; 121 }; 122 123 /// PadRange - Structure holding a try-range and the associated landing pad. 124 struct PadRange { 125 // The index of the landing pad. 126 unsigned PadIndex; 127 // The index of the begin and end labels in the landing pad's label lists. 128 unsigned RangeIndex; 129 }; 130 131 typedef DenseMap<unsigned, PadRange, KeyInfo> RangeMapType; 132 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. 138 // The landing pad starts at PadLabel. 139 unsigned PadLabel; // zero indicates that there is no landing pad. 140 unsigned Action; 141 }; 142 143 void EmitExceptionTable(); 144 145public: 146 //===--------------------------------------------------------------------===// 147 // Main entry points. 148 // 149 DwarfException(raw_ostream &OS, AsmPrinter *A, const TargetAsmInfo *T); 150 virtual ~DwarfException(); 151 152 /// SetModuleInfo - Set machine module information when it's known that pass 153 /// manager has created it. Set by the target AsmPrinter. 154 void SetModuleInfo(MachineModuleInfo *mmi) { 155 MMI = mmi; 156 } 157 158 /// BeginModule - Emit all exception information that should come prior to the 159 /// content. 160 void BeginModule(Module *M) { 161 this->M = M; 162 } 163 164 /// EndModule - Emit all exception information that should come after the 165 /// content. 166 void EndModule(); 167 168 /// BeginFunction - Gather pre-function exception information. Assumes being 169 /// emitted immediately after the function entry point. 170 void BeginFunction(MachineFunction *MF); 171 172 /// EndFunction - Gather and emit post-function exception information. 173 void EndFunction(); 174}; 175 176} // End of namespace llvm 177 178#endif 179