[PATCH] D129122: ManagedStatic: remove from PassManagerBuilder
Nicolai Hähnle via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 5 02:17:32 PDT 2022
nhaehnle created this revision.
nhaehnle added reviewers: efriedma, lattner.
Herald added subscribers: ormris, hiraditya.
Herald added a project: All.
nhaehnle requested review of this revision.
Herald added a project: LLVM.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D129122
Files:
llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
Index: llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
===================================================================
--- llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
+++ llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
@@ -23,7 +23,6 @@
#include "llvm/Analysis/TypeBasedAliasAnalysis.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/Support/CommandLine.h"
-#include "llvm/Support/ManagedStatic.h"
#include "llvm/Target/CGPassBuilderOption.h"
#include "llvm/Transforms/AggressiveInstCombine/AggressiveInstCombine.h"
#include "llvm/Transforms/IPO.h"
@@ -210,27 +209,43 @@
delete Inliner;
}
-/// Set of global extensions, automatically added as part of the standard set.
-static ManagedStatic<
+namespace {
+
+bool GlobalExtensionsConstructed = false;
+PassManagerBuilder::GlobalExtensionID GlobalExtensionsCounter;
+
+using GlobalExtensionsVector =
SmallVector<std::tuple<PassManagerBuilder::ExtensionPointTy,
PassManagerBuilder::ExtensionFn,
- PassManagerBuilder::GlobalExtensionID>,
- 8>>
- GlobalExtensions;
-static PassManagerBuilder::GlobalExtensionID GlobalExtensionsCounter;
+ PassManagerBuilder::GlobalExtensionID>>;
+
+struct GlobalExtensions {
+ GlobalExtensionsVector Extensions;
+
+ GlobalExtensions() { GlobalExtensionsConstructed = true; }
+};
+
+/// Set of global extensions, automatically added as part of the standard set.
+GlobalExtensionsVector &getGlobalExtensions() {
+ static GlobalExtensions GlobalExts;
+ return GlobalExts.Extensions;
+}
+
+} // anonymous namespace
/// 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();
+ return GlobalExtensionsConstructed && !getGlobalExtensions().empty();
}
PassManagerBuilder::GlobalExtensionID
PassManagerBuilder::addGlobalExtension(PassManagerBuilder::ExtensionPointTy Ty,
PassManagerBuilder::ExtensionFn Fn) {
auto ExtensionID = GlobalExtensionsCounter++;
- GlobalExtensions->push_back(std::make_tuple(Ty, std::move(Fn), ExtensionID));
+ getGlobalExtensions().push_back(
+ std::make_tuple(Ty, std::move(Fn), ExtensionID));
return ExtensionID;
}
@@ -238,17 +253,17 @@
PassManagerBuilder::GlobalExtensionID ExtensionID) {
// RegisterStandardPasses may try to call this function after GlobalExtensions
// has already been destroyed; doing so should not generate an error.
- if (!GlobalExtensions.isConstructed())
+ if (!GlobalExtensionsConstructed)
return;
auto GlobalExtension =
- llvm::find_if(*GlobalExtensions, [ExtensionID](const auto &elem) {
+ llvm::find_if(getGlobalExtensions(), [ExtensionID](const auto &elem) {
return std::get<2>(elem) == ExtensionID;
});
- assert(GlobalExtension != GlobalExtensions->end() &&
+ assert(GlobalExtension != getGlobalExtensions().end() &&
"The extension ID to be removed should always be valid.");
- GlobalExtensions->erase(GlobalExtension);
+ getGlobalExtensions().erase(GlobalExtension);
}
void PassManagerBuilder::addExtension(ExtensionPointTy Ty, ExtensionFn Fn) {
@@ -258,7 +273,7 @@
void PassManagerBuilder::addExtensionsToPM(ExtensionPointTy ETy,
legacy::PassManagerBase &PM) const {
if (GlobalExtensionsNotEmpty()) {
- for (auto &Ext : *GlobalExtensions) {
+ for (auto &Ext : getGlobalExtensions()) {
if (std::get<0>(Ext) == ETy)
std::get<1>(Ext)(*this, PM);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129122.442223.patch
Type: text/x-patch
Size: 3750 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220705/ee5a960f/attachment.bin>
More information about the llvm-commits
mailing list