4a56728fbb4a93858868503eaf55acaf3ae68897
[oota-llvm.git] / include / llvm / Analysis / EHPersonalities.h
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/Support/ErrorHandling.h"
14
15 namespace llvm {
16 class Function;
17 class Value;
18
19 enum class EHPersonality {
20   Unknown,
21   GNU_Ada,
22   GNU_C,
23   GNU_CXX,
24   GNU_ObjC,
25   MSVC_X86SEH,
26   MSVC_Win64SEH,
27   MSVC_CXX,
28   CoreCLR
29 };
30
31 /// \brief See if the given exception handling personality function is one
32 /// that we understand.  If so, return a description of it; otherwise return
33 /// Unknown.
34 EHPersonality classifyEHPersonality(const Value *Pers);
35
36 /// \brief Returns true if this personality function catches asynchronous
37 /// exceptions.
38 inline bool isAsynchronousEHPersonality(EHPersonality Pers) {
39   // The two SEH personality functions can catch asynch exceptions. We assume
40   // unknown personalities don't catch asynch exceptions.
41   switch (Pers) {
42   case EHPersonality::MSVC_X86SEH:
43   case EHPersonality::MSVC_Win64SEH:
44     return true;
45   default:
46     return false;
47   }
48   llvm_unreachable("invalid enum");
49 }
50
51 /// \brief Returns true if this is a personality function that invokes
52 /// handler funclets (which must return to it).
53 inline bool isFuncletEHPersonality(EHPersonality Pers) {
54   switch (Pers) {
55   case EHPersonality::MSVC_CXX:
56   case EHPersonality::MSVC_X86SEH:
57   case EHPersonality::MSVC_Win64SEH:
58   case EHPersonality::CoreCLR:
59     return true;
60   default:
61     return false;
62   }
63   llvm_unreachable("invalid enum");
64 }
65
66 /// \brief Return true if this personality may be safely removed if there
67 /// are no invoke instructions remaining in the current function.
68 inline bool isNoOpWithoutInvoke(EHPersonality Pers) {
69   switch (Pers) {
70   case EHPersonality::Unknown:
71     return false;
72   // All known personalities currently have this behavior
73   default:
74     return true;
75   }
76   llvm_unreachable("invalid enum");
77 }
78
79 bool canSimplifyInvokeNoUnwind(const Function *F);
80
81 } // end namespace llvm
82
83 #endif