LLVM 22.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
21
22namespace llvm {
23
24class BasicBlock;
25class DependenceInfo;
26class DominatorTree;
27class Instruction;
28class PostDominatorTree;
29
30/// Return true if \p I0 and \p I1 are control flow equivalent.
31/// Two instructions are control flow equivalent if their basic blocks are
32/// control flow equivalent.
33LLVM_ABI bool isControlFlowEquivalent(const Instruction &I0,
34 const Instruction &I1,
35 const DominatorTree &DT,
36 const PostDominatorTree &PDT);
37
38/// Return true if \p BB0 and \p BB1 are control flow equivalent.
39/// Two basic blocks are control flow equivalent if when one executes, the other
40/// is guaranteed to execute.
41LLVM_ABI bool isControlFlowEquivalent(const BasicBlock &BB0,
42 const BasicBlock &BB1,
43 const DominatorTree &DT,
44 const PostDominatorTree &PDT);
45
46/// Return true if \p I can be safely moved before \p InsertPoint.
47LLVM_ABI bool isSafeToMoveBefore(Instruction &I, Instruction &InsertPoint,
48 DominatorTree &DT,
49 const PostDominatorTree *PDT = nullptr,
50 DependenceInfo *DI = nullptr,
51 bool CheckForEntireBlock = false);
52
53/// Return true if all instructions (except the terminator) in \p BB can be
54/// safely moved before \p InsertPoint.
55LLVM_ABI bool isSafeToMoveBefore(BasicBlock &BB, Instruction &InsertPoint,
56 DominatorTree &DT,
57 const PostDominatorTree *PDT = nullptr,
58 DependenceInfo *DI = nullptr);
59
60/// Move instructions, in an order-preserving manner, from \p FromBB to the
61/// beginning of \p ToBB when proven safe.
62LLVM_ABI void moveInstructionsToTheBeginning(BasicBlock &FromBB,
63 BasicBlock &ToBB,
64 DominatorTree &DT,
65 const PostDominatorTree &PDT,
66 DependenceInfo &DI);
67
68/// Move instructions, in an order-preserving manner, from \p FromBB to the end
69/// of \p ToBB when proven safe.
70LLVM_ABI void moveInstructionsToTheEnd(BasicBlock &FromBB, BasicBlock &ToBB,
71 DominatorTree &DT,
72 const PostDominatorTree &PDT,
73 DependenceInfo &DI);
74
75/// In case that two BBs \p ThisBlock and \p OtherBlock are control flow
76/// equivalent but they do not strictly dominate and post-dominate each
77/// other, we determine if \p ThisBlock is reached after \p OtherBlock
78/// in the control flow.
79LLVM_ABI bool nonStrictlyPostDominate(const BasicBlock *ThisBlock,
80 const BasicBlock *OtherBlock,
81 const DominatorTree *DT,
82 const PostDominatorTree *PDT);
83
84// Check if I0 is reached before I1 in the control flow.
85LLVM_ABI bool isReachedBefore(const Instruction *I0, const Instruction *I1,
86 const DominatorTree *DT,
87 const PostDominatorTree *PDT);
88
89} // end namespace llvm
90
91#endif // LLVM_TRANSFORMS_UTILS_CODEMOVERUTILS_H
#define LLVM_ABI
Definition: Compiler.h:213
#define I(x, y, z)
Definition: MD5.cpp:58
@ BasicBlock
Various leaf nodes.
Definition: ISDOpcodes.h:81
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
LLVM_ABI 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.
LLVM_ABI bool isReachedBefore(const Instruction *I0, const Instruction *I1, const DominatorTree *DT, const PostDominatorTree *PDT)
LLVM_ABI bool isControlFlowEquivalent(const Instruction &I0, const Instruction &I1, const DominatorTree &DT, const PostDominatorTree &PDT)
Return true if I0 and I1 are control flow equivalent.
LLVM_ABI 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...
LLVM_ABI 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...
LLVM_ABI 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.