EscapeEnumerator.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===-- EscapeEnumerator.h --------------------------------------*- C++ -*-===//
  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. //
  14. // Defines a helper class that enumerates all possible exits from a function,
  15. // including exception handling.
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_TRANSFORMS_UTILS_ESCAPEENUMERATOR_H
  19. #define LLVM_TRANSFORMS_UTILS_ESCAPEENUMERATOR_H
  20. #include "llvm/IR/Function.h"
  21. #include "llvm/IR/IRBuilder.h"
  22. namespace llvm {
  23. class DomTreeUpdater;
  24. /// EscapeEnumerator - This is a little algorithm to find all escape points
  25. /// from a function so that "finally"-style code can be inserted. In addition
  26. /// to finding the existing return and unwind instructions, it also (if
  27. /// necessary) transforms any call instructions into invokes and sends them to
  28. /// a landing pad.
  29. class EscapeEnumerator {
  30. Function &F;
  31. const char *CleanupBBName;
  32. Function::iterator StateBB, StateE;
  33. IRBuilder<> Builder;
  34. bool Done = false;
  35. bool HandleExceptions;
  36. DomTreeUpdater *DTU;
  37. public:
  38. EscapeEnumerator(Function &F, const char *N = "cleanup",
  39. bool HandleExceptions = true, DomTreeUpdater *DTU = nullptr)
  40. : F(F), CleanupBBName(N), StateBB(F.begin()), StateE(F.end()),
  41. Builder(F.getContext()), HandleExceptions(HandleExceptions), DTU(DTU) {}
  42. IRBuilder<> *Next();
  43. };
  44. }
  45. #endif // LLVM_TRANSFORMS_UTILS_ESCAPEENUMERATOR_H
  46. #ifdef __GNUC__
  47. #pragma GCC diagnostic pop
  48. #endif