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