[llvm] bed3115 - [FuncAttrs] Extract code for adding a location access (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 20 03:03:41 PDT 2022
Author: Nikita Popov
Date: 2022-10-20T12:01:27+02:00
New Revision: bed31153b7354b27e7b5cc2bf29647c4ee8418e9
URL: https://github.com/llvm/llvm-project/commit/bed31153b7354b27e7b5cc2bf29647c4ee8418e9
DIFF: https://github.com/llvm/llvm-project/commit/bed31153b7354b27e7b5cc2bf29647c4ee8418e9.diff
LOG: [FuncAttrs] Extract code for adding a location access (NFC)
This code is the same for accesses from call arguments and for
accesses from other (single-location) instructions. Extract i
into a common function.
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 013e806207b4..7ca76adb3d68 100644
--- a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp
@@ -139,10 +139,17 @@ static MemoryEffects checkFunctionMemoryAccess(Function &F, bool ThisBody,
F.getAttributes().hasAttrSomewhere(Attribute::Preallocated))
ME |= MemoryEffects::argMemOnly(ModRefInfo::ModRef);
- // Returns true if Ptr is not based on a function argument.
- auto IsArgumentOrAlloca = [](const Value *Ptr) {
- const Value *UO = getUnderlyingObject(Ptr);
- return isa<Argument>(UO) || isa<AllocaInst>(UO);
+ auto AddLocAccess = [&](const MemoryLocation &Loc, ModRefInfo MR) {
+ // Ignore accesses to local memory.
+ if (AAR.pointsToConstantMemory(Loc, /*OrLocal=*/true))
+ return;
+
+ const Value *UO = getUnderlyingObject(Loc.Ptr);
+ // The accessed location can be either only argument memory, or
+ // argument & other memory, but never inaccessible memory.
+ ME |= MemoryEffects::argMemOnly(MR);
+ if (!isa<Argument>(UO) && !isa<AllocaInst>(UO))
+ ME |= MemoryEffects(MemoryEffects::Other, MR);
};
// Scan the function body for instructions that may read or write memory.
for (Instruction &I : instructions(F)) {
@@ -186,16 +193,7 @@ static MemoryEffects checkFunctionMemoryAccess(Function &F, bool ThisBody,
if (!Arg->getType()->isPtrOrPtrVectorTy())
continue;
- MemoryLocation Loc =
- MemoryLocation::getBeforeOrAfter(Arg, I.getAAMetadata());
- // 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;
-
- ME |= MemoryEffects::argMemOnly(ArgMR);
- if (!IsArgumentOrAlloca(Loc.Ptr))
- ME |= MemoryEffects(MemoryEffects::Other, ArgMR);
+ AddLocAccess(MemoryLocation::getBeforeOrAfter(Arg, I.getAAMetadata()), ArgMR);
}
}
continue;
@@ -221,15 +219,7 @@ static MemoryEffects checkFunctionMemoryAccess(Function &F, bool ThisBody,
if (I.isVolatile())
ME |= MemoryEffects::inaccessibleMemOnly(MR);
- // Ignore accesses to local memory.
- if (AAR.pointsToConstantMemory(*Loc, /*OrLocal=*/true))
- continue;
-
- // The accessed location can be either only argument memory, or
- // argument & other memory, but never inaccessible memory.
- ME |= MemoryEffects::argMemOnly(MR);
- if (!IsArgumentOrAlloca(Loc->Ptr))
- ME |= MemoryEffects(MemoryEffects::Other, MR);
+ AddLocAccess(*Loc, MR);
}
return OrigME & ME;
More information about the llvm-commits
mailing list