本文整理汇总了C++中ScalarEvolution::isKnownNonNegative方法的典型用法代码示例。如果您正苦于以下问题:C++ ScalarEvolution::isKnownNonNegative方法的具体用法?C++ ScalarEvolution::isKnownNonNegative怎么用?C++ ScalarEvolution::isKnownNonNegative使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ScalarEvolution
的用法示例。
在下文中一共展示了ScalarEvolution::isKnownNonNegative方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SplitRangeCheckCondition
/// Split a condition into something semantically equivalent to (0 <= I <
/// Limit), both comparisons signed and Len loop invariant on L and positive.
/// On success, return true and set Index to I and UpperLimit to Limit. Return
/// false on failure (we may still write to UpperLimit and Index on failure).
/// It does not try to interpret I as a loop index.
///
static bool SplitRangeCheckCondition(Loop *L, ScalarEvolution &SE,
Value *Condition, const SCEV *&Index,
Value *&UpperLimit) {
// TODO: currently this catches some silly cases like comparing "%idx slt 1".
// Our transformations are still correct, but less likely to be profitable in
// those cases. We have to come up with some heuristics that pick out the
// range checks that are more profitable to clone a loop for. This function
// in general can be made more robust.
using namespace llvm::PatternMatch;
Value *A = nullptr;
Value *B = nullptr;
ICmpInst::Predicate Pred = ICmpInst::BAD_ICMP_PREDICATE;
// In these early checks we assume that the matched UpperLimit is positive.
// We'll verify that fact later, before returning true.
if (match(Condition, m_And(m_Value(A), m_Value(B)))) {
Value *IndexV = nullptr;
Value *ExpectedUpperBoundCheck = nullptr;
if (IsLowerBoundCheck(A, IndexV))
ExpectedUpperBoundCheck = B;
else if (IsLowerBoundCheck(B, IndexV))
ExpectedUpperBoundCheck = A;
else
return false;
if (!IsUpperBoundCheck(ExpectedUpperBoundCheck, IndexV, UpperLimit))
return false;
Index = SE.getSCEV(IndexV);
if (isa<SCEVCouldNotCompute>(Index))
return false;
} else if (match(Condition, m_ICmp(Pred, m_Value(A), m_Value(B)))) {
switch (Pred) {
default:
return false;
case ICmpInst::ICMP_SGT:
std::swap(A, B);
// fall through
case ICmpInst::ICMP_SLT:
UpperLimit = B;
Index = SE.getSCEV(A);
if (isa<SCEVCouldNotCompute>(Index) || !SE.isKnownNonNegative(Index))
return false;
break;
case ICmpInst::ICMP_UGT:
std::swap(A, B);
// fall through
case ICmpInst::ICMP_ULT:
UpperLimit = B;
Index = SE.getSCEV(A);
if (isa<SCEVCouldNotCompute>(Index))
return false;
break;
}
} else {
return false;
}
const SCEV *UpperLimitSCEV = SE.getSCEV(UpperLimit);
if (isa<SCEVCouldNotCompute>(UpperLimitSCEV) ||
!SE.isKnownNonNegative(UpperLimitSCEV))
return false;
if (SE.getLoopDisposition(UpperLimitSCEV, L) !=
ScalarEvolution::LoopInvariant) {
DEBUG(dbgs() << " in function: " << L->getHeader()->getParent()->getName()
<< " ";
dbgs() << " UpperLimit is not loop invariant: "
<< UpperLimit->getName() << "\n";);