LLVM  3.7.0
EHStreamer.h
Go to the documentation of this file.
1 //===-- EHStreamer.h - Exception Handling Directive Streamer ---*- 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 exception info into assembly files.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_EHSTREAMER_H
15 #define LLVM_LIB_CODEGEN_ASMPRINTER_EHSTREAMER_H
16 
17 #include "AsmPrinterHandler.h"
18 #include "llvm/ADT/DenseMap.h"
19 
20 namespace llvm {
21 struct LandingPadInfo;
22 class MachineModuleInfo;
23 class MachineInstr;
24 class MachineFunction;
25 class AsmPrinter;
26 class MCSymbol;
27 class MCSymbolRefExpr;
28 
29 template <typename T>
30 class SmallVectorImpl;
31 
32 /// Emits exception handling directives.
34 protected:
35  /// Target of directive emission.
37 
38  /// Collected machine module information.
40 
41  /// How many leading type ids two landing pads have in common.
42  static unsigned sharedTypeIDs(const LandingPadInfo *L,
43  const LandingPadInfo *R);
44 
45  /// Structure holding a try-range and the associated landing pad.
46  struct PadRange {
47  // The index of the landing pad.
48  unsigned PadIndex;
49  // The index of the begin and end labels in the landing pad's label lists.
50  unsigned RangeIndex;
51  };
52 
54 
55  /// Structure describing an entry in the actions table.
56  struct ActionEntry {
57  int ValueForTypeID; // The value to write - may not be equal to the type id.
59  unsigned Previous;
60  };
61 
62  /// Structure describing an entry in the call-site table.
63  struct CallSiteEntry {
64  // The 'try-range' is BeginLabel .. EndLabel.
65  MCSymbol *BeginLabel; // Null indicates the start of the function.
66  MCSymbol *EndLabel; // Null indicates the end of the function.
67 
68  // LPad contains the landing pad start labels.
69  const LandingPadInfo *LPad; // Null indicates that there is no landing pad.
70  unsigned Action;
71  };
72 
73  /// Compute the actions table and gather the first action index for each
74  /// landing pad site.
75  unsigned computeActionsTable(const SmallVectorImpl<const LandingPadInfo*>&LPs,
77  SmallVectorImpl<unsigned> &FirstActions);
78 
79  /// Return `true' if this is a call to a function marked `nounwind'. Return
80  /// `false' otherwise.
81  bool callToNoUnwindFunction(const MachineInstr *MI);
82 
83  void computePadMap(const SmallVectorImpl<const LandingPadInfo *> &LandingPads,
84  RangeMapType &PadMap);
85 
86  /// Compute the call-site table. The entry for an invoke has a try-range
87  /// containing the call, a non-zero landing pad and an appropriate action.
88  /// The entry for an ordinary call has a try-range containing the call and
89  /// zero for the landing pad and the action. Calls marked 'nounwind' have
90  /// no entry and must not be contained in the try-range of any entry - they
91  /// form gaps in the table. Entries must be ordered by try-range address.
92  void computeCallSiteTable(SmallVectorImpl<CallSiteEntry> &CallSites,
94  const SmallVectorImpl<unsigned> &FirstActions);
95 
96  /// Emit landing pads and actions.
97  ///
98  /// The general organization of the table is complex, but the basic concepts
99  /// are easy. First there is a header which describes the location and
100  /// organization of the three components that follow.
101  /// 1. The landing pad site information describes the range of code covered
102  /// by the try. In our case it's an accumulation of the ranges covered
103  /// by the invokes in the try. There is also a reference to the landing
104  /// pad that handles the exception once processed. Finally an index into
105  /// the actions table.
106  /// 2. The action table, in our case, is composed of pairs of type ids
107  /// and next action offset. Starting with the action index from the
108  /// landing pad site, each type Id is checked for a match to the current
109  /// exception. If it matches then the exception and type id are passed
110  /// on to the landing pad. Otherwise the next action is looked up. This
111  /// chain is terminated with a next action of zero. If no type id is
112  /// found the frame is unwound and handling continues.
113  /// 3. Type id table contains references to all the C++ typeinfo for all
114  /// catches in the function. This tables is reversed indexed base 1.
115  void emitExceptionTable();
116 
117  virtual void emitTypeInfos(unsigned TTypeEncoding);
118 
119  // Helpers for for identifying what kind of clause an EH typeid or selector
120  // corresponds to. Negative selectors are for filter clauses, the zero
121  // selector is for cleanups, and positive selectors are for catch clauses.
122  static bool isFilterEHSelector(int Selector) { return Selector < 0; }
123  static bool isCleanupEHSelector(int Selector) { return Selector == 0; }
124  static bool isCatchEHSelector(int Selector) { return Selector > 0; }
125 
126 public:
128  ~EHStreamer() override;
129 
130  // Unused.
131  void setSymbolSize(const MCSymbol *Sym, uint64_t Size) override {}
132  void beginInstruction(const MachineInstr *MI) override {}
133  void endInstruction() override {}
134 };
135 }
136 
137 #endif
138 
Structure describing an entry in the call-site table.
Definition: EHStreamer.h:63
DenseMap< MCSymbol *, PadRange > RangeMapType
Definition: EHStreamer.h:53
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:39
void setSymbolSize(const MCSymbol *Sym, uint64_t Size) override
For symbols that have a size designated (e.g.
Definition: EHStreamer.h:131
Collects and handles AsmPrinter objects required to build debug or EH information.
Structure describing an entry in the actions table.
Definition: EHStreamer.h:56
static bool isFilterEHSelector(int Selector)
Definition: EHStreamer.h:122
const LandingPadInfo * LPad
Definition: EHStreamer.h:69
MachineModuleInfo * MMI
Collected machine module information.
Definition: EHStreamer.h:39
Emits exception handling directives.
Definition: EHStreamer.h:33
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APInt.h:33
LandingPadInfo - This structure is used to retain landing pad info for the current function...
void beginInstruction(const MachineInstr *MI) override
Process beginning of an instruction.
Definition: EHStreamer.h:132
static bool isCatchEHSelector(int Selector)
Definition: EHStreamer.h:124
static bool isCleanupEHSelector(int Selector)
Definition: EHStreamer.h:123
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:66
#define LLVM_LIBRARY_VISIBILITY
LLVM_LIBRARY_VISIBILITY - If a class marked with this attribute is linked into a shared library...
Definition: Compiler.h:110
AsmPrinter * Asm
Target of directive emission.
Definition: EHStreamer.h:36
void endInstruction() override
Process end of an instruction.
Definition: EHStreamer.h:133
Representation of each machine instruction.
Definition: MachineInstr.h:51
Structure holding a try-range and the associated landing pad.
Definition: EHStreamer.h:46
MachineModuleInfo - This class contains meta information specific to a module.