Skip to content

Commit c1004ca

Browse files
committed
[LVI] Use CmpInst::Predicate in APIs (NFC)
Unfortunately this requires including InstrTypes.h in the header, but I think that's fine given that that LazyValueInfo.h is not widely used.
1 parent 2dbb454 commit c1004ca

File tree

2 files changed

+19
-20
lines changed

2 files changed

+19
-20
lines changed

llvm/include/llvm/Analysis/LazyValueInfo.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#ifndef LLVM_ANALYSIS_LAZYVALUEINFO_H
1515
#define LLVM_ANALYSIS_LAZYVALUEINFO_H
1616

17+
#include "llvm/IR/InstrTypes.h"
1718
#include "llvm/IR/PassManager.h"
1819
#include "llvm/Pass.h"
1920

@@ -67,23 +68,23 @@ namespace llvm {
6768
/// Determine whether the specified value comparison with a constant is
6869
/// known to be true or false on the specified CFG edge. Pred is a CmpInst
6970
/// predicate.
70-
Tristate getPredicateOnEdge(unsigned Pred, Value *V, Constant *C,
71+
Tristate getPredicateOnEdge(CmpInst::Predicate Pred, Value *V, Constant *C,
7172
BasicBlock *FromBB, BasicBlock *ToBB,
7273
Instruction *CxtI = nullptr);
7374

7475
/// Determine whether the specified value comparison with a constant is
7576
/// known to be true or false at the specified instruction. \p Pred is a
7677
/// CmpInst predicate. If \p UseBlockValue is true, the block value is also
7778
/// taken into account.
78-
Tristate getPredicateAt(unsigned Pred, Value *V, Constant *C,
79+
Tristate getPredicateAt(CmpInst::Predicate Pred, Value *V, Constant *C,
7980
Instruction *CxtI, bool UseBlockValue);
8081

8182
/// Determine whether the specified value comparison is known to be true
8283
/// or false at the specified instruction. While this takes two Value's,
8384
/// it still requires that one of them is a constant.
8485
/// \p Pred is a CmpInst predicate.
8586
/// If \p UseBlockValue is true, the block value is also taken into account.
86-
Tristate getPredicateAt(unsigned Pred, Value *LHS, Value *RHS,
87+
Tristate getPredicateAt(CmpInst::Predicate Pred, Value *LHS, Value *RHS,
8788
Instruction *CxtI, bool UseBlockValue);
8889

8990
/// Determine whether the specified value is known to be a constant at the

llvm/lib/Analysis/LazyValueInfo.cpp

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,8 +1775,8 @@ ConstantRange LazyValueInfo::getConstantRangeOnEdge(Value *V,
17751775
}
17761776

17771777
static LazyValueInfo::Tristate
1778-
getPredicateResult(unsigned Pred, Constant *C, const ValueLatticeElement &Val,
1779-
const DataLayout &DL) {
1778+
getPredicateResult(CmpInst::Predicate Pred, Constant *C,
1779+
const ValueLatticeElement &Val, const DataLayout &DL) {
17801780
// If we know the value is a constant, evaluate the conditional.
17811781
Constant *Res = nullptr;
17821782
if (Val.isConstant()) {
@@ -1805,8 +1805,8 @@ getPredicateResult(unsigned Pred, Constant *C, const ValueLatticeElement &Val,
18051805
return LazyValueInfo::False;
18061806
} else {
18071807
// Handle more complex predicates.
1808-
ConstantRange TrueValues = ConstantRange::makeExactICmpRegion(
1809-
(ICmpInst::Predicate)Pred, CI->getValue());
1808+
ConstantRange TrueValues =
1809+
ConstantRange::makeExactICmpRegion(Pred, CI->getValue());
18101810
if (TrueValues.contains(CR))
18111811
return LazyValueInfo::True;
18121812
if (TrueValues.inverse().contains(CR))
@@ -1840,19 +1840,20 @@ getPredicateResult(unsigned Pred, Constant *C, const ValueLatticeElement &Val,
18401840
/// Determine whether the specified value comparison with a constant is known to
18411841
/// be true or false on the specified CFG edge. Pred is a CmpInst predicate.
18421842
LazyValueInfo::Tristate
1843-
LazyValueInfo::getPredicateOnEdge(unsigned Pred, Value *V, Constant *C,
1844-
BasicBlock *FromBB, BasicBlock *ToBB,
1845-
Instruction *CxtI) {
1843+
LazyValueInfo::getPredicateOnEdge(CmpInst::Predicate Pred, Value *V,
1844+
Constant *C, BasicBlock *FromBB,
1845+
BasicBlock *ToBB, Instruction *CxtI) {
18461846
Module *M = FromBB->getModule();
18471847
ValueLatticeElement Result =
18481848
getOrCreateImpl(M).getValueOnEdge(V, FromBB, ToBB, CxtI);
18491849

18501850
return getPredicateResult(Pred, C, Result, M->getDataLayout());
18511851
}
18521852

1853-
LazyValueInfo::Tristate
1854-
LazyValueInfo::getPredicateAt(unsigned Pred, Value *V, Constant *C,
1855-
Instruction *CxtI, bool UseBlockValue) {
1853+
LazyValueInfo::Tristate LazyValueInfo::getPredicateAt(CmpInst::Predicate Pred,
1854+
Value *V, Constant *C,
1855+
Instruction *CxtI,
1856+
bool UseBlockValue) {
18561857
// Is or is not NonNull are common predicates being queried. If
18571858
// isKnownNonZero can tell us the result of the predicate, we can
18581859
// return it quickly. But this is only a fastpath, and falling
@@ -1956,14 +1957,12 @@ LazyValueInfo::getPredicateAt(unsigned Pred, Value *V, Constant *C,
19561957
return Unknown;
19571958
}
19581959

1959-
LazyValueInfo::Tristate LazyValueInfo::getPredicateAt(unsigned P, Value *LHS,
1960-
Value *RHS,
1960+
LazyValueInfo::Tristate LazyValueInfo::getPredicateAt(CmpInst::Predicate Pred,
1961+
Value *LHS, Value *RHS,
19611962
Instruction *CxtI,
19621963
bool UseBlockValue) {
1963-
CmpInst::Predicate Pred = (CmpInst::Predicate)P;
1964-
19651964
if (auto *C = dyn_cast<Constant>(RHS))
1966-
return getPredicateAt(P, LHS, C, CxtI, UseBlockValue);
1965+
return getPredicateAt(Pred, LHS, C, CxtI, UseBlockValue);
19671966
if (auto *C = dyn_cast<Constant>(LHS))
19681967
return getPredicateAt(CmpInst::getSwappedPredicate(Pred), RHS, C, CxtI,
19691968
UseBlockValue);
@@ -1981,8 +1980,7 @@ LazyValueInfo::Tristate LazyValueInfo::getPredicateAt(unsigned P, Value *LHS,
19811980
ValueLatticeElement R =
19821981
getOrCreateImpl(M).getValueInBlock(RHS, CxtI->getParent(), CxtI);
19831982
Type *Ty = CmpInst::makeCmpResultType(LHS->getType());
1984-
if (Constant *Res = L.getCompare((CmpInst::Predicate)P, Ty, R,
1985-
M->getDataLayout())) {
1983+
if (Constant *Res = L.getCompare(Pred, Ty, R, M->getDataLayout())) {
19861984
if (Res->isNullValue())
19871985
return LazyValueInfo::False;
19881986
if (Res->isOneValue())

0 commit comments

Comments
 (0)