EscapeEnumerator.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. /// EscapeEnumerator - This is a little algorithm to find all escape points
  24. /// from a function so that "finally"-style code can be inserted. In addition
  25. /// to finding the existing return and unwind instructions, it also (if
  26. /// necessary) transforms any call instructions into invokes and sends them to
  27. /// a landing pad.
  28. class EscapeEnumerator {
  29. Function &F;
  30. const char *CleanupBBName;
  31. Function::iterator StateBB, StateE;
  32. IRBuilder<> Builder;
  33. bool Done;
  34. bool HandleExceptions;
  35. public:
  36. EscapeEnumerator(Function &F, const char *N = "cleanup",
  37. bool HandleExceptions = true)
  38. : F(F), CleanupBBName(N), StateBB(F.begin()), StateE(F.end()),
  39. Builder(F.getContext()), Done(false),
  40. HandleExceptions(HandleExceptions) {}
  41. IRBuilder<> *Next();
  42. };
  43. }
  44. #endif // LLVM_TRANSFORMS_UTILS_ESCAPEENUMERATOR_H
  45. #ifdef __GNUC__
  46. #pragma GCC diagnostic pop
  47. #endif