From 0c083024f0fdaa958ec8b1a8cd5b27dc53bf68af Mon Sep 17 00:00:00 2001 From: Hal Finkel Date: Mon, 1 Sep 2014 09:01:39 +0000 Subject: Feed AA to the inliner and use AA->getModRefBehavior in AddAliasScopeMetadata This feeds AA through the IFI structure into the inliner so that AddAliasScopeMetadata can use AA->getModRefBehavior to figure out which functions only access their arguments (instead of just hard-coding some knowledge of memory intrinsics). Most of the information is only available from BasicAA; this is important for preserving alias scoping information for target-specific intrinsics when doing the noalias parameter attribute to metadata conversion. llvm-svn: 216866 --- llvm/lib/Transforms/Utils/InlineFunction.cpp | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'llvm/lib/Transforms/Utils/InlineFunction.cpp') diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp index d885541..f2930dc 100644 --- a/llvm/lib/Transforms/Utils/InlineFunction.cpp +++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp @@ -394,7 +394,7 @@ static void CloneAliasScopeMetadata(CallSite CS, ValueToValueMapTy &VMap) { /// parameters with noalias metadata specifying the new scope, and tag all /// non-derived loads, stores and memory intrinsics with the new alias scopes. static void AddAliasScopeMetadata(CallSite CS, ValueToValueMapTy &VMap, - const DataLayout *DL) { + const DataLayout *DL, AliasAnalysis *AA) { if (!EnableNoAliasConversion) return; @@ -458,6 +458,7 @@ static void AddAliasScopeMetadata(CallSite CS, ValueToValueMapTy &VMap, if (!NI) continue; + bool IsArgMemOnlyCall = false, IsFuncCall = false; SmallVector PtrArgs; if (const LoadInst *LI = dyn_cast(I)) @@ -477,23 +478,28 @@ static void AddAliasScopeMetadata(CallSite CS, ValueToValueMapTy &VMap, if (ICS.doesNotAccessMemory()) continue; + IsFuncCall = true; + if (AA) { + AliasAnalysis::ModRefBehavior MRB = AA->getModRefBehavior(ICS); + if (MRB == AliasAnalysis::OnlyAccessesArgumentPointees || + MRB == AliasAnalysis::OnlyReadsArgumentPointees) + IsArgMemOnlyCall = true; + } + for (ImmutableCallSite::arg_iterator AI = ICS.arg_begin(), - AE = ICS.arg_end(); AI != AE; ++AI) + AE = ICS.arg_end(); AI != AE; ++AI) { // We need to check the underlying objects of all arguments, not just // the pointer arguments, because we might be passing pointers as // integers, etc. - // FIXME: If we know that the call only accesses pointer arguments, + // However, if we know that the call only accesses pointer arguments, // then we only need to check the pointer arguments. + if (IsArgMemOnlyCall && !(*AI)->getType()->isPointerTy()) + continue; + PtrArgs.push_back(*AI); + } } - bool IsFuncCall = isa(I) || isa(I); - // FIXME: We should have a way to access the - // IntrReadArgMem/IntrReadWriteArgMem properties of intrinsics, and we - // should have a way to determine that for regular functions too. For - // now, just do this for the memory intrinsics we understand. - bool IsArgMemOnlyCall = isa(I); - // If we found no pointers, then this instruction is not suitable for // pairing with an instruction to receive aliasing metadata. // However, if this is a call, this we might just alias with none of the @@ -975,7 +981,7 @@ bool llvm::InlineFunction(CallSite CS, InlineFunctionInfo &IFI, CloneAliasScopeMetadata(CS, VMap); // Add noalias metadata if necessary. - AddAliasScopeMetadata(CS, VMap, IFI.DL); + AddAliasScopeMetadata(CS, VMap, IFI.DL, IFI.AA); } // If there are any alloca instructions in the block that used to be the entry -- cgit v1.1