Files
pytorch/torch/csrc/jit/passes/pass_manager.cpp
Aaron Gokaslan 3916d7a575 Apply modernize-use-emplace to aten, c10, torch (#91077)
Apply clang-tidy check modernize-use-emplace. This is slightly more efficient by using an inplace constructor and is the recommended style in parts of the codebase covered by clang-tidy. This just manually applies the check to rest of the codebase. Pinging @ezyang as this is related to my other PRs he reviewed like #89000

Pull Request resolved: https://github.com/pytorch/pytorch/pull/91077
Approved by: https://github.com/ezyang
2022-12-19 07:49:56 +00:00

72 lines
1.6 KiB
C++

#include <torch/csrc/jit/passes/pass_manager.h>
namespace torch {
namespace jit {
// Start UUID at 1
static GraphPassNameType graphPassID = 1;
std::vector<GraphPassEntry>& getCustomPostPasses() {
static std::vector<GraphPassEntry> passes;
return passes;
}
std::vector<GraphPassEntry>& getCustomPrePasses() {
static std::vector<GraphPassEntry> passes;
return passes;
}
GraphPassNameType registerPostPass(GraphPass p) {
getCustomPostPasses().emplace_back(std::move(p), graphPassID);
return graphPassID++;
}
GraphPassNameType registerPass(GraphPass p) {
return registerPostPass(std::move(p));
}
GraphPassNameType registerPrePass(GraphPass p) {
getCustomPrePasses().emplace_back(std::move(p), graphPassID);
return graphPassID++;
}
void clearPostPass(GraphPassNameType pid) {
auto& passes = getCustomPostPasses();
auto it = passes.begin();
for (; it != passes.end(); it++) {
if (pid == (*it).second)
break;
}
if (it != passes.end())
passes.erase(it);
}
void clearPrePass(GraphPassNameType pid) {
auto& passes = getCustomPrePasses();
auto it = passes.begin();
for (; it != passes.end(); it++) {
if (pid == (*it).second)
break;
}
if (it != passes.end())
passes.erase(it);
}
void clearAllPostPasses() {
auto& passes = getCustomPostPasses();
passes.erase(passes.begin(), passes.end());
}
void clearAllPrePasses() {
auto& passes = getCustomPrePasses();
passes.erase(passes.begin(), passes.end());
}
// LEGACY CALL
RegisterPostPass::RegisterPostPass(GraphPass p) {
registerPass(std::move(p));
}
} // namespace jit
} // namespace torch