LLVM 17.0.0git
CodeMoverUtils.h
Go to the documentation of this file.
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
17namespace llvm {
18
19class BasicBlock;
20class DependenceInfo;
21class DominatorTree;
22class Instruction;
23class 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.
28bool 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.
35bool 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.
40bool 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.
48bool 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.
55void 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.
62void 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.
70bool 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.
76bool 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
#define I(x, y, z)
Definition: MD5.cpp:58
@ BasicBlock
Various leaf nodes.
Definition: ISDOpcodes.h:71
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void moveInstructionsToTheEnd(BasicBlock &FromBB, BasicBlock &ToBB, DominatorTree &DT, const PostDominatorTree &PDT, DependenceInfo &DI)
Move instructions, in an order-preserving manner, from FromBB to the end of ToBB when proven safe.
bool isReachedBefore(const Instruction *I0, const Instruction *I1, const DominatorTree *DT, const PostDominatorTree *PDT)
bool isControlFlowEquivalent(const Instruction &I0, const Instruction &I1, const DominatorTree &DT, const PostDominatorTree &PDT)
Return true if I0 and I1 are control flow equivalent.
bool nonStrictlyPostDominate(const BasicBlock *ThisBlock, const BasicBlock *OtherBlock, const DominatorTree *DT, const PostDominatorTree *PDT)
In case that two BBs ThisBlock and OtherBlock are control flow equivalent but they do not strictly do...
void moveInstructionsToTheBeginning(BasicBlock &FromBB, BasicBlock &ToBB, DominatorTree &DT, const PostDominatorTree &PDT, DependenceInfo &DI)
Move instructions, in an order-preserving manner, from FromBB to the beginning of ToBB when proven sa...
bool isSafeToMoveBefore(Instruction &I, Instruction &InsertPoint, DominatorTree &DT, const PostDominatorTree *PDT=nullptr, DependenceInfo *DI=nullptr, bool CheckForEntireBlock=false)
Return true if I can be safely moved before InsertPoint.