EHPersonalities.h 3.4 KB

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