Skip to content

Commit

Permalink
[SCEV] Add interface for constructing generic SCEVComparePredicate [NFC}
Browse files Browse the repository at this point in the history
  • Loading branch information
preames committed Feb 9, 2022
1 parent b71eed7 commit 83f895d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions llvm/include/llvm/Analysis/ScalarEvolution.h
Expand Up @@ -1167,6 +1167,8 @@ class ScalarEvolution {
}

const SCEVPredicate *getEqualPredicate(const SCEV *LHS, const SCEV *RHS);
const SCEVPredicate *getComparePredicate(ICmpInst::Predicate Pred,
const SCEV *LHS, const SCEV *RHS);

const SCEVPredicate *
getWrapPredicate(const SCEVAddRecExpr *AR,
Expand Down
10 changes: 8 additions & 2 deletions llvm/lib/Analysis/ScalarEvolution.cpp
Expand Up @@ -13537,19 +13537,25 @@ void ScalarEvolutionWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {

const SCEVPredicate *ScalarEvolution::getEqualPredicate(const SCEV *LHS,
const SCEV *RHS) {
return getComparePredicate(ICmpInst::ICMP_EQ, LHS, RHS);
}

const SCEVPredicate *
ScalarEvolution::getComparePredicate(const ICmpInst::Predicate Pred,
const SCEV *LHS, const SCEV *RHS) {
FoldingSetNodeID ID;
assert(LHS->getType() == RHS->getType() &&
"Type mismatch between LHS and RHS");
// Unique this node based on the arguments
ID.AddInteger(SCEVPredicate::P_Compare);
ID.AddInteger(ICmpInst::ICMP_EQ);
ID.AddInteger(Pred);
ID.AddPointer(LHS);
ID.AddPointer(RHS);
void *IP = nullptr;
if (const auto *S = UniquePreds.FindNodeOrInsertPos(ID, IP))
return S;
SCEVComparePredicate *Eq = new (SCEVAllocator)
SCEVComparePredicate(ID.Intern(SCEVAllocator), ICmpInst::ICMP_EQ, LHS, RHS);
SCEVComparePredicate(ID.Intern(SCEVAllocator), Pred, LHS, RHS);
UniquePreds.InsertNode(Eq, IP);
return Eq;
}
Expand Down

0 comments on commit 83f895d

Please sign in to comment.