LLVM  15.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 
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.
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.
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
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::isReachedBefore
bool isReachedBefore(const Instruction *I0, const Instruction *I1, const DominatorTree *DT, const PostDominatorTree *PDT)
Definition: CodeMoverUtils.cpp:467
llvm::isControlFlowEquivalent
bool isControlFlowEquivalent(const Instruction &I0, const Instruction &I1, const DominatorTree &DT, const PostDominatorTree &PDT)
Return true if I0 and I1 are control flow equivalent.
Definition: CodeMoverUtils.cpp:229
I1
@ I1
Definition: DXILOpLowering.cpp:38
llvm::nonStrictlyPostDominate
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...
Definition: CodeMoverUtils.cpp:434
llvm::moveInstructionsToTheEnd
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.
Definition: CodeMoverUtils.cpp:422
I
#define I(x, y, z)
Definition: MD5.cpp:58
llvm::ISD::BasicBlock
@ BasicBlock
Various leaf nodes.
Definition: ISDOpcodes.h:71
llvm::moveInstructionsToTheBeginning
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...
Definition: CodeMoverUtils.cpp:409
BB
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
Definition: README.txt:39
llvm::isSafeToMoveBefore
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.
Definition: CodeMoverUtils.cpp:310