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