1 //===- Transform/Utils/CodeMoverUtils.h - CodeMover Utils -------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This family of functions determine movements are safe on basic blocks, and 10 // instructions contained within a function. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef LLVM_TRANSFORMS_UTILS_CODEMOVERUTILS_H 15 #define LLVM_TRANSFORMS_UTILS_CODEMOVERUTILS_H 16 17 namespace llvm { 18 19 class BasicBlock; 20 class DependenceInfo; 21 class DominatorTree; 22 class Instruction; 23 class PostDominatorTree; 24 25 /// Return true if \p I0 and \p I1 are control flow equivalent. 26 /// Two instructions are control flow equivalent if their basic blocks are 27 /// control flow equivalent. 28 bool isControlFlowEquivalent(const Instruction &I0, const Instruction &I1, 29 const DominatorTree &DT, 30 const PostDominatorTree &PDT); 31 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 39 /// Return true if \p I can be safely moved before \p InsertPoint. 40 bool isSafeToMoveBefore(Instruction &I, Instruction &InsertPoint, 41 DominatorTree &DT, 42 const PostDominatorTree *PDT = nullptr, 43 DependenceInfo *DI = nullptr, 44 bool CheckForEntireBlock = false); 45 46 /// Return true if all instructions (except the terminator) in \p BB can be 47 /// safely moved before \p InsertPoint. 48 bool isSafeToMoveBefore(BasicBlock &BB, Instruction &InsertPoint, 49 DominatorTree &DT, 50 const PostDominatorTree *PDT = nullptr, 51 DependenceInfo *DI = nullptr); 52 53 /// Move instructions, in an order-preserving manner, from \p FromBB to the 54 /// beginning of \p ToBB when proven safe. 55 void moveInstructionsToTheBeginning(BasicBlock &FromBB, BasicBlock &ToBB, 56 DominatorTree &DT, 57 const PostDominatorTree &PDT, 58 DependenceInfo &DI); 59 60 /// Move instructions, in an order-preserving manner, from \p FromBB to the end 61 /// of \p ToBB when proven safe. 62 void moveInstructionsToTheEnd(BasicBlock &FromBB, BasicBlock &ToBB, 63 DominatorTree &DT, const PostDominatorTree &PDT, 64 DependenceInfo &DI); 65 66 /// In case that two BBs \p ThisBlock and \p OtherBlock are control flow 67 /// equivalent but they do not strictly dominate and post-dominate each 68 /// other, we determine if \p ThisBlock is reached after \p OtherBlock 69 /// in the control flow. 70 bool nonStrictlyPostDominate(const BasicBlock *ThisBlock, 71 const BasicBlock *OtherBlock, 72 const DominatorTree *DT, 73 const PostDominatorTree *PDT); 74 75 // Check if I0 is reached before I1 in the control flow. 76 bool isReachedBefore(const Instruction *I0, const Instruction *I1, 77 const DominatorTree *DT, const PostDominatorTree *PDT); 78 79 } // end namespace llvm 80 81 #endif // LLVM_TRANSFORMS_UTILS_CODEMOVERUTILS_H 82