EHPersonalities.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. namespace llvm {
  18. class BasicBlock;
  19. class Function;
  20. class Triple;
  21. class Value;
  22. enum class EHPersonality {
  23. Unknown,
  24. GNU_Ada,
  25. GNU_C,
  26. GNU_C_SjLj,
  27. GNU_CXX,
  28. GNU_CXX_SjLj,
  29. GNU_ObjC,
  30. MSVC_X86SEH,
  31. MSVC_TableSEH,
  32. MSVC_CXX,
  33. CoreCLR,
  34. Rust,
  35. Wasm_CXX,
  36. XL_CXX
  37. };
  38. /// 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. StringRef getEHPersonalityName(EHPersonality Pers);
  43. EHPersonality getDefaultEHPersonality(const Triple &T);
  44. /// Returns true if this personality function catches asynchronous
  45. /// exceptions.
  46. inline bool isAsynchronousEHPersonality(EHPersonality Pers) {
  47. // The two SEH personality functions can catch asynch exceptions. We assume
  48. // unknown personalities don't catch asynch exceptions.
  49. switch (Pers) {
  50. case EHPersonality::MSVC_X86SEH:
  51. case EHPersonality::MSVC_TableSEH:
  52. return true;
  53. default:
  54. return false;
  55. }
  56. llvm_unreachable("invalid enum");
  57. }
  58. /// Returns true if this is a personality function that invokes
  59. /// handler funclets (which must return to it).
  60. inline bool isFuncletEHPersonality(EHPersonality Pers) {
  61. switch (Pers) {
  62. case EHPersonality::MSVC_CXX:
  63. case EHPersonality::MSVC_X86SEH:
  64. case EHPersonality::MSVC_TableSEH:
  65. case EHPersonality::CoreCLR:
  66. return true;
  67. default:
  68. return false;
  69. }
  70. llvm_unreachable("invalid enum");
  71. }
  72. /// Returns true if this personality uses scope-style EH IR instructions:
  73. /// catchswitch, catchpad/ret, and cleanuppad/ret.
  74. inline bool isScopedEHPersonality(EHPersonality Pers) {
  75. switch (Pers) {
  76. case EHPersonality::MSVC_CXX:
  77. case EHPersonality::MSVC_X86SEH:
  78. case EHPersonality::MSVC_TableSEH:
  79. case EHPersonality::CoreCLR:
  80. case EHPersonality::Wasm_CXX:
  81. return true;
  82. default:
  83. return false;
  84. }
  85. llvm_unreachable("invalid enum");
  86. }
  87. /// Return true if this personality may be safely removed if there
  88. /// are no invoke instructions remaining in the current function.
  89. inline bool isNoOpWithoutInvoke(EHPersonality Pers) {
  90. switch (Pers) {
  91. case EHPersonality::Unknown:
  92. return false;
  93. // All known personalities currently have this behavior
  94. default:
  95. return true;
  96. }
  97. llvm_unreachable("invalid enum");
  98. }
  99. bool canSimplifyInvokeNoUnwind(const Function *F);
  100. typedef TinyPtrVector<BasicBlock *> ColorVector;
  101. /// If an EH funclet personality is in use (see isFuncletEHPersonality),
  102. /// this will recompute which blocks are in which funclet. It is possible that
  103. /// some blocks are in multiple funclets. Consider this analysis to be
  104. /// expensive.
  105. DenseMap<BasicBlock *, ColorVector> colorEHFunclets(Function &F);
  106. } // end namespace llvm
  107. #endif
  108. #ifdef __GNUC__
  109. #pragma GCC diagnostic pop
  110. #endif