LLVM 20.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// Please note that this is work in progress, and the functionality is not
13// ready for broader production use.
14//
15//===----------------------------------------------------------------------===//
16
17#ifndef LLVM_TRANSFORMS_UTILS_CODEMOVERUTILS_H
18#define LLVM_TRANSFORMS_UTILS_CODEMOVERUTILS_H
19
20namespace llvm {
21
22class BasicBlock;
23class DependenceInfo;
24class DominatorTree;
25class Instruction;
26class PostDominatorTree;
27
28/// Return true if \p I0 and \p I1 are control flow equivalent.
29/// Two instructions are control flow equivalent if their basic blocks are
30/// control flow equivalent.
31bool isControlFlowEquivalent(const Instruction &I0, const Instruction &I1,
32 const DominatorTree &DT,
33 const PostDominatorTree &PDT);
34
35/// Return true if \p BB0 and \p BB1 are control flow equivalent.
36/// Two basic blocks are control flow equivalent if when one executes, the other
37/// is guaranteed to execute.
38bool isControlFlowEquivalent(const BasicBlock &BB0, const BasicBlock &BB1,
39 const DominatorTree &DT,
40 const PostDominatorTree &PDT);
41
42/// Return true if \p I can be safely moved before \p InsertPoint.
43bool isSafeToMoveBefore(Instruction &I, Instruction &InsertPoint,
44 DominatorTree &DT,
45 const PostDominatorTree *PDT = nullptr,
46 DependenceInfo *DI = nullptr,
47 bool CheckForEntireBlock = false);
48
49/// Return true if all instructions (except the terminator) in \p BB can be
50/// safely moved before \p InsertPoint.
51bool isSafeToMoveBefore(BasicBlock &BB, Instruction &InsertPoint,
52 DominatorTree &DT,
53 const PostDominatorTree *PDT = nullptr,
54 DependenceInfo *DI = nullptr);
55
56/// Move instructions, in an order-preserving manner, from \p FromBB to the
57/// beginning of \p ToBB when proven safe.
58void moveInstructionsToTheBeginning(BasicBlock &FromBB, BasicBlock &ToBB,
59 DominatorTree &DT,
60 const PostDominatorTree &PDT,
61 DependenceInfo &DI);
62
63/// Move instructions, in an order-preserving manner, from \p FromBB to the end
64/// of \p ToBB when proven safe.
65void moveInstructionsToTheEnd(BasicBlock &FromBB, BasicBlock &ToBB,
66 DominatorTree &DT, const PostDominatorTree &PDT,
67 DependenceInfo &DI);
68
69/// In case that two BBs \p ThisBlock and \p OtherBlock are control flow
70/// equivalent but they do not strictly dominate and post-dominate each
71/// other, we determine if \p ThisBlock is reached after \p OtherBlock
72/// in the control flow.
73bool nonStrictlyPostDominate(const BasicBlock *ThisBlock,
74 const BasicBlock *OtherBlock,
75 const DominatorTree *DT,
76 const PostDominatorTree *PDT);
77
78// Check if I0 is reached before I1 in the control flow.
79bool isReachedBefore(const Instruction *I0, const Instruction *I1,
80 const DominatorTree *DT, const PostDominatorTree *PDT);
81
82} // end namespace llvm
83
84#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.