1 //===- EHPersonalities.h - Compute EH-related information -----------------===//
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 #ifndef LLVM_ANALYSIS_EHPERSONALITIES_H
11 #define LLVM_ANALYSIS_EHPERSONALITIES_H
12
13 #include "llvm/ADT/DenseMap.h"
14 #include "llvm/ADT/TinyPtrVector.h"
15 #include "llvm/Support/ErrorHandling.h"
16
17 namespace llvm {
18 class BasicBlock;
19 class Function;
20 class Value;
21
22 enum class EHPersonality {
23 Unknown,
24 GNU_Ada,
25 GNU_C,
26 GNU_C_SjLj,
27 GNU_CXX,
28 GNU_CXX_SjLj,
29 GNU_ObjC,
30 MSVC_X86SEH,
31 MSVC_Win64SEH,
32 MSVC_CXX,
33 CoreCLR,
34 Rust
35 };
36
37 /// \brief See if the given exception handling personality function is one
38 /// that we understand. If so, return a description of it; otherwise return
39 /// Unknown.
40 EHPersonality classifyEHPersonality(const Value *Pers);
41
42 /// \brief Returns true if this personality function catches asynchronous
43 /// exceptions.
isAsynchronousEHPersonality(EHPersonality Pers)44 inline bool isAsynchronousEHPersonality(EHPersonality Pers) {
45 // The two SEH personality functions can catch asynch exceptions. We assume
46 // unknown personalities don't catch asynch exceptions.
47 switch (Pers) {
48 case EHPersonality::MSVC_X86SEH:
49 case EHPersonality::MSVC_Win64SEH:
50 return true;
51 default:
52 return false;
53 }
54 llvm_unreachable("invalid enum");
55 }
56
57 /// \brief Returns true if this is a personality function that invokes
58 /// handler funclets (which must return to it).
isFuncletEHPersonality(EHPersonality Pers)59 inline bool isFuncletEHPersonality(EHPersonality Pers) {
60 switch (Pers) {
61 case EHPersonality::MSVC_CXX:
62 case EHPersonality::MSVC_X86SEH:
63 case EHPersonality::MSVC_Win64SEH:
64 case EHPersonality::CoreCLR:
65 return true;
66 default:
67 return false;
68 }
69 llvm_unreachable("invalid enum");
70 }
71
72 /// \brief Return true if this personality may be safely removed if there
73 /// are no invoke instructions remaining in the current function.
isNoOpWithoutInvoke(EHPersonality Pers)74 inline bool isNoOpWithoutInvoke(EHPersonality Pers) {
75 switch (Pers) {
76 case EHPersonality::Unknown:
77 return false;
78 // All known personalities currently have this behavior
79 default:
80 return true;
81 }
82 llvm_unreachable("invalid enum");
83 }
84
85 bool canSimplifyInvokeNoUnwind(const Function *F);
86
87 typedef TinyPtrVector<BasicBlock *> ColorVector;
88
89 /// \brief If an EH funclet personality is in use (see isFuncletEHPersonality),
90 /// this will recompute which blocks are in which funclet. It is possible that
91 /// some blocks are in multiple funclets. Consider this analysis to be
92 /// expensive.
93 DenseMap<BasicBlock *, ColorVector> colorEHFunclets(Function &F);
94
95 } // end namespace llvm
96
97 #endif
98