Lines Matching defs:ConstantRange
1 //===-- ConstantRange.cpp - ConstantRange implementation ------------------===//
25 #include "llvm/Support/ConstantRange.h"
32 ConstantRange::ConstantRange(uint32_t BitWidth, bool Full) {
41 ConstantRange::ConstantRange(APIntMoveTy V)
44 ConstantRange::ConstantRange(APIntMoveTy L, APIntMoveTy U)
47 "ConstantRange with unequal bit widths");
52 ConstantRange ConstantRange::makeICmpRegion(unsigned Pred,
53 const ConstantRange &CR) {
64 return ConstantRange(CR.getUpper(), CR.getLower());
65 return ConstantRange(W);
69 return ConstantRange(W, /* empty */ false);
70 return ConstantRange(APInt::getMinValue(W), UMax);
75 return ConstantRange(W, /* empty */ false);
76 return ConstantRange(APInt::getSignedMinValue(W), SMax);
81 return ConstantRange(W);
82 return ConstantRange(APInt::getMinValue(W), UMax + 1);
87 return ConstantRange(W);
88 return ConstantRange(APInt::getSignedMinValue(W), SMax + 1);
93 return ConstantRange(W, /* empty */ false);
94 return ConstantRange(UMin + 1, APInt::getNullValue(W));
99 return ConstantRange(W, /* empty */ false);
100 return ConstantRange(SMin + 1, APInt::getSignedMinValue(W));
105 return ConstantRange(W);
106 return ConstantRange(UMin, APInt::getNullValue(W));
111 return ConstantRange(W);
112 return ConstantRange(SMin, APInt::getSignedMinValue(W));
119 bool ConstantRange::isFullSet() const {
125 bool ConstantRange::isEmptySet() const {
132 bool ConstantRange::isWrappedSet() const {
139 bool ConstantRange::isSignWrappedSet() const {
146 APInt ConstantRange::getSetSize() const {
161 /// ConstantRange.
163 APInt ConstantRange::getUnsignedMax() const {
170 /// ConstantRange.
172 APInt ConstantRange::getUnsignedMin() const {
179 /// ConstantRange.
181 APInt ConstantRange::getSignedMax() const {
194 /// ConstantRange.
196 APInt ConstantRange::getSignedMin() const {
212 bool ConstantRange::contains(const APInt &V) const {
225 bool ConstantRange::contains(const ConstantRange &Other) const {
245 ConstantRange ConstantRange::subtract(const APInt &Val) const {
250 return ConstantRange(Lower - Val, Upper - Val);
255 ConstantRange ConstantRange::difference(const ConstantRange &CR) const {
264 ConstantRange ConstantRange::intersectWith(const ConstantRange &CR) const {
266 "ConstantRange types don't agree!");
278 return ConstantRange(getBitWidth(), false);
281 return ConstantRange(CR.Lower, Upper);
289 return ConstantRange(Lower, CR.Upper);
291 return ConstantRange(getBitWidth(), false);
300 return ConstantRange(CR.Lower, Upper);
308 return ConstantRange(getBitWidth(), false);
310 return ConstantRange(Lower, CR.Upper);
323 return ConstantRange(Lower, CR.Upper);
331 return ConstantRange(CR.Lower, Upper);
345 ConstantRange ConstantRange::unionWith(const ConstantRange &CR) const {
347 "ConstantRange types don't agree!");
359 return ConstantRange(Lower, CR.Upper);
360 return ConstantRange(CR.Lower, Upper);
370 return ConstantRange(getBitWidth());
372 return ConstantRange(L, U);
384 return ConstantRange(getBitWidth());
392 return ConstantRange(Lower, CR.Upper);
393 return ConstantRange(CR.Lower, Upper);
399 return ConstantRange(CR.Lower, Upper);
404 "ConstantRange::unionWith missed a case with one range wrapped");
405 return ConstantRange(Lower, CR.Upper);
411 return ConstantRange(getBitWidth());
419 return ConstantRange(L, U);
426 ConstantRange ConstantRange::zeroExtend(uint32_t DstTySize) const {
427 if (isEmptySet()) return ConstantRange(DstTySize, /*isFullSet=*/false);
436 return ConstantRange(LowerExt, APInt::getOneBitSet(DstTySize, SrcTySize));
439 return ConstantRange(Lower.zext(DstTySize), Upper.zext(DstTySize));
446 ConstantRange ConstantRange::signExtend(uint32_t DstTySize) const {
447 if (isEmptySet()) return ConstantRange(DstTySize, /*isFullSet=*/false);
452 return ConstantRange(APInt::getHighBitsSet(DstTySize,DstTySize-SrcTySize+1),
456 return ConstantRange(Lower.sext(DstTySize), Upper.sext(DstTySize));
463 ConstantRange ConstantRange::truncate(uint32_t DstTySize) const {
466 return ConstantRange(DstTySize, /*isFullSet=*/false);
468 return ConstantRange(DstTySize, /*isFullSet=*/true);
475 ConstantRange Union(DstTySize, /*isFullSet=*/false);
483 return ConstantRange(DstTySize, /*isFullSet=*/true);
485 Union = ConstantRange(APInt::getMaxValue(DstTySize),Upper.trunc(DstTySize));
502 return ConstantRange(LowerDiv.trunc(DstTySize),
508 return ConstantRange(LowerDiv.trunc(DstTySize),
511 return ConstantRange(DstTySize, /*isFullSet=*/true);
516 ConstantRange ConstantRange::zextOrTrunc(uint32_t DstTySize) const {
527 ConstantRange ConstantRange::sextOrTrunc(uint32_t DstTySize) const {
536 ConstantRange
537 ConstantRange::add(const ConstantRange &Other) const {
539 return ConstantRange(getBitWidth(), /*isFullSet=*/false);
541 return ConstantRange(getBitWidth(), /*isFullSet=*/true);
547 return ConstantRange(getBitWidth(), /*isFullSet=*/true);
549 ConstantRange X = ConstantRange(NewLower, NewUpper);
552 return ConstantRange(getBitWidth(), /*isFullSet=*/true);
557 ConstantRange
558 ConstantRange::sub(const ConstantRange &Other) const {
560 return ConstantRange(getBitWidth(), /*isFullSet=*/false);
562 return ConstantRange(getBitWidth(), /*isFullSet=*/true);
568 return ConstantRange(getBitWidth(), /*isFullSet=*/true);
570 ConstantRange X = ConstantRange(NewLower, NewUpper);
573 return ConstantRange(getBitWidth(), /*isFullSet=*/true);
578 ConstantRange
579 ConstantRange::multiply(const ConstantRange &Other) const {
586 return ConstantRange(getBitWidth(), /*isFullSet=*/false);
593 ConstantRange Result_zext = ConstantRange(this_min * Other_min,
598 ConstantRange
599 ConstantRange::smax(const ConstantRange &Other) const {
603 return ConstantRange(getBitWidth(), /*isFullSet=*/false);
607 return ConstantRange(getBitWidth(), /*isFullSet=*/true);
608 return ConstantRange(NewL, NewU);
611 ConstantRange
612 ConstantRange::umax(const ConstantRange &Other) const {
616 return ConstantRange(getBitWidth(), /*isFullSet=*/false);
620 return ConstantRange(getBitWidth(), /*isFullSet=*/true);
621 return ConstantRange(NewL, NewU);
624 ConstantRange
625 ConstantRange::udiv(const ConstantRange &RHS) const {
627 return ConstantRange(getBitWidth(), /*isFullSet=*/false);
629 return ConstantRange(getBitWidth(), /*isFullSet=*/true);
648 return ConstantRange(getBitWidth(), /*isFullSet=*/true);
650 return ConstantRange(Lower, Upper);
653 ConstantRange
654 ConstantRange::binaryAnd(const ConstantRange &Other) const {
656 return ConstantRange(getBitWidth(), /*isFullSet=*/false);
662 return ConstantRange(getBitWidth(), /*isFullSet=*/true);
663 return ConstantRange(APInt::getNullValue(getBitWidth()), umin + 1);
666 ConstantRange
667 ConstantRange::binaryOr(const ConstantRange &Other) const {
669 return ConstantRange(getBitWidth(), /*isFullSet=*/false);
675 return ConstantRange(getBitWidth(), /*isFullSet=*/true);
676 return ConstantRange(umax, APInt::getNullValue(getBitWidth()));
679 ConstantRange
680 ConstantRange::shl(const ConstantRange &Other) const {
682 return ConstantRange(getBitWidth(), /*isFullSet=*/false);
690 return ConstantRange(min, max + 1);
693 return ConstantRange(getBitWidth(), /*isFullSet=*/true);
696 ConstantRange
697 ConstantRange::lshr(const ConstantRange &Other) const {
699 return ConstantRange(getBitWidth(), /*isFullSet=*/false);
704 return ConstantRange(getBitWidth(), /*isFullSet=*/true);
706 return ConstantRange(min, max + 1);
709 ConstantRange ConstantRange::inverse() const {
711 return ConstantRange(getBitWidth(), /*isFullSet=*/false);
713 return ConstantRange(getBitWidth(), /*isFullSet=*/true);
714 return ConstantRange(Upper, Lower);
719 void ConstantRange::print(raw_ostream &OS) const {
730 void ConstantRange::dump() const {