aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/Value.cpp
diff options
context:
space:
mode:
authorSanjoy Das <sanjoy@playingwithpointers.com>2016-06-02 00:52:48 +0000
committerSanjoy Das <sanjoy@playingwithpointers.com>2016-06-02 00:52:48 +0000
commit00953cbe1d981eb1a12558b060611170c7641c0e (patch)
tree7186e0eaa223947a57b2eaa6002b38543127096d /llvm/lib/IR/Value.cpp
parenta530a3615e89cbe615db2db51468daa235b81d47 (diff)
downloadllvm-00953cbe1d981eb1a12558b060611170c7641c0e.zip
llvm-00953cbe1d981eb1a12558b060611170c7641c0e.tar.gz
llvm-00953cbe1d981eb1a12558b060611170c7641c0e.tar.bz2
Remove Value::isPointerDereferenceable; NFCI
... and merge into `Value::getPointerDereferenceableBytes`. This was suggested by Artur Pilipenko in D20764 -- since we no longer allow loads of unsized types, there is no need anymore to have this special logic. llvm-svn: 271455
Diffstat (limited to 'llvm/lib/IR/Value.cpp')
-rw-r--r--llvm/lib/IR/Value.cpp42
1 files changed, 18 insertions, 24 deletions
diff --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp
index de2c599..f8c87a1 100644
--- a/llvm/lib/IR/Value.cpp
+++ b/llvm/lib/IR/Value.cpp
@@ -525,13 +525,18 @@ Value *Value::stripInBoundsOffsets() {
return stripPointerCastsAndOffsets<PSK_InBounds>(this);
}
-unsigned Value::getPointerDereferenceableBytes(bool &CanBeNull) const {
+unsigned Value::getPointerDereferenceableBytes(const DataLayout &DL,
+ bool &CanBeNull) const {
assert(getType()->isPointerTy() && "must be pointer");
unsigned DerefBytes = 0;
CanBeNull = false;
if (const Argument *A = dyn_cast<Argument>(this)) {
DerefBytes = A->getDereferenceableBytes();
+ if (DerefBytes == 0 && A->hasByValAttr() && A->getType()->isSized()) {
+ DerefBytes = DL.getTypeStoreSize(A->getType());
+ CanBeNull = false;
+ }
if (DerefBytes == 0) {
DerefBytes = A->getDereferenceableOrNullBytes();
CanBeNull = true;
@@ -555,33 +560,22 @@ unsigned Value::getPointerDereferenceableBytes(bool &CanBeNull) const {
}
CanBeNull = true;
}
+ } else if (auto *AI = dyn_cast<AllocaInst>(this)) {
+ if (AI->getAllocatedType()->isSized()) {
+ DerefBytes = DL.getTypeStoreSize(AI->getAllocatedType());
+ CanBeNull = false;
+ }
+ } else if (auto *GV = dyn_cast<GlobalVariable>(this)) {
+ if (GV->getValueType()->isSized() && !GV->hasExternalWeakLinkage()) {
+ // TODO: Don't outright reject hasExternalWeakLinkage but set the
+ // CanBeNull flag.
+ DerefBytes = DL.getTypeStoreSize(GV->getValueType());
+ CanBeNull = false;
+ }
}
return DerefBytes;
}
-bool Value::isPointerDereferenceable(bool &CanBeNull) const {
- assert(getType()->isPointerTy() && "must be pointer");
-
- CanBeNull = false;
-
- // These are obviously ok.
- if (isa<AllocaInst>(this))
- return true;
-
- // Global variables which can't collapse to null are ok.
- // TODO: return true for those but set CanBeNull flag
- if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(this))
- if (!GV->hasExternalWeakLinkage())
- return true;
-
- // byval arguments are okay.
- if (const Argument *A = dyn_cast<Argument>(this))
- if (A->hasByValAttr())
- return true;
-
- return false;
-}
-
unsigned Value::getPointerAlignment(const DataLayout &DL) const {
assert(getType()->isPointerTy() && "must be pointer");