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/ADT/DenseMap.h" 14 #include "llvm/ADT/TinyPtrVector.h" 15 #include "llvm/ADT/Triple.h" 16 #include "llvm/Support/ErrorHandling.h" 17 18 namespace llvm { 19 class BasicBlock; 20 class Function; 21 class Value; 22 23 enum 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, 35 Rust 36 }; 37 38 /// \brief See if the given exception handling personality function is one 39 /// that we understand. If so, return a description of it; otherwise return 40 /// Unknown. 41 EHPersonality classifyEHPersonality(const Value *Pers); 42 43 StringRef getEHPersonalityName(EHPersonality Pers); 44 45 EHPersonality getDefaultEHPersonality(const Triple &T); 46 47 /// \brief Returns true if this personality function catches asynchronous 48 /// exceptions. 49 inline bool isAsynchronousEHPersonality(EHPersonality Pers) { 50 // The two SEH personality functions can catch asynch exceptions. We assume 51 // unknown personalities don't catch asynch exceptions. 52 switch (Pers) { 53 case EHPersonality::MSVC_X86SEH: 54 case EHPersonality::MSVC_Win64SEH: 55 return true; 56 default: 57 return false; 58 } 59 llvm_unreachable("invalid enum"); 60 } 61 62 /// \brief Returns true if this is a personality function that invokes 63 /// handler funclets (which must return to it). 64 inline bool isFuncletEHPersonality(EHPersonality Pers) { 65 switch (Pers) { 66 case EHPersonality::MSVC_CXX: 67 case EHPersonality::MSVC_X86SEH: 68 case EHPersonality::MSVC_Win64SEH: 69 case EHPersonality::CoreCLR: 70 return true; 71 default: 72 return false; 73 } 74 llvm_unreachable("invalid enum"); 75 } 76 77 /// \brief Return true if this personality may be safely removed if there 78 /// are no invoke instructions remaining in the current function. 79 inline bool isNoOpWithoutInvoke(EHPersonality Pers) { 80 switch (Pers) { 81 case EHPersonality::Unknown: 82 return false; 83 // All known personalities currently have this behavior 84 default: 85 return true; 86 } 87 llvm_unreachable("invalid enum"); 88 } 89 90 bool canSimplifyInvokeNoUnwind(const Function *F); 91 92 typedef TinyPtrVector<BasicBlock *> ColorVector; 93 94 /// \brief If an EH funclet personality is in use (see isFuncletEHPersonality), 95 /// this will recompute which blocks are in which funclet. It is possible that 96 /// some blocks are in multiple funclets. Consider this analysis to be 97 /// expensive. 98 DenseMap<BasicBlock *, ColorVector> colorEHFunclets(Function &F); 99 100 } // end namespace llvm 101 102 #endif 103