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