mirror of
https://github.com/FEX-Emu/FEX.git
synced 2026-10-06 09:00:17 +02:00
PassManager: Pass string by const reference where applicable
Gets rid of potential extraneous copies. We also add handling for cases where two passes with the same name are unintentionally added. Previously we'd blindly overwrite the mapping.
This commit is contained in:
1 parent
fa80d11960
commit
d619e36523
2 files changed
+26
-18
No files matched your search
@@ -13,6 +13,7 @@ $end_info$
|
||||
#include "Interface/IR/Passes/RegisterAllocationPass.h"
|
||||
|
||||
#include <FEXCore/Config/Config.h>
|
||||
#include <FEXCore/Utils/LogManager.h>
|
||||
#include <FEXCore/Utils/Profiler.h>
|
||||
|
||||
namespace FEXCore::IR {
|
||||
@@ -83,12 +84,9 @@ void PassManager::AddDefaultPasses(Context::ContextImpl* ctx) {
|
||||
#endif
|
||||
}
|
||||
|
||||
Pass* PassManager::InsertPass(fextl::unique_ptr<Pass> Pass, fextl::string Name) {
|
||||
auto PassPtr = InsertAt(Passes.end(), std::move(Pass))->get();
|
||||
|
||||
if (!Name.empty()) {
|
||||
NameToPassMaping[Name] = PassPtr;
|
||||
}
|
||||
Pass* PassManager::InsertPass(fextl::unique_ptr<Pass> Pass, const fextl::string& Name) {
|
||||
auto* PassPtr = InsertAt(Passes.end(), std::move(Pass))->get();
|
||||
AttemptNameMapping(Name, PassPtr);
|
||||
return PassPtr;
|
||||
}
|
||||
|
||||
@@ -98,13 +96,10 @@ PassManager::PassArrayType::iterator PassManager::InsertAt(PassArrayType::iterat
|
||||
}
|
||||
|
||||
#if defined(ASSERTIONS_ENABLED) && ASSERTIONS_ENABLED
|
||||
void PassManager::InsertValidationPass(fextl::unique_ptr<Pass> Pass, fextl::string Name) {
|
||||
void PassManager::InsertValidationPass(fextl::unique_ptr<Pass> Pass, const fextl::string& Name) {
|
||||
Pass->RegisterPassManager(this);
|
||||
auto PassPtr = ValidationPasses.emplace_back(std::move(Pass)).get();
|
||||
|
||||
if (!Name.empty()) {
|
||||
NameToPassMaping[Name] = PassPtr;
|
||||
}
|
||||
auto* PassPtr = ValidationPasses.emplace_back(std::move(Pass)).get();
|
||||
AttemptNameMapping(Name, PassPtr);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -121,4 +116,15 @@ void PassManager::Run(IREmitter* IREmit) {
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void PassManager::AttemptNameMapping(const fextl::string& Name, Pass* NewPass) {
|
||||
if (Name.empty()) {
|
||||
// Empty name is a 'don't care' case. e.g. Passes that just need to run,
|
||||
// but don't need to be actively looked up.
|
||||
return;
|
||||
}
|
||||
|
||||
const auto Result = NameToPassMaping.emplace(Name, NewPass);
|
||||
LOGMAN_THROW_A_FMT(Result.second, "Tried to insert pass with name '{}'. But name is already used", Name);
|
||||
}
|
||||
} // namespace FEXCore::IR
|
||||
@@ -44,18 +44,18 @@ public:
|
||||
|
||||
void Run(IREmitter* IREmit);
|
||||
|
||||
Pass* InsertPass(fextl::unique_ptr<Pass> Pass, fextl::string Name = "");
|
||||
Pass* InsertPass(fextl::unique_ptr<Pass> Pass, const fextl::string& Name = "");
|
||||
|
||||
bool HasPass(fextl::string Name) const {
|
||||
bool HasPass(const fextl::string& Name) const {
|
||||
return NameToPassMaping.contains(Name);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
T* GetPass(fextl::string Name) {
|
||||
return dynamic_cast<T*>(NameToPassMaping[Name]);
|
||||
T* GetPass(const fextl::string& Name) {
|
||||
return dynamic_cast<T*>(GetPass(Name));
|
||||
}
|
||||
|
||||
Pass* GetPass(fextl::string Name) {
|
||||
Pass* GetPass(const fextl::string& Name) {
|
||||
return NameToPassMaping[Name];
|
||||
}
|
||||
|
||||
@@ -72,9 +72,11 @@ private:
|
||||
|
||||
#if defined(ASSERTIONS_ENABLED) && ASSERTIONS_ENABLED
|
||||
fextl::vector<fextl::unique_ptr<Pass>> ValidationPasses;
|
||||
void InsertValidationPass(fextl::unique_ptr<Pass> Pass, fextl::string Name = "");
|
||||
void InsertValidationPass(fextl::unique_ptr<Pass> Pass, const fextl::string& Name = "");
|
||||
#endif
|
||||
|
||||
void AttemptNameMapping(const fextl::string& Name, Pass* NewPass);
|
||||
|
||||
FEX_CONFIG_OPT(Is64BitMode, IS64BIT_MODE);
|
||||
FEX_CONFIG_OPT(PassManagerDumpIR, PASSMANAGERDUMPIR);
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user