diff options
author | Reid Spencer <rspencer@reidspencer.com> | 2007-02-28 22:00:54 +0000 |
---|---|---|
committer | Reid Spencer <rspencer@reidspencer.com> | 2007-02-28 22:00:54 +0000 |
commit | 3da43849f2a2319ded6ed379ec8e7d620d6ac8c6 (patch) | |
tree | 15ae8b9a7ca2a7bcca10e5fabd55153ef7fee39c /lib/VMCore/Instructions.cpp | |
parent | 8782d481a3c720304540254a7b71d25bbe7cbf49 (diff) | |
download | external_llvm-3da43849f2a2319ded6ed379ec8e7d620d6ac8c6.zip external_llvm-3da43849f2a2319ded6ed379ec8e7d620d6ac8c6.tar.gz external_llvm-3da43849f2a2319ded6ed379ec8e7d620d6ac8c6.tar.bz2 |
Provide an ICmpInst::makeConstantRange to generate a ConstantRange value
from a predicate and an APInt. This is removed from ConstantRange class
so that ConstantRange doesn't have to depend on lib/VMCore.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34760 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/Instructions.cpp')
-rw-r--r-- | lib/VMCore/Instructions.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp index e1af531..f4519d4 100644 --- a/lib/VMCore/Instructions.cpp +++ b/lib/VMCore/Instructions.cpp @@ -18,6 +18,7 @@ #include "llvm/Function.h" #include "llvm/Instructions.h" #include "llvm/Support/CallSite.h" +#include "llvm/Support/ConstantRange.h" using namespace llvm; unsigned CallSite::getCallingConv() const { @@ -2217,6 +2218,41 @@ bool ICmpInst::isSignedPredicate(Predicate pred) { } } +/// Initialize a set of values that all satisfy the condition with C. +/// +ConstantRange +ICmpInst::makeConstantRange(Predicate pred, const APInt &C) { + APInt Lower(C); + APInt Upper(C); + uint32_t BitWidth = C.getBitWidth(); + switch (pred) { + default: assert(0 && "Invalid ICmp opcode to ConstantRange ctor!"); + case ICmpInst::ICMP_EQ: Upper++; break; + case ICmpInst::ICMP_NE: Lower++; break; + case ICmpInst::ICMP_ULT: Lower = APInt::getMinValue(BitWidth); break; + case ICmpInst::ICMP_SLT: Lower = APInt::getSignedMinValue(BitWidth); break; + case ICmpInst::ICMP_UGT: + Lower++; Upper = APInt::getMinValue(BitWidth); // Min = Next(Max) + break; + case ICmpInst::ICMP_SGT: + Lower++; Upper = APInt::getSignedMinValue(BitWidth); // Min = Next(Max) + break; + case ICmpInst::ICMP_ULE: + Lower = APInt::getMinValue(BitWidth); Upper++; + break; + case ICmpInst::ICMP_SLE: + Lower = APInt::getSignedMinValue(BitWidth); Upper++; + break; + case ICmpInst::ICMP_UGE: + Upper = APInt::getMinValue(BitWidth); // Min = Next(Max) + break; + case ICmpInst::ICMP_SGE: + Upper = APInt::getSignedMinValue(BitWidth); // Min = Next(Max) + break; + } + return ConstantRange(Lower, Upper); +} + FCmpInst::Predicate FCmpInst::getInversePredicate(Predicate pred) { switch (pred) { default: |