1 //===- EHPersonalities.h - Compute EH-related information -----------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_IR_EHPERSONALITIES_H
10 #define LLVM_IR_EHPERSONALITIES_H
11
12 #include "llvm/ADT/DenseMap.h"
13 #include "llvm/ADT/TinyPtrVector.h"
14 #include "llvm/Support/Compiler.h"
15
16 namespace llvm {
17 class BasicBlock;
18 class Function;
19 class Triple;
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_TableSEH,
32 MSVC_CXX,
33 CoreCLR,
34 Rust,
35 Wasm_CXX,
36 XL_CXX,
37 ZOS_CXX,
38 };
39
40 /// See if the given exception handling personality function is one
41 /// that we understand. If so, return a description of it; otherwise return
42 /// Unknown.
43 LLVM_ABI EHPersonality classifyEHPersonality(const Value *Pers);
44
45 LLVM_ABI StringRef getEHPersonalityName(EHPersonality Pers);
46
47 LLVM_ABI EHPersonality getDefaultEHPersonality(const Triple &T);
48
49 /// Returns true if this personality function catches asynchronous
50 /// exceptions.
isAsynchronousEHPersonality(EHPersonality Pers)51 inline bool isAsynchronousEHPersonality(EHPersonality Pers) {
52 // The two SEH personality functions can catch asynch exceptions. We assume
53 // unknown personalities don't catch asynch exceptions.
54 switch (Pers) {
55 case EHPersonality::MSVC_X86SEH:
56 case EHPersonality::MSVC_TableSEH:
57 return true;
58 default:
59 return false;
60 }
61 llvm_unreachable("invalid enum");
62 }
63
64 /// Returns true if this is a personality function that invokes
65 /// handler funclets (which must return to it).
isFuncletEHPersonality(EHPersonality Pers)66 inline bool isFuncletEHPersonality(EHPersonality Pers) {
67 switch (Pers) {
68 case EHPersonality::MSVC_CXX:
69 case EHPersonality::MSVC_X86SEH:
70 case EHPersonality::MSVC_TableSEH:
71 case EHPersonality::CoreCLR:
72 return true;
73 default:
74 return false;
75 }
76 llvm_unreachable("invalid enum");
77 }
78
79 /// Returns true if this personality uses scope-style EH IR instructions:
80 /// catchswitch, catchpad/ret, and cleanuppad/ret.
isScopedEHPersonality(EHPersonality Pers)81 inline bool isScopedEHPersonality(EHPersonality Pers) {
82 switch (Pers) {
83 case EHPersonality::MSVC_CXX:
84 case EHPersonality::MSVC_X86SEH:
85 case EHPersonality::MSVC_TableSEH:
86 case EHPersonality::CoreCLR:
87 case EHPersonality::Wasm_CXX:
88 return true;
89 default:
90 return false;
91 }
92 llvm_unreachable("invalid enum");
93 }
94
95 /// Return true if this personality may be safely removed if there
96 /// are no invoke instructions remaining in the current function.
isNoOpWithoutInvoke(EHPersonality Pers)97 inline bool isNoOpWithoutInvoke(EHPersonality Pers) {
98 switch (Pers) {
99 case EHPersonality::Unknown:
100 return false;
101 // All known personalities currently have this behavior
102 default:
103 return true;
104 }
105 llvm_unreachable("invalid enum");
106 }
107
108 LLVM_ABI bool canSimplifyInvokeNoUnwind(const Function *F);
109
110 typedef TinyPtrVector<BasicBlock *> ColorVector;
111
112 /// If an EH funclet personality is in use (see isFuncletEHPersonality),
113 /// this will recompute which blocks are in which funclet. It is possible that
114 /// some blocks are in multiple funclets. Consider this analysis to be
115 /// expensive.
116 LLVM_ABI DenseMap<BasicBlock *, ColorVector> colorEHFunclets(Function &F);
117
118 } // end namespace llvm
119
120 #endif // LLVM_IR_EHPERSONALITIES_H
121