forked from OSchip/llvm-project
Avoid constructing GlobalExtensions only to find out it is empty.
Summary: GlobalExtensions is dereferenced twice, once for iteration and then a check if it is empty. As a ManagedStatic this dereference forces it's construction which is unnecessary. Reviewers: efriedma, davide, mehdi_amini Reviewed By: mehdi_amini Subscribers: chapuni, llvm-commits, mehdi_amini Differential Revision: https://reviews.llvm.org/D33381 llvm-svn: 307229
This commit is contained in:
parent
42a96a286c
commit
52dfcd18d1
|
@ -188,6 +188,13 @@ PassManagerBuilder::~PassManagerBuilder() {
|
|||
static ManagedStatic<SmallVector<std::pair<PassManagerBuilder::ExtensionPointTy,
|
||||
PassManagerBuilder::ExtensionFn>, 8> > GlobalExtensions;
|
||||
|
||||
/// Check if GlobalExtensions is constructed and not empty.
|
||||
/// Since GlobalExtensions is a managed static, calling 'empty()' will trigger
|
||||
/// the construction of the object.
|
||||
static bool GlobalExtensionsNotEmpty() {
|
||||
return GlobalExtensions.isConstructed() && !GlobalExtensions->empty();
|
||||
}
|
||||
|
||||
void PassManagerBuilder::addGlobalExtension(
|
||||
PassManagerBuilder::ExtensionPointTy Ty,
|
||||
PassManagerBuilder::ExtensionFn Fn) {
|
||||
|
@ -200,9 +207,12 @@ void PassManagerBuilder::addExtension(ExtensionPointTy Ty, ExtensionFn Fn) {
|
|||
|
||||
void PassManagerBuilder::addExtensionsToPM(ExtensionPointTy ETy,
|
||||
legacy::PassManagerBase &PM) const {
|
||||
for (unsigned i = 0, e = GlobalExtensions->size(); i != e; ++i)
|
||||
if ((*GlobalExtensions)[i].first == ETy)
|
||||
(*GlobalExtensions)[i].second(*this, PM);
|
||||
if (GlobalExtensionsNotEmpty()) {
|
||||
for (auto &Ext : *GlobalExtensions) {
|
||||
if (Ext.first == ETy)
|
||||
Ext.second(*this, PM);
|
||||
}
|
||||
}
|
||||
for (unsigned i = 0, e = Extensions.size(); i != e; ++i)
|
||||
if (Extensions[i].first == ETy)
|
||||
Extensions[i].second(*this, PM);
|
||||
|
@ -415,7 +425,7 @@ void PassManagerBuilder::populateModulePassManager(
|
|||
// builds. The function merging pass is
|
||||
if (MergeFunctions)
|
||||
MPM.add(createMergeFunctionsPass());
|
||||
else if (!GlobalExtensions->empty() || !Extensions.empty())
|
||||
else if (GlobalExtensionsNotEmpty() || !Extensions.empty())
|
||||
MPM.add(createBarrierNoopPass());
|
||||
|
||||
addExtensionsToPM(EP_EnabledOnOptLevel0, MPM);
|
||||
|
|
Loading…
Reference in New Issue