EHPersonalities.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. //===- EHPersonalities.h - Compute EH-related information -----------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #ifndef LLVM_ANALYSIS_EHPERSONALITIES_H
  9. #define LLVM_ANALYSIS_EHPERSONALITIES_H
  10. #include "llvm/ADT/DenseMap.h"
  11. #include "llvm/ADT/TinyPtrVector.h"
  12. #include "llvm/Support/ErrorHandling.h"
  13. namespace llvm {
  14. class BasicBlock;
  15. class Function;
  16. class Triple;
  17. class Value;
  18. enum class EHPersonality {
  19. Unknown,
  20. GNU_Ada,
  21. GNU_C,
  22. GNU_C_SjLj,
  23. GNU_CXX,
  24. GNU_CXX_SjLj,
  25. GNU_ObjC,
  26. MSVC_X86SEH,
  27. MSVC_TableSEH,
  28. MSVC_CXX,
  29. CoreCLR,
  30. Rust,
  31. Wasm_CXX,
  32. XL_CXX
  33. };
  34. /// 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. StringRef getEHPersonalityName(EHPersonality Pers);
  39. EHPersonality getDefaultEHPersonality(const Triple &T);
  40. /// Returns true if this personality function catches asynchronous
  41. /// exceptions.
  42. inline bool isAsynchronousEHPersonality(EHPersonality Pers) {
  43. // The two SEH personality functions can catch asynch exceptions. We assume
  44. // unknown personalities don't catch asynch exceptions.
  45. switch (Pers) {
  46. case EHPersonality::MSVC_X86SEH:
  47. case EHPersonality::MSVC_TableSEH:
  48. return true;
  49. default:
  50. return false;
  51. }
  52. llvm_unreachable("invalid enum");
  53. }
  54. /// Returns true if this is a personality function that invokes
  55. /// handler funclets (which must return to it).
  56. inline bool isFuncletEHPersonality(EHPersonality Pers) {
  57. switch (Pers) {
  58. case EHPersonality::MSVC_CXX:
  59. case EHPersonality::MSVC_X86SEH:
  60. case EHPersonality::MSVC_TableSEH:
  61. case EHPersonality::CoreCLR:
  62. return true;
  63. default:
  64. return false;
  65. }
  66. llvm_unreachable("invalid enum");
  67. }
  68. /// Returns true if this personality uses scope-style EH IR instructions:
  69. /// catchswitch, catchpad/ret, and cleanuppad/ret.
  70. inline bool isScopedEHPersonality(EHPersonality Pers) {
  71. switch (Pers) {
  72. case EHPersonality::MSVC_CXX:
  73. case EHPersonality::MSVC_X86SEH:
  74. case EHPersonality::MSVC_TableSEH:
  75. case EHPersonality::CoreCLR:
  76. case EHPersonality::Wasm_CXX:
  77. return true;
  78. default:
  79. return false;
  80. }
  81. llvm_unreachable("invalid enum");
  82. }
  83. /// Return true if this personality may be safely removed if there
  84. /// are no invoke instructions remaining in the current function.
  85. inline bool isNoOpWithoutInvoke(EHPersonality Pers) {
  86. switch (Pers) {
  87. case EHPersonality::Unknown:
  88. return false;
  89. // All known personalities currently have this behavior
  90. default:
  91. return true;
  92. }
  93. llvm_unreachable("invalid enum");
  94. }
  95. bool canSimplifyInvokeNoUnwind(const Function *F);
  96. typedef TinyPtrVector<BasicBlock *> ColorVector;
  97. /// If an EH funclet personality is in use (see isFuncletEHPersonality),
  98. /// this will recompute which blocks are in which funclet. It is possible that
  99. /// some blocks are in multiple funclets. Consider this analysis to be
  100. /// expensive.
  101. DenseMap<BasicBlock *, ColorVector> colorEHFunclets(Function &F);
  102. } // end namespace llvm
  103. #endif