[llvm] 513d47c - [FunctionAttrs] Extract some code into separate functions (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 10 01:02:50 PDT 2023
Author: Nikita Popov
Date: 2023-08-10T10:02:43+02:00
New Revision: 513d47c65aa64fa25a1848de3a1cb0bdacc36a90
URL: https://github.com/llvm/llvm-project/commit/513d47c65aa64fa25a1848de3a1cb0bdacc36a90
DIFF: https://github.com/llvm/llvm-project/commit/513d47c65aa64fa25a1848de3a1cb0bdacc36a90.diff
LOG: [FunctionAttrs] Extract some code into separate functions (NFC)
To reduce diff in a future patch.
Added:
Modified:
llvm/lib/Transforms/IPO/FunctionAttrs.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
index d9fe1c20c43cbb..7a6fc02e783e75 100644
--- a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
@@ -110,6 +110,39 @@ using SCCNodeSet = SmallSetVector<Function *, 8>;
} // end anonymous namespace
+static void addLocAccess(MemoryEffects &ME, const MemoryLocation &Loc,
+ ModRefInfo MR, AAResults &AAR) {
+ // Ignore accesses to known-invariant or local memory.
+ MR &= AAR.getModRefInfoMask(Loc, /*IgnoreLocal=*/true);
+ if (isNoModRef(MR))
+ return;
+
+ const Value *UO = getUnderlyingObject(Loc.Ptr);
+ assert(!isa<AllocaInst>(UO) &&
+ "Should have been handled by getModRefInfoMask()");
+ if (isa<Argument>(UO)) {
+ ME |= MemoryEffects::argMemOnly(MR);
+ return;
+ }
+
+ // If it's not an identified object, it might be an argument.
+ if (!isIdentifiedObject(UO))
+ ME |= MemoryEffects::argMemOnly(MR);
+ ME |= MemoryEffects(IRMemLocation::Other, MR);
+}
+
+static void addArgLocs(MemoryEffects &ME, const CallBase *Call,
+ ModRefInfo ArgMR, AAResults &AAR) {
+ for (const Value *Arg : Call->args()) {
+ if (!Arg->getType()->isPtrOrPtrVectorTy())
+ continue;
+
+ addLocAccess(ME,
+ MemoryLocation::getBeforeOrAfter(Arg, Call->getAAMetadata()),
+ ArgMR, AAR);
+ }
+}
+
/// Returns the memory access attribute for function F using AAR for AA results,
/// where SCCNodes is the current SCC.
///
@@ -135,25 +168,6 @@ static MemoryEffects checkFunctionMemoryAccess(Function &F, bool ThisBody,
F.getAttributes().hasAttrSomewhere(Attribute::Preallocated))
ME |= MemoryEffects::argMemOnly(ModRefInfo::ModRef);
- auto AddLocAccess = [&](const MemoryLocation &Loc, ModRefInfo MR) {
- // Ignore accesses to known-invariant or local memory.
- MR &= AAR.getModRefInfoMask(Loc, /*IgnoreLocal=*/true);
- if (isNoModRef(MR))
- return;
-
- const Value *UO = getUnderlyingObject(Loc.Ptr);
- assert(!isa<AllocaInst>(UO) &&
- "Should have been handled by getModRefInfoMask()");
- if (isa<Argument>(UO)) {
- ME |= MemoryEffects::argMemOnly(MR);
- return;
- }
-
- // If it's not an identified object, it might be an argument.
- if (!isIdentifiedObject(UO))
- ME |= MemoryEffects::argMemOnly(MR);
- ME |= MemoryEffects(IRMemLocation::Other, MR);
- };
// Scan the function body for instructions that may read or write memory.
for (Instruction &I : instructions(F)) {
// Some instructions can be ignored even if they read or write memory.
@@ -190,15 +204,8 @@ static MemoryEffects checkFunctionMemoryAccess(Function &F, bool ThisBody,
// Check whether all pointer arguments point to local memory, and
// ignore calls that only access local memory.
ModRefInfo ArgMR = CallME.getModRef(IRMemLocation::ArgMem);
- if (ArgMR != ModRefInfo::NoModRef) {
- for (const Use &U : Call->args()) {
- const Value *Arg = U;
- if (!Arg->getType()->isPtrOrPtrVectorTy())
- continue;
-
- AddLocAccess(MemoryLocation::getBeforeOrAfter(Arg, I.getAAMetadata()), ArgMR);
- }
- }
+ if (ArgMR != ModRefInfo::NoModRef)
+ addArgLocs(ME, Call, ArgMR, AAR);
continue;
}
@@ -222,7 +229,7 @@ static MemoryEffects checkFunctionMemoryAccess(Function &F, bool ThisBody,
if (I.isVolatile())
ME |= MemoryEffects::inaccessibleMemOnly(MR);
- AddLocAccess(*Loc, MR);
+ addLocAccess(ME, *Loc, MR, AAR);
}
return OrigME & ME;
More information about the llvm-commits
mailing list