aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR
diff options
context:
space:
mode:
authorAndreas Jonson <andjo403@hotmail.com>2024-03-20 12:43:00 +0100
committerGitHub <noreply@github.com>2024-03-20 12:43:00 +0100
commite66cfebb04ff4fcf313905f49dbd863e7113432c (patch)
tree11f5ba3cd889f64b63387240d663a7ada1c80ee2 /llvm/lib/IR
parentf24d68a1078c4330a764a837eff58e9934637c1a (diff)
downloadllvm-e66cfebb04ff4fcf313905f49dbd863e7113432c.zip
llvm-e66cfebb04ff4fcf313905f49dbd863e7113432c.tar.gz
llvm-e66cfebb04ff4fcf313905f49dbd863e7113432c.tar.bz2
[ValueTracking] Handle range attributes (#85143)
Handle the range attribute in ValueTracking.
Diffstat (limited to 'llvm/lib/IR')
-rw-r--r--llvm/lib/IR/Function.cpp8
-rw-r--r--llvm/lib/IR/Instructions.cpp8
2 files changed, 16 insertions, 0 deletions
diff --git a/llvm/lib/IR/Function.cpp b/llvm/lib/IR/Function.cpp
index d22e1c1..eb126f1 100644
--- a/llvm/lib/IR/Function.cpp
+++ b/llvm/lib/IR/Function.cpp
@@ -24,6 +24,7 @@
#include "llvm/IR/Attributes.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Constant.h"
+#include "llvm/IR/ConstantRange.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/GlobalValue.h"
@@ -256,6 +257,13 @@ FPClassTest Argument::getNoFPClass() const {
return getParent()->getParamNoFPClass(getArgNo());
}
+std::optional<ConstantRange> Argument::getRange() const {
+ const Attribute RangeAttr = getAttribute(llvm::Attribute::Range);
+ if (RangeAttr.isValid())
+ return RangeAttr.getRange();
+ return std::nullopt;
+}
+
bool Argument::hasNestAttr() const {
if (!getType()->isPointerTy()) return false;
return hasAttribute(Attribute::Nest);
diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp
index c55d6cf..494d50f 100644
--- a/llvm/lib/IR/Instructions.cpp
+++ b/llvm/lib/IR/Instructions.cpp
@@ -19,6 +19,7 @@
#include "llvm/IR/Attributes.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Constant.h"
+#include "llvm/IR/ConstantRange.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DerivedTypes.h"
@@ -395,6 +396,13 @@ FPClassTest CallBase::getParamNoFPClass(unsigned i) const {
return Mask;
}
+std::optional<ConstantRange> CallBase::getRange() const {
+ const Attribute RangeAttr = getRetAttr(llvm::Attribute::Range);
+ if (RangeAttr.isValid())
+ return RangeAttr.getRange();
+ return std::nullopt;
+}
+
bool CallBase::isReturnNonNull() const {
if (hasRetAttr(Attribute::NonNull))
return true;