From bed31153b7354b27e7b5cc2bf29647c4ee8418e9 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Wed, 19 Oct 2022 16:55:24 +0200 Subject: [PATCH] [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. --- llvm/lib/Transforms/IPO/FunctionAttrs.cpp | 36 +++++++++++-------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/llvm/lib/Transforms/IPO/FunctionAttrs.cpp b/llvm/lib/Transforms/IPO/FunctionAttrs.cpp index 013e806..7ca76ad 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(UO) || isa(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(UO) && !isa(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; -- 2.7.4