aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/GlobalsModRef.cpp
diff options
context:
space:
mode:
authorVaivaswatha Nagaraj <vn@compilertree.com>2015-12-18 11:02:52 +0000
committerVaivaswatha Nagaraj <vn@compilertree.com>2015-12-18 11:02:52 +0000
commited237938da703c55cf83de0ca5090aa35a774a27 (patch)
treeeb8bfa0bcc5ae3b643e56c9c4284cbf7fef02eae /llvm/lib/Analysis/GlobalsModRef.cpp
parent652246108005857512e1b9b38b752ea564e97811 (diff)
downloadllvm-ed237938da703c55cf83de0ca5090aa35a774a27.zip
llvm-ed237938da703c55cf83de0ca5090aa35a774a27.tar.gz
llvm-ed237938da703c55cf83de0ca5090aa35a774a27.tar.bz2
GlobalsAA: Take advantage of ArgMemOnly, InaccessibleMemOnly and InaccessibleMemOrArgMemOnly attributes
Summary: 1. Modify AnalyzeCallGraph() to retain function info for external functions if the function has [InaccessibleMemOr]ArgMemOnly flags. 2. When analyzing the use of a global is function parameter at a call site, mark the callee also as modifying the global appropriately. 3. Add additional test cases. Depends on D15499 Reviewers: hfinkel, jmolloy Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D15605 llvm-svn: 255994
Diffstat (limited to 'llvm/lib/Analysis/GlobalsModRef.cpp')
-rw-r--r--llvm/lib/Analysis/GlobalsModRef.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/llvm/lib/Analysis/GlobalsModRef.cpp b/llvm/lib/Analysis/GlobalsModRef.cpp
index 86c2e50..51a83d5 100644
--- a/llvm/lib/Analysis/GlobalsModRef.cpp
+++ b/llvm/lib/Analysis/GlobalsModRef.cpp
@@ -376,6 +376,15 @@ bool GlobalsAAResult::AnalyzeUsesOfPointer(Value *V,
} else {
return true; // Argument of an unknown call.
}
+ // If the Callee is not ReadNone, it may read the global,
+ // and if it is not ReadOnly, it may also write to it.
+ Function *CalleeF = CS.getCalledFunction();
+ if (!CalleeF->doesNotAccessMemory()) {
+ if (Readers)
+ Readers->insert(CalleeF);
+ if (Writers && !CalleeF->onlyReadsMemory())
+ Writers->insert(CalleeF);
+ }
}
} else if (ICmpInst *ICI = dyn_cast<ICmpInst>(I)) {
if (!isa<ConstantPointerNull>(ICI->getOperand(1)))
@@ -507,7 +516,7 @@ void GlobalsAAResult::AnalyzeCallGraph(CallGraph &CG, Module &M) {
if (F->isDeclaration()) {
// Try to get mod/ref behaviour from function attributes.
- if (F->doesNotAccessMemory()) {
+ if (F->doesNotAccessMemory() || F->onlyAccessesInaccessibleMemory()) {
// Can't do better than that!
} else if (F->onlyReadsMemory()) {
FI.addModRefInfo(MRI_Ref);
@@ -515,6 +524,12 @@ void GlobalsAAResult::AnalyzeCallGraph(CallGraph &CG, Module &M) {
// This function might call back into the module and read a global -
// consider every global as possibly being read by this function.
FI.setMayReadAnyGlobal();
+ } else if (F->onlyAccessesArgMemory() ||
+ F->onlyAccessesInaccessibleMemOrArgMem()) {
+ // This function may only access (read/write) memory pointed to by its
+ // arguments. If this pointer is to a global, this escaping use of the
+ // pointer is captured in AnalyzeUsesOfPointer().
+ FI.addModRefInfo(MRI_ModRef);
} else {
FI.addModRefInfo(MRI_ModRef);
// Can't say anything useful unless it's an intrinsic - they don't