DwarfException.h revision 195098
1193323Sed//===-- DwarfException.h - Dwarf Exception Framework -----------*- C++ -*--===// 2193323Sed// 3193323Sed// The LLVM Compiler Infrastructure 4193323Sed// 5193323Sed// This file is distributed under the University of Illinois Open Source 6193323Sed// License. See LICENSE.TXT for details. 7193323Sed// 8193323Sed//===----------------------------------------------------------------------===// 9193323Sed// 10193323Sed// This file contains support for writing dwarf exception info into asm files. 11193323Sed// 12193323Sed//===----------------------------------------------------------------------===// 13193323Sed 14193323Sed#ifndef CODEGEN_ASMPRINTER_DWARFEXCEPTION_H__ 15193323Sed#define CODEGEN_ASMPRINTER_DWARFEXCEPTION_H__ 16193323Sed 17193323Sed#include "DIE.h" 18193323Sed#include "DwarfPrinter.h" 19193323Sed#include "llvm/CodeGen/AsmPrinter.h" 20193323Sed#include "llvm/ADT/DenseMap.h" 21193323Sed#include <string> 22193323Sed 23193323Sednamespace llvm { 24193323Sed 25193323Sedstruct LandingPadInfo; 26193323Sedclass MachineModuleInfo; 27193323Sedclass TargetAsmInfo; 28193323Sedclass Timer; 29193323Sedclass raw_ostream; 30193323Sed 31193323Sed//===----------------------------------------------------------------------===// 32193323Sed/// DwarfException - Emits Dwarf exception handling directives. 33193323Sed/// 34193323Sedclass VISIBILITY_HIDDEN DwarfException : public Dwarf { 35193323Sed struct FunctionEHFrameInfo { 36193323Sed std::string FnName; 37193323Sed unsigned Number; 38193323Sed unsigned PersonalityIndex; 39193323Sed bool hasCalls; 40193323Sed bool hasLandingPads; 41193323Sed std::vector<MachineMove> Moves; 42193323Sed const Function * function; 43193323Sed 44193323Sed FunctionEHFrameInfo(const std::string &FN, unsigned Num, unsigned P, 45193323Sed bool hC, bool hL, 46193323Sed const std::vector<MachineMove> &M, 47193323Sed const Function *f): 48193323Sed FnName(FN), Number(Num), PersonalityIndex(P), 49193323Sed hasCalls(hC), hasLandingPads(hL), Moves(M), function (f) { } 50193323Sed }; 51193323Sed 52193323Sed std::vector<FunctionEHFrameInfo> EHFrames; 53193323Sed 54193323Sed /// shouldEmitTable - Per-function flag to indicate if EH tables should 55193323Sed /// be emitted. 56193323Sed bool shouldEmitTable; 57193323Sed 58193323Sed /// shouldEmitMoves - Per-function flag to indicate if frame moves info 59193323Sed /// should be emitted. 60193323Sed bool shouldEmitMoves; 61193323Sed 62193323Sed /// shouldEmitTableModule - Per-module flag to indicate if EH tables 63193323Sed /// should be emitted. 64193323Sed bool shouldEmitTableModule; 65193323Sed 66193323Sed /// shouldEmitFrameModule - Per-module flag to indicate if frame moves 67193323Sed /// should be emitted. 68193323Sed bool shouldEmitMovesModule; 69193323Sed 70193323Sed /// ExceptionTimer - Timer for the Dwarf exception writer. 71193323Sed Timer *ExceptionTimer; 72193323Sed 73193323Sed /// EmitCommonEHFrame - Emit the common eh unwind frame. 74193323Sed /// 75193323Sed void EmitCommonEHFrame(const Function *Personality, unsigned Index); 76193323Sed 77193323Sed /// EmitEHFrame - Emit function exception frame information. 78193323Sed /// 79193323Sed void EmitEHFrame(const FunctionEHFrameInfo &EHFrameInfo); 80193323Sed 81193323Sed /// EmitExceptionTable - Emit landing pads and actions. 82193323Sed /// 83193323Sed /// The general organization of the table is complex, but the basic concepts 84193323Sed /// are easy. First there is a header which describes the location and 85193323Sed /// organization of the three components that follow. 86193323Sed /// 1. The landing pad site information describes the range of code covered 87193323Sed /// by the try. In our case it's an accumulation of the ranges covered 88193323Sed /// by the invokes in the try. There is also a reference to the landing 89193323Sed /// pad that handles the exception once processed. Finally an index into 90193323Sed /// the actions table. 91193323Sed /// 2. The action table, in our case, is composed of pairs of type ids 92193323Sed /// and next action offset. Starting with the action index from the 93193323Sed /// landing pad site, each type Id is checked for a match to the current 94193323Sed /// exception. If it matches then the exception and type id are passed 95193323Sed /// on to the landing pad. Otherwise the next action is looked up. This 96193323Sed /// chain is terminated with a next action of zero. If no type id is 97193323Sed /// found the the frame is unwound and handling continues. 98193323Sed /// 3. Type id table contains references to all the C++ typeinfo for all 99193323Sed /// catches in the function. This tables is reversed indexed base 1. 100193323Sed 101193323Sed /// SharedTypeIds - How many leading type ids two landing pads have in common. 102193323Sed static unsigned SharedTypeIds(const LandingPadInfo *L, 103193323Sed const LandingPadInfo *R); 104193323Sed 105193323Sed /// PadLT - Order landing pads lexicographically by type id. 106193323Sed static bool PadLT(const LandingPadInfo *L, const LandingPadInfo *R); 107193323Sed 108193323Sed struct KeyInfo { 109193323Sed static inline unsigned getEmptyKey() { return -1U; } 110193323Sed static inline unsigned getTombstoneKey() { return -2U; } 111193323Sed static unsigned getHashValue(const unsigned &Key) { return Key; } 112193323Sed static bool isEqual(unsigned LHS, unsigned RHS) { return LHS == RHS; } 113193323Sed static bool isPod() { return true; } 114193323Sed }; 115193323Sed 116193323Sed /// ActionEntry - Structure describing an entry in the actions table. 117193323Sed struct ActionEntry { 118193323Sed int ValueForTypeID; // The value to write - may not be equal to the type id. 119193323Sed int NextAction; 120193323Sed struct ActionEntry *Previous; 121193323Sed }; 122193323Sed 123193323Sed /// PadRange - Structure holding a try-range and the associated landing pad. 124193323Sed struct PadRange { 125193323Sed // The index of the landing pad. 126193323Sed unsigned PadIndex; 127193323Sed // The index of the begin and end labels in the landing pad's label lists. 128193323Sed unsigned RangeIndex; 129193323Sed }; 130193323Sed 131193323Sed typedef DenseMap<unsigned, PadRange, KeyInfo> RangeMapType; 132193323Sed 133193323Sed /// CallSiteEntry - Structure describing an entry in the call-site table. 134193323Sed struct CallSiteEntry { 135193323Sed // The 'try-range' is BeginLabel .. EndLabel. 136193323Sed unsigned BeginLabel; // zero indicates the start of the function. 137193323Sed unsigned EndLabel; // zero indicates the end of the function. 138193323Sed // The landing pad starts at PadLabel. 139193323Sed unsigned PadLabel; // zero indicates that there is no landing pad. 140193323Sed unsigned Action; 141193323Sed }; 142193323Sed 143193323Sed void EmitExceptionTable(); 144193323Sed 145193323Sedpublic: 146193323Sed //===--------------------------------------------------------------------===// 147193323Sed // Main entry points. 148193323Sed // 149193323Sed DwarfException(raw_ostream &OS, AsmPrinter *A, const TargetAsmInfo *T); 150193323Sed virtual ~DwarfException(); 151193323Sed 152193323Sed /// BeginModule - Emit all exception information that should come prior to the 153193323Sed /// content. 154195098Sed void BeginModule(Module *m, MachineModuleInfo *mmi) { 155195098Sed this->M = m; 156195098Sed this->MMI = mmi; 157193323Sed } 158193323Sed 159193323Sed /// EndModule - Emit all exception information that should come after the 160193323Sed /// content. 161193323Sed void EndModule(); 162193323Sed 163193323Sed /// BeginFunction - Gather pre-function exception information. Assumes being 164193323Sed /// emitted immediately after the function entry point. 165193323Sed void BeginFunction(MachineFunction *MF); 166193323Sed 167193323Sed /// EndFunction - Gather and emit post-function exception information. 168193323Sed void EndFunction(); 169193323Sed}; 170193323Sed 171193323Sed} // End of namespace llvm 172193323Sed 173193323Sed#endif 174