Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:00

0001 //===- EHPersonalities.h - Compute EH-related information -----------------===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_IR_EHPERSONALITIES_H
0010 #define LLVM_IR_EHPERSONALITIES_H
0011 
0012 #include "llvm/ADT/DenseMap.h"
0013 #include "llvm/ADT/TinyPtrVector.h"
0014 
0015 namespace llvm {
0016 class BasicBlock;
0017 class Function;
0018 class Triple;
0019 class Value;
0020 
0021 enum class EHPersonality {
0022   Unknown,
0023   GNU_Ada,
0024   GNU_C,
0025   GNU_C_SjLj,
0026   GNU_CXX,
0027   GNU_CXX_SjLj,
0028   GNU_ObjC,
0029   MSVC_X86SEH,
0030   MSVC_TableSEH,
0031   MSVC_CXX,
0032   CoreCLR,
0033   Rust,
0034   Wasm_CXX,
0035   XL_CXX,
0036   ZOS_CXX,
0037 };
0038 
0039 /// See if the given exception handling personality function is one
0040 /// that we understand.  If so, return a description of it; otherwise return
0041 /// Unknown.
0042 EHPersonality classifyEHPersonality(const Value *Pers);
0043 
0044 StringRef getEHPersonalityName(EHPersonality Pers);
0045 
0046 EHPersonality getDefaultEHPersonality(const Triple &T);
0047 
0048 /// Returns true if this personality function catches asynchronous
0049 /// exceptions.
0050 inline bool isAsynchronousEHPersonality(EHPersonality Pers) {
0051   // The two SEH personality functions can catch asynch exceptions. We assume
0052   // unknown personalities don't catch asynch exceptions.
0053   switch (Pers) {
0054   case EHPersonality::MSVC_X86SEH:
0055   case EHPersonality::MSVC_TableSEH:
0056     return true;
0057   default:
0058     return false;
0059   }
0060   llvm_unreachable("invalid enum");
0061 }
0062 
0063 /// Returns true if this is a personality function that invokes
0064 /// handler funclets (which must return to it).
0065 inline bool isFuncletEHPersonality(EHPersonality Pers) {
0066   switch (Pers) {
0067   case EHPersonality::MSVC_CXX:
0068   case EHPersonality::MSVC_X86SEH:
0069   case EHPersonality::MSVC_TableSEH:
0070   case EHPersonality::CoreCLR:
0071     return true;
0072   default:
0073     return false;
0074   }
0075   llvm_unreachable("invalid enum");
0076 }
0077 
0078 /// Returns true if this personality uses scope-style EH IR instructions:
0079 /// catchswitch, catchpad/ret, and cleanuppad/ret.
0080 inline bool isScopedEHPersonality(EHPersonality Pers) {
0081   switch (Pers) {
0082   case EHPersonality::MSVC_CXX:
0083   case EHPersonality::MSVC_X86SEH:
0084   case EHPersonality::MSVC_TableSEH:
0085   case EHPersonality::CoreCLR:
0086   case EHPersonality::Wasm_CXX:
0087     return true;
0088   default:
0089     return false;
0090   }
0091   llvm_unreachable("invalid enum");
0092 }
0093 
0094 /// Return true if this personality may be safely removed if there
0095 /// are no invoke instructions remaining in the current function.
0096 inline bool isNoOpWithoutInvoke(EHPersonality Pers) {
0097   switch (Pers) {
0098   case EHPersonality::Unknown:
0099     return false;
0100   // All known personalities currently have this behavior
0101   default:
0102     return true;
0103   }
0104   llvm_unreachable("invalid enum");
0105 }
0106 
0107 bool canSimplifyInvokeNoUnwind(const Function *F);
0108 
0109 typedef TinyPtrVector<BasicBlock *> ColorVector;
0110 
0111 /// If an EH funclet personality is in use (see isFuncletEHPersonality),
0112 /// this will recompute which blocks are in which funclet. It is possible that
0113 /// some blocks are in multiple funclets. Consider this analysis to be
0114 /// expensive.
0115 DenseMap<BasicBlock *, ColorVector> colorEHFunclets(Function &F);
0116 
0117 } // end namespace llvm
0118 
0119 #endif // LLVM_IR_EHPERSONALITIES_H