UnifyFunctionExitNodes.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //===-- UnifyFunctionExitNodes.h - Ensure fn's have one return --*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This pass is used to ensure that functions have at most one return and one
  11. // unwind instruction in them. Additionally, it keeps track of which node is
  12. // the new exit node of the CFG. If there are no return or unwind instructions
  13. // in the function, the getReturnBlock/getUnwindBlock methods will return a null
  14. // pointer.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_TRANSFORMS_UTILS_UNIFYFUNCTIONEXITNODES_H
  18. #define LLVM_TRANSFORMS_UTILS_UNIFYFUNCTIONEXITNODES_H
  19. #include "llvm/Pass.h"
  20. namespace llvm {
  21. struct UnifyFunctionExitNodes : public FunctionPass {
  22. BasicBlock *ReturnBlock, *UnwindBlock, *UnreachableBlock;
  23. public:
  24. static char ID; // Pass identification, replacement for typeid
  25. UnifyFunctionExitNodes() : FunctionPass(ID),
  26. ReturnBlock(nullptr), UnwindBlock(nullptr) {
  27. initializeUnifyFunctionExitNodesPass(*PassRegistry::getPassRegistry());
  28. }
  29. // We can preserve non-critical-edgeness when we unify function exit nodes
  30. void getAnalysisUsage(AnalysisUsage &AU) const override;
  31. // getReturn|Unwind|UnreachableBlock - Return the new single (or nonexistent)
  32. // return, unwind, or unreachable basic blocks in the CFG.
  33. //
  34. BasicBlock *getReturnBlock() const { return ReturnBlock; }
  35. BasicBlock *getUnwindBlock() const { return UnwindBlock; }
  36. BasicBlock *getUnreachableBlock() const { return UnreachableBlock; }
  37. bool runOnFunction(Function &F) override;
  38. };
  39. Pass *createUnifyFunctionExitNodesPass();
  40. } // End llvm namespace
  41. #endif