From deb9ea3a8c842f279cf9d7db695760acd55be660 Mon Sep 17 00:00:00 2001 From: Johannes Doerfert Date: Fri, 23 Aug 2019 15:42:19 +0000 Subject: [PATCH] [Attributor][NFCI] Avoid lookups when resolving returned values If the number of potentially returned values not change since the last traversal we do not need to visit the returned values again. This works as we only add values to the returned values set now. Differential Revision: https://reviews.llvm.org/D66484 llvm-svn: 369770 --- llvm/lib/Transforms/IPO/Attributor.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp index 373e491c846e..ea897d7e3610 100644 --- a/llvm/lib/Transforms/IPO/Attributor.cpp +++ b/llvm/lib/Transforms/IPO/Attributor.cpp @@ -682,13 +682,18 @@ class AAReturnedValuesImpl : public AAReturnedValues, public AbstractState { /// return instructions that might return them. DenseMap> ReturnedValues; + /// Mapping to remember the number of returned values for a call site such + /// that we can avoid updates if nothing changed. + DenseMap NumReturnedValuesPerKnownAA; + + /// Set of unresolved calls returned by the associated function. SmallSetVector UnresolvedCalls; /// State flags /// ///{ - bool IsFixed; - bool IsValidState; + bool IsFixed = false; + bool IsValidState = true; ///} public: @@ -774,7 +779,6 @@ public: /// See AbstractState::indicateOptimisticFixpoint(...). ChangeStatus indicateOptimisticFixpoint() override { IsFixed = true; - IsValidState &= true; return ChangeStatus::UNCHANGED; } @@ -974,6 +978,15 @@ ChangeStatus AAReturnedValuesImpl::updateImpl(Attributor &A) { if (Unresolved) continue; + // Now track transitively returned values. + unsigned &NumRetAA = NumReturnedValuesPerKnownAA[CB]; + if (NumRetAA == RetValAA.getNumReturnValues()) { + LLVM_DEBUG(dbgs() << "[AAReturnedValues] Skip call as it has not " + "changed since it was seen last\n"); + continue; + } + NumRetAA = RetValAA.getNumReturnValues(); + for (auto &RetValAAIt : RetValAA.returned_values()) { Value *RetVal = RetValAAIt.first; if (Argument *Arg = dyn_cast(RetVal)) {