From c4ad24deeed8165f1c636473459982b8d9570e74 Mon Sep 17 00:00:00 2001 From: Johannes Doerfert Date: Thu, 26 Jan 2023 21:05:30 -0800 Subject: [PATCH] [Attributor][NCFI] Explicitly state what interfering accesses to look for We used to check the query instructions for effects but that does not work well with complex accesses we will probably support in the future. Now we simply let the user decide what accesses to look for. --- llvm/include/llvm/Transforms/IPO/Attributor.h | 1 + llvm/lib/Transforms/IPO/Attributor.cpp | 6 ++++-- llvm/lib/Transforms/IPO/AttributorAttributes.cpp | 3 +-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/llvm/include/llvm/Transforms/IPO/Attributor.h b/llvm/include/llvm/Transforms/IPO/Attributor.h index da171f8..9cd351f 100644 --- a/llvm/include/llvm/Transforms/IPO/Attributor.h +++ b/llvm/include/llvm/Transforms/IPO/Attributor.h @@ -5483,6 +5483,7 @@ struct AAPointerInfo : public AbstractAttribute { /// read the intial value of the underlying memory. virtual bool forallInterferingAccesses( Attributor &A, const AbstractAttribute &QueryingAA, Instruction &I, + bool FindInterferingWrites, bool FindInterferingReads, function_ref CB, bool &HasBeenWrittenTo, AA::RangeTy &Range) const = 0; diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp index b9134ce..67d21ad 100644 --- a/llvm/lib/Transforms/IPO/Attributor.cpp +++ b/llvm/lib/Transforms/IPO/Attributor.cpp @@ -451,8 +451,10 @@ static bool getPotentialCopiesOfMemoryValue( AA::RangeTy Range; auto &PI = A.getAAFor(QueryingAA, IRPosition::value(Obj), DepClassTy::NONE); - if (!PI.forallInterferingAccesses(A, QueryingAA, I, CheckAccess, - HasBeenWrittenTo, Range)) { + if (!PI.forallInterferingAccesses(A, QueryingAA, I, + /* FindInterferingWrites */ IsLoad, + /* FindInterferingReads */ !IsLoad, + CheckAccess, HasBeenWrittenTo, Range)) { LLVM_DEBUG( dbgs() << "Failed to verify all interfering accesses for underlying object: " diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp index 2730adf..569a4a9 100644 --- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp +++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp @@ -1032,6 +1032,7 @@ struct AAPointerInfoImpl bool forallInterferingAccesses( Attributor &A, const AbstractAttribute &QueryingAA, Instruction &I, + bool FindInterferingWrites, bool FindInterferingReads, function_ref UserCB, bool &HasBeenWrittenTo, AA::RangeTy &Range) const override { HasBeenWrittenTo = false; @@ -1099,8 +1100,6 @@ struct AAPointerInfoImpl const auto &NoRecurseAA = A.getAAFor( QueryingAA, IRPosition::function(Scope), DepClassTy::OPTIONAL); - const bool FindInterferingWrites = I.mayReadFromMemory(); - const bool FindInterferingReads = I.mayWriteToMemory(); const bool UseDominanceReasoning = FindInterferingWrites && NoRecurseAA.isKnownNoRecurse(); const DominatorTree *DT = -- 2.7.4