1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-25 04:02:41 +01:00

[PM] Avoid duplicates in the Used/Preserved/Required sets

The pass analysis uses "sets" implemented using a SmallVector type
to keep track of Used, Preserved, Required and RequiredTransitive
passes. When having nested analyses we could end up with duplicates
in those sets, as there was no checks to see if a pass already
existed in the "set" before pushing to the vectors. This idea with
this patch is to avoid such duplicates by avoiding pushing elements
that already is contained when adding elements to those sets.

To align with the above PMDataManager::collectRequiredAndUsedAnalyses
is changed to skip adding both the Required and RequiredTransitive
passes to its result vectors (since RequiredTransitive always is
a subset of Required we ended up with duplicates when traversing
both sets).

Main goal with this is to avoid spending time verifying the same
analysis mulitple times in PMDataManager::verifyPreservedAnalysis
when iterating over the Preserved "set". It is assumed that removing
duplicates from a "set" shouldn't have any other negative impact
(I have not seen any problems so far). If this ends up causing
problems one could do some uniqueness filtering of the vector being
traversed in verifyPreservedAnalysis instead.

Reviewed By: foad

Differential Revision: https://reviews.llvm.org/D94416
This commit is contained in:
Bjorn Pettersson 2021-01-11 13:08:38 +01:00
parent f86f5e31ed
commit be875842f9
3 changed files with 19 additions and 18 deletions

View File

@ -17,11 +17,12 @@
#if !defined(LLVM_PASS_H) || defined(LLVM_PASSANALYSISSUPPORT_H)
#error "Do not include <PassAnalysisSupport.h>; include <Pass.h> instead"
#endif
#endif
#ifndef LLVM_PASSANALYSISSUPPORT_H
#define LLVM_PASSANALYSISSUPPORT_H
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallVector.h"
#include <cassert>
#include <tuple>
@ -58,6 +59,11 @@ private:
SmallVector<AnalysisID, 0> Used;
bool PreservesAll = false;
void pushUnique(VectorType &Set, AnalysisID ID) {
if (!llvm::is_contained(Set, ID))
Set.push_back(ID);
}
public:
AnalysisUsage() = default;
@ -80,17 +86,17 @@ public:
///@{
/// Add the specified ID to the set of analyses preserved by this pass.
AnalysisUsage &addPreservedID(const void *ID) {
Preserved.push_back(ID);
pushUnique(Preserved, ID);
return *this;
}
AnalysisUsage &addPreservedID(char &ID) {
Preserved.push_back(&ID);
pushUnique(Preserved, &ID);
return *this;
}
/// Add the specified Pass class to the set of analyses preserved by this pass.
template<class PassClass>
AnalysisUsage &addPreserved() {
Preserved.push_back(&PassClass::ID);
pushUnique(Preserved, &PassClass::ID);
return *this;
}
///@}
@ -99,17 +105,17 @@ public:
/// Add the specified ID to the set of analyses used by this pass if they are
/// available..
AnalysisUsage &addUsedIfAvailableID(const void *ID) {
Used.push_back(ID);
pushUnique(Used, ID);
return *this;
}
AnalysisUsage &addUsedIfAvailableID(char &ID) {
Used.push_back(&ID);
pushUnique(Used, &ID);
return *this;
}
/// Add the specified Pass class to the set of analyses used by this pass.
template<class PassClass>
AnalysisUsage &addUsedIfAvailable() {
Used.push_back(&PassClass::ID);
pushUnique(Used, &PassClass::ID);
return *this;
}
///@}

View File

@ -1110,12 +1110,6 @@ void PMDataManager::collectRequiredAndUsedAnalyses(
UP.push_back(AnalysisPass);
else
RP_NotAvail.push_back(RequiredID);
for (const auto &RequiredID : AnUsage->getRequiredTransitiveSet())
if (Pass *AnalysisPass = findAnalysisPass(RequiredID, true))
UP.push_back(AnalysisPass);
else
RP_NotAvail.push_back(RequiredID);
}
// All Required analyses should be available to the pass as it runs! Here

View File

@ -259,22 +259,23 @@ void AnalysisUsage::setPreservesCFG() {
AnalysisUsage &AnalysisUsage::addPreserved(StringRef Arg) {
const PassInfo *PI = Pass::lookupPassInfo(Arg);
// If the pass exists, preserve it. Otherwise silently do nothing.
if (PI) Preserved.push_back(PI->getTypeInfo());
if (PI)
pushUnique(Preserved, PI->getTypeInfo());
return *this;
}
AnalysisUsage &AnalysisUsage::addRequiredID(const void *ID) {
Required.push_back(ID);
pushUnique(Required, ID);
return *this;
}
AnalysisUsage &AnalysisUsage::addRequiredID(char &ID) {
Required.push_back(&ID);
pushUnique(Required, &ID);
return *this;
}
AnalysisUsage &AnalysisUsage::addRequiredTransitiveID(char &ID) {
Required.push_back(&ID);
RequiredTransitive.push_back(&ID);
pushUnique(Required, &ID);
pushUnique(RequiredTransitive, &ID);
return *this;
}