blob: fe0e65b828cac2cbeae9ce310d69410a30fd23ac [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===- 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/ADT/Triple.h"
16#include "llvm/Support/ErrorHandling.h"
17
18namespace llvm {
19class BasicBlock;
20class Function;
21class Value;
22
23enum class EHPersonality {
24 Unknown,
25 GNU_Ada,
26 GNU_C,
27 GNU_C_SjLj,
28 GNU_CXX,
29 GNU_CXX_SjLj,
30 GNU_ObjC,
31 MSVC_X86SEH,
32 MSVC_Win64SEH,
33 MSVC_CXX,
34 CoreCLR,
Andrew Scullcdfcccc2018-10-05 20:58:37 +010035 Rust,
36 Wasm_CXX
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010037};
38
Andrew Scullcdfcccc2018-10-05 20:58:37 +010039/// See if the given exception handling personality function is one
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010040/// that we understand. If so, return a description of it; otherwise return
41/// Unknown.
42EHPersonality classifyEHPersonality(const Value *Pers);
43
44StringRef getEHPersonalityName(EHPersonality Pers);
45
46EHPersonality getDefaultEHPersonality(const Triple &T);
47
Andrew Scullcdfcccc2018-10-05 20:58:37 +010048/// Returns true if this personality function catches asynchronous
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010049/// exceptions.
50inline bool isAsynchronousEHPersonality(EHPersonality Pers) {
51 // The two SEH personality functions can catch asynch exceptions. We assume
52 // unknown personalities don't catch asynch exceptions.
53 switch (Pers) {
54 case EHPersonality::MSVC_X86SEH:
55 case EHPersonality::MSVC_Win64SEH:
56 return true;
57 default:
58 return false;
59 }
60 llvm_unreachable("invalid enum");
61}
62
Andrew Scullcdfcccc2018-10-05 20:58:37 +010063/// Returns true if this is a personality function that invokes
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010064/// handler funclets (which must return to it).
65inline bool isFuncletEHPersonality(EHPersonality Pers) {
66 switch (Pers) {
67 case EHPersonality::MSVC_CXX:
68 case EHPersonality::MSVC_X86SEH:
69 case EHPersonality::MSVC_Win64SEH:
70 case EHPersonality::CoreCLR:
71 return true;
72 default:
73 return false;
74 }
75 llvm_unreachable("invalid enum");
76}
77
Andrew Scullcdfcccc2018-10-05 20:58:37 +010078/// Returns true if this personality uses scope-style EH IR instructions:
79/// catchswitch, catchpad/ret, and cleanuppad/ret.
80inline bool isScopedEHPersonality(EHPersonality Pers) {
81 switch (Pers) {
82 case EHPersonality::MSVC_CXX:
83 case EHPersonality::MSVC_X86SEH:
84 case EHPersonality::MSVC_Win64SEH:
85 case EHPersonality::CoreCLR:
86 case EHPersonality::Wasm_CXX:
87 return true;
88 default:
89 return false;
90 }
91 llvm_unreachable("invalid enum");
92}
93
94/// Return true if this personality may be safely removed if there
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010095/// are no invoke instructions remaining in the current function.
96inline bool isNoOpWithoutInvoke(EHPersonality Pers) {
97 switch (Pers) {
98 case EHPersonality::Unknown:
99 return false;
100 // All known personalities currently have this behavior
101 default:
102 return true;
103 }
104 llvm_unreachable("invalid enum");
105}
106
107bool canSimplifyInvokeNoUnwind(const Function *F);
108
109typedef TinyPtrVector<BasicBlock *> ColorVector;
110
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100111/// If an EH funclet personality is in use (see isFuncletEHPersonality),
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100112/// this will recompute which blocks are in which funclet. It is possible that
113/// some blocks are in multiple funclets. Consider this analysis to be
114/// expensive.
115DenseMap<BasicBlock *, ColorVector> colorEHFunclets(Function &F);
116
117} // end namespace llvm
118
119#endif