本文整理汇总了C++中APInt::slt方法的典型用法代码示例。如果您正苦于以下问题:C++ APInt::slt方法的具体用法?C++ APInt::slt怎么用?C++ APInt::slt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类APInt
的用法示例。
在下文中一共展示了APInt::slt方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: visitSelectInst
SizeOffsetType ObjectSizeOffsetVisitor::visitSelectInst(SelectInst &I) {
SizeOffsetType TrueSide = compute(I.getTrueValue());
SizeOffsetType FalseSide = compute(I.getFalseValue());
if (bothKnown(TrueSide) && bothKnown(FalseSide)) {
if (TrueSide == FalseSide) {
return TrueSide;
}
APInt TrueResult = getSizeWithOverflow(TrueSide);
APInt FalseResult = getSizeWithOverflow(FalseSide);
if (TrueResult == FalseResult) {
return TrueSide;
}
if (Options.EvalMode == ObjectSizeOpts::Mode::Min) {
if (TrueResult.slt(FalseResult))
return TrueSide;
return FalseSide;
}
if (Options.EvalMode == ObjectSizeOpts::Mode::Max) {
if (TrueResult.sgt(FalseResult))
return TrueSide;
return FalseSide;
}
}
return unknown();
}
示例2: findShortestPathAt
APInt IneqGraph::findShortestPathAt(Value *F, Value *T, BasicBlock *BB) {
DEBUG(dbgs() << "IneqGraph: findShortestPathAt: " << *F << " ==> " << *T << " at " << BB->getName() << "\n");
Value *SigmaOrF = VS->getSigmaForAt(F, BB);
Value *SigmaOrT = VS->getSigmaForAt(T, BB);
APInt Shortest = findShortestPath(SigmaOrF, SigmaOrT);
APInt Other = findShortestPath(F, SigmaOrT);
return Other.slt(Shortest) ? Other : Shortest;
}
示例3: findShortestPath
APInt GraphNode::findShortestPath(GraphNode *Dest, SetVector<GraphNode*> Visited) {
if (Dest == this) {
DEBUG(dbgs() << "IneqGraph: Reached: " << *Dest->getValue() << "\n");
return APInt(64, 0, true);
}
DEBUG(dbgs() << "IneqGraph: Node: " << *V << "\n");
if (Visited.count(this)) {
DEBUG(dbgs() << "IneqGraph: Visited\n");
return APInt::getSignedMaxValue(64); //(64, , true);
}
Visited.insert(this);
APInt MayMin = APInt::getSignedMaxValue(64);
for (may_iterator It = may_begin(), E = may_end();
It != E; ++It) {
APInt Total = It->getToEdge()->findShortestPath(Dest, Visited);
if (Total.slt(MayMin))
MayMin = Total + It->getWeight();
}
//DEBUG(dbgs() << "IneqGraph: Node: " << *V << ", MayMin: " << MayMin << "\n");
APInt MustMax = APInt::getSignedMinValue(64);
for (must_iterator It = must_begin(), E = must_end();
It != E; ++It) {
APInt Total = It->getToEdge()->findShortestPath(Dest, Visited);
if (MustMax.slt(Total))
MustMax = Total;
}
// DEBUG(dbgs() << "IneqGraph: Node: " << *V << ", MustMax: " << MustMax << "\n");
if (MustMax.isMinSignedValue()) {
//DEBUG(dbgs() << "IneqGraph: Node: " << *V << ", Distance: " << MayMin << "\n");
DEBUG(dbgs() << "IneqGraph: Ret: " << MayMin << "\n");
return MayMin;
} else {
APInt Min = MustMax.slt(MayMin) ? MustMax : MayMin;
//DEBUG(dbgs() << "IneqGraph: Node: " << *V << ", Distance: " << Min << "\n");
DEBUG(dbgs() << "IneqGraph: Ret: " << Min << "\n");
return Min;
}
}
示例4: ReplaceInstUsesWith
/// FoldSPFofSPF - We have an SPF (e.g. a min or max) of an SPF of the form:
/// SPF2(SPF1(A, B), C)
Instruction *InstCombiner::FoldSPFofSPF(Instruction *Inner,
SelectPatternFlavor SPF1,
Value *A, Value *B,
Instruction &Outer,
SelectPatternFlavor SPF2, Value *C) {
if (C == A || C == B) {
// MAX(MAX(A, B), B) -> MAX(A, B)
// MIN(MIN(a, b), a) -> MIN(a, b)
if (SPF1 == SPF2)
return ReplaceInstUsesWith(Outer, Inner);
// MAX(MIN(a, b), a) -> a
// MIN(MAX(a, b), a) -> a
if ((SPF1 == SPF_SMIN && SPF2 == SPF_SMAX) ||
(SPF1 == SPF_SMAX && SPF2 == SPF_SMIN) ||
(SPF1 == SPF_UMIN && SPF2 == SPF_UMAX) ||
(SPF1 == SPF_UMAX && SPF2 == SPF_UMIN))
return ReplaceInstUsesWith(Outer, C);
}
if (SPF1 == SPF2) {
if (ConstantInt *CB = dyn_cast<ConstantInt>(B)) {
if (ConstantInt *CC = dyn_cast<ConstantInt>(C)) {
APInt ACB = CB->getValue();
APInt ACC = CC->getValue();
// MIN(MIN(A, 23), 97) -> MIN(A, 23)
// MAX(MAX(A, 97), 23) -> MAX(A, 97)
if ((SPF1 == SPF_UMIN && ACB.ule(ACC)) ||
(SPF1 == SPF_SMIN && ACB.sle(ACC)) ||
(SPF1 == SPF_UMAX && ACB.uge(ACC)) ||
(SPF1 == SPF_SMAX && ACB.sge(ACC)))
return ReplaceInstUsesWith(Outer, Inner);
// MIN(MIN(A, 97), 23) -> MIN(A, 23)
// MAX(MAX(A, 23), 97) -> MAX(A, 97)
if ((SPF1 == SPF_UMIN && ACB.ugt(ACC)) ||
(SPF1 == SPF_SMIN && ACB.sgt(ACC)) ||
(SPF1 == SPF_UMAX && ACB.ult(ACC)) ||
(SPF1 == SPF_SMAX && ACB.slt(ACC))) {
Outer.replaceUsesOfWith(Inner, A);
return &Outer;
}
}
}
}
return nullptr;
}
示例5: constantFoldComparison
APInt swift::constantFoldComparison(APInt lhs, APInt rhs, BuiltinValueKind ID) {
bool result;
switch (ID) {
default: llvm_unreachable("Invalid integer compare kind");
case BuiltinValueKind::ICMP_EQ: result = lhs == rhs; break;
case BuiltinValueKind::ICMP_NE: result = lhs != rhs; break;
case BuiltinValueKind::ICMP_SLT: result = lhs.slt(rhs); break;
case BuiltinValueKind::ICMP_SGT: result = lhs.sgt(rhs); break;
case BuiltinValueKind::ICMP_SLE: result = lhs.sle(rhs); break;
case BuiltinValueKind::ICMP_SGE: result = lhs.sge(rhs); break;
case BuiltinValueKind::ICMP_ULT: result = lhs.ult(rhs); break;
case BuiltinValueKind::ICMP_UGT: result = lhs.ugt(rhs); break;
case BuiltinValueKind::ICMP_ULE: result = lhs.ule(rhs); break;
case BuiltinValueKind::ICMP_UGE: result = lhs.uge(rhs); break;
}
return APInt(1, result);
}
示例6: if
/*
* function join
*
* Here we perform the join operation in the interval lattice,
* using Cousot's widening operator. We join the current abstract state
* with the new_abstract_state and update the current abstract state of
* the node.
*
* This function returns true if the current abstract state has changed.
*/
bool llvm::RangeAnalysis::join(GraphNode* Node, Range new_abstract_state){
//Do not widen the range of a value that has an initial value
if (!getInitialState(Node).isMaxRange()) {
return false;
}
Range oldInterval = out_state[Node];
Range newInterval = new_abstract_state;
APInt oldLower = oldInterval.getLower();
APInt oldUpper = oldInterval.getUpper();
APInt newLower = newInterval.getLower();
APInt newUpper = newInterval.getUpper();
if (oldInterval.isUnknown())
out_state[Node] = newInterval;
else {
if (widening_count[Node] < MaxIterationCount) {
out_state[Node] = oldInterval.unionWith(newInterval);
widening_count[Node]++;
} else {
//Widening
APInt oldLower = oldInterval.getLower();
APInt oldUpper = oldInterval.getUpper();
APInt newLower = newInterval.getLower();
APInt newUpper = newInterval.getUpper();
if (newLower.slt(oldLower))
if (newUpper.sgt(oldUpper))
out_state[Node] = Range(Min, Max);
else
out_state[Node] = Range(Min, oldUpper);
else if (newUpper.sgt(oldUpper))
out_state[Node] = Range(oldLower, Max);
}
}
bool hasChanged = oldInterval != out_state[Node];
return hasChanged;
}
示例7: MultiplyOverflows
/// MultiplyOverflows - True if the multiply can not be expressed in an int
/// this size.
static bool MultiplyOverflows(ConstantInt *C1, ConstantInt *C2, bool sign) {
uint32_t W = C1->getBitWidth();
APInt LHSExt = C1->getValue(), RHSExt = C2->getValue();
if (sign) {
LHSExt = LHSExt.sext(W * 2);
RHSExt = RHSExt.sext(W * 2);
} else {
LHSExt = LHSExt.zext(W * 2);
RHSExt = RHSExt.zext(W * 2);
}
APInt MulExt = LHSExt * RHSExt;
if (!sign)
return MulExt.ugt(APInt::getLowBitsSet(W * 2, W));
APInt Min = APInt::getSignedMinValue(W).sext(W * 2);
APInt Max = APInt::getSignedMaxValue(W).sext(W * 2);
return MulExt.slt(Min) || MulExt.sgt(Max);
}
示例8: ReplaceInstUsesWith
/// FoldSPFofSPF - We have an SPF (e.g. a min or max) of an SPF of the form:
/// SPF2(SPF1(A, B), C)
Instruction *InstCombiner::FoldSPFofSPF(Instruction *Inner,
SelectPatternFlavor SPF1,
Value *A, Value *B,
Instruction &Outer,
SelectPatternFlavor SPF2, Value *C) {
if (C == A || C == B) {
// MAX(MAX(A, B), B) -> MAX(A, B)
// MIN(MIN(a, b), a) -> MIN(a, b)
if (SPF1 == SPF2)
return ReplaceInstUsesWith(Outer, Inner);
// MAX(MIN(a, b), a) -> a
// MIN(MAX(a, b), a) -> a
if ((SPF1 == SPF_SMIN && SPF2 == SPF_SMAX) ||
(SPF1 == SPF_SMAX && SPF2 == SPF_SMIN) ||
(SPF1 == SPF_UMIN && SPF2 == SPF_UMAX) ||
(SPF1 == SPF_UMAX && SPF2 == SPF_UMIN))
return ReplaceInstUsesWith(Outer, C);
}
if (SPF1 == SPF2) {
if (ConstantInt *CB = dyn_cast<ConstantInt>(B)) {
if (ConstantInt *CC = dyn_cast<ConstantInt>(C)) {
APInt ACB = CB->getValue();
APInt ACC = CC->getValue();
// MIN(MIN(A, 23), 97) -> MIN(A, 23)
// MAX(MAX(A, 97), 23) -> MAX(A, 97)
if ((SPF1 == SPF_UMIN && ACB.ule(ACC)) ||
(SPF1 == SPF_SMIN && ACB.sle(ACC)) ||
(SPF1 == SPF_UMAX && ACB.uge(ACC)) ||
(SPF1 == SPF_SMAX && ACB.sge(ACC)))
return ReplaceInstUsesWith(Outer, Inner);
// MIN(MIN(A, 97), 23) -> MIN(A, 23)
// MAX(MAX(A, 23), 97) -> MAX(A, 97)
if ((SPF1 == SPF_UMIN && ACB.ugt(ACC)) ||
(SPF1 == SPF_SMIN && ACB.sgt(ACC)) ||
(SPF1 == SPF_UMAX && ACB.ult(ACC)) ||
(SPF1 == SPF_SMAX && ACB.slt(ACC))) {
Outer.replaceUsesOfWith(Inner, A);
return &Outer;
}
}
}
}
// ABS(ABS(X)) -> ABS(X)
// NABS(NABS(X)) -> NABS(X)
if (SPF1 == SPF2 && (SPF1 == SPF_ABS || SPF1 == SPF_NABS)) {
return ReplaceInstUsesWith(Outer, Inner);
}
// ABS(NABS(X)) -> ABS(X)
// NABS(ABS(X)) -> NABS(X)
if ((SPF1 == SPF_ABS && SPF2 == SPF_NABS) ||
(SPF1 == SPF_NABS && SPF2 == SPF_ABS)) {
SelectInst *SI = cast<SelectInst>(Inner);
Value *NewSI = Builder->CreateSelect(
SI->getCondition(), SI->getFalseValue(), SI->getTrueValue());
return ReplaceInstUsesWith(Outer, NewSI);
}
return nullptr;
}
示例9: eval_rexpr
// caller must free returned value
const EmuVal* eval_rexpr(const Expr* e){
errs() << "\nDEBUG: about to eval rexpr:\n";
e->dump();
if(isa<IntegerLiteral>(e)){
const IntegerLiteral *obj = (const IntegerLiteral*)e;
APInt i = obj->getValue();
if(i.slt(EMU_MIN_INT) || i.sgt(EMU_MAX_INT)){
e->dump();
cant_handle();
}
return new EmuNum<NUM_TYPE_INT>(i);
} else if(isa<CharacterLiteral>(e)){
const CharacterLiteral *obj = (const CharacterLiteral*)e;
unsigned int i = obj->getValue();
if(i > 127){
e->dump();
cant_handle();
}
return new EmuNum<NUM_TYPE_CHAR>(new APInt(8, i, true));
} else if(isa<UnaryOperator>(e)){
const UnaryOperator *obj = (const UnaryOperator*)e;
const Expr* sub = obj->getSubExpr();
const auto op = obj->getOpcode();
switch(op){
case UO_AddrOf:
{
lvalue arg = eval_lexpr(sub);
return new EmuPtr(arg.ptr, e->getType());
}
case UO_LNot:
case UO_Minus:
{
const EmuVal* arg = eval_rexpr(sub);
if(!arg->obj_type->isIntegerType()){
cant_cast();
}
if(op == UO_LNot){
return ((const EmuNumGeneric*)arg)->lnot();
} else if (op == UO_Minus){
return ((const EmuNumGeneric*)arg)->neg();
}
}
case UO_Deref:
case UO_Extension:
case UO_Imag:
case UO_Real:
case UO_Not:
case UO_PostInc:
case UO_PostDec:
case UO_PreInc:
case UO_PreDec:
case UO_Plus:
default:
llvm::errs() << "Got opcode " << obj->getOpcode() << "\n";
cant_handle();
}
} else if(isa<BinaryOperator>(e)){
const BinaryOperator* ex = (const BinaryOperator*)e;
BinaryOperatorKind op = ex->getOpcode();
// right always an rexpr
const EmuVal *right = eval_rexpr(ex->getRHS());
switch(op){
case BO_Assign:
{
lvalue left = eval_lexpr(ex->getLHS());
const EmuVal* ans = right->cast_to(left.type);
delete right;
left.ptr.block->write(ans, left.ptr.offset);
return ans;
}
case BO_LT:
case BO_GT:
case BO_LE:
case BO_GE:
case BO_EQ:
case BO_NE:
{
const EmuVal *left = eval_rexpr(ex->getLHS());
QualType tl = left->obj_type.getCanonicalType();
QualType tr = right->obj_type.getCanonicalType();
if(tl != IntType || tr != IntType){
left->obj_type.dump();
right->obj_type.dump();
cant_handle();
}
const llvm::APInt* lval = &((const EmuNum<NUM_TYPE_INT>*)left)->val;
llvm::APInt rval = ((const EmuNum<NUM_TYPE_INT>*)right)->val;
int ans;
if(lval->isNegative()){
if(op == BO_LT) ans = (lval->slt(rval))?1:0;
else if(op==BO_GT) ans = (lval->sgt(rval))?1:0;
else if(op==BO_LE) ans = (lval->sle(rval))?1:0;
else if(op==BO_GE) ans = (lval->sge(rval))?1:0;
else if(op==BO_EQ) ans = (lval->eq( rval))?1:0;
else if(op==BO_NE) ans = (lval->ne( rval))?1:0;
} else if(rval.isNegative()){
//.........这里部分代码省略.........