summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2015-10-27 01:41:43 +0000
committerChandler Carruth <chandlerc@gmail.com>2015-10-27 01:41:43 +0000
commit69798fb5ec6500bdff0e33442d732a06de98f419 (patch)
tree843cc8b676ce5d3eeda71b0f397a857045f67792 /llvm/lib
parent63d2b7796138144cc6e3a8fb98f9c4b10606ea12 (diff)
downloadbcm5719-llvm-69798fb5ec6500bdff0e33442d732a06de98f419.tar.gz
bcm5719-llvm-69798fb5ec6500bdff0e33442d732a06de98f419.zip
[function-attrs] Refactor code to handle shorter code with early exits.
No functionality changed here, but the indentation is substantially reduced and IMO the code is much easier to read. I've also added some helpful comments. This is just a clean-up I wrote while studying the code, and that has been in my backlog for a while. llvm-svn: 251381
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/IPO/FunctionAttrs.cpp68
1 files changed, 37 insertions, 31 deletions
diff --git a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
index da657e3bbf0..6c357ed03a8 100644
--- a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
@@ -130,39 +130,45 @@ checkFunctionMemoryAccess(Function &F, AAResults &AAR,
if (CS.getCalledFunction() && SCCNodes.count(CS.getCalledFunction()))
continue;
FunctionModRefBehavior MRB = AAR.getModRefBehavior(CS);
- // If the call doesn't access arbitrary memory, we may be able to
- // figure out something.
- if (AliasAnalysis::onlyAccessesArgPointees(MRB)) {
- // If the call does access argument pointees, check each argument.
- if (AliasAnalysis::doesAccessArgPointees(MRB))
- // Check whether all pointer arguments point to local memory, and
- // ignore calls that only access local memory.
- for (CallSite::arg_iterator CI = CS.arg_begin(), CE = CS.arg_end();
- CI != CE; ++CI) {
- Value *Arg = *CI;
- if (Arg->getType()->isPointerTy()) {
- AAMDNodes AAInfo;
- I->getAAMetadata(AAInfo);
-
- MemoryLocation Loc(Arg, MemoryLocation::UnknownSize, AAInfo);
- if (!AAR.pointsToConstantMemory(Loc, /*OrLocal=*/true)) {
- if (MRB & MRI_Mod)
- // Writes non-local memory. Give up.
- return MAK_MayWrite;
- if (MRB & MRI_Ref)
- // Ok, it reads non-local memory.
- ReadsMemory = true;
- }
- }
- }
+
+ // If the call doesn't access memory, we're done.
+ if (!(MRB & MRI_ModRef))
continue;
+
+ if (!AliasAnalysis::onlyAccessesArgPointees(MRB)) {
+ // The call could access any memory. If that includes writes, give up.
+ if (MRB & MRI_Mod)
+ return MAK_MayWrite;
+ // If it reads, note it.
+ if (MRB & MRI_Ref)
+ ReadsMemory = true;
+ continue;
+ }
+
+ // Check whether all pointer arguments point to local memory, and
+ // ignore calls that only access local memory.
+ for (CallSite::arg_iterator CI = CS.arg_begin(), CE = CS.arg_end();
+ CI != CE; ++CI) {
+ Value *Arg = *CI;
+ if (!Arg->getType()->isPointerTy())
+ continue;
+
+ AAMDNodes AAInfo;
+ I->getAAMetadata(AAInfo);
+ MemoryLocation Loc(Arg, MemoryLocation::UnknownSize, AAInfo);
+
+ // Skip accesses to local or constant memory as they don't impact the
+ // externally visible mod/ref behavior.
+ if (AAR.pointsToConstantMemory(Loc, /*OrLocal=*/true))
+ continue;
+
+ if (MRB & MRI_Mod)
+ // Writes non-local memory. Give up.
+ return MAK_MayWrite;
+ if (MRB & MRI_Ref)
+ // Ok, it reads non-local memory.
+ ReadsMemory = true;
}
- // The call could access any memory. If that includes writes, give up.
- if (MRB & MRI_Mod)
- return MAK_MayWrite;
- // If it reads, note it.
- if (MRB & MRI_Ref)
- ReadsMemory = true;
continue;
} else if (LoadInst *LI = dyn_cast<LoadInst>(I)) {
// Ignore non-volatile loads from local memory. (Atomic is okay here.)
OpenPOWER on IntegriCloud