From 3670ec2897c02e51a4c3e4b788c99ea70d6106ea Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Wed, 16 Aug 2023 14:42:10 +0200 Subject: [LICM][AA] Move isWritableObject() to AA (NFC) Move this helper from LICM to AA, so it can be reused. --- llvm/lib/Analysis/AliasAnalysis.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'llvm/lib/Analysis/AliasAnalysis.cpp') 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(Object)) + return true; + + // TODO: Also handle sret. + if (auto *A = dyn_cast(Object)) + return A->hasByValAttr(); + + // TODO: Noalias shouldn't imply writability, this should check for an + // allocator function instead. + return isNoAliasCall(Object); +} -- cgit v1.1