diff options
author | Nikita Popov <npopov@redhat.com> | 2023-08-16 14:42:10 +0200 |
---|---|---|
committer | Nikita Popov <npopov@redhat.com> | 2023-08-16 14:43:01 +0200 |
commit | 3670ec2897c02e51a4c3e4b788c99ea70d6106ea (patch) | |
tree | 0197735eb70585d8c788ca6f3f47006ee792fd7e | |
parent | 566065207ba33cdc6d76c2d0c9304182ab408f73 (diff) | |
download | llvm-3670ec2897c02e51a4c3e4b788c99ea70d6106ea.zip llvm-3670ec2897c02e51a4c3e4b788c99ea70d6106ea.tar.gz llvm-3670ec2897c02e51a4c3e4b788c99ea70d6106ea.tar.bz2 |
[LICM][AA] Move isWritableObject() to AA (NFC)
Move this helper from LICM to AA, so it can be reused.
-rw-r--r-- | llvm/include/llvm/Analysis/AliasAnalysis.h | 7 | ||||
-rw-r--r-- | llvm/lib/Analysis/AliasAnalysis.cpp | 17 | ||||
-rw-r--r-- | llvm/lib/Transforms/Scalar/LICM.cpp | 17 |
3 files changed, 24 insertions, 17 deletions
diff --git a/llvm/include/llvm/Analysis/AliasAnalysis.h b/llvm/include/llvm/Analysis/AliasAnalysis.h index 8da8d51..4f06ae1 100644 --- a/llvm/include/llvm/Analysis/AliasAnalysis.h +++ b/llvm/include/llvm/Analysis/AliasAnalysis.h @@ -873,6 +873,13 @@ bool isEscapeSource(const Value *V); bool isNotVisibleOnUnwind(const Value *Object, bool &RequiresNoCaptureBeforeUnwind); +/// Return true if the Object is writable, in the sense that any location based +/// on this pointer that can be loaded can also be stored to without trapping. +/// +/// By itself, this does not imply that introducing spurious stores is safe, +/// for example due to thread-safety reasons. +bool isWritableObject(const Value *Object); + /// A manager for alias analyses. /// /// This class can have analyses registered with it and when run, it will run diff --git a/llvm/lib/Analysis/AliasAnalysis.cpp b/llvm/lib/Analysis/AliasAnalysis.cpp index 7b2f91f..75fe68a8 100644 --- a/llvm/lib/Analysis/AliasAnalysis.cpp +++ b/llvm/lib/Analysis/AliasAnalysis.cpp @@ -908,3 +908,20 @@ bool llvm::isNotVisibleOnUnwind(const Value *Object, return false; } + +// We don't consider globals as writable: While the physical memory is writable, +// we may not have provenance to perform the write. +bool llvm::isWritableObject(const Value *Object) { + // TODO: Alloca might not be writable after its lifetime ends. + // See https://github.com/llvm/llvm-project/issues/51838. + if (isa<AllocaInst>(Object)) + return true; + + // TODO: Also handle sret. + if (auto *A = dyn_cast<Argument>(Object)) + return A->hasByValAttr(); + + // TODO: Noalias shouldn't imply writability, this should check for an + // allocator function instead. + return isNoAliasCall(Object); +} diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp index 1d8fef9..ef8a97e 100644 --- a/llvm/lib/Transforms/Scalar/LICM.cpp +++ b/llvm/lib/Transforms/Scalar/LICM.cpp @@ -1943,23 +1943,6 @@ bool isNotVisibleOnUnwindInLoop(const Value *Object, const Loop *L, isNotCapturedBeforeOrInLoop(Object, L, DT); } -// We don't consider globals as writable: While the physical memory is writable, -// we may not have provenance to perform the write. -bool isWritableObject(const Value *Object) { - // TODO: Alloca might not be writable after its lifetime ends. - // See https://github.com/llvm/llvm-project/issues/51838. - if (isa<AllocaInst>(Object)) - return true; - - // TODO: Also handle sret. - if (auto *A = dyn_cast<Argument>(Object)) - return A->hasByValAttr(); - - // TODO: Noalias has nothing to do with writability, this should check for - // an allocator function. - return isNoAliasCall(Object); -} - bool isThreadLocalObject(const Value *Object, const Loop *L, DominatorTree *DT, TargetTransformInfo *TTI) { // The object must be function-local to start with, and then not captured |