[llvm] c1004ca - [LVI] Use CmpInst::Predicate in APIs (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 3 06:29:45 PDT 2024
Author: Nikita Popov
Date: 2024-07-03T15:26:57+02:00
New Revision: c1004cad4b62b70c4b316a49c5426271d4e1d740
URL: https://github.com/llvm/llvm-project/commit/c1004cad4b62b70c4b316a49c5426271d4e1d740
DIFF: https://github.com/llvm/llvm-project/commit/c1004cad4b62b70c4b316a49c5426271d4e1d740.diff
LOG: [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.
Added:
Modified:
llvm/include/llvm/Analysis/LazyValueInfo.h
llvm/lib/Analysis/LazyValueInfo.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Analysis/LazyValueInfo.h b/llvm/include/llvm/Analysis/LazyValueInfo.h
index 596fb2d73150f..1ac355e39cabe 100644
--- a/llvm/include/llvm/Analysis/LazyValueInfo.h
+++ b/llvm/include/llvm/Analysis/LazyValueInfo.h
@@ -14,6 +14,7 @@
#ifndef LLVM_ANALYSIS_LAZYVALUEINFO_H
#define LLVM_ANALYSIS_LAZYVALUEINFO_H
+#include "llvm/IR/InstrTypes.h"
#include "llvm/IR/PassManager.h"
#include "llvm/Pass.h"
@@ -67,7 +68,7 @@ namespace llvm {
/// Determine whether the specified value comparison with a constant is
/// known to be true or false on the specified CFG edge. Pred is a CmpInst
/// predicate.
- Tristate getPredicateOnEdge(unsigned Pred, Value *V, Constant *C,
+ Tristate getPredicateOnEdge(CmpInst::Predicate Pred, Value *V, Constant *C,
BasicBlock *FromBB, BasicBlock *ToBB,
Instruction *CxtI = nullptr);
@@ -75,7 +76,7 @@ namespace llvm {
/// known to be true or false at the specified instruction. \p Pred is a
/// CmpInst predicate. If \p UseBlockValue is true, the block value is also
/// taken into account.
- Tristate getPredicateAt(unsigned Pred, Value *V, Constant *C,
+ Tristate getPredicateAt(CmpInst::Predicate Pred, Value *V, Constant *C,
Instruction *CxtI, bool UseBlockValue);
/// Determine whether the specified value comparison is known to be true
@@ -83,7 +84,7 @@ namespace llvm {
/// it still requires that one of them is a constant.
/// \p Pred is a CmpInst predicate.
/// If \p UseBlockValue is true, the block value is also taken into account.
- Tristate getPredicateAt(unsigned Pred, Value *LHS, Value *RHS,
+ Tristate getPredicateAt(CmpInst::Predicate Pred, Value *LHS, Value *RHS,
Instruction *CxtI, bool UseBlockValue);
/// Determine whether the specified value is known to be a constant at the
diff --git a/llvm/lib/Analysis/LazyValueInfo.cpp b/llvm/lib/Analysis/LazyValueInfo.cpp
index 468b08a15d7df..b30e6a6a367c5 100644
--- a/llvm/lib/Analysis/LazyValueInfo.cpp
+++ b/llvm/lib/Analysis/LazyValueInfo.cpp
@@ -1775,8 +1775,8 @@ ConstantRange LazyValueInfo::getConstantRangeOnEdge(Value *V,
}
static LazyValueInfo::Tristate
-getPredicateResult(unsigned Pred, Constant *C, const ValueLatticeElement &Val,
- const DataLayout &DL) {
+getPredicateResult(CmpInst::Predicate Pred, Constant *C,
+ const ValueLatticeElement &Val, const DataLayout &DL) {
// If we know the value is a constant, evaluate the conditional.
Constant *Res = nullptr;
if (Val.isConstant()) {
@@ -1805,8 +1805,8 @@ getPredicateResult(unsigned Pred, Constant *C, const ValueLatticeElement &Val,
return LazyValueInfo::False;
} else {
// Handle more complex predicates.
- ConstantRange TrueValues = ConstantRange::makeExactICmpRegion(
- (ICmpInst::Predicate)Pred, CI->getValue());
+ ConstantRange TrueValues =
+ ConstantRange::makeExactICmpRegion(Pred, CI->getValue());
if (TrueValues.contains(CR))
return LazyValueInfo::True;
if (TrueValues.inverse().contains(CR))
@@ -1840,9 +1840,9 @@ getPredicateResult(unsigned Pred, Constant *C, const ValueLatticeElement &Val,
/// Determine whether the specified value comparison with a constant is known to
/// be true or false on the specified CFG edge. Pred is a CmpInst predicate.
LazyValueInfo::Tristate
-LazyValueInfo::getPredicateOnEdge(unsigned Pred, Value *V, Constant *C,
- BasicBlock *FromBB, BasicBlock *ToBB,
- Instruction *CxtI) {
+LazyValueInfo::getPredicateOnEdge(CmpInst::Predicate Pred, Value *V,
+ Constant *C, BasicBlock *FromBB,
+ BasicBlock *ToBB, Instruction *CxtI) {
Module *M = FromBB->getModule();
ValueLatticeElement Result =
getOrCreateImpl(M).getValueOnEdge(V, FromBB, ToBB, CxtI);
@@ -1850,9 +1850,10 @@ LazyValueInfo::getPredicateOnEdge(unsigned Pred, Value *V, Constant *C,
return getPredicateResult(Pred, C, Result, M->getDataLayout());
}
-LazyValueInfo::Tristate
-LazyValueInfo::getPredicateAt(unsigned Pred, Value *V, Constant *C,
- Instruction *CxtI, bool UseBlockValue) {
+LazyValueInfo::Tristate LazyValueInfo::getPredicateAt(CmpInst::Predicate Pred,
+ Value *V, Constant *C,
+ Instruction *CxtI,
+ bool UseBlockValue) {
// Is or is not NonNull are common predicates being queried. If
// isKnownNonZero can tell us the result of the predicate, we can
// return it quickly. But this is only a fastpath, and falling
@@ -1956,14 +1957,12 @@ LazyValueInfo::getPredicateAt(unsigned Pred, Value *V, Constant *C,
return Unknown;
}
-LazyValueInfo::Tristate LazyValueInfo::getPredicateAt(unsigned P, Value *LHS,
- Value *RHS,
+LazyValueInfo::Tristate LazyValueInfo::getPredicateAt(CmpInst::Predicate Pred,
+ Value *LHS, Value *RHS,
Instruction *CxtI,
bool UseBlockValue) {
- CmpInst::Predicate Pred = (CmpInst::Predicate)P;
-
if (auto *C = dyn_cast<Constant>(RHS))
- return getPredicateAt(P, LHS, C, CxtI, UseBlockValue);
+ return getPredicateAt(Pred, LHS, C, CxtI, UseBlockValue);
if (auto *C = dyn_cast<Constant>(LHS))
return getPredicateAt(CmpInst::getSwappedPredicate(Pred), RHS, C, CxtI,
UseBlockValue);
@@ -1981,8 +1980,7 @@ LazyValueInfo::Tristate LazyValueInfo::getPredicateAt(unsigned P, Value *LHS,
ValueLatticeElement R =
getOrCreateImpl(M).getValueInBlock(RHS, CxtI->getParent(), CxtI);
Type *Ty = CmpInst::makeCmpResultType(LHS->getType());
- if (Constant *Res = L.getCompare((CmpInst::Predicate)P, Ty, R,
- M->getDataLayout())) {
+ if (Constant *Res = L.getCompare(Pred, Ty, R, M->getDataLayout())) {
if (Res->isNullValue())
return LazyValueInfo::False;
if (Res->isOneValue())
More information about the llvm-commits
mailing list