[PATCH] D29695: FunctionAttrs: Factor out a function for querying memory access of a specific copy of a function. NFC.
Peter Collingbourne via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 13 13:50:32 PST 2017
pcc updated this revision to Diff 88253.
pcc added a comment.
- Address review comments
https://reviews.llvm.org/D29695
Files:
llvm/include/llvm/Transforms/IPO/FunctionAttrs.h
llvm/lib/Transforms/IPO/FunctionAttrs.cpp
Index: llvm/lib/Transforms/IPO/FunctionAttrs.cpp
===================================================================
--- llvm/lib/Transforms/IPO/FunctionAttrs.cpp
+++ llvm/lib/Transforms/IPO/FunctionAttrs.cpp
@@ -53,27 +53,15 @@
typedef SmallSetVector<Function *, 8> SCCNodeSet;
}
-namespace {
-/// The three kinds of memory access relevant to 'readonly' and
-/// 'readnone' attributes.
-enum MemoryAccessKind {
- MAK_ReadNone = 0,
- MAK_ReadOnly = 1,
- MAK_MayWrite = 2
-};
-}
-
-static MemoryAccessKind checkFunctionMemoryAccess(Function &F, AAResults &AAR,
+static MemoryAccessKind checkFunctionMemoryAccess(Function &F, bool ThisBody,
+ AAResults &AAR,
const SCCNodeSet &SCCNodes) {
FunctionModRefBehavior MRB = AAR.getModRefBehavior(&F);
if (MRB == FMRB_DoesNotAccessMemory)
// Already perfect!
return MAK_ReadNone;
- // Non-exact function definitions may not be selected at link time, and an
- // alternative version that writes to memory may be selected. See the comment
- // on GlobalValue::isDefinitionExact for more details.
- if (!F.hasExactDefinition()) {
+ if (!ThisBody) {
if (AliasAnalysis::onlyReadsMemory(MRB))
return MAK_ReadOnly;
@@ -172,6 +160,11 @@
return ReadsMemory ? MAK_ReadOnly : MAK_ReadNone;
}
+MemoryAccessKind llvm::computeFunctionBodyMemoryAccess(Function &F,
+ AAResults &AAR) {
+ return checkFunctionMemoryAccess(F, /*ThisBody=*/true, AAR, {});
+}
+
/// Deduce readonly/readnone attributes for the SCC.
template <typename AARGetterT>
static bool addReadAttrs(const SCCNodeSet &SCCNodes, AARGetterT &&AARGetter) {
@@ -182,7 +175,11 @@
// Call the callable parameter to look up AA results for this function.
AAResults &AAR = AARGetter(*F);
- switch (checkFunctionMemoryAccess(*F, AAR, SCCNodes)) {
+ // Non-exact function definitions may not be selected at link time, and an
+ // alternative version that writes to memory may be selected. See the
+ // comment on GlobalValue::isDefinitionExact for more details.
+ switch (checkFunctionMemoryAccess(*F, F->hasExactDefinition(),
+ AAR, SCCNodes)) {
case MAK_MayWrite:
return false;
case MAK_ReadOnly:
Index: llvm/include/llvm/Transforms/IPO/FunctionAttrs.h
===================================================================
--- llvm/include/llvm/Transforms/IPO/FunctionAttrs.h
+++ llvm/include/llvm/Transforms/IPO/FunctionAttrs.h
@@ -20,6 +20,19 @@
namespace llvm {
+class AAResults;
+
+/// The three kinds of memory access relevant to 'readonly' and
+/// 'readnone' attributes.
+enum MemoryAccessKind {
+ MAK_ReadNone = 0,
+ MAK_ReadOnly = 1,
+ MAK_MayWrite = 2
+};
+
+/// Returns the memory access properties of this copy of the function.
+MemoryAccessKind computeFunctionBodyMemoryAccess(Function &F, AAResults &AAR);
+
/// Computes function attributes in post-order over the call graph.
///
/// By operating in post-order, this pass computes precise attributes for
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29695.88253.patch
Type: text/x-patch
Size: 3151 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170213/b8f1b5b8/attachment-0001.bin>
More information about the llvm-commits
mailing list