23 #define DEBUG_TYPE "codemover-utils" 26 "Cannot move across instructions that has memory dependences");
27 STATISTIC(MayThrowException,
"Cannot move across instructions that may throw");
29 "Instructions are not control flow equivalent");
30 STATISTIC(NotMovedPHINode,
"Movement of PHINodes are not supported");
31 STATISTIC(NotMovedTerminator,
"Movement of Terminator are not supported");
62 assert(InBetweenInsts.
empty() &&
"Expecting InBetweenInsts to be empty");
68 WorkList.insert(NextInst);
72 WorkList.insert(&Succ->front());
77 getNextInsts(StartInst, WorkList);
78 while (!WorkList.
empty()) {
80 WorkList.
erase(CurInst);
82 if (CurInst == &EndInst)
85 if (!InBetweenInsts.
insert(CurInst).second)
88 getNextInsts(*CurInst, WorkList);
97 if (&I == &InsertPoint)
104 if (isa<PHINode>(I) || isa<PHINode>(InsertPoint))
116 const bool MoveForward = DT.
dominates(&I, &InsertPoint);
121 if (
auto *UserInst = dyn_cast<Instruction>(U.getUser()))
122 if (UserInst != &InsertPoint && !DT.
dominates(&InsertPoint, U))
128 if (
auto *OpInst = dyn_cast<Instruction>(
Op))
129 if (&InsertPoint == OpInst || !DT.
dominates(OpInst, &InsertPoint))
133 Instruction &StartInst = (MoveForward ?
I : InsertPoint);
138 InstsToCheck.
insert(&InsertPoint);
151 if (!CB->
hasFnAttr(Attribute::WillReturn))
165 auto DepResult = DI.
depends(&I, CurInst,
true);
167 (DepResult->isOutput() || DepResult->isFlow() ||
168 DepResult->isAnti()))
180 for (
auto It = ++FromBB.
rbegin(); It != FromBB.
rend();) {
bool isSafeToMoveBefore(Instruction &I, Instruction &InsertPoint, const DominatorTree &DT, const PostDominatorTree &PDT, DependenceInfo &DI)
Return true if I can be safely moved before InsertPoint.
iterator_range< use_iterator > uses()
NodeTy * getNextNode()
Get the next node, or nullptr for the list tail.
This class represents lattice values for constants.
bool isTerminator() const
void moveInstsBottomUp(BasicBlock &FromBB, BasicBlock &ToBB, const DominatorTree &DT, const PostDominatorTree &PDT, DependenceInfo &DI)
Move instructions from FromBB bottom up to the beginning of ToBB when proven safe.
STATISTIC(NumFunctions, "Total number of functions")
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
reverse_iterator rbegin()
DependenceInfo - This class is the main dependence-analysis driver.
A Use represents the edge between a Value definition and its users.
const char * getDesc() const
bool isControlFlowEquivalent(const Instruction &I0, const Instruction &I1, const DominatorTree &DT, const PostDominatorTree &PDT)
Return true if I0 and I1 are control flow equivalent.
static bool reportInvalidCandidate(const Instruction &I, llvm::Statistic &Stat)
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
std::unique_ptr< Dependence > depends(Instruction *Src, Instruction *Dst, bool PossiblyLoopIndependent)
depends - Tests for a dependence between the Src and Dst instructions.
LLVM Basic Block Representation.
bool dominates(const Instruction *I1, const Instruction *I2) const
Return true if I1 dominates I2.
LLVM_NODISCARD bool empty() const
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
bool mayThrow() const
Return true if this instruction may throw an exception.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly...
bool hasFnAttr(Attribute::AttrKind Kind) const
Determine whether this call has the given attribute.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
bool erase(PtrType Ptr)
erase - If the set contains the specified pointer, remove it and return true, otherwise return false...
bool dominates(const Instruction *Def, const Use &U) const
Return true if Def dominates a use in User.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
PostDominatorTree Class - Concrete subclass of DominatorTree that is used to compute the post-dominat...
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool isSafeToSpeculativelyExecute(const Value *V, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr)
Return true if the instruction does not have any effects besides calculating the result and does not ...
LLVM Value Representation.
succ_range successors(Instruction *I)
void moveBefore(Instruction *MovePos)
Unlink this instruction from its current basic block and insert it into the basic block that MovePos ...
const Instruction * getFirstNonPHIOrDbg() const
Returns a pointer to the first instruction in this block that is not a PHINode or a debug intrinsic...
static void collectInstructionsInBetween(Instruction &StartInst, const Instruction &EndInst, SmallPtrSetImpl< Instruction *> &InBetweenInsts)
Collect all instructions in between StartInst and EndInst, and store them in InBetweenInsts.
const BasicBlock * getParent() const