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 when one executes,
27 /// the other is guaranteed to execute. This is determined using dominators
28 /// and post-dominators: if A dominates B and B post-dominates A then A and B
29 /// are control-flow equivalent.
30 bool isControlFlowEquivalent(const Instruction &I0, const Instruction &I1,
31                              const DominatorTree &DT,
32                              const PostDominatorTree &PDT);
33 
34 /// Return true if \p BB0 and \p BB1 are control flow equivalent.
35 /// Two basic blocks are control flow equivalent if when one executes, the other
36 /// is guaranteed to execute. This is determined using dominators and
37 /// post-dominators: if A dominates B and B post-dominates A then A and B are
38 /// control-flow equivalent.
39 bool isControlFlowEquivalent(const BasicBlock &BB0, const BasicBlock &BB1,
40                              const DominatorTree &DT,
41                              const PostDominatorTree &PDT);
42 
43 /// Return true if \p I can be safely moved before \p InsertPoint.
44 bool isSafeToMoveBefore(Instruction &I, Instruction &InsertPoint,
45                         const DominatorTree &DT, const PostDominatorTree &PDT,
46                         DependenceInfo &DI);
47 
48 /// Move instructions from \p FromBB bottom up to the beginning of \p ToBB
49 /// when proven safe.
50 void moveInstsBottomUp(BasicBlock &FromBB, BasicBlock &ToBB,
51                        const DominatorTree &DT, const PostDominatorTree &PDT,
52                        DependenceInfo &DI);
53 
54 } // end namespace llvm
55 
56 #endif // LLVM_TRANSFORMS_UTILS_CODEMOVERUTILS_H
57