CodeMoverUtils.h 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- Transform/Utils/CodeMoverUtils.h - CodeMover Utils -------*- 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. // This family of functions determine movements are safe on basic blocks, and
  15. // instructions contained within a function.
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_TRANSFORMS_UTILS_CODEMOVERUTILS_H
  19. #define LLVM_TRANSFORMS_UTILS_CODEMOVERUTILS_H
  20. namespace llvm {
  21. class BasicBlock;
  22. class DependenceInfo;
  23. class DominatorTree;
  24. class Instruction;
  25. class PostDominatorTree;
  26. /// Return true if \p I0 and \p I1 are control flow equivalent.
  27. /// Two instructions are control flow equivalent if their basic blocks are
  28. /// control flow equivalent.
  29. bool isControlFlowEquivalent(const Instruction &I0, const Instruction &I1,
  30. const DominatorTree &DT,
  31. const PostDominatorTree &PDT);
  32. /// Return true if \p BB0 and \p BB1 are control flow equivalent.
  33. /// Two basic blocks are control flow equivalent if when one executes, the other
  34. /// is guaranteed to execute.
  35. bool isControlFlowEquivalent(const BasicBlock &BB0, const BasicBlock &BB1,
  36. const DominatorTree &DT,
  37. const PostDominatorTree &PDT);
  38. /// Return true if \p I can be safely moved before \p InsertPoint.
  39. bool isSafeToMoveBefore(Instruction &I, Instruction &InsertPoint,
  40. DominatorTree &DT,
  41. const PostDominatorTree *PDT = nullptr,
  42. DependenceInfo *DI = nullptr,
  43. bool CheckForEntireBlock = false);
  44. /// Return true if all instructions (except the terminator) in \p BB can be
  45. /// safely moved before \p InsertPoint.
  46. bool isSafeToMoveBefore(BasicBlock &BB, Instruction &InsertPoint,
  47. DominatorTree &DT,
  48. const PostDominatorTree *PDT = nullptr,
  49. DependenceInfo *DI = nullptr);
  50. /// Move instructions, in an order-preserving manner, from \p FromBB to the
  51. /// beginning of \p ToBB when proven safe.
  52. void moveInstructionsToTheBeginning(BasicBlock &FromBB, BasicBlock &ToBB,
  53. DominatorTree &DT,
  54. const PostDominatorTree &PDT,
  55. DependenceInfo &DI);
  56. /// Move instructions, in an order-preserving manner, from \p FromBB to the end
  57. /// of \p ToBB when proven safe.
  58. void moveInstructionsToTheEnd(BasicBlock &FromBB, BasicBlock &ToBB,
  59. DominatorTree &DT, const PostDominatorTree &PDT,
  60. DependenceInfo &DI);
  61. /// In case that two BBs \p ThisBlock and \p OtherBlock are control flow
  62. /// equivalent but they do not strictly dominate and post-dominate each
  63. /// other, we determine if \p ThisBlock is reached after \p OtherBlock
  64. /// in the control flow.
  65. bool nonStrictlyPostDominate(const BasicBlock *ThisBlock,
  66. const BasicBlock *OtherBlock,
  67. const DominatorTree *DT,
  68. const PostDominatorTree *PDT);
  69. // Check if I0 is reached before I1 in the control flow.
  70. bool isReachedBefore(const Instruction *I0, const Instruction *I1,
  71. const DominatorTree *DT, const PostDominatorTree *PDT);
  72. } // end namespace llvm
  73. #endif // LLVM_TRANSFORMS_UTILS_CODEMOVERUTILS_H
  74. #ifdef __GNUC__
  75. #pragma GCC diagnostic pop
  76. #endif