[llvm] 3670ec2 - [LICM][AA] Move isWritableObject() to AA (NFC)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 16 05:43:10 PDT 2023


Author: Nikita Popov
Date: 2023-08-16T14:43:01+02:00
New Revision: 3670ec2897c02e51a4c3e4b788c99ea70d6106ea

URL: https://github.com/llvm/llvm-project/commit/3670ec2897c02e51a4c3e4b788c99ea70d6106ea
DIFF: https://github.com/llvm/llvm-project/commit/3670ec2897c02e51a4c3e4b788c99ea70d6106ea.diff

LOG: [LICM][AA] Move isWritableObject() to AA (NFC)

Move this helper from LICM to AA, so it can be reused.

Added: 
    

Modified: 
    llvm/include/llvm/Analysis/AliasAnalysis.h
    llvm/lib/Analysis/AliasAnalysis.cpp
    llvm/lib/Transforms/Scalar/LICM.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Analysis/AliasAnalysis.h b/llvm/include/llvm/Analysis/AliasAnalysis.h
index 8da8d516499aa4..4f06ae1d38c6aa 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 7b2f91f5392a5b..75fe68a80ab608 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 1d8fef9e409aec..ef8a97e5ec20dd 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


        


More information about the llvm-commits mailing list