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