LLVM API Documentation

DwarfException.h
Go to the documentation of this file.
00001 //===-- DwarfException.h - Dwarf Exception Framework -----------*- C++ -*--===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file contains support for writing dwarf exception info into asm files.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_CODEGEN_ASMPRINTER_DWARFEXCEPTION_H
00015 #define LLVM_CODEGEN_ASMPRINTER_DWARFEXCEPTION_H
00016 
00017 #include "llvm/ADT/DenseMap.h"
00018 #include "llvm/CodeGen/AsmPrinter.h"
00019 #include <vector>
00020 
00021 namespace llvm {
00022 
00023 template <typename T> class SmallVectorImpl;
00024 struct LandingPadInfo;
00025 class MachineModuleInfo;
00026 class MachineInstr;
00027 class MachineFunction;
00028 class MCAsmInfo;
00029 class MCExpr;
00030 class MCSymbol;
00031 class Function;
00032 class AsmPrinter;
00033 
00034 //===----------------------------------------------------------------------===//
00035 /// DwarfException - Emits Dwarf exception handling directives.
00036 ///
00037 class DwarfException {
00038 protected:
00039   /// Asm - Target of Dwarf emission.
00040   AsmPrinter *Asm;
00041 
00042   /// MMI - Collected machine module information.
00043   MachineModuleInfo *MMI;
00044 
00045   /// SharedTypeIds - How many leading type ids two landing pads have in common.
00046   static unsigned SharedTypeIds(const LandingPadInfo *L,
00047                                 const LandingPadInfo *R);
00048 
00049   /// PadLT - Order landing pads lexicographically by type id.
00050   static bool PadLT(const LandingPadInfo *L, const LandingPadInfo *R);
00051 
00052   /// PadRange - Structure holding a try-range and the associated landing pad.
00053   struct PadRange {
00054     // The index of the landing pad.
00055     unsigned PadIndex;
00056     // The index of the begin and end labels in the landing pad's label lists.
00057     unsigned RangeIndex;
00058   };
00059 
00060   typedef DenseMap<MCSymbol *, PadRange> RangeMapType;
00061 
00062   /// ActionEntry - Structure describing an entry in the actions table.
00063   struct ActionEntry {
00064     int ValueForTypeID; // The value to write - may not be equal to the type id.
00065     int NextAction;
00066     unsigned Previous;
00067   };
00068 
00069   /// CallSiteEntry - Structure describing an entry in the call-site table.
00070   struct CallSiteEntry {
00071     // The 'try-range' is BeginLabel .. EndLabel.
00072     MCSymbol *BeginLabel; // zero indicates the start of the function.
00073     MCSymbol *EndLabel;   // zero indicates the end of the function.
00074 
00075     // The landing pad starts at PadLabel.
00076     MCSymbol *PadLabel;   // zero indicates that there is no landing pad.
00077     unsigned Action;
00078   };
00079 
00080   /// ComputeActionsTable - Compute the actions table and gather the first
00081   /// action index for each landing pad site.
00082   unsigned ComputeActionsTable(const SmallVectorImpl<const LandingPadInfo*>&LPs,
00083                                SmallVectorImpl<ActionEntry> &Actions,
00084                                SmallVectorImpl<unsigned> &FirstActions);
00085 
00086   /// CallToNoUnwindFunction - Return `true' if this is a call to a function
00087   /// marked `nounwind'. Return `false' otherwise.
00088   bool CallToNoUnwindFunction(const MachineInstr *MI);
00089 
00090   /// ComputeCallSiteTable - Compute the call-site table.  The entry for an
00091   /// invoke has a try-range containing the call, a non-zero landing pad and an
00092   /// appropriate action.  The entry for an ordinary call has a try-range
00093   /// containing the call and zero for the landing pad and the action.  Calls
00094   /// marked 'nounwind' have no entry and must not be contained in the try-range
00095   /// of any entry - they form gaps in the table.  Entries must be ordered by
00096   /// try-range address.
00097   void ComputeCallSiteTable(SmallVectorImpl<CallSiteEntry> &CallSites,
00098                             const RangeMapType &PadMap,
00099                             const SmallVectorImpl<const LandingPadInfo *> &LPs,
00100                             const SmallVectorImpl<unsigned> &FirstActions);
00101 
00102   /// EmitExceptionTable - Emit landing pads and actions.
00103   ///
00104   /// The general organization of the table is complex, but the basic concepts
00105   /// are easy.  First there is a header which describes the location and
00106   /// organization of the three components that follow.
00107   ///  1. The landing pad site information describes the range of code covered
00108   ///     by the try.  In our case it's an accumulation of the ranges covered
00109   ///     by the invokes in the try.  There is also a reference to the landing
00110   ///     pad that handles the exception once processed.  Finally an index into
00111   ///     the actions table.
00112   ///  2. The action table, in our case, is composed of pairs of type ids
00113   ///     and next action offset.  Starting with the action index from the
00114   ///     landing pad site, each type Id is checked for a match to the current
00115   ///     exception.  If it matches then the exception and type id are passed
00116   ///     on to the landing pad.  Otherwise the next action is looked up.  This
00117   ///     chain is terminated with a next action of zero.  If no type id is
00118   ///     found the frame is unwound and handling continues.
00119   ///  3. Type id table contains references to all the C++ typeinfo for all
00120   ///     catches in the function.  This tables is reversed indexed base 1.
00121   void EmitExceptionTable();
00122 
00123   virtual void EmitTypeInfos(unsigned TTypeEncoding);
00124 
00125 public:
00126   //===--------------------------------------------------------------------===//
00127   // Main entry points.
00128   //
00129   DwarfException(AsmPrinter *A);
00130   virtual ~DwarfException();
00131 
00132   /// EndModule - Emit all exception information that should come after the
00133   /// content.
00134   virtual void EndModule();
00135 
00136   /// BeginFunction - Gather pre-function exception information.  Assumes being
00137   /// emitted immediately after the function entry point.
00138   virtual void BeginFunction(const MachineFunction *MF);
00139 
00140   /// EndFunction - Gather and emit post-function exception information.
00141   virtual void EndFunction();
00142 };
00143 
00144 class DwarfCFIException : public DwarfException {
00145   /// shouldEmitPersonality - Per-function flag to indicate if .cfi_personality
00146   /// should be emitted.
00147   bool shouldEmitPersonality;
00148 
00149   /// shouldEmitLSDA - Per-function flag to indicate if .cfi_lsda
00150   /// should be emitted.
00151   bool shouldEmitLSDA;
00152 
00153   /// shouldEmitMoves - Per-function flag to indicate if frame moves info
00154   /// should be emitted.
00155   bool shouldEmitMoves;
00156 
00157   AsmPrinter::CFIMoveType moveTypeModule;
00158 
00159 public:
00160   //===--------------------------------------------------------------------===//
00161   // Main entry points.
00162   //
00163   DwarfCFIException(AsmPrinter *A);
00164   virtual ~DwarfCFIException();
00165 
00166   /// EndModule - Emit all exception information that should come after the
00167   /// content.
00168   virtual void EndModule();
00169 
00170   /// BeginFunction - Gather pre-function exception information.  Assumes being
00171   /// emitted immediately after the function entry point.
00172   virtual void BeginFunction(const MachineFunction *MF);
00173 
00174   /// EndFunction - Gather and emit post-function exception information.
00175   virtual void EndFunction();
00176 };
00177 
00178 class ARMException : public DwarfException {
00179   void EmitTypeInfos(unsigned TTypeEncoding);
00180 public:
00181   //===--------------------------------------------------------------------===//
00182   // Main entry points.
00183   //
00184   ARMException(AsmPrinter *A);
00185   virtual ~ARMException();
00186 
00187   /// EndModule - Emit all exception information that should come after the
00188   /// content.
00189   virtual void EndModule();
00190 
00191   /// BeginFunction - Gather pre-function exception information.  Assumes being
00192   /// emitted immediately after the function entry point.
00193   virtual void BeginFunction(const MachineFunction *MF);
00194 
00195   /// EndFunction - Gather and emit post-function exception information.
00196   virtual void EndFunction();
00197 };
00198 
00199 class Win64Exception : public DwarfException {
00200   /// shouldEmitPersonality - Per-function flag to indicate if personality
00201   /// info should be emitted.
00202   bool shouldEmitPersonality;
00203 
00204   /// shouldEmitLSDA - Per-function flag to indicate if the LSDA
00205   /// should be emitted.
00206   bool shouldEmitLSDA;
00207 
00208   /// shouldEmitMoves - Per-function flag to indicate if frame moves info
00209   /// should be emitted.
00210   bool shouldEmitMoves;
00211 
00212 public:
00213   //===--------------------------------------------------------------------===//
00214   // Main entry points.
00215   //
00216   Win64Exception(AsmPrinter *A);
00217   virtual ~Win64Exception();
00218 
00219   /// EndModule - Emit all exception information that should come after the
00220   /// content.
00221   virtual void EndModule();
00222 
00223   /// BeginFunction - Gather pre-function exception information.  Assumes being
00224   /// emitted immediately after the function entry point.
00225   virtual void BeginFunction(const MachineFunction *MF);
00226 
00227   /// EndFunction - Gather and emit post-function exception information.
00228   virtual void EndFunction();
00229 };
00230 
00231 } // End of namespace llvm
00232 
00233 #endif