Skip to content

Commit

Permalink
[GuardWidening] Rename 'isAvailableAt' -> 'canBeHoistedTo' (NFC)
Browse files Browse the repository at this point in the history
This better describes what this method does.
  • Loading branch information
d-makogon committed Feb 28, 2023
1 parent 4e34915 commit 5ec368d
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions llvm/lib/Transforms/Scalar/GuardWidening.cpp
Expand Up @@ -187,16 +187,16 @@ class GuardWideningImpl {
bool InvertCond);

/// Helper to check if \p V can be hoisted to \p InsertPos.
bool isAvailableAt(const Value *V, const Instruction *InsertPos) const {
bool canBeHoistedTo(const Value *V, const Instruction *InsertPos) const {
SmallPtrSet<const Instruction *, 8> Visited;
return isAvailableAt(V, InsertPos, Visited);
return canBeHoistedTo(V, InsertPos, Visited);
}

bool isAvailableAt(const Value *V, const Instruction *InsertPos,
SmallPtrSetImpl<const Instruction *> &Visited) const;
bool canBeHoistedTo(const Value *V, const Instruction *InsertPos,
SmallPtrSetImpl<const Instruction *> &Visited) const;

/// Helper to hoist \p V to \p InsertPos. Guaranteed to succeed if \c
/// isAvailableAt returned true.
/// canBeHoistedTo returned true.
void makeAvailableAt(Value *V, Instruction *InsertPos) const;

/// Common helper used by \c widenGuard and \c isWideningCondProfitable. Try
Expand Down Expand Up @@ -440,9 +440,9 @@ GuardWideningImpl::computeWideningScore(Instruction *DominatedInstr,
}

auto *WideningPoint = findInsertionPointForWideCondition(DominatingGuard);
if (!isAvailableAt(getCondition(DominatedInstr), WideningPoint))
if (!canBeHoistedTo(getCondition(DominatedInstr), WideningPoint))
return WS_IllegalOrNegative;
if (!isAvailableAt(getCondition(DominatingGuard), WideningPoint))
if (!canBeHoistedTo(getCondition(DominatingGuard), WideningPoint))
return WS_IllegalOrNegative;

// If the guard was conditional executed, it may never be reached
Expand Down Expand Up @@ -483,7 +483,7 @@ GuardWideningImpl::computeWideningScore(Instruction *DominatedInstr,
return MaybeHoistingOutOfIf() ? WS_IllegalOrNegative : WS_Neutral;
}

bool GuardWideningImpl::isAvailableAt(
bool GuardWideningImpl::canBeHoistedTo(
const Value *V, const Instruction *Loc,
SmallPtrSetImpl<const Instruction *> &Visited) const {
auto *Inst = dyn_cast<Instruction>(V);
Expand All @@ -502,7 +502,7 @@ bool GuardWideningImpl::isAvailableAt(
assert(DT.isReachableFromEntry(Inst->getParent()) &&
"We did a DFS from the block entry!");
return all_of(Inst->operands(),
[&](Value *Op) { return isAvailableAt(Op, Loc, Visited); });
[&](Value *Op) { return canBeHoistedTo(Op, Loc, Visited); });
}

void GuardWideningImpl::makeAvailableAt(Value *V, Instruction *Loc) const {
Expand All @@ -511,7 +511,8 @@ void GuardWideningImpl::makeAvailableAt(Value *V, Instruction *Loc) const {
return;

assert(isSafeToSpeculativelyExecute(Inst, Loc, &AC, &DT) &&
!Inst->mayReadFromMemory() && "Should've checked with isAvailableAt!");
!Inst->mayReadFromMemory() &&
"Should've checked with canBeHoistedTo!");

for (Value *Op : Inst->operands())
makeAvailableAt(Op, Loc);
Expand Down Expand Up @@ -552,7 +553,7 @@ bool GuardWideningImpl::widenCondCommon(Value *Cond0, Value *Cond1,
if (InsertPt) {
ConstantInt *NewRHS =
ConstantInt::get(Cond0->getContext(), NewRHSAP);
assert(isAvailableAt(LHS, InsertPt) && "must be");
assert(canBeHoistedTo(LHS, InsertPt) && "must be");
makeAvailableAt(LHS, InsertPt);
Result = new ICmpInst(InsertPt, Pred, LHS, NewRHS, "wide.chk");
}
Expand Down

0 comments on commit 5ec368d

Please sign in to comment.