diff options
author | Philip Reames <listmail@philipreames.com> | 2021-03-19 11:15:29 -0700 |
---|---|---|
committer | Philip Reames <listmail@philipreames.com> | 2021-03-19 11:17:19 -0700 |
commit | 5698537f81a2ecf1166f41cab264b92af670aaa1 (patch) | |
tree | ddf63abda7567ddc830bb59d2db784edd83d2f4e /llvm/lib/IR/Value.cpp | |
parent | 66f340051ac2d334f30ef85251323b12cb2e6e5f (diff) | |
download | llvm-5698537f81a2ecf1166f41cab264b92af670aaa1.zip llvm-5698537f81a2ecf1166f41cab264b92af670aaa1.tar.gz llvm-5698537f81a2ecf1166f41cab264b92af670aaa1.tar.bz2 |
Update basic deref API to account for possiblity of free [NFC]
This patch is plumbing to support work towards the goal outlined in the recent llvm-dev post "[llvm-dev] RFC: Decomposing deref(N) into deref(N) + nofree".
The point of this change is purely to simplify iteration on other pieces on way to making the switch. Rebuilding with a change to Value.h is slow and painful, so I want to get the API change landed. Once that's done, I plan to more closely audit each caller, add the inference rules in their own patch, then post a patch with the langref changes and test diffs. The value of the command line flag is that we can exercise the inference logic in standalone patches without needing the whole switch ready to go just yet.
Differential Revision: https://reviews.llvm.org/D98908
Diffstat (limited to 'llvm/lib/IR/Value.cpp')
-rw-r--r-- | llvm/lib/IR/Value.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp index 92ffae1..cfb91b5 100644 --- a/llvm/lib/IR/Value.cpp +++ b/llvm/lib/IR/Value.cpp @@ -38,6 +38,11 @@ using namespace llvm; +static cl::opt<unsigned> UseDerefAtPointSemantics( + "use-dereferenceable-at-point-semantics", cl::Hidden, cl::init(false), + cl::desc("Deref attributes and metadata infer facts at definition only")); + + static cl::opt<unsigned> NonGlobalValueMaxNameSize( "non-global-value-max-name-size", cl::Hidden, cl::init(1024), cl::desc("Maximum size for the name of non-global values.")); @@ -724,11 +729,13 @@ Value::stripInBoundsOffsets(function_ref<void(const Value *)> Func) const { } uint64_t Value::getPointerDereferenceableBytes(const DataLayout &DL, - bool &CanBeNull) const { + bool &CanBeNull, + bool &CanBeFreed) const { assert(getType()->isPointerTy() && "must be pointer"); uint64_t DerefBytes = 0; CanBeNull = false; + CanBeFreed = UseDerefAtPointSemantics; if (const Argument *A = dyn_cast<Argument>(this)) { DerefBytes = A->getDereferenceableBytes(); if (DerefBytes == 0) { @@ -783,6 +790,7 @@ uint64_t Value::getPointerDereferenceableBytes(const DataLayout &DL, DerefBytes = DL.getTypeStoreSize(AI->getAllocatedType()).getKnownMinSize(); CanBeNull = false; + CanBeFreed = false; } } else if (auto *GV = dyn_cast<GlobalVariable>(this)) { if (GV->getValueType()->isSized() && !GV->hasExternalWeakLinkage()) { @@ -790,6 +798,7 @@ uint64_t Value::getPointerDereferenceableBytes(const DataLayout &DL, // CanBeNull flag. DerefBytes = DL.getTypeStoreSize(GV->getValueType()).getFixedSize(); CanBeNull = false; + CanBeFreed = false; } } return DerefBytes; |