[WinEH] Recognize CoreCLR personality function
[oota-llvm.git] / lib / Analysis / LibCallSemantics.cpp
1 //===- LibCallSemantics.cpp - 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 implements interfaces that can be used to describe language
11 // specific runtime library interfaces (e.g. libc, libm, etc) to LLVM
12 // optimizers.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #include "llvm/Analysis/LibCallSemantics.h"
17 #include "llvm/ADT/StringSwitch.h"
18 #include "llvm/IR/Function.h"
19 using namespace llvm;
20
21 /// See if the given exception handling personality function is one that we
22 /// understand.  If so, return a description of it; otherwise return Unknown.
23 EHPersonality llvm::classifyEHPersonality(const Value *Pers) {
24   const Function *F =
25       Pers ? dyn_cast<Function>(Pers->stripPointerCasts()) : nullptr;
26   if (!F)
27     return EHPersonality::Unknown;
28   return StringSwitch<EHPersonality>(F->getName())
29     .Case("__gnat_eh_personality", EHPersonality::GNU_Ada)
30     .Case("__gxx_personality_v0",  EHPersonality::GNU_CXX)
31     .Case("__gcc_personality_v0",  EHPersonality::GNU_C)
32     .Case("__objc_personality_v0", EHPersonality::GNU_ObjC)
33     .Case("_except_handler3",      EHPersonality::MSVC_X86SEH)
34     .Case("_except_handler4",      EHPersonality::MSVC_X86SEH)
35     .Case("__C_specific_handler",  EHPersonality::MSVC_Win64SEH)
36     .Case("__CxxFrameHandler3",    EHPersonality::MSVC_CXX)
37     .Case("ProcessCLRException",   EHPersonality::CoreCLR)
38     .Default(EHPersonality::Unknown);
39 }
40
41 bool llvm::canSimplifyInvokeNoUnwind(const Function *F) {
42   EHPersonality Personality = classifyEHPersonality(F->getPersonalityFn());
43   // We can't simplify any invokes to nounwind functions if the personality
44   // function wants to catch asynch exceptions.  The nounwind attribute only
45   // implies that the function does not throw synchronous exceptions.
46   return !isAsynchronousEHPersonality(Personality);
47 }